wok rev 6713
linux/bootloader.sh: fix storelong()
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Thu Oct 14 13:05:38 2010 +0200 (2010-10-14) |
parents | 85369140d63a |
children | 3bff7f88b1c8 |
files | linux/stuff/bootloader.sh |
line diff
1.1 --- a/linux/stuff/bootloader.sh Thu Oct 14 03:23:01 2010 +0000 1.2 +++ b/linux/stuff/bootloader.sh Thu Oct 14 13:05:38 2010 +0200 1.3 @@ -10,10 +10,11 @@ 1.4 { 1.5 cat <<EOT 1.6 Usage: $0 bzImage [--prefix image_prefix] [--cmdline 'args'] 1.7 + [--rdev device] [--video mode] [--flags rootflags] 1.8 [--format 1440|1680|1720|2880 ] [--initrd initrdfile]... 1.9 1.10 Example: 1.11 -$0 /boot/vmlinuz-2.6.30.6 --cmdline 'rw lang=fr_FR kmap=fr-latin1 laptop autologin' --initrd /boot/rootfs.gz --initrd ./myconfig.gz 1.12 +$0 /boot/vmlinuz-2.6.30.6 --rdev /dev/ram0 --video -3 --cmdline 'rw lang=fr_FR kmap=fr-latin1 laptop autologin' --initrd /boot/rootfs.gz --initrd ./myconfig.gz 1.13 EOT 1.14 exit 1 1.15 } 1.16 @@ -21,27 +22,47 @@ 1.17 KERNEL="" 1.18 INITRD="" 1.19 CMDLINE="" 1.20 -PREFIX="floppy" 1.21 +PREFIX="floppy." 1.22 FORMAT="1440" 1.23 +RDEV="" 1.24 +VIDEO="" 1.25 +FLAGS="" 1.26 +DEBUG="" 1.27 while [ -n "$1" ]; do 1.28 case "$1" in 1.29 - --cmdline) CMDLINE="$2"; shift;; 1.30 - --initrd) INITRD="$INITRD $2"; shift;; 1.31 - --prefix) PREFIX="$2"; shift;; 1.32 - --format) FORMAT="$2"; shift;; 1.33 + --c*|-c*) CMDLINE="$2"; shift;; 1.34 + --i*|-i*) INITRD="$INITRD $2"; shift;; 1.35 + --p*|-p*) PREFIX="$2"; shift;; 1.36 + --fo*|-f*) FORMAT="$2"; shift;; 1.37 + --fl*) FLAGS="$2"; shift;; # 1 read-only, 0 read-write 1.38 + --r*|-r*) RDEV="$2"; shift;; # /dev/??? 1.39 + --v*|-v*) VIDEO="$2"; shift;; # -3 .. n 1.40 + --debug) DEBUG="1";; 1.41 *) KERNEL="$1";; 1.42 esac 1.43 shift 1.44 done 1.45 [ -n "$KERNEL" -a -f "$KERNEL" ] || usage 1.46 1.47 +# write a 16 bits data 1.48 +# usage: store16 offset data16 file 1.49 +store16() 1.50 +{ 1.51 + echo $2 | awk '{ printf "\\\\x%02X\\\\x%02X",$1%256,($1/256)%256 }' | \ 1.52 + xargs echo -en | \ 1.53 + dd bs=2 conv=notrunc of=$3 seek=$(( $1 / 2 )) 2> /dev/null 1.54 + [ -n "$DEBUG" ] && printf "store16(%04X) = %04X\n" $1 $2 1>&2 1.55 +} 1.56 + 1.57 # write a 32 bits data 1.58 # usage: storelong offset data32 file 1.59 storelong() 1.60 { 1.61 - echo $2 | awk '{ printf "%c%c%c%c",$1%256,($1/256)%256,($1/256/256)%256, 1.62 - ($1/256/256/256)%256 }' | \ 1.63 - dd bs=1 conv=notrunc of=$3 seek=$(( $1 )) 2> /dev/null 1.64 + echo $2 | awk '{ printf "\\\\x%02X\\\\x%02X\\\\x%02X\\\\x%02X", 1.65 + $1%256,($1/256)%256,($1/256/256)%256,($1/256/256/256)%256 }' | \ 1.66 + xargs echo -en | \ 1.67 + dd bs=4 conv=notrunc of=$3 seek=$(( $1 / 4 )) 2> /dev/null 1.68 + [ -n "$DEBUG" ] && printf "storelong(%04X) = %08X\n" $1 $2 1>&2 1.69 } 1.70 1.71 # read a 32 bits data 1.72 @@ -56,7 +77,10 @@ 1.73 { 1.74 # bzImage offsets 1.75 SetupSzOfs=497 1.76 + FlagsOfs=498 1.77 SyssizeOfs=500 1.78 + VideoModeOfs=506 1.79 + RootDevOfs=508 1.80 CodeAdrOfs=0x214 1.81 RamfsAdrOfs=0x218 1.82 RamfsLenOfs=0x21C 1.83 @@ -94,10 +118,26 @@ 1.84 setupszb=$(( $setupsz & 255 )) 1.85 dd if=$KERNEL bs=512 skip=1 count=$setupszb 2> /dev/null >> $bs 1.86 1.87 + if [ -n "$FLAGS" ]; then 1.88 + [ -n "$DEBUG" ] && echo -n "--flags " 1>&2 1.89 + store16 $FlagsOfs $(( $FLAGS )) $bs 1.90 + fi 1.91 + if [ -n "$VIDEO" ]; then 1.92 + [ -n "$DEBUG" ] && echo -n "--video " 1>&2 1.93 + store16 $VideoModeOfs $(( $VIDEO )) $bs 1.94 + fi 1.95 + if [ -n "$RDEV" ]; then 1.96 + [ -n "$DEBUG" ] && echo -n "--rdev " 1>&2 1.97 + n=$(stat -c '0x%02t%02T' $RDEV 2> /dev/null) 1.98 + [ -n "$n" ] || n=$RDEV 1.99 + store16 $RootDevOfs $(( $n )) $bs 1.100 + fi 1.101 + 1.102 # Store cmdline after setup 1.103 if [ -n "$CMDLINE" ]; then 1.104 + [ -n "$DEBUG" ] && echo -n "--cmdline '$CMDLINE' " 1>&2 1.105 echo -n "$CMDLINE" | dd bs=512 count=1 conv=sync 2> /dev/null >> $bs 1.106 - storelong ArgPtrOfs $(( $SetupBase + $stacktop )) $bs 1.107 + storelong $ArgPtrOfs $(( $SetupBase + $stacktop )) $bs 1.108 fi 1.109 1.110 # Compute initramfs size 1.111 @@ -105,6 +145,7 @@ 1.112 padding=0 1.113 for i in $( echo $INITRD | sed 's/,/ /' ); do 1.114 [ -s "$i" ] || continue 1.115 + [ -n "$DEBUG" ] && echo "--initrd $i " 1>&2 1.116 initrdlen=$(( $initrdlen + $padding )) 1.117 padding=$(stat -c %s $i) 1.118 initrdlen=$(( $initrdlen + $padding )) 1.119 @@ -114,6 +155,7 @@ 1.120 Ksize=$(( $(getlong $SyssizeOfs $bs)*16 )) 1.121 Kpad=$(( (($Ksize+4095)/4096)*4096 - Ksize )) 1.122 if [ $initrdlen -ne 0 ]; then 1.123 + [ -n "$DEBUG" ] && echo "initrdlen = $initrdlen " 1>&2 1.124 Kbase=$(getlong $CodeAdrOfs $bs) 1.125 storelong $RamfsAdrOfs \ 1.126 $(( (0x1000000 - $initrdlen) & 0xFFFF0000 )) $bs 1.127 @@ -134,10 +176,10 @@ 1.128 padding=0 1.129 for i in $( echo $INITRD | sed 's/,/ /' ); do 1.130 [ -s "$i" ] || continue 1.131 - [ $padding -ne 0 ] && dd if=/dev/zero bs=1 count=$padding 1.132 + [ $padding -ne 0 ] && dd if=/dev/zero bs=1 count=$padding 2> /dev/null 1.133 dd if=$i 2> /dev/null 1.134 - padding=$(( 4096 - ($(stat -c %s $i) & 4095) )) 1.135 - [ $padding -eq 4096 ] && padding=0 1.136 + padding=$(( 4 - ($(stat -c %s $i) & 3) )) 1.137 + [ $padding -eq 4 ] && padding=0 1.138 done 1.139 1.140 # Cleanup 1.141 @@ -147,7 +189,7 @@ 1.142 floppyset | split -b ${FORMAT}k /dev/stdin floppy$$ 1.143 i=1 1.144 ls floppy$$* | while read file ; do 1.145 - output=$PREFIX.$(printf "%03d" $i) 1.146 + output=$PREFIX$(printf "%03d" $i) 1.147 cat $file /dev/zero | dd bs=1k count=$FORMAT conv=sync of=$output 2> /dev/null 1.148 echo $output 1.149 rm -f $file