wok-4.x view linux/stuff/bootloader.sh @ rev 4506
linux/boot: fix cmdline tail
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Mon Nov 23 11:01:54 2009 +0100 (2009-11-23) |
parents | aa65a927a2f3 |
children | b1b311195e79 |
line source
1 #!/bin/sh
2 #
3 # This script creates a floppy image set from a linux bzImage and can merge
4 # a cmdline and/or one or more initramfs.
5 # The total size can not exceed 15M because INT 15H function 87H limitations.
6 #
7 # (C) 2009 Pascal Bellard - GNU General Public License v3.
9 usage()
10 {
11 cat <<EOT
12 Usage: $0 bzImage [--prefix image_prefix] [--cmdline 'args']
13 [--format 1440|1680|1720|2880 ] [--initrd initrdfile]...
15 Example:
16 $0 /boot/vmlinuz-2.6.30.6 --cmdline 'rw lang=fr_FR kmap=fr-latin1 laptop autologin' --initrd /boot/rootfs.gz --initrd ./myconfig.gz
17 EOT
18 exit 1
19 }
21 KERNEL=""
22 INITRD=""
23 CMDLINE=""
24 PREFIX="floppy"
25 FORMAT="1440"
26 while [ -n "$1" ]; do
27 case "$1" in
28 --cmdline) CMDLINE="$2"; shift;;
29 --initrd) INITRD="$INITRD $2"; shift;;
30 --prefix) PREFIX="$2"; shift;;
31 --format) FORMAT="$2"; shift;;
32 *) KERNEL="$1";;
33 esac
34 shift
35 done
36 [ -n "$KERNEL" -a -f "$KERNEL" ] || usage
38 # write a 32 bits data
39 # usage: storelong offset data32 file
40 storelong()
41 {
42 printf "00000 %02X %02X %02X %02X \n" \
43 $(( $2 & 255 )) $(( ($2>>8) & 255 )) \
44 $(( ($2>>16) & 255 )) $(( ($2>>24) & 255 )) | \
45 hexdump -R | dd bs=1 conv=notrunc of=$3 seek=$(( $1 )) 2> /dev/null
46 }
48 # read a 32 bits data
49 # usage: getlong offset file
50 getlong()
51 {
52 dd if=$2 bs=1 skip=$(( $1 )) count=4 2> /dev/null | \
53 hexdump -e '"" 1/4 "%d" "\n"'
54 }
56 floppyset()
57 {
58 # bzImage offsets
59 SetupSzOfs=497
60 SyssizeOfs=500
61 CodeAdrOfs=0x214
62 RamfsAdrOfs=0x218
63 RamfsLenOfs=0x21C
64 ArgPtrOfs=0x228
66 # boot+setup address
67 SetupBase=0x90000
69 stacktop=0x9E00
71 bs=/tmp/bs$$
73 # Get and patch boot sector
74 dd if=$KERNEL bs=512 count=1 of=$bs 2> /dev/null
75 uudecode <<EOT | dd of=$bs conv=notrunc 2> /dev/null
76 begin-base64 644 -
77 v/Sd/GgAkAcxyQYXify7eACO2cU3sQbzpY7ZiSeMRwKg8X2YQAYfxkX4P/qX
78 mEEx2+hAAb4AAoBMEYDHRCQAnAN0DuhmAb4oAjkcci9HixxW6EIBX4s16FIB
79 sCDNELAIzRBOmM0WPAh0BJiJBK07NXTx6CsBPAp14Yh8/rkYAGoA4vyJ5rAP
80 v/QB/k0csQW0k4lEHLABiUQUmYlUEIlUGGYx20PT40tmAx1m0+toABAHv4AA
81 KfuccwIB31NWMdvo1ABeuQCAtIf+RBzNFVudd9yhGgJIvxwCsQk4RBxysDHA
82 zRPqAAAgkLBGKMi+twHovABd6yOA+RNyBDjBd2iA/gJyBDjmd2mA/VBzc2AG
83 UlFTlrQCULkGAFGxBMHFBLAPIegEkCcUQCfodQDi7rAgzRBZ4rSYzRNhMfat
84 ka2SrVAoyHcCsAGYOfhyAon4UFK0As0TWpVeWHKcKfcB8cHmCQHzOMF1JojI
85 /saxATjmdRyI9P7FtgA8E3USgP1Qcg21AGC+ugHoJACYzRZhowQAUlFmjwYA
86 AAn/dZ4WB7AxLAO0DrsHAM0QPA1088OwDejv/6wIwHX4w1g6AEluc2VydCBu
87 ZXh0IGZsb3BweSBhbmQgcHJlc3MgYW55IGtleSB0byBjb250aW51ZS4HDQA=
88 ====
89 EOT
91 # Get setup
92 setupsz=$(getlong $SetupSzOfs $bs)
93 setupszb=$(( $setupsz & 255 ))
94 dd if=$KERNEL bs=512 skip=1 count=$setupszb 2> /dev/null >> $bs
96 # Store cmdline after setup
97 if [ -n "$CMDLINE" ]; then
98 echo -n "$CMDLINE" | dd bs=512 count=1 conv=sync 2> /dev/null >> $bs
99 storelong ArgPtrOfs $(( $SetupBase + $stacktop )) $bs
100 fi
102 # Compute initramfs size
103 initrdlen=0
104 padding=0
105 for i in $( echo $INITRD | sed 's/,/ /' ); do
106 [ -s "$i" ] || continue
107 initrdlen=$(( $initrdlen + $padding ))
108 padding=$(stat -c %s $i)
109 initrdlen=$(( $initrdlen + $padding ))
110 padding=$(( 4096 - ($padding & 4095) ))
111 [ $padding -eq 4096 ] && padding=0
112 done
113 Ksize=$(( $(getlong $SyssizeOfs $bs)*16 ))
114 Kpad=$(( (($Ksize+4095)/4096)*4096 - Ksize ))
115 if [ $initrdlen -ne 0 ]; then
116 Kbase=$(getlong $CodeAdrOfs $bs)
117 storelong $RamfsAdrOfs \
118 $(( (0x1000000 - $initrdlen) & 0xFFFF0000 )) $bs
119 storelong $RamfsLenOfs $initrdlen $bs
120 fi
122 # Output boot sector + setup + cmdline
123 dd if=$bs 2> /dev/null
125 # Output kernel code
126 dd if=$KERNEL bs=512 skip=$(( $setupszb + 1 )) 2> /dev/null
128 # Pad to next sector
129 Kpad=$(( 512 - ($(stat -c %s $KERNEL) & 511) ))
130 [ $Kpad -eq 512 ] || dd if=/dev/zero bs=1 count=$Kpad 2> /dev/null
132 # Output initramfs
133 padding=0
134 for i in $( echo $INITRD | sed 's/,/ /' ); do
135 [ -s "$i" ] || continue
136 [ $padding -ne 0 ] && dd if=/dev/zero bs=1 count=$padding
137 dd if=$i 2> /dev/null
138 padding=$(( 4096 - ($(stat -c %s $i) & 4095) ))
139 [ $padding -eq 4096 ] && padding=0
140 done
142 # Cleanup
143 rm -f $bs
144 }
146 floppyset | split -b ${FORMAT}k /dev/stdin floppy$$
147 i=1
148 ls floppy$$* | while read file ; do
149 output=$PREFIX.$(printf "%03d" $i)
150 cat $file /dev/zero | dd bs=1k count=$FORMAT conv=sync of=$output 2> /dev/null
151 echo $output
152 rm -f $file
153 i=$(( $i + 1 ))
154 done