Skip to content

Commit

Permalink
add kerenl build
Browse files Browse the repository at this point in the history
Signed-off-by: Bo YU <tsu.yubo@gmail.com>
  • Loading branch information
yuzibo committed Dec 17, 2023
1 parent a342c45 commit 390c79f
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 24 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Set up Git
run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*

- name: Get tag name
run: echo "Tag name is ${{ github.ref_name }}"

- name: "Update APT sources"
run: |
sudo apt update
Expand All @@ -29,7 +35,7 @@ jobs:
- name: Create vf2 rootfs
run: |
export DOCKER_BUILDKIT=1 COMPOSE_DOCKER_CLI_BUILD=1 vf2
docker-compose up vf2
KERNEL_VERSION=${{ github.ref_name }} docker-compose up vf2
ls -l image/*
- name: Release
uses: softprops/action-gh-release@v1
Expand Down
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
FROM debian:sid as builder
MAINTAINER Bo YU "tsu.yubo@gmail.com"

ENV KERNEL_VERSION=${KERNEL_VERSION}

ARG DEBIAN_FRONTEND=noninteractive

RUN --mount=type=cache,sharing=shared,target=/var/cache \
Expand Down Expand Up @@ -40,5 +42,5 @@ COPY --from=build_rootfs /build/rv64-sid/ ./rv64-port/
COPY create_image.sh build.sh ./
COPY rootfs/setup_rootfs.sh ./rv64-port/

CMD eatmydata /builder/build.sh
CMD eatmydata /builder/build.sh ${KERNEL_VERSION}

10 changes: 10 additions & 0 deletions Not-Use-Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
unmatched:
sudo rm -rf ./image/*
DOCKER_BUILDKIT=1 docker-compose build vf2
docker-compose up vf2


clean:
sudo rm -rf ./image/*
DOCKER_BUILDKIT=1 docker-compose build --no-cache
docker-compose up
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ sudo apt install -y qemu-user-static qemu-system qemu-utils qemu-system-misc bin
Need docker docker-compose installed, then type:
```bash
sudo DOCKER_BUILDKIT=1 docker-compose build vf2
sudo docker-compose up vf2
```
Or:
```bash
sudo make unmatched

# need kernel tag from
# https://github.com/yuzibo/vf2-linux/tags
sudo KERNEL_VERSION=vf2-v6.6.7-v1 docker-compose up vf2
```

Please note, any modify need to be done with step one.

Two image files will be generated into `image`:

```bash
Expand Down
4 changes: 3 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/sh

./create_image.sh /outport
KERNEL_VERSION="$1"

./create_image.sh /outport ${KERNEL_VERSION}
25 changes: 21 additions & 4 deletions create_image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

# It woule be good to test it outside of Docker
OUT_DIR="$1"
KERNEL_VERSION="$2"

ROOTFS_IMG="${OUT_DIR}/vf2-rootfs.img"
SD_DD_OPTS="bs=4k iflag=fullblock oflag=direct conv=fsync status=progress"
Expand Down Expand Up @@ -48,13 +49,29 @@ function make_image(){
kpartx -d ${ROOTFS_IMG}
}

function get_kernel_deb(){
vf2_image_repo="https://github.com/yuzibo/vf2-linux"
kernel_deb_url="${vf2_image_repo}/releases/download/${KERNEL_VERSION}/vf2-mainline-kernel-gcc-13.tar.gz"

wget --no-check-certificate ${kernel_deb_url}

tar -zxvf vf2-mainline-kernel-gcc-13.tar.gz -C /tmp

}

function copy_rootfs(){


echo "copy rootfs"
# from docker image has been defined
cp -a /builder/rv64-port/* "${ROOTFS_POINT}"
cp -av /builder/rv64-port/* "${ROOTFS_POINT}"

# Copy the rootfs
cp /usr/bin/qemu-riscv64-static ${ROOTFS_POINT}/usr/bin/
cp -v /usr/bin/qemu-riscv64-static ${ROOTFS_POINT}/usr/bin/

# should judge deb if exist
get_kernel_deb

cp -v /tmp/vf2_kernel_deb/*.deb ${ROOTFS_POINT}/tmp
chroot "${ROOTFS_POINT}" qemu-riscv64-static /bin/sh /setup_rootfs.sh
rm "${ROOTFS_POINT}/setup_rootfs.sh" "${ROOTFS_POINT}/usr/bin/qemu-riscv64-static"

Expand All @@ -67,7 +84,7 @@ function copy_rootfs(){
make_image

if [ $? -eq 0 ]; then
echo "make_immge executed successfully."
echo "make_image executed successfully."
# Now compress the image
echo "Compressing the image: ${ROOTFS_IMG}"
cd "${OUT_DIR}" && xz -T0 "${ROOTFS_IMG}"
Expand Down
3 changes: 3 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ services:
# build host dir with docker dir
volumes:
- './image:/outport'
# vf2 kernel passed here
environment:
- KERNEL_VERSION=${KERNEL_VERSION}
62 changes: 50 additions & 12 deletions rootfs/setup_rootfs.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/sh
#
set -ex

export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true
export LC_ALL=C LANGUAGE=C LANG=C
Expand Down Expand Up @@ -33,19 +34,62 @@ chown debian:debian /home/debian
# Set password to 'debian'
usermod --password "$(echo debian | openssl passwd -1 -stdin)" debian

# update-initramfs -u
#rm /boot/initrd*
# Set up fstab
cat > /etc/fstab <<EOF
# <file system> <mount point> <type> <options> <dump> <pass>
/dev/mmcblk1p2 /boot/efi vfat umask=0077 0 1
EOF

apt install -f /tmp/*.deb

# change device tree
echo "===== ln -s dtb files ====="
file_prefix="/usr/lib/linux-image-*"

file_path=$(ls -d $file_prefix)

if [ -e "$file_path" ]; then
echo "File found: $file_path"
lib_dir=$file_path
else
echo "File not found: $file_path"
fi

kernel_image=${lib_dir##*/}

cd ${lib_dir}/starfive/
ln -s jh7110-starfive-visionfive-2-v1.2a.dtb jh7110-visionfive-v2.dtb
cd -

#update-initramfs -c -k all
# update u-boot

# cp your latest dtb file,e.g, cp /usr/lib/linux-image-xx-riscv64
# need you confirm it here
apt install u-boot-menu
cat <<EOF >> /etc/default/u-boot
U_BOOT_PARAMETERS="rw console=tty0 console=ttyS0,115200 earlycon rootwait stmmaceth=chain_mode:1 selinux=0"
EOF

dpkg-reconfigure ${kernel_image}

# boot from sd card
sed -i -e 's|append |append root=/dev/mmcblk1p3 |' /boot/extlinux/extlinux.conf

# double check
cat /boot/extlinux/extlinux.conf

# create /boot/efi
mkdir -p /boot/efi

# Set up fstab
cat > /etc/fstab <<EOF
# <file system> <mount point> <type> <options> <dump> <pass>
/dev/mmcblk1p2 /boot/efi vfat umask=0077 0 1
# setup uboot uEnv
cat <<EOF > /boot/uEnv.txt
kernel_comp_addr_r=0xb0000000
kernel_comp_size=0x10000000
EOF



# Set hostname
echo vf2 > /etc/hostname

Expand All @@ -57,13 +101,7 @@ EOF
# Add needed modules in initrd
#echo "nvme" >> /etc/initramfs-tools/modules

# cp your latest dtb file,e.g, cp /usr/lib/linux-image-xx-riscv64
# need you confirm it here
#cp /usr/lib/linux-image-*/sifive/hifive-unmatched-a00.dtb /boot/
#echo U_BOOT_FDT=\"hifive-unmatched-a00.dtb\" >> /etc/default/u-boot
#echo U_BOOT_PARAMETERS=\"rw rootwait console=ttySIF0,115200 earlycon\" >> /etc/default/u-boot

u-boot-update

#
# Enable system services
Expand Down

0 comments on commit 390c79f

Please sign in to comment.