/
kernel-adaptation-simplified.inc
241 lines (194 loc) · 8.2 KB
/
kernel-adaptation-simplified.inc
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
%if 0%{!?rpm_device:1}
%define rpm_device %{device}
%endif
%if 0%{!?kernel_arch:1}
%define kernel_arch arm
%endif
# The prjconf should have an ExportFilter like this (mer/sailfish has this):
# ExportFilter: \.armv7hl\.rpm$ armv8el
# We lie about our architecture and allows OBS to cross-publish this 486 cross-built spec to the armv7hl repos
%if 0%{?device_target_cpu:1}
%define _target_cpu %{device_target_cpu}
%else
%define _target_cpu %{_arch}
%endif
%if 0%{!?defconfig:1}
%define defconfig defconfig
%endif
%if 0%{!?source_directory:1}
%define source_directory linux/
%endif
%if 0%{!?build_Image:1}
%define build_Image 1
%endif
%if 0%{!?build_uImage:1}
%define build_uImage 0
%endif
%if 0%{!?build_zImage:1}
%define build_zImage 0
%endif
%if 0%{!?build_modules:1}
%define build_modules 1
%endif
%define _tmpdir tmp
Name: kernel-adaptation-%{rpm_device}
Summary: Kernel adaptation for %{rpm_device}
Group: System
License: GPLv2
Provides: kernel
Source: %{name}-%{version}.tar.bz2
Requires(pre): kmod >= 9
BuildRequires: pkgconfig(ncurses)
BuildRequires: pkgconfig(openssl)
#BuildRequires: mer-kernel-checks
BuildRequires: kmod >= 9
#BuildRequires: perl
#BuildRequires: fdupes
BuildRequires: flex
BuildRequires: bison
BuildRequires: bc
BuildRequires: python
BuildRequires: python3-base
BuildRequires: openssl
#!BuildIgnore: rpmlint-mini
BuildRequires: dtc
BuildRequires: clang
#BuildRequires: lld
#BuildRequires: llvm
BuildRequires: lz4
%if 0%{?crossbuild:1}
BuildRequires: cross-%{crossbuild}-gcc
BuildRequires: cross-%{crossbuild}-binutils
BuildRequires: cross-%{crossbuild}-as
%endif
%description
%{summary}.
%prep
%setup -q -n %{name}-%{version}
%build
export ARCH=%{kernel_arch}
export LOCALVERSION="-%{device}"
export CLANG_TRIPLE=%{clangtriple}
export CROSS_COMPILE=%{crosscompile}
export CROSS_COMPILE32=%{crosscompile32}
export HOSTLDFLAGS=%{hostldflags}
rm -rf %{_tmpdir}
mkdir -p %{_tmpdir}
%if 0%{?crossbuild:1}
export CROSS_COMPILE=%{crossbuild}-meego-linux-gnu-
# FIXME? Shouldn't be needed
export PATH=/opt/cross/bin/:$PATH
%endif
#defconfig_name=$(basename %{defconfig})
#[ -e "./%{defconfig}" ] && cp -f ./%{defconfig} %{source_directory}/arch/%{kernel_arch}/configs/$defconfig_name
[ -e "./%{extra_config}" ] && cp -f ./%{extra_config} %{source_directory}/arch/%{kernel_arch}/configs/%{extra_config}
%if 0%{?apply_patches:1}
#Apply any patches
echo "***** Applying patches *****"
sh patches/apply-patches.sh %{source_directory}
%endif
echo "***** Cleaning *****"
#make -C %{source_directory} O=out clean
mkdir -p %{source_directory}/out
rm -rf %{source_directory}/out/*
%if 0%{?build_Image:1}
echo "***** Building Image *****"
make %{makeopts} -C %{source_directory} -j$(nproc) O=out %{kcflags} %{defconfig}
make %{makeopts} -C %{source_directory} -j$(nproc) O=out %{kcflags}
%endif
%if 0%{?build_modules:1}
echo "***** Building Modules *****"
make %{makeopts} -C %{source_directory} -j$(nproc) O=out %{kcflags} modules
%endif
%if 0%{?build_dtboimage:1}
echo "***** Building DTBO Image *****"
python2 kernel-adaptation-simplified/mkdtboimg.py create linux/out/dtbo.img %{source_directory}/out/arch/%{kernel_arch}/boot/dts/%{deviceinfo_dtbo}
%endif
%install
echo "***** Installing *****"
export ARCH=%{kernel_arch}
export LOCALVERSION="-%{device}"
export CLANG_TRIPLE=%{clangtriple}
export CROSS_COMPILE=%{crosscompile}
export CROSS_COMPILE32=%{crosscompile32}
export HOSTLDFLAGS=%{hostldflags}
%if %{build_modules}
mkdir -p %{buildroot}/lib/modules
make -C %{source_directory} O=out %{makeopts} INSTALL_MOD_STRIP=1 modules_install INSTALL_MOD_PATH=%{buildroot}
%endif
echo "***** Building Boot Image *****"
KERNEL=%{source_directory}/out/arch/%{kernel_arch}/boot/Image.gz
DTB=%{source_directory}/out/arch/%{kernel_arch}/boot/dts/%{deviceinfo_dtb}
EXTRA_ARGS=""
RAMDISK=%{ramdisk}
OUT=%{source_directory}/out/arch/%{kernel_arch}/boot/boot.img
mkdir -p %{buildroot}/boot
if [ "%{deviceinfo_bootimg_header_version}" -le 2 ]; then
EXTRA_ARGS+=" --base %{deviceinfo_flash_offset_base} --kernel_offset %{deviceinfo_flash_offset_kernel} --ramdisk_offset %{deviceinfo_flash_offset_ramdisk} --second_offset %{deviceinfo_flash_offset_second} --tags_offset %{deviceinfo_flash_offset_tags} --pagesize %{deviceinfo_flash_pagesize}"
fi
if [ "%{deviceinfo_bootimg_header_version}" -eq 2 ]; then
EXTRA_ARGS+=" --dtb $DTB --dtb_offset %{deviceinfo_flash_offset_dtb}"
fi
#Createl boot.img
if [ "%{deviceinfo_bootimg_header_version}" -le 2 ]; then
python3 $MKBOOTIMG_PATH/mkbootimg.py --kernel "$KERNEL" --ramdisk "$RAMDISK" --cmdline "%{deviceinfo_kernel_cmdline}" --header_version %{deviceinfo_bootimg_header_version} -o "$OUT" --os_version %{deviceinfo_bootimg_os_version} --os_patch_level %{deviceinfo_bootimg_os_patch_level} $EXTRA_ARGS
else
python3 $MKBOOTIMG_PATH/mkbootimg.py --kernel "$KERNEL" --ramdisk "$RAMDISK" --header_version %{deviceinfo_bootimg_header_version} -o "$OUT" --os_version %{deviceinfo_bootimg_os_version} --os_patch_level %{deviceinfo_bootimg_os_patch_level} $EXTRA_ARGS
# Build vendor_boot
%if 0%{?build_vendor_boot:1}
export DEVICEINFO_KERNEL_CMDLINE="%{deviceinfo_kernel_cmdline}"
export DEVICEINFO_DTB=%{deviceinfo_dtb}
export DEVICEINFO_RAMDISK_COMPRESSION=%{deviceinfo_ramdisk_compression}
export DEVICEINFO_FLASH_PAGESIZE=%{deviceinfo_flash_pagesize}
export DEVICEINFO_FLASH_OFFSET_BASE=%{deviceinfo_flash_offset_base}
export DEVICEINFO_FLASH_OFFSET_KERNEL=%{deviceinfo_flash_offset_kernel}
export DEVICEINFO_FLASH_OFFSET_RAMDISK=%{deviceinfo_flash_offset_ramdisk}
export DEVICEINFO_FLASH_OFFSET_TAGS=%{deviceinfo_flash_offset_tags}
export DEVICEINFO_FLASH_OFFSET_DTB=%{deviceinfo_flash_offset_dtb}
export DEVICEINFO_BOOTIMG_QCDT=%{deviceinfo_bootimg_qcdt}
export DEVICEINFO_BOOTIMG_HEADER_VERSION=%{deviceinfo_bootimg_header_version}
export DEVICEINFO_BOOTIMG_PARTITION_SIZE=%{deviceinfo_bootimg_partition_size}
export DEVICEINFO_BOOTIMG_OS_VERSION=%{deviceinfo_bootimg_os_version}
export DEVICEINFO_BOOTIMG_OS_PATCH_LEVEL=%{deviceinfo_bootimg_os_patch_level}
export DEVICEINFO_ROOTFS_IMAGE_SECTOR_SIZE=%{deviceinfo_rootfs_image_sector_size}
export DEVICEINFO_HALIUM_VERSION=%{deviceinfo_halium_version}
export DEVICEINFO_KERNEL_DISABLE_MODULES=%{deviceinfo_kernel_disable_modules}
bash ./kernel-adaptation-simplified/mkvendorboot.sh "$DTB"
cp tmp/vendor-ramdisk/vendor_boot.img %{buildroot}/boot/ || true
%endif
fi
#Use AVB Tool to create final boot.img
if [ -n "%{deviceinfo_bootimg_partition_size}" ]; then
EXTRA_ARGS=""
[ -f "$HERE/rsa4096_boot.pem" ] && EXTRA_ARGS=" --key $HERE/rsa4096_boot.pem --algorithm SHA256_RSA4096"
python3 "$AVB_PATH/avbtool.py" add_hash_footer --image "$OUT" --partition_name boot --partition_size %{deviceinfo_bootimg_partition_size} $EXTRA_ARGS
if [ -n "%{deviceinfo_bootimg_append_vbmeta}" ] && %{deviceinfo_bootimg_append_vbmeta}; then
python3 "$AVB_PATH/avbtool.py" append_vbmeta_image --image "$OUT" --partition_size "%{deviceinfo_bootimg_partition_size}" --vbmeta_image "$TMPDOWN/vbmeta.img"
fi
fi
%if %{build_Image}
echo "***** Installing Image *****"
cp %{source_directory}/out/arch/%{kernel_arch}/boot/*Image* %{buildroot}/boot/
cp %{source_directory}/out/arch/%{kernel_arch}/boot/dts/%{deviceinfo_dtb} %{buildroot}/boot/ || true
cp %{source_directory}/out/arch/%{kernel_arch}/boot/boot.img %{buildroot}/boot/ || true
%endif
%if 0%{?devicetrees:1}
for dtb in %{devicetrees}; do
mkdir -p %{buildroot}/boot/$(basename $(dirname $dtb))
cp linux/out/arch/%{kernel_arch}/boot/dts/$dtb %{buildroot}/boot/$dtb
cp %{buildroot}/boot/*/*.dtb %{buildroot}/boot/
done
%endif
%if 0%{?build_dtboimage:1}
cp %{source_directory}/out/dtbo.img %{buildroot}/boot/ || true
%endif
#Remove some kernel modules from the install
# Build filelist
find %{buildroot} ! \( -type d \) | sed -e s,"%{buildroot}",,g> %{_tmpdir}/kernel-adaptation.files
%post
# This oneshot is enabled only during package upgrades, as initial
# installation is done when we flash device.
if [ $1 -ne 1 ] ; then
add-preinit-oneshot /var/lib/platform-updates/flash-bootimg.sh || :
fi
%files -f %{_tmpdir}/kernel-adaptation.files