Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support build inside docker container #53

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
out/
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
out/
17 changes: 17 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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 "[email protected]"
RUN git config --global user.name "Local Container Build"

ADD . /LonganPi-3H-SDK

WORKDIR /LonganPi-3H-SDK/
RUN chmod +x *.sh

ENTRYPOINT [ "make" ]
82 changes: 82 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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} [email protected]

${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/
49 changes: 49 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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.
7 changes: 5 additions & 2 deletions mklinux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down