xref: /linux/arch/powerpc/boot/wrapper (revision 879c26d4f6a2b573d75cc235946019b6208ed6bc)
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
66*879c26d4SGeoff Levandrun_cmd() {
67*879c26d4SGeoff Levand    if [ "$V" = 1 ]; then
68*879c26d4SGeoff Levand        $* 2>&1
69*879c26d4SGeoff Levand    else
70*879c26d4SGeoff Levand        local msg
71*879c26d4SGeoff Levand
72*879c26d4SGeoff Levand        set +e
73*879c26d4SGeoff Levand        msg=$($* 2>&1)
74*879c26d4SGeoff Levand
75*879c26d4SGeoff Levand        if [ $? -ne "0" ]; then
76*879c26d4SGeoff Levand                echo $msg
77*879c26d4SGeoff Levand                exit 1
78*879c26d4SGeoff Levand        fi
79*879c26d4SGeoff Levand        set -e
80*879c26d4SGeoff Levand    fi
81*879c26d4SGeoff Levand}
82*879c26d4SGeoff Levand
832bf11819SPaul Mackerraswhile [ "$#" -gt 0 ]; do
842bf11819SPaul Mackerras    case "$1" in
852bf11819SPaul Mackerras    -o)
862bf11819SPaul Mackerras	shift
872bf11819SPaul Mackerras	[ "$#" -gt 0 ] || usage
882bf11819SPaul Mackerras	ofile="$1"
892bf11819SPaul Mackerras	;;
902bf11819SPaul Mackerras    -p)
912bf11819SPaul Mackerras	shift
922bf11819SPaul Mackerras	[ "$#" -gt 0 ] || usage
932bf11819SPaul Mackerras	platform="$1"
942bf11819SPaul Mackerras	;;
952bf11819SPaul Mackerras    -i)
962bf11819SPaul Mackerras	shift
972bf11819SPaul Mackerras	[ "$#" -gt 0 ] || usage
982bf11819SPaul Mackerras	initrd="$1"
992bf11819SPaul Mackerras	;;
1002bf11819SPaul Mackerras    -d)
1012bf11819SPaul Mackerras	shift
1022bf11819SPaul Mackerras	[ "$#" -gt 0 ] || usage
1032bf11819SPaul Mackerras	dtb="$1"
1042bf11819SPaul Mackerras	;;
1052bf11819SPaul Mackerras    -s)
1062bf11819SPaul Mackerras	shift
1072bf11819SPaul Mackerras	[ "$#" -gt 0 ] || usage
1082bf11819SPaul Mackerras	dts="$1"
1092bf11819SPaul Mackerras	;;
1102bf11819SPaul Mackerras    -c)
1112bf11819SPaul Mackerras	cacheit=y
1122bf11819SPaul Mackerras	;;
1132bf11819SPaul Mackerras    -C)
1142bf11819SPaul Mackerras	shift
1152bf11819SPaul Mackerras	[ "$#" -gt 0 ] || usage
1162bf11819SPaul Mackerras	CROSS="$1"
1172bf11819SPaul Mackerras	;;
1182bf11819SPaul Mackerras    -D)
1192bf11819SPaul Mackerras	shift
1202bf11819SPaul Mackerras	[ "$#" -gt 0 ] || usage
1212bf11819SPaul Mackerras	object="$1"
1225c539ee3SDavid Woodhouse	objbin="$1"
1232bf11819SPaul Mackerras	;;
1242bf11819SPaul Mackerras    -W)
1252bf11819SPaul Mackerras	shift
1262bf11819SPaul Mackerras	[ "$#" -gt 0 ] || usage
1272bf11819SPaul Mackerras	tmpdir="$1"
1282bf11819SPaul Mackerras	;;
129a9903811SScott Wood    --no-gzip)
130a9903811SScott Wood        gzip=
131a9903811SScott Wood        ;;
1322bf11819SPaul Mackerras    -?)
1332bf11819SPaul Mackerras	usage
1342bf11819SPaul Mackerras	;;
1352bf11819SPaul Mackerras    *)
1362bf11819SPaul Mackerras	[ -z "$kernel" ] || usage
1372bf11819SPaul Mackerras	kernel="$1"
1382bf11819SPaul Mackerras	;;
1392bf11819SPaul Mackerras    esac
1402bf11819SPaul Mackerras    shift
1412bf11819SPaul Mackerrasdone
1422bf11819SPaul Mackerras
1432bf11819SPaul Mackerrasif [ -n "$dts" ]; then
144701172d1SDavid Woodhouse    if [ ! -r "$dts" -a -r "$object/dts/$dts" ]; then
145701172d1SDavid Woodhouse	dts="$object/dts/$dts"
146701172d1SDavid Woodhouse    fi
1472bf11819SPaul Mackerras    if [ -z "$dtb" ]; then
1482bf11819SPaul Mackerras	dtb="$platform.dtb"
1492bf11819SPaul Mackerras    fi
150c79b2973SLucian Adrian Grijincu    $dtc -O dtb -o "$dtb" -b 0 "$dts"
1512bf11819SPaul Mackerrasfi
1522bf11819SPaul Mackerras
1532bf11819SPaul Mackerrasif [ -z "$kernel" ]; then
1542bf11819SPaul Mackerras    kernel=vmlinux
1552bf11819SPaul Mackerrasfi
1562bf11819SPaul Mackerras
157147c0516SCédric Le Goaterelfformat="`${CROSS}objdump -p "$kernel" | grep 'file format' | awk '{print $4}'`"
158147c0516SCédric Le Goatercase "$elfformat" in
159147c0516SCédric Le Goater    elf64-powerpcle)	format=elf64lppc	;;
160147c0516SCédric Le Goater    elf64-powerpc)	format=elf32ppc	;;
161147c0516SCédric Le Goater    elf32-powerpc)	format=elf32ppc	;;
162147c0516SCédric Le Goateresac
163147c0516SCédric Le Goater
164147c0516SCédric Le Goater
1652bf11819SPaul Mackerrasplatformo=$object/"$platform".o
1662bf11819SPaul Mackerraslds=$object/zImage.lds
1672bf11819SPaul Mackerrasext=strip
1682bf11819SPaul Mackerrasobjflags=-S
1692bf11819SPaul Mackerrastmp=$tmpdir/zImage.$$.o
1702bf11819SPaul Mackerrasksection=.kernel:vmlinux.strip
1712bf11819SPaul Mackerrasisection=.kernel:initrd
1729b09c6d9STony Breedslink_address='0x400000'
173dfbc2d75SStephen Rothwellmake_space=y
1742bf11819SPaul Mackerras
1752bf11819SPaul Mackerrascase "$platform" in
17644790a0bSBenjamin Herrenschmidtof)
17744790a0bSBenjamin Herrenschmidt    platformo="$object/of.o $object/epapr.o"
17844790a0bSBenjamin Herrenschmidt    make_space=n
17944790a0bSBenjamin Herrenschmidt    ;;
1809b09c6d9STony Breedspseries)
1812d9afb36SCédric Le Goater    platformo="$object/pseries-head.o $object/of.o $object/epapr.o"
1829b09c6d9STony Breeds    link_address='0x4000000'
183147c0516SCédric Le Goater    if [ "$format" != "elf32ppc" ]; then
184147c0516SCédric Le Goater	link_address=
185147c0516SCédric Le Goater	pie=-pie
186147c0516SCédric Le Goater    fi
187f5467e28SPaul Mackerras    make_space=n
1889b09c6d9STony Breeds    ;;
18958706ef9SCorey Minyardmaple)
1900c9fa291SBenjamin Herrenschmidt    platformo="$object/of.o $object/epapr.o"
19158706ef9SCorey Minyard    link_address='0x400000'
192f5467e28SPaul Mackerras    make_space=n
19358706ef9SCorey Minyard    ;;
1949b09c6d9STony Breedspmac|chrp)
1950c9fa291SBenjamin Herrenschmidt    platformo="$object/of.o $object/epapr.o"
196f5467e28SPaul Mackerras    make_space=n
1972bf11819SPaul Mackerras    ;;
198627aa944SMilton Millercoff)
1990c9fa291SBenjamin Herrenschmidt    platformo="$object/crt0.o $object/of.o $object/epapr.o"
2002bf11819SPaul Mackerras    lds=$object/zImage.coff.lds
2019b09c6d9STony Breeds    link_address='0x500000'
202f5467e28SPaul Mackerras    make_space=n
2036975a783SMichael Ellerman    pie=
2042bf11819SPaul Mackerras    ;;
20511eab297SBenjamin Herrenschmidtmiboot|uboot*)
2062bf11819SPaul Mackerras    # miboot and U-boot want just the bare bits, not an ELF binary
2072bf11819SPaul Mackerras    ext=bin
2082bf11819SPaul Mackerras    objflags="-O binary"
2092bf11819SPaul Mackerras    tmp="$ofile"
2102bf11819SPaul Mackerras    ksection=image
2112bf11819SPaul Mackerras    isection=initrd
2122bf11819SPaul Mackerras    ;;
2130fdd717eSScott Woodcuboot*)
21411c146ccSScott Wood    binary=y
2150fdd717eSScott Wood    gzip=
21625431333SGrant Likely    case "$platform" in
2178dd217b2SScott Wood    *-mpc866ads|*-mpc885ads|*-adder875*|*-ep88xc)
21825431333SGrant Likely        platformo=$object/cuboot-8xx.o
21925431333SGrant Likely        ;;
22025431333SGrant Likely    *5200*|*-motionpro)
22125431333SGrant Likely        platformo=$object/cuboot-52xx.o
22225431333SGrant Likely        ;;
22325431333SGrant Likely    *-pq2fads|*-ep8248e|*-mpc8272*|*-storcenter)
22425431333SGrant Likely        platformo=$object/cuboot-pq2.o
22525431333SGrant Likely        ;;
22625431333SGrant Likely    *-mpc824*)
22725431333SGrant Likely        platformo=$object/cuboot-824x.o
22825431333SGrant Likely        ;;
22959d13f9dSBryan O'Donoghue    *-mpc83*|*-asp834x*)
23025431333SGrant Likely        platformo=$object/cuboot-83xx.o
23125431333SGrant Likely        ;;
232ff880112SAlexandr Smirnov    *-tqm8541|*-mpc8560*|*-tqm8560|*-tqm8555|*-ksi8560*)
23325431333SGrant Likely        platformo=$object/cuboot-85xx-cpm2.o
23425431333SGrant Likely        ;;
2356dd1b64aSWolfgang Grandegger    *-mpc85*|*-tqm85*|*-sbc85*)
23625431333SGrant Likely        platformo=$object/cuboot-85xx.o
23725431333SGrant Likely        ;;
2388f23735dSGerhard Pircher    *-amigaone)
2398f23735dSGerhard Pircher        link_address='0x800000'
2408f23735dSGerhard Pircher        ;;
24125431333SGrant Likely    esac
2420fdd717eSScott Wood    ;;
243bafdb645SGeoff Levandps3)
244bafdb645SGeoff Levand    platformo="$object/ps3-head.o $object/ps3-hvcall.o $object/ps3.o"
245bafdb645SGeoff Levand    lds=$object/zImage.ps3.lds
246bafdb645SGeoff Levand    gzip=
247bafdb645SGeoff Levand    ext=bin
248bafdb645SGeoff Levand    objflags="-O binary --set-section-flags=.bss=contents,alloc,load,data"
249bafdb645SGeoff Levand    ksection=.kernel:vmlinux.bin
250bafdb645SGeoff Levand    isection=.kernel:initrd
2519b09c6d9STony Breeds    link_address=''
252dfbc2d75SStephen Rothwell    make_space=n
2536975a783SMichael Ellerman    pie=
254bafdb645SGeoff Levand    ;;
255a55387e5SScott Woodep88xc|ep405|ep8248e)
25611c146ccSScott Wood    platformo="$object/fixed-head.o $object/$platform.o"
25711c146ccSScott Wood    binary=y
25811c146ccSScott Wood    ;;
259a55387e5SScott Woodadder875-redboot)
260a55387e5SScott Wood    platformo="$object/fixed-head.o $object/redboot-8xx.o"
261a55387e5SScott Wood    binary=y
262a55387e5SScott Wood    ;;
263d2477b5cSGrant Likelysimpleboot-virtex405-*)
264d58577d8SJohn Linn    platformo="$object/virtex405-head.o $object/simpleboot.o $object/virtex.o"
265d58577d8SJohn Linn    binary=y
266d58577d8SJohn Linn    ;;
267d58577d8SJohn Linnsimpleboot-virtex440-*)
268a7e1cf0cSGrant Likely    platformo="$object/fixed-head.o $object/simpleboot.o $object/virtex.o"
269d2477b5cSGrant Likely    binary=y
270d2477b5cSGrant Likely    ;;
2711d46e379SGrant Likelysimpleboot-*)
272a7e1cf0cSGrant Likely    platformo="$object/fixed-head.o $object/simpleboot.o"
2731d46e379SGrant Likely    binary=y
2741d46e379SGrant Likely    ;;
27559d13f9dSBryan O'Donoghueasp834x-redboot)
27659d13f9dSBryan O'Donoghue    platformo="$object/fixed-head.o $object/redboot-83xx.o"
27759d13f9dSBryan O'Donoghue    binary=y
27859d13f9dSBryan O'Donoghue    ;;
27924760823SNate Casexpedite52*)
28024760823SNate Case    link_address='0x1400000'
28124760823SNate Case    platformo=$object/cuboot-85xx.o
28224760823SNate Case    ;;
2836cdd2417SAlbert Herranzgamecube|wii)
284b68a24bcSAlbert Herranz    link_address='0x600000'
285b68a24bcSAlbert Herranz    platformo="$object/$platform-head.o $object/$platform.o"
286b68a24bcSAlbert Herranz    ;;
287228d5505STony Breedstreeboot-currituck)
288228d5505STony Breeds    link_address='0x1000000'
289228d5505STony Breeds    ;;
2902a2c74b2SAlistair Poppletreeboot-akebono)
2912a2c74b2SAlistair Popple    link_address='0x1000000'
2922a2c74b2SAlistair Popple    ;;
293b4e8c8ddSTorez Smithtreeboot-iss4xx-mpic)
294b4e8c8ddSTorez Smith    platformo="$object/treeboot-iss4xx.o"
295b4e8c8ddSTorez Smith    ;;
2966c5b59b9SDavid Gibsonepapr)
29790d1d44eSJeremy Kerr    platformo="$object/pseries-head.o $object/epapr.o $object/epapr-wrapper.o"
2986c5b59b9SDavid Gibson    link_address='0x20000000'
2996c5b59b9SDavid Gibson    pie=-pie
3006c5b59b9SDavid Gibson    ;;
301be201981SStephen Chiversmvme5100)
302be201981SStephen Chivers    platformo="$object/fixed-head.o $object/mvme5100.o"
303be201981SStephen Chivers    binary=y
304be201981SStephen Chivers    ;;
3052bf11819SPaul Mackerrasesac
3062bf11819SPaul Mackerras
3072bf11819SPaul Mackerrasvmz="$tmpdir/`basename \"$kernel\"`.$ext"
3081383a34fSMilton Millerif [ -z "$cacheit" -o ! -f "$vmz$gzip" -o "$vmz$gzip" -ot "$kernel" ]; then
3092bf11819SPaul Mackerras    ${CROSS}objcopy $objflags "$kernel" "$vmz.$$"
310a9903811SScott Wood
311c55aef0eSSuzuki Poulose    strip_size=$(stat -c %s $vmz.$$)
312c55aef0eSSuzuki Poulose
313a9903811SScott Wood    if [ -n "$gzip" ]; then
314c4f56af0SMichal Marek        gzip -n -f -9 "$vmz.$$"
315a9903811SScott Wood    fi
316a9903811SScott Wood
3172bf11819SPaul Mackerras    if [ -n "$cacheit" ]; then
318a9903811SScott Wood	mv -f "$vmz.$$$gzip" "$vmz$gzip"
3192bf11819SPaul Mackerras    else
3202bf11819SPaul Mackerras	vmz="$vmz.$$"
3212bf11819SPaul Mackerras    fi
322c55aef0eSSuzuki Pouloseelse
323c55aef0eSSuzuki Poulose    # Calculate the vmlinux.strip size
324c55aef0eSSuzuki Poulose    ${CROSS}objcopy $objflags "$kernel" "$vmz.$$"
325c55aef0eSSuzuki Poulose    strip_size=$(stat -c %s $vmz.$$)
326c55aef0eSSuzuki Poulose    rm -f $vmz.$$
327c55aef0eSSuzuki Poulosefi
328c55aef0eSSuzuki Poulose
329dfbc2d75SStephen Rothwellif [ "$make_space" = "y" ]; then
330c55aef0eSSuzuki Poulose	# Round the size to next higher MB limit
331c55aef0eSSuzuki Poulose	round_size=$(((strip_size + 0xfffff) & 0xfff00000))
332c55aef0eSSuzuki Poulose
333c55aef0eSSuzuki Poulose	round_size=0x$(printf "%x" $round_size)
334c55aef0eSSuzuki Poulose	link_addr=$(printf "%d" $link_address)
335c55aef0eSSuzuki Poulose
336c55aef0eSSuzuki Poulose	if [ $link_addr -lt $strip_size ]; then
337eba3d97dSSuzuki Poulose	    echo "INFO: Uncompressed kernel (size 0x$(printf "%x\n" $strip_size))" \
338c55aef0eSSuzuki Poulose			"overlaps the address of the wrapper($link_address)"
339eba3d97dSSuzuki Poulose	    echo "INFO: Fixing the link_address of wrapper to ($round_size)"
340c55aef0eSSuzuki Poulose	    link_address=$round_size
3412bf11819SPaul Mackerras	fi
342dfbc2d75SStephen Rothwellfi
3432bf11819SPaul Mackerras
344a9903811SScott Woodvmz="$vmz$gzip"
345a9903811SScott Wood
346a6afacb6SDavid Gibson# Extract kernel version information, some platforms want to include
347a6afacb6SDavid Gibson# it in the image header
3482bf11819SPaul Mackerrasversion=`${CROSS}strings "$kernel" | grep '^Linux version [-0-9.]' | \
3492bf11819SPaul Mackerras    cut -d' ' -f3`
3502bf11819SPaul Mackerrasif [ -n "$version" ]; then
351a6afacb6SDavid Gibson    uboot_version="-n Linux-$version"
3522bf11819SPaul Mackerrasfi
3530fdd717eSScott Wood
354b18796d3SKumar Gala# physical offset of kernel image
355b18796d3SKumar Galamembase=`${CROSS}objdump -p "$kernel" | grep -m 1 LOAD | awk '{print $7}'`
356b18796d3SKumar Gala
3570fdd717eSScott Woodcase "$platform" in
3580fdd717eSScott Wooduboot)
3590fdd717eSScott Wood    rm -f "$ofile"
3603f884bf5SPeter Tyser    ${MKIMAGE} -A ppc -O linux -T kernel -C gzip -a $membase -e $membase \
361a6afacb6SDavid Gibson	$uboot_version -d "$vmz" "$ofile"
3622bf11819SPaul Mackerras    if [ -z "$cacheit" ]; then
363a9903811SScott Wood	rm -f "$vmz"
3642bf11819SPaul Mackerras    fi
3652bf11819SPaul Mackerras    exit 0
3662bf11819SPaul Mackerras    ;;
36711eab297SBenjamin Herrenschmidtuboot-obs600)
36811eab297SBenjamin Herrenschmidt    rm -f "$ofile"
36911eab297SBenjamin Herrenschmidt    # obs600 wants a multi image with an initrd, so we need to put a fake
37011eab297SBenjamin Herrenschmidt    # one in even when building a "normal" image.
37111eab297SBenjamin Herrenschmidt    if [ -n "$initrd" ]; then
37211eab297SBenjamin Herrenschmidt	real_rd="$initrd"
37311eab297SBenjamin Herrenschmidt    else
37411eab297SBenjamin Herrenschmidt	real_rd=`mktemp`
37511eab297SBenjamin Herrenschmidt	echo "\0" >>"$real_rd"
37611eab297SBenjamin Herrenschmidt    fi
37711eab297SBenjamin Herrenschmidt    ${MKIMAGE} -A ppc -O linux -T multi -C gzip -a $membase -e $membase \
37811eab297SBenjamin Herrenschmidt	$uboot_version -d "$vmz":"$real_rd":"$dtb" "$ofile"
37911eab297SBenjamin Herrenschmidt    if [ -z "$initrd" ]; then
38011eab297SBenjamin Herrenschmidt	rm -f "$real_rd"
38111eab297SBenjamin Herrenschmidt    fi
38211eab297SBenjamin Herrenschmidt    if [ -z "$cacheit" ]; then
38311eab297SBenjamin Herrenschmidt	rm -f "$vmz"
38411eab297SBenjamin Herrenschmidt    fi
38511eab297SBenjamin Herrenschmidt    exit 0
38611eab297SBenjamin Herrenschmidt    ;;
3872bf11819SPaul Mackerrasesac
3882bf11819SPaul Mackerras
3892bf11819SPaul Mackerrasaddsec() {
3902bf11819SPaul Mackerras    ${CROSS}objcopy $4 $1 \
3912bf11819SPaul Mackerras	--add-section=$3="$2" \
3922bf11819SPaul Mackerras	--set-section-flags=$3=contents,alloc,load,readonly,data
3932bf11819SPaul Mackerras}
3942bf11819SPaul Mackerras
395a9903811SScott Woodaddsec $tmp "$vmz" $ksection $object/empty.o
3962bf11819SPaul Mackerrasif [ -z "$cacheit" ]; then
397a9903811SScott Wood    rm -f "$vmz"
3982bf11819SPaul Mackerrasfi
3992bf11819SPaul Mackerras
4002bf11819SPaul Mackerrasif [ -n "$initrd" ]; then
401c888554bSMark A. Greer    addsec $tmp "$initrd" $isection
4022bf11819SPaul Mackerrasfi
4032bf11819SPaul Mackerras
4042bf11819SPaul Mackerrasif [ -n "$dtb" ]; then
405c888554bSMark A. Greer    addsec $tmp "$dtb" .kernel:dtb
406e9c4b4bdSMark A. Greer    if [ -n "$dts" ]; then
407e9c4b4bdSMark A. Greer	rm $dtb
408e9c4b4bdSMark A. Greer    fi
4092bf11819SPaul Mackerrasfi
4102bf11819SPaul Mackerras
4112bf11819SPaul Mackerrasif [ "$platform" != "miboot" ]; then
4129b09c6d9STony Breeds    if [ -n "$link_address" ] ; then
4136975a783SMichael Ellerman        text_start="-Ttext $link_address"
4149b09c6d9STony Breeds    fi
415147c0516SCédric Le Goater    ${CROSS}ld -m $format -T $lds $text_start $pie -o "$ofile" \
416cd197ffcSDavid Gibson	$platformo $tmp $object/wrapper.a
4172bf11819SPaul Mackerras    rm $tmp
4182bf11819SPaul Mackerrasfi
4192bf11819SPaul Mackerras
420a6afacb6SDavid Gibson# Some platforms need the zImage's entry point and base address
421a6afacb6SDavid Gibsonbase=0x`${CROSS}nm "$ofile" | grep ' _start$' | cut -d' ' -f1`
422a6afacb6SDavid Gibsonentry=`${CROSS}objdump -f "$ofile" | grep '^start address ' | cut -d' ' -f3`
423a6afacb6SDavid Gibson
42411c146ccSScott Woodif [ -n "$binary" ]; then
42511c146ccSScott Wood    mv "$ofile" "$ofile".elf
426aeb4552fSScott Wood    ${CROSS}objcopy -O binary "$ofile".elf "$ofile"
42711c146ccSScott Woodfi
42811c146ccSScott Wood
4292bf11819SPaul Mackerras# post-processing needed for some platforms
4302bf11819SPaul Mackerrascase "$platform" in
43158706ef9SCorey Minyardpseries|chrp|maple)
4325663a123SPaul Mackerras    $objbin/addnote "$ofile"
4330dcd4401SPaul Mackerras    ;;
434627aa944SMilton Millercoff)
435cd197ffcSDavid Gibson    ${CROSS}objcopy -O aixcoff-rs6000 --set-start "$entry" "$ofile"
4365c539ee3SDavid Woodhouse    $objbin/hack-coff "$ofile"
4372bf11819SPaul Mackerras    ;;
4380fdd717eSScott Woodcuboot*)
439c4f56af0SMichal Marek    gzip -n -f -9 "$ofile"
4403f884bf5SPeter Tyser    ${MKIMAGE} -A ppc -O linux -T kernel -C gzip -a "$base" -e "$entry" \
441aeb4552fSScott Wood            $uboot_version -d "$ofile".gz "$ofile"
4420fdd717eSScott Wood    ;;
443f6dfc805SDavid Gibsontreeboot*)
444f6dfc805SDavid Gibson    mv "$ofile" "$ofile.elf"
4455c539ee3SDavid Woodhouse    $objbin/mktree "$ofile.elf" "$ofile" "$base" "$entry"
446f6dfc805SDavid Gibson    if [ -z "$cacheit" ]; then
447f6dfc805SDavid Gibson	rm -f "$ofile.elf"
448f6dfc805SDavid Gibson    fi
449f6dfc805SDavid Gibson    exit 0
450f6dfc805SDavid Gibson    ;;
451bafdb645SGeoff Levandps3)
4525761eaa3SGeoff Levand    # The ps3's loader supports loading a gzipped binary image from flash
4535761eaa3SGeoff Levand    # rom to ram addr zero. The loader then enters the system reset
4545761eaa3SGeoff Levand    # vector at addr 0x100.  A bootwrapper overlay is used to arrange for
4555761eaa3SGeoff Levand    # a binary image of the kernel to be at addr zero, and yet have a
4565761eaa3SGeoff Levand    # suitable bootwrapper entry at 0x100.  To construct the final rom
4575761eaa3SGeoff Levand    # image 512 bytes from offset 0x100 is copied to the bootwrapper
4585761eaa3SGeoff Levand    # place holder at symbol __system_reset_kernel.  The 512 bytes of the
4595761eaa3SGeoff Levand    # bootwrapper entry code at symbol __system_reset_overlay is then
4605761eaa3SGeoff Levand    # copied to offset 0x100.  At runtime the bootwrapper program copies
4615761eaa3SGeoff Levand    # the data at __system_reset_kernel back to addr 0x100.
462bafdb645SGeoff Levand
463aeb4552fSScott Wood    system_reset_overlay=0x`${CROSS}nm "$ofile" \
464bafdb645SGeoff Levand        | grep ' __system_reset_overlay$'       \
465bafdb645SGeoff Levand        | cut -d' ' -f1`
466bafdb645SGeoff Levand    system_reset_overlay=`printf "%d" $system_reset_overlay`
467aeb4552fSScott Wood    system_reset_kernel=0x`${CROSS}nm "$ofile" \
468bafdb645SGeoff Levand        | grep ' __system_reset_kernel$'       \
469bafdb645SGeoff Levand        | cut -d' ' -f1`
470bafdb645SGeoff Levand    system_reset_kernel=`printf "%d" $system_reset_kernel`
471bafdb645SGeoff Levand    overlay_dest="256"
4725761eaa3SGeoff Levand    overlay_size="512"
473bafdb645SGeoff Levand
474aeb4552fSScott Wood    ${CROSS}objcopy -O binary "$ofile" "$ofile.bin"
475aeb4552fSScott Wood
476*879c26d4SGeoff Levand    run_cmd dd if="$ofile.bin" of="$ofile.bin" conv=notrunc   \
477bafdb645SGeoff Levand        skip=$overlay_dest seek=$system_reset_kernel          \
478d4740373SGrant Likely        count=$overlay_size bs=1
479bafdb645SGeoff Levand
480*879c26d4SGeoff Levand    run_cmd dd if="$ofile.bin" of="$ofile.bin" conv=notrunc   \
481bafdb645SGeoff Levand        skip=$system_reset_overlay seek=$overlay_dest         \
482d4740373SGrant Likely        count=$overlay_size bs=1
483bafdb645SGeoff Levand
484928b9695SDavid Woodhouse    odir="$(dirname "$ofile.bin")"
485928b9695SDavid Woodhouse    rm -f "$odir/otheros.bld"
486c4f56af0SMichal Marek    gzip -n --force -9 --stdout "$ofile.bin" > "$odir/otheros.bld"
487bafdb645SGeoff Levand    ;;
4882bf11819SPaul Mackerrasesac
489