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..3df98bb --- /dev/null +++ b/Dockerfile @@ -0,0 +1,17 @@ +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 . /LonganPi-3H-SDK + +WORKDIR /LonganPi-3H-SDK/ +RUN chmod +x *.sh + +ENTRYPOINT [ "make" ] diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..adc53f7 --- /dev/null +++ b/Makefile @@ -0,0 +1,82 @@ +# 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 meant to be run inside the container have the suffix .base, .img and .files + +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/ + 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/ 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 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