Subject: Re: mopd and byte order
To: Blaz Zupan <blaz@inlimbo.org>
From: Maciej W. Rozycki <macro@ds2.pg.gda.pl>
List: port-pmax
Date: 03/02/2002 01:24:08
On Fri, 1 Mar 2002, Blaz Zupan wrote:

> Now it's time for me to give a status report. Had some trouble compiling the
> patched mopd, the problem was with the makefiles, I needed to use gmake and
> also had to fix the Makefiles to put -lelf last in the link line, otherwise it

 Hmm, using "@" and "^" variables in explicit rules is elegant but risky,
otherwise I can't see any problems -- any standard make should do.  Moving
"-lelf" last is probably a good thing to do.  Do the problems persist if
the following patch is applied? 

> wouldn't link on NetBSD/sparc (I worked without this on FreeBSD). When running
> on FreeBSD, mopd didn't work, which was apparently due to a very old #ifdef
> FreeBSD in put.c. On NetBSD, there was no package for libelf, so I had to

 I didn't touch system-specific code I couldn't test -- the conditional
clause looks weird indeed; it's probably a bug workaround.  Does it work
if you change "#if !defined(__FreeBSD__)" into "#if 1"?  It would be good
to know which version of FreeBSD the workaround is not needed from and how
to detect it in the preprocessor.

> compile it by myself, which didn't work out of the box. The following patch
> fixed the libelf compile on NetBSD:
[...]
> -for ac_hdr in unistd.h fcntl.h elf.h sys/elf.h link.h sys/link.h
> +for ac_hdr in unistd.h fcntl.h sys/elf.h link.h sys/link.h

 Weird -- is there anything wrong with <elf.h> on NetBSD?  Anyone could
comment?

 Anyway, the test should probably check for a trivial definition, like
Elf32_Word in <elf.h> and <sys/elf.h> to choose the right one. 

> -      *-linux*)
> +      *-linux*|*-netbsd*)

 This one looks obvious.

 Libelf is actively maintained, so it should be easy to get fixes in, but
I'd need to know what's wrong with <elf.h> and find a volunteer to test
patches.

> After finally struggling through the mopd compile (on NetBSD/sparc), it
> finally worked and I was able to MOP netboot a NetBSD ELF kernel.

 Excellent.

> Unfortunatelly it hung at exactly the same place as the diskboot. So I'm
> giving up on NetBSD.

 Do you mean it started at all?  If so, it's nice this patched mopd may be
useful for NetBSD as well.  Too bad the kernel hung on your system, but I
cannot help you with that, sorry -- someone else here probably could.

> Amazingly enough, the Linux kernel seems to boot fine and I'm working on a
> Linux installation right now. The only reason I was not able to try Linux
> before was, that I did not have a working mopd (remember, tftp does not work
> on my prom). Thanks Maciej!

 Well, I have the MOP-only KN03 V5.1b, too.  Otherwise I wouldn't probably
have had much enough incentive to do my mopd work.  My DEFZA is MOP-only,
as well, so chances are I'll get mopd working over FDDI one day as well... 
:-) 

 A patch follows.  All other patches as available at my site must be
applied before (or ones that modify Makefiles, actually). 

  Maciej

-- 
+  Maciej W. Rozycki, Technical University of Gdansk, Poland   +
+--------------------------------------------------------------+
+        e-mail: macro@ds2.pg.gda.pl, PGP key available        +

mopd-2.5.3-make.patch
diff -u --recursive --new-file mopd-2.5.3.macro/Makefile mopd-2.5.3/Makefile
--- mopd-2.5.3.macro/Makefile	Fri Mar  1 23:28:05 2002
+++ mopd-2.5.3/Makefile	Fri Mar  1 23:31:11 2002
@@ -4,6 +4,7 @@
 
 CFLAGS = -O2 -g
 LDFLAGS =
+LIBELF = -lelf
 
 SUBDIRS = common mopd mopchk mopprobe moptrace
 
@@ -11,6 +12,7 @@
 	@for dir in $(SUBDIRS); do \
 		(cd $$dir && \
 		 $(MAKE) "AR=$(AR)" "CC=$(CC)" "RANLIB=$(RANLIB)" \
-			 "CFLAGS=$(CFLAGS)" "LDFLAGS=$(LDFLAGS)" $@) || \
+			 "CFLAGS=$(CFLAGS)" "LDFLAGS=$(LDFLAGS)" \
+			 "LIBELF=$(LIBELF) $@) || \
 		 exit 1; \
 	done
diff -u --recursive --new-file mopd-2.5.3.macro/mopa.out/Makefile mopd-2.5.3/mopa.out/Makefile
--- mopd-2.5.3.macro/mopa.out/Makefile	Fri Mar  1 23:28:06 2002
+++ mopd-2.5.3/mopa.out/Makefile	Fri Mar  1 23:32:03 2002
@@ -7,7 +7,7 @@
 all: $(PROGS)
 
 mopa.out: $(OBJS) $(LIBS)
-	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^
+	$(CC) $(CFLAGS) $(LDFLAGS) -o mopa.out $(OBJS) $(LIBS)
 
 ../common/libcommon.a:
 	cd ../common && $(MAKE) libcommon.a
diff -u --recursive --new-file mopd-2.5.3.macro/mopchk/Makefile mopd-2.5.3/mopchk/Makefile
--- mopd-2.5.3.macro/mopchk/Makefile	Fri Mar  1 23:28:45 2002
+++ mopd-2.5.3/mopchk/Makefile	Fri Mar  1 23:33:43 2002
@@ -3,12 +3,12 @@
 LIBS = ../common/libcommon.a
 
 CPPFLAGS = -I..
-LDADD = -lelf
+LIBELF = -lelf
 
 all: $(PROGS)
 
 mopchk: $(OBJS) $(LIBS)
-	$(CC) $(CFLAGS) $(LDFLAGS) $(LDADD) -o $@ $^
+	$(CC) $(CFLAGS) $(LDFLAGS) -o mopchk $(OBJS) $(LIBS) $(LIBELF)
 
 ../common/libcommon.a:
 	cd ../common && $(MAKE) libcommon.a
diff -u --recursive --new-file mopd-2.5.3.macro/mopd/Makefile mopd-2.5.3/mopd/Makefile
--- mopd-2.5.3.macro/mopd/Makefile	Fri Mar  1 23:28:45 2002
+++ mopd-2.5.3/mopd/Makefile	Fri Mar  1 23:33:55 2002
@@ -8,7 +8,7 @@
 all: $(PROGS)
 
 mopd: $(OBJS) $(LIBS)
-	$(CC) $(CFLAGS) $(LDFLAGS) $(LDADD) -o $@ $^
+	$(CC) $(CFLAGS) $(LDFLAGS) $(LDADD) -o mopd $(OBJS) $(LIBS)
 
 ../common/libcommon.a:
 	cd ../common && $(MAKE) libcommon.a
diff -u --recursive --new-file mopd-2.5.3.macro/mopprobe/Makefile mopd-2.5.3/mopprobe/Makefile
--- mopd-2.5.3.macro/mopprobe/Makefile	Fri Mar  1 23:28:07 2002
+++ mopd-2.5.3/mopprobe/Makefile	Fri Mar  1 23:34:07 2002
@@ -7,7 +7,7 @@
 all: $(PROGS)
 
 mopprobe: $(OBJS) $(LIBS)
-	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^
+	$(CC) $(CFLAGS) $(LDFLAGS) -o mopprobe $(OBJS) $(LIBS)
 
 ../common/libcommon.a:
 	cd ../common && $(MAKE) libcommon.a
diff -u --recursive --new-file mopd-2.5.3.macro/moptrace/Makefile mopd-2.5.3/moptrace/Makefile
--- mopd-2.5.3.macro/moptrace/Makefile	Fri Mar  1 23:28:07 2002
+++ mopd-2.5.3/moptrace/Makefile	Fri Mar  1 23:34:20 2002
@@ -7,7 +7,7 @@
 all: $(PROGS)
 
 moptrace: $(OBJS) $(LIBS)
-	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^
+	$(CC) $(CFLAGS) $(LDFLAGS) -o moptrace $(OBJS) $(LIBS)
 
 ../common/libcommon.a:
 	cd ../common && $(MAKE) libcommon.a