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
148 platformo="$object/ps3-head.o $object/ps3-hvcall.o $object/ps3.o"
149 lds=$object/zImage.ps3.lds
152 objflags="-O binary --set-section-flags=.bss=contents,alloc,load,data"
153 ksection=.kernel:vmlinux.bin
154 isection=.kernel:initrd
158 vmz="$tmpdir/`basename \"$kernel\"`.$ext"
159 if [ -z "$cacheit" -o ! -f "$vmz$gzip" -o "$vmz$gzip" -ot "$kernel" ]; then
160 ${CROSS}objcopy $objflags "$kernel" "$vmz.$$"
162 if [ -n "$gzip" ]; then
166 if [ -n "$cacheit" ]; then
167 mv -f "$vmz.$$$gzip" "$vmz$gzip"
175 # Extract kernel version information, some platforms want to include
176 # it in the image header
177 version=`${CROSS}strings "$kernel" | grep '^Linux version [-0-9.]' | \
179 if [ -n "$version" ]; then
180 uboot_version="-n Linux-$version"
186 mkimage -A ppc -O linux -T kernel -C gzip -a 00000000 -e 00000000 \
187 $uboot_version -d "$vmz" "$ofile"
188 if [ -z "$cacheit" ]; then
196 ${CROSS}objcopy $4 $1 \
197 --add-section=$3="$2" \
198 --set-section-flags=$3=contents,alloc,load,readonly,data
201 addsec $tmp "$vmz" $ksection $object/empty.o
202 if [ -z "$cacheit" ]; then
206 if [ -n "$initrd" ]; then
207 addsec $tmp "$initrd" $isection
210 if [ -n "$dtb" ]; then
211 addsec $tmp "$dtb" .kernel:dtb
212 if [ -n "$dts" ]; then
217 if [ "$platform" != "miboot" ]; then
218 ${CROSS}ld -m elf32ppc -T $lds -o "$ofile" \
219 $platformo $tmp $object/wrapper.a
223 # Some platforms need the zImage's entry point and base address
224 base=0x`${CROSS}nm "$ofile" | grep ' _start$' | cut -d' ' -f1`
225 entry=`${CROSS}objdump -f "$ofile" | grep '^start address ' | cut -d' ' -f3`
227 # post-processing needed for some platforms
230 $object/addnote "$ofile"
233 ${CROSS}objcopy -O aixcoff-rs6000 --set-start "$entry" "$ofile"
234 $object/hack-coff "$ofile"
237 mv "$ofile" "$ofile".elf
238 ${CROSS}objcopy -O binary "$ofile".elf "$ofile".bin
239 gzip -f -9 "$ofile".bin
240 mkimage -A ppc -O linux -T kernel -C gzip -a "$base" -e "$entry" \
241 $uboot_version -d "$ofile".bin.gz "$ofile"
244 mv "$ofile" "$ofile.elf"
245 $object/mktree "$ofile.elf" "$ofile" "$base" "$entry"
246 if [ -z "$cacheit" ]; then
252 # The ps3's loader supports loading gzipped binary images from flash
253 # rom to addr zero. The loader enters the image at addr 0x100. A
254 # bootwrapper overlay is use to arrange for the kernel to be loaded
255 # to addr zero and to have a suitable bootwrapper entry at 0x100.
256 # To construct the rom image, 0x100 bytes from offset 0x100 in the
257 # kernel is copied to the bootwrapper symbol __system_reset_kernel.
258 # The 0x100 bytes at the bootwrapper symbol __system_reset_overlay is
259 # then copied to offset 0x100. At runtime the bootwrapper program
260 # copies the 0x100 bytes at __system_reset_kernel to addr 0x100.
262 system_reset_overlay=0x`${CROSS}nm "$ofile" \
263 | grep ' __system_reset_overlay$' \
265 system_reset_overlay=`printf "%d" $system_reset_overlay`
266 system_reset_kernel=0x`${CROSS}nm "$ofile" \
267 | grep ' __system_reset_kernel$' \
269 system_reset_kernel=`printf "%d" $system_reset_kernel`
273 rm -f "$object/otheros.bld"
275 ${CROSS}objcopy -O binary "$ofile" "$ofile.bin"
277 msg=$(dd if="$ofile.bin" of="$ofile.bin" conv=notrunc \
278 skip=$overlay_dest seek=$system_reset_kernel \
279 count=$overlay_size bs=1 2>&1)
281 if [ $? -ne "0" ]; then
286 msg=$(dd if="$ofile.bin" of="$ofile.bin" conv=notrunc \
287 skip=$system_reset_overlay seek=$overlay_dest \
288 count=$overlay_size bs=1 2>&1)
290 if [ $? -ne "0" ]; then
295 gzip --force -9 --stdout "$ofile.bin" > "$object/otheros.bld"