12bf11819SPaul Mackerras#!/bin/sh 22bf11819SPaul Mackerras 32bf11819SPaul Mackerras# Copyright (C) 2006 Paul Mackerras, IBM Corporation <paulus@samba.org> 42bf11819SPaul Mackerras# This program may be used under the terms of version 2 of the GNU 52bf11819SPaul Mackerras# General Public License. 62bf11819SPaul Mackerras 72bf11819SPaul Mackerras# This script takes a kernel binary and optionally an initrd image 82bf11819SPaul Mackerras# and/or a device-tree blob, and creates a bootable zImage for a 92bf11819SPaul Mackerras# given platform. 102bf11819SPaul Mackerras 112bf11819SPaul Mackerras# Options: 122bf11819SPaul Mackerras# -o zImage specify output file 132bf11819SPaul Mackerras# -p platform specify platform (links in $platform.o) 142bf11819SPaul Mackerras# -i initrd specify initrd file 152bf11819SPaul Mackerras# -d devtree specify device-tree blob 162bf11819SPaul Mackerras# -s tree.dts specify device-tree source file (needs dtc installed) 172bf11819SPaul Mackerras# -c cache $kernel.strip.gz (use if present & newer, else make) 182bf11819SPaul Mackerras# -C prefix specify command prefix for cross-building tools 192bf11819SPaul Mackerras# (strip, objcopy, ld) 202bf11819SPaul Mackerras# -D dir specify directory containing data files used by script 212bf11819SPaul Mackerras# (default ./arch/powerpc/boot) 222bf11819SPaul Mackerras# -W dir specify working directory for temporary files (default .) 232bf11819SPaul Mackerras 24d4740373SGrant Likely# Stop execution if any command fails 25d4740373SGrant Likelyset -e 26d4740373SGrant Likely 277f66c1fdSGrant Likely# Allow for verbose output 287f66c1fdSGrant Likelyif [ "$V" = 1 ]; then 297f66c1fdSGrant Likely set -x 307f66c1fdSGrant Likelyfi 317f66c1fdSGrant Likely 322bf11819SPaul Mackerras# defaults 332bf11819SPaul Mackerraskernel= 342bf11819SPaul Mackerrasofile=zImage 352bf11819SPaul Mackerrasplatform=of 362bf11819SPaul Mackerrasinitrd= 372bf11819SPaul Mackerrasdtb= 382bf11819SPaul Mackerrasdts= 392bf11819SPaul Mackerrascacheit= 4011c146ccSScott Woodbinary= 41a9903811SScott Woodgzip=.gz 426975a783SMichael Ellermanpie= 43*147c0516SCédric Le Goaterformat= 442bf11819SPaul Mackerras 452bf11819SPaul Mackerras# cross-compilation prefix 462bf11819SPaul MackerrasCROSS= 472bf11819SPaul Mackerras 483f884bf5SPeter Tyser# mkimage wrapper script 493f884bf5SPeter TyserMKIMAGE=$srctree/scripts/mkuboot.sh 503f884bf5SPeter Tyser 512bf11819SPaul Mackerras# directory for object and other files used by this script 522bf11819SPaul Mackerrasobject=arch/powerpc/boot 535c539ee3SDavid Woodhouseobjbin=$object 54c79b2973SLucian Adrian Grijincudtc=scripts/dtc/dtc 552bf11819SPaul Mackerras 562bf11819SPaul Mackerras# directory for working files 572bf11819SPaul Mackerrastmpdir=. 582bf11819SPaul Mackerras 592bf11819SPaul Mackerrasusage() { 602bf11819SPaul Mackerras echo 'Usage: wrapper [-o output] [-p platform] [-i initrd]' >&2 612bf11819SPaul Mackerras echo ' [-d devtree] [-s tree.dts] [-c] [-C cross-prefix]' >&2 62a9903811SScott Wood echo ' [-D datadir] [-W workingdir] [--no-gzip] [vmlinux]' >&2 632bf11819SPaul Mackerras exit 1 642bf11819SPaul Mackerras} 652bf11819SPaul Mackerras 662bf11819SPaul Mackerraswhile [ "$#" -gt 0 ]; do 672bf11819SPaul Mackerras case "$1" in 682bf11819SPaul Mackerras -o) 692bf11819SPaul Mackerras shift 702bf11819SPaul Mackerras [ "$#" -gt 0 ] || usage 712bf11819SPaul Mackerras ofile="$1" 722bf11819SPaul Mackerras ;; 732bf11819SPaul Mackerras -p) 742bf11819SPaul Mackerras shift 752bf11819SPaul Mackerras [ "$#" -gt 0 ] || usage 762bf11819SPaul Mackerras platform="$1" 772bf11819SPaul Mackerras ;; 782bf11819SPaul Mackerras -i) 792bf11819SPaul Mackerras shift 802bf11819SPaul Mackerras [ "$#" -gt 0 ] || usage 812bf11819SPaul Mackerras initrd="$1" 822bf11819SPaul Mackerras ;; 832bf11819SPaul Mackerras -d) 842bf11819SPaul Mackerras shift 852bf11819SPaul Mackerras [ "$#" -gt 0 ] || usage 862bf11819SPaul Mackerras dtb="$1" 872bf11819SPaul Mackerras ;; 882bf11819SPaul Mackerras -s) 892bf11819SPaul Mackerras shift 902bf11819SPaul Mackerras [ "$#" -gt 0 ] || usage 912bf11819SPaul Mackerras dts="$1" 922bf11819SPaul Mackerras ;; 932bf11819SPaul Mackerras -c) 942bf11819SPaul Mackerras cacheit=y 952bf11819SPaul Mackerras ;; 962bf11819SPaul Mackerras -C) 972bf11819SPaul Mackerras shift 982bf11819SPaul Mackerras [ "$#" -gt 0 ] || usage 992bf11819SPaul Mackerras CROSS="$1" 1002bf11819SPaul Mackerras ;; 1012bf11819SPaul Mackerras -D) 1022bf11819SPaul Mackerras shift 1032bf11819SPaul Mackerras [ "$#" -gt 0 ] || usage 1042bf11819SPaul Mackerras object="$1" 1055c539ee3SDavid Woodhouse objbin="$1" 1062bf11819SPaul Mackerras ;; 1072bf11819SPaul Mackerras -W) 1082bf11819SPaul Mackerras shift 1092bf11819SPaul Mackerras [ "$#" -gt 0 ] || usage 1102bf11819SPaul Mackerras tmpdir="$1" 1112bf11819SPaul Mackerras ;; 112a9903811SScott Wood --no-gzip) 113a9903811SScott Wood gzip= 114a9903811SScott Wood ;; 1152bf11819SPaul Mackerras -?) 1162bf11819SPaul Mackerras usage 1172bf11819SPaul Mackerras ;; 1182bf11819SPaul Mackerras *) 1192bf11819SPaul Mackerras [ -z "$kernel" ] || usage 1202bf11819SPaul Mackerras kernel="$1" 1212bf11819SPaul Mackerras ;; 1222bf11819SPaul Mackerras esac 1232bf11819SPaul Mackerras shift 1242bf11819SPaul Mackerrasdone 1252bf11819SPaul Mackerras 1262bf11819SPaul Mackerrasif [ -n "$dts" ]; then 127701172d1SDavid Woodhouse if [ ! -r "$dts" -a -r "$object/dts/$dts" ]; then 128701172d1SDavid Woodhouse dts="$object/dts/$dts" 129701172d1SDavid Woodhouse fi 1302bf11819SPaul Mackerras if [ -z "$dtb" ]; then 1312bf11819SPaul Mackerras dtb="$platform.dtb" 1322bf11819SPaul Mackerras fi 133c79b2973SLucian Adrian Grijincu $dtc -O dtb -o "$dtb" -b 0 "$dts" 1342bf11819SPaul Mackerrasfi 1352bf11819SPaul Mackerras 1362bf11819SPaul Mackerrasif [ -z "$kernel" ]; then 1372bf11819SPaul Mackerras kernel=vmlinux 1382bf11819SPaul Mackerrasfi 1392bf11819SPaul Mackerras 140*147c0516SCédric Le Goaterelfformat="`${CROSS}objdump -p "$kernel" | grep 'file format' | awk '{print $4}'`" 141*147c0516SCédric Le Goatercase "$elfformat" in 142*147c0516SCédric Le Goater elf64-powerpcle) format=elf64lppc ;; 143*147c0516SCédric Le Goater elf64-powerpc) format=elf32ppc ;; 144*147c0516SCédric Le Goater elf32-powerpc) format=elf32ppc ;; 145*147c0516SCédric Le Goateresac 146*147c0516SCédric Le Goater 147*147c0516SCédric Le Goater 1482bf11819SPaul Mackerrasplatformo=$object/"$platform".o 1492bf11819SPaul Mackerraslds=$object/zImage.lds 1502bf11819SPaul Mackerrasext=strip 1512bf11819SPaul Mackerrasobjflags=-S 1522bf11819SPaul Mackerrastmp=$tmpdir/zImage.$$.o 1532bf11819SPaul Mackerrasksection=.kernel:vmlinux.strip 1542bf11819SPaul Mackerrasisection=.kernel:initrd 1559b09c6d9STony Breedslink_address='0x400000' 156dfbc2d75SStephen Rothwellmake_space=y 1572bf11819SPaul Mackerras 1582bf11819SPaul Mackerrascase "$platform" in 15944790a0bSBenjamin Herrenschmidtof) 16044790a0bSBenjamin Herrenschmidt platformo="$object/of.o $object/epapr.o" 16144790a0bSBenjamin Herrenschmidt make_space=n 16244790a0bSBenjamin Herrenschmidt ;; 1639b09c6d9STony Breedspseries) 1642d9afb36SCédric Le Goater platformo="$object/pseries-head.o $object/of.o $object/epapr.o" 1659b09c6d9STony Breeds link_address='0x4000000' 166*147c0516SCédric Le Goater if [ "$format" != "elf32ppc" ]; then 167*147c0516SCédric Le Goater link_address= 168*147c0516SCédric Le Goater pie=-pie 169*147c0516SCédric Le Goater fi 170f5467e28SPaul Mackerras make_space=n 1719b09c6d9STony Breeds ;; 17258706ef9SCorey Minyardmaple) 1730c9fa291SBenjamin Herrenschmidt platformo="$object/of.o $object/epapr.o" 17458706ef9SCorey Minyard link_address='0x400000' 175f5467e28SPaul Mackerras make_space=n 17658706ef9SCorey Minyard ;; 1779b09c6d9STony Breedspmac|chrp) 1780c9fa291SBenjamin Herrenschmidt platformo="$object/of.o $object/epapr.o" 179f5467e28SPaul Mackerras make_space=n 1802bf11819SPaul Mackerras ;; 181627aa944SMilton Millercoff) 1820c9fa291SBenjamin Herrenschmidt platformo="$object/crt0.o $object/of.o $object/epapr.o" 1832bf11819SPaul Mackerras lds=$object/zImage.coff.lds 1849b09c6d9STony Breeds link_address='0x500000' 185f5467e28SPaul Mackerras make_space=n 1866975a783SMichael Ellerman pie= 1872bf11819SPaul Mackerras ;; 18811eab297SBenjamin Herrenschmidtmiboot|uboot*) 1892bf11819SPaul Mackerras # miboot and U-boot want just the bare bits, not an ELF binary 1902bf11819SPaul Mackerras ext=bin 1912bf11819SPaul Mackerras objflags="-O binary" 1922bf11819SPaul Mackerras tmp="$ofile" 1932bf11819SPaul Mackerras ksection=image 1942bf11819SPaul Mackerras isection=initrd 1952bf11819SPaul Mackerras ;; 1960fdd717eSScott Woodcuboot*) 19711c146ccSScott Wood binary=y 1980fdd717eSScott Wood gzip= 19925431333SGrant Likely case "$platform" in 2008dd217b2SScott Wood *-mpc866ads|*-mpc885ads|*-adder875*|*-ep88xc) 20125431333SGrant Likely platformo=$object/cuboot-8xx.o 20225431333SGrant Likely ;; 20325431333SGrant Likely *5200*|*-motionpro) 20425431333SGrant Likely platformo=$object/cuboot-52xx.o 20525431333SGrant Likely ;; 20625431333SGrant Likely *-pq2fads|*-ep8248e|*-mpc8272*|*-storcenter) 20725431333SGrant Likely platformo=$object/cuboot-pq2.o 20825431333SGrant Likely ;; 20925431333SGrant Likely *-mpc824*) 21025431333SGrant Likely platformo=$object/cuboot-824x.o 21125431333SGrant Likely ;; 21259d13f9dSBryan O'Donoghue *-mpc83*|*-asp834x*) 21325431333SGrant Likely platformo=$object/cuboot-83xx.o 21425431333SGrant Likely ;; 215ff880112SAlexandr Smirnov *-tqm8541|*-mpc8560*|*-tqm8560|*-tqm8555|*-ksi8560*) 21625431333SGrant Likely platformo=$object/cuboot-85xx-cpm2.o 21725431333SGrant Likely ;; 2186dd1b64aSWolfgang Grandegger *-mpc85*|*-tqm85*|*-sbc85*) 21925431333SGrant Likely platformo=$object/cuboot-85xx.o 22025431333SGrant Likely ;; 2218f23735dSGerhard Pircher *-amigaone) 2228f23735dSGerhard Pircher link_address='0x800000' 2238f23735dSGerhard Pircher ;; 22425431333SGrant Likely esac 2250fdd717eSScott Wood ;; 226bafdb645SGeoff Levandps3) 227bafdb645SGeoff Levand platformo="$object/ps3-head.o $object/ps3-hvcall.o $object/ps3.o" 228bafdb645SGeoff Levand lds=$object/zImage.ps3.lds 229bafdb645SGeoff Levand gzip= 230bafdb645SGeoff Levand ext=bin 231bafdb645SGeoff Levand objflags="-O binary --set-section-flags=.bss=contents,alloc,load,data" 232bafdb645SGeoff Levand ksection=.kernel:vmlinux.bin 233bafdb645SGeoff Levand isection=.kernel:initrd 2349b09c6d9STony Breeds link_address='' 235dfbc2d75SStephen Rothwell make_space=n 2366975a783SMichael Ellerman pie= 237bafdb645SGeoff Levand ;; 238a55387e5SScott Woodep88xc|ep405|ep8248e) 23911c146ccSScott Wood platformo="$object/fixed-head.o $object/$platform.o" 24011c146ccSScott Wood binary=y 24111c146ccSScott Wood ;; 242a55387e5SScott Woodadder875-redboot) 243a55387e5SScott Wood platformo="$object/fixed-head.o $object/redboot-8xx.o" 244a55387e5SScott Wood binary=y 245a55387e5SScott Wood ;; 246d2477b5cSGrant Likelysimpleboot-virtex405-*) 247d58577d8SJohn Linn platformo="$object/virtex405-head.o $object/simpleboot.o $object/virtex.o" 248d58577d8SJohn Linn binary=y 249d58577d8SJohn Linn ;; 250d58577d8SJohn Linnsimpleboot-virtex440-*) 251a7e1cf0cSGrant Likely platformo="$object/fixed-head.o $object/simpleboot.o $object/virtex.o" 252d2477b5cSGrant Likely binary=y 253d2477b5cSGrant Likely ;; 2541d46e379SGrant Likelysimpleboot-*) 255a7e1cf0cSGrant Likely platformo="$object/fixed-head.o $object/simpleboot.o" 2561d46e379SGrant Likely binary=y 2571d46e379SGrant Likely ;; 25859d13f9dSBryan O'Donoghueasp834x-redboot) 25959d13f9dSBryan O'Donoghue platformo="$object/fixed-head.o $object/redboot-83xx.o" 26059d13f9dSBryan O'Donoghue binary=y 26159d13f9dSBryan O'Donoghue ;; 26224760823SNate Casexpedite52*) 26324760823SNate Case link_address='0x1400000' 26424760823SNate Case platformo=$object/cuboot-85xx.o 26524760823SNate Case ;; 2666cdd2417SAlbert Herranzgamecube|wii) 267b68a24bcSAlbert Herranz link_address='0x600000' 268b68a24bcSAlbert Herranz platformo="$object/$platform-head.o $object/$platform.o" 269b68a24bcSAlbert Herranz ;; 270228d5505STony Breedstreeboot-currituck) 271228d5505STony Breeds link_address='0x1000000' 272228d5505STony Breeds ;; 273b4e8c8ddSTorez Smithtreeboot-iss4xx-mpic) 274b4e8c8ddSTorez Smith platformo="$object/treeboot-iss4xx.o" 275b4e8c8ddSTorez Smith ;; 2766c5b59b9SDavid Gibsonepapr) 2770c9fa291SBenjamin Herrenschmidt platformo="$object/epapr.o $object/epapr-wrapper.o" 2786c5b59b9SDavid Gibson link_address='0x20000000' 2796c5b59b9SDavid Gibson pie=-pie 2806c5b59b9SDavid Gibson ;; 281be201981SStephen Chiversmvme5100) 282be201981SStephen Chivers platformo="$object/fixed-head.o $object/mvme5100.o" 283be201981SStephen Chivers binary=y 284be201981SStephen Chivers ;; 2852bf11819SPaul Mackerrasesac 2862bf11819SPaul Mackerras 2872bf11819SPaul Mackerrasvmz="$tmpdir/`basename \"$kernel\"`.$ext" 2881383a34fSMilton Millerif [ -z "$cacheit" -o ! -f "$vmz$gzip" -o "$vmz$gzip" -ot "$kernel" ]; then 2892bf11819SPaul Mackerras ${CROSS}objcopy $objflags "$kernel" "$vmz.$$" 290a9903811SScott Wood 291c55aef0eSSuzuki Poulose strip_size=$(stat -c %s $vmz.$$) 292c55aef0eSSuzuki Poulose 293a9903811SScott Wood if [ -n "$gzip" ]; then 294c4f56af0SMichal Marek gzip -n -f -9 "$vmz.$$" 295a9903811SScott Wood fi 296a9903811SScott Wood 2972bf11819SPaul Mackerras if [ -n "$cacheit" ]; then 298a9903811SScott Wood mv -f "$vmz.$$$gzip" "$vmz$gzip" 2992bf11819SPaul Mackerras else 3002bf11819SPaul Mackerras vmz="$vmz.$$" 3012bf11819SPaul Mackerras fi 302c55aef0eSSuzuki Pouloseelse 303c55aef0eSSuzuki Poulose # Calculate the vmlinux.strip size 304c55aef0eSSuzuki Poulose ${CROSS}objcopy $objflags "$kernel" "$vmz.$$" 305c55aef0eSSuzuki Poulose strip_size=$(stat -c %s $vmz.$$) 306c55aef0eSSuzuki Poulose rm -f $vmz.$$ 307c55aef0eSSuzuki Poulosefi 308c55aef0eSSuzuki Poulose 309dfbc2d75SStephen Rothwellif [ "$make_space" = "y" ]; then 310c55aef0eSSuzuki Poulose # Round the size to next higher MB limit 311c55aef0eSSuzuki Poulose round_size=$(((strip_size + 0xfffff) & 0xfff00000)) 312c55aef0eSSuzuki Poulose 313c55aef0eSSuzuki Poulose round_size=0x$(printf "%x" $round_size) 314c55aef0eSSuzuki Poulose link_addr=$(printf "%d" $link_address) 315c55aef0eSSuzuki Poulose 316c55aef0eSSuzuki Poulose if [ $link_addr -lt $strip_size ]; then 317eba3d97dSSuzuki Poulose echo "INFO: Uncompressed kernel (size 0x$(printf "%x\n" $strip_size))" \ 318c55aef0eSSuzuki Poulose "overlaps the address of the wrapper($link_address)" 319eba3d97dSSuzuki Poulose echo "INFO: Fixing the link_address of wrapper to ($round_size)" 320c55aef0eSSuzuki Poulose link_address=$round_size 3212bf11819SPaul Mackerras fi 322dfbc2d75SStephen Rothwellfi 3232bf11819SPaul Mackerras 324a9903811SScott Woodvmz="$vmz$gzip" 325a9903811SScott Wood 326a6afacb6SDavid Gibson# Extract kernel version information, some platforms want to include 327a6afacb6SDavid Gibson# it in the image header 3282bf11819SPaul Mackerrasversion=`${CROSS}strings "$kernel" | grep '^Linux version [-0-9.]' | \ 3292bf11819SPaul Mackerras cut -d' ' -f3` 3302bf11819SPaul Mackerrasif [ -n "$version" ]; then 331a6afacb6SDavid Gibson uboot_version="-n Linux-$version" 3322bf11819SPaul Mackerrasfi 3330fdd717eSScott Wood 334b18796d3SKumar Gala# physical offset of kernel image 335b18796d3SKumar Galamembase=`${CROSS}objdump -p "$kernel" | grep -m 1 LOAD | awk '{print $7}'` 336b18796d3SKumar Gala 3370fdd717eSScott Woodcase "$platform" in 3380fdd717eSScott Wooduboot) 3390fdd717eSScott Wood rm -f "$ofile" 3403f884bf5SPeter Tyser ${MKIMAGE} -A ppc -O linux -T kernel -C gzip -a $membase -e $membase \ 341a6afacb6SDavid Gibson $uboot_version -d "$vmz" "$ofile" 3422bf11819SPaul Mackerras if [ -z "$cacheit" ]; then 343a9903811SScott Wood rm -f "$vmz" 3442bf11819SPaul Mackerras fi 3452bf11819SPaul Mackerras exit 0 3462bf11819SPaul Mackerras ;; 34711eab297SBenjamin Herrenschmidtuboot-obs600) 34811eab297SBenjamin Herrenschmidt rm -f "$ofile" 34911eab297SBenjamin Herrenschmidt # obs600 wants a multi image with an initrd, so we need to put a fake 35011eab297SBenjamin Herrenschmidt # one in even when building a "normal" image. 35111eab297SBenjamin Herrenschmidt if [ -n "$initrd" ]; then 35211eab297SBenjamin Herrenschmidt real_rd="$initrd" 35311eab297SBenjamin Herrenschmidt else 35411eab297SBenjamin Herrenschmidt real_rd=`mktemp` 35511eab297SBenjamin Herrenschmidt echo "\0" >>"$real_rd" 35611eab297SBenjamin Herrenschmidt fi 35711eab297SBenjamin Herrenschmidt ${MKIMAGE} -A ppc -O linux -T multi -C gzip -a $membase -e $membase \ 35811eab297SBenjamin Herrenschmidt $uboot_version -d "$vmz":"$real_rd":"$dtb" "$ofile" 35911eab297SBenjamin Herrenschmidt if [ -z "$initrd" ]; then 36011eab297SBenjamin Herrenschmidt rm -f "$real_rd" 36111eab297SBenjamin Herrenschmidt fi 36211eab297SBenjamin Herrenschmidt if [ -z "$cacheit" ]; then 36311eab297SBenjamin Herrenschmidt rm -f "$vmz" 36411eab297SBenjamin Herrenschmidt fi 36511eab297SBenjamin Herrenschmidt exit 0 36611eab297SBenjamin Herrenschmidt ;; 3672bf11819SPaul Mackerrasesac 3682bf11819SPaul Mackerras 3692bf11819SPaul Mackerrasaddsec() { 3702bf11819SPaul Mackerras ${CROSS}objcopy $4 $1 \ 3712bf11819SPaul Mackerras --add-section=$3="$2" \ 3722bf11819SPaul Mackerras --set-section-flags=$3=contents,alloc,load,readonly,data 3732bf11819SPaul Mackerras} 3742bf11819SPaul Mackerras 375a9903811SScott Woodaddsec $tmp "$vmz" $ksection $object/empty.o 3762bf11819SPaul Mackerrasif [ -z "$cacheit" ]; then 377a9903811SScott Wood rm -f "$vmz" 3782bf11819SPaul Mackerrasfi 3792bf11819SPaul Mackerras 3802bf11819SPaul Mackerrasif [ -n "$initrd" ]; then 381c888554bSMark A. Greer addsec $tmp "$initrd" $isection 3822bf11819SPaul Mackerrasfi 3832bf11819SPaul Mackerras 3842bf11819SPaul Mackerrasif [ -n "$dtb" ]; then 385c888554bSMark A. Greer addsec $tmp "$dtb" .kernel:dtb 386e9c4b4bdSMark A. Greer if [ -n "$dts" ]; then 387e9c4b4bdSMark A. Greer rm $dtb 388e9c4b4bdSMark A. Greer fi 3892bf11819SPaul Mackerrasfi 3902bf11819SPaul Mackerras 3912bf11819SPaul Mackerrasif [ "$platform" != "miboot" ]; then 3929b09c6d9STony Breeds if [ -n "$link_address" ] ; then 3936975a783SMichael Ellerman text_start="-Ttext $link_address" 3949b09c6d9STony Breeds fi 395*147c0516SCédric Le Goater ${CROSS}ld -m $format -T $lds $text_start $pie -o "$ofile" \ 396cd197ffcSDavid Gibson $platformo $tmp $object/wrapper.a 3972bf11819SPaul Mackerras rm $tmp 3982bf11819SPaul Mackerrasfi 3992bf11819SPaul Mackerras 400a6afacb6SDavid Gibson# Some platforms need the zImage's entry point and base address 401a6afacb6SDavid Gibsonbase=0x`${CROSS}nm "$ofile" | grep ' _start$' | cut -d' ' -f1` 402a6afacb6SDavid Gibsonentry=`${CROSS}objdump -f "$ofile" | grep '^start address ' | cut -d' ' -f3` 403a6afacb6SDavid Gibson 40411c146ccSScott Woodif [ -n "$binary" ]; then 40511c146ccSScott Wood mv "$ofile" "$ofile".elf 406aeb4552fSScott Wood ${CROSS}objcopy -O binary "$ofile".elf "$ofile" 40711c146ccSScott Woodfi 40811c146ccSScott Wood 4092bf11819SPaul Mackerras# post-processing needed for some platforms 4102bf11819SPaul Mackerrascase "$platform" in 41158706ef9SCorey Minyardpseries|chrp|maple) 4125663a123SPaul Mackerras $objbin/addnote "$ofile" 4130dcd4401SPaul Mackerras ;; 414627aa944SMilton Millercoff) 415cd197ffcSDavid Gibson ${CROSS}objcopy -O aixcoff-rs6000 --set-start "$entry" "$ofile" 4165c539ee3SDavid Woodhouse $objbin/hack-coff "$ofile" 4172bf11819SPaul Mackerras ;; 4180fdd717eSScott Woodcuboot*) 419c4f56af0SMichal Marek gzip -n -f -9 "$ofile" 4203f884bf5SPeter Tyser ${MKIMAGE} -A ppc -O linux -T kernel -C gzip -a "$base" -e "$entry" \ 421aeb4552fSScott Wood $uboot_version -d "$ofile".gz "$ofile" 4220fdd717eSScott Wood ;; 423f6dfc805SDavid Gibsontreeboot*) 424f6dfc805SDavid Gibson mv "$ofile" "$ofile.elf" 4255c539ee3SDavid Woodhouse $objbin/mktree "$ofile.elf" "$ofile" "$base" "$entry" 426f6dfc805SDavid Gibson if [ -z "$cacheit" ]; then 427f6dfc805SDavid Gibson rm -f "$ofile.elf" 428f6dfc805SDavid Gibson fi 429f6dfc805SDavid Gibson exit 0 430f6dfc805SDavid Gibson ;; 431bafdb645SGeoff Levandps3) 4325761eaa3SGeoff Levand # The ps3's loader supports loading a gzipped binary image from flash 4335761eaa3SGeoff Levand # rom to ram addr zero. The loader then enters the system reset 4345761eaa3SGeoff Levand # vector at addr 0x100. A bootwrapper overlay is used to arrange for 4355761eaa3SGeoff Levand # a binary image of the kernel to be at addr zero, and yet have a 4365761eaa3SGeoff Levand # suitable bootwrapper entry at 0x100. To construct the final rom 4375761eaa3SGeoff Levand # image 512 bytes from offset 0x100 is copied to the bootwrapper 4385761eaa3SGeoff Levand # place holder at symbol __system_reset_kernel. The 512 bytes of the 4395761eaa3SGeoff Levand # bootwrapper entry code at symbol __system_reset_overlay is then 4405761eaa3SGeoff Levand # copied to offset 0x100. At runtime the bootwrapper program copies 4415761eaa3SGeoff Levand # the data at __system_reset_kernel back to addr 0x100. 442bafdb645SGeoff Levand 443aeb4552fSScott Wood system_reset_overlay=0x`${CROSS}nm "$ofile" \ 444bafdb645SGeoff Levand | grep ' __system_reset_overlay$' \ 445bafdb645SGeoff Levand | cut -d' ' -f1` 446bafdb645SGeoff Levand system_reset_overlay=`printf "%d" $system_reset_overlay` 447aeb4552fSScott Wood system_reset_kernel=0x`${CROSS}nm "$ofile" \ 448bafdb645SGeoff Levand | grep ' __system_reset_kernel$' \ 449bafdb645SGeoff Levand | cut -d' ' -f1` 450bafdb645SGeoff Levand system_reset_kernel=`printf "%d" $system_reset_kernel` 451bafdb645SGeoff Levand overlay_dest="256" 4525761eaa3SGeoff Levand overlay_size="512" 453bafdb645SGeoff Levand 454aeb4552fSScott Wood ${CROSS}objcopy -O binary "$ofile" "$ofile.bin" 455aeb4552fSScott Wood 456d4740373SGrant Likely dd if="$ofile.bin" of="$ofile.bin" conv=notrunc \ 457bafdb645SGeoff Levand skip=$overlay_dest seek=$system_reset_kernel \ 458d4740373SGrant Likely count=$overlay_size bs=1 459bafdb645SGeoff Levand 460d4740373SGrant Likely dd if="$ofile.bin" of="$ofile.bin" conv=notrunc \ 461bafdb645SGeoff Levand skip=$system_reset_overlay seek=$overlay_dest \ 462d4740373SGrant Likely count=$overlay_size bs=1 463bafdb645SGeoff Levand 464928b9695SDavid Woodhouse odir="$(dirname "$ofile.bin")" 465928b9695SDavid Woodhouse rm -f "$odir/otheros.bld" 466c4f56af0SMichal Marek gzip -n --force -9 --stdout "$ofile.bin" > "$odir/otheros.bld" 467bafdb645SGeoff Levand ;; 4682bf11819SPaul Mackerrasesac 469