3 # Copyright (C) 2006 Paul Mackerras, IBM Corporation <paulus@samba.org>
4 # This program may be used under the terms of version 2 of the GNU
5 # General Public License.
7 # This script takes a kernel binary and optionally an initrd image
8 # and/or a device-tree blob, and creates a bootable zImage for a
12 # -o zImage specify output file
13 # -p platform specify platform (links in $platform.o)
14 # -i initrd specify initrd file
15 # -d devtree specify device-tree blob
16 # -s tree.dts specify device-tree source file (needs dtc installed)
17 # -c cache $kernel.strip.gz (use if present & newer, else make)
18 # -C prefix specify command prefix for cross-building tools
19 # (strip, objcopy, ld)
20 # -D dir specify directory containing data files used by script
21 # (default ./arch/powerpc/boot)
22 # -W dir specify working directory for temporary files (default .)
33 # cross-compilation prefix
36 # directory for object and other files used by this script
37 object=arch/powerpc/boot
39 # directory for working files
43 echo 'Usage: wrapper [-o output] [-p platform] [-i initrd]' >&2
44 echo ' [-d devtree] [-s tree.dts] [-c] [-C cross-prefix]' >&2
45 echo ' [-D datadir] [-W workingdir] [vmlinux]' >&2
49 while [ "$#" -gt 0 ]; do
53 [ "$#" -gt 0 ] || usage
58 [ "$#" -gt 0 ] || usage
63 [ "$#" -gt 0 ] || usage
68 [ "$#" -gt 0 ] || usage
73 [ "$#" -gt 0 ] || usage
81 [ "$#" -gt 0 ] || usage
86 [ "$#" -gt 0 ] || usage
91 [ "$#" -gt 0 ] || usage
98 [ -z "$kernel" ] || usage
105 if [ -n "$dts" ]; then
106 if [ -z "$dtb" ]; then
109 dtc -O dtb -o "$dtb" -b 0 -V 16 "$dts" || exit 1
112 if [ -z "$kernel" ]; then
116 platformo=$object/"$platform".o
117 lds=$object/zImage.lds
120 tmp=$tmpdir/zImage.$$.o
121 ksection=.kernel:vmlinux.strip
122 isection=.kernel:initrd
126 platformo=$object/of.o
129 platformo=$object/of.o
130 lds=$object/zImage.coff.lds
133 # miboot and U-boot want just the bare bits, not an ELF binary
142 vmz="$tmpdir/`basename \"$kernel\"`.$ext"
143 if [ -z "$cacheit" -o ! -f "$vmz.gz" -o "$vmz.gz" -ot "$kernel" ]; then
144 ${CROSS}objcopy $objflags "$kernel" "$vmz.$$"
146 if [ -n "$cacheit" ]; then
147 mv -f "$vmz.$$.gz" "$vmz.gz"
156 version=`${CROSS}strings "$kernel" | grep '^Linux version [-0-9.]' | \
158 if [ -n "$version" ]; then
159 version="-n Linux-$version"
161 mkimage -A ppc -O linux -T kernel -C gzip -a 00000000 -e 00000000 \
162 $version -d "$vmz.gz" "$ofile"
163 if [ -z "$cacheit" ]; then
171 ${CROSS}objcopy $4 $1 \
172 --add-section=$3="$2" \
173 --set-section-flags=$3=contents,alloc,load,readonly,data
176 addsec $tmp "$vmz.gz" $ksection $object/empty.o
177 if [ -z "$cacheit" ]; then
181 if [ -n "$initrd" ]; then
182 addsec $tmp "$initrd" initrd
185 if [ -n "$dtb" ]; then
186 addsec $tmp "$dtb" dtb
189 if [ "$platform" != "miboot" ]; then
190 ${CROSS}ld -m elf32ppc -T $lds -o "$ofile" \
191 $object/crt0.o $platformo $tmp $object/wrapper.a
195 # post-processing needed for some platforms
198 $object/addnote "$ofile"
201 ${CROSS}objcopy -O aixcoff-rs6000 --set-start 0x500000 "$ofile"
202 $object/hack-coff "$ofile"