blob: ae0f88ec4a3295e570c1032f6feb323aa5038473 [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
66while [ "$#" -gt 0 ]; do
67 case "$1" in
68 -o)
69 shift
70 [ "$#" -gt 0 ] || usage
71 ofile="$1"
72 ;;
73 -p)
74 shift
75 [ "$#" -gt 0 ] || usage
76 platform="$1"
77 ;;
78 -i)
79 shift
80 [ "$#" -gt 0 ] || usage
81 initrd="$1"
82 ;;
83 -d)
84 shift
85 [ "$#" -gt 0 ] || usage
86 dtb="$1"
87 ;;
88 -s)
89 shift
90 [ "$#" -gt 0 ] || usage
91 dts="$1"
92 ;;
93 -c)
94 cacheit=y
95 ;;
96 -C)
97 shift
98 [ "$#" -gt 0 ] || usage
99 CROSS="$1"
100 ;;
101 -D)
102 shift
103 [ "$#" -gt 0 ] || usage
104 object="$1"
David Woodhouse5c539ee32007-12-03 13:52:05 +1100105 objbin="$1"
Paul Mackerras2bf11812006-09-27 22:47:03 +1000106 ;;
107 -W)
108 shift
109 [ "$#" -gt 0 ] || usage
110 tmpdir="$1"
111 ;;
Scott Wooda9903812007-03-16 12:27:59 -0500112 --no-gzip)
113 gzip=
114 ;;
Paul Mackerras2bf11812006-09-27 22:47:03 +1000115 -?)
116 usage
117 ;;
118 *)
119 [ -z "$kernel" ] || usage
120 kernel="$1"
121 ;;
122 esac
123 shift
124done
125
126if [ -n "$dts" ]; then
David Woodhouse701172d12007-12-03 13:49:24 +1100127 if [ ! -r "$dts" -a -r "$object/dts/$dts" ]; then
128 dts="$object/dts/$dts"
129 fi
Paul Mackerras2bf11812006-09-27 22:47:03 +1000130 if [ -z "$dtb" ]; then
131 dtb="$platform.dtb"
132 fi
Lucian Adrian Grijincuc79b2972009-07-23 00:13:37 +0000133 $dtc -O dtb -o "$dtb" -b 0 "$dts"
Paul Mackerras2bf11812006-09-27 22:47:03 +1000134fi
135
136if [ -z "$kernel" ]; then
137 kernel=vmlinux
138fi
139
Cédric Le Goater147c0512014-04-24 09:23:39 +0200140elfformat="`${CROSS}objdump -p "$kernel" | grep 'file format' | awk '{print $4}'`"
141case "$elfformat" in
142 elf64-powerpcle) format=elf64lppc ;;
143 elf64-powerpc) format=elf32ppc ;;
144 elf32-powerpc) format=elf32ppc ;;
145esac
146
147
Paul Mackerras2bf11812006-09-27 22:47:03 +1000148platformo=$object/"$platform".o
149lds=$object/zImage.lds
150ext=strip
151objflags=-S
152tmp=$tmpdir/zImage.$$.o
153ksection=.kernel:vmlinux.strip
154isection=.kernel:initrd
Tony Breeds9b09c6d2008-06-24 14:20:29 +1000155link_address='0x400000'
Stephen Rothwelldfbc2d72012-03-20 14:13:51 +1100156make_space=y
Paul Mackerras2bf11812006-09-27 22:47:03 +1000157
158case "$platform" in
Benjamin Herrenschmidt44790a02013-11-05 10:09:11 +1100159of)
160 platformo="$object/of.o $object/epapr.o"
161 make_space=n
162 ;;
Tony Breeds9b09c6d2008-06-24 14:20:29 +1000163pseries)
Cédric Le Goater2d9afb32014-04-24 09:23:38 +0200164 platformo="$object/pseries-head.o $object/of.o $object/epapr.o"
Tony Breeds9b09c6d2008-06-24 14:20:29 +1000165 link_address='0x4000000'
Cédric Le Goater147c0512014-04-24 09:23:39 +0200166 if [ "$format" != "elf32ppc" ]; then
167 link_address=
168 pie=-pie
169 fi
Paul Mackerrasf5467e22013-10-29 16:21:26 +1100170 make_space=n
Tony Breeds9b09c6d2008-06-24 14:20:29 +1000171 ;;
Corey Minyard58706ef2010-01-29 14:18:20 +0000172maple)
Benjamin Herrenschmidt0c9fa292013-09-24 16:10:38 +1000173 platformo="$object/of.o $object/epapr.o"
Corey Minyard58706ef2010-01-29 14:18:20 +0000174 link_address='0x400000'
Paul Mackerrasf5467e22013-10-29 16:21:26 +1100175 make_space=n
Corey Minyard58706ef2010-01-29 14:18:20 +0000176 ;;
Tony Breeds9b09c6d2008-06-24 14:20:29 +1000177pmac|chrp)
Benjamin Herrenschmidt0c9fa292013-09-24 16:10:38 +1000178 platformo="$object/of.o $object/epapr.o"
Paul Mackerrasf5467e22013-10-29 16:21:26 +1100179 make_space=n
Paul Mackerras2bf11812006-09-27 22:47:03 +1000180 ;;
Milton Miller627aa942007-05-31 01:29:01 +1000181coff)
Benjamin Herrenschmidt0c9fa292013-09-24 16:10:38 +1000182 platformo="$object/crt0.o $object/of.o $object/epapr.o"
Paul Mackerras2bf11812006-09-27 22:47:03 +1000183 lds=$object/zImage.coff.lds
Tony Breeds9b09c6d2008-06-24 14:20:29 +1000184 link_address='0x500000'
Paul Mackerrasf5467e22013-10-29 16:21:26 +1100185 make_space=n
Michael Ellerman6975a782011-04-12 20:38:55 +0000186 pie=
Paul Mackerras2bf11812006-09-27 22:47:03 +1000187 ;;
Benjamin Herrenschmidt11eab2972011-12-01 19:35:08 +0000188miboot|uboot*)
Paul Mackerras2bf11812006-09-27 22:47:03 +1000189 # miboot and U-boot want just the bare bits, not an ELF binary
190 ext=bin
191 objflags="-O binary"
192 tmp="$ofile"
193 ksection=image
194 isection=initrd
195 ;;
Scott Wood0fdd7172007-04-17 09:25:50 +1000196cuboot*)
Scott Wood11c146c2007-09-14 14:58:25 -0500197 binary=y
Scott Wood0fdd7172007-04-17 09:25:50 +1000198 gzip=
Grant Likely25431332008-02-07 05:18:34 +1100199 case "$platform" in
Scott Wood8dd217b2008-07-31 19:10:22 +0300200 *-mpc866ads|*-mpc885ads|*-adder875*|*-ep88xc)
Grant Likely25431332008-02-07 05:18:34 +1100201 platformo=$object/cuboot-8xx.o
202 ;;
203 *5200*|*-motionpro)
204 platformo=$object/cuboot-52xx.o
205 ;;
206 *-pq2fads|*-ep8248e|*-mpc8272*|*-storcenter)
207 platformo=$object/cuboot-pq2.o
208 ;;
209 *-mpc824*)
210 platformo=$object/cuboot-824x.o
211 ;;
Bryan O'Donoghue59d13f92008-05-08 13:47:00 +0100212 *-mpc83*|*-asp834x*)
Grant Likely25431332008-02-07 05:18:34 +1100213 platformo=$object/cuboot-83xx.o
214 ;;
Alexandr Smirnovff880112008-03-04 19:34:26 +0300215 *-tqm8541|*-mpc8560*|*-tqm8560|*-tqm8555|*-ksi8560*)
Grant Likely25431332008-02-07 05:18:34 +1100216 platformo=$object/cuboot-85xx-cpm2.o
217 ;;
Wolfgang Grandegger6dd1b642008-06-06 13:50:04 +0200218 *-mpc85*|*-tqm85*|*-sbc85*)
Grant Likely25431332008-02-07 05:18:34 +1100219 platformo=$object/cuboot-85xx.o
220 ;;
Gerhard Pircher8f237352009-02-10 12:26:11 +0000221 *-amigaone)
222 link_address='0x800000'
223 ;;
Grant Likely25431332008-02-07 05:18:34 +1100224 esac
Scott Wood0fdd7172007-04-17 09:25:50 +1000225 ;;
Geoff Levandbafdb642007-07-04 09:07:18 +1000226ps3)
227 platformo="$object/ps3-head.o $object/ps3-hvcall.o $object/ps3.o"
228 lds=$object/zImage.ps3.lds
229 gzip=
230 ext=bin
231 objflags="-O binary --set-section-flags=.bss=contents,alloc,load,data"
232 ksection=.kernel:vmlinux.bin
233 isection=.kernel:initrd
Tony Breeds9b09c6d2008-06-24 14:20:29 +1000234 link_address=''
Stephen Rothwelldfbc2d72012-03-20 14:13:51 +1100235 make_space=n
Michael Ellerman6975a782011-04-12 20:38:55 +0000236 pie=
Geoff Levandbafdb642007-07-04 09:07:18 +1000237 ;;
Scott Wooda55387e2008-02-20 12:33:38 -0600238ep88xc|ep405|ep8248e)
Scott Wood11c146c2007-09-14 14:58:25 -0500239 platformo="$object/fixed-head.o $object/$platform.o"
240 binary=y
241 ;;
Scott Wooda55387e2008-02-20 12:33:38 -0600242adder875-redboot)
243 platformo="$object/fixed-head.o $object/redboot-8xx.o"
244 binary=y
245 ;;
Grant Likelyd2477b52008-03-19 04:07:43 +1100246simpleboot-virtex405-*)
John Linnd58577d2008-07-02 15:11:28 -0700247 platformo="$object/virtex405-head.o $object/simpleboot.o $object/virtex.o"
248 binary=y
249 ;;
250simpleboot-virtex440-*)
Grant Likelya7e1cf02009-03-11 09:36:26 -0600251 platformo="$object/fixed-head.o $object/simpleboot.o $object/virtex.o"
Grant Likelyd2477b52008-03-19 04:07:43 +1100252 binary=y
253 ;;
Grant Likely1d46e372008-07-04 00:59:37 -0600254simpleboot-*)
Grant Likelya7e1cf02009-03-11 09:36:26 -0600255 platformo="$object/fixed-head.o $object/simpleboot.o"
Grant Likely1d46e372008-07-04 00:59:37 -0600256 binary=y
257 ;;
Bryan O'Donoghue59d13f92008-05-08 13:47:00 +0100258asp834x-redboot)
259 platformo="$object/fixed-head.o $object/redboot-83xx.o"
260 binary=y
261 ;;
Nate Case24760822009-06-11 14:43:01 -0500262xpedite52*)
263 link_address='0x1400000'
264 platformo=$object/cuboot-85xx.o
265 ;;
Albert Herranz6cdd24172009-12-12 06:31:45 +0000266gamecube|wii)
Albert Herranzb68a24b2009-12-12 06:31:36 +0000267 link_address='0x600000'
268 platformo="$object/$platform-head.o $object/$platform.o"
269 ;;
Tony Breeds228d5502011-11-30 21:39:24 +0000270treeboot-currituck)
271 link_address='0x1000000'
272 ;;
Alistair Popple2a2c74b2014-03-06 14:52:27 +1100273treeboot-akebono)
274 link_address='0x1000000'
275 ;;
Torez Smithb4e8c8d2010-03-05 10:45:54 +0000276treeboot-iss4xx-mpic)
277 platformo="$object/treeboot-iss4xx.o"
278 ;;
David Gibson6c5b59b2011-04-14 18:29:16 +0000279epapr)
Benjamin Herrenschmidt0c9fa292013-09-24 16:10:38 +1000280 platformo="$object/epapr.o $object/epapr-wrapper.o"
David Gibson6c5b59b2011-04-14 18:29:16 +0000281 link_address='0x20000000'
282 pie=-pie
283 ;;
Stephen Chiversbe201982014-01-09 13:01:22 +1100284mvme5100)
285 platformo="$object/fixed-head.o $object/mvme5100.o"
286 binary=y
287 ;;
Paul Mackerras2bf11812006-09-27 22:47:03 +1000288esac
289
290vmz="$tmpdir/`basename \"$kernel\"`.$ext"
Milton Miller1383a342007-03-28 02:21:04 -0600291if [ -z "$cacheit" -o ! -f "$vmz$gzip" -o "$vmz$gzip" -ot "$kernel" ]; then
Paul Mackerras2bf11812006-09-27 22:47:03 +1000292 ${CROSS}objcopy $objflags "$kernel" "$vmz.$$"
Scott Wooda9903812007-03-16 12:27:59 -0500293
Suzuki Poulosec55aef02011-12-14 22:59:57 +0000294 strip_size=$(stat -c %s $vmz.$$)
295
Scott Wooda9903812007-03-16 12:27:59 -0500296 if [ -n "$gzip" ]; then
Michal Marekc4f56af2011-04-05 04:58:50 +0000297 gzip -n -f -9 "$vmz.$$"
Scott Wooda9903812007-03-16 12:27:59 -0500298 fi
299
Paul Mackerras2bf11812006-09-27 22:47:03 +1000300 if [ -n "$cacheit" ]; then
Scott Wooda9903812007-03-16 12:27:59 -0500301 mv -f "$vmz.$$$gzip" "$vmz$gzip"
Paul Mackerras2bf11812006-09-27 22:47:03 +1000302 else
303 vmz="$vmz.$$"
304 fi
Suzuki Poulosec55aef02011-12-14 22:59:57 +0000305else
306 # Calculate the vmlinux.strip size
307 ${CROSS}objcopy $objflags "$kernel" "$vmz.$$"
308 strip_size=$(stat -c %s $vmz.$$)
309 rm -f $vmz.$$
310fi
311
Stephen Rothwelldfbc2d72012-03-20 14:13:51 +1100312if [ "$make_space" = "y" ]; then
313 # Round the size to next higher MB limit
314 round_size=$(((strip_size + 0xfffff) & 0xfff00000))
Suzuki Poulosec55aef02011-12-14 22:59:57 +0000315
Stephen Rothwelldfbc2d72012-03-20 14:13:51 +1100316 round_size=0x$(printf "%x" $round_size)
317 link_addr=$(printf "%d" $link_address)
Suzuki Poulosec55aef02011-12-14 22:59:57 +0000318
Stephen Rothwelldfbc2d72012-03-20 14:13:51 +1100319 if [ $link_addr -lt $strip_size ]; then
320 echo "INFO: Uncompressed kernel (size 0x$(printf "%x\n" $strip_size))" \
321 "overlaps the address of the wrapper($link_address)"
322 echo "INFO: Fixing the link_address of wrapper to ($round_size)"
323 link_address=$round_size
324 fi
Paul Mackerras2bf11812006-09-27 22:47:03 +1000325fi
326
Scott Wooda9903812007-03-16 12:27:59 -0500327vmz="$vmz$gzip"
328
David Gibsona6afacb2007-05-01 10:20:20 +1000329# Extract kernel version information, some platforms want to include
330# it in the image header
331version=`${CROSS}strings "$kernel" | grep '^Linux version [-0-9.]' | \
332 cut -d' ' -f3`
333if [ -n "$version" ]; then
334 uboot_version="-n Linux-$version"
335fi
Scott Wood0fdd7172007-04-17 09:25:50 +1000336
Kumar Galab18796d2008-04-16 05:52:29 +1000337# physical offset of kernel image
338membase=`${CROSS}objdump -p "$kernel" | grep -m 1 LOAD | awk '{print $7}'`
339
Scott Wood0fdd7172007-04-17 09:25:50 +1000340case "$platform" in
341uboot)
342 rm -f "$ofile"
Peter Tyser3f884bf2009-12-30 15:23:26 -0700343 ${MKIMAGE} -A ppc -O linux -T kernel -C gzip -a $membase -e $membase \
David Gibsona6afacb2007-05-01 10:20:20 +1000344 $uboot_version -d "$vmz" "$ofile"
Paul Mackerras2bf11812006-09-27 22:47:03 +1000345 if [ -z "$cacheit" ]; then
Scott Wooda9903812007-03-16 12:27:59 -0500346 rm -f "$vmz"
Paul Mackerras2bf11812006-09-27 22:47:03 +1000347 fi
348 exit 0
349 ;;
Benjamin Herrenschmidt11eab2972011-12-01 19:35:08 +0000350uboot-obs600)
351 rm -f "$ofile"
352 # obs600 wants a multi image with an initrd, so we need to put a fake
353 # one in even when building a "normal" image.
354 if [ -n "$initrd" ]; then
355 real_rd="$initrd"
356 else
357 real_rd=`mktemp`
358 echo "\0" >>"$real_rd"
359 fi
360 ${MKIMAGE} -A ppc -O linux -T multi -C gzip -a $membase -e $membase \
361 $uboot_version -d "$vmz":"$real_rd":"$dtb" "$ofile"
362 if [ -z "$initrd" ]; then
363 rm -f "$real_rd"
364 fi
365 if [ -z "$cacheit" ]; then
366 rm -f "$vmz"
367 fi
368 exit 0
369 ;;
Paul Mackerras2bf11812006-09-27 22:47:03 +1000370esac
371
372addsec() {
373 ${CROSS}objcopy $4 $1 \
374 --add-section=$3="$2" \
375 --set-section-flags=$3=contents,alloc,load,readonly,data
376}
377
Scott Wooda9903812007-03-16 12:27:59 -0500378addsec $tmp "$vmz" $ksection $object/empty.o
Paul Mackerras2bf11812006-09-27 22:47:03 +1000379if [ -z "$cacheit" ]; then
Scott Wooda9903812007-03-16 12:27:59 -0500380 rm -f "$vmz"
Paul Mackerras2bf11812006-09-27 22:47:03 +1000381fi
382
383if [ -n "$initrd" ]; then
Mark A. Greerc8885542006-10-16 13:49:27 -0700384 addsec $tmp "$initrd" $isection
Paul Mackerras2bf11812006-09-27 22:47:03 +1000385fi
386
387if [ -n "$dtb" ]; then
Mark A. Greerc8885542006-10-16 13:49:27 -0700388 addsec $tmp "$dtb" .kernel:dtb
Mark A. Greere9c4b4b2006-11-08 17:50:44 -0700389 if [ -n "$dts" ]; then
390 rm $dtb
391 fi
Paul Mackerras2bf11812006-09-27 22:47:03 +1000392fi
393
394if [ "$platform" != "miboot" ]; then
Tony Breeds9b09c6d2008-06-24 14:20:29 +1000395 if [ -n "$link_address" ] ; then
Michael Ellerman6975a782011-04-12 20:38:55 +0000396 text_start="-Ttext $link_address"
Tony Breeds9b09c6d2008-06-24 14:20:29 +1000397 fi
Cédric Le Goater147c0512014-04-24 09:23:39 +0200398 ${CROSS}ld -m $format -T $lds $text_start $pie -o "$ofile" \
David Gibsoncd197ff2007-03-05 14:24:52 +1100399 $platformo $tmp $object/wrapper.a
Paul Mackerras2bf11812006-09-27 22:47:03 +1000400 rm $tmp
401fi
402
David Gibsona6afacb2007-05-01 10:20:20 +1000403# Some platforms need the zImage's entry point and base address
404base=0x`${CROSS}nm "$ofile" | grep ' _start$' | cut -d' ' -f1`
405entry=`${CROSS}objdump -f "$ofile" | grep '^start address ' | cut -d' ' -f3`
406
Scott Wood11c146c2007-09-14 14:58:25 -0500407if [ -n "$binary" ]; then
408 mv "$ofile" "$ofile".elf
Scott Woodaeb45522007-10-25 02:56:28 +1000409 ${CROSS}objcopy -O binary "$ofile".elf "$ofile"
Scott Wood11c146c2007-09-14 14:58:25 -0500410fi
411
Paul Mackerras2bf11812006-09-27 22:47:03 +1000412# post-processing needed for some platforms
413case "$platform" in
Corey Minyard58706ef2010-01-29 14:18:20 +0000414pseries|chrp|maple)
Paul Mackerras5663a122008-10-31 22:27:17 +1100415 $objbin/addnote "$ofile"
Paul Mackerras0dcd4402008-10-20 17:42:42 +0000416 ;;
Milton Miller627aa942007-05-31 01:29:01 +1000417coff)
David Gibsoncd197ff2007-03-05 14:24:52 +1100418 ${CROSS}objcopy -O aixcoff-rs6000 --set-start "$entry" "$ofile"
David Woodhouse5c539ee32007-12-03 13:52:05 +1100419 $objbin/hack-coff "$ofile"
Paul Mackerras2bf11812006-09-27 22:47:03 +1000420 ;;
Scott Wood0fdd7172007-04-17 09:25:50 +1000421cuboot*)
Michal Marekc4f56af2011-04-05 04:58:50 +0000422 gzip -n -f -9 "$ofile"
Peter Tyser3f884bf2009-12-30 15:23:26 -0700423 ${MKIMAGE} -A ppc -O linux -T kernel -C gzip -a "$base" -e "$entry" \
Scott Woodaeb45522007-10-25 02:56:28 +1000424 $uboot_version -d "$ofile".gz "$ofile"
Scott Wood0fdd7172007-04-17 09:25:50 +1000425 ;;
David Gibsonf6dfc802007-05-08 14:10:01 +1000426treeboot*)
427 mv "$ofile" "$ofile.elf"
David Woodhouse5c539ee32007-12-03 13:52:05 +1100428 $objbin/mktree "$ofile.elf" "$ofile" "$base" "$entry"
David Gibsonf6dfc802007-05-08 14:10:01 +1000429 if [ -z "$cacheit" ]; then
430 rm -f "$ofile.elf"
431 fi
432 exit 0
433 ;;
Geoff Levandbafdb642007-07-04 09:07:18 +1000434ps3)
Geoff Levand5761eaa2008-03-28 07:41:45 +1100435 # The ps3's loader supports loading a gzipped binary image from flash
436 # rom to ram addr zero. The loader then enters the system reset
437 # vector at addr 0x100. A bootwrapper overlay is used to arrange for
438 # a binary image of the kernel to be at addr zero, and yet have a
439 # suitable bootwrapper entry at 0x100. To construct the final rom
440 # image 512 bytes from offset 0x100 is copied to the bootwrapper
441 # place holder at symbol __system_reset_kernel. The 512 bytes of the
442 # bootwrapper entry code at symbol __system_reset_overlay is then
443 # copied to offset 0x100. At runtime the bootwrapper program copies
444 # the data at __system_reset_kernel back to addr 0x100.
Geoff Levandbafdb642007-07-04 09:07:18 +1000445
Scott Woodaeb45522007-10-25 02:56:28 +1000446 system_reset_overlay=0x`${CROSS}nm "$ofile" \
Geoff Levandbafdb642007-07-04 09:07:18 +1000447 | grep ' __system_reset_overlay$' \
448 | cut -d' ' -f1`
449 system_reset_overlay=`printf "%d" $system_reset_overlay`
Scott Woodaeb45522007-10-25 02:56:28 +1000450 system_reset_kernel=0x`${CROSS}nm "$ofile" \
Geoff Levandbafdb642007-07-04 09:07:18 +1000451 | grep ' __system_reset_kernel$' \
452 | cut -d' ' -f1`
453 system_reset_kernel=`printf "%d" $system_reset_kernel`
454 overlay_dest="256"
Geoff Levand5761eaa2008-03-28 07:41:45 +1100455 overlay_size="512"
Geoff Levandbafdb642007-07-04 09:07:18 +1000456
Scott Woodaeb45522007-10-25 02:56:28 +1000457 ${CROSS}objcopy -O binary "$ofile" "$ofile.bin"
458
Grant Likelyd4740372007-10-23 14:27:36 +1000459 dd if="$ofile.bin" of="$ofile.bin" conv=notrunc \
460 skip=$overlay_dest seek=$system_reset_kernel \
461 count=$overlay_size bs=1
Geoff Levandbafdb642007-07-04 09:07:18 +1000462
Grant Likelyd4740372007-10-23 14:27:36 +1000463 dd if="$ofile.bin" of="$ofile.bin" conv=notrunc \
464 skip=$system_reset_overlay seek=$overlay_dest \
465 count=$overlay_size bs=1
Geoff Levandbafdb642007-07-04 09:07:18 +1000466
David Woodhouse928b9692007-12-03 13:48:03 +1100467 odir="$(dirname "$ofile.bin")"
468 rm -f "$odir/otheros.bld"
Michal Marekc4f56af2011-04-05 04:58:50 +0000469 gzip -n --force -9 --stdout "$ofile.bin" > "$odir/otheros.bld"
Geoff Levandbafdb642007-07-04 09:07:18 +1000470 ;;
Paul Mackerras2bf11812006-09-27 22:47:03 +1000471esac