powerpc: Add a new zImage for maple using a different link address
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / arch / powerpc / boot / wrapper
blob7160b3b1fb35385e81c2ff6f4ccbe01eeb79ce3c
1 #!/bin/sh
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
9 # given platform.
11 # Options:
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
25 set -e
27 # Allow for verbose output
28 if [ "$V" = 1 ]; then
29 set -x
32 # defaults
33 kernel=
34 ofile=zImage
35 platform=of
36 initrd=
37 dtb=
38 dts=
39 cacheit=
40 binary=
41 gzip=.gz
43 # cross-compilation prefix
44 CROSS=
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
51 objbin=$object
52 dtc=scripts/dtc/dtc
54 # directory for working files
55 tmpdir=.
57 usage() {
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
61 exit 1
64 while [ "$#" -gt 0 ]; do
65 case "$1" in
66 -o)
67 shift
68 [ "$#" -gt 0 ] || usage
69 ofile="$1"
71 -p)
72 shift
73 [ "$#" -gt 0 ] || usage
74 platform="$1"
76 -i)
77 shift
78 [ "$#" -gt 0 ] || usage
79 initrd="$1"
81 -d)
82 shift
83 [ "$#" -gt 0 ] || usage
84 dtb="$1"
86 -s)
87 shift
88 [ "$#" -gt 0 ] || usage
89 dts="$1"
91 -c)
92 cacheit=y
94 -C)
95 shift
96 [ "$#" -gt 0 ] || usage
97 CROSS="$1"
99 -D)
100 shift
101 [ "$#" -gt 0 ] || usage
102 object="$1"
103 objbin="$1"
106 shift
107 [ "$#" -gt 0 ] || usage
108 tmpdir="$1"
110 --no-gzip)
111 gzip=
114 usage
117 [ -z "$kernel" ] || usage
118 kernel="$1"
120 esac
121 shift
122 done
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
129 dtb="$platform.dtb"
131 $dtc -O dtb -o "$dtb" -b 0 "$dts"
134 if [ -z "$kernel" ]; then
135 kernel=vmlinux
138 platformo=$object/"$platform".o
139 lds=$object/zImage.lds
140 ext=strip
141 objflags=-S
142 tmp=$tmpdir/zImage.$$.o
143 ksection=.kernel:vmlinux.strip
144 isection=.kernel:initrd
145 link_address='0x400000'
147 case "$platform" in
148 pseries)
149 platformo=$object/of.o
150 link_address='0x4000000'
152 maple)
153 platformo=$object/of.o
154 link_address='0x400000'
156 pmac|chrp)
157 platformo=$object/of.o
159 coff)
160 platformo=$object/of.o
161 lds=$object/zImage.coff.lds
162 link_address='0x500000'
164 miboot|uboot)
165 # miboot and U-boot want just the bare bits, not an ELF binary
166 ext=bin
167 objflags="-O binary"
168 tmp="$ofile"
169 ksection=image
170 isection=initrd
172 cuboot*)
173 binary=y
174 gzip=
175 case "$platform" in
176 *-mpc866ads|*-mpc885ads|*-adder875*|*-ep88xc)
177 platformo=$object/cuboot-8xx.o
179 *5200*|*-motionpro)
180 platformo=$object/cuboot-52xx.o
182 *-pq2fads|*-ep8248e|*-mpc8272*|*-storcenter)
183 platformo=$object/cuboot-pq2.o
185 *-mpc824*)
186 platformo=$object/cuboot-824x.o
188 *-mpc83*|*-asp834x*)
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
197 *-amigaone)
198 link_address='0x800000'
200 esac
202 ps3)
203 platformo="$object/ps3-head.o $object/ps3-hvcall.o $object/ps3.o"
204 lds=$object/zImage.ps3.lds
205 gzip=
206 ext=bin
207 objflags="-O binary --set-section-flags=.bss=contents,alloc,load,data"
208 ksection=.kernel:vmlinux.bin
209 isection=.kernel:initrd
210 link_address=''
212 ep88xc|ep405|ep8248e)
213 platformo="$object/fixed-head.o $object/$platform.o"
214 binary=y
216 adder875-redboot)
217 platformo="$object/fixed-head.o $object/redboot-8xx.o"
218 binary=y
220 simpleboot-virtex405-*)
221 platformo="$object/virtex405-head.o $object/simpleboot.o $object/virtex.o"
222 binary=y
224 simpleboot-virtex440-*)
225 platformo="$object/fixed-head.o $object/simpleboot.o $object/virtex.o"
226 binary=y
228 simpleboot-*)
229 platformo="$object/fixed-head.o $object/simpleboot.o"
230 binary=y
232 asp834x-redboot)
233 platformo="$object/fixed-head.o $object/redboot-83xx.o"
234 binary=y
236 xpedite52*)
237 link_address='0x1400000'
238 platformo=$object/cuboot-85xx.o
240 gamecube|wii)
241 link_address='0x600000'
242 platformo="$object/$platform-head.o $object/$platform.o"
244 esac
246 vmz="$tmpdir/`basename \"$kernel\"`.$ext"
247 if [ -z "$cacheit" -o ! -f "$vmz$gzip" -o "$vmz$gzip" -ot "$kernel" ]; then
248 ${CROSS}objcopy $objflags "$kernel" "$vmz.$$"
250 if [ -n "$gzip" ]; then
251 gzip -f -9 "$vmz.$$"
254 if [ -n "$cacheit" ]; then
255 mv -f "$vmz.$$$gzip" "$vmz$gzip"
256 else
257 vmz="$vmz.$$"
261 vmz="$vmz$gzip"
263 # Extract kernel version information, some platforms want to include
264 # it in the image header
265 version=`${CROSS}strings "$kernel" | grep '^Linux version [-0-9.]' | \
266 cut -d' ' -f3`
267 if [ -n "$version" ]; then
268 uboot_version="-n Linux-$version"
271 # physical offset of kernel image
272 membase=`${CROSS}objdump -p "$kernel" | grep -m 1 LOAD | awk '{print $7}'`
274 case "$platform" in
275 uboot)
276 rm -f "$ofile"
277 ${MKIMAGE} -A ppc -O linux -T kernel -C gzip -a $membase -e $membase \
278 $uboot_version -d "$vmz" "$ofile"
279 if [ -z "$cacheit" ]; then
280 rm -f "$vmz"
282 exit 0
284 esac
286 addsec() {
287 ${CROSS}objcopy $4 $1 \
288 --add-section=$3="$2" \
289 --set-section-flags=$3=contents,alloc,load,readonly,data
292 addsec $tmp "$vmz" $ksection $object/empty.o
293 if [ -z "$cacheit" ]; then
294 rm -f "$vmz"
297 if [ -n "$initrd" ]; then
298 addsec $tmp "$initrd" $isection
301 if [ -n "$dtb" ]; then
302 addsec $tmp "$dtb" .kernel:dtb
303 if [ -n "$dts" ]; then
304 rm $dtb
308 if [ "$platform" != "miboot" ]; then
309 if [ -n "$link_address" ] ; then
310 text_start="-Ttext $link_address --defsym _start=$link_address"
312 ${CROSS}ld -m elf32ppc -T $lds $text_start -o "$ofile" \
313 $platformo $tmp $object/wrapper.a
314 rm $tmp
317 # Some platforms need the zImage's entry point and base address
318 base=0x`${CROSS}nm "$ofile" | grep ' _start$' | cut -d' ' -f1`
319 entry=`${CROSS}objdump -f "$ofile" | grep '^start address ' | cut -d' ' -f3`
321 if [ -n "$binary" ]; then
322 mv "$ofile" "$ofile".elf
323 ${CROSS}objcopy -O binary "$ofile".elf "$ofile"
326 # post-processing needed for some platforms
327 case "$platform" in
328 pseries|chrp|maple)
329 $objbin/addnote "$ofile"
331 coff)
332 ${CROSS}objcopy -O aixcoff-rs6000 --set-start "$entry" "$ofile"
333 $objbin/hack-coff "$ofile"
335 cuboot*)
336 gzip -f -9 "$ofile"
337 ${MKIMAGE} -A ppc -O linux -T kernel -C gzip -a "$base" -e "$entry" \
338 $uboot_version -d "$ofile".gz "$ofile"
340 treeboot*)
341 mv "$ofile" "$ofile.elf"
342 $objbin/mktree "$ofile.elf" "$ofile" "$base" "$entry"
343 if [ -z "$cacheit" ]; then
344 rm -f "$ofile.elf"
346 exit 0
348 ps3)
349 # The ps3's loader supports loading a gzipped binary image from flash
350 # rom to ram addr zero. The loader then enters the system reset
351 # vector at addr 0x100. A bootwrapper overlay is used to arrange for
352 # a binary image of the kernel to be at addr zero, and yet have a
353 # suitable bootwrapper entry at 0x100. To construct the final rom
354 # image 512 bytes from offset 0x100 is copied to the bootwrapper
355 # place holder at symbol __system_reset_kernel. The 512 bytes of the
356 # bootwrapper entry code at symbol __system_reset_overlay is then
357 # copied to offset 0x100. At runtime the bootwrapper program copies
358 # the data at __system_reset_kernel back to addr 0x100.
360 system_reset_overlay=0x`${CROSS}nm "$ofile" \
361 | grep ' __system_reset_overlay$' \
362 | cut -d' ' -f1`
363 system_reset_overlay=`printf "%d" $system_reset_overlay`
364 system_reset_kernel=0x`${CROSS}nm "$ofile" \
365 | grep ' __system_reset_kernel$' \
366 | cut -d' ' -f1`
367 system_reset_kernel=`printf "%d" $system_reset_kernel`
368 overlay_dest="256"
369 overlay_size="512"
371 ${CROSS}objcopy -O binary "$ofile" "$ofile.bin"
373 dd if="$ofile.bin" of="$ofile.bin" conv=notrunc \
374 skip=$overlay_dest seek=$system_reset_kernel \
375 count=$overlay_size bs=1
377 dd if="$ofile.bin" of="$ofile.bin" conv=notrunc \
378 skip=$system_reset_overlay seek=$overlay_dest \
379 count=$overlay_size bs=1
381 odir="$(dirname "$ofile.bin")"
382 rm -f "$odir/otheros.bld"
383 gzip --force -9 --stdout "$ofile.bin" > "$odir/otheros.bld"
385 esac