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 446975a783SMichael Ellermanpie= 45147c0516SCédric Le Goaterformat= 462bf11819SPaul Mackerras 472bf11819SPaul Mackerras# cross-compilation prefix 482bf11819SPaul MackerrasCROSS= 492bf11819SPaul Mackerras 503f884bf5SPeter Tyser# mkimage wrapper script 513f884bf5SPeter TyserMKIMAGE=$srctree/scripts/mkuboot.sh 523f884bf5SPeter Tyser 532bf11819SPaul Mackerras# directory for object and other files used by this script 542bf11819SPaul Mackerrasobject=arch/powerpc/boot 555c539ee3SDavid Woodhouseobjbin=$object 56c79b2973SLucian Adrian Grijincudtc=scripts/dtc/dtc 572bf11819SPaul Mackerras 582bf11819SPaul Mackerras# directory for working files 592bf11819SPaul Mackerrastmpdir=. 602bf11819SPaul Mackerras 612bf11819SPaul Mackerrasusage() { 622bf11819SPaul Mackerras echo 'Usage: wrapper [-o output] [-p platform] [-i initrd]' >&2 632bf11819SPaul Mackerras echo ' [-d devtree] [-s tree.dts] [-c] [-C cross-prefix]' >&2 64f1e510bbSOliver O'Halloran echo ' [-D datadir] [-W workingdir] [-Z (gz|xz|none)]' >&2 65f1e510bbSOliver O'Halloran echo ' [--no-compression] [vmlinux]' >&2 662bf11819SPaul Mackerras exit 1 672bf11819SPaul Mackerras} 682bf11819SPaul Mackerras 69879c26d4SGeoff Levandrun_cmd() { 70879c26d4SGeoff Levand if [ "$V" = 1 ]; then 71879c26d4SGeoff Levand $* 2>&1 72879c26d4SGeoff Levand else 73879c26d4SGeoff Levand local msg 74879c26d4SGeoff Levand 75879c26d4SGeoff Levand set +e 76879c26d4SGeoff Levand msg=$($* 2>&1) 77879c26d4SGeoff Levand 78879c26d4SGeoff Levand if [ $? -ne "0" ]; then 79879c26d4SGeoff Levand echo $msg 80879c26d4SGeoff Levand exit 1 81879c26d4SGeoff Levand fi 82879c26d4SGeoff Levand set -e 83879c26d4SGeoff Levand fi 84879c26d4SGeoff Levand} 85879c26d4SGeoff Levand 862bf11819SPaul Mackerraswhile [ "$#" -gt 0 ]; do 872bf11819SPaul Mackerras case "$1" in 882bf11819SPaul Mackerras -o) 892bf11819SPaul Mackerras shift 902bf11819SPaul Mackerras [ "$#" -gt 0 ] || usage 912bf11819SPaul Mackerras ofile="$1" 922bf11819SPaul Mackerras ;; 932bf11819SPaul Mackerras -p) 942bf11819SPaul Mackerras shift 952bf11819SPaul Mackerras [ "$#" -gt 0 ] || usage 962bf11819SPaul Mackerras platform="$1" 972bf11819SPaul Mackerras ;; 982bf11819SPaul Mackerras -i) 992bf11819SPaul Mackerras shift 1002bf11819SPaul Mackerras [ "$#" -gt 0 ] || usage 1012bf11819SPaul Mackerras initrd="$1" 1022bf11819SPaul Mackerras ;; 1032bf11819SPaul Mackerras -d) 1042bf11819SPaul Mackerras shift 1052bf11819SPaul Mackerras [ "$#" -gt 0 ] || usage 1062bf11819SPaul Mackerras dtb="$1" 1072bf11819SPaul Mackerras ;; 1082bf11819SPaul Mackerras -s) 1092bf11819SPaul Mackerras shift 1102bf11819SPaul Mackerras [ "$#" -gt 0 ] || usage 1112bf11819SPaul Mackerras dts="$1" 1122bf11819SPaul Mackerras ;; 1132bf11819SPaul Mackerras -c) 1142bf11819SPaul Mackerras cacheit=y 1152bf11819SPaul Mackerras ;; 1162bf11819SPaul Mackerras -C) 1172bf11819SPaul Mackerras shift 1182bf11819SPaul Mackerras [ "$#" -gt 0 ] || usage 1192bf11819SPaul Mackerras CROSS="$1" 1202bf11819SPaul Mackerras ;; 1212bf11819SPaul Mackerras -D) 1222bf11819SPaul Mackerras shift 1232bf11819SPaul Mackerras [ "$#" -gt 0 ] || usage 1242bf11819SPaul Mackerras object="$1" 1255c539ee3SDavid Woodhouse objbin="$1" 1262bf11819SPaul Mackerras ;; 1272bf11819SPaul Mackerras -W) 1282bf11819SPaul Mackerras shift 1292bf11819SPaul Mackerras [ "$#" -gt 0 ] || usage 1302bf11819SPaul Mackerras tmpdir="$1" 1312bf11819SPaul Mackerras ;; 132f1e510bbSOliver O'Halloran -z) 133f1e510bbSOliver O'Halloran compression=.gz 134f1e510bbSOliver O'Halloran ;; 135f1e510bbSOliver O'Halloran -Z) 136f1e510bbSOliver O'Halloran shift 137f1e510bbSOliver O'Halloran [ "$#" -gt 0 ] || usage 138f1e510bbSOliver O'Halloran [ "$1" != "gz" -o "$1" != "xz" -o "$1" != "none" ] || usage 139f1e510bbSOliver O'Halloran 140f1e510bbSOliver O'Halloran compression=".$1" 141f1e510bbSOliver O'Halloran 142f1e510bbSOliver O'Halloran if [ $compression = ".none" ]; then 143f1e510bbSOliver O'Halloran compression= 144f1e510bbSOliver O'Halloran fi 145f1e510bbSOliver O'Halloran ;; 146a9903811SScott Wood --no-gzip) 147f1e510bbSOliver O'Halloran # a "feature" of the the wrapper script is that it can be used outside 148f1e510bbSOliver O'Halloran # the kernel tree. So keeping this around for backwards compatibility. 149f1e510bbSOliver O'Halloran compression= 150a9903811SScott Wood ;; 1512bf11819SPaul Mackerras -?) 1522bf11819SPaul Mackerras usage 1532bf11819SPaul Mackerras ;; 1542bf11819SPaul Mackerras *) 1552bf11819SPaul Mackerras [ -z "$kernel" ] || usage 1562bf11819SPaul Mackerras kernel="$1" 1572bf11819SPaul Mackerras ;; 1582bf11819SPaul Mackerras esac 1592bf11819SPaul Mackerras shift 1602bf11819SPaul Mackerrasdone 1612bf11819SPaul Mackerras 162f1e510bbSOliver O'Halloran 1632bf11819SPaul Mackerrasif [ -n "$dts" ]; then 164701172d1SDavid Woodhouse if [ ! -r "$dts" -a -r "$object/dts/$dts" ]; then 165701172d1SDavid Woodhouse dts="$object/dts/$dts" 166701172d1SDavid Woodhouse fi 1672bf11819SPaul Mackerras if [ -z "$dtb" ]; then 1682bf11819SPaul Mackerras dtb="$platform.dtb" 1692bf11819SPaul Mackerras fi 170c79b2973SLucian Adrian Grijincu $dtc -O dtb -o "$dtb" -b 0 "$dts" 1712bf11819SPaul Mackerrasfi 1722bf11819SPaul Mackerras 1732bf11819SPaul Mackerrasif [ -z "$kernel" ]; then 1742bf11819SPaul Mackerras kernel=vmlinux 1752bf11819SPaul Mackerrasfi 1762bf11819SPaul Mackerras 17758531b0cSLaurent VivierLANG=C elfformat="`${CROSS}objdump -p "$kernel" | grep 'file format' | awk '{print $4}'`" 178147c0516SCédric Le Goatercase "$elfformat" in 179147c0516SCédric Le Goater elf64-powerpcle) format=elf64lppc ;; 180147c0516SCédric Le Goater elf64-powerpc) format=elf32ppc ;; 181147c0516SCédric Le Goater elf32-powerpc) format=elf32ppc ;; 182147c0516SCédric Le Goateresac 183147c0516SCédric Le Goater 184*ff45000fSNicholas Pigginld_version() 185*ff45000fSNicholas Piggin{ 186*ff45000fSNicholas Piggin # Poached from scripts/ld-version.sh, but we don't want to call that because 187*ff45000fSNicholas Piggin # this script (wrapper) is distributed separately from the kernel source. 188*ff45000fSNicholas Piggin # Extract linker version number from stdin and turn into single number. 189*ff45000fSNicholas Piggin awk '{ 190*ff45000fSNicholas Piggin gsub(".*\\)", ""); 191*ff45000fSNicholas Piggin gsub(".*version ", ""); 192*ff45000fSNicholas Piggin gsub("-.*", ""); 193*ff45000fSNicholas Piggin split($1,a, "."); 194*ff45000fSNicholas Piggin print a[1]*100000000 + a[2]*1000000 + a[3]*10000; 195*ff45000fSNicholas Piggin exit 196*ff45000fSNicholas Piggin }' 197*ff45000fSNicholas Piggin} 198*ff45000fSNicholas Piggin 199*ff45000fSNicholas Piggin# Do not include PT_INTERP segment when linking pie. Non-pie linking 200*ff45000fSNicholas Piggin# just ignores this option. 201*ff45000fSNicholas PigginLD_VERSION=$(${CROSS}ld --version | ld_version) 202*ff45000fSNicholas PigginLD_NO_DL_MIN_VERSION=$(echo 2.26 | ld_version) 203*ff45000fSNicholas Pigginif [ "$LD_VERSION" -ge "$LD_NO_DL_MIN_VERSION" ] ; then 204*ff45000fSNicholas Piggin nodl="--no-dynamic-linker" 205*ff45000fSNicholas Pigginfi 206147c0516SCédric Le Goater 2072bf11819SPaul Mackerrasplatformo=$object/"$platform".o 2082bf11819SPaul Mackerraslds=$object/zImage.lds 2092bf11819SPaul Mackerrasext=strip 2102bf11819SPaul Mackerrasobjflags=-S 2112bf11819SPaul Mackerrastmp=$tmpdir/zImage.$$.o 2122bf11819SPaul Mackerrasksection=.kernel:vmlinux.strip 2132bf11819SPaul Mackerrasisection=.kernel:initrd 2149b09c6d9STony Breedslink_address='0x400000' 215dfbc2d75SStephen Rothwellmake_space=y 2162bf11819SPaul Mackerras 2172bf11819SPaul Mackerrascase "$platform" in 21844790a0bSBenjamin Herrenschmidtof) 21944790a0bSBenjamin Herrenschmidt platformo="$object/of.o $object/epapr.o" 22044790a0bSBenjamin Herrenschmidt make_space=n 22144790a0bSBenjamin Herrenschmidt ;; 2229b09c6d9STony Breedspseries) 2232d9afb36SCédric Le Goater platformo="$object/pseries-head.o $object/of.o $object/epapr.o" 2249b09c6d9STony Breeds link_address='0x4000000' 225147c0516SCédric Le Goater if [ "$format" != "elf32ppc" ]; then 226147c0516SCédric Le Goater link_address= 227147c0516SCédric Le Goater pie=-pie 228147c0516SCédric Le Goater fi 229f5467e28SPaul Mackerras make_space=n 2309b09c6d9STony Breeds ;; 23158706ef9SCorey Minyardmaple) 2320c9fa291SBenjamin Herrenschmidt platformo="$object/of.o $object/epapr.o" 23358706ef9SCorey Minyard link_address='0x400000' 234f5467e28SPaul Mackerras make_space=n 23558706ef9SCorey Minyard ;; 2369b09c6d9STony Breedspmac|chrp) 2370c9fa291SBenjamin Herrenschmidt platformo="$object/of.o $object/epapr.o" 238f5467e28SPaul Mackerras make_space=n 2392bf11819SPaul Mackerras ;; 240627aa944SMilton Millercoff) 2410c9fa291SBenjamin Herrenschmidt platformo="$object/crt0.o $object/of.o $object/epapr.o" 2422bf11819SPaul Mackerras lds=$object/zImage.coff.lds 2439b09c6d9STony Breeds link_address='0x500000' 244f5467e28SPaul Mackerras make_space=n 2456975a783SMichael Ellerman pie= 2462bf11819SPaul Mackerras ;; 24711eab297SBenjamin Herrenschmidtmiboot|uboot*) 2482bf11819SPaul Mackerras # miboot and U-boot want just the bare bits, not an ELF binary 2492bf11819SPaul Mackerras ext=bin 2502bf11819SPaul Mackerras objflags="-O binary" 2512bf11819SPaul Mackerras tmp="$ofile" 2522bf11819SPaul Mackerras ksection=image 2532bf11819SPaul Mackerras isection=initrd 2542bf11819SPaul Mackerras ;; 2550fdd717eSScott Woodcuboot*) 25611c146ccSScott Wood binary=y 257f1e510bbSOliver O'Halloran compression= 25825431333SGrant Likely case "$platform" in 2598dd217b2SScott Wood *-mpc866ads|*-mpc885ads|*-adder875*|*-ep88xc) 26025431333SGrant Likely platformo=$object/cuboot-8xx.o 26125431333SGrant Likely ;; 26225431333SGrant Likely *5200*|*-motionpro) 26325431333SGrant Likely platformo=$object/cuboot-52xx.o 26425431333SGrant Likely ;; 26525431333SGrant Likely *-pq2fads|*-ep8248e|*-mpc8272*|*-storcenter) 26625431333SGrant Likely platformo=$object/cuboot-pq2.o 26725431333SGrant Likely ;; 26825431333SGrant Likely *-mpc824*) 26925431333SGrant Likely platformo=$object/cuboot-824x.o 27025431333SGrant Likely ;; 27159d13f9dSBryan O'Donoghue *-mpc83*|*-asp834x*) 27225431333SGrant Likely platformo=$object/cuboot-83xx.o 27325431333SGrant Likely ;; 274ff880112SAlexandr Smirnov *-tqm8541|*-mpc8560*|*-tqm8560|*-tqm8555|*-ksi8560*) 27525431333SGrant Likely platformo=$object/cuboot-85xx-cpm2.o 27625431333SGrant Likely ;; 2776dd1b64aSWolfgang Grandegger *-mpc85*|*-tqm85*|*-sbc85*) 27825431333SGrant Likely platformo=$object/cuboot-85xx.o 27925431333SGrant Likely ;; 2808f23735dSGerhard Pircher *-amigaone) 2818f23735dSGerhard Pircher link_address='0x800000' 2828f23735dSGerhard Pircher ;; 28325431333SGrant Likely esac 2840fdd717eSScott Wood ;; 285bafdb645SGeoff Levandps3) 286bafdb645SGeoff Levand platformo="$object/ps3-head.o $object/ps3-hvcall.o $object/ps3.o" 287bafdb645SGeoff Levand lds=$object/zImage.ps3.lds 288f1e510bbSOliver O'Halloran compression= 289bafdb645SGeoff Levand ext=bin 290bafdb645SGeoff Levand objflags="-O binary --set-section-flags=.bss=contents,alloc,load,data" 291bafdb645SGeoff Levand ksection=.kernel:vmlinux.bin 292bafdb645SGeoff Levand isection=.kernel:initrd 2939b09c6d9STony Breeds link_address='' 294dfbc2d75SStephen Rothwell make_space=n 2956975a783SMichael Ellerman pie= 296bafdb645SGeoff Levand ;; 297a55387e5SScott Woodep88xc|ep405|ep8248e) 29811c146ccSScott Wood platformo="$object/fixed-head.o $object/$platform.o" 29911c146ccSScott Wood binary=y 30011c146ccSScott Wood ;; 301a55387e5SScott Woodadder875-redboot) 302a55387e5SScott Wood platformo="$object/fixed-head.o $object/redboot-8xx.o" 303a55387e5SScott Wood binary=y 304a55387e5SScott Wood ;; 305d2477b5cSGrant Likelysimpleboot-virtex405-*) 306d58577d8SJohn Linn platformo="$object/virtex405-head.o $object/simpleboot.o $object/virtex.o" 307d58577d8SJohn Linn binary=y 308d58577d8SJohn Linn ;; 309d58577d8SJohn Linnsimpleboot-virtex440-*) 310a7e1cf0cSGrant Likely platformo="$object/fixed-head.o $object/simpleboot.o $object/virtex.o" 311d2477b5cSGrant Likely binary=y 312d2477b5cSGrant Likely ;; 3131d46e379SGrant Likelysimpleboot-*) 314a7e1cf0cSGrant Likely platformo="$object/fixed-head.o $object/simpleboot.o" 3151d46e379SGrant Likely binary=y 3161d46e379SGrant Likely ;; 31759d13f9dSBryan O'Donoghueasp834x-redboot) 31859d13f9dSBryan O'Donoghue platformo="$object/fixed-head.o $object/redboot-83xx.o" 31959d13f9dSBryan O'Donoghue binary=y 32059d13f9dSBryan O'Donoghue ;; 32124760823SNate Casexpedite52*) 32224760823SNate Case link_address='0x1400000' 32324760823SNate Case platformo=$object/cuboot-85xx.o 32424760823SNate Case ;; 3256cdd2417SAlbert Herranzgamecube|wii) 326b68a24bcSAlbert Herranz link_address='0x600000' 327b68a24bcSAlbert Herranz platformo="$object/$platform-head.o $object/$platform.o" 328b68a24bcSAlbert Herranz ;; 329228d5505STony Breedstreeboot-currituck) 330228d5505STony Breeds link_address='0x1000000' 331228d5505STony Breeds ;; 3322a2c74b2SAlistair Poppletreeboot-akebono) 3332a2c74b2SAlistair Popple link_address='0x1000000' 3342a2c74b2SAlistair Popple ;; 335b4e8c8ddSTorez Smithtreeboot-iss4xx-mpic) 336b4e8c8ddSTorez Smith platformo="$object/treeboot-iss4xx.o" 337b4e8c8ddSTorez Smith ;; 3386c5b59b9SDavid Gibsonepapr) 33990d1d44eSJeremy Kerr platformo="$object/pseries-head.o $object/epapr.o $object/epapr-wrapper.o" 3406c5b59b9SDavid Gibson link_address='0x20000000' 3416c5b59b9SDavid Gibson pie=-pie 3426c5b59b9SDavid Gibson ;; 343be201981SStephen Chiversmvme5100) 344be201981SStephen Chivers platformo="$object/fixed-head.o $object/mvme5100.o" 345be201981SStephen Chivers binary=y 346be201981SStephen Chivers ;; 34797493e2eSAlessio Igor Boganimvme7100) 34897493e2eSAlessio Igor Bogani platformo="$object/motload-head.o $object/mvme7100.o" 34997493e2eSAlessio Igor Bogani link_address='0x4000000' 35097493e2eSAlessio Igor Bogani binary=y 35197493e2eSAlessio Igor Bogani ;; 3522bf11819SPaul Mackerrasesac 3532bf11819SPaul Mackerras 3542bf11819SPaul Mackerrasvmz="$tmpdir/`basename \"$kernel\"`.$ext" 355a9903811SScott Wood 356f1e510bbSOliver O'Halloran# Calculate the vmlinux.strip size 357f1e510bbSOliver O'Halloran${CROSS}objcopy $objflags "$kernel" "$vmz.$$" 358c55aef0eSSuzuki Poulosestrip_size=$(stat -c %s $vmz.$$) 359c55aef0eSSuzuki Poulose 360f1e510bbSOliver O'Halloranif [ -z "$cacheit" -o ! -f "$vmz$compression" -o "$vmz$compression" -ot "$kernel" ]; then 361f1e510bbSOliver O'Halloran # recompress the image if we need to 362f1e510bbSOliver O'Halloran case $compression in 363f1e510bbSOliver O'Halloran .xz) 364f1e510bbSOliver O'Halloran xz --check=crc32 -f -6 "$vmz.$$" 365f1e510bbSOliver O'Halloran ;; 366f1e510bbSOliver O'Halloran .gz) 367c4f56af0SMichal Marek gzip -n -f -9 "$vmz.$$" 368f1e510bbSOliver O'Halloran ;; 369f1e510bbSOliver O'Halloran *) 370f1e510bbSOliver O'Halloran # drop the compression suffix so the stripped vmlinux is used 371f1e510bbSOliver O'Halloran compression= 372f1e510bbSOliver O'Halloran ;; 373f1e510bbSOliver O'Halloran esac 374a9903811SScott Wood 3752bf11819SPaul Mackerras if [ -n "$cacheit" ]; then 376f1e510bbSOliver O'Halloran mv -f "$vmz.$$$compression" "$vmz$compression" 3772bf11819SPaul Mackerras else 3782bf11819SPaul Mackerras vmz="$vmz.$$" 3792bf11819SPaul Mackerras fi 380c55aef0eSSuzuki Pouloseelse 381c55aef0eSSuzuki Poulose rm -f $vmz.$$ 382c55aef0eSSuzuki Poulosefi 383c55aef0eSSuzuki Poulose 384f1e510bbSOliver O'Halloranvmz="$vmz$compression" 385f1e510bbSOliver O'Halloran 386dfbc2d75SStephen Rothwellif [ "$make_space" = "y" ]; then 387c55aef0eSSuzuki Poulose # Round the size to next higher MB limit 388c55aef0eSSuzuki Poulose round_size=$(((strip_size + 0xfffff) & 0xfff00000)) 389c55aef0eSSuzuki Poulose 390c55aef0eSSuzuki Poulose round_size=0x$(printf "%x" $round_size) 391c55aef0eSSuzuki Poulose link_addr=$(printf "%d" $link_address) 392c55aef0eSSuzuki Poulose 393c55aef0eSSuzuki Poulose if [ $link_addr -lt $strip_size ]; then 394eba3d97dSSuzuki Poulose echo "INFO: Uncompressed kernel (size 0x$(printf "%x\n" $strip_size))" \ 395c55aef0eSSuzuki Poulose "overlaps the address of the wrapper($link_address)" 396eba3d97dSSuzuki Poulose echo "INFO: Fixing the link_address of wrapper to ($round_size)" 397c55aef0eSSuzuki Poulose link_address=$round_size 3982bf11819SPaul Mackerras fi 399dfbc2d75SStephen Rothwellfi 4002bf11819SPaul Mackerras 401a6afacb6SDavid Gibson# Extract kernel version information, some platforms want to include 402a6afacb6SDavid Gibson# it in the image header 4032bf11819SPaul Mackerrasversion=`${CROSS}strings "$kernel" | grep '^Linux version [-0-9.]' | \ 4042bf11819SPaul Mackerras cut -d' ' -f3` 4052bf11819SPaul Mackerrasif [ -n "$version" ]; then 406a6afacb6SDavid Gibson uboot_version="-n Linux-$version" 4072bf11819SPaul Mackerrasfi 4080fdd717eSScott Wood 409b18796d3SKumar Gala# physical offset of kernel image 410b18796d3SKumar Galamembase=`${CROSS}objdump -p "$kernel" | grep -m 1 LOAD | awk '{print $7}'` 411b18796d3SKumar Gala 4120fdd717eSScott Woodcase "$platform" in 4130fdd717eSScott Wooduboot) 4140fdd717eSScott Wood rm -f "$ofile" 4153f884bf5SPeter Tyser ${MKIMAGE} -A ppc -O linux -T kernel -C gzip -a $membase -e $membase \ 416a6afacb6SDavid Gibson $uboot_version -d "$vmz" "$ofile" 4172bf11819SPaul Mackerras if [ -z "$cacheit" ]; then 418a9903811SScott Wood rm -f "$vmz" 4192bf11819SPaul Mackerras fi 4202bf11819SPaul Mackerras exit 0 4212bf11819SPaul Mackerras ;; 42211eab297SBenjamin Herrenschmidtuboot-obs600) 42311eab297SBenjamin Herrenschmidt rm -f "$ofile" 42411eab297SBenjamin Herrenschmidt # obs600 wants a multi image with an initrd, so we need to put a fake 42511eab297SBenjamin Herrenschmidt # one in even when building a "normal" image. 42611eab297SBenjamin Herrenschmidt if [ -n "$initrd" ]; then 42711eab297SBenjamin Herrenschmidt real_rd="$initrd" 42811eab297SBenjamin Herrenschmidt else 42911eab297SBenjamin Herrenschmidt real_rd=`mktemp` 43011eab297SBenjamin Herrenschmidt echo "\0" >>"$real_rd" 43111eab297SBenjamin Herrenschmidt fi 43211eab297SBenjamin Herrenschmidt ${MKIMAGE} -A ppc -O linux -T multi -C gzip -a $membase -e $membase \ 43311eab297SBenjamin Herrenschmidt $uboot_version -d "$vmz":"$real_rd":"$dtb" "$ofile" 43411eab297SBenjamin Herrenschmidt if [ -z "$initrd" ]; then 43511eab297SBenjamin Herrenschmidt rm -f "$real_rd" 43611eab297SBenjamin Herrenschmidt fi 43711eab297SBenjamin Herrenschmidt if [ -z "$cacheit" ]; then 43811eab297SBenjamin Herrenschmidt rm -f "$vmz" 43911eab297SBenjamin Herrenschmidt fi 44011eab297SBenjamin Herrenschmidt exit 0 44111eab297SBenjamin Herrenschmidt ;; 4422bf11819SPaul Mackerrasesac 4432bf11819SPaul Mackerras 4442bf11819SPaul Mackerrasaddsec() { 4452bf11819SPaul Mackerras ${CROSS}objcopy $4 $1 \ 4462bf11819SPaul Mackerras --add-section=$3="$2" \ 4472bf11819SPaul Mackerras --set-section-flags=$3=contents,alloc,load,readonly,data 4482bf11819SPaul Mackerras} 4492bf11819SPaul Mackerras 450a9903811SScott Woodaddsec $tmp "$vmz" $ksection $object/empty.o 4512bf11819SPaul Mackerrasif [ -z "$cacheit" ]; then 452a9903811SScott Wood rm -f "$vmz" 4532bf11819SPaul Mackerrasfi 4542bf11819SPaul Mackerras 4552bf11819SPaul Mackerrasif [ -n "$initrd" ]; then 456c888554bSMark A. Greer addsec $tmp "$initrd" $isection 4572bf11819SPaul Mackerrasfi 4582bf11819SPaul Mackerras 4592bf11819SPaul Mackerrasif [ -n "$dtb" ]; then 460c888554bSMark A. Greer addsec $tmp "$dtb" .kernel:dtb 461e9c4b4bdSMark A. Greer if [ -n "$dts" ]; then 462e9c4b4bdSMark A. Greer rm $dtb 463e9c4b4bdSMark A. Greer fi 4642bf11819SPaul Mackerrasfi 4652bf11819SPaul Mackerras 4662bf11819SPaul Mackerrasif [ "$platform" != "miboot" ]; then 4679b09c6d9STony Breeds if [ -n "$link_address" ] ; then 4686975a783SMichael Ellerman text_start="-Ttext $link_address" 4699b09c6d9STony Breeds fi 470f1e510bbSOliver O'Halloran#link everything 471*ff45000fSNicholas Piggin ${CROSS}ld -m $format -T $lds $text_start $pie $nodl -o "$ofile" \ 472cd197ffcSDavid Gibson $platformo $tmp $object/wrapper.a 4732bf11819SPaul Mackerras rm $tmp 4742bf11819SPaul Mackerrasfi 4752bf11819SPaul Mackerras 476a6afacb6SDavid Gibson# Some platforms need the zImage's entry point and base address 477a6afacb6SDavid Gibsonbase=0x`${CROSS}nm "$ofile" | grep ' _start$' | cut -d' ' -f1` 478a6afacb6SDavid Gibsonentry=`${CROSS}objdump -f "$ofile" | grep '^start address ' | cut -d' ' -f3` 479a6afacb6SDavid Gibson 48011c146ccSScott Woodif [ -n "$binary" ]; then 48111c146ccSScott Wood mv "$ofile" "$ofile".elf 482aeb4552fSScott Wood ${CROSS}objcopy -O binary "$ofile".elf "$ofile" 48311c146ccSScott Woodfi 48411c146ccSScott Wood 4852bf11819SPaul Mackerras# post-processing needed for some platforms 4862bf11819SPaul Mackerrascase "$platform" in 48758706ef9SCorey Minyardpseries|chrp|maple) 4885663a123SPaul Mackerras $objbin/addnote "$ofile" 4890dcd4401SPaul Mackerras ;; 490627aa944SMilton Millercoff) 491cd197ffcSDavid Gibson ${CROSS}objcopy -O aixcoff-rs6000 --set-start "$entry" "$ofile" 4925c539ee3SDavid Woodhouse $objbin/hack-coff "$ofile" 4932bf11819SPaul Mackerras ;; 4940fdd717eSScott Woodcuboot*) 495c4f56af0SMichal Marek gzip -n -f -9 "$ofile" 4963f884bf5SPeter Tyser ${MKIMAGE} -A ppc -O linux -T kernel -C gzip -a "$base" -e "$entry" \ 497aeb4552fSScott Wood $uboot_version -d "$ofile".gz "$ofile" 4980fdd717eSScott Wood ;; 499f6dfc805SDavid Gibsontreeboot*) 500f6dfc805SDavid Gibson mv "$ofile" "$ofile.elf" 5015c539ee3SDavid Woodhouse $objbin/mktree "$ofile.elf" "$ofile" "$base" "$entry" 502f6dfc805SDavid Gibson if [ -z "$cacheit" ]; then 503f6dfc805SDavid Gibson rm -f "$ofile.elf" 504f6dfc805SDavid Gibson fi 505f6dfc805SDavid Gibson exit 0 506f6dfc805SDavid Gibson ;; 507bafdb645SGeoff Levandps3) 5085761eaa3SGeoff Levand # The ps3's loader supports loading a gzipped binary image from flash 5095761eaa3SGeoff Levand # rom to ram addr zero. The loader then enters the system reset 5105761eaa3SGeoff Levand # vector at addr 0x100. A bootwrapper overlay is used to arrange for 5115761eaa3SGeoff Levand # a binary image of the kernel to be at addr zero, and yet have a 5125761eaa3SGeoff Levand # suitable bootwrapper entry at 0x100. To construct the final rom 5135761eaa3SGeoff Levand # image 512 bytes from offset 0x100 is copied to the bootwrapper 5145761eaa3SGeoff Levand # place holder at symbol __system_reset_kernel. The 512 bytes of the 5155761eaa3SGeoff Levand # bootwrapper entry code at symbol __system_reset_overlay is then 5165761eaa3SGeoff Levand # copied to offset 0x100. At runtime the bootwrapper program copies 5175761eaa3SGeoff Levand # the data at __system_reset_kernel back to addr 0x100. 518bafdb645SGeoff Levand 519aeb4552fSScott Wood system_reset_overlay=0x`${CROSS}nm "$ofile" \ 520bafdb645SGeoff Levand | grep ' __system_reset_overlay$' \ 521bafdb645SGeoff Levand | cut -d' ' -f1` 522bafdb645SGeoff Levand system_reset_overlay=`printf "%d" $system_reset_overlay` 523aeb4552fSScott Wood system_reset_kernel=0x`${CROSS}nm "$ofile" \ 524bafdb645SGeoff Levand | grep ' __system_reset_kernel$' \ 525bafdb645SGeoff Levand | cut -d' ' -f1` 526bafdb645SGeoff Levand system_reset_kernel=`printf "%d" $system_reset_kernel` 527bafdb645SGeoff Levand overlay_dest="256" 5285761eaa3SGeoff Levand overlay_size="512" 529bafdb645SGeoff Levand 530aeb4552fSScott Wood ${CROSS}objcopy -O binary "$ofile" "$ofile.bin" 531aeb4552fSScott Wood 532879c26d4SGeoff Levand run_cmd dd if="$ofile.bin" of="$ofile.bin" conv=notrunc \ 533bafdb645SGeoff Levand skip=$overlay_dest seek=$system_reset_kernel \ 534d4740373SGrant Likely count=$overlay_size bs=1 535bafdb645SGeoff Levand 536879c26d4SGeoff Levand run_cmd dd if="$ofile.bin" of="$ofile.bin" conv=notrunc \ 537bafdb645SGeoff Levand skip=$system_reset_overlay seek=$overlay_dest \ 538d4740373SGrant Likely count=$overlay_size bs=1 539bafdb645SGeoff Levand 540928b9695SDavid Woodhouse odir="$(dirname "$ofile.bin")" 541928b9695SDavid Woodhouse rm -f "$odir/otheros.bld" 542c4f56af0SMichal Marek gzip -n --force -9 --stdout "$ofile.bin" > "$odir/otheros.bld" 543bafdb645SGeoff Levand ;; 5442bf11819SPaul Mackerrasesac 545