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 .)
35 # cross-compilation prefix
38 # directory for object and other files used by this script
39 object
=arch
/powerpc
/boot
41 # directory for working files
45 echo 'Usage: wrapper [-o output] [-p platform] [-i initrd]' >&2
46 echo ' [-d devtree] [-s tree.dts] [-c] [-C cross-prefix]' >&2
47 echo ' [-D datadir] [-W workingdir] [--no-gzip] [vmlinux]' >&2
51 while [ "$#" -gt 0 ]; do
55 [ "$#" -gt 0 ] || usage
60 [ "$#" -gt 0 ] || usage
65 [ "$#" -gt 0 ] || usage
70 [ "$#" -gt 0 ] || usage
75 [ "$#" -gt 0 ] || usage
83 [ "$#" -gt 0 ] || usage
88 [ "$#" -gt 0 ] || usage
93 [ "$#" -gt 0 ] || usage
103 [ -z "$kernel" ] || usage
110 if [ -n "$dts" ]; then
111 if [ -z "$dtb" ]; then
114 dtc
-O dtb
-o "$dtb" -b 0 -V 16 "$dts" ||
exit 1
117 if [ -z "$kernel" ]; then
121 platformo
=$object/"$platform".o
122 lds
=$object/zImage.lds
125 tmp
=$tmpdir/zImage.$$.o
126 ksection
=.kernel
:vmlinux.strip
127 isection
=.kernel
:initrd
131 platformo
=$object/of.o
134 platformo
=$object/of.o
135 lds
=$object/zImage.coff.lds
138 # miboot and U-boot want just the bare bits, not an ELF binary
150 platformo
="$object/ps3-head.o $object/ps3-hvcall.o $object/ps3.o"
151 lds
=$object/zImage.ps3.lds
155 objflags
="-O binary --set-section-flags=.bss=contents,alloc,load,data"
156 ksection
=.kernel
:vmlinux.bin
157 isection
=.kernel
:initrd
160 platformo
="$object/fixed-head.o $object/$platform.o"
165 vmz
="$tmpdir/`basename \"$kernel\"`.$ext"
166 if [ -z "$cacheit" -o ! -f "$vmz$gzip" -o "$vmz$gzip" -ot "$kernel" ]; then
167 ${CROSS}objcopy
$objflags "$kernel" "$vmz.$$"
169 if [ -n "$gzip" ]; then
173 if [ -n "$cacheit" ]; then
174 mv -f "$vmz.$$$gzip" "$vmz$gzip"
182 # Extract kernel version information, some platforms want to include
183 # it in the image header
184 version
=`${CROSS}strings "$kernel" | grep '^Linux version [-0-9.]' | \
186 if [ -n "$version" ]; then
187 uboot_version
="-n Linux-$version"
193 mkimage
-A ppc
-O linux
-T kernel
-C gzip -a 00000000 -e 00000000 \
194 $uboot_version -d "$vmz" "$ofile"
195 if [ -z "$cacheit" ]; then
203 ${CROSS}objcopy
$4 $1 \
204 --add-section=$3="$2" \
205 --set-section-flags=$3=contents
,alloc
,load
,readonly,data
208 addsec
$tmp "$vmz" $ksection $object/empty.o
209 if [ -z "$cacheit" ]; then
213 if [ -n "$initrd" ]; then
214 addsec
$tmp "$initrd" $isection
217 if [ -n "$dtb" ]; then
218 addsec
$tmp "$dtb" .kernel
:dtb
219 if [ -n "$dts" ]; then
224 if [ "$platform" != "miboot" ]; then
225 ${CROSS}ld
-m elf32ppc
-T $lds -o "$ofile" \
226 $platformo $tmp $object/wrapper.a
230 # Some platforms need the zImage's entry point and base address
231 base
=0x
`${CROSS}nm "$ofile" | grep ' _start$' | cut -d' ' -f1`
232 entry
=`${CROSS}objdump -f "$ofile" | grep '^start address ' | cut -d' ' -f3`
234 if [ -n "$binary" ]; then
235 mv "$ofile" "$ofile".elf
236 ${CROSS}objcopy
-O binary
"$ofile".elf
"$ofile".bin
239 # post-processing needed for some platforms
242 $object/addnote
"$ofile"
245 ${CROSS}objcopy
-O aixcoff-rs6000
--set-start "$entry" "$ofile"
246 $object/hack-coff
"$ofile"
249 gzip -f -9 "$ofile".bin
250 mkimage
-A ppc
-O linux
-T kernel
-C gzip -a "$base" -e "$entry" \
251 $uboot_version -d "$ofile".bin.gz
"$ofile"
254 mv "$ofile" "$ofile.elf"
255 $object/mktree
"$ofile.elf" "$ofile" "$base" "$entry"
256 if [ -z "$cacheit" ]; then
262 # The ps3's loader supports loading gzipped binary images from flash
263 # rom to addr zero. The loader enters the image at addr 0x100. A
264 # bootwrapper overlay is use to arrange for the kernel to be loaded
265 # to addr zero and to have a suitable bootwrapper entry at 0x100.
266 # To construct the rom image, 0x100 bytes from offset 0x100 in the
267 # kernel is copied to the bootwrapper symbol __system_reset_kernel.
268 # The 0x100 bytes at the bootwrapper symbol __system_reset_overlay is
269 # then copied to offset 0x100. At runtime the bootwrapper program
270 # copies the 0x100 bytes at __system_reset_kernel to addr 0x100.
272 system_reset_overlay
=0x
`${CROSS}nm "$ofile".elf \
273 | grep ' __system_reset_overlay$' \
275 system_reset_overlay
=`printf "%d" $system_reset_overlay`
276 system_reset_kernel
=0x
`${CROSS}nm "$ofile".elf \
277 | grep ' __system_reset_kernel$' \
279 system_reset_kernel
=`printf "%d" $system_reset_kernel`
283 rm -f "$object/otheros.bld"
285 msg
=$
(dd if="$ofile.bin" of
="$ofile.bin" conv
=notrunc \
286 skip
=$overlay_dest seek
=$system_reset_kernel \
287 count
=$overlay_size bs
=1 2>&1)
289 if [ $?
-ne "0" ]; then
294 msg
=$
(dd if="$ofile.bin" of
="$ofile.bin" conv
=notrunc \
295 skip
=$system_reset_overlay seek
=$overlay_dest \
296 count
=$overlay_size bs
=1 2>&1)
298 if [ $?
-ne "0" ]; then
303 gzip --force -9 --stdout "$ofile.bin" > "$object/otheros.bld"