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 .) 23*f1e510bbSOliver O'Halloran# -z use gzip (legacy) 24*f1e510bbSOliver 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= 43*f1e510bbSOliver 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 64*f1e510bbSOliver O'Halloran echo ' [-D datadir] [-W workingdir] [-Z (gz|xz|none)]' >&2 65*f1e510bbSOliver 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 ;; 132*f1e510bbSOliver O'Halloran -z) 133*f1e510bbSOliver O'Halloran compression=.gz 134*f1e510bbSOliver O'Halloran ;; 135*f1e510bbSOliver O'Halloran -Z) 136*f1e510bbSOliver O'Halloran shift 137*f1e510bbSOliver O'Halloran [ "$#" -gt 0 ] || usage 138*f1e510bbSOliver O'Halloran [ "$1" != "gz" -o "$1" != "xz" -o "$1" != "none" ] || usage 139*f1e510bbSOliver O'Halloran 140*f1e510bbSOliver O'Halloran compression=".$1" 141*f1e510bbSOliver O'Halloran 142*f1e510bbSOliver O'Halloran if [ $compression = ".none" ]; then 143*f1e510bbSOliver O'Halloran compression= 144*f1e510bbSOliver O'Halloran fi 145*f1e510bbSOliver O'Halloran ;; 146a9903811SScott Wood --no-gzip) 147*f1e510bbSOliver O'Halloran # a "feature" of the the wrapper script is that it can be used outside 148*f1e510bbSOliver O'Halloran # the kernel tree. So keeping this around for backwards compatibility. 149*f1e510bbSOliver 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 162*f1e510bbSOliver 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 184147c0516SCédric Le Goater 1852bf11819SPaul Mackerrasplatformo=$object/"$platform".o 1862bf11819SPaul Mackerraslds=$object/zImage.lds 1872bf11819SPaul Mackerrasext=strip 1882bf11819SPaul Mackerrasobjflags=-S 1892bf11819SPaul Mackerrastmp=$tmpdir/zImage.$$.o 1902bf11819SPaul Mackerrasksection=.kernel:vmlinux.strip 1912bf11819SPaul Mackerrasisection=.kernel:initrd 1929b09c6d9STony Breedslink_address='0x400000' 193dfbc2d75SStephen Rothwellmake_space=y 1942bf11819SPaul Mackerras 1952bf11819SPaul Mackerrascase "$platform" in 19644790a0bSBenjamin Herrenschmidtof) 19744790a0bSBenjamin Herrenschmidt platformo="$object/of.o $object/epapr.o" 19844790a0bSBenjamin Herrenschmidt make_space=n 19944790a0bSBenjamin Herrenschmidt ;; 2009b09c6d9STony Breedspseries) 2012d9afb36SCédric Le Goater platformo="$object/pseries-head.o $object/of.o $object/epapr.o" 2029b09c6d9STony Breeds link_address='0x4000000' 203147c0516SCédric Le Goater if [ "$format" != "elf32ppc" ]; then 204147c0516SCédric Le Goater link_address= 205147c0516SCédric Le Goater pie=-pie 206147c0516SCédric Le Goater fi 207f5467e28SPaul Mackerras make_space=n 2089b09c6d9STony Breeds ;; 20958706ef9SCorey Minyardmaple) 2100c9fa291SBenjamin Herrenschmidt platformo="$object/of.o $object/epapr.o" 21158706ef9SCorey Minyard link_address='0x400000' 212f5467e28SPaul Mackerras make_space=n 21358706ef9SCorey Minyard ;; 2149b09c6d9STony Breedspmac|chrp) 2150c9fa291SBenjamin Herrenschmidt platformo="$object/of.o $object/epapr.o" 216f5467e28SPaul Mackerras make_space=n 2172bf11819SPaul Mackerras ;; 218627aa944SMilton Millercoff) 2190c9fa291SBenjamin Herrenschmidt platformo="$object/crt0.o $object/of.o $object/epapr.o" 2202bf11819SPaul Mackerras lds=$object/zImage.coff.lds 2219b09c6d9STony Breeds link_address='0x500000' 222f5467e28SPaul Mackerras make_space=n 2236975a783SMichael Ellerman pie= 2242bf11819SPaul Mackerras ;; 22511eab297SBenjamin Herrenschmidtmiboot|uboot*) 2262bf11819SPaul Mackerras # miboot and U-boot want just the bare bits, not an ELF binary 2272bf11819SPaul Mackerras ext=bin 2282bf11819SPaul Mackerras objflags="-O binary" 2292bf11819SPaul Mackerras tmp="$ofile" 2302bf11819SPaul Mackerras ksection=image 2312bf11819SPaul Mackerras isection=initrd 2322bf11819SPaul Mackerras ;; 2330fdd717eSScott Woodcuboot*) 23411c146ccSScott Wood binary=y 235*f1e510bbSOliver O'Halloran compression= 23625431333SGrant Likely case "$platform" in 2378dd217b2SScott Wood *-mpc866ads|*-mpc885ads|*-adder875*|*-ep88xc) 23825431333SGrant Likely platformo=$object/cuboot-8xx.o 23925431333SGrant Likely ;; 24025431333SGrant Likely *5200*|*-motionpro) 24125431333SGrant Likely platformo=$object/cuboot-52xx.o 24225431333SGrant Likely ;; 24325431333SGrant Likely *-pq2fads|*-ep8248e|*-mpc8272*|*-storcenter) 24425431333SGrant Likely platformo=$object/cuboot-pq2.o 24525431333SGrant Likely ;; 24625431333SGrant Likely *-mpc824*) 24725431333SGrant Likely platformo=$object/cuboot-824x.o 24825431333SGrant Likely ;; 24959d13f9dSBryan O'Donoghue *-mpc83*|*-asp834x*) 25025431333SGrant Likely platformo=$object/cuboot-83xx.o 25125431333SGrant Likely ;; 252ff880112SAlexandr Smirnov *-tqm8541|*-mpc8560*|*-tqm8560|*-tqm8555|*-ksi8560*) 25325431333SGrant Likely platformo=$object/cuboot-85xx-cpm2.o 25425431333SGrant Likely ;; 2556dd1b64aSWolfgang Grandegger *-mpc85*|*-tqm85*|*-sbc85*) 25625431333SGrant Likely platformo=$object/cuboot-85xx.o 25725431333SGrant Likely ;; 2588f23735dSGerhard Pircher *-amigaone) 2598f23735dSGerhard Pircher link_address='0x800000' 2608f23735dSGerhard Pircher ;; 26125431333SGrant Likely esac 2620fdd717eSScott Wood ;; 263bafdb645SGeoff Levandps3) 264bafdb645SGeoff Levand platformo="$object/ps3-head.o $object/ps3-hvcall.o $object/ps3.o" 265bafdb645SGeoff Levand lds=$object/zImage.ps3.lds 266*f1e510bbSOliver O'Halloran compression= 267bafdb645SGeoff Levand ext=bin 268bafdb645SGeoff Levand objflags="-O binary --set-section-flags=.bss=contents,alloc,load,data" 269bafdb645SGeoff Levand ksection=.kernel:vmlinux.bin 270bafdb645SGeoff Levand isection=.kernel:initrd 2719b09c6d9STony Breeds link_address='' 272dfbc2d75SStephen Rothwell make_space=n 2736975a783SMichael Ellerman pie= 274bafdb645SGeoff Levand ;; 275a55387e5SScott Woodep88xc|ep405|ep8248e) 27611c146ccSScott Wood platformo="$object/fixed-head.o $object/$platform.o" 27711c146ccSScott Wood binary=y 27811c146ccSScott Wood ;; 279a55387e5SScott Woodadder875-redboot) 280a55387e5SScott Wood platformo="$object/fixed-head.o $object/redboot-8xx.o" 281a55387e5SScott Wood binary=y 282a55387e5SScott Wood ;; 283d2477b5cSGrant Likelysimpleboot-virtex405-*) 284d58577d8SJohn Linn platformo="$object/virtex405-head.o $object/simpleboot.o $object/virtex.o" 285d58577d8SJohn Linn binary=y 286d58577d8SJohn Linn ;; 287d58577d8SJohn Linnsimpleboot-virtex440-*) 288a7e1cf0cSGrant Likely platformo="$object/fixed-head.o $object/simpleboot.o $object/virtex.o" 289d2477b5cSGrant Likely binary=y 290d2477b5cSGrant Likely ;; 2911d46e379SGrant Likelysimpleboot-*) 292a7e1cf0cSGrant Likely platformo="$object/fixed-head.o $object/simpleboot.o" 2931d46e379SGrant Likely binary=y 2941d46e379SGrant Likely ;; 29559d13f9dSBryan O'Donoghueasp834x-redboot) 29659d13f9dSBryan O'Donoghue platformo="$object/fixed-head.o $object/redboot-83xx.o" 29759d13f9dSBryan O'Donoghue binary=y 29859d13f9dSBryan O'Donoghue ;; 29924760823SNate Casexpedite52*) 30024760823SNate Case link_address='0x1400000' 30124760823SNate Case platformo=$object/cuboot-85xx.o 30224760823SNate Case ;; 3036cdd2417SAlbert Herranzgamecube|wii) 304b68a24bcSAlbert Herranz link_address='0x600000' 305b68a24bcSAlbert Herranz platformo="$object/$platform-head.o $object/$platform.o" 306b68a24bcSAlbert Herranz ;; 307228d5505STony Breedstreeboot-currituck) 308228d5505STony Breeds link_address='0x1000000' 309228d5505STony Breeds ;; 3102a2c74b2SAlistair Poppletreeboot-akebono) 3112a2c74b2SAlistair Popple link_address='0x1000000' 3122a2c74b2SAlistair Popple ;; 313b4e8c8ddSTorez Smithtreeboot-iss4xx-mpic) 314b4e8c8ddSTorez Smith platformo="$object/treeboot-iss4xx.o" 315b4e8c8ddSTorez Smith ;; 3166c5b59b9SDavid Gibsonepapr) 31790d1d44eSJeremy Kerr platformo="$object/pseries-head.o $object/epapr.o $object/epapr-wrapper.o" 3186c5b59b9SDavid Gibson link_address='0x20000000' 3196c5b59b9SDavid Gibson pie=-pie 3206c5b59b9SDavid Gibson ;; 321be201981SStephen Chiversmvme5100) 322be201981SStephen Chivers platformo="$object/fixed-head.o $object/mvme5100.o" 323be201981SStephen Chivers binary=y 324be201981SStephen Chivers ;; 32597493e2eSAlessio Igor Boganimvme7100) 32697493e2eSAlessio Igor Bogani platformo="$object/motload-head.o $object/mvme7100.o" 32797493e2eSAlessio Igor Bogani link_address='0x4000000' 32897493e2eSAlessio Igor Bogani binary=y 32997493e2eSAlessio Igor Bogani ;; 3302bf11819SPaul Mackerrasesac 3312bf11819SPaul Mackerras 3322bf11819SPaul Mackerrasvmz="$tmpdir/`basename \"$kernel\"`.$ext" 333a9903811SScott Wood 334*f1e510bbSOliver O'Halloran# Calculate the vmlinux.strip size 335*f1e510bbSOliver O'Halloran${CROSS}objcopy $objflags "$kernel" "$vmz.$$" 336c55aef0eSSuzuki Poulosestrip_size=$(stat -c %s $vmz.$$) 337c55aef0eSSuzuki Poulose 338*f1e510bbSOliver O'Halloranif [ -z "$cacheit" -o ! -f "$vmz$compression" -o "$vmz$compression" -ot "$kernel" ]; then 339*f1e510bbSOliver O'Halloran # recompress the image if we need to 340*f1e510bbSOliver O'Halloran case $compression in 341*f1e510bbSOliver O'Halloran .xz) 342*f1e510bbSOliver O'Halloran xz --check=crc32 -f -6 "$vmz.$$" 343*f1e510bbSOliver O'Halloran ;; 344*f1e510bbSOliver O'Halloran .gz) 345c4f56af0SMichal Marek gzip -n -f -9 "$vmz.$$" 346*f1e510bbSOliver O'Halloran ;; 347*f1e510bbSOliver O'Halloran *) 348*f1e510bbSOliver O'Halloran # drop the compression suffix so the stripped vmlinux is used 349*f1e510bbSOliver O'Halloran compression= 350*f1e510bbSOliver O'Halloran ;; 351*f1e510bbSOliver O'Halloran esac 352a9903811SScott Wood 3532bf11819SPaul Mackerras if [ -n "$cacheit" ]; then 354*f1e510bbSOliver O'Halloran mv -f "$vmz.$$$compression" "$vmz$compression" 3552bf11819SPaul Mackerras else 3562bf11819SPaul Mackerras vmz="$vmz.$$" 3572bf11819SPaul Mackerras fi 358c55aef0eSSuzuki Pouloseelse 359c55aef0eSSuzuki Poulose rm -f $vmz.$$ 360c55aef0eSSuzuki Poulosefi 361c55aef0eSSuzuki Poulose 362*f1e510bbSOliver O'Halloranvmz="$vmz$compression" 363*f1e510bbSOliver O'Halloran 364dfbc2d75SStephen Rothwellif [ "$make_space" = "y" ]; then 365c55aef0eSSuzuki Poulose # Round the size to next higher MB limit 366c55aef0eSSuzuki Poulose round_size=$(((strip_size + 0xfffff) & 0xfff00000)) 367c55aef0eSSuzuki Poulose 368c55aef0eSSuzuki Poulose round_size=0x$(printf "%x" $round_size) 369c55aef0eSSuzuki Poulose link_addr=$(printf "%d" $link_address) 370c55aef0eSSuzuki Poulose 371c55aef0eSSuzuki Poulose if [ $link_addr -lt $strip_size ]; then 372eba3d97dSSuzuki Poulose echo "INFO: Uncompressed kernel (size 0x$(printf "%x\n" $strip_size))" \ 373c55aef0eSSuzuki Poulose "overlaps the address of the wrapper($link_address)" 374eba3d97dSSuzuki Poulose echo "INFO: Fixing the link_address of wrapper to ($round_size)" 375c55aef0eSSuzuki Poulose link_address=$round_size 3762bf11819SPaul Mackerras fi 377dfbc2d75SStephen Rothwellfi 3782bf11819SPaul Mackerras 379a6afacb6SDavid Gibson# Extract kernel version information, some platforms want to include 380a6afacb6SDavid Gibson# it in the image header 3812bf11819SPaul Mackerrasversion=`${CROSS}strings "$kernel" | grep '^Linux version [-0-9.]' | \ 3822bf11819SPaul Mackerras cut -d' ' -f3` 3832bf11819SPaul Mackerrasif [ -n "$version" ]; then 384a6afacb6SDavid Gibson uboot_version="-n Linux-$version" 3852bf11819SPaul Mackerrasfi 3860fdd717eSScott Wood 387b18796d3SKumar Gala# physical offset of kernel image 388b18796d3SKumar Galamembase=`${CROSS}objdump -p "$kernel" | grep -m 1 LOAD | awk '{print $7}'` 389b18796d3SKumar Gala 3900fdd717eSScott Woodcase "$platform" in 3910fdd717eSScott Wooduboot) 3920fdd717eSScott Wood rm -f "$ofile" 3933f884bf5SPeter Tyser ${MKIMAGE} -A ppc -O linux -T kernel -C gzip -a $membase -e $membase \ 394a6afacb6SDavid Gibson $uboot_version -d "$vmz" "$ofile" 3952bf11819SPaul Mackerras if [ -z "$cacheit" ]; then 396a9903811SScott Wood rm -f "$vmz" 3972bf11819SPaul Mackerras fi 3982bf11819SPaul Mackerras exit 0 3992bf11819SPaul Mackerras ;; 40011eab297SBenjamin Herrenschmidtuboot-obs600) 40111eab297SBenjamin Herrenschmidt rm -f "$ofile" 40211eab297SBenjamin Herrenschmidt # obs600 wants a multi image with an initrd, so we need to put a fake 40311eab297SBenjamin Herrenschmidt # one in even when building a "normal" image. 40411eab297SBenjamin Herrenschmidt if [ -n "$initrd" ]; then 40511eab297SBenjamin Herrenschmidt real_rd="$initrd" 40611eab297SBenjamin Herrenschmidt else 40711eab297SBenjamin Herrenschmidt real_rd=`mktemp` 40811eab297SBenjamin Herrenschmidt echo "\0" >>"$real_rd" 40911eab297SBenjamin Herrenschmidt fi 41011eab297SBenjamin Herrenschmidt ${MKIMAGE} -A ppc -O linux -T multi -C gzip -a $membase -e $membase \ 41111eab297SBenjamin Herrenschmidt $uboot_version -d "$vmz":"$real_rd":"$dtb" "$ofile" 41211eab297SBenjamin Herrenschmidt if [ -z "$initrd" ]; then 41311eab297SBenjamin Herrenschmidt rm -f "$real_rd" 41411eab297SBenjamin Herrenschmidt fi 41511eab297SBenjamin Herrenschmidt if [ -z "$cacheit" ]; then 41611eab297SBenjamin Herrenschmidt rm -f "$vmz" 41711eab297SBenjamin Herrenschmidt fi 41811eab297SBenjamin Herrenschmidt exit 0 41911eab297SBenjamin Herrenschmidt ;; 4202bf11819SPaul Mackerrasesac 4212bf11819SPaul Mackerras 4222bf11819SPaul Mackerrasaddsec() { 4232bf11819SPaul Mackerras ${CROSS}objcopy $4 $1 \ 4242bf11819SPaul Mackerras --add-section=$3="$2" \ 4252bf11819SPaul Mackerras --set-section-flags=$3=contents,alloc,load,readonly,data 4262bf11819SPaul Mackerras} 4272bf11819SPaul Mackerras 428a9903811SScott Woodaddsec $tmp "$vmz" $ksection $object/empty.o 4292bf11819SPaul Mackerrasif [ -z "$cacheit" ]; then 430a9903811SScott Wood rm -f "$vmz" 4312bf11819SPaul Mackerrasfi 4322bf11819SPaul Mackerras 4332bf11819SPaul Mackerrasif [ -n "$initrd" ]; then 434c888554bSMark A. Greer addsec $tmp "$initrd" $isection 4352bf11819SPaul Mackerrasfi 4362bf11819SPaul Mackerras 4372bf11819SPaul Mackerrasif [ -n "$dtb" ]; then 438c888554bSMark A. Greer addsec $tmp "$dtb" .kernel:dtb 439e9c4b4bdSMark A. Greer if [ -n "$dts" ]; then 440e9c4b4bdSMark A. Greer rm $dtb 441e9c4b4bdSMark A. Greer fi 4422bf11819SPaul Mackerrasfi 4432bf11819SPaul Mackerras 4442bf11819SPaul Mackerrasif [ "$platform" != "miboot" ]; then 4459b09c6d9STony Breeds if [ -n "$link_address" ] ; then 4466975a783SMichael Ellerman text_start="-Ttext $link_address" 4479b09c6d9STony Breeds fi 448*f1e510bbSOliver O'Halloran#link everything 449147c0516SCédric Le Goater ${CROSS}ld -m $format -T $lds $text_start $pie -o "$ofile" \ 450cd197ffcSDavid Gibson $platformo $tmp $object/wrapper.a 4512bf11819SPaul Mackerras rm $tmp 4522bf11819SPaul Mackerrasfi 4532bf11819SPaul Mackerras 454a6afacb6SDavid Gibson# Some platforms need the zImage's entry point and base address 455a6afacb6SDavid Gibsonbase=0x`${CROSS}nm "$ofile" | grep ' _start$' | cut -d' ' -f1` 456a6afacb6SDavid Gibsonentry=`${CROSS}objdump -f "$ofile" | grep '^start address ' | cut -d' ' -f3` 457a6afacb6SDavid Gibson 45811c146ccSScott Woodif [ -n "$binary" ]; then 45911c146ccSScott Wood mv "$ofile" "$ofile".elf 460aeb4552fSScott Wood ${CROSS}objcopy -O binary "$ofile".elf "$ofile" 46111c146ccSScott Woodfi 46211c146ccSScott Wood 4632bf11819SPaul Mackerras# post-processing needed for some platforms 4642bf11819SPaul Mackerrascase "$platform" in 46558706ef9SCorey Minyardpseries|chrp|maple) 4665663a123SPaul Mackerras $objbin/addnote "$ofile" 4670dcd4401SPaul Mackerras ;; 468627aa944SMilton Millercoff) 469cd197ffcSDavid Gibson ${CROSS}objcopy -O aixcoff-rs6000 --set-start "$entry" "$ofile" 4705c539ee3SDavid Woodhouse $objbin/hack-coff "$ofile" 4712bf11819SPaul Mackerras ;; 4720fdd717eSScott Woodcuboot*) 473c4f56af0SMichal Marek gzip -n -f -9 "$ofile" 4743f884bf5SPeter Tyser ${MKIMAGE} -A ppc -O linux -T kernel -C gzip -a "$base" -e "$entry" \ 475aeb4552fSScott Wood $uboot_version -d "$ofile".gz "$ofile" 4760fdd717eSScott Wood ;; 477f6dfc805SDavid Gibsontreeboot*) 478f6dfc805SDavid Gibson mv "$ofile" "$ofile.elf" 4795c539ee3SDavid Woodhouse $objbin/mktree "$ofile.elf" "$ofile" "$base" "$entry" 480f6dfc805SDavid Gibson if [ -z "$cacheit" ]; then 481f6dfc805SDavid Gibson rm -f "$ofile.elf" 482f6dfc805SDavid Gibson fi 483f6dfc805SDavid Gibson exit 0 484f6dfc805SDavid Gibson ;; 485bafdb645SGeoff Levandps3) 4865761eaa3SGeoff Levand # The ps3's loader supports loading a gzipped binary image from flash 4875761eaa3SGeoff Levand # rom to ram addr zero. The loader then enters the system reset 4885761eaa3SGeoff Levand # vector at addr 0x100. A bootwrapper overlay is used to arrange for 4895761eaa3SGeoff Levand # a binary image of the kernel to be at addr zero, and yet have a 4905761eaa3SGeoff Levand # suitable bootwrapper entry at 0x100. To construct the final rom 4915761eaa3SGeoff Levand # image 512 bytes from offset 0x100 is copied to the bootwrapper 4925761eaa3SGeoff Levand # place holder at symbol __system_reset_kernel. The 512 bytes of the 4935761eaa3SGeoff Levand # bootwrapper entry code at symbol __system_reset_overlay is then 4945761eaa3SGeoff Levand # copied to offset 0x100. At runtime the bootwrapper program copies 4955761eaa3SGeoff Levand # the data at __system_reset_kernel back to addr 0x100. 496bafdb645SGeoff Levand 497aeb4552fSScott Wood system_reset_overlay=0x`${CROSS}nm "$ofile" \ 498bafdb645SGeoff Levand | grep ' __system_reset_overlay$' \ 499bafdb645SGeoff Levand | cut -d' ' -f1` 500bafdb645SGeoff Levand system_reset_overlay=`printf "%d" $system_reset_overlay` 501aeb4552fSScott Wood system_reset_kernel=0x`${CROSS}nm "$ofile" \ 502bafdb645SGeoff Levand | grep ' __system_reset_kernel$' \ 503bafdb645SGeoff Levand | cut -d' ' -f1` 504bafdb645SGeoff Levand system_reset_kernel=`printf "%d" $system_reset_kernel` 505bafdb645SGeoff Levand overlay_dest="256" 5065761eaa3SGeoff Levand overlay_size="512" 507bafdb645SGeoff Levand 508aeb4552fSScott Wood ${CROSS}objcopy -O binary "$ofile" "$ofile.bin" 509aeb4552fSScott Wood 510879c26d4SGeoff Levand run_cmd dd if="$ofile.bin" of="$ofile.bin" conv=notrunc \ 511bafdb645SGeoff Levand skip=$overlay_dest seek=$system_reset_kernel \ 512d4740373SGrant Likely count=$overlay_size bs=1 513bafdb645SGeoff Levand 514879c26d4SGeoff Levand run_cmd dd if="$ofile.bin" of="$ofile.bin" conv=notrunc \ 515bafdb645SGeoff Levand skip=$system_reset_overlay seek=$overlay_dest \ 516d4740373SGrant Likely count=$overlay_size bs=1 517bafdb645SGeoff Levand 518928b9695SDavid Woodhouse odir="$(dirname "$ofile.bin")" 519928b9695SDavid Woodhouse rm -f "$odir/otheros.bld" 520c4f56af0SMichal Marek gzip -n --force -9 --stdout "$ofile.bin" > "$odir/otheros.bld" 521bafdb645SGeoff Levand ;; 5222bf11819SPaul Mackerrasesac 523