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 .)
34 # cross-compilation prefix
37 # directory for object and other files used by this script
38 object=arch/powerpc/boot
40 # directory for working files
44 echo 'Usage: wrapper [-o output] [-p platform] [-i initrd]' >&2
45 echo ' [-d devtree] [-s tree.dts] [-c] [-C cross-prefix]' >&2
46 echo ' [-D datadir] [-W workingdir] [--no-gzip] [vmlinux]' >&2
50 while [ "$#" -gt 0 ]; do
54 [ "$#" -gt 0 ] || usage
59 [ "$#" -gt 0 ] || usage
64 [ "$#" -gt 0 ] || usage
69 [ "$#" -gt 0 ] || usage
74 [ "$#" -gt 0 ] || usage
82 [ "$#" -gt 0 ] || usage
87 [ "$#" -gt 0 ] || usage
92 [ "$#" -gt 0 ] || usage
102 [ -z "$kernel" ] || usage
109 if [ -n "$dts" ]; then
110 if [ -z "$dtb" ]; then
113 dtc -O dtb -o "$dtb" -b 0 -V 16 "$dts" || exit 1
116 if [ -z "$kernel" ]; then
120 platformo=$object/"$platform".o
121 lds=$object/zImage.lds
124 tmp=$tmpdir/zImage.$$.o
125 ksection=.kernel:vmlinux.strip
126 isection=.kernel:initrd
130 platformo=$object/of.o
133 platformo=$object/of.o
134 lds=$object/zImage.coff.lds
137 # miboot and U-boot want just the bare bits, not an ELF binary
149 vmz="$tmpdir/`basename \"$kernel\"`.$ext"
150 if [ -z "$cacheit" -o ! -f "$vmz$gzip" -o "$vmz$gzip" -ot "$kernel" ]; then
151 ${CROSS}objcopy $objflags "$kernel" "$vmz.$$"
153 if [ -n "$gzip" ]; then
157 if [ -n "$cacheit" ]; then
158 mv -f "$vmz.$$$gzip" "$vmz$gzip"
168 version=`${CROSS}strings "$kernel" | grep '^Linux version [-0-9.]' | \
170 if [ -n "$version" ]; then
171 version="-n Linux-$version"
178 mkimage -A ppc -O linux -T kernel -C gzip -a 00000000 -e 00000000 \
179 $version -d "$vmz" "$ofile"
180 if [ -z "$cacheit" ]; then
188 ${CROSS}objcopy $4 $1 \
189 --add-section=$3="$2" \
190 --set-section-flags=$3=contents,alloc,load,readonly,data
193 addsec $tmp "$vmz" $ksection $object/empty.o
194 if [ -z "$cacheit" ]; then
198 if [ -n "$initrd" ]; then
199 addsec $tmp "$initrd" $isection
202 if [ -n "$dtb" ]; then
203 addsec $tmp "$dtb" .kernel:dtb
204 if [ -n "$dts" ]; then
209 if [ "$platform" != "miboot" ]; then
210 ${CROSS}ld -m elf32ppc -T $lds -o "$ofile" \
211 $platformo $tmp $object/wrapper.a
215 # post-processing needed for some platforms
218 $object/addnote "$ofile"
221 entry=`objdump -f "$ofile" | grep '^start address ' | \
223 ${CROSS}objcopy -O aixcoff-rs6000 --set-start "$entry" "$ofile"
224 $object/hack-coff "$ofile"
227 base=`${CROSS}nm "$ofile" | grep ' _start$' | cut -d' ' -f1`
228 entry=`${CROSS}objdump -f "$ofile" | grep '^start address ' | \
230 mv "$ofile" "$ofile".elf
231 ${CROSS}objcopy -O binary "$ofile".elf "$ofile".bin
232 gzip -f -9 "$ofile".bin
233 mkimage -A ppc -O linux -T kernel -C gzip -a "$base" -e "$entry" \
234 $version -d "$ofile".bin.gz "$ofile"