Merge branch 'merge' of git://git.kernel.org/pub/scm/linux/kernel/git/paulus/powerpc
[deliverable/linux.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=
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
621da0f8 182 addsec $tmp "$initrd" $isection
2bf11819
PM
183fi
184
185if [ -n "$dtb" ]; then
621da0f8 186 addsec $tmp "$dtb" .kernel:dtb
2bf11819
PM
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
This page took 0.04586 seconds and 5 git commands to generate.