[POWERPC] Create and use set_pci_dma_ops
[linux-2.6/btrfs-unstable.git] / arch / powerpc / boot / wrapper
blob024e4d425c596b30fd9b31817d0dbc2bb0a4a990
1 #!/bin/sh
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
9 # given platform.
11 # Options:
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 .)
24 # defaults
25 kernel=
26 ofile=zImage
27 platform=of
28 initrd=
29 dtb=
30 dts=
31 cacheit=
33 # cross-compilation prefix
34 CROSS=
36 # directory for object and other files used by this script
37 object=arch/powerpc/boot
39 # directory for working files
40 tmpdir=.
42 usage() {
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
46 exit 1
49 while [ "$#" -gt 0 ]; do
50 case "$1" in
51 -o)
52 shift
53 [ "$#" -gt 0 ] || usage
54 ofile="$1"
56 -p)
57 shift
58 [ "$#" -gt 0 ] || usage
59 platform="$1"
61 -i)
62 shift
63 [ "$#" -gt 0 ] || usage
64 initrd="$1"
66 -d)
67 shift
68 [ "$#" -gt 0 ] || usage
69 dtb="$1"
71 -s)
72 shift
73 [ "$#" -gt 0 ] || usage
74 dts="$1"
76 -c)
77 cacheit=y
79 -C)
80 shift
81 [ "$#" -gt 0 ] || usage
82 CROSS="$1"
84 -D)
85 shift
86 [ "$#" -gt 0 ] || usage
87 object="$1"
89 -W)
90 shift
91 [ "$#" -gt 0 ] || usage
92 tmpdir="$1"
94 -?)
95 usage
98 [ -z "$kernel" ] || usage
99 kernel="$1"
101 esac
102 shift
103 done
105 if [ -n "$dts" ]; then
106 if [ -z "$dtb" ]; then
107 dtb="$platform.dtb"
109 dtc -O dtb -o "$dtb" -b 0 -V 16 "$dts" || exit 1
112 if [ -z "$kernel" ]; then
113 kernel=vmlinux
116 platformo=$object/"$platform".o
117 lds=$object/zImage.lds
118 ext=strip
119 objflags=-S
120 tmp=$tmpdir/zImage.$$.o
121 ksection=.kernel:vmlinux.strip
122 isection=.kernel:initrd
124 case "$platform" in
125 pmac|pseries|chrp)
126 platformo=$object/of.o
128 pmaccoff)
129 platformo=$object/of.o
130 lds=$object/zImage.coff.lds
132 miboot|uboot)
133 # miboot and U-boot want just the bare bits, not an ELF binary
134 ext=bin
135 objflags="-O binary"
136 tmp="$ofile"
137 ksection=image
138 isection=initrd
140 esac
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.$$"
145 gzip -f -9 "$vmz.$$"
146 if [ -n "$cacheit" ]; then
147 mv -f "$vmz.$$.gz" "$vmz.gz"
148 else
149 vmz="$vmz.$$"
153 case "$platform" in
154 uboot)
155 rm -f "$ofile"
156 version=`${CROSS}strings "$kernel" | grep '^Linux version [-0-9.]' | \
157 cut -d' ' -f3`
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
164 rm -f $vmz.gz
166 exit 0
168 esac
170 addsec() {
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
178 rm -f "$vmz.gz"
181 if [ -n "$initrd" ]; then
182 addsec $tmp "$initrd" $isection
185 if [ -n "$dtb" ]; then
186 addsec $tmp "$dtb" .kernel:dtb
187 if [ -n "$dts" ]; then
188 rm $dtb
192 if [ "$platform" != "miboot" ]; then
193 ${CROSS}ld -m elf32ppc -T $lds -o "$ofile" \
194 $object/crt0.o $platformo $tmp $object/wrapper.a
195 rm $tmp
198 # post-processing needed for some platforms
199 case "$platform" in
200 pseries|chrp)
201 $object/addnote "$ofile"
203 pmaccoff)
204 ${CROSS}objcopy -O aixcoff-rs6000 --set-start 0x500000 "$ofile"
205 $object/hack-coff "$ofile"
207 esac