blob: b979b362e6e9ad2306000d8b3c476f4947291fc2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
|
#!/bin/sh
set -e
#OPTIONS='CONFIG_DEBUG_SECTION_MISMATCH=y'
#OPTIONS='C=1'
OPTIONS="KALLSYMS_EXTRA_PASS=0"
KCFLAGS="-Werror -Wno-error=cpp"
NFS_ROOT=$HOME/src/netboot
TFTP_ROOT=$HOME/tftpboot
echo $PWD | grep -q libcamera && PLATFORM=x86
echo $PWD | grep -q media && PLATFORM=omap3
echo $PWD | grep -q omap && PLATFORM=omap4+
echo $PWD | grep -q plusoptix && PLATFORM=imx7
echo $PWD | grep -q renesas && PLATFORM=gen3
echo $PWD | grep -q xilinx && PLATFORM=zynqmp
do_compile_doc=0
do_menu_config=0
do_package_deb=0
opt_bootloader=
opt_cmdline_file=
opt_defconfig=
while [[ $# != 0 ]] ; do
option=$1
shift
case $option in
--bootloader)
opt_bootloader=$1
if [[ ! -r $opt_bootloader ]] ; then
echo "Boot loader file $opt_bootloader is not readable"
exit 1
fi
shift
;;
--cmdline)
opt_cmdline_file=$1
if [[ ! -r $opt_cmdline_file ]] ; then
echo "Command line file $opt_cmdline_file is not readable"
exit 1
fi
shift
;;
--config)
do_menu_config=1
;;
--deb)
do_package_deb=1
;;
--defconfig)
opt_defconfig=$1
if [[ ! -r $opt_defconfig ]] ; then
echo "defconfig file $opt_defconfig is not readable"
exit 1
fi
shift
;;
--doc)
do_compile_doc=1
;;
--*)
echo "Unrecognized option $option"
exit 1
;;
*)
PLATFORM=$option
;;
esac
done
case $PLATFORM in
gen3)
ARCH=arm64
BOOT_DIR=$TFTP_ROOT/gen3
DTBS="renesas/r8a7795-es1-h3ulcb.dtb renesas/r8a7795-es1-salvator-x.dtb renesas/r8a7795-h3ulcb.dtb renesas/r8a7795-h3ulcb-kf.dtb renesas/r8a7795-salvator-x.dtb renesas/r8a7795-salvator-xs.dtb renesas/r8a7796-m3ulcb.dtb renesas/r8a7796-salvator-x.dtb renesas/r8a77995-draak.dtb"
DTBS=$(cd arch/arm64/boot/dts ; ls renesas/*.dts | sed 's/\.dts/.dtb/')
#DTBS="renesas/r8a77965-salvator-xs.dtb"
IMAGE=FIT
LOADADDR=0x48080000
;;
imx7)
ARCH=arm
#BOOT_DIR=$TFTP_ROOT/imx7
BOOT_DIR=$NFS_ROOT/arm32/boot
DTBS="imx7d-sx-pl-emar.dtb imx7d-sx-pl-test.dtb"
IMAGE=zImage
LOADADDR=0x80008000
;;
omap3)
ARCH=arm
BOOT_DIR=$TFTP_ROOT/omap3
DTBS="omap3-beagle-xm.dtb omap3-overo-storm-tobi.dtb"
IMAGE=zImage
;;
omap4+)
ARCH=arm
BOOT_DIR=$TFTP_ROOT/omap4
DTBS="omap4-panda.dtb omap4-panda-es.dtb am57xx-evm-reva3.dtb:am57xx-beagle-x15.dtb"
IMAGE=FIT
LOADADDR=0x80008000
;;
scarlet)
ARCH=arm64
BOOT_DIR=$NFS_ROOT/arm64/boot
CMDLINE="console=ttyS2,115200n8 earlyprintk=ttyS2,115200n8 console=tty1 init=/sbin/init root=PARTUUID=%U/PARTNROFF=1 rootwait rw noinitrd ignore_loglevel"
CMDLINE="console=ttyS2,115200n8 earlyprintk=ttyS2,115200n8 console=tty1 ip=dhcp root=/dev/nfs rootwait rw noinitrd ignore_loglevel"
DTBS="rockchip/rk3399-gru-scarlet-inx.dtb"
IMAGE=cros-arm
LOADADDR=0
;;
soraka)
ARCH=x86
BOOT_DIR=$TFTP_ROOT/x86
CMDLINE="console=ttyS0,115200n8 earlyprintk=ttyS0,115200n8 console=tty1 ip=dhcp root=/dev/nfs rootwait rw noinitrd ignore_loglevel"
IMAGE=cros-x86
KCFLAGS="$KCFLAGS -Wno-error=frame-larger-than="
;;
x86)
ARCH=x86
BOOT_DIR=$TFTP_ROOT/x86
IMAGE=bzImage
KCFLAGS="$KCFLAGS -Wno-error=frame-larger-than="
;;
zynqmp)
ARCH=arm64
BOOT_DIR=$TFTP_ROOT/xilinx
DTBS="xilinx/zynqmp-zcu106-revA.dtb"
IMAGE=Image
LOADADDR=0x10000000
KCFLAGS="$KCFLAGS -Wno-error=packed-not-aligned -Wno-error=sizeof-pointer-memaccess -Wno-error=stringop-truncation -Wno-error=stringop-overflow"
target_dir=$NFS_ROOT/zynqmp
;;
*)
echo "Invalid platform $PLATFORM"
exit 1
;;
esac
case $ARCH in
arm)
arch_dir=arm32
cross_compile=arm-buildroot-linux-uclibcgnueabihf-
image_kernel=zImage
;;
arm64)
arch_dir=arm64
cross_compile=aarch64-buildroot-linux-gnu-
image_kernel=Image
;;
x86)
arch_dir=x86
cross_compile=
image_kernel=bzImage
;;
esac
target_dir=${target_dir:-$NFS_ROOT/$arch_dir}
output_dir=${output_dir:-$PWD/output/$arch_dir}
#
# Parallelize make with twice as many jobs as CPUs
#
num_cpus=$(cat /proc/cpuinfo | grep '^processor\b' | wc -l)
pmake="make -j$((num_cpus*2))"
OPTIONS="KALLSYMS_EXTRA_PASS=0 KCFLAGS='$KCFLAGS'"
echo "Compiling for platform $PLATFORM with $num_cpus CPUs"
mkdir -p $output_dir/
if [[ -n "$opt_defconfig" ]] ; then
mkdir -p $output_dir/arch/$ARCH/configs/
cp $opt_defconfig $output_dir/arch/$ARCH/configs/build_defconfig
make ARCH=$ARCH O=$output_dir build_defconfig
rm $output_dir/arch/$ARCH/configs/build_defconfig
fi
if [[ $do_menu_config = 1 ]] ; then
make ARCH=$ARCH O=$output_dir menuconfig
exit 0
fi
#
# Compile documentation if requested
#
if [[ $do_compile_doc = 1 ]] ; then
$pmake ARCH=$ARCH O=$output_dir DOCBOOKS='' htmldocs
fi
#
# Compile the kernel, modules and DTBs
#
dtbs=
for dtb in $DTBS ; do
dtb=${dtb/:*/}
dtbs="$dtbs $dtb"
done
eval $pmake ARCH=$ARCH O=$output_dir CROSS_COMPILE=$cross_compile $OPTIONS \
$image_kernel $dtbs
grep 'CONFIG_MODULES=y' $output_dir/.config > /dev/null && modules=modules
if [[ x$modules == xmodules ]] ; then
eval $pmake ARCH=$ARCH O=$output_dir CROSS_COMPILE=$cross_compile $OPTIONS \
$modules
fi
version=$(cat $output_dir/include/generated/utsrelease.h | cut -d '"' -f 2)
#
# Create the image
#
make_fit_image() {
local kernel_its=$output_dir/arch/$ARCH/boot/kernel_fdt.its
cat <<EOF > $kernel_its
/dts-v1/;
/ {
description = "Kernel + FDT image for $board board";
#address-cells = <1>;
images {
kernel {
description = "Linux kernel";
data = /incbin/("$output_dir/arch/$ARCH/boot/$image_kernel");
type = "kernel";
arch = "$ARCH";
os = "linux";
compression = "none";
load = <$LOADADDR>;
entry = <$LOADADDR>;
hash-1 {
algo = "crc32";
};
hash-2 {
algo = "sha1";
};
};
EOF
local dtb
for dtb in $DTBS ; do
local src=${dtb/:*/}
local dst=${dtb/*:/}
dst=${dst/*\//}
cat <<EOF >> $kernel_its
fdt-$dst {
description = "Flattened Device Tree blob $dst";
data = /incbin/("$output_dir/arch/$ARCH/boot/dts/$src");
type = "flat_dt";
arch = "$ARCH";
compression = "none";
hash-1 {
algo = "crc32";
};
hash-2 {
algo = "sha1";
};
};
EOF
done
local config=$(echo $DTBS | sed 's/.*[:/]//')
cat <<EOF >> $kernel_its
};
configurations {
default = "conf-$config";
EOF
for dtb in $DTBS ; do
local dst=${dtb/*:/}
dst=${dst/*\//}
cat <<EOF >> $kernel_its
conf-$dst {
description = "Boot Linux kernel with $dst blob";
kernel = "kernel";
fdt = "fdt-$dst";
};
EOF
done
cat <<EOF >> $kernel_its
};
};
EOF
PATH="$output_dir/scripts/dtc:$PATH" mkimage -f $kernel_its ${kernel_its/its/itb}
}
make_srec_image() {
local image=$output_dir/arch/$ARCH/boot/$image_kernel
cat $image | lzma -z -e > $image.xz
objcopy -I binary -O srec --srec-forceS3 --srec-len 516 \
$image.xz $image.xz.srec
for dtb in $DTBS ; do
local src=${dtb/:*/}
objcopy -I binary -O srec --srec-forceS3 --srec-len 516 \
$src $src.srec
done
}
make_uboot_image() {
mkimage -A $ARCH -O linux -T kernel -C none -a $LOADADDR -e $LOADADDR \
-n "Linux-${version}" -d $output_dir/arch/$ARCH/boot/$kernel_image \
$output_dir/arch/$ARCH/boot/uImage
}
make_cros_image() {
local boot_dir=$output_dir/arch/$ARCH/boot
local vmlinuz=$boot_dir/$1
local bootloader
local config
if [[ -f $opt_bootloader ]] ; then
bootloader=$opt_bootloader
else
dd if=/dev/zero of=$boot_dir/bootloader bs=512 count=1
bootloader=$boot_dir/bootloader
fi
if [[ -f $opt_cmdline_file ]] ; then
config=$opt_cmdline_file
else
echo "$CMDLINE" > $boot_dir/cmdline
config=$boot_dir/cmdline
fi
vbutil_kernel \
--pack $boot_dir/vmlinuz.image \
--version 1 \
--vmlinuz $vmlinuz \
--arch $ARCH \
--keyblock /usr/share/vboot/devkeys/kernel.keyblock \
--signprivate /usr/share/vboot/devkeys/kernel_data_key.vbprivk \
--config $config \
--bootloader $bootloader
}
case $IMAGE in
FIT)
make_fit_image
image_file=$output_dir/arch/$ARCH/boot/kernel_fdt.itb
;;
cros-arm)
make_fit_image
make_cros_image kernel_fdt.itb
image_file=$output_dir/arch/$ARCH/boot/vmlinuz.image
;;
cros-x86)
make_fit_image
make_cros_image bzImage
image_file=$output_dir/arch/$ARCH/boot/vmlinuz.image
;;
srec)
make_srec_image
image_file=$output_dir/arch/$ARCH/boot/$kernel_image.xz.srec
;;
uImage)
make_uboot_image
image_file=$output_dir/arch/$ARCH/boot/uImage
;;
*)
image_file=$output_dir/arch/$ARCH/boot/$IMAGE
;;
esac
#
# Copy the files to their destination directories
#
copy_dtbs() {
local dtb
local target_dir=$1
for dtb in $DTBS ; do
local src=${dtb/:*/}
local dst=${dtb/*:/}
dst=${dst/*\//}
cp $output_dir/arch/${ARCH}/boot/dts/$src* $target_dir/$dst
done
}
mkdir -p $BOOT_DIR
cp $image_file $BOOT_DIR/
if [[ $IMAGE != FIT && $IMAGE != cros-arm && $IMAGE != cros-x86 ]] ; then
copy_dtbs $BOOT_DIR/
fi
if [[ x$modules = xmodules ]] ; then
$pmake ARCH=$ARCH O=$output_dir CROSS_COMPILE=$cross_compile INSTALL_MOD_PATH=$target_dir modules_install
echo "Kernel modules installed to $target_dir/lib/modules/$version"
fi
if [[ $do_package_deb = 1 ]] ; then
$pmake ARCH=$ARCH O=$output_dir CROSS_COMPILE=$cross_compile bindeb-pkg
fi
echo "Kernel image available in $image_file"
echo "Build $version completed at $(date)"
|