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= 43147c0516SCé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 140147c0516SCédric Le Goaterelfformat="`${CROSS}objdump -p "$kernel" | grep 'file format' | awk '{print $4}'`" 141147c0516SCédric Le Goatercase "$elfformat" in 142147c0516SCédric Le Goater elf64-powerpcle) format=elf64lppc ;; 143147c0516SCédric Le Goater elf64-powerpc) format=elf32ppc ;; 144147c0516SCédric Le Goater elf32-powerpc) format=elf32ppc ;; 145147c0516SCédric Le Goateresac 146147c0516SCédric Le Goater 147147c0516SCé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' 166147c0516SCédric Le Goater if [ "$format" != "elf32ppc" ]; then 167147c0516SCédric Le Goater link_address= 168147c0516SCédric Le Goater pie=-pie 169147c0516SCé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 ;; 2732a2c74b2SAlistair Poppletreeboot-akebono) 2742a2c74b2SAlistair Popple link_address='0x1000000' 2752a2c74b2SAlistair Popple ;; 276b4e8c8ddSTorez Smithtreeboot-iss4xx-mpic) 277b4e8c8ddSTorez Smith platformo="$object/treeboot-iss4xx.o" 278b4e8c8ddSTorez Smith ;; 2796c5b59b9SDavid Gibsonepapr) 280*90d1d44eSJeremy Kerr platformo="$object/pseries-head.o $object/epapr.o $object/epapr-wrapper.o" 2816c5b59b9SDavid Gibson link_address='0x20000000' 2826c5b59b9SDavid Gibson pie=-pie 2836c5b59b9SDavid Gibson ;; 284be201981SStephen Chiversmvme5100) 285be201981SStephen Chivers platformo="$object/fixed-head.o $object/mvme5100.o" 286be201981SStephen Chivers binary=y 287be201981SStephen Chivers ;; 2882bf11819SPaul Mackerrasesac 2892bf11819SPaul Mackerras 2902bf11819SPaul Mackerrasvmz="$tmpdir/`basename \"$kernel\"`.$ext" 2911383a34fSMilton Millerif [ -z "$cacheit" -o ! -f "$vmz$gzip" -o "$vmz$gzip" -ot "$kernel" ]; then 2922bf11819SPaul Mackerras ${CROSS}objcopy $objflags "$kernel" "$vmz.$$" 293a9903811SScott Wood 294c55aef0eSSuzuki Poulose strip_size=$(stat -c %s $vmz.$$) 295c55aef0eSSuzuki Poulose 296a9903811SScott Wood if [ -n "$gzip" ]; then 297c4f56af0SMichal Marek gzip -n -f -9 "$vmz.$$" 298a9903811SScott Wood fi 299a9903811SScott Wood 3002bf11819SPaul Mackerras if [ -n "$cacheit" ]; then 301a9903811SScott Wood mv -f "$vmz.$$$gzip" "$vmz$gzip" 3022bf11819SPaul Mackerras else 3032bf11819SPaul Mackerras vmz="$vmz.$$" 3042bf11819SPaul Mackerras fi 305c55aef0eSSuzuki Pouloseelse 306c55aef0eSSuzuki Poulose # Calculate the vmlinux.strip size 307c55aef0eSSuzuki Poulose ${CROSS}objcopy $objflags "$kernel" "$vmz.$$" 308c55aef0eSSuzuki Poulose strip_size=$(stat -c %s $vmz.$$) 309c55aef0eSSuzuki Poulose rm -f $vmz.$$ 310c55aef0eSSuzuki Poulosefi 311c55aef0eSSuzuki Poulose 312dfbc2d75SStephen Rothwellif [ "$make_space" = "y" ]; then 313c55aef0eSSuzuki Poulose # Round the size to next higher MB limit 314c55aef0eSSuzuki Poulose round_size=$(((strip_size + 0xfffff) & 0xfff00000)) 315c55aef0eSSuzuki Poulose 316c55aef0eSSuzuki Poulose round_size=0x$(printf "%x" $round_size) 317c55aef0eSSuzuki Poulose link_addr=$(printf "%d" $link_address) 318c55aef0eSSuzuki Poulose 319c55aef0eSSuzuki Poulose if [ $link_addr -lt $strip_size ]; then 320eba3d97dSSuzuki Poulose echo "INFO: Uncompressed kernel (size 0x$(printf "%x\n" $strip_size))" \ 321c55aef0eSSuzuki Poulose "overlaps the address of the wrapper($link_address)" 322eba3d97dSSuzuki Poulose echo "INFO: Fixing the link_address of wrapper to ($round_size)" 323c55aef0eSSuzuki Poulose link_address=$round_size 3242bf11819SPaul Mackerras fi 325dfbc2d75SStephen Rothwellfi 3262bf11819SPaul Mackerras 327a9903811SScott Woodvmz="$vmz$gzip" 328a9903811SScott Wood 329a6afacb6SDavid Gibson# Extract kernel version information, some platforms want to include 330a6afacb6SDavid Gibson# it in the image header 3312bf11819SPaul Mackerrasversion=`${CROSS}strings "$kernel" | grep '^Linux version [-0-9.]' | \ 3322bf11819SPaul Mackerras cut -d' ' -f3` 3332bf11819SPaul Mackerrasif [ -n "$version" ]; then 334a6afacb6SDavid Gibson uboot_version="-n Linux-$version" 3352bf11819SPaul Mackerrasfi 3360fdd717eSScott Wood 337b18796d3SKumar Gala# physical offset of kernel image 338b18796d3SKumar Galamembase=`${CROSS}objdump -p "$kernel" | grep -m 1 LOAD | awk '{print $7}'` 339b18796d3SKumar Gala 3400fdd717eSScott Woodcase "$platform" in 3410fdd717eSScott Wooduboot) 3420fdd717eSScott Wood rm -f "$ofile" 3433f884bf5SPeter Tyser ${MKIMAGE} -A ppc -O linux -T kernel -C gzip -a $membase -e $membase \ 344a6afacb6SDavid Gibson $uboot_version -d "$vmz" "$ofile" 3452bf11819SPaul Mackerras if [ -z "$cacheit" ]; then 346a9903811SScott Wood rm -f "$vmz" 3472bf11819SPaul Mackerras fi 3482bf11819SPaul Mackerras exit 0 3492bf11819SPaul Mackerras ;; 35011eab297SBenjamin Herrenschmidtuboot-obs600) 35111eab297SBenjamin Herrenschmidt rm -f "$ofile" 35211eab297SBenjamin Herrenschmidt # obs600 wants a multi image with an initrd, so we need to put a fake 35311eab297SBenjamin Herrenschmidt # one in even when building a "normal" image. 35411eab297SBenjamin Herrenschmidt if [ -n "$initrd" ]; then 35511eab297SBenjamin Herrenschmidt real_rd="$initrd" 35611eab297SBenjamin Herrenschmidt else 35711eab297SBenjamin Herrenschmidt real_rd=`mktemp` 35811eab297SBenjamin Herrenschmidt echo "\0" >>"$real_rd" 35911eab297SBenjamin Herrenschmidt fi 36011eab297SBenjamin Herrenschmidt ${MKIMAGE} -A ppc -O linux -T multi -C gzip -a $membase -e $membase \ 36111eab297SBenjamin Herrenschmidt $uboot_version -d "$vmz":"$real_rd":"$dtb" "$ofile" 36211eab297SBenjamin Herrenschmidt if [ -z "$initrd" ]; then 36311eab297SBenjamin Herrenschmidt rm -f "$real_rd" 36411eab297SBenjamin Herrenschmidt fi 36511eab297SBenjamin Herrenschmidt if [ -z "$cacheit" ]; then 36611eab297SBenjamin Herrenschmidt rm -f "$vmz" 36711eab297SBenjamin Herrenschmidt fi 36811eab297SBenjamin Herrenschmidt exit 0 36911eab297SBenjamin Herrenschmidt ;; 3702bf11819SPaul Mackerrasesac 3712bf11819SPaul Mackerras 3722bf11819SPaul Mackerrasaddsec() { 3732bf11819SPaul Mackerras ${CROSS}objcopy $4 $1 \ 3742bf11819SPaul Mackerras --add-section=$3="$2" \ 3752bf11819SPaul Mackerras --set-section-flags=$3=contents,alloc,load,readonly,data 3762bf11819SPaul Mackerras} 3772bf11819SPaul Mackerras 378a9903811SScott Woodaddsec $tmp "$vmz" $ksection $object/empty.o 3792bf11819SPaul Mackerrasif [ -z "$cacheit" ]; then 380a9903811SScott Wood rm -f "$vmz" 3812bf11819SPaul Mackerrasfi 3822bf11819SPaul Mackerras 3832bf11819SPaul Mackerrasif [ -n "$initrd" ]; then 384c888554bSMark A. Greer addsec $tmp "$initrd" $isection 3852bf11819SPaul Mackerrasfi 3862bf11819SPaul Mackerras 3872bf11819SPaul Mackerrasif [ -n "$dtb" ]; then 388c888554bSMark A. Greer addsec $tmp "$dtb" .kernel:dtb 389e9c4b4bdSMark A. Greer if [ -n "$dts" ]; then 390e9c4b4bdSMark A. Greer rm $dtb 391e9c4b4bdSMark A. Greer fi 3922bf11819SPaul Mackerrasfi 3932bf11819SPaul Mackerras 3942bf11819SPaul Mackerrasif [ "$platform" != "miboot" ]; then 3959b09c6d9STony Breeds if [ -n "$link_address" ] ; then 3966975a783SMichael Ellerman text_start="-Ttext $link_address" 3979b09c6d9STony Breeds fi 398147c0516SCédric Le Goater ${CROSS}ld -m $format -T $lds $text_start $pie -o "$ofile" \ 399cd197ffcSDavid Gibson $platformo $tmp $object/wrapper.a 4002bf11819SPaul Mackerras rm $tmp 4012bf11819SPaul Mackerrasfi 4022bf11819SPaul Mackerras 403a6afacb6SDavid Gibson# Some platforms need the zImage's entry point and base address 404a6afacb6SDavid Gibsonbase=0x`${CROSS}nm "$ofile" | grep ' _start$' | cut -d' ' -f1` 405a6afacb6SDavid Gibsonentry=`${CROSS}objdump -f "$ofile" | grep '^start address ' | cut -d' ' -f3` 406a6afacb6SDavid Gibson 40711c146ccSScott Woodif [ -n "$binary" ]; then 40811c146ccSScott Wood mv "$ofile" "$ofile".elf 409aeb4552fSScott Wood ${CROSS}objcopy -O binary "$ofile".elf "$ofile" 41011c146ccSScott Woodfi 41111c146ccSScott Wood 4122bf11819SPaul Mackerras# post-processing needed for some platforms 4132bf11819SPaul Mackerrascase "$platform" in 41458706ef9SCorey Minyardpseries|chrp|maple) 4155663a123SPaul Mackerras $objbin/addnote "$ofile" 4160dcd4401SPaul Mackerras ;; 417627aa944SMilton Millercoff) 418cd197ffcSDavid Gibson ${CROSS}objcopy -O aixcoff-rs6000 --set-start "$entry" "$ofile" 4195c539ee3SDavid Woodhouse $objbin/hack-coff "$ofile" 4202bf11819SPaul Mackerras ;; 4210fdd717eSScott Woodcuboot*) 422c4f56af0SMichal Marek gzip -n -f -9 "$ofile" 4233f884bf5SPeter Tyser ${MKIMAGE} -A ppc -O linux -T kernel -C gzip -a "$base" -e "$entry" \ 424aeb4552fSScott Wood $uboot_version -d "$ofile".gz "$ofile" 4250fdd717eSScott Wood ;; 426f6dfc805SDavid Gibsontreeboot*) 427f6dfc805SDavid Gibson mv "$ofile" "$ofile.elf" 4285c539ee3SDavid Woodhouse $objbin/mktree "$ofile.elf" "$ofile" "$base" "$entry" 429f6dfc805SDavid Gibson if [ -z "$cacheit" ]; then 430f6dfc805SDavid Gibson rm -f "$ofile.elf" 431f6dfc805SDavid Gibson fi 432f6dfc805SDavid Gibson exit 0 433f6dfc805SDavid Gibson ;; 434bafdb645SGeoff Levandps3) 4355761eaa3SGeoff Levand # The ps3's loader supports loading a gzipped binary image from flash 4365761eaa3SGeoff Levand # rom to ram addr zero. The loader then enters the system reset 4375761eaa3SGeoff Levand # vector at addr 0x100. A bootwrapper overlay is used to arrange for 4385761eaa3SGeoff Levand # a binary image of the kernel to be at addr zero, and yet have a 4395761eaa3SGeoff Levand # suitable bootwrapper entry at 0x100. To construct the final rom 4405761eaa3SGeoff Levand # image 512 bytes from offset 0x100 is copied to the bootwrapper 4415761eaa3SGeoff Levand # place holder at symbol __system_reset_kernel. The 512 bytes of the 4425761eaa3SGeoff Levand # bootwrapper entry code at symbol __system_reset_overlay is then 4435761eaa3SGeoff Levand # copied to offset 0x100. At runtime the bootwrapper program copies 4445761eaa3SGeoff Levand # the data at __system_reset_kernel back to addr 0x100. 445bafdb645SGeoff Levand 446aeb4552fSScott Wood system_reset_overlay=0x`${CROSS}nm "$ofile" \ 447bafdb645SGeoff Levand | grep ' __system_reset_overlay$' \ 448bafdb645SGeoff Levand | cut -d' ' -f1` 449bafdb645SGeoff Levand system_reset_overlay=`printf "%d" $system_reset_overlay` 450aeb4552fSScott Wood system_reset_kernel=0x`${CROSS}nm "$ofile" \ 451bafdb645SGeoff Levand | grep ' __system_reset_kernel$' \ 452bafdb645SGeoff Levand | cut -d' ' -f1` 453bafdb645SGeoff Levand system_reset_kernel=`printf "%d" $system_reset_kernel` 454bafdb645SGeoff Levand overlay_dest="256" 4555761eaa3SGeoff Levand overlay_size="512" 456bafdb645SGeoff Levand 457aeb4552fSScott Wood ${CROSS}objcopy -O binary "$ofile" "$ofile.bin" 458aeb4552fSScott Wood 459d4740373SGrant Likely dd if="$ofile.bin" of="$ofile.bin" conv=notrunc \ 460bafdb645SGeoff Levand skip=$overlay_dest seek=$system_reset_kernel \ 461d4740373SGrant Likely count=$overlay_size bs=1 462bafdb645SGeoff Levand 463d4740373SGrant Likely dd if="$ofile.bin" of="$ofile.bin" conv=notrunc \ 464bafdb645SGeoff Levand skip=$system_reset_overlay seek=$overlay_dest \ 465d4740373SGrant Likely count=$overlay_size bs=1 466bafdb645SGeoff Levand 467928b9695SDavid Woodhouse odir="$(dirname "$ofile.bin")" 468928b9695SDavid Woodhouse rm -f "$odir/otheros.bld" 469c4f56af0SMichal Marek gzip -n --force -9 --stdout "$ofile.bin" > "$odir/otheros.bld" 470bafdb645SGeoff Levand ;; 4712bf11819SPaul Mackerrasesac 472