Paul Mackerras | 2bf1181 | 2006-09-27 22:47:03 +1000 | [diff] [blame] | 1 | #!/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 Likely | d474037 | 2007-10-23 14:27:36 +1000 | [diff] [blame] | 24 | # Stop execution if any command fails |
| 25 | set -e |
| 26 | |
Grant Likely | 7f66c1f | 2007-10-23 14:27:31 +1000 | [diff] [blame] | 27 | # Allow for verbose output |
| 28 | if [ "$V" = 1 ]; then |
| 29 | set -x |
| 30 | fi |
| 31 | |
Paul Mackerras | 2bf1181 | 2006-09-27 22:47:03 +1000 | [diff] [blame] | 32 | # defaults |
| 33 | kernel= |
| 34 | ofile=zImage |
| 35 | platform=of |
| 36 | initrd= |
| 37 | dtb= |
| 38 | dts= |
| 39 | cacheit= |
Scott Wood | 11c146c | 2007-09-14 14:58:25 -0500 | [diff] [blame] | 40 | binary= |
Scott Wood | a990381 | 2007-03-16 12:27:59 -0500 | [diff] [blame] | 41 | gzip=.gz |
Paul Mackerras | 2bf1181 | 2006-09-27 22:47:03 +1000 | [diff] [blame] | 42 | |
| 43 | # cross-compilation prefix |
| 44 | CROSS= |
| 45 | |
| 46 | # directory for object and other files used by this script |
| 47 | object=arch/powerpc/boot |
David Woodhouse | 5c539ee | 2007-12-03 13:52:05 +1100 | [diff] [blame] | 48 | objbin=$object |
Lucian Adrian Grijincu | c79b297 | 2009-07-23 00:13:37 +0000 | [diff] [blame^] | 49 | dtc=scripts/dtc/dtc |
Paul Mackerras | 2bf1181 | 2006-09-27 22:47:03 +1000 | [diff] [blame] | 50 | |
| 51 | # directory for working files |
| 52 | tmpdir=. |
| 53 | |
| 54 | usage() { |
| 55 | echo 'Usage: wrapper [-o output] [-p platform] [-i initrd]' >&2 |
| 56 | echo ' [-d devtree] [-s tree.dts] [-c] [-C cross-prefix]' >&2 |
Scott Wood | a990381 | 2007-03-16 12:27:59 -0500 | [diff] [blame] | 57 | echo ' [-D datadir] [-W workingdir] [--no-gzip] [vmlinux]' >&2 |
Paul Mackerras | 2bf1181 | 2006-09-27 22:47:03 +1000 | [diff] [blame] | 58 | exit 1 |
| 59 | } |
| 60 | |
| 61 | while [ "$#" -gt 0 ]; do |
| 62 | case "$1" in |
| 63 | -o) |
| 64 | shift |
| 65 | [ "$#" -gt 0 ] || usage |
| 66 | ofile="$1" |
| 67 | ;; |
| 68 | -p) |
| 69 | shift |
| 70 | [ "$#" -gt 0 ] || usage |
| 71 | platform="$1" |
| 72 | ;; |
| 73 | -i) |
| 74 | shift |
| 75 | [ "$#" -gt 0 ] || usage |
| 76 | initrd="$1" |
| 77 | ;; |
| 78 | -d) |
| 79 | shift |
| 80 | [ "$#" -gt 0 ] || usage |
| 81 | dtb="$1" |
| 82 | ;; |
| 83 | -s) |
| 84 | shift |
| 85 | [ "$#" -gt 0 ] || usage |
| 86 | dts="$1" |
| 87 | ;; |
| 88 | -c) |
| 89 | cacheit=y |
| 90 | ;; |
| 91 | -C) |
| 92 | shift |
| 93 | [ "$#" -gt 0 ] || usage |
| 94 | CROSS="$1" |
| 95 | ;; |
| 96 | -D) |
| 97 | shift |
| 98 | [ "$#" -gt 0 ] || usage |
| 99 | object="$1" |
David Woodhouse | 5c539ee | 2007-12-03 13:52:05 +1100 | [diff] [blame] | 100 | objbin="$1" |
Paul Mackerras | 2bf1181 | 2006-09-27 22:47:03 +1000 | [diff] [blame] | 101 | ;; |
| 102 | -W) |
| 103 | shift |
| 104 | [ "$#" -gt 0 ] || usage |
| 105 | tmpdir="$1" |
| 106 | ;; |
Scott Wood | a990381 | 2007-03-16 12:27:59 -0500 | [diff] [blame] | 107 | --no-gzip) |
| 108 | gzip= |
| 109 | ;; |
Paul Mackerras | 2bf1181 | 2006-09-27 22:47:03 +1000 | [diff] [blame] | 110 | -?) |
| 111 | usage |
| 112 | ;; |
| 113 | *) |
| 114 | [ -z "$kernel" ] || usage |
| 115 | kernel="$1" |
| 116 | ;; |
| 117 | esac |
| 118 | shift |
| 119 | done |
| 120 | |
| 121 | if [ -n "$dts" ]; then |
David Woodhouse | 701172d1 | 2007-12-03 13:49:24 +1100 | [diff] [blame] | 122 | if [ ! -r "$dts" -a -r "$object/dts/$dts" ]; then |
| 123 | dts="$object/dts/$dts" |
| 124 | fi |
Paul Mackerras | 2bf1181 | 2006-09-27 22:47:03 +1000 | [diff] [blame] | 125 | if [ -z "$dtb" ]; then |
| 126 | dtb="$platform.dtb" |
| 127 | fi |
Lucian Adrian Grijincu | c79b297 | 2009-07-23 00:13:37 +0000 | [diff] [blame^] | 128 | $dtc -O dtb -o "$dtb" -b 0 "$dts" |
Paul Mackerras | 2bf1181 | 2006-09-27 22:47:03 +1000 | [diff] [blame] | 129 | fi |
| 130 | |
| 131 | if [ -z "$kernel" ]; then |
| 132 | kernel=vmlinux |
| 133 | fi |
| 134 | |
| 135 | platformo=$object/"$platform".o |
| 136 | lds=$object/zImage.lds |
| 137 | ext=strip |
| 138 | objflags=-S |
| 139 | tmp=$tmpdir/zImage.$$.o |
| 140 | ksection=.kernel:vmlinux.strip |
| 141 | isection=.kernel:initrd |
Tony Breeds | 9b09c6d | 2008-06-24 14:20:29 +1000 | [diff] [blame] | 142 | link_address='0x400000' |
Paul Mackerras | 2bf1181 | 2006-09-27 22:47:03 +1000 | [diff] [blame] | 143 | |
| 144 | case "$platform" in |
Tony Breeds | 9b09c6d | 2008-06-24 14:20:29 +1000 | [diff] [blame] | 145 | pseries) |
| 146 | platformo=$object/of.o |
| 147 | link_address='0x4000000' |
| 148 | ;; |
| 149 | pmac|chrp) |
Paul Mackerras | 2bf1181 | 2006-09-27 22:47:03 +1000 | [diff] [blame] | 150 | platformo=$object/of.o |
| 151 | ;; |
Milton Miller | 627aa94 | 2007-05-31 01:29:01 +1000 | [diff] [blame] | 152 | coff) |
Paul Mackerras | 2bf1181 | 2006-09-27 22:47:03 +1000 | [diff] [blame] | 153 | platformo=$object/of.o |
| 154 | lds=$object/zImage.coff.lds |
Tony Breeds | 9b09c6d | 2008-06-24 14:20:29 +1000 | [diff] [blame] | 155 | link_address='0x500000' |
Paul Mackerras | 2bf1181 | 2006-09-27 22:47:03 +1000 | [diff] [blame] | 156 | ;; |
| 157 | miboot|uboot) |
| 158 | # miboot and U-boot want just the bare bits, not an ELF binary |
| 159 | ext=bin |
| 160 | objflags="-O binary" |
| 161 | tmp="$ofile" |
| 162 | ksection=image |
| 163 | isection=initrd |
| 164 | ;; |
Scott Wood | 0fdd717 | 2007-04-17 09:25:50 +1000 | [diff] [blame] | 165 | cuboot*) |
Scott Wood | 11c146c | 2007-09-14 14:58:25 -0500 | [diff] [blame] | 166 | binary=y |
Scott Wood | 0fdd717 | 2007-04-17 09:25:50 +1000 | [diff] [blame] | 167 | gzip= |
Grant Likely | 2543133 | 2008-02-07 05:18:34 +1100 | [diff] [blame] | 168 | case "$platform" in |
Scott Wood | 8dd217b | 2008-07-31 19:10:22 +0300 | [diff] [blame] | 169 | *-mpc866ads|*-mpc885ads|*-adder875*|*-ep88xc) |
Grant Likely | 2543133 | 2008-02-07 05:18:34 +1100 | [diff] [blame] | 170 | platformo=$object/cuboot-8xx.o |
| 171 | ;; |
| 172 | *5200*|*-motionpro) |
| 173 | platformo=$object/cuboot-52xx.o |
| 174 | ;; |
| 175 | *-pq2fads|*-ep8248e|*-mpc8272*|*-storcenter) |
| 176 | platformo=$object/cuboot-pq2.o |
| 177 | ;; |
| 178 | *-mpc824*) |
| 179 | platformo=$object/cuboot-824x.o |
| 180 | ;; |
Bryan O'Donoghue | 59d13f9 | 2008-05-08 13:47:00 +0100 | [diff] [blame] | 181 | *-mpc83*|*-asp834x*) |
Grant Likely | 2543133 | 2008-02-07 05:18:34 +1100 | [diff] [blame] | 182 | platformo=$object/cuboot-83xx.o |
| 183 | ;; |
Alexandr Smirnov | ff88011 | 2008-03-04 19:34:26 +0300 | [diff] [blame] | 184 | *-tqm8541|*-mpc8560*|*-tqm8560|*-tqm8555|*-ksi8560*) |
Grant Likely | 2543133 | 2008-02-07 05:18:34 +1100 | [diff] [blame] | 185 | platformo=$object/cuboot-85xx-cpm2.o |
| 186 | ;; |
Wolfgang Grandegger | 6dd1b64 | 2008-06-06 13:50:04 +0200 | [diff] [blame] | 187 | *-mpc85*|*-tqm85*|*-sbc85*) |
Grant Likely | 2543133 | 2008-02-07 05:18:34 +1100 | [diff] [blame] | 188 | platformo=$object/cuboot-85xx.o |
| 189 | ;; |
Gerhard Pircher | 8f23735 | 2009-02-10 12:26:11 +0000 | [diff] [blame] | 190 | *-amigaone) |
| 191 | link_address='0x800000' |
| 192 | ;; |
Grant Likely | 2543133 | 2008-02-07 05:18:34 +1100 | [diff] [blame] | 193 | esac |
Scott Wood | 0fdd717 | 2007-04-17 09:25:50 +1000 | [diff] [blame] | 194 | ;; |
Geoff Levand | bafdb64 | 2007-07-04 09:07:18 +1000 | [diff] [blame] | 195 | ps3) |
| 196 | platformo="$object/ps3-head.o $object/ps3-hvcall.o $object/ps3.o" |
| 197 | lds=$object/zImage.ps3.lds |
| 198 | gzip= |
| 199 | ext=bin |
| 200 | objflags="-O binary --set-section-flags=.bss=contents,alloc,load,data" |
| 201 | ksection=.kernel:vmlinux.bin |
| 202 | isection=.kernel:initrd |
Tony Breeds | 9b09c6d | 2008-06-24 14:20:29 +1000 | [diff] [blame] | 203 | link_address='' |
Geoff Levand | bafdb64 | 2007-07-04 09:07:18 +1000 | [diff] [blame] | 204 | ;; |
Scott Wood | a55387e | 2008-02-20 12:33:38 -0600 | [diff] [blame] | 205 | ep88xc|ep405|ep8248e) |
Scott Wood | 11c146c | 2007-09-14 14:58:25 -0500 | [diff] [blame] | 206 | platformo="$object/fixed-head.o $object/$platform.o" |
| 207 | binary=y |
| 208 | ;; |
Scott Wood | a55387e | 2008-02-20 12:33:38 -0600 | [diff] [blame] | 209 | adder875-redboot) |
| 210 | platformo="$object/fixed-head.o $object/redboot-8xx.o" |
| 211 | binary=y |
| 212 | ;; |
Grant Likely | d2477b5 | 2008-03-19 04:07:43 +1100 | [diff] [blame] | 213 | simpleboot-virtex405-*) |
John Linn | d58577d | 2008-07-02 15:11:28 -0700 | [diff] [blame] | 214 | platformo="$object/virtex405-head.o $object/simpleboot.o $object/virtex.o" |
| 215 | binary=y |
| 216 | ;; |
| 217 | simpleboot-virtex440-*) |
Grant Likely | a7e1cf0 | 2009-03-11 09:36:26 -0600 | [diff] [blame] | 218 | platformo="$object/fixed-head.o $object/simpleboot.o $object/virtex.o" |
Grant Likely | d2477b5 | 2008-03-19 04:07:43 +1100 | [diff] [blame] | 219 | binary=y |
| 220 | ;; |
Grant Likely | 1d46e37 | 2008-07-04 00:59:37 -0600 | [diff] [blame] | 221 | simpleboot-*) |
Grant Likely | a7e1cf0 | 2009-03-11 09:36:26 -0600 | [diff] [blame] | 222 | platformo="$object/fixed-head.o $object/simpleboot.o" |
Grant Likely | 1d46e37 | 2008-07-04 00:59:37 -0600 | [diff] [blame] | 223 | binary=y |
| 224 | ;; |
Bryan O'Donoghue | 59d13f9 | 2008-05-08 13:47:00 +0100 | [diff] [blame] | 225 | asp834x-redboot) |
| 226 | platformo="$object/fixed-head.o $object/redboot-83xx.o" |
| 227 | binary=y |
| 228 | ;; |
Nate Case | 2476082 | 2009-06-11 14:43:01 -0500 | [diff] [blame] | 229 | xpedite52*) |
| 230 | link_address='0x1400000' |
| 231 | platformo=$object/cuboot-85xx.o |
| 232 | ;; |
Paul Mackerras | 2bf1181 | 2006-09-27 22:47:03 +1000 | [diff] [blame] | 233 | esac |
| 234 | |
| 235 | vmz="$tmpdir/`basename \"$kernel\"`.$ext" |
Milton Miller | 1383a34 | 2007-03-28 02:21:04 -0600 | [diff] [blame] | 236 | if [ -z "$cacheit" -o ! -f "$vmz$gzip" -o "$vmz$gzip" -ot "$kernel" ]; then |
Paul Mackerras | 2bf1181 | 2006-09-27 22:47:03 +1000 | [diff] [blame] | 237 | ${CROSS}objcopy $objflags "$kernel" "$vmz.$$" |
Scott Wood | a990381 | 2007-03-16 12:27:59 -0500 | [diff] [blame] | 238 | |
| 239 | if [ -n "$gzip" ]; then |
| 240 | gzip -f -9 "$vmz.$$" |
| 241 | fi |
| 242 | |
Paul Mackerras | 2bf1181 | 2006-09-27 22:47:03 +1000 | [diff] [blame] | 243 | if [ -n "$cacheit" ]; then |
Scott Wood | a990381 | 2007-03-16 12:27:59 -0500 | [diff] [blame] | 244 | mv -f "$vmz.$$$gzip" "$vmz$gzip" |
Paul Mackerras | 2bf1181 | 2006-09-27 22:47:03 +1000 | [diff] [blame] | 245 | else |
| 246 | vmz="$vmz.$$" |
| 247 | fi |
| 248 | fi |
| 249 | |
Scott Wood | a990381 | 2007-03-16 12:27:59 -0500 | [diff] [blame] | 250 | vmz="$vmz$gzip" |
| 251 | |
David Gibson | a6afacb | 2007-05-01 10:20:20 +1000 | [diff] [blame] | 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.]' | \ |
| 255 | cut -d' ' -f3` |
| 256 | if [ -n "$version" ]; then |
| 257 | uboot_version="-n Linux-$version" |
| 258 | fi |
Scott Wood | 0fdd717 | 2007-04-17 09:25:50 +1000 | [diff] [blame] | 259 | |
Kumar Gala | b18796d | 2008-04-16 05:52:29 +1000 | [diff] [blame] | 260 | # physical offset of kernel image |
| 261 | membase=`${CROSS}objdump -p "$kernel" | grep -m 1 LOAD | awk '{print $7}'` |
| 262 | |
Scott Wood | 0fdd717 | 2007-04-17 09:25:50 +1000 | [diff] [blame] | 263 | case "$platform" in |
| 264 | uboot) |
| 265 | rm -f "$ofile" |
Kumar Gala | b18796d | 2008-04-16 05:52:29 +1000 | [diff] [blame] | 266 | mkimage -A ppc -O linux -T kernel -C gzip -a $membase -e $membase \ |
David Gibson | a6afacb | 2007-05-01 10:20:20 +1000 | [diff] [blame] | 267 | $uboot_version -d "$vmz" "$ofile" |
Paul Mackerras | 2bf1181 | 2006-09-27 22:47:03 +1000 | [diff] [blame] | 268 | if [ -z "$cacheit" ]; then |
Scott Wood | a990381 | 2007-03-16 12:27:59 -0500 | [diff] [blame] | 269 | rm -f "$vmz" |
Paul Mackerras | 2bf1181 | 2006-09-27 22:47:03 +1000 | [diff] [blame] | 270 | fi |
| 271 | exit 0 |
| 272 | ;; |
| 273 | esac |
| 274 | |
| 275 | addsec() { |
| 276 | ${CROSS}objcopy $4 $1 \ |
| 277 | --add-section=$3="$2" \ |
| 278 | --set-section-flags=$3=contents,alloc,load,readonly,data |
| 279 | } |
| 280 | |
Scott Wood | a990381 | 2007-03-16 12:27:59 -0500 | [diff] [blame] | 281 | addsec $tmp "$vmz" $ksection $object/empty.o |
Paul Mackerras | 2bf1181 | 2006-09-27 22:47:03 +1000 | [diff] [blame] | 282 | if [ -z "$cacheit" ]; then |
Scott Wood | a990381 | 2007-03-16 12:27:59 -0500 | [diff] [blame] | 283 | rm -f "$vmz" |
Paul Mackerras | 2bf1181 | 2006-09-27 22:47:03 +1000 | [diff] [blame] | 284 | fi |
| 285 | |
| 286 | if [ -n "$initrd" ]; then |
Mark A. Greer | c888554 | 2006-10-16 13:49:27 -0700 | [diff] [blame] | 287 | addsec $tmp "$initrd" $isection |
Paul Mackerras | 2bf1181 | 2006-09-27 22:47:03 +1000 | [diff] [blame] | 288 | fi |
| 289 | |
| 290 | if [ -n "$dtb" ]; then |
Mark A. Greer | c888554 | 2006-10-16 13:49:27 -0700 | [diff] [blame] | 291 | addsec $tmp "$dtb" .kernel:dtb |
Mark A. Greer | e9c4b4b | 2006-11-08 17:50:44 -0700 | [diff] [blame] | 292 | if [ -n "$dts" ]; then |
| 293 | rm $dtb |
| 294 | fi |
Paul Mackerras | 2bf1181 | 2006-09-27 22:47:03 +1000 | [diff] [blame] | 295 | fi |
| 296 | |
| 297 | if [ "$platform" != "miboot" ]; then |
Tony Breeds | 9b09c6d | 2008-06-24 14:20:29 +1000 | [diff] [blame] | 298 | if [ -n "$link_address" ] ; then |
| 299 | text_start="-Ttext $link_address --defsym _start=$link_address" |
| 300 | fi |
| 301 | ${CROSS}ld -m elf32ppc -T $lds $text_start -o "$ofile" \ |
David Gibson | cd197ff | 2007-03-05 14:24:52 +1100 | [diff] [blame] | 302 | $platformo $tmp $object/wrapper.a |
Paul Mackerras | 2bf1181 | 2006-09-27 22:47:03 +1000 | [diff] [blame] | 303 | rm $tmp |
| 304 | fi |
| 305 | |
David Gibson | a6afacb | 2007-05-01 10:20:20 +1000 | [diff] [blame] | 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` |
| 309 | |
Scott Wood | 11c146c | 2007-09-14 14:58:25 -0500 | [diff] [blame] | 310 | if [ -n "$binary" ]; then |
| 311 | mv "$ofile" "$ofile".elf |
Scott Wood | aeb4552 | 2007-10-25 02:56:28 +1000 | [diff] [blame] | 312 | ${CROSS}objcopy -O binary "$ofile".elf "$ofile" |
Scott Wood | 11c146c | 2007-09-14 14:58:25 -0500 | [diff] [blame] | 313 | fi |
| 314 | |
Paul Mackerras | 2bf1181 | 2006-09-27 22:47:03 +1000 | [diff] [blame] | 315 | # post-processing needed for some platforms |
| 316 | case "$platform" in |
Paul Mackerras | 5663a12 | 2008-10-31 22:27:17 +1100 | [diff] [blame] | 317 | pseries|chrp) |
| 318 | $objbin/addnote "$ofile" |
Paul Mackerras | 0dcd440 | 2008-10-20 17:42:42 +0000 | [diff] [blame] | 319 | ;; |
Milton Miller | 627aa94 | 2007-05-31 01:29:01 +1000 | [diff] [blame] | 320 | coff) |
David Gibson | cd197ff | 2007-03-05 14:24:52 +1100 | [diff] [blame] | 321 | ${CROSS}objcopy -O aixcoff-rs6000 --set-start "$entry" "$ofile" |
David Woodhouse | 5c539ee | 2007-12-03 13:52:05 +1100 | [diff] [blame] | 322 | $objbin/hack-coff "$ofile" |
Paul Mackerras | 2bf1181 | 2006-09-27 22:47:03 +1000 | [diff] [blame] | 323 | ;; |
Scott Wood | 0fdd717 | 2007-04-17 09:25:50 +1000 | [diff] [blame] | 324 | cuboot*) |
Scott Wood | aeb4552 | 2007-10-25 02:56:28 +1000 | [diff] [blame] | 325 | gzip -f -9 "$ofile" |
Scott Wood | 0fdd717 | 2007-04-17 09:25:50 +1000 | [diff] [blame] | 326 | mkimage -A ppc -O linux -T kernel -C gzip -a "$base" -e "$entry" \ |
Scott Wood | aeb4552 | 2007-10-25 02:56:28 +1000 | [diff] [blame] | 327 | $uboot_version -d "$ofile".gz "$ofile" |
Scott Wood | 0fdd717 | 2007-04-17 09:25:50 +1000 | [diff] [blame] | 328 | ;; |
David Gibson | f6dfc80 | 2007-05-08 14:10:01 +1000 | [diff] [blame] | 329 | treeboot*) |
| 330 | mv "$ofile" "$ofile.elf" |
David Woodhouse | 5c539ee | 2007-12-03 13:52:05 +1100 | [diff] [blame] | 331 | $objbin/mktree "$ofile.elf" "$ofile" "$base" "$entry" |
David Gibson | f6dfc80 | 2007-05-08 14:10:01 +1000 | [diff] [blame] | 332 | if [ -z "$cacheit" ]; then |
| 333 | rm -f "$ofile.elf" |
| 334 | fi |
| 335 | exit 0 |
| 336 | ;; |
Geoff Levand | bafdb64 | 2007-07-04 09:07:18 +1000 | [diff] [blame] | 337 | ps3) |
Geoff Levand | 5761eaa | 2008-03-28 07:41:45 +1100 | [diff] [blame] | 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. |
Geoff Levand | bafdb64 | 2007-07-04 09:07:18 +1000 | [diff] [blame] | 348 | |
Scott Wood | aeb4552 | 2007-10-25 02:56:28 +1000 | [diff] [blame] | 349 | system_reset_overlay=0x`${CROSS}nm "$ofile" \ |
Geoff Levand | bafdb64 | 2007-07-04 09:07:18 +1000 | [diff] [blame] | 350 | | grep ' __system_reset_overlay$' \ |
| 351 | | cut -d' ' -f1` |
| 352 | system_reset_overlay=`printf "%d" $system_reset_overlay` |
Scott Wood | aeb4552 | 2007-10-25 02:56:28 +1000 | [diff] [blame] | 353 | system_reset_kernel=0x`${CROSS}nm "$ofile" \ |
Geoff Levand | bafdb64 | 2007-07-04 09:07:18 +1000 | [diff] [blame] | 354 | | grep ' __system_reset_kernel$' \ |
| 355 | | cut -d' ' -f1` |
| 356 | system_reset_kernel=`printf "%d" $system_reset_kernel` |
| 357 | overlay_dest="256" |
Geoff Levand | 5761eaa | 2008-03-28 07:41:45 +1100 | [diff] [blame] | 358 | overlay_size="512" |
Geoff Levand | bafdb64 | 2007-07-04 09:07:18 +1000 | [diff] [blame] | 359 | |
Scott Wood | aeb4552 | 2007-10-25 02:56:28 +1000 | [diff] [blame] | 360 | ${CROSS}objcopy -O binary "$ofile" "$ofile.bin" |
| 361 | |
Grant Likely | d474037 | 2007-10-23 14:27:36 +1000 | [diff] [blame] | 362 | dd if="$ofile.bin" of="$ofile.bin" conv=notrunc \ |
| 363 | skip=$overlay_dest seek=$system_reset_kernel \ |
| 364 | count=$overlay_size bs=1 |
Geoff Levand | bafdb64 | 2007-07-04 09:07:18 +1000 | [diff] [blame] | 365 | |
Grant Likely | d474037 | 2007-10-23 14:27:36 +1000 | [diff] [blame] | 366 | dd if="$ofile.bin" of="$ofile.bin" conv=notrunc \ |
| 367 | skip=$system_reset_overlay seek=$overlay_dest \ |
| 368 | count=$overlay_size bs=1 |
Geoff Levand | bafdb64 | 2007-07-04 09:07:18 +1000 | [diff] [blame] | 369 | |
David Woodhouse | 928b969 | 2007-12-03 13:48:03 +1100 | [diff] [blame] | 370 | odir="$(dirname "$ofile.bin")" |
| 371 | rm -f "$odir/otheros.bld" |
| 372 | gzip --force -9 --stdout "$ofile.bin" > "$odir/otheros.bld" |
Geoff Levand | bafdb64 | 2007-07-04 09:07:18 +1000 | [diff] [blame] | 373 | ;; |
Paul Mackerras | 2bf1181 | 2006-09-27 22:47:03 +1000 | [diff] [blame] | 374 | esac |