CVS commit: [uebayasi-xip] src/sys/arch/evbppc/compile

2010-11-06 Thread Masao Uebayashi
Module Name:src
Committed By:   uebayasi
Date:   Sat Nov  6 16:21:16 UTC 2010

Modified Files:
src/sys/arch/evbppc/compile [uebayasi-xip]: walnut-mkimg.sh

Log Message:
Typo.


To generate a diff of this commit:
cvs rdiff -u -r1.3.98.1 -r1.3.98.2 \
src/sys/arch/evbppc/compile/walnut-mkimg.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/evbppc/compile/walnut-mkimg.sh
diff -u src/sys/arch/evbppc/compile/walnut-mkimg.sh:1.3.98.1 src/sys/arch/evbppc/compile/walnut-mkimg.sh:1.3.98.2
--- src/sys/arch/evbppc/compile/walnut-mkimg.sh:1.3.98.1	Wed Aug 11 13:30:50 2010
+++ src/sys/arch/evbppc/compile/walnut-mkimg.sh	Sat Nov  6 16:21:15 2010
@@ -1,7 +1,7 @@
 #!/bin/sh
-# $NetBSD: walnut-mkimg.sh,v 1.3.98.1 2010/08/11 13:30:50 uebayasi Exp $
+# $NetBSD: walnut-mkimg.sh,v 1.3.98.2 2010/11/06 16:21:15 uebayasi Exp $
 
-# Convert a input to an tftp image loadable by the IBM PowerPC OpenBIOS.
+# Convert an input to a TFTP image loadable by the IBM PowerPC OpenBIOS.
 
 magic=5394511	# IBM OpenBIOS magic number 0x0052504f
 start=0



CVS commit: [uebayasi-xip] src/sys/arch/evbppc/compile

2010-08-11 Thread Masao Uebayashi
Module Name:src
Committed By:   uebayasi
Date:   Wed Aug 11 13:30:50 UTC 2010

Modified Files:
src/sys/arch/evbppc/compile [uebayasi-xip]: walnut-mkimg.sh

Log Message:
Support files other than kernel executables.

For filesystem images, embed (not prepend) OpenBIOS image headers to
the images, so that alignment is kept in the resulting files.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.3.98.1 src/sys/arch/evbppc/compile/walnut-mkimg.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/evbppc/compile/walnut-mkimg.sh
diff -u src/sys/arch/evbppc/compile/walnut-mkimg.sh:1.3 src/sys/arch/evbppc/compile/walnut-mkimg.sh:1.3.98.1
--- src/sys/arch/evbppc/compile/walnut-mkimg.sh:1.3	Sun Dec 11 12:17:11 2005
+++ src/sys/arch/evbppc/compile/walnut-mkimg.sh	Wed Aug 11 13:30:50 2010
@@ -1,36 +1,76 @@
 #!/bin/sh
-# $NetBSD: walnut-mkimg.sh,v 1.3 2005/12/11 12:17:11 christos Exp $
+# $NetBSD: walnut-mkimg.sh,v 1.3.98.1 2010/08/11 13:30:50 uebayasi Exp $
 
-# Convert a kernel to an tftp image loadable by the IBM PowerPC OpenBIOS.
+# Convert a input to an tftp image loadable by the IBM PowerPC OpenBIOS.
 
 magic=5394511	# IBM OpenBIOS magic number 0x0052504f
+start=0
+size=0
+overwrite=0
 
 if [ $# -ne 2 ] ; then
-	echo usage: $0 kernel image 12
+	echo usage: $0 input image 12
 	exit 1
 fi
 
-kernel=$1; shift
+input=$1; shift
 output=$1; shift
 
 : ${OBJDUMP=objdump}
 : ${OBJCOPY=objcopy}
 
-start=`${OBJDUMP} -f ${kernel} | awk '/start address/ { print $NF }'`
-start=`printf %d $start`
-${OBJCOPY} -O binary ${kernel} ${kernel}.bin.$$
-size=`/bin/ls -l ${kernel}.bin.$$ | awk '{ printf %d, ( $5 + 511 ) / 512 }'`
-
-printf %d\n%d\n%d\n0\n%d\n0\n0\n0\n $magic $start $size $start |
-awk '{
-		printf %c, int($0 / 256 / 256 / 256) % 256;
-		printf %c, int($0 / 256 / 256  ) % 256;
-		printf %c, int($0 / 256) % 256;
-		printf %c, int($0  ) % 256;
-	}
-'  ${output}
-
-cat ${kernel}.bin.$$  ${output}
+file=$( file $input )
+case $file in
+*:\ ELF\ *)
+	start=`${OBJDUMP} -f ${input} | awk '/start address/ { print $NF }'`
+	start=`printf %d $start`
+	${OBJCOPY} -O binary ${input} ${input}.bin.$$
+	;;
+*)
+	case $file in
+	*\ [Ff]ile\ [Ss]ystem*|*\ [Ff]ilesystem*)
+		overwrite=1
+		;;
+	esac
+	cp ${input} ${input}.bin.$$
+	;;
+esac
+
+size=`stat -f '%z' ${input}.bin.$$`
+size=$(( ( $size + 511 ) / 512 ))
+
+enc()
+{
+	local _x=$1; shift
+	printf $( printf '\\x%x' $_x )
+}
+
+be32enc()
+{
+	local _x=$1; shift
+	enc $(( ( $_x  24 )  0xff ))
+	enc $(( ( $_x  16 )  0xff ))
+	enc $(( ( $_x   8 )  0xff ))
+	enc $(( ( $_x   0 )  0xff ))
+}
+
+{
+	be32enc $magic
+	be32enc $start
+	be32enc $size
+	be32enc 0
+	be32enc $start
+	be32enc 0
+	be32enc 0
+	be32enc 0
+}  ${input}.hdr.$$
+
+if [ $overwrite = 0 ]; then
+	cat ${input}.hdr.$$ ${input}.bin.$$  ${output}
+else
+	cp ${input}.bin.$$ ${output}
+	dd if=${input}.hdr.$$ of=${output} conv=notrunc
+fi
 
-rm -f ${kernel}.bin.$$
+rm -f ${input}.hdr.$$ ${input}.bin.$$
 exit