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 .) 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 327f66c1fdSGrant Likelyfi 337f66c1fdSGrant Likely 342bf11819SPaul Mackerras# defaults 352bf11819SPaul Mackerraskernel= 362bf11819SPaul Mackerrasofile=zImage 372bf11819SPaul Mackerrasplatform=of 382bf11819SPaul Mackerrasinitrd= 392bf11819SPaul Mackerrasdtb= 402bf11819SPaul Mackerrasdts= 412bf11819SPaul Mackerrascacheit= 4211c146ccSScott Woodbinary= 43f1e510bbSOliver O'Hallorancompression=.gz 44fbded57cSChristophe Leroyuboot_comp=gzip 456975a783SMichael Ellermanpie= 46147c0516SCédric Le Goaterformat= 472bf11819SPaul Mackerras 482bf11819SPaul Mackerras# cross-compilation prefix 492bf11819SPaul MackerrasCROSS= 502bf11819SPaul Mackerras 513f884bf5SPeter Tyser# mkimage wrapper script 523f884bf5SPeter TyserMKIMAGE=$srctree/scripts/mkuboot.sh 533f884bf5SPeter Tyser 542bf11819SPaul Mackerras# directory for object and other files used by this script 552bf11819SPaul Mackerrasobject=arch/powerpc/boot 565c539ee3SDavid Woodhouseobjbin=$object 57c79b2973SLucian Adrian Grijincudtc=scripts/dtc/dtc 582bf11819SPaul Mackerras 592bf11819SPaul Mackerras# directory for working files 602bf11819SPaul Mackerrastmpdir=. 612bf11819SPaul Mackerras 622bf11819SPaul Mackerrasusage() { 632bf11819SPaul Mackerras echo 'Usage: wrapper [-o output] [-p platform] [-i initrd]' >&2 642bf11819SPaul Mackerras echo ' [-d devtree] [-s tree.dts] [-c] [-C cross-prefix]' >&2 65f1e510bbSOliver O'Halloran echo ' [-D datadir] [-W workingdir] [-Z (gz|xz|none)]' >&2 66f1e510bbSOliver O'Halloran echo ' [--no-compression] [vmlinux]' >&2 672bf11819SPaul Mackerras exit 1 682bf11819SPaul Mackerras} 692bf11819SPaul Mackerras 70879c26d4SGeoff Levandrun_cmd() { 71879c26d4SGeoff Levand if [ "$V" = 1 ]; then 72879c26d4SGeoff Levand $* 2>&1 73879c26d4SGeoff Levand else 74879c26d4SGeoff Levand local msg 75879c26d4SGeoff Levand 76879c26d4SGeoff Levand set +e 77879c26d4SGeoff Levand msg=$($* 2>&1) 78879c26d4SGeoff Levand 79879c26d4SGeoff Levand if [ $? -ne "0" ]; then 80879c26d4SGeoff Levand echo $msg 81879c26d4SGeoff Levand exit 1 82879c26d4SGeoff Levand fi 83879c26d4SGeoff Levand set -e 84879c26d4SGeoff Levand fi 85879c26d4SGeoff Levand} 86879c26d4SGeoff Levand 872bf11819SPaul Mackerraswhile [ "$#" -gt 0 ]; do 882bf11819SPaul Mackerras case "$1" in 892bf11819SPaul Mackerras -o) 902bf11819SPaul Mackerras shift 912bf11819SPaul Mackerras [ "$#" -gt 0 ] || usage 922bf11819SPaul Mackerras ofile="$1" 932bf11819SPaul Mackerras ;; 942bf11819SPaul Mackerras -p) 952bf11819SPaul Mackerras shift 962bf11819SPaul Mackerras [ "$#" -gt 0 ] || usage 972bf11819SPaul Mackerras platform="$1" 982bf11819SPaul Mackerras ;; 992bf11819SPaul Mackerras -i) 1002bf11819SPaul Mackerras shift 1012bf11819SPaul Mackerras [ "$#" -gt 0 ] || usage 1022bf11819SPaul Mackerras initrd="$1" 1032bf11819SPaul Mackerras ;; 1042bf11819SPaul Mackerras -d) 1052bf11819SPaul Mackerras shift 1062bf11819SPaul Mackerras [ "$#" -gt 0 ] || usage 1072bf11819SPaul Mackerras dtb="$1" 1082bf11819SPaul Mackerras ;; 1092bf11819SPaul Mackerras -s) 1102bf11819SPaul Mackerras shift 1112bf11819SPaul Mackerras [ "$#" -gt 0 ] || usage 1122bf11819SPaul Mackerras dts="$1" 1132bf11819SPaul Mackerras ;; 1142bf11819SPaul Mackerras -c) 1152bf11819SPaul Mackerras cacheit=y 1162bf11819SPaul Mackerras ;; 1172bf11819SPaul Mackerras -C) 1182bf11819SPaul Mackerras shift 1192bf11819SPaul Mackerras [ "$#" -gt 0 ] || usage 1202bf11819SPaul Mackerras CROSS="$1" 1212bf11819SPaul Mackerras ;; 1222bf11819SPaul Mackerras -D) 1232bf11819SPaul Mackerras shift 1242bf11819SPaul Mackerras [ "$#" -gt 0 ] || usage 1252bf11819SPaul Mackerras object="$1" 1265c539ee3SDavid Woodhouse objbin="$1" 1272bf11819SPaul Mackerras ;; 1282bf11819SPaul Mackerras -W) 1292bf11819SPaul Mackerras shift 1302bf11819SPaul Mackerras [ "$#" -gt 0 ] || usage 1312bf11819SPaul Mackerras tmpdir="$1" 1322bf11819SPaul Mackerras ;; 133f1e510bbSOliver O'Halloran -z) 134f1e510bbSOliver O'Halloran compression=.gz 135fbded57cSChristophe Leroy uboot_comp=gzip 136f1e510bbSOliver O'Halloran ;; 137f1e510bbSOliver O'Halloran -Z) 138f1e510bbSOliver O'Halloran shift 139f1e510bbSOliver O'Halloran [ "$#" -gt 0 ] || usage 140*1cc9a21bSChristophe Leroy [ "$1" != "gz" -o "$1" != "xz" -o "$1" != "lzma" -o "$1" != "none" ] || usage 141f1e510bbSOliver O'Halloran 142f1e510bbSOliver O'Halloran compression=".$1" 143fbded57cSChristophe Leroy uboot_comp=$1 144f1e510bbSOliver O'Halloran 145f1e510bbSOliver O'Halloran if [ $compression = ".none" ]; then 146f1e510bbSOliver O'Halloran compression= 147fbded57cSChristophe Leroy uboot_comp=none 148fbded57cSChristophe Leroy fi 149fbded57cSChristophe Leroy if [ $uboot_comp = "gz" ]; then 150fbded57cSChristophe Leroy uboot_comp=gzip 151f1e510bbSOliver O'Halloran fi 152f1e510bbSOliver O'Halloran ;; 153a9903811SScott Wood --no-gzip) 154f1e510bbSOliver O'Halloran # a "feature" of the the wrapper script is that it can be used outside 155f1e510bbSOliver O'Halloran # the kernel tree. So keeping this around for backwards compatibility. 156f1e510bbSOliver O'Halloran compression= 157fbded57cSChristophe Leroy uboot_comp=none 158a9903811SScott Wood ;; 1592bf11819SPaul Mackerras -?) 1602bf11819SPaul Mackerras usage 1612bf11819SPaul Mackerras ;; 1622bf11819SPaul Mackerras *) 1632bf11819SPaul Mackerras [ -z "$kernel" ] || usage 1642bf11819SPaul Mackerras kernel="$1" 1652bf11819SPaul Mackerras ;; 1662bf11819SPaul Mackerras esac 1672bf11819SPaul Mackerras shift 1682bf11819SPaul Mackerrasdone 1692bf11819SPaul Mackerras 170f1e510bbSOliver O'Halloran 1712bf11819SPaul Mackerrasif [ -n "$dts" ]; then 172701172d1SDavid Woodhouse if [ ! -r "$dts" -a -r "$object/dts/$dts" ]; then 173701172d1SDavid Woodhouse dts="$object/dts/$dts" 174701172d1SDavid Woodhouse fi 1752bf11819SPaul Mackerras if [ -z "$dtb" ]; then 1762bf11819SPaul Mackerras dtb="$platform.dtb" 1772bf11819SPaul Mackerras fi 178c79b2973SLucian Adrian Grijincu $dtc -O dtb -o "$dtb" -b 0 "$dts" 1792bf11819SPaul Mackerrasfi 1802bf11819SPaul Mackerras 1812bf11819SPaul Mackerrasif [ -z "$kernel" ]; then 1822bf11819SPaul Mackerras kernel=vmlinux 1832bf11819SPaul Mackerrasfi 1842bf11819SPaul Mackerras 18558531b0cSLaurent VivierLANG=C elfformat="`${CROSS}objdump -p "$kernel" | grep 'file format' | awk '{print $4}'`" 186147c0516SCédric Le Goatercase "$elfformat" in 187147c0516SCédric Le Goater elf64-powerpcle) format=elf64lppc ;; 188147c0516SCédric Le Goater elf64-powerpc) format=elf32ppc ;; 189147c0516SCédric Le Goater elf32-powerpc) format=elf32ppc ;; 190147c0516SCédric Le Goateresac 191147c0516SCédric Le Goater 192ff45000fSNicholas Pigginld_version() 193ff45000fSNicholas Piggin{ 194ff45000fSNicholas Piggin # Poached from scripts/ld-version.sh, but we don't want to call that because 195ff45000fSNicholas Piggin # this script (wrapper) is distributed separately from the kernel source. 196ff45000fSNicholas Piggin # Extract linker version number from stdin and turn into single number. 197ff45000fSNicholas Piggin awk '{ 198ff45000fSNicholas Piggin gsub(".*\\)", ""); 199ff45000fSNicholas Piggin gsub(".*version ", ""); 200ff45000fSNicholas Piggin gsub("-.*", ""); 201ff45000fSNicholas Piggin split($1,a, "."); 202ff45000fSNicholas Piggin print a[1]*100000000 + a[2]*1000000 + a[3]*10000; 203ff45000fSNicholas Piggin exit 204ff45000fSNicholas Piggin }' 205ff45000fSNicholas Piggin} 206ff45000fSNicholas Piggin 207ff45000fSNicholas Piggin# Do not include PT_INTERP segment when linking pie. Non-pie linking 208ff45000fSNicholas Piggin# just ignores this option. 209ff45000fSNicholas PigginLD_VERSION=$(${CROSS}ld --version | ld_version) 210ff45000fSNicholas PigginLD_NO_DL_MIN_VERSION=$(echo 2.26 | ld_version) 211ff45000fSNicholas Pigginif [ "$LD_VERSION" -ge "$LD_NO_DL_MIN_VERSION" ] ; then 212ff45000fSNicholas Piggin nodl="--no-dynamic-linker" 213ff45000fSNicholas Pigginfi 214147c0516SCédric Le Goater 2152bf11819SPaul Mackerrasplatformo=$object/"$platform".o 2162bf11819SPaul Mackerraslds=$object/zImage.lds 2172bf11819SPaul Mackerrasext=strip 2182bf11819SPaul Mackerrasobjflags=-S 2192bf11819SPaul Mackerrastmp=$tmpdir/zImage.$$.o 2202bf11819SPaul Mackerrasksection=.kernel:vmlinux.strip 2212bf11819SPaul Mackerrasisection=.kernel:initrd 2229b09c6d9STony Breedslink_address='0x400000' 223dfbc2d75SStephen Rothwellmake_space=y 2242bf11819SPaul Mackerras 2252bf11819SPaul Mackerrascase "$platform" in 22644790a0bSBenjamin Herrenschmidtof) 22744790a0bSBenjamin Herrenschmidt platformo="$object/of.o $object/epapr.o" 22844790a0bSBenjamin Herrenschmidt make_space=n 22944790a0bSBenjamin Herrenschmidt ;; 2309b09c6d9STony Breedspseries) 2312d9afb36SCédric Le Goater platformo="$object/pseries-head.o $object/of.o $object/epapr.o" 2329b09c6d9STony Breeds link_address='0x4000000' 233147c0516SCédric Le Goater if [ "$format" != "elf32ppc" ]; then 234147c0516SCédric Le Goater link_address= 235147c0516SCédric Le Goater pie=-pie 236147c0516SCédric Le Goater fi 237f5467e28SPaul Mackerras make_space=n 2389b09c6d9STony Breeds ;; 23958706ef9SCorey Minyardmaple) 2400c9fa291SBenjamin Herrenschmidt platformo="$object/of.o $object/epapr.o" 24158706ef9SCorey Minyard link_address='0x400000' 242f5467e28SPaul Mackerras make_space=n 24358706ef9SCorey Minyard ;; 2449b09c6d9STony Breedspmac|chrp) 2450c9fa291SBenjamin Herrenschmidt platformo="$object/of.o $object/epapr.o" 246f5467e28SPaul Mackerras make_space=n 2472bf11819SPaul Mackerras ;; 248627aa944SMilton Millercoff) 2490c9fa291SBenjamin Herrenschmidt platformo="$object/crt0.o $object/of.o $object/epapr.o" 2502bf11819SPaul Mackerras lds=$object/zImage.coff.lds 2519b09c6d9STony Breeds link_address='0x500000' 252f5467e28SPaul Mackerras make_space=n 2536975a783SMichael Ellerman pie= 2542bf11819SPaul Mackerras ;; 25511eab297SBenjamin Herrenschmidtmiboot|uboot*) 2562bf11819SPaul Mackerras # miboot and U-boot want just the bare bits, not an ELF binary 2572bf11819SPaul Mackerras ext=bin 2582bf11819SPaul Mackerras objflags="-O binary" 2592bf11819SPaul Mackerras tmp="$ofile" 2602bf11819SPaul Mackerras ksection=image 2612bf11819SPaul Mackerras isection=initrd 2622bf11819SPaul Mackerras ;; 2630fdd717eSScott Woodcuboot*) 26411c146ccSScott Wood binary=y 265f1e510bbSOliver O'Halloran compression= 26625431333SGrant Likely case "$platform" in 2678dd217b2SScott Wood *-mpc866ads|*-mpc885ads|*-adder875*|*-ep88xc) 26825431333SGrant Likely platformo=$object/cuboot-8xx.o 26925431333SGrant Likely ;; 27025431333SGrant Likely *5200*|*-motionpro) 27125431333SGrant Likely platformo=$object/cuboot-52xx.o 27225431333SGrant Likely ;; 27325431333SGrant Likely *-pq2fads|*-ep8248e|*-mpc8272*|*-storcenter) 27425431333SGrant Likely platformo=$object/cuboot-pq2.o 27525431333SGrant Likely ;; 27625431333SGrant Likely *-mpc824*) 27725431333SGrant Likely platformo=$object/cuboot-824x.o 27825431333SGrant Likely ;; 27959d13f9dSBryan O'Donoghue *-mpc83*|*-asp834x*) 28025431333SGrant Likely platformo=$object/cuboot-83xx.o 28125431333SGrant Likely ;; 282ff880112SAlexandr Smirnov *-tqm8541|*-mpc8560*|*-tqm8560|*-tqm8555|*-ksi8560*) 28325431333SGrant Likely platformo=$object/cuboot-85xx-cpm2.o 28425431333SGrant Likely ;; 2856dd1b64aSWolfgang Grandegger *-mpc85*|*-tqm85*|*-sbc85*) 28625431333SGrant Likely platformo=$object/cuboot-85xx.o 28725431333SGrant Likely ;; 2888f23735dSGerhard Pircher *-amigaone) 2898f23735dSGerhard Pircher link_address='0x800000' 2908f23735dSGerhard Pircher ;; 29125431333SGrant Likely esac 2920fdd717eSScott Wood ;; 293bafdb645SGeoff Levandps3) 294bafdb645SGeoff Levand platformo="$object/ps3-head.o $object/ps3-hvcall.o $object/ps3.o" 295bafdb645SGeoff Levand lds=$object/zImage.ps3.lds 296f1e510bbSOliver O'Halloran compression= 297bafdb645SGeoff Levand ext=bin 298bafdb645SGeoff Levand objflags="-O binary --set-section-flags=.bss=contents,alloc,load,data" 299bafdb645SGeoff Levand ksection=.kernel:vmlinux.bin 300bafdb645SGeoff Levand isection=.kernel:initrd 3019b09c6d9STony Breeds link_address='' 302dfbc2d75SStephen Rothwell make_space=n 3036975a783SMichael Ellerman pie= 304bafdb645SGeoff Levand ;; 305a55387e5SScott Woodep88xc|ep405|ep8248e) 30611c146ccSScott Wood platformo="$object/fixed-head.o $object/$platform.o" 30711c146ccSScott Wood binary=y 30811c146ccSScott Wood ;; 309a55387e5SScott Woodadder875-redboot) 310a55387e5SScott Wood platformo="$object/fixed-head.o $object/redboot-8xx.o" 311a55387e5SScott Wood binary=y 312a55387e5SScott Wood ;; 313d2477b5cSGrant Likelysimpleboot-virtex405-*) 314d58577d8SJohn Linn platformo="$object/virtex405-head.o $object/simpleboot.o $object/virtex.o" 315d58577d8SJohn Linn binary=y 316d58577d8SJohn Linn ;; 317d58577d8SJohn Linnsimpleboot-virtex440-*) 318a7e1cf0cSGrant Likely platformo="$object/fixed-head.o $object/simpleboot.o $object/virtex.o" 319d2477b5cSGrant Likely binary=y 320d2477b5cSGrant Likely ;; 3211d46e379SGrant Likelysimpleboot-*) 322a7e1cf0cSGrant Likely platformo="$object/fixed-head.o $object/simpleboot.o" 3231d46e379SGrant Likely binary=y 3241d46e379SGrant Likely ;; 32559d13f9dSBryan O'Donoghueasp834x-redboot) 32659d13f9dSBryan O'Donoghue platformo="$object/fixed-head.o $object/redboot-83xx.o" 32759d13f9dSBryan O'Donoghue binary=y 32859d13f9dSBryan O'Donoghue ;; 32924760823SNate Casexpedite52*) 33024760823SNate Case link_address='0x1400000' 33124760823SNate Case platformo=$object/cuboot-85xx.o 33224760823SNate Case ;; 3336cdd2417SAlbert Herranzgamecube|wii) 334b68a24bcSAlbert Herranz link_address='0x600000' 335b68a24bcSAlbert Herranz platformo="$object/$platform-head.o $object/$platform.o" 336b68a24bcSAlbert Herranz ;; 337228d5505STony Breedstreeboot-currituck) 338228d5505STony Breeds link_address='0x1000000' 339228d5505STony Breeds ;; 3402a2c74b2SAlistair Poppletreeboot-akebono) 3412a2c74b2SAlistair Popple link_address='0x1000000' 3422a2c74b2SAlistair Popple ;; 343b4e8c8ddSTorez Smithtreeboot-iss4xx-mpic) 344b4e8c8ddSTorez Smith platformo="$object/treeboot-iss4xx.o" 345b4e8c8ddSTorez Smith ;; 3466c5b59b9SDavid Gibsonepapr) 34790d1d44eSJeremy Kerr platformo="$object/pseries-head.o $object/epapr.o $object/epapr-wrapper.o" 3486c5b59b9SDavid Gibson link_address='0x20000000' 3496c5b59b9SDavid Gibson pie=-pie 3506c5b59b9SDavid Gibson ;; 351be201981SStephen Chiversmvme5100) 352be201981SStephen Chivers platformo="$object/fixed-head.o $object/mvme5100.o" 353be201981SStephen Chivers binary=y 354be201981SStephen Chivers ;; 35597493e2eSAlessio Igor Boganimvme7100) 35697493e2eSAlessio Igor Bogani platformo="$object/motload-head.o $object/mvme7100.o" 35797493e2eSAlessio Igor Bogani link_address='0x4000000' 35897493e2eSAlessio Igor Bogani binary=y 35997493e2eSAlessio Igor Bogani ;; 3602bf11819SPaul Mackerrasesac 3612bf11819SPaul Mackerras 3622bf11819SPaul Mackerrasvmz="$tmpdir/`basename \"$kernel\"`.$ext" 363a9903811SScott Wood 364f1e510bbSOliver O'Halloran# Calculate the vmlinux.strip size 365f1e510bbSOliver O'Halloran${CROSS}objcopy $objflags "$kernel" "$vmz.$$" 366a670b0b4SMichael Forneystrip_size=$(${CONFIG_SHELL} "${srctree}/scripts/file-size.sh" "$vmz.$$") 367c55aef0eSSuzuki Poulose 368f1e510bbSOliver O'Halloranif [ -z "$cacheit" -o ! -f "$vmz$compression" -o "$vmz$compression" -ot "$kernel" ]; then 369f1e510bbSOliver O'Halloran # recompress the image if we need to 370f1e510bbSOliver O'Halloran case $compression in 371f1e510bbSOliver O'Halloran .xz) 372f1e510bbSOliver O'Halloran xz --check=crc32 -f -6 "$vmz.$$" 373f1e510bbSOliver O'Halloran ;; 374f1e510bbSOliver O'Halloran .gz) 375c4f56af0SMichal Marek gzip -n -f -9 "$vmz.$$" 376f1e510bbSOliver O'Halloran ;; 377*1cc9a21bSChristophe Leroy .lzma) 378*1cc9a21bSChristophe Leroy xz --format=lzma -f -6 "$vmz.$$" 379*1cc9a21bSChristophe Leroy ;; 380f1e510bbSOliver O'Halloran *) 381f1e510bbSOliver O'Halloran # drop the compression suffix so the stripped vmlinux is used 382f1e510bbSOliver O'Halloran compression= 383fbded57cSChristophe Leroy uboot_comp=none 384f1e510bbSOliver O'Halloran ;; 385f1e510bbSOliver O'Halloran esac 386a9903811SScott Wood 3872bf11819SPaul Mackerras if [ -n "$cacheit" ]; then 388f1e510bbSOliver O'Halloran mv -f "$vmz.$$$compression" "$vmz$compression" 3892bf11819SPaul Mackerras else 3902bf11819SPaul Mackerras vmz="$vmz.$$" 3912bf11819SPaul Mackerras fi 392c55aef0eSSuzuki Pouloseelse 393c55aef0eSSuzuki Poulose rm -f $vmz.$$ 394c55aef0eSSuzuki Poulosefi 395c55aef0eSSuzuki Poulose 396f1e510bbSOliver O'Halloranvmz="$vmz$compression" 397f1e510bbSOliver O'Halloran 398dfbc2d75SStephen Rothwellif [ "$make_space" = "y" ]; then 399c55aef0eSSuzuki Poulose # Round the size to next higher MB limit 400c55aef0eSSuzuki Poulose round_size=$(((strip_size + 0xfffff) & 0xfff00000)) 401c55aef0eSSuzuki Poulose 402c55aef0eSSuzuki Poulose round_size=0x$(printf "%x" $round_size) 403c55aef0eSSuzuki Poulose link_addr=$(printf "%d" $link_address) 404c55aef0eSSuzuki Poulose 405c55aef0eSSuzuki Poulose if [ $link_addr -lt $strip_size ]; then 406eba3d97dSSuzuki Poulose echo "INFO: Uncompressed kernel (size 0x$(printf "%x\n" $strip_size))" \ 407c55aef0eSSuzuki Poulose "overlaps the address of the wrapper($link_address)" 408eba3d97dSSuzuki Poulose echo "INFO: Fixing the link_address of wrapper to ($round_size)" 409c55aef0eSSuzuki Poulose link_address=$round_size 4102bf11819SPaul Mackerras fi 411dfbc2d75SStephen Rothwellfi 4122bf11819SPaul Mackerras 413a6afacb6SDavid Gibson# Extract kernel version information, some platforms want to include 414a6afacb6SDavid Gibson# it in the image header 4152bf11819SPaul Mackerrasversion=`${CROSS}strings "$kernel" | grep '^Linux version [-0-9.]' | \ 4162bf11819SPaul Mackerras cut -d' ' -f3` 4172bf11819SPaul Mackerrasif [ -n "$version" ]; then 418a6afacb6SDavid Gibson uboot_version="-n Linux-$version" 4192bf11819SPaul Mackerrasfi 4200fdd717eSScott Wood 421b18796d3SKumar Gala# physical offset of kernel image 422b18796d3SKumar Galamembase=`${CROSS}objdump -p "$kernel" | grep -m 1 LOAD | awk '{print $7}'` 423b18796d3SKumar Gala 4240fdd717eSScott Woodcase "$platform" in 4250fdd717eSScott Wooduboot) 4260fdd717eSScott Wood rm -f "$ofile" 427fbded57cSChristophe Leroy ${MKIMAGE} -A ppc -O linux -T kernel -C $uboot_comp -a $membase -e $membase \ 428a6afacb6SDavid Gibson $uboot_version -d "$vmz" "$ofile" 4292bf11819SPaul Mackerras if [ -z "$cacheit" ]; then 430a9903811SScott Wood rm -f "$vmz" 4312bf11819SPaul Mackerras fi 4322bf11819SPaul Mackerras exit 0 4332bf11819SPaul Mackerras ;; 43411eab297SBenjamin Herrenschmidtuboot-obs600) 43511eab297SBenjamin Herrenschmidt rm -f "$ofile" 43611eab297SBenjamin Herrenschmidt # obs600 wants a multi image with an initrd, so we need to put a fake 43711eab297SBenjamin Herrenschmidt # one in even when building a "normal" image. 43811eab297SBenjamin Herrenschmidt if [ -n "$initrd" ]; then 43911eab297SBenjamin Herrenschmidt real_rd="$initrd" 44011eab297SBenjamin Herrenschmidt else 44111eab297SBenjamin Herrenschmidt real_rd=`mktemp` 44211eab297SBenjamin Herrenschmidt echo "\0" >>"$real_rd" 44311eab297SBenjamin Herrenschmidt fi 44411eab297SBenjamin Herrenschmidt ${MKIMAGE} -A ppc -O linux -T multi -C gzip -a $membase -e $membase \ 44511eab297SBenjamin Herrenschmidt $uboot_version -d "$vmz":"$real_rd":"$dtb" "$ofile" 44611eab297SBenjamin Herrenschmidt if [ -z "$initrd" ]; then 44711eab297SBenjamin Herrenschmidt rm -f "$real_rd" 44811eab297SBenjamin Herrenschmidt fi 44911eab297SBenjamin Herrenschmidt if [ -z "$cacheit" ]; then 45011eab297SBenjamin Herrenschmidt rm -f "$vmz" 45111eab297SBenjamin Herrenschmidt fi 45211eab297SBenjamin Herrenschmidt exit 0 45311eab297SBenjamin Herrenschmidt ;; 4542bf11819SPaul Mackerrasesac 4552bf11819SPaul Mackerras 4562bf11819SPaul Mackerrasaddsec() { 4572bf11819SPaul Mackerras ${CROSS}objcopy $4 $1 \ 4582bf11819SPaul Mackerras --add-section=$3="$2" \ 4592bf11819SPaul Mackerras --set-section-flags=$3=contents,alloc,load,readonly,data 4602bf11819SPaul Mackerras} 4612bf11819SPaul Mackerras 462a9903811SScott Woodaddsec $tmp "$vmz" $ksection $object/empty.o 4632bf11819SPaul Mackerrasif [ -z "$cacheit" ]; then 464a9903811SScott Wood rm -f "$vmz" 4652bf11819SPaul Mackerrasfi 4662bf11819SPaul Mackerras 4672bf11819SPaul Mackerrasif [ -n "$initrd" ]; then 468c888554bSMark A. Greer addsec $tmp "$initrd" $isection 4692bf11819SPaul Mackerrasfi 4702bf11819SPaul Mackerras 4712bf11819SPaul Mackerrasif [ -n "$dtb" ]; then 472c888554bSMark A. Greer addsec $tmp "$dtb" .kernel:dtb 473e9c4b4bdSMark A. Greer if [ -n "$dts" ]; then 474e9c4b4bdSMark A. Greer rm $dtb 475e9c4b4bdSMark A. Greer fi 4762bf11819SPaul Mackerrasfi 4772bf11819SPaul Mackerras 4782bf11819SPaul Mackerrasif [ "$platform" != "miboot" ]; then 4799b09c6d9STony Breeds if [ -n "$link_address" ] ; then 4806975a783SMichael Ellerman text_start="-Ttext $link_address" 4819b09c6d9STony Breeds fi 482f1e510bbSOliver O'Halloran#link everything 483ff45000fSNicholas Piggin ${CROSS}ld -m $format -T $lds $text_start $pie $nodl -o "$ofile" \ 484cd197ffcSDavid Gibson $platformo $tmp $object/wrapper.a 4852bf11819SPaul Mackerras rm $tmp 4862bf11819SPaul Mackerrasfi 4872bf11819SPaul Mackerras 488a6afacb6SDavid Gibson# Some platforms need the zImage's entry point and base address 489a6afacb6SDavid Gibsonbase=0x`${CROSS}nm "$ofile" | grep ' _start$' | cut -d' ' -f1` 490a6afacb6SDavid Gibsonentry=`${CROSS}objdump -f "$ofile" | grep '^start address ' | cut -d' ' -f3` 491a6afacb6SDavid Gibson 49211c146ccSScott Woodif [ -n "$binary" ]; then 49311c146ccSScott Wood mv "$ofile" "$ofile".elf 494aeb4552fSScott Wood ${CROSS}objcopy -O binary "$ofile".elf "$ofile" 49511c146ccSScott Woodfi 49611c146ccSScott Wood 4972bf11819SPaul Mackerras# post-processing needed for some platforms 4982bf11819SPaul Mackerrascase "$platform" in 49958706ef9SCorey Minyardpseries|chrp|maple) 5005663a123SPaul Mackerras $objbin/addnote "$ofile" 5010dcd4401SPaul Mackerras ;; 502627aa944SMilton Millercoff) 503cd197ffcSDavid Gibson ${CROSS}objcopy -O aixcoff-rs6000 --set-start "$entry" "$ofile" 5045c539ee3SDavid Woodhouse $objbin/hack-coff "$ofile" 5052bf11819SPaul Mackerras ;; 5060fdd717eSScott Woodcuboot*) 507c4f56af0SMichal Marek gzip -n -f -9 "$ofile" 5083f884bf5SPeter Tyser ${MKIMAGE} -A ppc -O linux -T kernel -C gzip -a "$base" -e "$entry" \ 509aeb4552fSScott Wood $uboot_version -d "$ofile".gz "$ofile" 5100fdd717eSScott Wood ;; 511f6dfc805SDavid Gibsontreeboot*) 512f6dfc805SDavid Gibson mv "$ofile" "$ofile.elf" 5135c539ee3SDavid Woodhouse $objbin/mktree "$ofile.elf" "$ofile" "$base" "$entry" 514f6dfc805SDavid Gibson if [ -z "$cacheit" ]; then 515f6dfc805SDavid Gibson rm -f "$ofile.elf" 516f6dfc805SDavid Gibson fi 517f6dfc805SDavid Gibson exit 0 518f6dfc805SDavid Gibson ;; 519bafdb645SGeoff Levandps3) 5205761eaa3SGeoff Levand # The ps3's loader supports loading a gzipped binary image from flash 5215761eaa3SGeoff Levand # rom to ram addr zero. The loader then enters the system reset 5225761eaa3SGeoff Levand # vector at addr 0x100. A bootwrapper overlay is used to arrange for 5235761eaa3SGeoff Levand # a binary image of the kernel to be at addr zero, and yet have a 5245761eaa3SGeoff Levand # suitable bootwrapper entry at 0x100. To construct the final rom 5255761eaa3SGeoff Levand # image 512 bytes from offset 0x100 is copied to the bootwrapper 5265761eaa3SGeoff Levand # place holder at symbol __system_reset_kernel. The 512 bytes of the 5275761eaa3SGeoff Levand # bootwrapper entry code at symbol __system_reset_overlay is then 5285761eaa3SGeoff Levand # copied to offset 0x100. At runtime the bootwrapper program copies 5295761eaa3SGeoff Levand # the data at __system_reset_kernel back to addr 0x100. 530bafdb645SGeoff Levand 531aeb4552fSScott Wood system_reset_overlay=0x`${CROSS}nm "$ofile" \ 532bafdb645SGeoff Levand | grep ' __system_reset_overlay$' \ 533bafdb645SGeoff Levand | cut -d' ' -f1` 534bafdb645SGeoff Levand system_reset_overlay=`printf "%d" $system_reset_overlay` 535aeb4552fSScott Wood system_reset_kernel=0x`${CROSS}nm "$ofile" \ 536bafdb645SGeoff Levand | grep ' __system_reset_kernel$' \ 537bafdb645SGeoff Levand | cut -d' ' -f1` 538bafdb645SGeoff Levand system_reset_kernel=`printf "%d" $system_reset_kernel` 539bafdb645SGeoff Levand overlay_dest="256" 5405761eaa3SGeoff Levand overlay_size="512" 541bafdb645SGeoff Levand 542aeb4552fSScott Wood ${CROSS}objcopy -O binary "$ofile" "$ofile.bin" 543aeb4552fSScott Wood 544879c26d4SGeoff Levand run_cmd dd if="$ofile.bin" of="$ofile.bin" conv=notrunc \ 545bafdb645SGeoff Levand skip=$overlay_dest seek=$system_reset_kernel \ 546d4740373SGrant Likely count=$overlay_size bs=1 547bafdb645SGeoff Levand 548879c26d4SGeoff Levand run_cmd dd if="$ofile.bin" of="$ofile.bin" conv=notrunc \ 549bafdb645SGeoff Levand skip=$system_reset_overlay seek=$overlay_dest \ 550d4740373SGrant Likely count=$overlay_size bs=1 551bafdb645SGeoff Levand 552928b9695SDavid Woodhouse odir="$(dirname "$ofile.bin")" 553928b9695SDavid Woodhouse rm -f "$odir/otheros.bld" 554c4f56af0SMichal Marek gzip -n --force -9 --stdout "$ofile.bin" > "$odir/otheros.bld" 555bafdb645SGeoff Levand ;; 5562bf11819SPaul Mackerrasesac 557