xref: /linux/arch/powerpc/boot/wrapper (revision f61200d3e3386e78d49677dfb3911c9d7c0dfe4b)
12bf11819SPaul Mackerras#!/bin/sh
200b46d22SThomas Gleixner# SPDX-License-Identifier: GPL-2.0-only
32bf11819SPaul Mackerras
42bf11819SPaul Mackerras# Copyright (C) 2006 Paul Mackerras, IBM Corporation <paulus@samba.org>
52bf11819SPaul Mackerras
62bf11819SPaul Mackerras# This script takes a kernel binary and optionally an initrd image
72bf11819SPaul Mackerras# and/or a device-tree blob, and creates a bootable zImage for a
82bf11819SPaul Mackerras# given platform.
92bf11819SPaul Mackerras
102bf11819SPaul Mackerras# Options:
112bf11819SPaul Mackerras# -o zImage	specify output file
122bf11819SPaul Mackerras# -p platform	specify platform (links in $platform.o)
132bf11819SPaul Mackerras# -i initrd	specify initrd file
142bf11819SPaul Mackerras# -d devtree	specify device-tree blob
152bf11819SPaul Mackerras# -s tree.dts	specify device-tree source file (needs dtc installed)
16528229d2SBenjamin Herrenschmidt# -e esm_blob   specify ESM blob for secure images
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 .)
23f1e510bbSOliver O'Halloran# -z		use gzip (legacy)
24f1e510bbSOliver O'Halloran# -Z zsuffix    compression to use (gz, xz or none)
252bf11819SPaul Mackerras
26d4740373SGrant Likely# Stop execution if any command fails
27d4740373SGrant Likelyset -e
28d4740373SGrant Likely
297f66c1fdSGrant Likely# Allow for verbose output
307f66c1fdSGrant Likelyif [ "$V" = 1 ]; then
317f66c1fdSGrant Likely    set -x
32*f61200d3SGeoff Levand    map="-Map wrapper.map"
337f66c1fdSGrant Likelyfi
347f66c1fdSGrant Likely
352bf11819SPaul Mackerras# defaults
362bf11819SPaul Mackerraskernel=
372bf11819SPaul Mackerrasofile=zImage
382bf11819SPaul Mackerrasplatform=of
392bf11819SPaul Mackerrasinitrd=
402bf11819SPaul Mackerrasdtb=
412bf11819SPaul Mackerrasdts=
42528229d2SBenjamin Herrenschmidtesm_blob=
432bf11819SPaul Mackerrascacheit=
4411c146ccSScott Woodbinary=
45f1e510bbSOliver O'Hallorancompression=.gz
46fbded57cSChristophe Leroyuboot_comp=gzip
476975a783SMichael Ellermanpie=
48147c0516SCédric Le Goaterformat=
492bf11819SPaul Mackerras
502bf11819SPaul Mackerras# cross-compilation prefix
512bf11819SPaul MackerrasCROSS=
522bf11819SPaul Mackerras
533f884bf5SPeter Tyser# mkimage wrapper script
543f884bf5SPeter TyserMKIMAGE=$srctree/scripts/mkuboot.sh
553f884bf5SPeter Tyser
562bf11819SPaul Mackerras# directory for object and other files used by this script
572bf11819SPaul Mackerrasobject=arch/powerpc/boot
585c539ee3SDavid Woodhouseobjbin=$object
59c79b2973SLucian Adrian Grijincudtc=scripts/dtc/dtc
602bf11819SPaul Mackerras
612bf11819SPaul Mackerras# directory for working files
622bf11819SPaul Mackerrastmpdir=.
632bf11819SPaul Mackerras
642bf11819SPaul Mackerrasusage() {
652bf11819SPaul Mackerras    echo 'Usage: wrapper [-o output] [-p platform] [-i initrd]' >&2
66528229d2SBenjamin Herrenschmidt    echo '       [-d devtree] [-s tree.dts] [-e esm_blob]' >&2
67528229d2SBenjamin Herrenschmidt    echo '       [-c] [-C cross-prefix] [-D datadir] [-W workingdir]' >&2
68528229d2SBenjamin Herrenschmidt    echo '       [-Z (gz|xz|none)] [--no-compression] [vmlinux]' >&2
692bf11819SPaul Mackerras    exit 1
702bf11819SPaul Mackerras}
712bf11819SPaul Mackerras
72879c26d4SGeoff Levandrun_cmd() {
73879c26d4SGeoff Levand    if [ "$V" = 1 ]; then
74879c26d4SGeoff Levand        $* 2>&1
75879c26d4SGeoff Levand    else
76879c26d4SGeoff Levand        local msg
77879c26d4SGeoff Levand
78879c26d4SGeoff Levand        set +e
79879c26d4SGeoff Levand        msg=$($* 2>&1)
80879c26d4SGeoff Levand
81879c26d4SGeoff Levand        if [ $? -ne "0" ]; then
82879c26d4SGeoff Levand                echo $msg
83879c26d4SGeoff Levand                exit 1
84879c26d4SGeoff Levand        fi
85879c26d4SGeoff Levand        set -e
86879c26d4SGeoff Levand    fi
87879c26d4SGeoff Levand}
88879c26d4SGeoff Levand
892bf11819SPaul Mackerraswhile [ "$#" -gt 0 ]; do
902bf11819SPaul Mackerras    case "$1" in
912bf11819SPaul Mackerras    -o)
922bf11819SPaul Mackerras	shift
932bf11819SPaul Mackerras	[ "$#" -gt 0 ] || usage
942bf11819SPaul Mackerras	ofile="$1"
952bf11819SPaul Mackerras	;;
962bf11819SPaul Mackerras    -p)
972bf11819SPaul Mackerras	shift
982bf11819SPaul Mackerras	[ "$#" -gt 0 ] || usage
992bf11819SPaul Mackerras	platform="$1"
1002bf11819SPaul Mackerras	;;
1012bf11819SPaul Mackerras    -i)
1022bf11819SPaul Mackerras	shift
1032bf11819SPaul Mackerras	[ "$#" -gt 0 ] || usage
1042bf11819SPaul Mackerras	initrd="$1"
1052bf11819SPaul Mackerras	;;
1062bf11819SPaul Mackerras    -d)
1072bf11819SPaul Mackerras	shift
1082bf11819SPaul Mackerras	[ "$#" -gt 0 ] || usage
1092bf11819SPaul Mackerras	dtb="$1"
1102bf11819SPaul Mackerras	;;
111528229d2SBenjamin Herrenschmidt    -e)
112528229d2SBenjamin Herrenschmidt	shift
113528229d2SBenjamin Herrenschmidt	[ "$#" -gt 0 ] || usage
114528229d2SBenjamin Herrenschmidt	esm_blob="$1"
115528229d2SBenjamin Herrenschmidt	;;
1162bf11819SPaul Mackerras    -s)
1172bf11819SPaul Mackerras	shift
1182bf11819SPaul Mackerras	[ "$#" -gt 0 ] || usage
1192bf11819SPaul Mackerras	dts="$1"
1202bf11819SPaul Mackerras	;;
1212bf11819SPaul Mackerras    -c)
1222bf11819SPaul Mackerras	cacheit=y
1232bf11819SPaul Mackerras	;;
1242bf11819SPaul Mackerras    -C)
1252bf11819SPaul Mackerras	shift
1262bf11819SPaul Mackerras	[ "$#" -gt 0 ] || usage
1272bf11819SPaul Mackerras	CROSS="$1"
1282bf11819SPaul Mackerras	;;
1292bf11819SPaul Mackerras    -D)
1302bf11819SPaul Mackerras	shift
1312bf11819SPaul Mackerras	[ "$#" -gt 0 ] || usage
1322bf11819SPaul Mackerras	object="$1"
1335c539ee3SDavid Woodhouse	objbin="$1"
1342bf11819SPaul Mackerras	;;
1352bf11819SPaul Mackerras    -W)
1362bf11819SPaul Mackerras	shift
1372bf11819SPaul Mackerras	[ "$#" -gt 0 ] || usage
1382bf11819SPaul Mackerras	tmpdir="$1"
1392bf11819SPaul Mackerras	;;
140f1e510bbSOliver O'Halloran    -z)
141f1e510bbSOliver O'Halloran	compression=.gz
142fbded57cSChristophe Leroy	uboot_comp=gzip
143f1e510bbSOliver O'Halloran	;;
144f1e510bbSOliver O'Halloran    -Z)
145f1e510bbSOliver O'Halloran	shift
146f1e510bbSOliver O'Halloran	[ "$#" -gt 0 ] || usage
147264bffadSChristophe Leroy        [ "$1" != "gz" -o "$1" != "xz" -o "$1" != "lzma" -o "$1" != "lzo" -o "$1" != "none" ] || usage
148f1e510bbSOliver O'Halloran
149f1e510bbSOliver O'Halloran	compression=".$1"
150fbded57cSChristophe Leroy	uboot_comp=$1
151f1e510bbSOliver O'Halloran
152f1e510bbSOliver O'Halloran        if [ $compression = ".none" ]; then
153f1e510bbSOliver O'Halloran                compression=
154fbded57cSChristophe Leroy		uboot_comp=none
155fbded57cSChristophe Leroy        fi
156fbded57cSChristophe Leroy	if [ $uboot_comp = "gz" ]; then
157fbded57cSChristophe Leroy		uboot_comp=gzip
158f1e510bbSOliver O'Halloran	fi
159f1e510bbSOliver O'Halloran	;;
160a9903811SScott Wood    --no-gzip)
161f1e510bbSOliver O'Halloran        # a "feature" of the the wrapper script is that it can be used outside
162f1e510bbSOliver O'Halloran        # the kernel tree. So keeping this around for backwards compatibility.
163f1e510bbSOliver O'Halloran        compression=
164fbded57cSChristophe Leroy	uboot_comp=none
165a9903811SScott Wood        ;;
1662bf11819SPaul Mackerras    -?)
1672bf11819SPaul Mackerras	usage
1682bf11819SPaul Mackerras	;;
1692bf11819SPaul Mackerras    *)
1702bf11819SPaul Mackerras	[ -z "$kernel" ] || usage
1712bf11819SPaul Mackerras	kernel="$1"
1722bf11819SPaul Mackerras	;;
1732bf11819SPaul Mackerras    esac
1742bf11819SPaul Mackerras    shift
1752bf11819SPaul Mackerrasdone
1762bf11819SPaul Mackerras
177f1e510bbSOliver O'Halloran
1782bf11819SPaul Mackerrasif [ -n "$dts" ]; then
179701172d1SDavid Woodhouse    if [ ! -r "$dts" -a -r "$object/dts/$dts" ]; then
180701172d1SDavid Woodhouse	dts="$object/dts/$dts"
181701172d1SDavid Woodhouse    fi
1822bf11819SPaul Mackerras    if [ -z "$dtb" ]; then
1832bf11819SPaul Mackerras	dtb="$platform.dtb"
1842bf11819SPaul Mackerras    fi
185c79b2973SLucian Adrian Grijincu    $dtc -O dtb -o "$dtb" -b 0 "$dts"
1862bf11819SPaul Mackerrasfi
1872bf11819SPaul Mackerras
1882bf11819SPaul Mackerrasif [ -z "$kernel" ]; then
1892bf11819SPaul Mackerras    kernel=vmlinux
1902bf11819SPaul Mackerrasfi
1912bf11819SPaul Mackerras
19258531b0cSLaurent VivierLANG=C elfformat="`${CROSS}objdump -p "$kernel" | grep 'file format' | awk '{print $4}'`"
193147c0516SCédric Le Goatercase "$elfformat" in
194147c0516SCédric Le Goater    elf64-powerpcle)	format=elf64lppc	;;
195147c0516SCédric Le Goater    elf64-powerpc)	format=elf32ppc	;;
196147c0516SCédric Le Goater    elf32-powerpc)	format=elf32ppc	;;
197147c0516SCédric Le Goateresac
198147c0516SCédric Le Goater
199ff45000fSNicholas Pigginld_version()
200ff45000fSNicholas Piggin{
201ff45000fSNicholas Piggin    # Poached from scripts/ld-version.sh, but we don't want to call that because
202ff45000fSNicholas Piggin    # this script (wrapper) is distributed separately from the kernel source.
203ff45000fSNicholas Piggin    # Extract linker version number from stdin and turn into single number.
204ff45000fSNicholas Piggin    awk '{
205ff45000fSNicholas Piggin	gsub(".*\\)", "");
206ff45000fSNicholas Piggin	gsub(".*version ", "");
207ff45000fSNicholas Piggin	gsub("-.*", "");
208ff45000fSNicholas Piggin	split($1,a, ".");
209ff45000fSNicholas Piggin	print a[1]*100000000 + a[2]*1000000 + a[3]*10000;
210ff45000fSNicholas Piggin	exit
211ff45000fSNicholas Piggin    }'
212ff45000fSNicholas Piggin}
213ff45000fSNicholas Piggin
214ff45000fSNicholas Piggin# Do not include PT_INTERP segment when linking pie. Non-pie linking
215ff45000fSNicholas Piggin# just ignores this option.
216ff45000fSNicholas PigginLD_VERSION=$(${CROSS}ld --version | ld_version)
217ff45000fSNicholas PigginLD_NO_DL_MIN_VERSION=$(echo 2.26 | ld_version)
218ff45000fSNicholas Pigginif [ "$LD_VERSION" -ge "$LD_NO_DL_MIN_VERSION" ] ; then
219ff45000fSNicholas Piggin	nodl="--no-dynamic-linker"
220ff45000fSNicholas Pigginfi
221147c0516SCédric Le Goater
2222bf11819SPaul Mackerrasplatformo=$object/"$platform".o
2232bf11819SPaul Mackerraslds=$object/zImage.lds
2242bf11819SPaul Mackerrasext=strip
2252bf11819SPaul Mackerrasobjflags=-S
2262bf11819SPaul Mackerrastmp=$tmpdir/zImage.$$.o
2272bf11819SPaul Mackerrasksection=.kernel:vmlinux.strip
2282bf11819SPaul Mackerrasisection=.kernel:initrd
229528229d2SBenjamin Herrenschmidtesection=.kernel:esm_blob
2309b09c6d9STony Breedslink_address='0x400000'
231dfbc2d75SStephen Rothwellmake_space=y
2322bf11819SPaul Mackerras
233528229d2SBenjamin Herrenschmidt
234528229d2SBenjamin Herrenschmidtif [ -n "$esm_blob" -a "$platform" != "pseries" ]; then
235528229d2SBenjamin Herrenschmidt    echo "ESM blob not support on non-pseries platforms" >&2
236528229d2SBenjamin Herrenschmidt    exit 1
237528229d2SBenjamin Herrenschmidtfi
238528229d2SBenjamin Herrenschmidt
2392bf11819SPaul Mackerrascase "$platform" in
24044790a0bSBenjamin Herrenschmidtof)
24144790a0bSBenjamin Herrenschmidt    platformo="$object/of.o $object/epapr.o"
24244790a0bSBenjamin Herrenschmidt    make_space=n
24344790a0bSBenjamin Herrenschmidt    ;;
2449b09c6d9STony Breedspseries)
2452d9afb36SCédric Le Goater    platformo="$object/pseries-head.o $object/of.o $object/epapr.o"
2469b09c6d9STony Breeds    link_address='0x4000000'
247147c0516SCédric Le Goater    if [ "$format" != "elf32ppc" ]; then
248147c0516SCédric Le Goater	link_address=
249147c0516SCédric Le Goater	pie=-pie
250147c0516SCédric Le Goater    fi
251f5467e28SPaul Mackerras    make_space=n
2529b09c6d9STony Breeds    ;;
25358706ef9SCorey Minyardmaple)
2540c9fa291SBenjamin Herrenschmidt    platformo="$object/of.o $object/epapr.o"
25558706ef9SCorey Minyard    link_address='0x400000'
256f5467e28SPaul Mackerras    make_space=n
25758706ef9SCorey Minyard    ;;
2589b09c6d9STony Breedspmac|chrp)
2590c9fa291SBenjamin Herrenschmidt    platformo="$object/of.o $object/epapr.o"
260f5467e28SPaul Mackerras    make_space=n
2612bf11819SPaul Mackerras    ;;
262627aa944SMilton Millercoff)
2630c9fa291SBenjamin Herrenschmidt    platformo="$object/crt0.o $object/of.o $object/epapr.o"
2642bf11819SPaul Mackerras    lds=$object/zImage.coff.lds
2659b09c6d9STony Breeds    link_address='0x500000'
266f5467e28SPaul Mackerras    make_space=n
2676975a783SMichael Ellerman    pie=
2682bf11819SPaul Mackerras    ;;
26911eab297SBenjamin Herrenschmidtmiboot|uboot*)
2702bf11819SPaul Mackerras    # miboot and U-boot want just the bare bits, not an ELF binary
2712bf11819SPaul Mackerras    ext=bin
2722bf11819SPaul Mackerras    objflags="-O binary"
2732bf11819SPaul Mackerras    tmp="$ofile"
2742bf11819SPaul Mackerras    ksection=image
2752bf11819SPaul Mackerras    isection=initrd
2762bf11819SPaul Mackerras    ;;
2770fdd717eSScott Woodcuboot*)
27811c146ccSScott Wood    binary=y
279f1e510bbSOliver O'Halloran    compression=
28025431333SGrant Likely    case "$platform" in
2818dd217b2SScott Wood    *-mpc866ads|*-mpc885ads|*-adder875*|*-ep88xc)
28225431333SGrant Likely        platformo=$object/cuboot-8xx.o
28325431333SGrant Likely        ;;
28425431333SGrant Likely    *5200*|*-motionpro)
28525431333SGrant Likely        platformo=$object/cuboot-52xx.o
28625431333SGrant Likely        ;;
28725431333SGrant Likely    *-pq2fads|*-ep8248e|*-mpc8272*|*-storcenter)
28825431333SGrant Likely        platformo=$object/cuboot-pq2.o
28925431333SGrant Likely        ;;
29025431333SGrant Likely    *-mpc824*)
29125431333SGrant Likely        platformo=$object/cuboot-824x.o
29225431333SGrant Likely        ;;
29359d13f9dSBryan O'Donoghue    *-mpc83*|*-asp834x*)
29425431333SGrant Likely        platformo=$object/cuboot-83xx.o
29525431333SGrant Likely        ;;
296ff880112SAlexandr Smirnov    *-tqm8541|*-mpc8560*|*-tqm8560|*-tqm8555|*-ksi8560*)
29725431333SGrant Likely        platformo=$object/cuboot-85xx-cpm2.o
29825431333SGrant Likely        ;;
2996dd1b64aSWolfgang Grandegger    *-mpc85*|*-tqm85*|*-sbc85*)
30025431333SGrant Likely        platformo=$object/cuboot-85xx.o
30125431333SGrant Likely        ;;
3028f23735dSGerhard Pircher    *-amigaone)
3038f23735dSGerhard Pircher        link_address='0x800000'
3048f23735dSGerhard Pircher        ;;
30525431333SGrant Likely    esac
3060fdd717eSScott Wood    ;;
307bafdb645SGeoff Levandps3)
308bafdb645SGeoff Levand    platformo="$object/ps3-head.o $object/ps3-hvcall.o $object/ps3.o"
309bafdb645SGeoff Levand    lds=$object/zImage.ps3.lds
310f1e510bbSOliver O'Halloran    compression=
311bafdb645SGeoff Levand    ext=bin
312bafdb645SGeoff Levand    objflags="-O binary --set-section-flags=.bss=contents,alloc,load,data"
313bafdb645SGeoff Levand    ksection=.kernel:vmlinux.bin
314bafdb645SGeoff Levand    isection=.kernel:initrd
3159b09c6d9STony Breeds    link_address=''
316dfbc2d75SStephen Rothwell    make_space=n
3176975a783SMichael Ellerman    pie=
318bafdb645SGeoff Levand    ;;
319a55387e5SScott Woodep88xc|ep405|ep8248e)
32011c146ccSScott Wood    platformo="$object/fixed-head.o $object/$platform.o"
32111c146ccSScott Wood    binary=y
32211c146ccSScott Wood    ;;
323a55387e5SScott Woodadder875-redboot)
324a55387e5SScott Wood    platformo="$object/fixed-head.o $object/redboot-8xx.o"
325a55387e5SScott Wood    binary=y
326a55387e5SScott Wood    ;;
327d2477b5cSGrant Likelysimpleboot-virtex405-*)
328d58577d8SJohn Linn    platformo="$object/virtex405-head.o $object/simpleboot.o $object/virtex.o"
329d58577d8SJohn Linn    binary=y
330d58577d8SJohn Linn    ;;
331d58577d8SJohn Linnsimpleboot-virtex440-*)
332a7e1cf0cSGrant Likely    platformo="$object/fixed-head.o $object/simpleboot.o $object/virtex.o"
333d2477b5cSGrant Likely    binary=y
334d2477b5cSGrant Likely    ;;
3351d46e379SGrant Likelysimpleboot-*)
336a7e1cf0cSGrant Likely    platformo="$object/fixed-head.o $object/simpleboot.o"
3371d46e379SGrant Likely    binary=y
3381d46e379SGrant Likely    ;;
33959d13f9dSBryan O'Donoghueasp834x-redboot)
34059d13f9dSBryan O'Donoghue    platformo="$object/fixed-head.o $object/redboot-83xx.o"
34159d13f9dSBryan O'Donoghue    binary=y
34259d13f9dSBryan O'Donoghue    ;;
34324760823SNate Casexpedite52*)
34424760823SNate Case    link_address='0x1400000'
34524760823SNate Case    platformo=$object/cuboot-85xx.o
34624760823SNate Case    ;;
3476cdd2417SAlbert Herranzgamecube|wii)
348b68a24bcSAlbert Herranz    link_address='0x600000'
349b68a24bcSAlbert Herranz    platformo="$object/$platform-head.o $object/$platform.o"
350b68a24bcSAlbert Herranz    ;;
351228d5505STony Breedstreeboot-currituck)
352228d5505STony Breeds    link_address='0x1000000'
353228d5505STony Breeds    ;;
3542a2c74b2SAlistair Poppletreeboot-akebono)
3552a2c74b2SAlistair Popple    link_address='0x1000000'
3562a2c74b2SAlistair Popple    ;;
357b4e8c8ddSTorez Smithtreeboot-iss4xx-mpic)
358b4e8c8ddSTorez Smith    platformo="$object/treeboot-iss4xx.o"
359b4e8c8ddSTorez Smith    ;;
3606c5b59b9SDavid Gibsonepapr)
36190d1d44eSJeremy Kerr    platformo="$object/pseries-head.o $object/epapr.o $object/epapr-wrapper.o"
3626c5b59b9SDavid Gibson    link_address='0x20000000'
3636c5b59b9SDavid Gibson    pie=-pie
3646c5b59b9SDavid Gibson    ;;
365be201981SStephen Chiversmvme5100)
366be201981SStephen Chivers    platformo="$object/fixed-head.o $object/mvme5100.o"
367be201981SStephen Chivers    binary=y
368be201981SStephen Chivers    ;;
36997493e2eSAlessio Igor Boganimvme7100)
37097493e2eSAlessio Igor Bogani    platformo="$object/motload-head.o $object/mvme7100.o"
37197493e2eSAlessio Igor Bogani    link_address='0x4000000'
37297493e2eSAlessio Igor Bogani    binary=y
37397493e2eSAlessio Igor Bogani    ;;
3742bf11819SPaul Mackerrasesac
3752bf11819SPaul Mackerras
3762bf11819SPaul Mackerrasvmz="$tmpdir/`basename \"$kernel\"`.$ext"
377a9903811SScott Wood
378f1e510bbSOliver O'Halloran# Calculate the vmlinux.strip size
379f1e510bbSOliver O'Halloran${CROSS}objcopy $objflags "$kernel" "$vmz.$$"
380a670b0b4SMichael Forneystrip_size=$(${CONFIG_SHELL} "${srctree}/scripts/file-size.sh" "$vmz.$$")
381c55aef0eSSuzuki Poulose
382f1e510bbSOliver O'Halloranif [ -z "$cacheit" -o ! -f "$vmz$compression" -o "$vmz$compression" -ot "$kernel" ]; then
383f1e510bbSOliver O'Halloran    # recompress the image if we need to
384f1e510bbSOliver O'Halloran    case $compression in
385f1e510bbSOliver O'Halloran    .xz)
386f1e510bbSOliver O'Halloran        xz --check=crc32 -f -6 "$vmz.$$"
387f1e510bbSOliver O'Halloran        ;;
388f1e510bbSOliver O'Halloran    .gz)
389c4f56af0SMichal Marek        gzip -n -f -9 "$vmz.$$"
390f1e510bbSOliver O'Halloran        ;;
3911cc9a21bSChristophe Leroy    .lzma)
3921cc9a21bSChristophe Leroy        xz --format=lzma -f -6 "$vmz.$$"
3931cc9a21bSChristophe Leroy	;;
394264bffadSChristophe Leroy    .lzo)
395264bffadSChristophe Leroy        lzop -f -9 "$vmz.$$"
396264bffadSChristophe Leroy	;;
397f1e510bbSOliver O'Halloran    *)
398f1e510bbSOliver O'Halloran        # drop the compression suffix so the stripped vmlinux is used
399f1e510bbSOliver O'Halloran        compression=
400fbded57cSChristophe Leroy	uboot_comp=none
401f1e510bbSOliver O'Halloran	;;
402f1e510bbSOliver O'Halloran    esac
403a9903811SScott Wood
4042bf11819SPaul Mackerras    if [ -n "$cacheit" ]; then
405f1e510bbSOliver O'Halloran	mv -f "$vmz.$$$compression" "$vmz$compression"
4062bf11819SPaul Mackerras    else
4072bf11819SPaul Mackerras	vmz="$vmz.$$"
4082bf11819SPaul Mackerras    fi
409c55aef0eSSuzuki Pouloseelse
410c55aef0eSSuzuki Poulose    rm -f $vmz.$$
411c55aef0eSSuzuki Poulosefi
412c55aef0eSSuzuki Poulose
413f1e510bbSOliver O'Halloranvmz="$vmz$compression"
414f1e510bbSOliver O'Halloran
415dfbc2d75SStephen Rothwellif [ "$make_space" = "y" ]; then
416c55aef0eSSuzuki Poulose	# Round the size to next higher MB limit
417c55aef0eSSuzuki Poulose	round_size=$(((strip_size + 0xfffff) & 0xfff00000))
418c55aef0eSSuzuki Poulose
419c55aef0eSSuzuki Poulose	round_size=0x$(printf "%x" $round_size)
420c55aef0eSSuzuki Poulose	link_addr=$(printf "%d" $link_address)
421c55aef0eSSuzuki Poulose
422c55aef0eSSuzuki Poulose	if [ $link_addr -lt $strip_size ]; then
423eba3d97dSSuzuki Poulose	    echo "INFO: Uncompressed kernel (size 0x$(printf "%x\n" $strip_size))" \
424c55aef0eSSuzuki Poulose			"overlaps the address of the wrapper($link_address)"
425eba3d97dSSuzuki Poulose	    echo "INFO: Fixing the link_address of wrapper to ($round_size)"
426c55aef0eSSuzuki Poulose	    link_address=$round_size
4272bf11819SPaul Mackerras	fi
428dfbc2d75SStephen Rothwellfi
4292bf11819SPaul Mackerras
430a6afacb6SDavid Gibson# Extract kernel version information, some platforms want to include
431a6afacb6SDavid Gibson# it in the image header
4322bf11819SPaul Mackerrasversion=`${CROSS}strings "$kernel" | grep '^Linux version [-0-9.]' | \
4332bf11819SPaul Mackerras    cut -d' ' -f3`
4342bf11819SPaul Mackerrasif [ -n "$version" ]; then
435a6afacb6SDavid Gibson    uboot_version="-n Linux-$version"
4362bf11819SPaul Mackerrasfi
4370fdd717eSScott Wood
438b18796d3SKumar Gala# physical offset of kernel image
439b18796d3SKumar Galamembase=`${CROSS}objdump -p "$kernel" | grep -m 1 LOAD | awk '{print $7}'`
440b18796d3SKumar Gala
4410fdd717eSScott Woodcase "$platform" in
4420fdd717eSScott Wooduboot)
4430fdd717eSScott Wood    rm -f "$ofile"
444fbded57cSChristophe Leroy    ${MKIMAGE} -A ppc -O linux -T kernel -C $uboot_comp -a $membase -e $membase \
445a6afacb6SDavid Gibson	$uboot_version -d "$vmz" "$ofile"
4462bf11819SPaul Mackerras    if [ -z "$cacheit" ]; then
447a9903811SScott Wood	rm -f "$vmz"
4482bf11819SPaul Mackerras    fi
4492bf11819SPaul Mackerras    exit 0
4502bf11819SPaul Mackerras    ;;
45111eab297SBenjamin Herrenschmidtuboot-obs600)
45211eab297SBenjamin Herrenschmidt    rm -f "$ofile"
45311eab297SBenjamin Herrenschmidt    # obs600 wants a multi image with an initrd, so we need to put a fake
45411eab297SBenjamin Herrenschmidt    # one in even when building a "normal" image.
45511eab297SBenjamin Herrenschmidt    if [ -n "$initrd" ]; then
45611eab297SBenjamin Herrenschmidt	real_rd="$initrd"
45711eab297SBenjamin Herrenschmidt    else
45811eab297SBenjamin Herrenschmidt	real_rd=`mktemp`
45911eab297SBenjamin Herrenschmidt	echo "\0" >>"$real_rd"
46011eab297SBenjamin Herrenschmidt    fi
46111eab297SBenjamin Herrenschmidt    ${MKIMAGE} -A ppc -O linux -T multi -C gzip -a $membase -e $membase \
46211eab297SBenjamin Herrenschmidt	$uboot_version -d "$vmz":"$real_rd":"$dtb" "$ofile"
46311eab297SBenjamin Herrenschmidt    if [ -z "$initrd" ]; then
46411eab297SBenjamin Herrenschmidt	rm -f "$real_rd"
46511eab297SBenjamin Herrenschmidt    fi
46611eab297SBenjamin Herrenschmidt    if [ -z "$cacheit" ]; then
46711eab297SBenjamin Herrenschmidt	rm -f "$vmz"
46811eab297SBenjamin Herrenschmidt    fi
46911eab297SBenjamin Herrenschmidt    exit 0
47011eab297SBenjamin Herrenschmidt    ;;
4712bf11819SPaul Mackerrasesac
4722bf11819SPaul Mackerras
4732bf11819SPaul Mackerrasaddsec() {
4742bf11819SPaul Mackerras    ${CROSS}objcopy $4 $1 \
4752bf11819SPaul Mackerras	--add-section=$3="$2" \
4762bf11819SPaul Mackerras	--set-section-flags=$3=contents,alloc,load,readonly,data
4772bf11819SPaul Mackerras}
4782bf11819SPaul Mackerras
479a9903811SScott Woodaddsec $tmp "$vmz" $ksection $object/empty.o
4802bf11819SPaul Mackerrasif [ -z "$cacheit" ]; then
481a9903811SScott Wood    rm -f "$vmz"
4822bf11819SPaul Mackerrasfi
4832bf11819SPaul Mackerras
4842bf11819SPaul Mackerrasif [ -n "$initrd" ]; then
485c888554bSMark A. Greer    addsec $tmp "$initrd" $isection
4862bf11819SPaul Mackerrasfi
4872bf11819SPaul Mackerras
4882bf11819SPaul Mackerrasif [ -n "$dtb" ]; then
489c888554bSMark A. Greer    addsec $tmp "$dtb" .kernel:dtb
490e9c4b4bdSMark A. Greer    if [ -n "$dts" ]; then
491e9c4b4bdSMark A. Greer	rm $dtb
492e9c4b4bdSMark A. Greer    fi
4932bf11819SPaul Mackerrasfi
4942bf11819SPaul Mackerras
495528229d2SBenjamin Herrenschmidtif [ -n "$esm_blob" ]; then
496528229d2SBenjamin Herrenschmidt    addsec $tmp "$esm_blob" $esection
497528229d2SBenjamin Herrenschmidtfi
498528229d2SBenjamin Herrenschmidt
4992bf11819SPaul Mackerrasif [ "$platform" != "miboot" ]; then
5009b09c6d9STony Breeds    if [ -n "$link_address" ] ; then
5016975a783SMichael Ellerman        text_start="-Ttext $link_address"
5029b09c6d9STony Breeds    fi
503f1e510bbSOliver O'Halloran#link everything
504*f61200d3SGeoff Levand    ${CROSS}ld -m $format -T $lds $text_start $pie $nodl -o "$ofile" $map \
505cd197ffcSDavid Gibson	$platformo $tmp $object/wrapper.a
5062bf11819SPaul Mackerras    rm $tmp
5072bf11819SPaul Mackerrasfi
5082bf11819SPaul Mackerras
509a6afacb6SDavid Gibson# Some platforms need the zImage's entry point and base address
510a6afacb6SDavid Gibsonbase=0x`${CROSS}nm "$ofile" | grep ' _start$' | cut -d' ' -f1`
511a6afacb6SDavid Gibsonentry=`${CROSS}objdump -f "$ofile" | grep '^start address ' | cut -d' ' -f3`
512a6afacb6SDavid Gibson
51311c146ccSScott Woodif [ -n "$binary" ]; then
51411c146ccSScott Wood    mv "$ofile" "$ofile".elf
515aeb4552fSScott Wood    ${CROSS}objcopy -O binary "$ofile".elf "$ofile"
51611c146ccSScott Woodfi
51711c146ccSScott Wood
5182bf11819SPaul Mackerras# post-processing needed for some platforms
5192bf11819SPaul Mackerrascase "$platform" in
52058706ef9SCorey Minyardpseries|chrp|maple)
5215663a123SPaul Mackerras    $objbin/addnote "$ofile"
5220dcd4401SPaul Mackerras    ;;
523627aa944SMilton Millercoff)
524cd197ffcSDavid Gibson    ${CROSS}objcopy -O aixcoff-rs6000 --set-start "$entry" "$ofile"
5255c539ee3SDavid Woodhouse    $objbin/hack-coff "$ofile"
5262bf11819SPaul Mackerras    ;;
5270fdd717eSScott Woodcuboot*)
528c4f56af0SMichal Marek    gzip -n -f -9 "$ofile"
5293f884bf5SPeter Tyser    ${MKIMAGE} -A ppc -O linux -T kernel -C gzip -a "$base" -e "$entry" \
530aeb4552fSScott Wood            $uboot_version -d "$ofile".gz "$ofile"
5310fdd717eSScott Wood    ;;
532f6dfc805SDavid Gibsontreeboot*)
533f6dfc805SDavid Gibson    mv "$ofile" "$ofile.elf"
5345c539ee3SDavid Woodhouse    $objbin/mktree "$ofile.elf" "$ofile" "$base" "$entry"
535f6dfc805SDavid Gibson    if [ -z "$cacheit" ]; then
536f6dfc805SDavid Gibson	rm -f "$ofile.elf"
537f6dfc805SDavid Gibson    fi
538f6dfc805SDavid Gibson    exit 0
539f6dfc805SDavid Gibson    ;;
540bafdb645SGeoff Levandps3)
5415761eaa3SGeoff Levand    # The ps3's loader supports loading a gzipped binary image from flash
5425761eaa3SGeoff Levand    # rom to ram addr zero. The loader then enters the system reset
5435761eaa3SGeoff Levand    # vector at addr 0x100.  A bootwrapper overlay is used to arrange for
5445761eaa3SGeoff Levand    # a binary image of the kernel to be at addr zero, and yet have a
5455761eaa3SGeoff Levand    # suitable bootwrapper entry at 0x100.  To construct the final rom
5465761eaa3SGeoff Levand    # image 512 bytes from offset 0x100 is copied to the bootwrapper
5475761eaa3SGeoff Levand    # place holder at symbol __system_reset_kernel.  The 512 bytes of the
5485761eaa3SGeoff Levand    # bootwrapper entry code at symbol __system_reset_overlay is then
5495761eaa3SGeoff Levand    # copied to offset 0x100.  At runtime the bootwrapper program copies
5505761eaa3SGeoff Levand    # the data at __system_reset_kernel back to addr 0x100.
551bafdb645SGeoff Levand
552aeb4552fSScott Wood    system_reset_overlay=0x`${CROSS}nm "$ofile" \
553bafdb645SGeoff Levand        | grep ' __system_reset_overlay$'       \
554bafdb645SGeoff Levand        | cut -d' ' -f1`
555bafdb645SGeoff Levand    system_reset_overlay=`printf "%d" $system_reset_overlay`
556aeb4552fSScott Wood    system_reset_kernel=0x`${CROSS}nm "$ofile" \
557bafdb645SGeoff Levand        | grep ' __system_reset_kernel$'       \
558bafdb645SGeoff Levand        | cut -d' ' -f1`
559bafdb645SGeoff Levand    system_reset_kernel=`printf "%d" $system_reset_kernel`
560bafdb645SGeoff Levand    overlay_dest="256"
5615761eaa3SGeoff Levand    overlay_size="512"
562bafdb645SGeoff Levand
563aeb4552fSScott Wood    ${CROSS}objcopy -O binary "$ofile" "$ofile.bin"
564aeb4552fSScott Wood
565879c26d4SGeoff Levand    run_cmd dd if="$ofile.bin" of="$ofile.bin" conv=notrunc   \
566bafdb645SGeoff Levand        skip=$overlay_dest seek=$system_reset_kernel          \
567d4740373SGrant Likely        count=$overlay_size bs=1
568bafdb645SGeoff Levand
569879c26d4SGeoff Levand    run_cmd dd if="$ofile.bin" of="$ofile.bin" conv=notrunc   \
570bafdb645SGeoff Levand        skip=$system_reset_overlay seek=$overlay_dest         \
571d4740373SGrant Likely        count=$overlay_size bs=1
572bafdb645SGeoff Levand
573928b9695SDavid Woodhouse    odir="$(dirname "$ofile.bin")"
574928b9695SDavid Woodhouse    rm -f "$odir/otheros.bld"
575c4f56af0SMichal Marek    gzip -n --force -9 --stdout "$ofile.bin" > "$odir/otheros.bld"
576bafdb645SGeoff Levand    ;;
5772bf11819SPaul Mackerrasesac
578