3 # Copyright (C) 2006 Paul Mackerras, IBM Corporation <paulus@samba.org>
4 # This program may be used under the terms of version 2 of the GNU
5 # General Public License.
7 # This script takes a kernel binary and optionally an initrd image
8 # and/or a device-tree blob, and creates a bootable zImage for a
12 # -o zImage specify output file
13 # -p platform specify platform (links in $platform.o)
14 # -i initrd specify initrd file
15 # -d devtree specify device-tree blob
16 # -s tree.dts specify device-tree source file (needs dtc installed)
17 # -c cache $kernel.strip.gz (use if present & newer, else make)
18 # -C prefix specify command prefix for cross-building tools
19 # (strip, objcopy, ld)
20 # -D dir specify directory containing data files used by script
21 # (default ./arch/powerpc/boot)
22 # -W dir specify working directory for temporary files (default .)
24 # Allow for verbose output
40 # cross-compilation prefix
43 # directory for object and other files used by this script
44 object=arch/powerpc/boot
46 # directory for working files
50 echo 'Usage: wrapper [-o output] [-p platform] [-i initrd]' >&2
51 echo ' [-d devtree] [-s tree.dts] [-c] [-C cross-prefix]' >&2
52 echo ' [-D datadir] [-W workingdir] [--no-gzip] [vmlinux]' >&2
56 while [ "$#" -gt 0 ]; do
60 [ "$#" -gt 0 ] || usage
65 [ "$#" -gt 0 ] || usage
70 [ "$#" -gt 0 ] || usage
75 [ "$#" -gt 0 ] || usage
80 [ "$#" -gt 0 ] || usage
88 [ "$#" -gt 0 ] || usage
93 [ "$#" -gt 0 ] || usage
98 [ "$#" -gt 0 ] || usage
108 [ -z "$kernel" ] || usage
115 if [ -n "$dts" ]; then
116 if [ -z "$dtb" ]; then
119 dtc -O dtb -o "$dtb" -b 0 -V 16 "$dts" || exit 1
122 if [ -z "$kernel" ]; then
126 platformo=$object/"$platform".o
127 lds=$object/zImage.lds
130 tmp=$tmpdir/zImage.$$.o
131 ksection=.kernel:vmlinux.strip
132 isection=.kernel:initrd
136 platformo=$object/of.o
139 platformo=$object/of.o
140 lds=$object/zImage.coff.lds
143 # miboot and U-boot want just the bare bits, not an ELF binary
155 platformo="$object/ps3-head.o $object/ps3-hvcall.o $object/ps3.o"
156 lds=$object/zImage.ps3.lds
160 objflags="-O binary --set-section-flags=.bss=contents,alloc,load,data"
161 ksection=.kernel:vmlinux.bin
162 isection=.kernel:initrd
165 platformo="$object/fixed-head.o $object/$platform.o"
170 vmz="$tmpdir/`basename \"$kernel\"`.$ext"
171 if [ -z "$cacheit" -o ! -f "$vmz$gzip" -o "$vmz$gzip" -ot "$kernel" ]; then
172 ${CROSS}objcopy $objflags "$kernel" "$vmz.$$"
174 if [ -n "$gzip" ]; then
178 if [ -n "$cacheit" ]; then
179 mv -f "$vmz.$$$gzip" "$vmz$gzip"
187 # Extract kernel version information, some platforms want to include
188 # it in the image header
189 version=`${CROSS}strings "$kernel" | grep '^Linux version [-0-9.]' | \
191 if [ -n "$version" ]; then
192 uboot_version="-n Linux-$version"
198 mkimage -A ppc -O linux -T kernel -C gzip -a 00000000 -e 00000000 \
199 $uboot_version -d "$vmz" "$ofile"
200 if [ -z "$cacheit" ]; then
208 ${CROSS}objcopy $4 $1 \
209 --add-section=$3="$2" \
210 --set-section-flags=$3=contents,alloc,load,readonly,data
213 addsec $tmp "$vmz" $ksection $object/empty.o
214 if [ -z "$cacheit" ]; then
218 if [ -n "$initrd" ]; then
219 addsec $tmp "$initrd" $isection
222 if [ -n "$dtb" ]; then
223 addsec $tmp "$dtb" .kernel:dtb
224 if [ -n "$dts" ]; then
229 if [ "$platform" != "miboot" ]; then
230 ${CROSS}ld -m elf32ppc -T $lds -o "$ofile" \
231 $platformo $tmp $object/wrapper.a
235 # Some platforms need the zImage's entry point and base address
236 base=0x`${CROSS}nm "$ofile" | grep ' _start$' | cut -d' ' -f1`
237 entry=`${CROSS}objdump -f "$ofile" | grep '^start address ' | cut -d' ' -f3`
239 if [ -n "$binary" ]; then
240 mv "$ofile" "$ofile".elf
241 ${CROSS}objcopy -O binary "$ofile".elf "$ofile".bin
244 # post-processing needed for some platforms
247 $object/addnote "$ofile"
250 ${CROSS}objcopy -O aixcoff-rs6000 --set-start "$entry" "$ofile"
251 $object/hack-coff "$ofile"
254 gzip -f -9 "$ofile".bin
255 mkimage -A ppc -O linux -T kernel -C gzip -a "$base" -e "$entry" \
256 $uboot_version -d "$ofile".bin.gz "$ofile"
259 mv "$ofile" "$ofile.elf"
260 $object/mktree "$ofile.elf" "$ofile" "$base" "$entry"
261 if [ -z "$cacheit" ]; then
267 # The ps3's loader supports loading gzipped binary images from flash
268 # rom to addr zero. The loader enters the image at addr 0x100. A
269 # bootwrapper overlay is use to arrange for the kernel to be loaded
270 # to addr zero and to have a suitable bootwrapper entry at 0x100.
271 # To construct the rom image, 0x100 bytes from offset 0x100 in the
272 # kernel is copied to the bootwrapper symbol __system_reset_kernel.
273 # The 0x100 bytes at the bootwrapper symbol __system_reset_overlay is
274 # then copied to offset 0x100. At runtime the bootwrapper program
275 # copies the 0x100 bytes at __system_reset_kernel to addr 0x100.
277 system_reset_overlay=0x`${CROSS}nm "$ofile".elf \
278 | grep ' __system_reset_overlay$' \
280 system_reset_overlay=`printf "%d" $system_reset_overlay`
281 system_reset_kernel=0x`${CROSS}nm "$ofile".elf \
282 | grep ' __system_reset_kernel$' \
284 system_reset_kernel=`printf "%d" $system_reset_kernel`
288 rm -f "$object/otheros.bld"
290 msg=$(dd if="$ofile.bin" of="$ofile.bin" conv=notrunc \
291 skip=$overlay_dest seek=$system_reset_kernel \
292 count=$overlay_size bs=1 2>&1)
294 if [ $? -ne "0" ]; then
299 msg=$(dd if="$ofile.bin" of="$ofile.bin" conv=notrunc \
300 skip=$system_reset_overlay seek=$overlay_dest \
301 count=$overlay_size bs=1 2>&1)
303 if [ $? -ne "0" ]; then
308 gzip --force -9 --stdout "$ofile.bin" > "$object/otheros.bld"