blob: ceaa75d5a684330aa58246c3991fc2954f4ac353 [file] [log] [blame]
Paul Mackerras2bf11812006-09-27 22:47:03 +10001#!/bin/sh
2
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.
6
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.
10
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 .)
23
Grant Likelyd4740372007-10-23 14:27:36 +100024# Stop execution if any command fails
25set -e
26
Grant Likely7f66c1f2007-10-23 14:27:31 +100027# Allow for verbose output
28if [ "$V" = 1 ]; then
29 set -x
30fi
31
Paul Mackerras2bf11812006-09-27 22:47:03 +100032# defaults
33kernel=
34ofile=zImage
35platform=of
36initrd=
37dtb=
38dts=
39cacheit=
Scott Wood11c146c2007-09-14 14:58:25 -050040binary=
Scott Wooda9903812007-03-16 12:27:59 -050041gzip=.gz
Michael Ellerman6975a782011-04-12 20:38:55 +000042pie=
Cédric Le Goater147c0512014-04-24 09:23:39 +020043format=
Paul Mackerras2bf11812006-09-27 22:47:03 +100044
45# cross-compilation prefix
46CROSS=
47
Peter Tyser3f884bf2009-12-30 15:23:26 -070048# mkimage wrapper script
49MKIMAGE=$srctree/scripts/mkuboot.sh
50
Paul Mackerras2bf11812006-09-27 22:47:03 +100051# directory for object and other files used by this script
52object=arch/powerpc/boot
David Woodhouse5c539ee32007-12-03 13:52:05 +110053objbin=$object
Lucian Adrian Grijincuc79b2972009-07-23 00:13:37 +000054dtc=scripts/dtc/dtc
Paul Mackerras2bf11812006-09-27 22:47:03 +100055
56# directory for working files
57tmpdir=.
58
59usage() {
60 echo 'Usage: wrapper [-o output] [-p platform] [-i initrd]' >&2
61 echo ' [-d devtree] [-s tree.dts] [-c] [-C cross-prefix]' >&2
Scott Wooda9903812007-03-16 12:27:59 -050062 echo ' [-D datadir] [-W workingdir] [--no-gzip] [vmlinux]' >&2
Paul Mackerras2bf11812006-09-27 22:47:03 +100063 exit 1
64}
65
Geoff Levand879c26d2015-10-19 10:53:26 -070066run_cmd() {
67 if [ "$V" = 1 ]; then
68 $* 2>&1
69 else
70 local msg
71
72 set +e
73 msg=$($* 2>&1)
74
75 if [ $? -ne "0" ]; then
76 echo $msg
77 exit 1
78 fi
79 set -e
80 fi
81}
82
Paul Mackerras2bf11812006-09-27 22:47:03 +100083while [ "$#" -gt 0 ]; do
84 case "$1" in
85 -o)
86 shift
87 [ "$#" -gt 0 ] || usage
88 ofile="$1"
89 ;;
90 -p)
91 shift
92 [ "$#" -gt 0 ] || usage
93 platform="$1"
94 ;;
95 -i)
96 shift
97 [ "$#" -gt 0 ] || usage
98 initrd="$1"
99 ;;
100 -d)
101 shift
102 [ "$#" -gt 0 ] || usage
103 dtb="$1"
104 ;;
105 -s)
106 shift
107 [ "$#" -gt 0 ] || usage
108 dts="$1"
109 ;;
110 -c)
111 cacheit=y
112 ;;
113 -C)
114 shift
115 [ "$#" -gt 0 ] || usage
116 CROSS="$1"
117 ;;
118 -D)
119 shift
120 [ "$#" -gt 0 ] || usage
121 object="$1"
David Woodhouse5c539ee32007-12-03 13:52:05 +1100122 objbin="$1"
Paul Mackerras2bf11812006-09-27 22:47:03 +1000123 ;;
124 -W)
125 shift
126 [ "$#" -gt 0 ] || usage
127 tmpdir="$1"
128 ;;
Scott Wooda9903812007-03-16 12:27:59 -0500129 --no-gzip)
130 gzip=
131 ;;
Paul Mackerras2bf11812006-09-27 22:47:03 +1000132 -?)
133 usage
134 ;;
135 *)
136 [ -z "$kernel" ] || usage
137 kernel="$1"
138 ;;
139 esac
140 shift
141done
142
143if [ -n "$dts" ]; then
David Woodhouse701172d12007-12-03 13:49:24 +1100144 if [ ! -r "$dts" -a -r "$object/dts/$dts" ]; then
145 dts="$object/dts/$dts"
146 fi
Paul Mackerras2bf11812006-09-27 22:47:03 +1000147 if [ -z "$dtb" ]; then
148 dtb="$platform.dtb"
149 fi
Lucian Adrian Grijincuc79b2972009-07-23 00:13:37 +0000150 $dtc -O dtb -o "$dtb" -b 0 "$dts"
Paul Mackerras2bf11812006-09-27 22:47:03 +1000151fi
152
153if [ -z "$kernel" ]; then
154 kernel=vmlinux
155fi
156
Cédric Le Goater147c0512014-04-24 09:23:39 +0200157elfformat="`${CROSS}objdump -p "$kernel" | grep 'file format' | awk '{print $4}'`"
158case "$elfformat" in
159 elf64-powerpcle) format=elf64lppc ;;
160 elf64-powerpc) format=elf32ppc ;;
161 elf32-powerpc) format=elf32ppc ;;
162esac
163
164
Paul Mackerras2bf11812006-09-27 22:47:03 +1000165platformo=$object/"$platform".o
166lds=$object/zImage.lds
167ext=strip
168objflags=-S
169tmp=$tmpdir/zImage.$$.o
170ksection=.kernel:vmlinux.strip
171isection=.kernel:initrd
Tony Breeds9b09c6d2008-06-24 14:20:29 +1000172link_address='0x400000'
Stephen Rothwelldfbc2d72012-03-20 14:13:51 +1100173make_space=y
Paul Mackerras2bf11812006-09-27 22:47:03 +1000174
175case "$platform" in
Benjamin Herrenschmidt44790a02013-11-05 10:09:11 +1100176of)
177 platformo="$object/of.o $object/epapr.o"
178 make_space=n
179 ;;
Tony Breeds9b09c6d2008-06-24 14:20:29 +1000180pseries)
Cédric Le Goater2d9afb32014-04-24 09:23:38 +0200181 platformo="$object/pseries-head.o $object/of.o $object/epapr.o"
Tony Breeds9b09c6d2008-06-24 14:20:29 +1000182 link_address='0x4000000'
Cédric Le Goater147c0512014-04-24 09:23:39 +0200183 if [ "$format" != "elf32ppc" ]; then
184 link_address=
185 pie=-pie
186 fi
Paul Mackerrasf5467e22013-10-29 16:21:26 +1100187 make_space=n
Tony Breeds9b09c6d2008-06-24 14:20:29 +1000188 ;;
Corey Minyard58706ef2010-01-29 14:18:20 +0000189maple)
Benjamin Herrenschmidt0c9fa292013-09-24 16:10:38 +1000190 platformo="$object/of.o $object/epapr.o"
Corey Minyard58706ef2010-01-29 14:18:20 +0000191 link_address='0x400000'
Paul Mackerrasf5467e22013-10-29 16:21:26 +1100192 make_space=n
Corey Minyard58706ef2010-01-29 14:18:20 +0000193 ;;
Tony Breeds9b09c6d2008-06-24 14:20:29 +1000194pmac|chrp)
Benjamin Herrenschmidt0c9fa292013-09-24 16:10:38 +1000195 platformo="$object/of.o $object/epapr.o"
Paul Mackerrasf5467e22013-10-29 16:21:26 +1100196 make_space=n
Paul Mackerras2bf11812006-09-27 22:47:03 +1000197 ;;
Milton Miller627aa942007-05-31 01:29:01 +1000198coff)
Benjamin Herrenschmidt0c9fa292013-09-24 16:10:38 +1000199 platformo="$object/crt0.o $object/of.o $object/epapr.o"
Paul Mackerras2bf11812006-09-27 22:47:03 +1000200 lds=$object/zImage.coff.lds
Tony Breeds9b09c6d2008-06-24 14:20:29 +1000201 link_address='0x500000'
Paul Mackerrasf5467e22013-10-29 16:21:26 +1100202 make_space=n
Michael Ellerman6975a782011-04-12 20:38:55 +0000203 pie=
Paul Mackerras2bf11812006-09-27 22:47:03 +1000204 ;;
Benjamin Herrenschmidt11eab2972011-12-01 19:35:08 +0000205miboot|uboot*)
Paul Mackerras2bf11812006-09-27 22:47:03 +1000206 # miboot and U-boot want just the bare bits, not an ELF binary
207 ext=bin
208 objflags="-O binary"
209 tmp="$ofile"
210 ksection=image
211 isection=initrd
212 ;;
Scott Wood0fdd7172007-04-17 09:25:50 +1000213cuboot*)
Scott Wood11c146c2007-09-14 14:58:25 -0500214 binary=y
Scott Wood0fdd7172007-04-17 09:25:50 +1000215 gzip=
Grant Likely25431332008-02-07 05:18:34 +1100216 case "$platform" in
Scott Wood8dd217b2008-07-31 19:10:22 +0300217 *-mpc866ads|*-mpc885ads|*-adder875*|*-ep88xc)
Grant Likely25431332008-02-07 05:18:34 +1100218 platformo=$object/cuboot-8xx.o
219 ;;
220 *5200*|*-motionpro)
221 platformo=$object/cuboot-52xx.o
222 ;;
223 *-pq2fads|*-ep8248e|*-mpc8272*|*-storcenter)
224 platformo=$object/cuboot-pq2.o
225 ;;
226 *-mpc824*)
227 platformo=$object/cuboot-824x.o
228 ;;
Bryan O'Donoghue59d13f92008-05-08 13:47:00 +0100229 *-mpc83*|*-asp834x*)
Grant Likely25431332008-02-07 05:18:34 +1100230 platformo=$object/cuboot-83xx.o
231 ;;
Alexandr Smirnovff880112008-03-04 19:34:26 +0300232 *-tqm8541|*-mpc8560*|*-tqm8560|*-tqm8555|*-ksi8560*)
Grant Likely25431332008-02-07 05:18:34 +1100233 platformo=$object/cuboot-85xx-cpm2.o
234 ;;
Wolfgang Grandegger6dd1b642008-06-06 13:50:04 +0200235 *-mpc85*|*-tqm85*|*-sbc85*)
Grant Likely25431332008-02-07 05:18:34 +1100236 platformo=$object/cuboot-85xx.o
237 ;;
Gerhard Pircher8f237352009-02-10 12:26:11 +0000238 *-amigaone)
239 link_address='0x800000'
240 ;;
Grant Likely25431332008-02-07 05:18:34 +1100241 esac
Scott Wood0fdd7172007-04-17 09:25:50 +1000242 ;;
Geoff Levandbafdb642007-07-04 09:07:18 +1000243ps3)
244 platformo="$object/ps3-head.o $object/ps3-hvcall.o $object/ps3.o"
245 lds=$object/zImage.ps3.lds
246 gzip=
247 ext=bin
248 objflags="-O binary --set-section-flags=.bss=contents,alloc,load,data"
249 ksection=.kernel:vmlinux.bin
250 isection=.kernel:initrd
Tony Breeds9b09c6d2008-06-24 14:20:29 +1000251 link_address=''
Stephen Rothwelldfbc2d72012-03-20 14:13:51 +1100252 make_space=n
Michael Ellerman6975a782011-04-12 20:38:55 +0000253 pie=
Geoff Levandbafdb642007-07-04 09:07:18 +1000254 ;;
Scott Wooda55387e2008-02-20 12:33:38 -0600255ep88xc|ep405|ep8248e)
Scott Wood11c146c2007-09-14 14:58:25 -0500256 platformo="$object/fixed-head.o $object/$platform.o"
257 binary=y
258 ;;
Scott Wooda55387e2008-02-20 12:33:38 -0600259adder875-redboot)
260 platformo="$object/fixed-head.o $object/redboot-8xx.o"
261 binary=y
262 ;;
Grant Likelyd2477b52008-03-19 04:07:43 +1100263simpleboot-virtex405-*)
John Linnd58577d2008-07-02 15:11:28 -0700264 platformo="$object/virtex405-head.o $object/simpleboot.o $object/virtex.o"
265 binary=y
266 ;;
267simpleboot-virtex440-*)
Grant Likelya7e1cf02009-03-11 09:36:26 -0600268 platformo="$object/fixed-head.o $object/simpleboot.o $object/virtex.o"
Grant Likelyd2477b52008-03-19 04:07:43 +1100269 binary=y
270 ;;
Grant Likely1d46e372008-07-04 00:59:37 -0600271simpleboot-*)
Grant Likelya7e1cf02009-03-11 09:36:26 -0600272 platformo="$object/fixed-head.o $object/simpleboot.o"
Grant Likely1d46e372008-07-04 00:59:37 -0600273 binary=y
274 ;;
Bryan O'Donoghue59d13f92008-05-08 13:47:00 +0100275asp834x-redboot)
276 platformo="$object/fixed-head.o $object/redboot-83xx.o"
277 binary=y
278 ;;
Nate Case24760822009-06-11 14:43:01 -0500279xpedite52*)
280 link_address='0x1400000'
281 platformo=$object/cuboot-85xx.o
282 ;;
Albert Herranz6cdd24172009-12-12 06:31:45 +0000283gamecube|wii)
Albert Herranzb68a24b2009-12-12 06:31:36 +0000284 link_address='0x600000'
285 platformo="$object/$platform-head.o $object/$platform.o"
286 ;;
Tony Breeds228d5502011-11-30 21:39:24 +0000287treeboot-currituck)
288 link_address='0x1000000'
289 ;;
Alistair Popple2a2c74b2014-03-06 14:52:27 +1100290treeboot-akebono)
291 link_address='0x1000000'
292 ;;
Torez Smithb4e8c8d2010-03-05 10:45:54 +0000293treeboot-iss4xx-mpic)
294 platformo="$object/treeboot-iss4xx.o"
295 ;;
David Gibson6c5b59b2011-04-14 18:29:16 +0000296epapr)
Jeremy Kerr90d1d442015-02-11 12:55:44 +0800297 platformo="$object/pseries-head.o $object/epapr.o $object/epapr-wrapper.o"
David Gibson6c5b59b2011-04-14 18:29:16 +0000298 link_address='0x20000000'
299 pie=-pie
300 ;;
Stephen Chiversbe201982014-01-09 13:01:22 +1100301mvme5100)
302 platformo="$object/fixed-head.o $object/mvme5100.o"
303 binary=y
304 ;;
Paul Mackerras2bf11812006-09-27 22:47:03 +1000305esac
306
307vmz="$tmpdir/`basename \"$kernel\"`.$ext"
Milton Miller1383a342007-03-28 02:21:04 -0600308if [ -z "$cacheit" -o ! -f "$vmz$gzip" -o "$vmz$gzip" -ot "$kernel" ]; then
Paul Mackerras2bf11812006-09-27 22:47:03 +1000309 ${CROSS}objcopy $objflags "$kernel" "$vmz.$$"
Scott Wooda9903812007-03-16 12:27:59 -0500310
Suzuki Poulosec55aef02011-12-14 22:59:57 +0000311 strip_size=$(stat -c %s $vmz.$$)
312
Scott Wooda9903812007-03-16 12:27:59 -0500313 if [ -n "$gzip" ]; then
Michal Marekc4f56af2011-04-05 04:58:50 +0000314 gzip -n -f -9 "$vmz.$$"
Scott Wooda9903812007-03-16 12:27:59 -0500315 fi
316
Paul Mackerras2bf11812006-09-27 22:47:03 +1000317 if [ -n "$cacheit" ]; then
Scott Wooda9903812007-03-16 12:27:59 -0500318 mv -f "$vmz.$$$gzip" "$vmz$gzip"
Paul Mackerras2bf11812006-09-27 22:47:03 +1000319 else
320 vmz="$vmz.$$"
321 fi
Suzuki Poulosec55aef02011-12-14 22:59:57 +0000322else
323 # Calculate the vmlinux.strip size
324 ${CROSS}objcopy $objflags "$kernel" "$vmz.$$"
325 strip_size=$(stat -c %s $vmz.$$)
326 rm -f $vmz.$$
327fi
328
Stephen Rothwelldfbc2d72012-03-20 14:13:51 +1100329if [ "$make_space" = "y" ]; then
330 # Round the size to next higher MB limit
331 round_size=$(((strip_size + 0xfffff) & 0xfff00000))
Suzuki Poulosec55aef02011-12-14 22:59:57 +0000332
Stephen Rothwelldfbc2d72012-03-20 14:13:51 +1100333 round_size=0x$(printf "%x" $round_size)
334 link_addr=$(printf "%d" $link_address)
Suzuki Poulosec55aef02011-12-14 22:59:57 +0000335
Stephen Rothwelldfbc2d72012-03-20 14:13:51 +1100336 if [ $link_addr -lt $strip_size ]; then
337 echo "INFO: Uncompressed kernel (size 0x$(printf "%x\n" $strip_size))" \
338 "overlaps the address of the wrapper($link_address)"
339 echo "INFO: Fixing the link_address of wrapper to ($round_size)"
340 link_address=$round_size
341 fi
Paul Mackerras2bf11812006-09-27 22:47:03 +1000342fi
343
Scott Wooda9903812007-03-16 12:27:59 -0500344vmz="$vmz$gzip"
345
David Gibsona6afacb2007-05-01 10:20:20 +1000346# Extract kernel version information, some platforms want to include
347# it in the image header
348version=`${CROSS}strings "$kernel" | grep '^Linux version [-0-9.]' | \
349 cut -d' ' -f3`
350if [ -n "$version" ]; then
351 uboot_version="-n Linux-$version"
352fi
Scott Wood0fdd7172007-04-17 09:25:50 +1000353
Kumar Galab18796d2008-04-16 05:52:29 +1000354# physical offset of kernel image
355membase=`${CROSS}objdump -p "$kernel" | grep -m 1 LOAD | awk '{print $7}'`
356
Scott Wood0fdd7172007-04-17 09:25:50 +1000357case "$platform" in
358uboot)
359 rm -f "$ofile"
Peter Tyser3f884bf2009-12-30 15:23:26 -0700360 ${MKIMAGE} -A ppc -O linux -T kernel -C gzip -a $membase -e $membase \
David Gibsona6afacb2007-05-01 10:20:20 +1000361 $uboot_version -d "$vmz" "$ofile"
Paul Mackerras2bf11812006-09-27 22:47:03 +1000362 if [ -z "$cacheit" ]; then
Scott Wooda9903812007-03-16 12:27:59 -0500363 rm -f "$vmz"
Paul Mackerras2bf11812006-09-27 22:47:03 +1000364 fi
365 exit 0
366 ;;
Benjamin Herrenschmidt11eab2972011-12-01 19:35:08 +0000367uboot-obs600)
368 rm -f "$ofile"
369 # obs600 wants a multi image with an initrd, so we need to put a fake
370 # one in even when building a "normal" image.
371 if [ -n "$initrd" ]; then
372 real_rd="$initrd"
373 else
374 real_rd=`mktemp`
375 echo "\0" >>"$real_rd"
376 fi
377 ${MKIMAGE} -A ppc -O linux -T multi -C gzip -a $membase -e $membase \
378 $uboot_version -d "$vmz":"$real_rd":"$dtb" "$ofile"
379 if [ -z "$initrd" ]; then
380 rm -f "$real_rd"
381 fi
382 if [ -z "$cacheit" ]; then
383 rm -f "$vmz"
384 fi
385 exit 0
386 ;;
Paul Mackerras2bf11812006-09-27 22:47:03 +1000387esac
388
389addsec() {
390 ${CROSS}objcopy $4 $1 \
391 --add-section=$3="$2" \
392 --set-section-flags=$3=contents,alloc,load,readonly,data
393}
394
Scott Wooda9903812007-03-16 12:27:59 -0500395addsec $tmp "$vmz" $ksection $object/empty.o
Paul Mackerras2bf11812006-09-27 22:47:03 +1000396if [ -z "$cacheit" ]; then
Scott Wooda9903812007-03-16 12:27:59 -0500397 rm -f "$vmz"
Paul Mackerras2bf11812006-09-27 22:47:03 +1000398fi
399
400if [ -n "$initrd" ]; then
Mark A. Greerc8885542006-10-16 13:49:27 -0700401 addsec $tmp "$initrd" $isection
Paul Mackerras2bf11812006-09-27 22:47:03 +1000402fi
403
404if [ -n "$dtb" ]; then
Mark A. Greerc8885542006-10-16 13:49:27 -0700405 addsec $tmp "$dtb" .kernel:dtb
Mark A. Greere9c4b4b2006-11-08 17:50:44 -0700406 if [ -n "$dts" ]; then
407 rm $dtb
408 fi
Paul Mackerras2bf11812006-09-27 22:47:03 +1000409fi
410
411if [ "$platform" != "miboot" ]; then
Tony Breeds9b09c6d2008-06-24 14:20:29 +1000412 if [ -n "$link_address" ] ; then
Michael Ellerman6975a782011-04-12 20:38:55 +0000413 text_start="-Ttext $link_address"
Tony Breeds9b09c6d2008-06-24 14:20:29 +1000414 fi
Cédric Le Goater147c0512014-04-24 09:23:39 +0200415 ${CROSS}ld -m $format -T $lds $text_start $pie -o "$ofile" \
David Gibsoncd197ff2007-03-05 14:24:52 +1100416 $platformo $tmp $object/wrapper.a
Paul Mackerras2bf11812006-09-27 22:47:03 +1000417 rm $tmp
418fi
419
David Gibsona6afacb2007-05-01 10:20:20 +1000420# Some platforms need the zImage's entry point and base address
421base=0x`${CROSS}nm "$ofile" | grep ' _start$' | cut -d' ' -f1`
422entry=`${CROSS}objdump -f "$ofile" | grep '^start address ' | cut -d' ' -f3`
423
Scott Wood11c146c2007-09-14 14:58:25 -0500424if [ -n "$binary" ]; then
425 mv "$ofile" "$ofile".elf
Scott Woodaeb45522007-10-25 02:56:28 +1000426 ${CROSS}objcopy -O binary "$ofile".elf "$ofile"
Scott Wood11c146c2007-09-14 14:58:25 -0500427fi
428
Paul Mackerras2bf11812006-09-27 22:47:03 +1000429# post-processing needed for some platforms
430case "$platform" in
Corey Minyard58706ef2010-01-29 14:18:20 +0000431pseries|chrp|maple)
Paul Mackerras5663a122008-10-31 22:27:17 +1100432 $objbin/addnote "$ofile"
Paul Mackerras0dcd4402008-10-20 17:42:42 +0000433 ;;
Milton Miller627aa942007-05-31 01:29:01 +1000434coff)
David Gibsoncd197ff2007-03-05 14:24:52 +1100435 ${CROSS}objcopy -O aixcoff-rs6000 --set-start "$entry" "$ofile"
David Woodhouse5c539ee32007-12-03 13:52:05 +1100436 $objbin/hack-coff "$ofile"
Paul Mackerras2bf11812006-09-27 22:47:03 +1000437 ;;
Scott Wood0fdd7172007-04-17 09:25:50 +1000438cuboot*)
Michal Marekc4f56af2011-04-05 04:58:50 +0000439 gzip -n -f -9 "$ofile"
Peter Tyser3f884bf2009-12-30 15:23:26 -0700440 ${MKIMAGE} -A ppc -O linux -T kernel -C gzip -a "$base" -e "$entry" \
Scott Woodaeb45522007-10-25 02:56:28 +1000441 $uboot_version -d "$ofile".gz "$ofile"
Scott Wood0fdd7172007-04-17 09:25:50 +1000442 ;;
David Gibsonf6dfc802007-05-08 14:10:01 +1000443treeboot*)
444 mv "$ofile" "$ofile.elf"
David Woodhouse5c539ee32007-12-03 13:52:05 +1100445 $objbin/mktree "$ofile.elf" "$ofile" "$base" "$entry"
David Gibsonf6dfc802007-05-08 14:10:01 +1000446 if [ -z "$cacheit" ]; then
447 rm -f "$ofile.elf"
448 fi
449 exit 0
450 ;;
Geoff Levandbafdb642007-07-04 09:07:18 +1000451ps3)
Geoff Levand5761eaa2008-03-28 07:41:45 +1100452 # The ps3's loader supports loading a gzipped binary image from flash
453 # rom to ram addr zero. The loader then enters the system reset
454 # vector at addr 0x100. A bootwrapper overlay is used to arrange for
455 # a binary image of the kernel to be at addr zero, and yet have a
456 # suitable bootwrapper entry at 0x100. To construct the final rom
457 # image 512 bytes from offset 0x100 is copied to the bootwrapper
458 # place holder at symbol __system_reset_kernel. The 512 bytes of the
459 # bootwrapper entry code at symbol __system_reset_overlay is then
460 # copied to offset 0x100. At runtime the bootwrapper program copies
461 # the data at __system_reset_kernel back to addr 0x100.
Geoff Levandbafdb642007-07-04 09:07:18 +1000462
Scott Woodaeb45522007-10-25 02:56:28 +1000463 system_reset_overlay=0x`${CROSS}nm "$ofile" \
Geoff Levandbafdb642007-07-04 09:07:18 +1000464 | grep ' __system_reset_overlay$' \
465 | cut -d' ' -f1`
466 system_reset_overlay=`printf "%d" $system_reset_overlay`
Scott Woodaeb45522007-10-25 02:56:28 +1000467 system_reset_kernel=0x`${CROSS}nm "$ofile" \
Geoff Levandbafdb642007-07-04 09:07:18 +1000468 | grep ' __system_reset_kernel$' \
469 | cut -d' ' -f1`
470 system_reset_kernel=`printf "%d" $system_reset_kernel`
471 overlay_dest="256"
Geoff Levand5761eaa2008-03-28 07:41:45 +1100472 overlay_size="512"
Geoff Levandbafdb642007-07-04 09:07:18 +1000473
Scott Woodaeb45522007-10-25 02:56:28 +1000474 ${CROSS}objcopy -O binary "$ofile" "$ofile.bin"
475
Geoff Levand879c26d2015-10-19 10:53:26 -0700476 run_cmd dd if="$ofile.bin" of="$ofile.bin" conv=notrunc \
477 skip=$overlay_dest seek=$system_reset_kernel \
Grant Likelyd4740372007-10-23 14:27:36 +1000478 count=$overlay_size bs=1
Geoff Levandbafdb642007-07-04 09:07:18 +1000479
Geoff Levand879c26d2015-10-19 10:53:26 -0700480 run_cmd dd if="$ofile.bin" of="$ofile.bin" conv=notrunc \
481 skip=$system_reset_overlay seek=$overlay_dest \
Grant Likelyd4740372007-10-23 14:27:36 +1000482 count=$overlay_size bs=1
Geoff Levandbafdb642007-07-04 09:07:18 +1000483
David Woodhouse928b9692007-12-03 13:48:03 +1100484 odir="$(dirname "$ofile.bin")"
485 rm -f "$odir/otheros.bld"
Michal Marekc4f56af2011-04-05 04:58:50 +0000486 gzip -n --force -9 --stdout "$ofile.bin" > "$odir/otheros.bld"
Geoff Levandbafdb642007-07-04 09:07:18 +1000487 ;;
Paul Mackerras2bf11812006-09-27 22:47:03 +1000488esac