-
Notifications
You must be signed in to change notification settings - Fork 0
233 lines (195 loc) · 9.22 KB
/
build.yml
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
name: k1-sdcard
on:
push:
pull_request:
workflow_dispatch:
schedule:
- cron: "0 2 * * *"
env:
wget_alias: 'wget --retry-connrefused --waitretry=1 --read-timeout=20 --timeout=15 -t 0'
ARCH: riscv
CROSS_COMPILE: riscv64-linux-gnu-
jobs:
build:
runs-on: ubuntu-24.04
steps:
- name: Update Apt Cache
run: sudo apt update
- name: Free Disk Space (Ubuntu)
uses: jlumbroso/free-disk-space@main
with:
# this might remove tools that are actually needed,
# if set to "true" but frees about 6 GB
tool-cache: true
# all of these default to true, but feel free to set to
# "false" if necessary for your workflow
android: true
dotnet: true
haskell: true
large-packages: true
docker-images: true
swap-storage: true
- name: Install software
run: |
sudo apt install -y gdisk dosfstools g++-riscv64-linux-gnu cpp-riscv64-linux-gnu build-essential \
libncurses-dev gawk flex bison openssl libssl-dev tree u-boot-tools \
dkms libelf-dev libudev-dev libpci-dev libiberty-dev autoconf device-tree-compiler \
libconfuse-dev mtools binfmt-support qemu-user-static curl wget mmdebstrap \
debian-archive-keyring debian-keyring debian-ports-archive-keyring genimage
- name: Checkout mkimg
uses: actions/checkout@v4
- name: Checkout opensbi
uses: actions/checkout@v4
with:
repository: ruyisdk-debian-riscv/k1-opensbi
ref: k1-opensbi
path: k1-opensbi
- name: opensbi compile
run: |
mkdir output
${CROSS_COMPILE}gcc -v
pushd ${GITHUB_WORKSPACE}/k1-opensbi
make PLATFORM=generic -j`nproc`
cp -v build/platform/generic/firmware/fw_dynamic.itb ${GITHUB_WORKSPACE}/output/
popd
tree ${GITHUB_WORKSPACE}/output
- name: Checkout uboot
uses: actions/checkout@v4
with:
repository: ruyisdk-debian-riscv/k1-uboot-2022.10
ref: bl-v2.0.y-ext
path: k1-uboot
- name: uboot compile
run: |
pushd ${GITHUB_WORKSPACE}/k1-uboot
make k1_defconfig
make -j`nproc`
# factory
mkdir -p ${GITHUB_WORKSPACE}/output/factory
cp -v u-boot.itb ${GITHUB_WORKSPACE}/output/
cp -v u-boot-env-default.bin ${GITHUB_WORKSPACE}/output/env.bin
cp -v bootinfo_*.bin ${GITHUB_WORKSPACE}/output/factory
cp -v FSBL.bin ${GITHUB_WORKSPACE}/output/factory
popd
tree ${GITHUB_WORKSPACE}/output
- name: kernel download
uses: dawidd6/action-download-artifact@v6
with:
name: k1-kernel-gcc-13-k1
path: output
repo: ruyisdk-debian-riscv/k1-kernel
branch: k1-6.12.y
workflow: kernel.yml
workflow_search: true
workflow_conclusion: success
- name: Remove unused deb
run: |
rm -rf ${GITHUB_WORKSPACE}/output/linux-image-*-dbg_*_riscv64.deb
rm -rf ${GITHUB_WORKSPACE}/output/linux-libc-dev_*_riscv64.deb
- name: Create rootfs
run: |
wget https://deb.debian.org/debian/pool/main/d/debian-archive-keyring/debian-archive-keyring_2023.4_all.deb
sudo dpkg -i debian-archive-keyring_2023.4_all.deb
BOOT_SIZE=500M
ROOT_SIZE=3G
BOOT_IMG="boot.ext4"
truncate -s "$BOOT_SIZE" "$BOOT_IMG"
ROOT_IMG="root.ext4"
truncate -s "$ROOT_SIZE" "$ROOT_IMG"
# Format partitions
sudo mkfs.ext4 -F "$BOOT_IMG"
sudo mkfs.ext4 -F "$ROOT_IMG"
CHROOT_TARGET=${GITHUB_WORKSPACE}/rootfs
mkdir "$CHROOT_TARGET"
sudo mount "$ROOT_IMG" "$CHROOT_TARGET"
PACKAGE_LIST="ca-certificates cloud-guest-utils neofetch network-manager debian-archive-keyring u-boot-menu sudo initramfs-tools locales bluez blueman systemd-timesyncd"
sudo mmdebstrap --architectures=riscv64 \
--include="$PACKAGE_LIST" \
sid "$CHROOT_TARGET" \
"deb https://deb.debian.org/debian/ sid main contrib non-free non-free-firmware"
sudo mkdir "$CHROOT_TARGET"/mnt/boot
sudo mv -v "$CHROOT_TARGET"/boot/* "$CHROOT_TARGET"/mnt/boot/
sudo mount "$BOOT_IMG" "$CHROOT_TARGET"/boot
sudo mv -v "$CHROOT_TARGET"/mnt/boot/* "$CHROOT_TARGET"/boot/
sudo rm -rf "$CHROOT_TARGET"/mnt/boot
sudo mount -t proc /proc "$CHROOT_TARGET"/proc
sudo mount -B /sys "$CHROOT_TARGET"/sys
sudo mount -B /run "$CHROOT_TARGET"/run
sudo mount -B /dev "$CHROOT_TARGET"/dev
sudo mount -B /dev/pts "$CHROOT_TARGET"/dev/pts
sudo mount -t tmpfs tmpfs "$CHROOT_TARGET"/tmp
sudo mount -t tmpfs tmpfs "$CHROOT_TARGET"/var/tmp
sudo mount -t tmpfs tmpfs "$CHROOT_TARGET"/var/cache/apt/archives/
# Set locale to en_US.UTF-8 UTF-8
sudo chroot "$CHROOT_TARGET" sh -c "echo 'locales locales/default_environment_locale select en_US.UTF-8' | debconf-set-selections"
sudo chroot "$CHROOT_TARGET" sh -c "echo 'locales locales/locales_to_be_generated multiselect en_US.UTF-8 UTF-8' | debconf-set-selections"
sudo chroot "$CHROOT_TARGET" sh -c "rm /etc/locale.gen"
sudo chroot "$CHROOT_TARGET" sh -c "dpkg-reconfigure --frontend noninteractive locales"
# Set default timezone to Asia/Shanghai
sudo chroot "$CHROOT_TARGET" sh -c "ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime"
echo "Asia/Shanghai" | sudo tee $CHROOT_TARGET/etc/timezone
# Set up fstab
echo '/dev/mmcblk2p6 / auto defaults 1 1' | sudo tee -a $CHROOT_TARGET/etc/fstab
echo '/dev/mmcblk2p5 /boot auto defaults 0 0' | sudo tee -a $CHROOT_TARGET/etc/fstab
# Add user
sudo chroot "$CHROOT_TARGET" sh -c "useradd -m -s /bin/bash -G adm,cdrom,floppy,sudo,input,audio,dip,video,plugdev,netdev,bluetooth,lp debian"
sudo chroot "$CHROOT_TARGET" sh -c "echo 'debian:debian' | chpasswd"
# Install kernel
cp -v ${GITHUB_WORKSPACE}/output/*.deb "$CHROOT_TARGET/tmp/"
sudo chroot "$CHROOT_TARGET" sh -c "dpkg -i /tmp/*.deb"
# Add update-u-boot config
sudo cp -v config/u-boot $CHROOT_TARGET/etc/default/u-boot
# Update extlinux config
sudo chroot "$CHROOT_TARGET" sh -c "u-boot-update"
# Change hostname
echo debian-k1 | sudo tee $CHROOT_TARGET/etc/hostname
echo "127.0.1.1 debian-k1" | sudo tee -a $CHROOT_TARGET/etc/hosts
# install ssh
sudo chroot "$CHROOT_TARGET" sh -c "apt update && apt install -y ssh"
# cleanup kernel
sudo rm -rf "$CHROOT_TARGET"/root/*.deb
# Clean up
sudo umount -l "$CHROOT_TARGET"
# move img to output
mv -v "$BOOT_IMG" "$ROOT_IMG" ${GITHUB_WORKSPACE}/output/
- name: genimage-sdcard
run: |
export SD_TARGET=${GITHUB_WORKSPACE}/config/genimage.cfg
export LOOP_DEVICE="/dev/loop100"
export SD_NAME=debian-k1-sdcard.img
export CHROOT_TARGET=${GITHUB_WORKSPACE}/rootfs
pushd ${GITHUB_WORKSPACE}/output
genimage --config ${SD_TARGET} \
--inputpath $(pwd) \
--outputpath $(pwd) \
--rootpath="$(mktemp -d)"
# cp -v *.img ${GITHUB_WORKSPACE}/output/
sudo losetup -P "${LOOP_DEVICE}" ${SD_NAME}
sudo mount "${LOOP_DEVICE}"p6 $CHROOT_TARGET
sudo mount "${LOOP_DEVICE}"p5 $CHROOT_TARGET/boot
sudo sed -i "s/mmcblk2/mmcblk0/g" $CHROOT_TARGET/etc/fstab
sudo sed -i "s/mmcblk2/mmcblk0/g" $CHROOT_TARGET/etc/default/u-boot
sudo sed -i "s/mmcblk2/mmcblk0/g" $CHROOT_TARGET/boot/extlinux/extlinux.conf
sudo umount -l $CHROOT_TARGET
sudo losetup -d "${LOOP_DEVICE}"
popd
tree ${GITHUB_WORKSPACE}/output
- name: 'Upload sdcard img'
uses: actions/upload-artifact@v4
with:
name: k1-img-sdcard
path: output/debian-k1-sdcard.img
retention-days: 30
- name: Copy other file
run: |
cp -vf ${GITHUB_WORKSPACE}/config/partition_universal.json ${GITHUB_WORKSPACE}/output/
- name: Clean up
run: |
rm -rf ${GITHUB_WORKSPACE}/output/*.deb
rm -rf ${GITHUB_WORKSPACE}/output/debian-k1-sdcard.img
- name: 'Upload emmc img'
uses: actions/upload-artifact@v4
with:
name: k1-img-emmc
path: output/*
retention-days: 30