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 # directory for object and other files used by this script
47 object
=arch
/powerpc
/boot
51 # directory for working files
55 echo 'Usage: wrapper [-o output] [-p platform] [-i initrd]' >&2
56 echo ' [-d devtree] [-s tree.dts] [-c] [-C cross-prefix]' >&2
57 echo ' [-D datadir] [-W workingdir] [--no-gzip] [vmlinux]' >&2
61 while [ "$#" -gt 0 ]; do
65 [ "$#" -gt 0 ] || usage
70 [ "$#" -gt 0 ] || usage
75 [ "$#" -gt 0 ] || usage
80 [ "$#" -gt 0 ] || usage
85 [ "$#" -gt 0 ] || usage
93 [ "$#" -gt 0 ] || usage
98 [ "$#" -gt 0 ] || usage
104 [ "$#" -gt 0 ] || usage
114 [ -z "$kernel" ] || usage
121 if [ -n "$dts" ]; then
122 if [ ! -r "$dts" -a -r "$object/dts/$dts" ]; then
123 dts
="$object/dts/$dts"
125 if [ -z "$dtb" ]; then
128 $dtc -O dtb
-o "$dtb" -b 0 "$dts"
131 if [ -z "$kernel" ]; then
135 platformo
=$object/"$platform".o
136 lds
=$object/zImage.lds
139 tmp
=$tmpdir/zImage.$$.o
140 ksection
=.kernel
:vmlinux.strip
141 isection
=.kernel
:initrd
142 link_address
='0x400000'
146 platformo
=$object/of.o
147 link_address
='0x4000000'
150 platformo
=$object/of.o
153 platformo
=$object/of.o
154 lds
=$object/zImage.coff.lds
155 link_address
='0x500000'
158 # miboot and U-boot want just the bare bits, not an ELF binary
169 *-mpc866ads|
*-mpc885ads|
*-adder875*|
*-ep88xc)
170 platformo
=$object/cuboot-8xx.o
173 platformo
=$object/cuboot-52xx.o
175 *-pq2fads|
*-ep8248e|
*-mpc8272*|
*-storcenter)
176 platformo
=$object/cuboot-pq2.o
179 platformo
=$object/cuboot-824x.o
182 platformo
=$object/cuboot-83xx.o
184 *-tqm8541|
*-mpc8560*|
*-tqm8560|
*-tqm8555|
*-ksi8560*)
185 platformo
=$object/cuboot-85xx-cpm2.o
187 *-mpc85*|
*-tqm85*|
*-sbc85*)
188 platformo
=$object/cuboot-85xx.o
191 link_address
='0x800000'
196 platformo
="$object/ps3-head.o $object/ps3-hvcall.o $object/ps3.o"
197 lds
=$object/zImage.ps3.lds
200 objflags
="-O binary --set-section-flags=.bss=contents,alloc,load,data"
201 ksection
=.kernel
:vmlinux.bin
202 isection
=.kernel
:initrd
205 ep88xc|ep405|ep8248e
)
206 platformo
="$object/fixed-head.o $object/$platform.o"
210 platformo
="$object/fixed-head.o $object/redboot-8xx.o"
213 simpleboot-virtex405-
*)
214 platformo
="$object/virtex405-head.o $object/simpleboot.o $object/virtex.o"
217 simpleboot-virtex440-
*)
218 platformo
="$object/fixed-head.o $object/simpleboot.o $object/virtex.o"
222 platformo
="$object/fixed-head.o $object/simpleboot.o"
226 platformo
="$object/fixed-head.o $object/redboot-83xx.o"
230 link_address
='0x1400000'
231 platformo
=$object/cuboot-85xx.o
235 vmz
="$tmpdir/`basename \"$kernel\"`.$ext"
236 if [ -z "$cacheit" -o ! -f "$vmz$gzip" -o "$vmz$gzip" -ot "$kernel" ]; then
237 ${CROSS}objcopy
$objflags "$kernel" "$vmz.$$"
239 if [ -n "$gzip" ]; then
243 if [ -n "$cacheit" ]; then
244 mv -f "$vmz.$$$gzip" "$vmz$gzip"
252 # Extract kernel version information, some platforms want to include
253 # it in the image header
254 version
=`${CROSS}strings "$kernel" | grep '^Linux version [-0-9.]' | \
256 if [ -n "$version" ]; then
257 uboot_version
="-n Linux-$version"
260 # physical offset of kernel image
261 membase
=`${CROSS}objdump -p "$kernel" | grep -m 1 LOAD | awk '{print $7}'`
266 mkimage
-A ppc
-O linux
-T kernel
-C gzip -a $membase -e $membase \
267 $uboot_version -d "$vmz" "$ofile"
268 if [ -z "$cacheit" ]; then
276 ${CROSS}objcopy
$4 $1 \
277 --add-section=$3="$2" \
278 --set-section-flags=$3=contents
,alloc
,load
,readonly,data
281 addsec
$tmp "$vmz" $ksection $object/empty.o
282 if [ -z "$cacheit" ]; then
286 if [ -n "$initrd" ]; then
287 addsec
$tmp "$initrd" $isection
290 if [ -n "$dtb" ]; then
291 addsec
$tmp "$dtb" .kernel
:dtb
292 if [ -n "$dts" ]; then
297 if [ "$platform" != "miboot" ]; then
298 if [ -n "$link_address" ] ; then
299 text_start
="-Ttext $link_address --defsym _start=$link_address"
301 ${CROSS}ld
-m elf32ppc
-T $lds $text_start -o "$ofile" \
302 $platformo $tmp $object/wrapper.a
306 # Some platforms need the zImage's entry point and base address
307 base
=0x
`${CROSS}nm "$ofile" | grep ' _start$' | cut -d' ' -f1`
308 entry
=`${CROSS}objdump -f "$ofile" | grep '^start address ' | cut -d' ' -f3`
310 if [ -n "$binary" ]; then
311 mv "$ofile" "$ofile".elf
312 ${CROSS}objcopy
-O binary
"$ofile".elf
"$ofile"
315 # post-processing needed for some platforms
318 $objbin/addnote
"$ofile"
321 ${CROSS}objcopy
-O aixcoff-rs6000
--set-start "$entry" "$ofile"
322 $objbin/hack-coff
"$ofile"
326 mkimage
-A ppc
-O linux
-T kernel
-C gzip -a "$base" -e "$entry" \
327 $uboot_version -d "$ofile".gz
"$ofile"
330 mv "$ofile" "$ofile.elf"
331 $objbin/mktree
"$ofile.elf" "$ofile" "$base" "$entry"
332 if [ -z "$cacheit" ]; then
338 # The ps3's loader supports loading a gzipped binary image from flash
339 # rom to ram addr zero. The loader then enters the system reset
340 # vector at addr 0x100. A bootwrapper overlay is used to arrange for
341 # a binary image of the kernel to be at addr zero, and yet have a
342 # suitable bootwrapper entry at 0x100. To construct the final rom
343 # image 512 bytes from offset 0x100 is copied to the bootwrapper
344 # place holder at symbol __system_reset_kernel. The 512 bytes of the
345 # bootwrapper entry code at symbol __system_reset_overlay is then
346 # copied to offset 0x100. At runtime the bootwrapper program copies
347 # the data at __system_reset_kernel back to addr 0x100.
349 system_reset_overlay
=0x
`${CROSS}nm "$ofile" \
350 | grep ' __system_reset_overlay$' \
352 system_reset_overlay
=`printf "%d" $system_reset_overlay`
353 system_reset_kernel
=0x
`${CROSS}nm "$ofile" \
354 | grep ' __system_reset_kernel$' \
356 system_reset_kernel
=`printf "%d" $system_reset_kernel`
360 ${CROSS}objcopy
-O binary
"$ofile" "$ofile.bin"
362 dd if="$ofile.bin" of
="$ofile.bin" conv
=notrunc \
363 skip
=$overlay_dest seek
=$system_reset_kernel \
364 count
=$overlay_size bs
=1
366 dd if="$ofile.bin" of
="$ofile.bin" conv
=notrunc \
367 skip
=$system_reset_overlay seek
=$overlay_dest \
368 count
=$overlay_size bs
=1
370 odir
="$(dirname "$ofile.bin
")"
371 rm -f "$odir/otheros.bld"
372 gzip --force -9 --stdout "$ofile.bin" > "$odir/otheros.bld"