aboutsummaryrefslogtreecommitdiffstats
path: root/arch/powerpc/boot/wrapper
diff options
context:
space:
mode:
authorPaul Mackerras <paulus@samba.org>2006-09-27 08:47:03 -0400
committerPaul Mackerras <paulus@samba.org>2006-09-28 00:30:02 -0400
commit2bf118197cb4d9a5e7a9e45b5b007235fdc9f402 (patch)
treed9d7ceadb4eb1b277e914fcca74c901773f17832 /arch/powerpc/boot/wrapper
parent4e6d816e51728d5006c53e78e079ac62b902f8aa (diff)
[POWERPC] Create a "wrapper" script and use it in arch/powerpc/boot
This puts the knowledge of how to create various sorts of zImage wrappers into a script called "wrapper" that could be used outside of the kernel tree. This changes arch/powerpc/boot so it first builds the files that the wrapper script needs, then runs it to create whatever flavours of zImage are required. This version does uImages as well. The zImage names are changed slightly; zImage.pseries is the one with the PT_NOTE program header entry added, and zImage.pmac is the one without. If the zImage.pseries gets made, it will also get hardlinked to zImage; otherwise, if zImage.pmac is made, it gets hardlinked to zImage. Signed-off-by: Paul Mackerras <paulus@samba.org>
Diffstat (limited to 'arch/powerpc/boot/wrapper')
-rwxr-xr-xarch/powerpc/boot/wrapper204
1 files changed, 204 insertions, 0 deletions
diff --git a/arch/powerpc/boot/wrapper b/arch/powerpc/boot/wrapper
new file mode 100755
index 000000000000..eab7318729e9
--- /dev/null
+++ b/arch/powerpc/boot/wrapper
@@ -0,0 +1,204 @@
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=
32
33# cross-compilation prefix
34CROSS=
35
36# directory for object and other files used by this script
37object=arch/powerpc/boot
38
39# directory for working files
40tmpdir=.
41
42usage() {
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
47}
48
49while [ "$#" -gt 0 ]; do
50 case "$1" in
51 -o)
52 shift
53 [ "$#" -gt 0 ] || usage
54 ofile="$1"
55 ;;
56 -p)
57 shift
58 [ "$#" -gt 0 ] || usage
59 platform="$1"
60 ;;
61 -i)
62 shift
63 [ "$#" -gt 0 ] || usage
64 initrd="$1"
65 ;;
66 -d)
67 shift
68 [ "$#" -gt 0 ] || usage
69 dtb="$1"
70 ;;
71 -s)
72 shift
73 [ "$#" -gt 0 ] || usage
74 dts="$1"
75 ;;
76 -c)
77 cacheit=y
78 ;;
79 -C)
80 shift
81 [ "$#" -gt 0 ] || usage
82 CROSS="$1"
83 ;;
84 -D)
85 shift
86 [ "$#" -gt 0 ] || usage
87 object="$1"
88 ;;
89 -W)
90 shift
91 [ "$#" -gt 0 ] || usage
92 tmpdir="$1"
93 ;;
94 -?)
95 usage
96 ;;
97 *)
98 [ -z "$kernel" ] || usage
99 kernel="$1"
100 ;;
101 esac
102 shift
103done
104
105if [ -n "$dts" ]; then
106 if [ -z "$dtb" ]; then
107 dtb="$platform.dtb"
108 fi
109 dtc -O dtb -o "$dtb" -b 0 -V 16 "$dts" || exit 1
110fi
111
112if [ -z "$kernel" ]; then
113 kernel=vmlinux
114fi
115
116platformo=$object/"$platform".o
117lds=$object/zImage.lds
118ext=strip
119objflags=-S
120tmp=$tmpdir/zImage.$$.o
121ksection=.kernel:vmlinux.strip
122isection=.kernel:initrd
123
124case "$platform" in
125pmac|pseries|chrp)
126 platformo=$object/of.o
127 ;;
128pmaccoff)
129 platformo=$object/of.o
130 lds=$object/zImage.coff.lds
131 ;;
132miboot|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
139 ;;
140esac
141
142vmz="$tmpdir/`basename \"$kernel\"`.$ext"
143if [ -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.$$"
150 fi
151fi
152
153case "$platform" in
154uboot)
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"
160 fi
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
165 fi
166 exit 0
167 ;;
168esac
169
170addsec() {
171 ${CROSS}objcopy $4 $1 \
172 --add-section=$3="$2" \
173 --set-section-flags=$3=contents,alloc,load,readonly,data
174}
175
176addsec $tmp "$vmz.gz" $ksection $object/empty.o
177if [ -z "$cacheit" ]; then
178 rm -f "$vmz.gz"
179fi
180
181if [ -n "$initrd" ]; then
182 addsec $tmp "$initrd" initrd
183fi
184
185if [ -n "$dtb" ]; then
186 addsec $tmp "$dtb" dtb
187fi
188
189if [ "$platform" != "miboot" ]; then
190 ${CROSS}ld -m elf32ppc -T $lds -o "$ofile" \
191 $object/crt0.o $platformo $tmp $object/wrapper.a
192 rm $tmp
193fi
194
195# post-processing needed for some platforms
196case "$platform" in
197pseries|chrp)
198 $object/addnote "$ofile"
199 ;;
200pmaccoff)
201 ${CROSS}objcopy -O aixcoff-rs6000 --set-start 0x500000 "$ofile"
202 $object/hack-coff "$ofile"
203 ;;
204esac