Skip to content

k1-sdcard

k1-sdcard #197

Workflow file for this run

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