[POWERPC] bootwrapper: Add CONFIG_DEVICE_TREE
[linux-block.git] / arch / powerpc / boot / wrapper
CommitLineData
2bf11819
PM
1#!/bin/sh
2
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.
6
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.
10
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 .)
23
24# defaults
25kernel=
26ofile=zImage
27platform=of
28initrd=
29dtb=
30dts=
31cacheit=
a9903811 32gzip=.gz
2bf11819
PM
33
34# cross-compilation prefix
35CROSS=
36
37# directory for object and other files used by this script
38object=arch/powerpc/boot
39
40# directory for working files
41tmpdir=.
42
43usage() {
44 echo 'Usage: wrapper [-o output] [-p platform] [-i initrd]' >&2
45 echo ' [-d devtree] [-s tree.dts] [-c] [-C cross-prefix]' >&2
a9903811 46 echo ' [-D datadir] [-W workingdir] [--no-gzip] [vmlinux]' >&2
2bf11819
PM
47 exit 1
48}
49
50while [ "$#" -gt 0 ]; do
51 case "$1" in
52 -o)
53 shift
54 [ "$#" -gt 0 ] || usage
55 ofile="$1"
56 ;;
57 -p)
58 shift
59 [ "$#" -gt 0 ] || usage
60 platform="$1"
61 ;;
62 -i)
63 shift
64 [ "$#" -gt 0 ] || usage
65 initrd="$1"
66 ;;
67 -d)
68 shift
69 [ "$#" -gt 0 ] || usage
70 dtb="$1"
71 ;;
72 -s)
73 shift
74 [ "$#" -gt 0 ] || usage
75 dts="$1"
76 ;;
77 -c)
78 cacheit=y
79 ;;
80 -C)
81 shift
82 [ "$#" -gt 0 ] || usage
83 CROSS="$1"
84 ;;
85 -D)
86 shift
87 [ "$#" -gt 0 ] || usage
88 object="$1"
89 ;;
90 -W)
91 shift
92 [ "$#" -gt 0 ] || usage
93 tmpdir="$1"
94 ;;
a9903811
SW
95 --no-gzip)
96 gzip=
97 ;;
2bf11819
PM
98 -?)
99 usage
100 ;;
101 *)
102 [ -z "$kernel" ] || usage
103 kernel="$1"
104 ;;
105 esac
106 shift
107done
108
109if [ -n "$dts" ]; then
110 if [ -z "$dtb" ]; then
111 dtb="$platform.dtb"
112 fi
113 dtc -O dtb -o "$dtb" -b 0 -V 16 "$dts" || exit 1
114fi
115
116if [ -z "$kernel" ]; then
117 kernel=vmlinux
118fi
119
120platformo=$object/"$platform".o
121lds=$object/zImage.lds
122ext=strip
123objflags=-S
124tmp=$tmpdir/zImage.$$.o
125ksection=.kernel:vmlinux.strip
126isection=.kernel:initrd
127
128case "$platform" in
129pmac|pseries|chrp)
130 platformo=$object/of.o
131 ;;
132pmaccoff)
133 platformo=$object/of.o
134 lds=$object/zImage.coff.lds
135 ;;
136miboot|uboot)
137 # miboot and U-boot want just the bare bits, not an ELF binary
138 ext=bin
139 objflags="-O binary"
140 tmp="$ofile"
141 ksection=image
142 isection=initrd
143 ;;
144esac
145
146vmz="$tmpdir/`basename \"$kernel\"`.$ext"
1383a34f 147if [ -z "$cacheit" -o ! -f "$vmz$gzip" -o "$vmz$gzip" -ot "$kernel" ]; then
2bf11819 148 ${CROSS}objcopy $objflags "$kernel" "$vmz.$$"
a9903811
SW
149
150 if [ -n "$gzip" ]; then
151 gzip -f -9 "$vmz.$$"
152 fi
153
2bf11819 154 if [ -n "$cacheit" ]; then
a9903811 155 mv -f "$vmz.$$$gzip" "$vmz$gzip"
2bf11819
PM
156 else
157 vmz="$vmz.$$"
158 fi
159fi
160
a9903811
SW
161vmz="$vmz$gzip"
162
2bf11819
PM
163case "$platform" in
164uboot)
165 rm -f "$ofile"
166 version=`${CROSS}strings "$kernel" | grep '^Linux version [-0-9.]' | \
167 cut -d' ' -f3`
168 if [ -n "$version" ]; then
169 version="-n Linux-$version"
170 fi
171 mkimage -A ppc -O linux -T kernel -C gzip -a 00000000 -e 00000000 \
a9903811 172 $version -d "$vmz" "$ofile"
2bf11819 173 if [ -z "$cacheit" ]; then
a9903811 174 rm -f "$vmz"
2bf11819
PM
175 fi
176 exit 0
177 ;;
178esac
179
180addsec() {
181 ${CROSS}objcopy $4 $1 \
182 --add-section=$3="$2" \
183 --set-section-flags=$3=contents,alloc,load,readonly,data
184}
185
a9903811 186addsec $tmp "$vmz" $ksection $object/empty.o
2bf11819 187if [ -z "$cacheit" ]; then
a9903811 188 rm -f "$vmz"
2bf11819
PM
189fi
190
191if [ -n "$initrd" ]; then
c888554b 192 addsec $tmp "$initrd" $isection
2bf11819
PM
193fi
194
195if [ -n "$dtb" ]; then
c888554b 196 addsec $tmp "$dtb" .kernel:dtb
e9c4b4bd
MG
197 if [ -n "$dts" ]; then
198 rm $dtb
199 fi
2bf11819
PM
200fi
201
202if [ "$platform" != "miboot" ]; then
203 ${CROSS}ld -m elf32ppc -T $lds -o "$ofile" \
cd197ffc 204 $platformo $tmp $object/wrapper.a
2bf11819
PM
205 rm $tmp
206fi
207
208# post-processing needed for some platforms
209case "$platform" in
210pseries|chrp)
211 $object/addnote "$ofile"
212 ;;
213pmaccoff)
cd197ffc
DG
214 entry=`objdump -f "$ofile" | grep '^start address ' | \
215 cut -d' ' -f3`
216 ${CROSS}objcopy -O aixcoff-rs6000 --set-start "$entry" "$ofile"
2bf11819
PM
217 $object/hack-coff "$ofile"
218 ;;
219esac