xref: /linux/arch/powerpc/boot/wrapper (revision be2019816e4dcdb02493da332b65a8b68b70106c)
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=
432bf11819SPaul Mackerras
442bf11819SPaul Mackerras# cross-compilation prefix
452bf11819SPaul MackerrasCROSS=
462bf11819SPaul Mackerras
473f884bf5SPeter Tyser# mkimage wrapper script
483f884bf5SPeter TyserMKIMAGE=$srctree/scripts/mkuboot.sh
493f884bf5SPeter Tyser
502bf11819SPaul Mackerras# directory for object and other files used by this script
512bf11819SPaul Mackerrasobject=arch/powerpc/boot
525c539ee3SDavid Woodhouseobjbin=$object
53c79b2973SLucian Adrian Grijincudtc=scripts/dtc/dtc
542bf11819SPaul Mackerras
552bf11819SPaul Mackerras# directory for working files
562bf11819SPaul Mackerrastmpdir=.
572bf11819SPaul Mackerras
582bf11819SPaul Mackerrasusage() {
592bf11819SPaul Mackerras    echo 'Usage: wrapper [-o output] [-p platform] [-i initrd]' >&2
602bf11819SPaul Mackerras    echo '       [-d devtree] [-s tree.dts] [-c] [-C cross-prefix]' >&2
61a9903811SScott Wood    echo '       [-D datadir] [-W workingdir] [--no-gzip] [vmlinux]' >&2
622bf11819SPaul Mackerras    exit 1
632bf11819SPaul Mackerras}
642bf11819SPaul Mackerras
652bf11819SPaul Mackerraswhile [ "$#" -gt 0 ]; do
662bf11819SPaul Mackerras    case "$1" in
672bf11819SPaul Mackerras    -o)
682bf11819SPaul Mackerras	shift
692bf11819SPaul Mackerras	[ "$#" -gt 0 ] || usage
702bf11819SPaul Mackerras	ofile="$1"
712bf11819SPaul Mackerras	;;
722bf11819SPaul Mackerras    -p)
732bf11819SPaul Mackerras	shift
742bf11819SPaul Mackerras	[ "$#" -gt 0 ] || usage
752bf11819SPaul Mackerras	platform="$1"
762bf11819SPaul Mackerras	;;
772bf11819SPaul Mackerras    -i)
782bf11819SPaul Mackerras	shift
792bf11819SPaul Mackerras	[ "$#" -gt 0 ] || usage
802bf11819SPaul Mackerras	initrd="$1"
812bf11819SPaul Mackerras	;;
822bf11819SPaul Mackerras    -d)
832bf11819SPaul Mackerras	shift
842bf11819SPaul Mackerras	[ "$#" -gt 0 ] || usage
852bf11819SPaul Mackerras	dtb="$1"
862bf11819SPaul Mackerras	;;
872bf11819SPaul Mackerras    -s)
882bf11819SPaul Mackerras	shift
892bf11819SPaul Mackerras	[ "$#" -gt 0 ] || usage
902bf11819SPaul Mackerras	dts="$1"
912bf11819SPaul Mackerras	;;
922bf11819SPaul Mackerras    -c)
932bf11819SPaul Mackerras	cacheit=y
942bf11819SPaul Mackerras	;;
952bf11819SPaul Mackerras    -C)
962bf11819SPaul Mackerras	shift
972bf11819SPaul Mackerras	[ "$#" -gt 0 ] || usage
982bf11819SPaul Mackerras	CROSS="$1"
992bf11819SPaul Mackerras	;;
1002bf11819SPaul Mackerras    -D)
1012bf11819SPaul Mackerras	shift
1022bf11819SPaul Mackerras	[ "$#" -gt 0 ] || usage
1032bf11819SPaul Mackerras	object="$1"
1045c539ee3SDavid Woodhouse	objbin="$1"
1052bf11819SPaul Mackerras	;;
1062bf11819SPaul Mackerras    -W)
1072bf11819SPaul Mackerras	shift
1082bf11819SPaul Mackerras	[ "$#" -gt 0 ] || usage
1092bf11819SPaul Mackerras	tmpdir="$1"
1102bf11819SPaul Mackerras	;;
111a9903811SScott Wood    --no-gzip)
112a9903811SScott Wood        gzip=
113a9903811SScott Wood        ;;
1142bf11819SPaul Mackerras    -?)
1152bf11819SPaul Mackerras	usage
1162bf11819SPaul Mackerras	;;
1172bf11819SPaul Mackerras    *)
1182bf11819SPaul Mackerras	[ -z "$kernel" ] || usage
1192bf11819SPaul Mackerras	kernel="$1"
1202bf11819SPaul Mackerras	;;
1212bf11819SPaul Mackerras    esac
1222bf11819SPaul Mackerras    shift
1232bf11819SPaul Mackerrasdone
1242bf11819SPaul Mackerras
1252bf11819SPaul Mackerrasif [ -n "$dts" ]; then
126701172d1SDavid Woodhouse    if [ ! -r "$dts" -a -r "$object/dts/$dts" ]; then
127701172d1SDavid Woodhouse	dts="$object/dts/$dts"
128701172d1SDavid Woodhouse    fi
1292bf11819SPaul Mackerras    if [ -z "$dtb" ]; then
1302bf11819SPaul Mackerras	dtb="$platform.dtb"
1312bf11819SPaul Mackerras    fi
132c79b2973SLucian Adrian Grijincu    $dtc -O dtb -o "$dtb" -b 0 "$dts"
1332bf11819SPaul Mackerrasfi
1342bf11819SPaul Mackerras
1352bf11819SPaul Mackerrasif [ -z "$kernel" ]; then
1362bf11819SPaul Mackerras    kernel=vmlinux
1372bf11819SPaul Mackerrasfi
1382bf11819SPaul Mackerras
1392bf11819SPaul Mackerrasplatformo=$object/"$platform".o
1402bf11819SPaul Mackerraslds=$object/zImage.lds
1412bf11819SPaul Mackerrasext=strip
1422bf11819SPaul Mackerrasobjflags=-S
1432bf11819SPaul Mackerrastmp=$tmpdir/zImage.$$.o
1442bf11819SPaul Mackerrasksection=.kernel:vmlinux.strip
1452bf11819SPaul Mackerrasisection=.kernel:initrd
1469b09c6d9STony Breedslink_address='0x400000'
147dfbc2d75SStephen Rothwellmake_space=y
1482bf11819SPaul Mackerras
1492bf11819SPaul Mackerrascase "$platform" in
15044790a0bSBenjamin Herrenschmidtof)
15144790a0bSBenjamin Herrenschmidt    platformo="$object/of.o $object/epapr.o"
15244790a0bSBenjamin Herrenschmidt    make_space=n
15344790a0bSBenjamin Herrenschmidt    ;;
1549b09c6d9STony Breedspseries)
1550c9fa291SBenjamin Herrenschmidt    platformo="$object/of.o $object/epapr.o"
1569b09c6d9STony Breeds    link_address='0x4000000'
157f5467e28SPaul Mackerras    make_space=n
1589b09c6d9STony Breeds    ;;
15958706ef9SCorey Minyardmaple)
1600c9fa291SBenjamin Herrenschmidt    platformo="$object/of.o $object/epapr.o"
16158706ef9SCorey Minyard    link_address='0x400000'
162f5467e28SPaul Mackerras    make_space=n
16358706ef9SCorey Minyard    ;;
1649b09c6d9STony Breedspmac|chrp)
1650c9fa291SBenjamin Herrenschmidt    platformo="$object/of.o $object/epapr.o"
166f5467e28SPaul Mackerras    make_space=n
1672bf11819SPaul Mackerras    ;;
168627aa944SMilton Millercoff)
1690c9fa291SBenjamin Herrenschmidt    platformo="$object/crt0.o $object/of.o $object/epapr.o"
1702bf11819SPaul Mackerras    lds=$object/zImage.coff.lds
1719b09c6d9STony Breeds    link_address='0x500000'
172f5467e28SPaul Mackerras    make_space=n
1736975a783SMichael Ellerman    pie=
1742bf11819SPaul Mackerras    ;;
17511eab297SBenjamin Herrenschmidtmiboot|uboot*)
1762bf11819SPaul Mackerras    # miboot and U-boot want just the bare bits, not an ELF binary
1772bf11819SPaul Mackerras    ext=bin
1782bf11819SPaul Mackerras    objflags="-O binary"
1792bf11819SPaul Mackerras    tmp="$ofile"
1802bf11819SPaul Mackerras    ksection=image
1812bf11819SPaul Mackerras    isection=initrd
1822bf11819SPaul Mackerras    ;;
1830fdd717eSScott Woodcuboot*)
18411c146ccSScott Wood    binary=y
1850fdd717eSScott Wood    gzip=
18625431333SGrant Likely    case "$platform" in
1878dd217b2SScott Wood    *-mpc866ads|*-mpc885ads|*-adder875*|*-ep88xc)
18825431333SGrant Likely        platformo=$object/cuboot-8xx.o
18925431333SGrant Likely        ;;
19025431333SGrant Likely    *5200*|*-motionpro)
19125431333SGrant Likely        platformo=$object/cuboot-52xx.o
19225431333SGrant Likely        ;;
19325431333SGrant Likely    *-pq2fads|*-ep8248e|*-mpc8272*|*-storcenter)
19425431333SGrant Likely        platformo=$object/cuboot-pq2.o
19525431333SGrant Likely        ;;
19625431333SGrant Likely    *-mpc824*)
19725431333SGrant Likely        platformo=$object/cuboot-824x.o
19825431333SGrant Likely        ;;
19959d13f9dSBryan O'Donoghue    *-mpc83*|*-asp834x*)
20025431333SGrant Likely        platformo=$object/cuboot-83xx.o
20125431333SGrant Likely        ;;
202ff880112SAlexandr Smirnov    *-tqm8541|*-mpc8560*|*-tqm8560|*-tqm8555|*-ksi8560*)
20325431333SGrant Likely        platformo=$object/cuboot-85xx-cpm2.o
20425431333SGrant Likely        ;;
2056dd1b64aSWolfgang Grandegger    *-mpc85*|*-tqm85*|*-sbc85*)
20625431333SGrant Likely        platformo=$object/cuboot-85xx.o
20725431333SGrant Likely        ;;
2088f23735dSGerhard Pircher    *-amigaone)
2098f23735dSGerhard Pircher        link_address='0x800000'
2108f23735dSGerhard Pircher        ;;
21125431333SGrant Likely    esac
2120fdd717eSScott Wood    ;;
213bafdb645SGeoff Levandps3)
214bafdb645SGeoff Levand    platformo="$object/ps3-head.o $object/ps3-hvcall.o $object/ps3.o"
215bafdb645SGeoff Levand    lds=$object/zImage.ps3.lds
216bafdb645SGeoff Levand    gzip=
217bafdb645SGeoff Levand    ext=bin
218bafdb645SGeoff Levand    objflags="-O binary --set-section-flags=.bss=contents,alloc,load,data"
219bafdb645SGeoff Levand    ksection=.kernel:vmlinux.bin
220bafdb645SGeoff Levand    isection=.kernel:initrd
2219b09c6d9STony Breeds    link_address=''
222dfbc2d75SStephen Rothwell    make_space=n
2236975a783SMichael Ellerman    pie=
224bafdb645SGeoff Levand    ;;
225a55387e5SScott Woodep88xc|ep405|ep8248e)
22611c146ccSScott Wood    platformo="$object/fixed-head.o $object/$platform.o"
22711c146ccSScott Wood    binary=y
22811c146ccSScott Wood    ;;
229a55387e5SScott Woodadder875-redboot)
230a55387e5SScott Wood    platformo="$object/fixed-head.o $object/redboot-8xx.o"
231a55387e5SScott Wood    binary=y
232a55387e5SScott Wood    ;;
233d2477b5cSGrant Likelysimpleboot-virtex405-*)
234d58577d8SJohn Linn    platformo="$object/virtex405-head.o $object/simpleboot.o $object/virtex.o"
235d58577d8SJohn Linn    binary=y
236d58577d8SJohn Linn    ;;
237d58577d8SJohn Linnsimpleboot-virtex440-*)
238a7e1cf0cSGrant Likely    platformo="$object/fixed-head.o $object/simpleboot.o $object/virtex.o"
239d2477b5cSGrant Likely    binary=y
240d2477b5cSGrant Likely    ;;
2411d46e379SGrant Likelysimpleboot-*)
242a7e1cf0cSGrant Likely    platformo="$object/fixed-head.o $object/simpleboot.o"
2431d46e379SGrant Likely    binary=y
2441d46e379SGrant Likely    ;;
24559d13f9dSBryan O'Donoghueasp834x-redboot)
24659d13f9dSBryan O'Donoghue    platformo="$object/fixed-head.o $object/redboot-83xx.o"
24759d13f9dSBryan O'Donoghue    binary=y
24859d13f9dSBryan O'Donoghue    ;;
24924760823SNate Casexpedite52*)
25024760823SNate Case    link_address='0x1400000'
25124760823SNate Case    platformo=$object/cuboot-85xx.o
25224760823SNate Case    ;;
2536cdd2417SAlbert Herranzgamecube|wii)
254b68a24bcSAlbert Herranz    link_address='0x600000'
255b68a24bcSAlbert Herranz    platformo="$object/$platform-head.o $object/$platform.o"
256b68a24bcSAlbert Herranz    ;;
257228d5505STony Breedstreeboot-currituck)
258228d5505STony Breeds    link_address='0x1000000'
259228d5505STony Breeds    ;;
260b4e8c8ddSTorez Smithtreeboot-iss4xx-mpic)
261b4e8c8ddSTorez Smith    platformo="$object/treeboot-iss4xx.o"
262b4e8c8ddSTorez Smith    ;;
2636c5b59b9SDavid Gibsonepapr)
2640c9fa291SBenjamin Herrenschmidt    platformo="$object/epapr.o $object/epapr-wrapper.o"
2656c5b59b9SDavid Gibson    link_address='0x20000000'
2666c5b59b9SDavid Gibson    pie=-pie
2676c5b59b9SDavid Gibson    ;;
268*be201981SStephen Chiversmvme5100)
269*be201981SStephen Chivers    platformo="$object/fixed-head.o $object/mvme5100.o"
270*be201981SStephen Chivers    binary=y
271*be201981SStephen Chivers    ;;
2722bf11819SPaul Mackerrasesac
2732bf11819SPaul Mackerras
2742bf11819SPaul Mackerrasvmz="$tmpdir/`basename \"$kernel\"`.$ext"
2751383a34fSMilton Millerif [ -z "$cacheit" -o ! -f "$vmz$gzip" -o "$vmz$gzip" -ot "$kernel" ]; then
2762bf11819SPaul Mackerras    ${CROSS}objcopy $objflags "$kernel" "$vmz.$$"
277a9903811SScott Wood
278c55aef0eSSuzuki Poulose    strip_size=$(stat -c %s $vmz.$$)
279c55aef0eSSuzuki Poulose
280a9903811SScott Wood    if [ -n "$gzip" ]; then
281c4f56af0SMichal Marek        gzip -n -f -9 "$vmz.$$"
282a9903811SScott Wood    fi
283a9903811SScott Wood
2842bf11819SPaul Mackerras    if [ -n "$cacheit" ]; then
285a9903811SScott Wood	mv -f "$vmz.$$$gzip" "$vmz$gzip"
2862bf11819SPaul Mackerras    else
2872bf11819SPaul Mackerras	vmz="$vmz.$$"
2882bf11819SPaul Mackerras    fi
289c55aef0eSSuzuki Pouloseelse
290c55aef0eSSuzuki Poulose    # Calculate the vmlinux.strip size
291c55aef0eSSuzuki Poulose    ${CROSS}objcopy $objflags "$kernel" "$vmz.$$"
292c55aef0eSSuzuki Poulose    strip_size=$(stat -c %s $vmz.$$)
293c55aef0eSSuzuki Poulose    rm -f $vmz.$$
294c55aef0eSSuzuki Poulosefi
295c55aef0eSSuzuki Poulose
296dfbc2d75SStephen Rothwellif [ "$make_space" = "y" ]; then
297c55aef0eSSuzuki Poulose	# Round the size to next higher MB limit
298c55aef0eSSuzuki Poulose	round_size=$(((strip_size + 0xfffff) & 0xfff00000))
299c55aef0eSSuzuki Poulose
300c55aef0eSSuzuki Poulose	round_size=0x$(printf "%x" $round_size)
301c55aef0eSSuzuki Poulose	link_addr=$(printf "%d" $link_address)
302c55aef0eSSuzuki Poulose
303c55aef0eSSuzuki Poulose	if [ $link_addr -lt $strip_size ]; then
304eba3d97dSSuzuki Poulose	    echo "INFO: Uncompressed kernel (size 0x$(printf "%x\n" $strip_size))" \
305c55aef0eSSuzuki Poulose			"overlaps the address of the wrapper($link_address)"
306eba3d97dSSuzuki Poulose	    echo "INFO: Fixing the link_address of wrapper to ($round_size)"
307c55aef0eSSuzuki Poulose	    link_address=$round_size
3082bf11819SPaul Mackerras	fi
309dfbc2d75SStephen Rothwellfi
3102bf11819SPaul Mackerras
311a9903811SScott Woodvmz="$vmz$gzip"
312a9903811SScott Wood
313a6afacb6SDavid Gibson# Extract kernel version information, some platforms want to include
314a6afacb6SDavid Gibson# it in the image header
3152bf11819SPaul Mackerrasversion=`${CROSS}strings "$kernel" | grep '^Linux version [-0-9.]' | \
3162bf11819SPaul Mackerras    cut -d' ' -f3`
3172bf11819SPaul Mackerrasif [ -n "$version" ]; then
318a6afacb6SDavid Gibson    uboot_version="-n Linux-$version"
3192bf11819SPaul Mackerrasfi
3200fdd717eSScott Wood
321b18796d3SKumar Gala# physical offset of kernel image
322b18796d3SKumar Galamembase=`${CROSS}objdump -p "$kernel" | grep -m 1 LOAD | awk '{print $7}'`
323b18796d3SKumar Gala
3240fdd717eSScott Woodcase "$platform" in
3250fdd717eSScott Wooduboot)
3260fdd717eSScott Wood    rm -f "$ofile"
3273f884bf5SPeter Tyser    ${MKIMAGE} -A ppc -O linux -T kernel -C gzip -a $membase -e $membase \
328a6afacb6SDavid Gibson	$uboot_version -d "$vmz" "$ofile"
3292bf11819SPaul Mackerras    if [ -z "$cacheit" ]; then
330a9903811SScott Wood	rm -f "$vmz"
3312bf11819SPaul Mackerras    fi
3322bf11819SPaul Mackerras    exit 0
3332bf11819SPaul Mackerras    ;;
33411eab297SBenjamin Herrenschmidtuboot-obs600)
33511eab297SBenjamin Herrenschmidt    rm -f "$ofile"
33611eab297SBenjamin Herrenschmidt    # obs600 wants a multi image with an initrd, so we need to put a fake
33711eab297SBenjamin Herrenschmidt    # one in even when building a "normal" image.
33811eab297SBenjamin Herrenschmidt    if [ -n "$initrd" ]; then
33911eab297SBenjamin Herrenschmidt	real_rd="$initrd"
34011eab297SBenjamin Herrenschmidt    else
34111eab297SBenjamin Herrenschmidt	real_rd=`mktemp`
34211eab297SBenjamin Herrenschmidt	echo "\0" >>"$real_rd"
34311eab297SBenjamin Herrenschmidt    fi
34411eab297SBenjamin Herrenschmidt    ${MKIMAGE} -A ppc -O linux -T multi -C gzip -a $membase -e $membase \
34511eab297SBenjamin Herrenschmidt	$uboot_version -d "$vmz":"$real_rd":"$dtb" "$ofile"
34611eab297SBenjamin Herrenschmidt    if [ -z "$initrd" ]; then
34711eab297SBenjamin Herrenschmidt	rm -f "$real_rd"
34811eab297SBenjamin Herrenschmidt    fi
34911eab297SBenjamin Herrenschmidt    if [ -z "$cacheit" ]; then
35011eab297SBenjamin Herrenschmidt	rm -f "$vmz"
35111eab297SBenjamin Herrenschmidt    fi
35211eab297SBenjamin Herrenschmidt    exit 0
35311eab297SBenjamin Herrenschmidt    ;;
3542bf11819SPaul Mackerrasesac
3552bf11819SPaul Mackerras
3562bf11819SPaul Mackerrasaddsec() {
3572bf11819SPaul Mackerras    ${CROSS}objcopy $4 $1 \
3582bf11819SPaul Mackerras	--add-section=$3="$2" \
3592bf11819SPaul Mackerras	--set-section-flags=$3=contents,alloc,load,readonly,data
3602bf11819SPaul Mackerras}
3612bf11819SPaul Mackerras
362a9903811SScott Woodaddsec $tmp "$vmz" $ksection $object/empty.o
3632bf11819SPaul Mackerrasif [ -z "$cacheit" ]; then
364a9903811SScott Wood    rm -f "$vmz"
3652bf11819SPaul Mackerrasfi
3662bf11819SPaul Mackerras
3672bf11819SPaul Mackerrasif [ -n "$initrd" ]; then
368c888554bSMark A. Greer    addsec $tmp "$initrd" $isection
3692bf11819SPaul Mackerrasfi
3702bf11819SPaul Mackerras
3712bf11819SPaul Mackerrasif [ -n "$dtb" ]; then
372c888554bSMark A. Greer    addsec $tmp "$dtb" .kernel:dtb
373e9c4b4bdSMark A. Greer    if [ -n "$dts" ]; then
374e9c4b4bdSMark A. Greer	rm $dtb
375e9c4b4bdSMark A. Greer    fi
3762bf11819SPaul Mackerrasfi
3772bf11819SPaul Mackerras
3782bf11819SPaul Mackerrasif [ "$platform" != "miboot" ]; then
3799b09c6d9STony Breeds    if [ -n "$link_address" ] ; then
3806975a783SMichael Ellerman        text_start="-Ttext $link_address"
3819b09c6d9STony Breeds    fi
3826975a783SMichael Ellerman    ${CROSS}ld -m elf32ppc -T $lds $text_start $pie -o "$ofile" \
383cd197ffcSDavid Gibson	$platformo $tmp $object/wrapper.a
3842bf11819SPaul Mackerras    rm $tmp
3852bf11819SPaul Mackerrasfi
3862bf11819SPaul Mackerras
387a6afacb6SDavid Gibson# Some platforms need the zImage's entry point and base address
388a6afacb6SDavid Gibsonbase=0x`${CROSS}nm "$ofile" | grep ' _start$' | cut -d' ' -f1`
389a6afacb6SDavid Gibsonentry=`${CROSS}objdump -f "$ofile" | grep '^start address ' | cut -d' ' -f3`
390a6afacb6SDavid Gibson
39111c146ccSScott Woodif [ -n "$binary" ]; then
39211c146ccSScott Wood    mv "$ofile" "$ofile".elf
393aeb4552fSScott Wood    ${CROSS}objcopy -O binary "$ofile".elf "$ofile"
39411c146ccSScott Woodfi
39511c146ccSScott Wood
3962bf11819SPaul Mackerras# post-processing needed for some platforms
3972bf11819SPaul Mackerrascase "$platform" in
39858706ef9SCorey Minyardpseries|chrp|maple)
3995663a123SPaul Mackerras    $objbin/addnote "$ofile"
4000dcd4401SPaul Mackerras    ;;
401627aa944SMilton Millercoff)
402cd197ffcSDavid Gibson    ${CROSS}objcopy -O aixcoff-rs6000 --set-start "$entry" "$ofile"
4035c539ee3SDavid Woodhouse    $objbin/hack-coff "$ofile"
4042bf11819SPaul Mackerras    ;;
4050fdd717eSScott Woodcuboot*)
406c4f56af0SMichal Marek    gzip -n -f -9 "$ofile"
4073f884bf5SPeter Tyser    ${MKIMAGE} -A ppc -O linux -T kernel -C gzip -a "$base" -e "$entry" \
408aeb4552fSScott Wood            $uboot_version -d "$ofile".gz "$ofile"
4090fdd717eSScott Wood    ;;
410f6dfc805SDavid Gibsontreeboot*)
411f6dfc805SDavid Gibson    mv "$ofile" "$ofile.elf"
4125c539ee3SDavid Woodhouse    $objbin/mktree "$ofile.elf" "$ofile" "$base" "$entry"
413f6dfc805SDavid Gibson    if [ -z "$cacheit" ]; then
414f6dfc805SDavid Gibson	rm -f "$ofile.elf"
415f6dfc805SDavid Gibson    fi
416f6dfc805SDavid Gibson    exit 0
417f6dfc805SDavid Gibson    ;;
418bafdb645SGeoff Levandps3)
4195761eaa3SGeoff Levand    # The ps3's loader supports loading a gzipped binary image from flash
4205761eaa3SGeoff Levand    # rom to ram addr zero. The loader then enters the system reset
4215761eaa3SGeoff Levand    # vector at addr 0x100.  A bootwrapper overlay is used to arrange for
4225761eaa3SGeoff Levand    # a binary image of the kernel to be at addr zero, and yet have a
4235761eaa3SGeoff Levand    # suitable bootwrapper entry at 0x100.  To construct the final rom
4245761eaa3SGeoff Levand    # image 512 bytes from offset 0x100 is copied to the bootwrapper
4255761eaa3SGeoff Levand    # place holder at symbol __system_reset_kernel.  The 512 bytes of the
4265761eaa3SGeoff Levand    # bootwrapper entry code at symbol __system_reset_overlay is then
4275761eaa3SGeoff Levand    # copied to offset 0x100.  At runtime the bootwrapper program copies
4285761eaa3SGeoff Levand    # the data at __system_reset_kernel back to addr 0x100.
429bafdb645SGeoff Levand
430aeb4552fSScott Wood    system_reset_overlay=0x`${CROSS}nm "$ofile" \
431bafdb645SGeoff Levand        | grep ' __system_reset_overlay$'       \
432bafdb645SGeoff Levand        | cut -d' ' -f1`
433bafdb645SGeoff Levand    system_reset_overlay=`printf "%d" $system_reset_overlay`
434aeb4552fSScott Wood    system_reset_kernel=0x`${CROSS}nm "$ofile" \
435bafdb645SGeoff Levand        | grep ' __system_reset_kernel$'       \
436bafdb645SGeoff Levand        | cut -d' ' -f1`
437bafdb645SGeoff Levand    system_reset_kernel=`printf "%d" $system_reset_kernel`
438bafdb645SGeoff Levand    overlay_dest="256"
4395761eaa3SGeoff Levand    overlay_size="512"
440bafdb645SGeoff Levand
441aeb4552fSScott Wood    ${CROSS}objcopy -O binary "$ofile" "$ofile.bin"
442aeb4552fSScott Wood
443d4740373SGrant Likely    dd if="$ofile.bin" of="$ofile.bin" conv=notrunc   \
444bafdb645SGeoff Levand        skip=$overlay_dest seek=$system_reset_kernel  \
445d4740373SGrant Likely        count=$overlay_size bs=1
446bafdb645SGeoff Levand
447d4740373SGrant Likely    dd if="$ofile.bin" of="$ofile.bin" conv=notrunc   \
448bafdb645SGeoff Levand        skip=$system_reset_overlay seek=$overlay_dest \
449d4740373SGrant Likely        count=$overlay_size bs=1
450bafdb645SGeoff Levand
451928b9695SDavid Woodhouse    odir="$(dirname "$ofile.bin")"
452928b9695SDavid Woodhouse    rm -f "$odir/otheros.bld"
453c4f56af0SMichal Marek    gzip -n --force -9 --stdout "$ofile.bin" > "$odir/otheros.bld"
454bafdb645SGeoff Levand    ;;
4552bf11819SPaul Mackerrasesac
456