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 .)
23 # -z use gzip (legacy)
24 # -Z zsuffix compression to use (gz, xz or none)
26 # Stop execution if any command fails
29 # Allow for verbose output
47 # cross-compilation prefix
50 # mkimage wrapper script
51 MKIMAGE
=$srctree/scripts
/mkuboot.sh
53 # directory for object and other files used by this script
54 object
=arch
/powerpc
/boot
58 # directory for working files
62 echo 'Usage: wrapper [-o output] [-p platform] [-i initrd]' >&2
63 echo ' [-d devtree] [-s tree.dts] [-c] [-C cross-prefix]' >&2
64 echo ' [-D datadir] [-W workingdir] [-Z (gz|xz|none)]' >&2
65 echo ' [--no-compression] [vmlinux]' >&2
78 if [ $?
-ne "0" ]; then
86 while [ "$#" -gt 0 ]; do
90 [ "$#" -gt 0 ] || usage
95 [ "$#" -gt 0 ] || usage
100 [ "$#" -gt 0 ] || usage
105 [ "$#" -gt 0 ] || usage
110 [ "$#" -gt 0 ] || usage
118 [ "$#" -gt 0 ] || usage
123 [ "$#" -gt 0 ] || usage
129 [ "$#" -gt 0 ] || usage
137 [ "$#" -gt 0 ] || usage
138 [ "$1" != "gz" -o "$1" != "xz" -o "$1" != "none" ] || usage
142 if [ $compression = ".none" ]; then
147 # a "feature" of the the wrapper script is that it can be used outside
148 # the kernel tree. So keeping this around for backwards compatibility.
155 [ -z "$kernel" ] || usage
163 if [ -n "$dts" ]; then
164 if [ ! -r "$dts" -a -r "$object/dts/$dts" ]; then
165 dts
="$object/dts/$dts"
167 if [ -z "$dtb" ]; then
170 $dtc -O dtb
-o "$dtb" -b 0 "$dts"
173 if [ -z "$kernel" ]; then
177 LANG
=C elfformat
="`${CROSS}objdump -p "$kernel" | grep 'file format' | awk '{print $4}'`"
179 elf64-powerpcle
) format
=elf64lppc
;;
180 elf64-powerpc
) format
=elf32ppc
;;
181 elf32-powerpc
) format
=elf32ppc
;;
185 platformo
=$object/"$platform".o
186 lds
=$object/zImage.lds
189 tmp
=$tmpdir/zImage.$$.o
190 ksection
=.kernel
:vmlinux.strip
191 isection
=.kernel
:initrd
192 link_address
='0x400000'
197 platformo
="$object/of.o $object/epapr.o"
201 platformo
="$object/pseries-head.o $object/of.o $object/epapr.o"
202 link_address
='0x4000000'
203 if [ "$format" != "elf32ppc" ]; then
210 platformo
="$object/of.o $object/epapr.o"
211 link_address
='0x400000'
215 platformo
="$object/of.o $object/epapr.o"
219 platformo
="$object/crt0.o $object/of.o $object/epapr.o"
220 lds
=$object/zImage.coff.lds
221 link_address
='0x500000'
226 # miboot and U-boot want just the bare bits, not an ELF binary
237 *-mpc866ads|
*-mpc885ads|
*-adder875*|
*-ep88xc)
238 platformo
=$object/cuboot-8xx.o
241 platformo
=$object/cuboot-52xx.o
243 *-pq2fads|
*-ep8248e|
*-mpc8272*|
*-storcenter)
244 platformo
=$object/cuboot-pq2.o
247 platformo
=$object/cuboot-824x.o
250 platformo
=$object/cuboot-83xx.o
252 *-tqm8541|
*-mpc8560*|
*-tqm8560|
*-tqm8555|
*-ksi8560*)
253 platformo
=$object/cuboot-85xx-cpm2.o
255 *-mpc85*|
*-tqm85*|
*-sbc85*)
256 platformo
=$object/cuboot-85xx.o
259 link_address
='0x800000'
264 platformo
="$object/ps3-head.o $object/ps3-hvcall.o $object/ps3.o"
265 lds
=$object/zImage.ps3.lds
268 objflags
="-O binary --set-section-flags=.bss=contents,alloc,load,data"
269 ksection
=.kernel
:vmlinux.bin
270 isection
=.kernel
:initrd
275 ep88xc|ep405|ep8248e
)
276 platformo
="$object/fixed-head.o $object/$platform.o"
280 platformo
="$object/fixed-head.o $object/redboot-8xx.o"
283 simpleboot-virtex405-
*)
284 platformo
="$object/virtex405-head.o $object/simpleboot.o $object/virtex.o"
287 simpleboot-virtex440-
*)
288 platformo
="$object/fixed-head.o $object/simpleboot.o $object/virtex.o"
292 platformo
="$object/fixed-head.o $object/simpleboot.o"
296 platformo
="$object/fixed-head.o $object/redboot-83xx.o"
300 link_address
='0x1400000'
301 platformo
=$object/cuboot-85xx.o
304 link_address
='0x600000'
305 platformo
="$object/$platform-head.o $object/$platform.o"
308 link_address
='0x1000000'
311 link_address
='0x1000000'
313 treeboot-iss4xx-mpic
)
314 platformo
="$object/treeboot-iss4xx.o"
317 platformo
="$object/pseries-head.o $object/epapr.o $object/epapr-wrapper.o"
318 link_address
='0x20000000'
322 platformo
="$object/fixed-head.o $object/mvme5100.o"
326 platformo
="$object/motload-head.o $object/mvme7100.o"
327 link_address
='0x4000000'
332 vmz
="$tmpdir/`basename \"$kernel\"`.$ext"
334 # Calculate the vmlinux.strip size
335 ${CROSS}objcopy
$objflags "$kernel" "$vmz.$$"
336 strip_size
=$
(stat
-c %s
$vmz.$$
)
338 if [ -z "$cacheit" -o ! -f "$vmz$compression" -o "$vmz$compression" -ot "$kernel" ]; then
339 # recompress the image if we need to
342 xz
--check=crc32
-f -6 "$vmz.$$"
345 gzip -n -f -9 "$vmz.$$"
348 # drop the compression suffix so the stripped vmlinux is used
353 if [ -n "$cacheit" ]; then
354 mv -f "$vmz.$$$compression" "$vmz$compression"
362 vmz
="$vmz$compression"
364 if [ "$make_space" = "y" ]; then
365 # Round the size to next higher MB limit
366 round_size
=$
(((strip_size
+ 0xfffff) & 0xfff00000))
368 round_size
=0x$
(printf "%x" $round_size)
369 link_addr
=$
(printf "%d" $link_address)
371 if [ $link_addr -lt $strip_size ]; then
372 echo "INFO: Uncompressed kernel (size 0x$(printf "%x
\n" $strip_size))" \
373 "overlaps the address of the wrapper($link_address)"
374 echo "INFO: Fixing the link_address of wrapper to ($round_size)"
375 link_address
=$round_size
379 # Extract kernel version information, some platforms want to include
380 # it in the image header
381 version
=`${CROSS}strings "$kernel" | grep '^Linux version [-0-9.]' | \
383 if [ -n "$version" ]; then
384 uboot_version
="-n Linux-$version"
387 # physical offset of kernel image
388 membase
=`${CROSS}objdump -p "$kernel" | grep -m 1 LOAD | awk '{print $7}'`
393 ${MKIMAGE} -A ppc
-O linux
-T kernel
-C gzip -a $membase -e $membase \
394 $uboot_version -d "$vmz" "$ofile"
395 if [ -z "$cacheit" ]; then
402 # obs600 wants a multi image with an initrd, so we need to put a fake
403 # one in even when building a "normal" image.
404 if [ -n "$initrd" ]; then
408 echo "\0" >>"$real_rd"
410 ${MKIMAGE} -A ppc
-O linux
-T multi
-C gzip -a $membase -e $membase \
411 $uboot_version -d "$vmz":"$real_rd":"$dtb" "$ofile"
412 if [ -z "$initrd" ]; then
415 if [ -z "$cacheit" ]; then
423 ${CROSS}objcopy
$4 $1 \
424 --add-section=$3="$2" \
425 --set-section-flags=$3=contents
,alloc
,load
,readonly,data
428 addsec
$tmp "$vmz" $ksection $object/empty.o
429 if [ -z "$cacheit" ]; then
433 if [ -n "$initrd" ]; then
434 addsec
$tmp "$initrd" $isection
437 if [ -n "$dtb" ]; then
438 addsec
$tmp "$dtb" .kernel
:dtb
439 if [ -n "$dts" ]; then
444 if [ "$platform" != "miboot" ]; then
445 if [ -n "$link_address" ] ; then
446 text_start
="-Ttext $link_address"
449 ${CROSS}ld
-m $format -T $lds $text_start $pie -o "$ofile" \
450 $platformo $tmp $object/wrapper.a
454 # Some platforms need the zImage's entry point and base address
455 base
=0x
`${CROSS}nm "$ofile" | grep ' _start$' | cut -d' ' -f1`
456 entry
=`${CROSS}objdump -f "$ofile" | grep '^start address ' | cut -d' ' -f3`
458 if [ -n "$binary" ]; then
459 mv "$ofile" "$ofile".elf
460 ${CROSS}objcopy
-O binary
"$ofile".elf
"$ofile"
463 # post-processing needed for some platforms
466 $objbin/addnote
"$ofile"
469 ${CROSS}objcopy
-O aixcoff-rs6000
--set-start "$entry" "$ofile"
470 $objbin/hack-coff
"$ofile"
473 gzip -n -f -9 "$ofile"
474 ${MKIMAGE} -A ppc
-O linux
-T kernel
-C gzip -a "$base" -e "$entry" \
475 $uboot_version -d "$ofile".gz
"$ofile"
478 mv "$ofile" "$ofile.elf"
479 $objbin/mktree
"$ofile.elf" "$ofile" "$base" "$entry"
480 if [ -z "$cacheit" ]; then
486 # The ps3's loader supports loading a gzipped binary image from flash
487 # rom to ram addr zero. The loader then enters the system reset
488 # vector at addr 0x100. A bootwrapper overlay is used to arrange for
489 # a binary image of the kernel to be at addr zero, and yet have a
490 # suitable bootwrapper entry at 0x100. To construct the final rom
491 # image 512 bytes from offset 0x100 is copied to the bootwrapper
492 # place holder at symbol __system_reset_kernel. The 512 bytes of the
493 # bootwrapper entry code at symbol __system_reset_overlay is then
494 # copied to offset 0x100. At runtime the bootwrapper program copies
495 # the data at __system_reset_kernel back to addr 0x100.
497 system_reset_overlay
=0x
`${CROSS}nm "$ofile" \
498 | grep ' __system_reset_overlay$' \
500 system_reset_overlay
=`printf "%d" $system_reset_overlay`
501 system_reset_kernel
=0x
`${CROSS}nm "$ofile" \
502 | grep ' __system_reset_kernel$' \
504 system_reset_kernel
=`printf "%d" $system_reset_kernel`
508 ${CROSS}objcopy
-O binary
"$ofile" "$ofile.bin"
510 run_cmd
dd if="$ofile.bin" of
="$ofile.bin" conv
=notrunc \
511 skip
=$overlay_dest seek
=$system_reset_kernel \
512 count
=$overlay_size bs
=1
514 run_cmd
dd if="$ofile.bin" of
="$ofile.bin" conv
=notrunc \
515 skip
=$system_reset_overlay seek
=$overlay_dest \
516 count
=$overlay_size bs
=1
518 odir
="$(dirname "$ofile.bin
")"
519 rm -f "$odir/otheros.bld"
520 gzip -n --force -9 --stdout "$ofile.bin" > "$odir/otheros.bld"