forked from sehraf/d1-riscv-arch-image-builder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
1_compile.sh
executable file
·277 lines (236 loc) · 11.1 KB
/
1_compile.sh
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
#!/usr/bin/sh
set -e
# set -x
. ./consts.sh
clean_dir() {
_DIR=${1}
# kind of dangerous ...
[ "${_DIR}" = '/' ] && exit 1
rm -rf "${_DIR}" || true
}
pin_commit() {
_COMMIT=${1}
_COMMIT_IS=$(git rev-parse HEAD)
[ "${IGNORE_COMMITS}" != '0' ] || [ "${_COMMIT}" = "${_COMMIT_IS}" ] || ( echo "Commit mismatch"; exit 1)
}
patch_config() {
key="$1"
val="$2"
if [ -z "$key" ] || [ -z "$val" ] ; then
exit 1
fi
echo "CONFIG_${key}=${val}" >> linux-build/.config
}
for DEP in riscv64-linux-gnu-gcc swig cpio ; do
check_deps ${DEP}
done
mkdir -p build
mkdir -p "${OUT_DIR}"
cd build
if [ ! -f "${OUT_DIR}/boot0_sdcard_sun20iw1p1.bin" ] ; then
# build Boot0
DIR='sun20i_d1_spl'
clean_dir ${DIR}
git clone https://github.com/smaeul/sun20i_d1_spl
cd "${DIR}"
git checkout "${COMMIT_BOOT0}"
make CROSS_COMPILE="${CROSS_COMPILE}" p=sun20iw1p1 mmc
cd ..
cp ${DIR}/nboot/boot0_sdcard_sun20iw1p1.bin "${OUT_DIR}"
fi
if [ ! -f "${OUT_DIR}/u-boot.toc1" ] ; then
# build OpenSBI
DIR='opensbi'
clean_dir ${DIR}
git clone https://github.com/smaeul/opensbi
cd ${DIR}
git checkout d1-wip
make CROSS_COMPILE="${CROSS_COMPILE}" PLATFORM=generic FW_PIC=y FW_OPTIONS=0x2
cd ..
# cp opensbi/build/platform/generic/firmware/fw_dynamic.bin ${OUT_DIR}
# build U-Boot
DIR='u-boot'
clean_dir ${DIR}
git clone https://github.com/smaeul/u-boot.git
cd ${DIR}
git checkout d1-wip
pin_commit "${COMMIT_UBOOT}"
make CROSS_COMPILE="${CROSS_COMPILE}" ARCH="${ARCH}" nezha_defconfig
# make CROSS_COMPILE=${CROSS_COMPILE} ARCH=${ARCH} lichee_rv_defconfig
make CROSS_COMPILE="${CROSS_COMPILE}" ARCH="${ARCH}" -j "${NPROC}"
cd ..
# cp u-boot/arch/riscv/dts/sun20i-d1-lichee-rv-dock.dtb ${OUT_DIR}
# build u-boot toc
cat << EOF > licheerv_toc1.cfg
[opensbi]
file = opensbi/build/platform/generic/firmware/fw_dynamic.bin
addr = 0x40000000
[dtb]
file = u-boot/arch/riscv/dts/sun20i-d1-lichee-rv-dock.dtb
addr = 0x44000000
[u-boot]
file = u-boot/u-boot-nodtb.bin
addr = 0x4a000000
EOF
${DIR}/tools/mkimage -T sunxi_toc1 -d licheerv_toc1.cfg u-boot.toc1
cp u-boot.toc1 "${OUT_DIR}"
fi
if [ ! -f "${OUT_DIR}/boot.scr" ] ; then
DIR='u-boot'
# https://andreas.welcomes-you.com/boot-sw-debian-risc-v-lichee-rv/
cat << 'EOF' > bootscr.txt
setenv bootargs earlycon=sbi console=ttyS0,115200n8 root=/dev/mmcblk0p2 cma=96M
echo "Loading kernel from mmc 0:1 to address ${kernel_addr_r}"
load mmc 0:1 ${kernel_addr_r} Image
echo "Booting kernel with bootargs as $bootargs; and fdtcontroladdr is $fdtcontroladdr"
booti ${kernel_addr_r} - ${fdtcontroladdr}
EOF
${DIR}/tools/mkimage -T script -C none -O linux -A "${ARCH}" -d bootscr.txt boot.scr
rm bootscr.txt
cp boot.scr "${OUT_DIR}"
fi
if [ ! -f "${OUT_DIR}/Image" ] || [ ! -f "${OUT_DIR}/Image.gz" ] ; then
# TODO use archlinux-riscv kernel
# build kernel
DIR='linux'
clean_dir ${DIR}
clean_dir ${DIR}-build
# try not to clone complete linux source tree here!
git clone --depth 1 https://github.com/smaeul/linux -b d1-wip-v5.18-rc1
cd ${DIR}
pin_commit "${COMMIT_KERNEL}"
cd ..
# LicheeRV defconfig
# mkdir -p linux-build/arch/riscv/configs
# cp ../licheerv_linux_defconfig linux-build/arch/riscv/configs/licheerv_defconfig
# make ARCH=${ARCH} -C linux O=../linux-build licheerv_defconfig
case "$KERNEL" in
'nezha_defconfig')
# Nezha defconfig
# enable WiFi
echo 'CONFIG_WIRELESS=y' >> ${DIR}/arch/riscv/configs/nezha_defconfig
echo 'CONFIG_CFG80211=m' >> ${DIR}/arch/riscv/configs/nezha_defconfig
# enable /proc/config.gz
echo 'CONFIG_IKCONFIG_PROC=y' >> ${DIR}/arch/riscv/configs/nezha_defconfig
# There is no LAN. so let there be USB-LAN
echo 'CONFIG_USB_NET_DRIVERS=m' >> ${DIR}/arch/riscv/configs/nezha_defconfig
echo 'CONFIG_USB_CATC=m' >> ${DIR}/arch/riscv/configs/nezha_defconfig
echo 'CONFIG_USB_KAWETH=m' >> ${DIR}/arch/riscv/configs/nezha_defconfig
echo 'CONFIG_USB_PEGASUS=m' >> ${DIR}/arch/riscv/configs/nezha_defconfig
echo 'CONFIG_USB_RTL8150=m' >> ${DIR}/arch/riscv/configs/nezha_defconfig
echo 'CONFIG_USB_RTL8152=m' >> ${DIR}/arch/riscv/configs/nezha_defconfig
echo 'CONFIG_USB_LAN78XX=m' >> ${DIR}/arch/riscv/configs/nezha_defconfig
echo 'CONFIG_USB_USBNET=m' >> ${DIR}/arch/riscv/configs/nezha_defconfig
echo 'CONFIG_USB_NET_AX8817X=m' >> ${DIR}/arch/riscv/configs/nezha_defconfig
echo 'CONFIG_USB_NET_AX88179_178A=m' >> ${DIR}/arch/riscv/configs/nezha_defconfig
echo 'CONFIG_USB_NET_CDCETHER=m' >> ${DIR}/arch/riscv/configs/nezha_defconfig
echo 'CONFIG_USB_NET_CDC_EEM=m' >> ${DIR}/arch/riscv/configs/nezha_defconfig
echo 'CONFIG_USB_NET_CDC_NCM=m' >> ${DIR}/arch/riscv/configs/nezha_defconfig
echo 'CONFIG_USB_NET_HUAWEI_CDC_NCM=m' >> ${DIR}/arch/riscv/configs/nezha_defconfig
echo 'CONFIG_USB_NET_CDC_MBIM=m' >> ${DIR}/arch/riscv/configs/nezha_defconfig
echo 'CONFIG_USB_NET_DM9601=m' >> ${DIR}/arch/riscv/configs/nezha_defconfig
echo 'CONFIG_USB_NET_SR9700=m' >> ${DIR}/arch/riscv/configs/nezha_defconfig
echo 'CONFIG_USB_NET_SR9800=m' >> ${DIR}/arch/riscv/configs/nezha_defconfig
echo 'CONFIG_USB_NET_SMSC75XX=m' >> ${DIR}/arch/riscv/configs/nezha_defconfig
echo 'CONFIG_USB_NET_SMSC95XX=m' >> ${DIR}/arch/riscv/configs/nezha_defconfig
echo 'CONFIG_USB_NET_GL620A=m' >> ${DIR}/arch/riscv/configs/nezha_defconfig
echo 'CONFIG_USB_NET_NET1080=m' >> ${DIR}/arch/riscv/configs/nezha_defconfig
echo 'CONFIG_USB_NET_PLUSB=m' >> ${DIR}/arch/riscv/configs/nezha_defconfig
echo 'CONFIG_USB_NET_MCS7830=m' >> ${DIR}/arch/riscv/configs/nezha_defconfig
echo 'CONFIG_USB_NET_RNDIS_HOST=m' >> ${DIR}/arch/riscv/configs/nezha_defconfig
echo 'CONFIG_USB_NET_CDC_SUBSET_ENABLE=m' >> ${DIR}/arch/riscv/configs/nezha_defconfig
echo 'CONFIG_USB_NET_CDC_SUBSET=m' >> ${DIR}/arch/riscv/configs/nezha_defconfig
echo 'CONFIG_USB_ALI_M5632=y' >> ${DIR}/arch/riscv/configs/nezha_defconfig
echo 'CONFIG_USB_AN2720=y' >> ${DIR}/arch/riscv/configs/nezha_defconfig
echo 'CONFIG_USB_BELKIN=y' >> ${DIR}/arch/riscv/configs/nezha_defconfig
echo 'CONFIG_USB_ARMLINUX=y' >> ${DIR}/arch/riscv/configs/nezha_defconfig
echo 'CONFIG_USB_EPSON2888=y' >> ${DIR}/arch/riscv/configs/nezha_defconfig
echo 'CONFIG_USB_KC2190=y' >> ${DIR}/arch/riscv/configs/nezha_defconfig
echo 'CONFIG_USB_NET_ZAURUS=m' >> ${DIR}/arch/riscv/configs/nezha_defconfig
echo 'CONFIG_USB_NET_CX82310_ETH=m' >> ${DIR}/arch/riscv/configs/nezha_defconfig
echo 'CONFIG_USB_NET_KALMIA=m' >> ${DIR}/arch/riscv/configs/nezha_defconfig
echo 'CONFIG_USB_NET_QMI_WWAN=m' >> ${DIR}/arch/riscv/configs/nezha_defconfig
echo 'CONFIG_USB_NET_INT51X1=m' >> ${DIR}/arch/riscv/configs/nezha_defconfig
echo 'CONFIG_USB_IPHETH=m' >> ${DIR}/arch/riscv/configs/nezha_defconfig
echo 'CONFIG_USB_SIERRA_NET=m' >> ${DIR}/arch/riscv/configs/nezha_defconfig
echo 'CONFIG_USB_VL600=m' >> ${DIR}/arch/riscv/configs/nezha_defconfig
echo 'CONFIG_USB_NET_CH9200=m' >> ${DIR}/arch/riscv/configs/nezha_defconfig
echo 'CONFIG_USB_NET_AQC111=m' >> ${DIR}/arch/riscv/configs/nezha_defconfig
echo 'CONFIG_USB_RTL8153_ECM=m' >> ${DIR}/arch/riscv/configs/nezha_defconfig
# enable systemV IPC (needed by fakeroot during makepkg)
echo 'CONFIG_SYSVIPC=y' >> ${DIR}/arch/riscv/configs/nezha_defconfig
echo 'CONFIG_SYSVIPC_SYSCTL=y' >> ${DIR}/arch/riscv/configs/nezha_defconfig
# enable swap
echo 'CONFIG_SWAP=y' >> ${DIR}/arch/riscv/configs/nezha_defconfig
echo 'CONFIG_ZSWAP=y' >> ${DIR}/arch/riscv/configs/nezha_defconfig
make ARCH="${ARCH}" -C linux O=../linux-build nezha_defconfig
;;
# Archlinux PR #1001 https://github.com/felixonmars/archriscv-packages/pull/1001 config
# https://github.com/felixonmars/archriscv-packages/blob/6689a4fdcd76dbbab777803493873f65e127e3e6/linux-nezha-git/config
# mkdir -p linux-build/arch/riscv/configs
# cp ../arch_nezha_git_config linux-build/arch/riscv/configs/licheerv_defconfig
# make ARCH=${ARCH} -C linux O=../linux-build licheerv_defconfig
'arch')
# https://archriscv.felixc.at/repo/core/linux-5.17.3.arch1-1-riscv64.pkg.tar.zst
# setup linux-build
make ARCH="${ARCH}" -C linux O=../linux-build nezha_defconfig
# deploy config
cp ../../linux-5.17.3.arch1-1-riscv64.config linux-build/.config
# apply defaults
make CROSS_COMPILE="${CROSS_COMPILE}" ARCH="${ARCH}" -j "${NPROC}" -C linux-build olddefconfig
# patch config
patch_config ARCH_FLATMEM_ENABLE y
patch_config RISCV_DMA_NONCOHERENT y
patch_config RISCV_SBI_V01 y
patch_config HVC_RISCV_SBI y
patch_config SERIAL_EARLYCON_RISCV_SBI y
patch_config BROKEN_ON_SMP y
patch_config ARCH_SUNXI y
patch_config ERRATA_THEAD y
patch_config DRM_SUN4I m
patch_config DRM_SUN6I_DSI m
patch_config DRM_SUN8I_DW_HDMI m
patch_config DRM_SUN8I_MIXER m
patch_config DRM_SUN4I_HDMI n
patch_config DRM_SUN4I_BACKEND n
patch_config CRYPTO_DEV_SUN8I_CE y
patch_config CRYPTO_DEV_SUN8I_CE_HASH y
patch_config CRYPTO_DEV_SUN8I_CE_PRNG y
patch_config CRYPTO_DEV_SUN8I_CE_TRNG y
patch_config SPI_SUN6I m
patch_config PHY_SUN4I_USB m
patch_config SUN50I_IOMMU y
patch_config SUN8I_DE2_CCU y
patch_config SUN8I_DSP_REMOTEPROC y
patch_config SUN8I_THERMAL y
patch_config SUNXI_WATCHDOG y
patch_config GPIO_SYSFS y
# patch_config EXPORT y
# patch_config VMLINUX_MAP y
# these needs to be built-in (probably)
patch_config EXT4_FS y
patch_config MMC y
patch_config MMC_SUNXI y
# apply defaults
make CROSS_COMPILE="${CROSS_COMPILE}" ARCH="${ARCH}" -j "${NPROC}" -C linux-build olddefconfig
;;
*)
echo "Unknown kernel option '$KERNEL'"
exit 1
;;
esac
# compile it!
make CROSS_COMPILE="${CROSS_COMPILE}" ARCH="${ARCH}" -j "${NPROC}" -C linux-build
cp linux-build/arch/riscv/boot/Image.gz "${OUT_DIR}"
cp linux-build/arch/riscv/boot/Image "${OUT_DIR}"
fi
if [ ! -f "${OUT_DIR}/8723ds.ko" ] ; then
# build WiFi driver
DIR='rtl8723ds'
clean_dir ${DIR}
git clone https://github.com/lwfinger/rtl8723ds.git
cd ${DIR}
make CROSS_COMPILE="${CROSS_COMPILE}" ARCH="${ARCH}" KSRC=../linux-build -j "${NPROC}" modules || true
cd ..
cp ${DIR}/8723ds.ko "${OUT_DIR}"
fi