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 # Stop execution if any command fails
27 # Allow for verbose output
43 # cross-compilation prefix
46 # mkimage wrapper script
47 MKIMAGE=$srctree/scripts/mkuboot.sh
49 # directory for object and other files used by this script
50 object=arch/powerpc/boot
54 # directory for working files
58 echo 'Usage: wrapper [-o output] [-p platform] [-i initrd]' >&2
59 echo ' [-d devtree] [-s tree.dts] [-c] [-C cross-prefix]' >&2
60 echo ' [-D datadir] [-W workingdir] [--no-gzip] [vmlinux]' >&2
64 while [ "$#" -gt 0 ]; do
68 [ "$#" -gt 0 ] || usage
73 [ "$#" -gt 0 ] || usage
78 [ "$#" -gt 0 ] || usage
83 [ "$#" -gt 0 ] || usage
88 [ "$#" -gt 0 ] || usage
96 [ "$#" -gt 0 ] || usage
101 [ "$#" -gt 0 ] || usage
107 [ "$#" -gt 0 ] || usage
117 [ -z "$kernel" ] || usage
124 if [ -n "$dts" ]; then
125 if [ ! -r "$dts" -a -r "$object/dts/$dts" ]; then
126 dts="$object/dts/$dts"
128 if [ -z "$dtb" ]; then
131 $dtc -O dtb -o "$dtb" -b 0 "$dts"
134 if [ -z "$kernel" ]; then
138 platformo=$object/"$platform".o
139 lds=$object/zImage.lds
142 tmp=$tmpdir/zImage.$$.o
143 ksection=.kernel:vmlinux.strip
144 isection=.kernel:initrd
145 link_address='0x400000'
149 platformo=$object/of.o
150 link_address='0x4000000'
153 platformo=$object/of.o
154 link_address='0x400000'
157 platformo=$object/of.o
160 platformo=$object/of.o
161 lds=$object/zImage.coff.lds
162 link_address='0x500000'
165 # miboot and U-boot want just the bare bits, not an ELF binary
176 *-mpc866ads|*-mpc885ads|*-adder875*|*-ep88xc)
177 platformo=$object/cuboot-8xx.o
180 platformo=$object/cuboot-52xx.o
182 *-pq2fads|*-ep8248e|*-mpc8272*|*-storcenter)
183 platformo=$object/cuboot-pq2.o
186 platformo=$object/cuboot-824x.o
189 platformo=$object/cuboot-83xx.o
191 *-tqm8541|*-mpc8560*|*-tqm8560|*-tqm8555|*-ksi8560*)
192 platformo=$object/cuboot-85xx-cpm2.o
194 *-mpc85*|*-tqm85*|*-sbc85*)
195 platformo=$object/cuboot-85xx.o
198 link_address='0x800000'
203 platformo="$object/ps3-head.o $object/ps3-hvcall.o $object/ps3.o"
204 lds=$object/zImage.ps3.lds
207 objflags="-O binary --set-section-flags=.bss=contents,alloc,load,data"
208 ksection=.kernel:vmlinux.bin
209 isection=.kernel:initrd
212 ep88xc|ep405|ep8248e)
213 platformo="$object/fixed-head.o $object/$platform.o"
217 platformo="$object/fixed-head.o $object/redboot-8xx.o"
220 simpleboot-virtex405-*)
221 platformo="$object/virtex405-head.o $object/simpleboot.o $object/virtex.o"
224 simpleboot-virtex440-*)
225 platformo="$object/fixed-head.o $object/simpleboot.o $object/virtex.o"
229 platformo="$object/fixed-head.o $object/simpleboot.o"
233 platformo="$object/fixed-head.o $object/redboot-83xx.o"
237 link_address='0x1400000'
238 platformo=$object/cuboot-85xx.o
241 link_address='0x600000'
242 platformo="$object/$platform-head.o $object/$platform.o"
244 treeboot-iss4xx-mpic)
245 platformo="$object/treeboot-iss4xx.o"
249 vmz="$tmpdir/`basename \"$kernel\"`.$ext"
250 if [ -z "$cacheit" -o ! -f "$vmz$gzip" -o "$vmz$gzip" -ot "$kernel" ]; then
251 ${CROSS}objcopy $objflags "$kernel" "$vmz.$$"
253 if [ -n "$gzip" ]; then
257 if [ -n "$cacheit" ]; then
258 mv -f "$vmz.$$$gzip" "$vmz$gzip"
266 # Extract kernel version information, some platforms want to include
267 # it in the image header
268 version=`${CROSS}strings "$kernel" | grep '^Linux version [-0-9.]' | \
270 if [ -n "$version" ]; then
271 uboot_version="-n Linux-$version"
274 # physical offset of kernel image
275 membase=`${CROSS}objdump -p "$kernel" | grep -m 1 LOAD | awk '{print $7}'`
280 ${MKIMAGE} -A ppc -O linux -T kernel -C gzip -a $membase -e $membase \
281 $uboot_version -d "$vmz" "$ofile"
282 if [ -z "$cacheit" ]; then
290 ${CROSS}objcopy $4 $1 \
291 --add-section=$3="$2" \
292 --set-section-flags=$3=contents,alloc,load,readonly,data
295 addsec $tmp "$vmz" $ksection $object/empty.o
296 if [ -z "$cacheit" ]; then
300 if [ -n "$initrd" ]; then
301 addsec $tmp "$initrd" $isection
304 if [ -n "$dtb" ]; then
305 addsec $tmp "$dtb" .kernel:dtb
306 if [ -n "$dts" ]; then
311 if [ "$platform" != "miboot" ]; then
312 if [ -n "$link_address" ] ; then
313 text_start="-Ttext $link_address --defsym _start=$link_address"
315 ${CROSS}ld -m elf32ppc -T $lds $text_start -o "$ofile" \
316 $platformo $tmp $object/wrapper.a
320 # Some platforms need the zImage's entry point and base address
321 base=0x`${CROSS}nm "$ofile" | grep ' _start$' | cut -d' ' -f1`
322 entry=`${CROSS}objdump -f "$ofile" | grep '^start address ' | cut -d' ' -f3`
324 if [ -n "$binary" ]; then
325 mv "$ofile" "$ofile".elf
326 ${CROSS}objcopy -O binary "$ofile".elf "$ofile"
329 # post-processing needed for some platforms
332 $objbin/addnote "$ofile"
335 ${CROSS}objcopy -O aixcoff-rs6000 --set-start "$entry" "$ofile"
336 $objbin/hack-coff "$ofile"
340 ${MKIMAGE} -A ppc -O linux -T kernel -C gzip -a "$base" -e "$entry" \
341 $uboot_version -d "$ofile".gz "$ofile"
344 mv "$ofile" "$ofile.elf"
345 $objbin/mktree "$ofile.elf" "$ofile" "$base" "$entry"
346 if [ -z "$cacheit" ]; then
352 # The ps3's loader supports loading a gzipped binary image from flash
353 # rom to ram addr zero. The loader then enters the system reset
354 # vector at addr 0x100. A bootwrapper overlay is used to arrange for
355 # a binary image of the kernel to be at addr zero, and yet have a
356 # suitable bootwrapper entry at 0x100. To construct the final rom
357 # image 512 bytes from offset 0x100 is copied to the bootwrapper
358 # place holder at symbol __system_reset_kernel. The 512 bytes of the
359 # bootwrapper entry code at symbol __system_reset_overlay is then
360 # copied to offset 0x100. At runtime the bootwrapper program copies
361 # the data at __system_reset_kernel back to addr 0x100.
363 system_reset_overlay=0x`${CROSS}nm "$ofile" \
364 | grep ' __system_reset_overlay$' \
366 system_reset_overlay=`printf "%d" $system_reset_overlay`
367 system_reset_kernel=0x`${CROSS}nm "$ofile" \
368 | grep ' __system_reset_kernel$' \
370 system_reset_kernel=`printf "%d" $system_reset_kernel`
374 ${CROSS}objcopy -O binary "$ofile" "$ofile.bin"
376 dd if="$ofile.bin" of="$ofile.bin" conv=notrunc \
377 skip=$overlay_dest seek=$system_reset_kernel \
378 count=$overlay_size bs=1
380 dd if="$ofile.bin" of="$ofile.bin" conv=notrunc \
381 skip=$system_reset_overlay seek=$overlay_dest \
382 count=$overlay_size bs=1
384 odir="$(dirname "$ofile.bin")"
385 rm -f "$odir/otheros.bld"
386 gzip --force -9 --stdout "$ofile.bin" > "$odir/otheros.bld"