Subject: Cross-compiling bootblocks
To: None <port-hp300@netbsd.org>
From: Gregory McGarry <g.mcgarry@ieee.org>
List: port-hp300
Date: 05/13/2001 12:23:06
I have been bringing my local cross-compiling changes up to date
for an ELF kernel.  The problem is that loadfile(), isn't
endian independent so while mkboot under a.out would work, it
doesn't work on ELF.  elf2ecoff(1) also has this problem.

Although this issue isn't hp300 specific, any comments?

Here are the hp300-specific changes:

Index: Makefile
===================================================================
RCS file: /cvsroot/syssrc/sys/arch/hp300/stand/mkboot/Makefile,v
retrieving revision 1.5
diff -u -r1.5 Makefile
--- Makefile	2001/01/02 04:14:34	1.5
+++ Makefile	2001/05/13 00:06:09
@@ -2,13 +2,13 @@
 
 LIBSA=	${.CURDIR}/../../../../lib/libsa
 
-PROG=	mkboot
+HOSTPROG=	mkboot
 SRCS=	mkboot.c loadfile.c
 
 .PATH.c: ${LIBSA}
 
-CPPFLAGS+= -I${LIBSA} -I.
+HOST_CPPFLAGS+= -I${LIBSA} -I. -I${DESTDIR}/usr/include
 LDSTATIC?=-static
 MKMAN=	no
 
-.include <bsd.prog.mk>
+.include <bsd.hostprog.mk>
Index: mkboot.c
===================================================================
RCS file: /cvsroot/syssrc/sys/arch/hp300/stand/mkboot/mkboot.c,v
retrieving revision 1.2
diff -u -r1.2 mkboot.c
--- mkboot.c	2001/01/02 04:14:34	1.2
+++ mkboot.c	2001/05/13 00:06:09
@@ -150,44 +150,49 @@
 	}
 	/* clear possibly unused directory entries */
 	strncpy(lifd[1].dir_name, "	     ", 10);
-	lifd[1].dir_type = -1;
-	lifd[1].dir_addr = 0;
-	lifd[1].dir_length = 0;
-	lifd[1].dir_flag = 0xFF;
-	lifd[1].dir_exec = 0;
+	lifd[1].dir_type = htobe16(-1);
+	lifd[1].dir_addr = htobe32(0);
+	lifd[1].dir_length = htobe32(0);
+	lifd[1].dir_flag = htobe16(0xFF);
+	lifd[1].dir_exec = htobe32(0);
 	lifd[7] = lifd[6] = lifd[5] = lifd[4] = lifd[3] = lifd[2] = lifd[1];
 	/* record volume info */
-	lifv.vol_id = VOL_ID;
+	lifv.vol_id = htobe16(VOL_ID);
 	strncpy(lifv.vol_label, "BOOT43", 6);
-	lifv.vol_addr = btolifs(LIF_DIRSTART);
-	lifv.vol_oct = VOL_OCT;
-	lifv.vol_dirsize = btolifs(LIF_DIRSIZE);
-	lifv.vol_version = 1;
+	lifv.vol_addr = htobe32(btolifs(LIF_DIRSTART));
+	lifv.vol_oct = htobe16(VOL_OCT);
+	lifv.vol_dirsize = htobe32(btolifs(LIF_DIRSIZE));
+	lifv.vol_version = htobe16(1);
 	/* output bootfile one */
 	lseek(to, LIF_FILESTART, SEEK_SET);
 	putfile(n1, to);
 	n = btolifs(ld.count + sizeof(ld));
 	strcpy(lifd[0].dir_name, lifname(n1));
-	lifd[0].dir_type = DIR_TYPE;
-	lifd[0].dir_addr = btolifs(LIF_FILESTART);
-	lifd[0].dir_length = n;
+	lifd[0].dir_type = htobe16(DIR_TYPE);
+	lifd[0].dir_addr = htobe32(btolifs(LIF_FILESTART));
+	lifd[0].dir_length = htobe32(n);
 	bcddate(n1, lifd[0].dir_toc);
-	lifd[0].dir_flag = DIR_FLAG;
-	lifd[0].dir_exec = lpflag? loadpoint + entrypoint : entrypoint;
-	lifv.vol_length = lifd[0].dir_addr + lifd[0].dir_length;
+	lifd[0].dir_flag = htobe16(DIR_FLAG);
+	lifd[0].dir_exec =
+		htobe32(lpflag ?
+		loadpoint + be32toh(entrypoint) : be32toh(entrypoint));
+	lifv.vol_length = htobe32(lifd[0].dir_addr + lifd[0].dir_length);
 	/* if there is an optional second boot program, output it */
 	if (n2) {
 		lseek(to, LIF_FILESTART+lifstob(n), SEEK_SET);
 		putfile(n2, to);
 		n = btolifs(ld.count + sizeof(ld));
 		strcpy(lifd[1].dir_name, lifname(n2));
-		lifd[1].dir_type = DIR_TYPE;
-		lifd[1].dir_addr = lifv.vol_length;
-		lifd[1].dir_length = n;
+		lifd[1].dir_type = htobe16(DIR_TYPE);
+		lifd[1].dir_addr = htobe32(lifv.vol_length);
+		lifd[1].dir_length = htobe32(n);
 		bcddate(n2, lifd[1].dir_toc);
-		lifd[1].dir_flag = DIR_FLAG;
-		lifd[1].dir_exec = lpflag? loadpoint + entrypoint : entrypoint;
-		lifv.vol_length = lifd[1].dir_addr + lifd[1].dir_length;
+		lifd[1].dir_flag = htobe16(DIR_FLAG);
+		lifd[1].dir_exec =
+			htobe32(lpflag ?
+			loadpoint + be32toh(entrypoint) : be32toh(entrypoint));
+		lifv.vol_length =
+			htobe32(lifd[1].dir_addr + lifd[1].dir_length);
 	}
 	/* ditto for three */
 	if (n3) {
@@ -195,13 +200,16 @@
 		putfile(n3, to);
 		n = btolifs(ld.count + sizeof(ld));
 		strcpy(lifd[2].dir_name, lifname(n3));
-		lifd[2].dir_type = DIR_TYPE;
-		lifd[2].dir_addr = lifv.vol_length;
-		lifd[2].dir_length = n;
+		lifd[2].dir_type = htobe16(DIR_TYPE);
+		lifd[2].dir_addr = htobe32(lifv.vol_length);
+		lifd[2].dir_length = htobe32(n);
 		bcddate(n3, lifd[2].dir_toc);
-		lifd[2].dir_flag = DIR_FLAG;
-		lifd[2].dir_exec = lpflag? loadpoint + entrypoint : entrypoint;
-		lifv.vol_length = lifd[2].dir_addr + lifd[2].dir_length;
+		lifd[2].dir_flag = htobe16(DIR_FLAG);
+		lifd[2].dir_exec =
+			htobe32(lpflag ?
+			loadpoint + be32toh(entrypoint) : be32toh(entrypoint));
+		lifv.vol_length =
+			htobe32(lifd[2].dir_addr + lifd[2].dir_length);
 	}
 	/* output volume/directory header info */
 	lseek(to, LIF_VOLSTART, SEEK_SET);

	-- Gregory McGarry <g.mcgarry@ieee.org>