wok diff linux-libre/stuff/bootloader.sh @ rev 18778
syslinux/iso2exe/init: fix 'Show flavor infos'
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Fri Jan 01 16:02:21 2016 +0100 (2016-01-01) |
parents | abe27fd0192d |
children |
line diff
1.1 --- a/linux-libre/stuff/bootloader.sh Tue Mar 15 03:23:44 2011 +0100 1.2 +++ b/linux-libre/stuff/bootloader.sh Fri Jan 01 16:02:21 2016 +0100 1.3 @@ -15,90 +15,60 @@ 1.4 1.5 Default values: --format 1440 --tracks 80 --prefix floppy. 1.6 1.7 +Or: cat fd0*.img | $0 --extract 1.8 + 1.9 +Create the kernel, cmdline and rootfs files from a floppy set 1.10 + 1.11 Example: 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 +$0 /boot/vmlinuz-2.6.30.6 --rdev /dev/ram0 --video -3 \ 1.14 +--cmdline 'rw lang=fr_FR kmap=fr-latin1 laptop autologin' \ 1.15 +--initrd /boot/rootfs.gz --initrd ./myconfig.gz 1.16 EOT 1.17 exit 1 1.18 } 1.19 1.20 -KERNEL="" 1.21 -INITRD="" 1.22 -CMDLINE="" 1.23 -PREFIX="floppy." 1.24 -FORMAT="1440" 1.25 -RDEV="" 1.26 -VIDEO="" 1.27 -FLAGS="" 1.28 -TRACKS="" 1.29 -DEBUG="" 1.30 -while [ -n "$1" ]; do 1.31 - case "$1" in 1.32 - --c*|-c*) CMDLINE="$2"; shift;; 1.33 - --i*|-i*) INITRD="$INITRD $2"; shift;; 1.34 - --p*|-p*) PREFIX="$2"; shift;; 1.35 - --fo*|-f*) FORMAT="$2"; shift;; 1.36 - --fl*) FLAGS="$2"; shift;; # 1 read-only, 0 read-write 1.37 - --r*|-r*) RDEV="$2"; shift;; # /dev/??? 1.38 - --v*|-v*) VIDEO="$2"; shift;; # -3 .. n 1.39 - --t*|-t*) TRACKS="$2"; shift;; # likely 81 .. 84 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 -if [ -n "$TRACKS" ]; then 1.47 - if [ $(( $FORMAT % $TRACKS )) -ne 0 ]; then 1.48 - echo "Invalid track count for format $FORMAT." 1.49 - usage 1.50 - fi 1.51 -fi 1.52 +ddq() 1.53 +{ 1.54 + dd $@ 2> /dev/null 1.55 +} 1.56 1.57 -# write a 16 bits data 1.58 -# usage: store16 offset data16 file 1.59 -store16() 1.60 +dbg() 1.61 { 1.62 - n=$2; i=2; while [ $i -ne 0 ]; do 1.63 - printf '\\\\x%02X' $(($n & 255)) 1.64 - i=$(($i-1)); n=$(($n >> 8)) 1.65 - done | xargs echo -en | \ 1.66 - dd bs=2 conv=notrunc of=$3 seek=$(( $1 / 2 )) 2> /dev/null 1.67 - [ -n "$DEBUG" ] && printf "store16(%04X) = %04X\n" $1 $2 1>&2 1.68 + [ -n "$DEBUG" ] && echo "$@" 1>&2 1.69 } 1.70 1.71 # write a 32 bits data 1.72 -# usage: storelong offset data32 file 1.73 -storelong() 1.74 +# usage: put offset data32 file [bytes] 1.75 +put() 1.76 { 1.77 - n=$2; i=4; while [ $i -ne 0 ]; do 1.78 + n=$2; for i in $(seq 1 ${4:-4}); do 1.79 printf '\\\\x%02X' $(($n & 255)) 1.80 - i=$(($i-1)); n=$(($n >> 8)) 1.81 - done | xargs echo -en | \ 1.82 - dd bs=4 conv=notrunc of=$3 seek=$(( $1 / 4 )) 2> /dev/null 1.83 - [ -n "$DEBUG" ] && printf "storelong(%04X) = %08X\n" $1 $2 1>&2 1.84 + n=$(($n >> 8)) 1.85 + done | xargs echo -en | ddq bs=1 conv=notrunc of=$3 seek=$1 1.86 + [ -n "$DEBUG" ] && printf "put$4(%04X) = %X\n" $1 $2 1>&2 1.87 } 1.88 1.89 # read a 32 bits data 1.90 -# usage: getlong offset file 1.91 -getlong() 1.92 +# usage: get offset file [bytes] 1.93 +get() 1.94 { 1.95 - dd if=$2 bs=1 skip=$(( $1 )) count=4 2> /dev/null | \ 1.96 - hexdump -e '"" 1/4 "%d" "\n"' 1.97 + ddq if=$2 bs=1 skip=$(($1)) count=${3:-4} | hexdump -e '"" 1/4 "%d"' 1.98 } 1.99 1.100 +SetupSzOfs=0x1F1 1.101 +SyssizeOfs=0x1F4 1.102 +RamfsLenOfs=0x21C 1.103 +ArgPtrOfs=0x228 1.104 + 1.105 floppyset() 1.106 { 1.107 # bzImage offsets 1.108 - CylinderCount=496 1.109 - SetupSzOfs=497 1.110 - FlagsOfs=498 1.111 - SyssizeOfs=500 1.112 - VideoModeOfs=506 1.113 - RootDevOfs=508 1.114 + CylinderCount=0x1F0 1.115 + FlagsOfs=0x1F2 1.116 + VideoModeOfs=0x1FA 1.117 + RootDevOfs=0x1FC 1.118 CodeAdrOfs=0x214 1.119 RamfsAdrOfs=0x218 1.120 - RamfsLenOfs=0x21C 1.121 - ArgPtrOfs=0x228 1.122 1.123 # boot+setup address 1.124 SetupBase=0x90000 1.125 @@ -109,8 +79,8 @@ 1.126 1.127 # Get and patch boot sector 1.128 # See http://hg.slitaz.org/wok/raw-file/711d076b277c/linux/stuff/linux-header-2.6.34.u 1.129 - dd if=$KERNEL bs=512 count=1 of=$bs 2> /dev/null 1.130 - uudecode <<EOT | dd of=$bs conv=notrunc 2> /dev/null 1.131 + ddq if=$KERNEL bs=512 count=1 of=$bs 1.132 + uudecode <<EOT | ddq of=$bs conv=notrunc 1.133 begin-base64 644 - 1.134 /L+6nWgAkAcGF4n8McC5HQDzq1sfD6mg8X1ABlfFd3ixBvOlZWaPR3gGH8ZF 1.135 +D/6l1hB6DQBvgACA3QO6HYBWwseKAJ0LFNH6AoBXuhmAbAgzRCwCM0QTuhl 1.136 @@ -128,35 +98,33 @@ 1.137 EOT 1.138 1.139 # Get setup 1.140 - setupsz=$(getlong $SetupSzOfs $bs) 1.141 - setupszb=$(( $setupsz & 255 )) 1.142 - dd if=$KERNEL bs=512 skip=1 count=$setupszb 2> /dev/null >> $bs 1.143 + setupsz=$(get $SetupSzOfs $bs 1) 1.144 + ddq if=$KERNEL bs=512 skip=1 count=$setupsz >> $bs 1.145 1.146 if [ -n "$TRACKS" ]; then 1.147 - [ -n "$DEBUG" ] && echo -n "--tracks " 1>&2 1.148 - n=$(getlong $CylinderCount $bs) 1.149 - store16 $CylinderCount $(( ($n & -256) + $TRACKS )) $bs 1.150 + dbg -n "--tracks " 1.151 + put $CylinderCount $TRACKS $bs 1 1.152 fi 1.153 if [ -n "$FLAGS" ]; then 1.154 - [ -n "$DEBUG" ] && echo -n "--flags " 1>&2 1.155 - store16 $FlagsOfs $FLAGS $bs 1.156 + dbg -n "--flags " 1.157 + put $FlagsOfs $FLAGS $bs 2 1.158 fi 1.159 if [ -n "$VIDEO" ]; then 1.160 - [ -n "$DEBUG" ] && echo -n "--video " 1>&2 1.161 - store16 $VideoModeOfs $VIDEO $bs 1.162 + dbg -n "--video " 1.163 + put $VideoModeOfs $VIDEO $bs 2 1.164 fi 1.165 if [ -n "$RDEV" ]; then 1.166 - [ -n "$DEBUG" ] && echo -n "--rdev " 1>&2 1.167 + dbg -n "--rdev " 1.168 n=$(stat -c '0x%02t%02T' $RDEV 2> /dev/null) 1.169 [ -n "$n" ] || n=$RDEV 1.170 - store16 $RootDevOfs $n $bs 1.171 + put $RootDevOfs $n $bs 2 1.172 fi 1.173 1.174 # Store cmdline after setup 1.175 if [ -n "$CMDLINE" ]; then 1.176 - [ -n "$DEBUG" ] && echo -n "--cmdline '$CMDLINE' " 1>&2 1.177 - echo -n "$CMDLINE" | dd bs=512 count=1 conv=sync 2> /dev/null >> $bs 1.178 - storelong $ArgPtrOfs $(( $SetupBase + $stacktop )) $bs 1.179 + dbg -n "--cmdline '$CMDLINE' " 1.180 + echo -n "$CMDLINE" | ddq bs=512 count=1 conv=sync >> $bs 1.181 + put $ArgPtrOfs $(( $SetupBase + $stacktop )) $bs 1.182 fi 1.183 1.184 # Compute initramfs size 1.185 @@ -164,39 +132,39 @@ 1.186 padding=0 1.187 for i in $( echo $INITRD | sed 's/,/ /' ); do 1.188 [ -s "$i" ] || continue 1.189 - [ -n "$DEBUG" ] && echo "--initrd $i " 1>&2 1.190 + dbg "--initrd $i " 1.191 initrdlen=$(( $initrdlen + $padding )) 1.192 padding=$(stat -c %s $i) 1.193 initrdlen=$(( $initrdlen + $padding )) 1.194 padding=$(( 4096 - ($padding & 4095) )) 1.195 [ $padding -eq 4096 ] && padding=0 1.196 done 1.197 - Ksize=$(( $(getlong $SyssizeOfs $bs)*16 )) 1.198 + Ksize=$(( $(get $SyssizeOfs $bs)*16 )) 1.199 Kpad=$(( (($Ksize+4095)/4096)*4096 - Ksize )) 1.200 if [ $initrdlen -ne 0 ]; then 1.201 - [ -n "$DEBUG" ] && echo "initrdlen = $initrdlen " 1>&2 1.202 - Kbase=$(getlong $CodeAdrOfs $bs) 1.203 - storelong $RamfsAdrOfs \ 1.204 + dbg "initrdlen = $initrdlen " 1.205 + Kbase=$(get $CodeAdrOfs $bs) 1.206 + put $RamfsAdrOfs \ 1.207 $(( (0x1000000 - $initrdlen) & 0xFFFF0000 )) $bs 1.208 - storelong $RamfsLenOfs $(( ($initrdlen + 3) & -4 )) $bs 1.209 + put $RamfsLenOfs $(( ($initrdlen + 3) & -4 )) $bs 1.210 fi 1.211 1.212 # Output boot sector + setup + cmdline 1.213 - dd if=$bs 2> /dev/null 1.214 + ddq if=$bs 1.215 1.216 # Output kernel code 1.217 - dd if=$KERNEL bs=512 skip=$(( $setupszb + 1 )) 2> /dev/null 1.218 + ddq if=$KERNEL bs=512 skip=$(( $setupsz + 1 )) 1.219 1.220 # Pad to next sector 1.221 Kpad=$(( 512 - ($(stat -c %s $KERNEL) & 511) )) 1.222 - [ $Kpad -eq 512 ] || dd if=/dev/zero bs=1 count=$Kpad 2> /dev/null 1.223 + [ $Kpad -eq 512 ] || ddq if=/dev/zero bs=1 count=$Kpad 1.224 1.225 # Output initramfs 1.226 padding=0 1.227 for i in $( echo $INITRD | sed 's/,/ /' ); do 1.228 [ -s "$i" ] || continue 1.229 - [ $padding -ne 0 ] && dd if=/dev/zero bs=1 count=$padding 2> /dev/null 1.230 - dd if=$i 2> /dev/null 1.231 + [ $padding -ne 0 ] && ddq if=/dev/zero bs=1 count=$padding 1.232 + ddq if=$i 1.233 padding=$(( 4 - ($(stat -c %s $i) & 3) )) 1.234 [ $padding -eq 4 ] && padding=0 1.235 done 1.236 @@ -205,6 +173,47 @@ 1.237 rm -f $bs 1.238 } 1.239 1.240 +KERNEL="" 1.241 +INITRD="" 1.242 +CMDLINE="" 1.243 +PREFIX="floppy." 1.244 +FORMAT="1440" 1.245 +RDEV="" 1.246 +VIDEO="" 1.247 +FLAGS="" 1.248 +TRACKS="" 1.249 +DEBUG="" 1.250 +while [ -n "$1" ]; do 1.251 + case "${1/--/-}" in 1.252 + -c*) CMDLINE="$2"; shift;; 1.253 + -i*) INITRD="$INITRD $2"; shift;; 1.254 + -p*) PREFIX="$2"; shift;; 1.255 + -fl*) FLAGS="$2"; shift;; # 1 read-only, 0 read-write 1.256 + -f*) FORMAT="$2"; shift;; 1.257 + -r*) RDEV="$2"; shift;; # /dev/??? 1.258 + -v*) VIDEO="$2"; shift;; # -3 .. n 1.259 + -t*) TRACKS="$2"; shift;; # likely 81 .. 84 1.260 + -d*) DEBUG="1";; 1.261 + -e*) ddq bs=512 count=2 > kernel 1.262 + setupsz=$(get $SetupSzOfs kernel 1) 1.263 + ddq bs=512 count=$(($setupsz - 1)) >> kernel 1.264 + [ $(get $ArgPtrOfs kernel) -ne 0 ] && 1.265 + ddq bs=512 count=1 | strings > cmdline 1.266 + syssz=$(get $SyssizeOfs kernel) 1.267 + ddq bs=512 count=$(( ($syssz + 31) / 32 )) >> kernel 1.268 + ddq bs=16 seek=$(($syssz + 32 + $setupsz*32)) count=0 of=kernel 1.269 + ramsz=$(get $RamfsLenOfs kernel) 1.270 + ddq bs=512 count=$((($ramsz + 511) / 512)) of=rootfs 1.271 + ddq bs=1 seek=$ramsz count=0 of=rootfs 1.272 + exit ;; 1.273 + *) KERNEL="$1";; 1.274 + esac 1.275 + shift 1.276 +done 1.277 +[ -n "$KERNEL" -a -f "$KERNEL" ] || usage 1.278 +[ -n "$TRACKS" ] && [ $(( $FORMAT % $TRACKS )) -ne 0 ] && 1.279 + echo "Invalid track count for format $FORMAT." && usage 1.280 + 1.281 if [ "$FORMAT" == "0" ]; then # unsplitted 1.282 floppyset > $PREFIX 1.283 exit 1.284 @@ -213,7 +222,7 @@ 1.285 i=1 1.286 ls floppy$$* | while read file ; do 1.287 output=$PREFIX$(printf "%03d" $i) 1.288 - cat $file /dev/zero | dd bs=1k count=$FORMAT conv=sync of=$output 2> /dev/null 1.289 + cat $file /dev/zero | ddq bs=1k count=$FORMAT conv=sync of=$output 1.290 echo $output 1.291 rm -f $file 1.292 i=$(( $i + 1 ))