Skip to content

Commit 7b525de

Browse files
authored
Merge pull request #33 from eduble/main
Cross-architecture support using docker and qemu
2 parents 92e9ca3 + e2a6228 commit 7b525de

19 files changed

Lines changed: 622 additions & 494 deletions

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# nanopi-r5
22
#### *Stock Debian ARM64 Linux for the NanoPi R5C & R5S*
33

4-
This stock Debian ARM64 Linux image is built directly from official packages using the Debian [Debootstrap](https://wiki.debian.org/Debootstrap) utility, see: https://github.com/inindev/nanopi-r5/blob/main/debian/nanopi-r5c/make_debian_img.sh#L126
4+
This stock Debian ARM64 Linux image is built directly from official packages using the Debian [Debootstrap](https://wiki.debian.org/Debootstrap) utility, see file `steps/install_rootfs_1st_stage.sh`.
55

6-
Being an unmodified Debian build, patches are directory available from the Debian repos using the stock **apt** package manager, see: https://github.com/inindev/nanopi-r5/blob/main/debian/nanopi-r5c/make_debian_img.sh#L355-L365
6+
Being an unmodified Debian build, patches are directly available from the Debian repos using the stock **apt** package manager, see function `file_apt_sources()` in file `steps/finalize_rootfs.sh`.
77

88
If you want to run true up-stream Debian Linux on your ARM64 device, this is the way to do it.
99

@@ -180,7 +180,8 @@ Note: Once booted, ```sudo apt update``` then ```sudo apt upgrade``` to get the
180180

181181
<br/>
182182

183-
The build script builds native arm64 binaries and thus needs to be run from an arm64 device such as a raspberry pi4 running a 64 bit arm linux. The initial build of this project used a debian arm64 odroid m1, but now uses a nanopi r5s running stock debian bookworm arm64.
183+
The build script uses docker and qemu to build an image compatible with arm64 devices,
184+
even if you run it on a standard x86 machine.
184185

185186
<br/>
186187

@@ -198,7 +199,7 @@ cd nanopi-r5
198199
(R5S) cd debian/nanopi-r5s
199200
sudo sh make_debian_img.sh
200201
```
201-
* note: edit the build script to change various options: ```nano make_debian_img.sh```
202+
* note: edit the script at `debian/env.sh` to change various options: ```nano ../env.sh```
202203

203204
<br/>
204205

debian/.dockerignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
**/mmc_*.img
2+
**/mmc_*.img.xz

debian/Dockerfile

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# -- 1st stage: builder_A, run with host arch
2+
FROM debian:bookworm as builder_A
3+
ARG MODEL
4+
ARG KERNEL_FW_URL
5+
ARG KERNEL_FW_SHA256
6+
ARG RELEASE_URL
7+
WORKDIR /root
8+
ADD env.sh tools.sh ./
9+
COPY common/files files/
10+
RUN mkdir steps
11+
ADD steps/init_builder_A.sh steps/
12+
RUN sh steps/init_builder_A.sh
13+
ADD steps/download.sh steps/
14+
RUN sh steps/download.sh "${KERNEL_FW_URL}" "${KERNEL_FW_SHA256}"
15+
RUN sh steps/download.sh "${RELEASE_URL}/rk3568-nanopi-${MODEL}.dtb"
16+
ADD steps/configure_files.sh steps/
17+
RUN sh steps/configure_files.sh "${MODEL}"
18+
ADD steps/install_firmware.sh steps/
19+
RUN sh steps/install_firmware.sh
20+
ADD steps/install_rootfs_1st_stage.sh steps/
21+
RUN sh steps/install_rootfs_1st_stage.sh
22+
23+
# -- 2nd stage: finalize rootfs, run with arm64 arch transparently emulated by qemu
24+
FROM --platform=linux/arm64/v8 scratch as rootfs_finalizer
25+
COPY --from=builder_A /root/rootfs /
26+
RUN /debootstrap/debootstrap --second-stage
27+
WORKDIR /root
28+
ADD env.sh tools.sh ./
29+
RUN mkdir steps
30+
ADD steps/create_user.sh steps/
31+
RUN sh steps/create_user.sh
32+
RUN rm -rf env.sh tools.sh steps # cleanup
33+
RUN rm -rf /var/cache/* /var/lib/apt/lists/* # discard the cache
34+
35+
# -- 3rd stage: builder_B, run with host arch
36+
FROM debian:bookworm as builder_B
37+
ARG MODEL
38+
ARG PARAMS
39+
ARG RELEASE_URL
40+
COPY --from=rootfs_finalizer / /root/rootfs
41+
WORKDIR /root
42+
COPY nanopi-${MODEL}/files files/
43+
ADD env.sh tools.sh ./
44+
RUN mkdir steps
45+
ADD steps/init_builder_B.sh steps/
46+
RUN sh steps/init_builder_B.sh
47+
ADD steps/download.sh steps/
48+
RUN sh steps/download.sh "${RELEASE_URL}/idbloader-${MODEL}.img"
49+
RUN sh steps/download.sh "${RELEASE_URL}/u-boot-${MODEL}.itb"
50+
ADD steps/finalize_rootfs.sh steps/
51+
RUN sh steps/finalize_rootfs.sh ${MODEL} ${PARAMS}
52+
COPY --from=builder_A /root/fs.uuid /root/
53+
ADD steps/build_image.sh steps/
54+
RUN sh steps/build_image.sh

debian/README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
## stock debian bookworm linux for the nanopi r5c & r5s
22

3-
<i>Note: This script is intended to be run from a 64 bit arm device such as an odroid m1 or a raspberry pi4.</i>
4-
3+
<i>
4+
Note: This script is intended to be run:
5+
* on a Debian machine
6+
* with docker.io package installed
7+
* with qemu-user-static package installed (unless the machine has an ARM64 cpu)
8+
* by a user allowed to use docker (sudo usermod -a -G docker USER)
9+
</i>
510
<br/>
611

712
**build debian bookworm using debootstrap**
@@ -29,7 +34,7 @@ pass: debian
2934

3035
<br/>
3136

32-
**multiple build options are available by editing make_debian_img.sh**
37+
**multiple build options are available by editing debian/env.sh**
3338
```
3439
media='mmc_2g.img' # or block device '/dev/sdX'
3540
deb_dist='bookworm'

0 commit comments

Comments
 (0)