From be3dfd89b470e2d4c787a618457403f618f6eb28 Mon Sep 17 00:00:00 2001 From: chriswue Date: Tue, 7 May 2024 08:16:48 +1200 Subject: [PATCH 1/5] Improve Linux tree clone speed No need to clone the entire repo. Just a shallow fetch of the specific sha is sufficient. --- mklinux.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/mklinux.sh b/mklinux.sh index 750a874..e591e40 100755 --- a/mklinux.sh +++ b/mklinux.sh @@ -26,9 +26,12 @@ set -eux if [ ! -e build/linux ] then - git clone $URL build/linux --branch=${BRANCH} + mkdir -p build/linux cd build/linux - git checkout 3b47bc037bd44f142ac09848e8d3ecccc726be99 + git init + git remote add origin $URL + git fetch --depth 1 origin 3b47bc037bd44f142ac09848e8d3ecccc726be99 + git checkout FETCH_HEAD find ../../linux/ -name *.patch | sort | while read line do git am < $line From f5059eab17ac60a811067d0d38c3ff09cc78dc95 Mon Sep 17 00:00:00 2001 From: chriswue Date: Fri, 10 May 2024 10:10:04 +1200 Subject: [PATCH 2/5] Create docker build setup (#1) dockerize the build --- .dockerignore | 1 + .gitignore | 1 + Dockerfile | 20 ++++++++++++ Makefile | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 49 ++++++++++++++++++++++++++++++ 5 files changed, 155 insertions(+) create mode 100644 .dockerignore create mode 100644 .gitignore create mode 100644 Dockerfile create mode 100644 Makefile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..466e248 --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +out/ \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..466e248 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +out/ \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..9cca5ad --- /dev/null +++ b/Dockerfile @@ -0,0 +1,20 @@ +FROM ubuntu:22.04 + +RUN apt update && apt install -y \ + gcc-aarch64-linux-gnu mmdebstrap git binfmt-support make build-essential bc \ + kmod bison flex gcc libncurses-dev debian-archive-keyring swig libssl-dev \ + python3-setuptools python3-dev qemu-user-static fdisk util-linux jq dosfstools + +# stop git from complaining +RUN git config --global user.email "pi3h@container.local" +RUN git config --global user.name "Local Container Build" + +ADD ./certs/* /usr/local/share/ca-certificates +RUN update-ca-certificates + +ADD . /LonganPi-3H-SDK + +WORKDIR /LonganPi-3H-SDK/ +RUN chmod +x *.sh + +ENTRYPOINT [ "make" ] \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..8449e47 --- /dev/null +++ b/Makefile @@ -0,0 +1,84 @@ +# This is a hybrid Makefile - it is meant run on the host to kick-off the docker container build +# but it's also used inside the container to perform the actual build steps. +# The make targets that are meatn to be run inside the container have the suffix "incontainer" + +TAG := longanpi3h-build:latest +OUTPUT_DIR := /LonganPi-3H-SDK/out +#OUTPUT_DIR := out + +OUTPUT_TARGETS := debian-cli debian-gui ubuntu-cli +OUTPUT_TARGETS_IMG := $(addsuffix -img,${OUTPUT_TARGETS}) + +# Targets that are meant to be run on the host +build: + mkdir -p out/ + mkdir -p certs + cp /usr/local/share/ca-certificates/* certs/ + docker build --progress=plain -t ${TAG} . + +${OUTPUT_TARGETS}: build + docker run --rm -v $(shell pwd)/out:${OUTPUT_DIR} --privileged ${TAG} $@.files + +${OUTPUT_TARGETS_IMG}: build + docker run --rm -v $(shell pwd)/out:${OUTPUT_DIR} --privileged ${TAG} $(patsubst %-img,%.img,$@) + +# Targets that are meant to be run inside the container +base-internal: + update-binfmts --enable + ./mkatf.sh + ./mkuboot.sh + ./mklinux.sh + +%.base: base-internal + ./mkrootfs-$(basename $@).sh + +%.files: %.base + cp build/rootfs* ${OUTPUT_DIR} + cp build/u-boot* ${OUTPUT_DIR} + mkdir -p ${OUTPUT_DIR}/boot + cp -r overlay/boot/* ${OUTPUT_DIR}/boot + +.ONESHELL: +%.img: %.base + $(eval OUTFILE := build/LPI3H_$(patsubst %.img,%,$@)_$(shell date +%Y%m%d).img) + @echo Creating image file + @dd if=/dev/zero of=${OUTFILE} bs=1M count=3072 + @echo Creating image file partitions + @printf '%s\n' ',+64M,c;' ',,;' | sfdisk --wipe always --label dos ${OUTFILE} + @PARTS=$$(sfdisk -J ${OUTFILE}) + @P1START=$$(echo $$PARTS | jq '.partitiontable.partitions[0].start*512') + @P1LIMIT=$$(echo $$PARTS | jq '.partitiontable.partitions[0].size*512') + @P2START=$$(echo $$PARTS | jq '.partitiontable.partitions[1].start*512') + @P2LIMIT=$$(echo $$PARTS | jq '.partitiontable.partitions[1].size*512') + @echo Mounting image file as loop device + @LO_IMG=$$(losetup --show -f ${OUTFILE}) + @LO_P1=$$(losetup --show -o $$P1START --sizelimit $$P1LIMIT -f ${OUTFILE}) + @LO_P2=$$(losetup --show -o $$P2START --sizelimit $$P2LIMIT -f ${OUTFILE}) + @echo Creating boot FS + @mkfs -t vfat $$LO_P1 + @echo Creating root FS + @mkfs -t ext4 $$LO_P2 + @echo Flashing u-boot + @dd if=build/u-boot-sunxi-with-spl.bin of=$$LO_IMG bs=1k seek=8 conv=fsync + @echo Mounting boot partition + @mkdir -p build/tmp/kernel + @mount $$LO_P1 build/tmp/kernel + @echo Copying kernel files to boot partition + @cp -r overlay/boot/* build/tmp/kernel + @echo Unmounting boot parition + @umount $$LO_P1 + @echo Mounting root partition + @mkdir -p build/tmp/rootfs + @mount $$LO_P2 build/tmp/rootfs + @echo Copying root-fs files to root partition + @tar -xf build/rootfs-$(patsubst %.img,%,$@).tar -C build/tmp/rootfs/ + @echo Unmounting root partition + @umount $$LO_P2 + @losetup -d $$LO_P1 + @losetup -d $$LO_P2 + @losetup -d $$LO_IMG + @echo Copying image file to ${OUTPUT_DIR} + @cp ${OUTFILE} ${OUTPUT_DIR} + +clean: + rm -rf out/ \ No newline at end of file diff --git a/README.md b/README.md index 1e48a32..cb0445d 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,13 @@ +# Table of Contents + +[TOC] + # LonganPi-3H-SDK Scripts and blobs for LonganPi 3H image build. > Tested on Ubuntu 22.04.2 LTS and WSL2 Ubuntu-22.04 +## Command Line Build + 0. Install some dependencies ```shell sudo apt update @@ -36,3 +42,46 @@ sudo ./mkrootfs-debian-gui.sh # sudo ./mkrootfs-ubuntu-cli.sh ``` +## Docker build + +**Note:** The container to execute the actual image build is run with the `--privileged` flag (due to `quemu` usage). If you cannot run privileged containers in your environment then the docker build will most likely not work for you. + +If you have `make` and `docker` installed you can also build the image with docker. The `Makefile` has two utility targets and two main group of targets that you can run. An `out/` folder will be created which is mounted into the container and the output files will be copied in there. + +### Utility Targets + +```shell +# Just build the build-container +make build + +# remove the out/ directory +make clean +``` + +### Targets to build the root FS and boot files + +```shell +# Build Debian desktop root FS +make debian-gui + +# Build Debian root FS without gui +make debian-cli + +# Build Ubuntu root FS without gui +make ubuntu-cli +``` + +### Targets to build the full image + +```shell +# Build Debian desktop image +make debian-gui-img + +# Build Debian image without gui +make debian-cli-img + +# Build Ubuntu image without gui +make ubuntu-cli-img +``` + +From there you can follow https://wiki.sipeed.com/hardware/en/longan/h618/lpi3h/7_develop_mainline.html to create a boot card. \ No newline at end of file From abe12ce204c41a42d14ec1c368bf431e14e1ec4c Mon Sep 17 00:00:00 2001 From: chriswue Date: Fri, 10 May 2024 10:16:20 +1200 Subject: [PATCH 3/5] Update Dockerfile remove custom cert stuff --- Dockerfile | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 9cca5ad..3df98bb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,12 +9,9 @@ RUN apt update && apt install -y \ RUN git config --global user.email "pi3h@container.local" RUN git config --global user.name "Local Container Build" -ADD ./certs/* /usr/local/share/ca-certificates -RUN update-ca-certificates - ADD . /LonganPi-3H-SDK WORKDIR /LonganPi-3H-SDK/ RUN chmod +x *.sh -ENTRYPOINT [ "make" ] \ No newline at end of file +ENTRYPOINT [ "make" ] From 23b64a349960ae17e9b6fb795f22eeea6f5a2703 Mon Sep 17 00:00:00 2001 From: chriswue Date: Fri, 10 May 2024 10:16:47 +1200 Subject: [PATCH 4/5] Update Makefile remove custom cert stuff --- Makefile | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 8449e47..07a0faf 100644 --- a/Makefile +++ b/Makefile @@ -12,8 +12,6 @@ OUTPUT_TARGETS_IMG := $(addsuffix -img,${OUTPUT_TARGETS}) # Targets that are meant to be run on the host build: mkdir -p out/ - mkdir -p certs - cp /usr/local/share/ca-certificates/* certs/ docker build --progress=plain -t ${TAG} . ${OUTPUT_TARGETS}: build @@ -81,4 +79,4 @@ base-internal: @cp ${OUTFILE} ${OUTPUT_DIR} clean: - rm -rf out/ \ No newline at end of file + rm -rf out/ From 0a98c5e762f7c17e417c93c557791a3daf010ed4 Mon Sep 17 00:00:00 2001 From: chriswue Date: Fri, 10 May 2024 10:18:22 +1200 Subject: [PATCH 5/5] Update Makefile fix comment --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 07a0faf..adc53f7 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ -# This is a hybrid Makefile - it is meant run on the host to kick-off the docker container build +# This is a hybrid Makefile - it is meant run on the host to kick-off the docker container build, # but it's also used inside the container to perform the actual build steps. -# The make targets that are meatn to be run inside the container have the suffix "incontainer" +# The make targets that are meant to be run inside the container have the suffix .base, .img and .files TAG := longanpi3h-build:latest OUTPUT_DIR := /LonganPi-3H-SDK/out