18c2ecf20Sopenharmony_ci#!/bin/sh 28c2ecf20Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0-only 38c2ecf20Sopenharmony_ci 48c2ecf20Sopenharmony_ci# Copyright (C) 2006 Paul Mackerras, IBM Corporation <paulus@samba.org> 58c2ecf20Sopenharmony_ci 68c2ecf20Sopenharmony_ci# This script takes a kernel binary and optionally an initrd image 78c2ecf20Sopenharmony_ci# and/or a device-tree blob, and creates a bootable zImage for a 88c2ecf20Sopenharmony_ci# given platform. 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci# Options: 118c2ecf20Sopenharmony_ci# -o zImage specify output file 128c2ecf20Sopenharmony_ci# -p platform specify platform (links in $platform.o) 138c2ecf20Sopenharmony_ci# -i initrd specify initrd file 148c2ecf20Sopenharmony_ci# -d devtree specify device-tree blob 158c2ecf20Sopenharmony_ci# -s tree.dts specify device-tree source file (needs dtc installed) 168c2ecf20Sopenharmony_ci# -e esm_blob specify ESM blob for secure images 178c2ecf20Sopenharmony_ci# -c cache $kernel.strip.gz (use if present & newer, else make) 188c2ecf20Sopenharmony_ci# -C prefix specify command prefix for cross-building tools 198c2ecf20Sopenharmony_ci# (strip, objcopy, ld) 208c2ecf20Sopenharmony_ci# -D dir specify directory containing data files used by script 218c2ecf20Sopenharmony_ci# (default ./arch/powerpc/boot) 228c2ecf20Sopenharmony_ci# -W dir specify working directory for temporary files (default .) 238c2ecf20Sopenharmony_ci# -z use gzip (legacy) 248c2ecf20Sopenharmony_ci# -Z zsuffix compression to use (gz, xz or none) 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_ci# Stop execution if any command fails 278c2ecf20Sopenharmony_ciset -e 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_ci# Allow for verbose output 308c2ecf20Sopenharmony_ciif [ "$V" = 1 ]; then 318c2ecf20Sopenharmony_ci set -x 328c2ecf20Sopenharmony_ci map="-Map wrapper.map" 338c2ecf20Sopenharmony_cifi 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci# defaults 368c2ecf20Sopenharmony_cikernel= 378c2ecf20Sopenharmony_ciofile=zImage 388c2ecf20Sopenharmony_ciplatform=of 398c2ecf20Sopenharmony_ciinitrd= 408c2ecf20Sopenharmony_cidtb= 418c2ecf20Sopenharmony_cidts= 428c2ecf20Sopenharmony_ciesm_blob= 438c2ecf20Sopenharmony_cicacheit= 448c2ecf20Sopenharmony_cibinary= 458c2ecf20Sopenharmony_cicompression=.gz 468c2ecf20Sopenharmony_ciuboot_comp=gzip 478c2ecf20Sopenharmony_cipie= 488c2ecf20Sopenharmony_ciformat= 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_ci# cross-compilation prefix 518c2ecf20Sopenharmony_ciCROSS= 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_ci# mkimage wrapper script 548c2ecf20Sopenharmony_ciMKIMAGE=$srctree/scripts/mkuboot.sh 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_ci# directory for object and other files used by this script 578c2ecf20Sopenharmony_ciobject=arch/powerpc/boot 588c2ecf20Sopenharmony_ciobjbin=$object 598c2ecf20Sopenharmony_cidtc=scripts/dtc/dtc 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_ci# directory for working files 628c2ecf20Sopenharmony_citmpdir=. 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_ciusage() { 658c2ecf20Sopenharmony_ci echo 'Usage: wrapper [-o output] [-p platform] [-i initrd]' >&2 668c2ecf20Sopenharmony_ci echo ' [-d devtree] [-s tree.dts] [-e esm_blob]' >&2 678c2ecf20Sopenharmony_ci echo ' [-c] [-C cross-prefix] [-D datadir] [-W workingdir]' >&2 688c2ecf20Sopenharmony_ci echo ' [-Z (gz|xz|none)] [--no-compression] [vmlinux]' >&2 698c2ecf20Sopenharmony_ci exit 1 708c2ecf20Sopenharmony_ci} 718c2ecf20Sopenharmony_ci 728c2ecf20Sopenharmony_cirun_cmd() { 738c2ecf20Sopenharmony_ci if [ "$V" = 1 ]; then 748c2ecf20Sopenharmony_ci $* 2>&1 758c2ecf20Sopenharmony_ci else 768c2ecf20Sopenharmony_ci local msg 778c2ecf20Sopenharmony_ci 788c2ecf20Sopenharmony_ci set +e 798c2ecf20Sopenharmony_ci msg=$($* 2>&1) 808c2ecf20Sopenharmony_ci 818c2ecf20Sopenharmony_ci if [ $? -ne "0" ]; then 828c2ecf20Sopenharmony_ci echo $msg 838c2ecf20Sopenharmony_ci exit 1 848c2ecf20Sopenharmony_ci fi 858c2ecf20Sopenharmony_ci set -e 868c2ecf20Sopenharmony_ci fi 878c2ecf20Sopenharmony_ci} 888c2ecf20Sopenharmony_ci 898c2ecf20Sopenharmony_ciwhile [ "$#" -gt 0 ]; do 908c2ecf20Sopenharmony_ci case "$1" in 918c2ecf20Sopenharmony_ci -o) 928c2ecf20Sopenharmony_ci shift 938c2ecf20Sopenharmony_ci [ "$#" -gt 0 ] || usage 948c2ecf20Sopenharmony_ci ofile="$1" 958c2ecf20Sopenharmony_ci ;; 968c2ecf20Sopenharmony_ci -p) 978c2ecf20Sopenharmony_ci shift 988c2ecf20Sopenharmony_ci [ "$#" -gt 0 ] || usage 998c2ecf20Sopenharmony_ci platform="$1" 1008c2ecf20Sopenharmony_ci ;; 1018c2ecf20Sopenharmony_ci -i) 1028c2ecf20Sopenharmony_ci shift 1038c2ecf20Sopenharmony_ci [ "$#" -gt 0 ] || usage 1048c2ecf20Sopenharmony_ci initrd="$1" 1058c2ecf20Sopenharmony_ci ;; 1068c2ecf20Sopenharmony_ci -d) 1078c2ecf20Sopenharmony_ci shift 1088c2ecf20Sopenharmony_ci [ "$#" -gt 0 ] || usage 1098c2ecf20Sopenharmony_ci dtb="$1" 1108c2ecf20Sopenharmony_ci ;; 1118c2ecf20Sopenharmony_ci -e) 1128c2ecf20Sopenharmony_ci shift 1138c2ecf20Sopenharmony_ci [ "$#" -gt 0 ] || usage 1148c2ecf20Sopenharmony_ci esm_blob="$1" 1158c2ecf20Sopenharmony_ci ;; 1168c2ecf20Sopenharmony_ci -s) 1178c2ecf20Sopenharmony_ci shift 1188c2ecf20Sopenharmony_ci [ "$#" -gt 0 ] || usage 1198c2ecf20Sopenharmony_ci dts="$1" 1208c2ecf20Sopenharmony_ci ;; 1218c2ecf20Sopenharmony_ci -c) 1228c2ecf20Sopenharmony_ci cacheit=y 1238c2ecf20Sopenharmony_ci ;; 1248c2ecf20Sopenharmony_ci -C) 1258c2ecf20Sopenharmony_ci shift 1268c2ecf20Sopenharmony_ci [ "$#" -gt 0 ] || usage 1278c2ecf20Sopenharmony_ci CROSS="$1" 1288c2ecf20Sopenharmony_ci ;; 1298c2ecf20Sopenharmony_ci -D) 1308c2ecf20Sopenharmony_ci shift 1318c2ecf20Sopenharmony_ci [ "$#" -gt 0 ] || usage 1328c2ecf20Sopenharmony_ci object="$1" 1338c2ecf20Sopenharmony_ci objbin="$1" 1348c2ecf20Sopenharmony_ci ;; 1358c2ecf20Sopenharmony_ci -W) 1368c2ecf20Sopenharmony_ci shift 1378c2ecf20Sopenharmony_ci [ "$#" -gt 0 ] || usage 1388c2ecf20Sopenharmony_ci tmpdir="$1" 1398c2ecf20Sopenharmony_ci ;; 1408c2ecf20Sopenharmony_ci -z) 1418c2ecf20Sopenharmony_ci compression=.gz 1428c2ecf20Sopenharmony_ci uboot_comp=gzip 1438c2ecf20Sopenharmony_ci ;; 1448c2ecf20Sopenharmony_ci -Z) 1458c2ecf20Sopenharmony_ci shift 1468c2ecf20Sopenharmony_ci [ "$#" -gt 0 ] || usage 1478c2ecf20Sopenharmony_ci [ "$1" != "gz" -o "$1" != "xz" -o "$1" != "lzma" -o "$1" != "lzo" -o "$1" != "none" ] || usage 1488c2ecf20Sopenharmony_ci 1498c2ecf20Sopenharmony_ci compression=".$1" 1508c2ecf20Sopenharmony_ci uboot_comp=$1 1518c2ecf20Sopenharmony_ci 1528c2ecf20Sopenharmony_ci if [ $compression = ".none" ]; then 1538c2ecf20Sopenharmony_ci compression= 1548c2ecf20Sopenharmony_ci uboot_comp=none 1558c2ecf20Sopenharmony_ci fi 1568c2ecf20Sopenharmony_ci if [ $uboot_comp = "gz" ]; then 1578c2ecf20Sopenharmony_ci uboot_comp=gzip 1588c2ecf20Sopenharmony_ci fi 1598c2ecf20Sopenharmony_ci ;; 1608c2ecf20Sopenharmony_ci --no-gzip) 1618c2ecf20Sopenharmony_ci # a "feature" of the the wrapper script is that it can be used outside 1628c2ecf20Sopenharmony_ci # the kernel tree. So keeping this around for backwards compatibility. 1638c2ecf20Sopenharmony_ci compression= 1648c2ecf20Sopenharmony_ci uboot_comp=none 1658c2ecf20Sopenharmony_ci ;; 1668c2ecf20Sopenharmony_ci -?) 1678c2ecf20Sopenharmony_ci usage 1688c2ecf20Sopenharmony_ci ;; 1698c2ecf20Sopenharmony_ci *) 1708c2ecf20Sopenharmony_ci [ -z "$kernel" ] || usage 1718c2ecf20Sopenharmony_ci kernel="$1" 1728c2ecf20Sopenharmony_ci ;; 1738c2ecf20Sopenharmony_ci esac 1748c2ecf20Sopenharmony_ci shift 1758c2ecf20Sopenharmony_cidone 1768c2ecf20Sopenharmony_ci 1778c2ecf20Sopenharmony_ci 1788c2ecf20Sopenharmony_ciif [ -n "$dts" ]; then 1798c2ecf20Sopenharmony_ci if [ ! -r "$dts" -a -r "$object/dts/$dts" ]; then 1808c2ecf20Sopenharmony_ci dts="$object/dts/$dts" 1818c2ecf20Sopenharmony_ci fi 1828c2ecf20Sopenharmony_ci if [ -z "$dtb" ]; then 1838c2ecf20Sopenharmony_ci dtb="$platform.dtb" 1848c2ecf20Sopenharmony_ci fi 1858c2ecf20Sopenharmony_ci $dtc -O dtb -o "$dtb" -b 0 "$dts" 1868c2ecf20Sopenharmony_cifi 1878c2ecf20Sopenharmony_ci 1888c2ecf20Sopenharmony_ciif [ -z "$kernel" ]; then 1898c2ecf20Sopenharmony_ci kernel=vmlinux 1908c2ecf20Sopenharmony_cifi 1918c2ecf20Sopenharmony_ci 1928c2ecf20Sopenharmony_ciLANG=C elfformat="`${CROSS}objdump -p "$kernel" | grep 'file format' | awk '{print $4}'`" 1938c2ecf20Sopenharmony_cicase "$elfformat" in 1948c2ecf20Sopenharmony_ci elf64-powerpcle) format=elf64lppc ;; 1958c2ecf20Sopenharmony_ci elf64-powerpc) format=elf32ppc ;; 1968c2ecf20Sopenharmony_ci elf32-powerpc) format=elf32ppc ;; 1978c2ecf20Sopenharmony_ciesac 1988c2ecf20Sopenharmony_ci 1998c2ecf20Sopenharmony_cild_version() 2008c2ecf20Sopenharmony_ci{ 2018c2ecf20Sopenharmony_ci # Poached from scripts/ld-version.sh, but we don't want to call that because 2028c2ecf20Sopenharmony_ci # this script (wrapper) is distributed separately from the kernel source. 2038c2ecf20Sopenharmony_ci # Extract linker version number from stdin and turn into single number. 2048c2ecf20Sopenharmony_ci awk '{ 2058c2ecf20Sopenharmony_ci gsub(".*\\)", ""); 2068c2ecf20Sopenharmony_ci gsub(".*version ", ""); 2078c2ecf20Sopenharmony_ci gsub("-.*", ""); 2088c2ecf20Sopenharmony_ci split($1,a, "."); 2098c2ecf20Sopenharmony_ci print a[1]*100000000 + a[2]*1000000 + a[3]*10000; 2108c2ecf20Sopenharmony_ci exit 2118c2ecf20Sopenharmony_ci }' 2128c2ecf20Sopenharmony_ci} 2138c2ecf20Sopenharmony_ci 2148c2ecf20Sopenharmony_ci# Do not include PT_INTERP segment when linking pie. Non-pie linking 2158c2ecf20Sopenharmony_ci# just ignores this option. 2168c2ecf20Sopenharmony_ciLD_VERSION=$(${CROSS}ld --version | ld_version) 2178c2ecf20Sopenharmony_ciLD_NO_DL_MIN_VERSION=$(echo 2.26 | ld_version) 2188c2ecf20Sopenharmony_ciif [ "$LD_VERSION" -ge "$LD_NO_DL_MIN_VERSION" ] ; then 2198c2ecf20Sopenharmony_ci nodl="--no-dynamic-linker" 2208c2ecf20Sopenharmony_cifi 2218c2ecf20Sopenharmony_ci 2228c2ecf20Sopenharmony_ciplatformo=$object/"$platform".o 2238c2ecf20Sopenharmony_cilds=$object/zImage.lds 2248c2ecf20Sopenharmony_ciext=strip 2258c2ecf20Sopenharmony_ciobjflags=-S 2268c2ecf20Sopenharmony_citmp=$tmpdir/zImage.$$.o 2278c2ecf20Sopenharmony_ciksection=.kernel:vmlinux.strip 2288c2ecf20Sopenharmony_ciisection=.kernel:initrd 2298c2ecf20Sopenharmony_ciesection=.kernel:esm_blob 2308c2ecf20Sopenharmony_cilink_address='0x400000' 2318c2ecf20Sopenharmony_cimake_space=y 2328c2ecf20Sopenharmony_ci 2338c2ecf20Sopenharmony_ci 2348c2ecf20Sopenharmony_ciif [ -n "$esm_blob" -a "$platform" != "pseries" ]; then 2358c2ecf20Sopenharmony_ci echo "ESM blob not support on non-pseries platforms" >&2 2368c2ecf20Sopenharmony_ci exit 1 2378c2ecf20Sopenharmony_cifi 2388c2ecf20Sopenharmony_ci 2398c2ecf20Sopenharmony_cicase "$platform" in 2408c2ecf20Sopenharmony_ciof) 2418c2ecf20Sopenharmony_ci platformo="$object/of.o $object/epapr.o" 2428c2ecf20Sopenharmony_ci make_space=n 2438c2ecf20Sopenharmony_ci ;; 2448c2ecf20Sopenharmony_cipseries) 2458c2ecf20Sopenharmony_ci platformo="$object/pseries-head.o $object/of.o $object/epapr.o" 2468c2ecf20Sopenharmony_ci link_address='0x4000000' 2478c2ecf20Sopenharmony_ci if [ "$format" != "elf32ppc" ]; then 2488c2ecf20Sopenharmony_ci link_address= 2498c2ecf20Sopenharmony_ci pie=-pie 2508c2ecf20Sopenharmony_ci fi 2518c2ecf20Sopenharmony_ci make_space=n 2528c2ecf20Sopenharmony_ci ;; 2538c2ecf20Sopenharmony_cimaple) 2548c2ecf20Sopenharmony_ci platformo="$object/of.o $object/epapr.o" 2558c2ecf20Sopenharmony_ci link_address='0x400000' 2568c2ecf20Sopenharmony_ci make_space=n 2578c2ecf20Sopenharmony_ci ;; 2588c2ecf20Sopenharmony_cipmac|chrp) 2598c2ecf20Sopenharmony_ci platformo="$object/of.o $object/epapr.o" 2608c2ecf20Sopenharmony_ci make_space=n 2618c2ecf20Sopenharmony_ci ;; 2628c2ecf20Sopenharmony_cicoff) 2638c2ecf20Sopenharmony_ci platformo="$object/crt0.o $object/of.o $object/epapr.o" 2648c2ecf20Sopenharmony_ci lds=$object/zImage.coff.lds 2658c2ecf20Sopenharmony_ci link_address='0x500000' 2668c2ecf20Sopenharmony_ci make_space=n 2678c2ecf20Sopenharmony_ci pie= 2688c2ecf20Sopenharmony_ci ;; 2698c2ecf20Sopenharmony_cimiboot|uboot*) 2708c2ecf20Sopenharmony_ci # miboot and U-boot want just the bare bits, not an ELF binary 2718c2ecf20Sopenharmony_ci ext=bin 2728c2ecf20Sopenharmony_ci objflags="-O binary" 2738c2ecf20Sopenharmony_ci tmp="$ofile" 2748c2ecf20Sopenharmony_ci ksection=image 2758c2ecf20Sopenharmony_ci isection=initrd 2768c2ecf20Sopenharmony_ci ;; 2778c2ecf20Sopenharmony_cicuboot*) 2788c2ecf20Sopenharmony_ci binary=y 2798c2ecf20Sopenharmony_ci compression= 2808c2ecf20Sopenharmony_ci case "$platform" in 2818c2ecf20Sopenharmony_ci *-mpc866ads|*-mpc885ads|*-adder875*|*-ep88xc) 2828c2ecf20Sopenharmony_ci platformo=$object/cuboot-8xx.o 2838c2ecf20Sopenharmony_ci ;; 2848c2ecf20Sopenharmony_ci *5200*|*-motionpro) 2858c2ecf20Sopenharmony_ci platformo=$object/cuboot-52xx.o 2868c2ecf20Sopenharmony_ci ;; 2878c2ecf20Sopenharmony_ci *-pq2fads|*-ep8248e|*-mpc8272*|*-storcenter) 2888c2ecf20Sopenharmony_ci platformo=$object/cuboot-pq2.o 2898c2ecf20Sopenharmony_ci ;; 2908c2ecf20Sopenharmony_ci *-mpc824*) 2918c2ecf20Sopenharmony_ci platformo=$object/cuboot-824x.o 2928c2ecf20Sopenharmony_ci ;; 2938c2ecf20Sopenharmony_ci *-mpc83*|*-asp834x*) 2948c2ecf20Sopenharmony_ci platformo=$object/cuboot-83xx.o 2958c2ecf20Sopenharmony_ci ;; 2968c2ecf20Sopenharmony_ci *-tqm8541|*-mpc8560*|*-tqm8560|*-tqm8555|*-ksi8560*) 2978c2ecf20Sopenharmony_ci platformo=$object/cuboot-85xx-cpm2.o 2988c2ecf20Sopenharmony_ci ;; 2998c2ecf20Sopenharmony_ci *-mpc85*|*-tqm85*|*-sbc85*) 3008c2ecf20Sopenharmony_ci platformo=$object/cuboot-85xx.o 3018c2ecf20Sopenharmony_ci ;; 3028c2ecf20Sopenharmony_ci *-amigaone) 3038c2ecf20Sopenharmony_ci link_address='0x800000' 3048c2ecf20Sopenharmony_ci ;; 3058c2ecf20Sopenharmony_ci esac 3068c2ecf20Sopenharmony_ci ;; 3078c2ecf20Sopenharmony_cips3) 3088c2ecf20Sopenharmony_ci platformo="$object/ps3-head.o $object/ps3-hvcall.o $object/ps3.o" 3098c2ecf20Sopenharmony_ci lds=$object/zImage.ps3.lds 3108c2ecf20Sopenharmony_ci compression= 3118c2ecf20Sopenharmony_ci ext=bin 3128c2ecf20Sopenharmony_ci objflags="-O binary --set-section-flags=.bss=contents,alloc,load,data" 3138c2ecf20Sopenharmony_ci ksection=.kernel:vmlinux.bin 3148c2ecf20Sopenharmony_ci isection=.kernel:initrd 3158c2ecf20Sopenharmony_ci link_address='' 3168c2ecf20Sopenharmony_ci make_space=n 3178c2ecf20Sopenharmony_ci pie= 3188c2ecf20Sopenharmony_ci ;; 3198c2ecf20Sopenharmony_ciep88xc|ep405|ep8248e) 3208c2ecf20Sopenharmony_ci platformo="$object/fixed-head.o $object/$platform.o" 3218c2ecf20Sopenharmony_ci binary=y 3228c2ecf20Sopenharmony_ci ;; 3238c2ecf20Sopenharmony_ciadder875-redboot) 3248c2ecf20Sopenharmony_ci platformo="$object/fixed-head.o $object/redboot-8xx.o" 3258c2ecf20Sopenharmony_ci binary=y 3268c2ecf20Sopenharmony_ci ;; 3278c2ecf20Sopenharmony_cisimpleboot-*) 3288c2ecf20Sopenharmony_ci platformo="$object/fixed-head.o $object/simpleboot.o" 3298c2ecf20Sopenharmony_ci binary=y 3308c2ecf20Sopenharmony_ci ;; 3318c2ecf20Sopenharmony_ciasp834x-redboot) 3328c2ecf20Sopenharmony_ci platformo="$object/fixed-head.o $object/redboot-83xx.o" 3338c2ecf20Sopenharmony_ci binary=y 3348c2ecf20Sopenharmony_ci ;; 3358c2ecf20Sopenharmony_cixpedite52*) 3368c2ecf20Sopenharmony_ci link_address='0x1400000' 3378c2ecf20Sopenharmony_ci platformo=$object/cuboot-85xx.o 3388c2ecf20Sopenharmony_ci ;; 3398c2ecf20Sopenharmony_cigamecube|wii) 3408c2ecf20Sopenharmony_ci link_address='0x600000' 3418c2ecf20Sopenharmony_ci platformo="$object/$platform-head.o $object/$platform.o" 3428c2ecf20Sopenharmony_ci ;; 3438c2ecf20Sopenharmony_citreeboot-currituck) 3448c2ecf20Sopenharmony_ci link_address='0x1000000' 3458c2ecf20Sopenharmony_ci ;; 3468c2ecf20Sopenharmony_citreeboot-akebono) 3478c2ecf20Sopenharmony_ci link_address='0x1000000' 3488c2ecf20Sopenharmony_ci ;; 3498c2ecf20Sopenharmony_citreeboot-iss4xx-mpic) 3508c2ecf20Sopenharmony_ci platformo="$object/treeboot-iss4xx.o" 3518c2ecf20Sopenharmony_ci ;; 3528c2ecf20Sopenharmony_ciepapr) 3538c2ecf20Sopenharmony_ci platformo="$object/pseries-head.o $object/epapr.o $object/epapr-wrapper.o" 3548c2ecf20Sopenharmony_ci link_address='0x20000000' 3558c2ecf20Sopenharmony_ci pie=-pie 3568c2ecf20Sopenharmony_ci ;; 3578c2ecf20Sopenharmony_cimvme5100) 3588c2ecf20Sopenharmony_ci platformo="$object/fixed-head.o $object/mvme5100.o" 3598c2ecf20Sopenharmony_ci binary=y 3608c2ecf20Sopenharmony_ci ;; 3618c2ecf20Sopenharmony_cimvme7100) 3628c2ecf20Sopenharmony_ci platformo="$object/motload-head.o $object/mvme7100.o" 3638c2ecf20Sopenharmony_ci link_address='0x4000000' 3648c2ecf20Sopenharmony_ci binary=y 3658c2ecf20Sopenharmony_ci ;; 3668c2ecf20Sopenharmony_ciesac 3678c2ecf20Sopenharmony_ci 3688c2ecf20Sopenharmony_civmz="$tmpdir/`basename \"$kernel\"`.$ext" 3698c2ecf20Sopenharmony_ci 3708c2ecf20Sopenharmony_ci# Calculate the vmlinux.strip size 3718c2ecf20Sopenharmony_ci${CROSS}objcopy $objflags "$kernel" "$vmz.$$" 3728c2ecf20Sopenharmony_cistrip_size=$(${CONFIG_SHELL} "${srctree}/scripts/file-size.sh" "$vmz.$$") 3738c2ecf20Sopenharmony_ci 3748c2ecf20Sopenharmony_ciif [ -z "$cacheit" -o ! -f "$vmz$compression" -o "$vmz$compression" -ot "$kernel" ]; then 3758c2ecf20Sopenharmony_ci # recompress the image if we need to 3768c2ecf20Sopenharmony_ci case $compression in 3778c2ecf20Sopenharmony_ci .xz) 3788c2ecf20Sopenharmony_ci xz --check=crc32 -f -6 "$vmz.$$" 3798c2ecf20Sopenharmony_ci ;; 3808c2ecf20Sopenharmony_ci .gz) 3818c2ecf20Sopenharmony_ci gzip -n -f -9 "$vmz.$$" 3828c2ecf20Sopenharmony_ci ;; 3838c2ecf20Sopenharmony_ci .lzma) 3848c2ecf20Sopenharmony_ci xz --format=lzma -f -6 "$vmz.$$" 3858c2ecf20Sopenharmony_ci ;; 3868c2ecf20Sopenharmony_ci .lzo) 3878c2ecf20Sopenharmony_ci lzop -f -9 "$vmz.$$" 3888c2ecf20Sopenharmony_ci ;; 3898c2ecf20Sopenharmony_ci *) 3908c2ecf20Sopenharmony_ci # drop the compression suffix so the stripped vmlinux is used 3918c2ecf20Sopenharmony_ci compression= 3928c2ecf20Sopenharmony_ci uboot_comp=none 3938c2ecf20Sopenharmony_ci ;; 3948c2ecf20Sopenharmony_ci esac 3958c2ecf20Sopenharmony_ci 3968c2ecf20Sopenharmony_ci if [ -n "$cacheit" ]; then 3978c2ecf20Sopenharmony_ci mv -f "$vmz.$$$compression" "$vmz$compression" 3988c2ecf20Sopenharmony_ci else 3998c2ecf20Sopenharmony_ci vmz="$vmz.$$" 4008c2ecf20Sopenharmony_ci fi 4018c2ecf20Sopenharmony_cielse 4028c2ecf20Sopenharmony_ci rm -f $vmz.$$ 4038c2ecf20Sopenharmony_cifi 4048c2ecf20Sopenharmony_ci 4058c2ecf20Sopenharmony_civmz="$vmz$compression" 4068c2ecf20Sopenharmony_ci 4078c2ecf20Sopenharmony_ciif [ "$make_space" = "y" ]; then 4088c2ecf20Sopenharmony_ci # Round the size to next higher MB limit 4098c2ecf20Sopenharmony_ci round_size=$(((strip_size + 0xfffff) & 0xfff00000)) 4108c2ecf20Sopenharmony_ci 4118c2ecf20Sopenharmony_ci round_size=0x$(printf "%x" $round_size) 4128c2ecf20Sopenharmony_ci link_addr=$(printf "%d" $link_address) 4138c2ecf20Sopenharmony_ci 4148c2ecf20Sopenharmony_ci if [ $link_addr -lt $strip_size ]; then 4158c2ecf20Sopenharmony_ci echo "INFO: Uncompressed kernel (size 0x$(printf "%x\n" $strip_size))" \ 4168c2ecf20Sopenharmony_ci "overlaps the address of the wrapper($link_address)" 4178c2ecf20Sopenharmony_ci echo "INFO: Fixing the link_address of wrapper to ($round_size)" 4188c2ecf20Sopenharmony_ci link_address=$round_size 4198c2ecf20Sopenharmony_ci fi 4208c2ecf20Sopenharmony_cifi 4218c2ecf20Sopenharmony_ci 4228c2ecf20Sopenharmony_ci# Extract kernel version information, some platforms want to include 4238c2ecf20Sopenharmony_ci# it in the image header 4248c2ecf20Sopenharmony_civersion=`${CROSS}strings "$kernel" | grep '^Linux version [-0-9.]' | \ 4258c2ecf20Sopenharmony_ci cut -d' ' -f3` 4268c2ecf20Sopenharmony_ciif [ -n "$version" ]; then 4278c2ecf20Sopenharmony_ci uboot_version="-n Linux-$version" 4288c2ecf20Sopenharmony_cifi 4298c2ecf20Sopenharmony_ci 4308c2ecf20Sopenharmony_ci# physical offset of kernel image 4318c2ecf20Sopenharmony_cimembase=`${CROSS}objdump -p "$kernel" | grep -m 1 LOAD | awk '{print $7}'` 4328c2ecf20Sopenharmony_ci 4338c2ecf20Sopenharmony_cicase "$platform" in 4348c2ecf20Sopenharmony_ciuboot) 4358c2ecf20Sopenharmony_ci rm -f "$ofile" 4368c2ecf20Sopenharmony_ci ${MKIMAGE} -A ppc -O linux -T kernel -C $uboot_comp -a $membase -e $membase \ 4378c2ecf20Sopenharmony_ci $uboot_version -d "$vmz" "$ofile" 4388c2ecf20Sopenharmony_ci if [ -z "$cacheit" ]; then 4398c2ecf20Sopenharmony_ci rm -f "$vmz" 4408c2ecf20Sopenharmony_ci fi 4418c2ecf20Sopenharmony_ci exit 0 4428c2ecf20Sopenharmony_ci ;; 4438c2ecf20Sopenharmony_ciuboot-obs600) 4448c2ecf20Sopenharmony_ci rm -f "$ofile" 4458c2ecf20Sopenharmony_ci # obs600 wants a multi image with an initrd, so we need to put a fake 4468c2ecf20Sopenharmony_ci # one in even when building a "normal" image. 4478c2ecf20Sopenharmony_ci if [ -n "$initrd" ]; then 4488c2ecf20Sopenharmony_ci real_rd="$initrd" 4498c2ecf20Sopenharmony_ci else 4508c2ecf20Sopenharmony_ci real_rd=`mktemp` 4518c2ecf20Sopenharmony_ci echo "\0" >>"$real_rd" 4528c2ecf20Sopenharmony_ci fi 4538c2ecf20Sopenharmony_ci ${MKIMAGE} -A ppc -O linux -T multi -C gzip -a $membase -e $membase \ 4548c2ecf20Sopenharmony_ci $uboot_version -d "$vmz":"$real_rd":"$dtb" "$ofile" 4558c2ecf20Sopenharmony_ci if [ -z "$initrd" ]; then 4568c2ecf20Sopenharmony_ci rm -f "$real_rd" 4578c2ecf20Sopenharmony_ci fi 4588c2ecf20Sopenharmony_ci if [ -z "$cacheit" ]; then 4598c2ecf20Sopenharmony_ci rm -f "$vmz" 4608c2ecf20Sopenharmony_ci fi 4618c2ecf20Sopenharmony_ci exit 0 4628c2ecf20Sopenharmony_ci ;; 4638c2ecf20Sopenharmony_ciesac 4648c2ecf20Sopenharmony_ci 4658c2ecf20Sopenharmony_ciaddsec() { 4668c2ecf20Sopenharmony_ci ${CROSS}objcopy $4 $1 \ 4678c2ecf20Sopenharmony_ci --add-section=$3="$2" \ 4688c2ecf20Sopenharmony_ci --set-section-flags=$3=contents,alloc,load,readonly,data 4698c2ecf20Sopenharmony_ci} 4708c2ecf20Sopenharmony_ci 4718c2ecf20Sopenharmony_ciaddsec $tmp "$vmz" $ksection $object/empty.o 4728c2ecf20Sopenharmony_ciif [ -z "$cacheit" ]; then 4738c2ecf20Sopenharmony_ci rm -f "$vmz" 4748c2ecf20Sopenharmony_cifi 4758c2ecf20Sopenharmony_ci 4768c2ecf20Sopenharmony_ciif [ -n "$initrd" ]; then 4778c2ecf20Sopenharmony_ci addsec $tmp "$initrd" $isection 4788c2ecf20Sopenharmony_cifi 4798c2ecf20Sopenharmony_ci 4808c2ecf20Sopenharmony_ciif [ -n "$dtb" ]; then 4818c2ecf20Sopenharmony_ci addsec $tmp "$dtb" .kernel:dtb 4828c2ecf20Sopenharmony_ci if [ -n "$dts" ]; then 4838c2ecf20Sopenharmony_ci rm $dtb 4848c2ecf20Sopenharmony_ci fi 4858c2ecf20Sopenharmony_cifi 4868c2ecf20Sopenharmony_ci 4878c2ecf20Sopenharmony_ciif [ -n "$esm_blob" ]; then 4888c2ecf20Sopenharmony_ci addsec $tmp "$esm_blob" $esection 4898c2ecf20Sopenharmony_cifi 4908c2ecf20Sopenharmony_ci 4918c2ecf20Sopenharmony_ciif [ "$platform" != "miboot" ]; then 4928c2ecf20Sopenharmony_ci if [ -n "$link_address" ] ; then 4938c2ecf20Sopenharmony_ci text_start="-Ttext $link_address" 4948c2ecf20Sopenharmony_ci fi 4958c2ecf20Sopenharmony_ci#link everything 4968c2ecf20Sopenharmony_ci ${CROSS}ld -m $format -T $lds $text_start $pie $nodl -o "$ofile" $map \ 4978c2ecf20Sopenharmony_ci $platformo $tmp $object/wrapper.a 4988c2ecf20Sopenharmony_ci rm $tmp 4998c2ecf20Sopenharmony_cifi 5008c2ecf20Sopenharmony_ci 5018c2ecf20Sopenharmony_ci# Some platforms need the zImage's entry point and base address 5028c2ecf20Sopenharmony_cibase=0x`${CROSS}nm "$ofile" | grep ' _start$' | cut -d' ' -f1` 5038c2ecf20Sopenharmony_cientry=`${CROSS}objdump -f "$ofile" | grep '^start address ' | cut -d' ' -f3` 5048c2ecf20Sopenharmony_ci 5058c2ecf20Sopenharmony_ciif [ -n "$binary" ]; then 5068c2ecf20Sopenharmony_ci mv "$ofile" "$ofile".elf 5078c2ecf20Sopenharmony_ci ${CROSS}objcopy -O binary "$ofile".elf "$ofile" 5088c2ecf20Sopenharmony_cifi 5098c2ecf20Sopenharmony_ci 5108c2ecf20Sopenharmony_ci# post-processing needed for some platforms 5118c2ecf20Sopenharmony_cicase "$platform" in 5128c2ecf20Sopenharmony_cipseries|chrp|maple) 5138c2ecf20Sopenharmony_ci $objbin/addnote "$ofile" 5148c2ecf20Sopenharmony_ci ;; 5158c2ecf20Sopenharmony_cicoff) 5168c2ecf20Sopenharmony_ci ${CROSS}objcopy -O aixcoff-rs6000 --set-start "$entry" "$ofile" 5178c2ecf20Sopenharmony_ci $objbin/hack-coff "$ofile" 5188c2ecf20Sopenharmony_ci ;; 5198c2ecf20Sopenharmony_cicuboot*) 5208c2ecf20Sopenharmony_ci gzip -n -f -9 "$ofile" 5218c2ecf20Sopenharmony_ci ${MKIMAGE} -A ppc -O linux -T kernel -C gzip -a "$base" -e "$entry" \ 5228c2ecf20Sopenharmony_ci $uboot_version -d "$ofile".gz "$ofile" 5238c2ecf20Sopenharmony_ci ;; 5248c2ecf20Sopenharmony_citreeboot*) 5258c2ecf20Sopenharmony_ci mv "$ofile" "$ofile.elf" 5268c2ecf20Sopenharmony_ci $objbin/mktree "$ofile.elf" "$ofile" "$base" "$entry" 5278c2ecf20Sopenharmony_ci if [ -z "$cacheit" ]; then 5288c2ecf20Sopenharmony_ci rm -f "$ofile.elf" 5298c2ecf20Sopenharmony_ci fi 5308c2ecf20Sopenharmony_ci exit 0 5318c2ecf20Sopenharmony_ci ;; 5328c2ecf20Sopenharmony_cips3) 5338c2ecf20Sopenharmony_ci # The ps3's loader supports loading a gzipped binary image from flash 5348c2ecf20Sopenharmony_ci # rom to ram addr zero. The loader then enters the system reset 5358c2ecf20Sopenharmony_ci # vector at addr 0x100. A bootwrapper overlay is used to arrange for 5368c2ecf20Sopenharmony_ci # a binary image of the kernel to be at addr zero, and yet have a 5378c2ecf20Sopenharmony_ci # suitable bootwrapper entry at 0x100. To construct the final rom 5388c2ecf20Sopenharmony_ci # image 512 bytes from offset 0x100 is copied to the bootwrapper 5398c2ecf20Sopenharmony_ci # place holder at symbol __system_reset_kernel. The 512 bytes of the 5408c2ecf20Sopenharmony_ci # bootwrapper entry code at symbol __system_reset_overlay is then 5418c2ecf20Sopenharmony_ci # copied to offset 0x100. At runtime the bootwrapper program copies 5428c2ecf20Sopenharmony_ci # the data at __system_reset_kernel back to addr 0x100. 5438c2ecf20Sopenharmony_ci 5448c2ecf20Sopenharmony_ci system_reset_overlay=0x`${CROSS}nm "$ofile" \ 5458c2ecf20Sopenharmony_ci | grep ' __system_reset_overlay$' \ 5468c2ecf20Sopenharmony_ci | cut -d' ' -f1` 5478c2ecf20Sopenharmony_ci system_reset_overlay=`printf "%d" $system_reset_overlay` 5488c2ecf20Sopenharmony_ci system_reset_kernel=0x`${CROSS}nm "$ofile" \ 5498c2ecf20Sopenharmony_ci | grep ' __system_reset_kernel$' \ 5508c2ecf20Sopenharmony_ci | cut -d' ' -f1` 5518c2ecf20Sopenharmony_ci system_reset_kernel=`printf "%d" $system_reset_kernel` 5528c2ecf20Sopenharmony_ci overlay_dest="256" 5538c2ecf20Sopenharmony_ci overlay_size="512" 5548c2ecf20Sopenharmony_ci 5558c2ecf20Sopenharmony_ci ${CROSS}objcopy -O binary "$ofile" "$ofile.bin" 5568c2ecf20Sopenharmony_ci 5578c2ecf20Sopenharmony_ci run_cmd dd if="$ofile.bin" of="$ofile.bin" conv=notrunc \ 5588c2ecf20Sopenharmony_ci skip=$overlay_dest seek=$system_reset_kernel \ 5598c2ecf20Sopenharmony_ci count=$overlay_size bs=1 5608c2ecf20Sopenharmony_ci 5618c2ecf20Sopenharmony_ci run_cmd dd if="$ofile.bin" of="$ofile.bin" conv=notrunc \ 5628c2ecf20Sopenharmony_ci skip=$system_reset_overlay seek=$overlay_dest \ 5638c2ecf20Sopenharmony_ci count=$overlay_size bs=1 5648c2ecf20Sopenharmony_ci 5658c2ecf20Sopenharmony_ci odir="$(dirname "$ofile.bin")" 5668c2ecf20Sopenharmony_ci 5678c2ecf20Sopenharmony_ci # The ps3's flash loader has a size limit of 16 MiB for the uncompressed 5688c2ecf20Sopenharmony_ci # image. If a compressed image that exceeded this limit is written to 5698c2ecf20Sopenharmony_ci # flash the loader will decompress that image until the 16 MiB limit is 5708c2ecf20Sopenharmony_ci # reached, then enter the system reset vector of the partially decompressed 5718c2ecf20Sopenharmony_ci # image. No warning is issued. 5728c2ecf20Sopenharmony_ci rm -f "$odir"/{otheros,otheros-too-big}.bld 5738c2ecf20Sopenharmony_ci size=$(${CROSS}nm --no-sort --radix=d "$ofile" | egrep ' _end$' | cut -d' ' -f1) 5748c2ecf20Sopenharmony_ci bld="otheros.bld" 5758c2ecf20Sopenharmony_ci if [ $size -gt $((0x1000000)) ]; then 5768c2ecf20Sopenharmony_ci bld="otheros-too-big.bld" 5778c2ecf20Sopenharmony_ci fi 5788c2ecf20Sopenharmony_ci gzip -n --force -9 --stdout "$ofile.bin" > "$odir/$bld" 5798c2ecf20Sopenharmony_ci ;; 5808c2ecf20Sopenharmony_ciesac 581