Skip to content

Commit 52574b5

Browse files
authored
Merge pull request #5 from lool/image-gen
Generate images for 512B and 4096B sector sizes
2 parents 24f3168 + 06c54bf commit 52574b5

File tree

5 files changed

+155
-192
lines changed

5 files changed

+155
-192
lines changed

.github/workflows/debos.yml

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -62,43 +62,46 @@ jobs:
6262
# operating system from the github runner one; install debos
6363
- name: Setup build environment
6464
run: |
65-
set -x
66-
# privileged container as debos will use mounts
67-
sudo incus init "${INCUS_IMAGE}" "${INCUS_NAME}" \
68-
-c security.privileged=true -c security.nesting=true
69-
sudo incus start "${INCUS_NAME}"
70-
# wait for network to be up (prior to running apt)
71-
sudo incus exec "${INCUS_NAME}" \
65+
set -x
66+
# privileged container as debos will use mounts
67+
sudo incus init "${INCUS_IMAGE}" "${INCUS_NAME}" \
68+
-c security.privileged=true -c security.nesting=true
69+
sudo incus start "${INCUS_NAME}"
70+
# wait for network to be up (prior to running apt)
71+
sudo incus exec "${INCUS_NAME}" \
7272
/usr/lib/systemd/systemd-networkd-wait-online
73-
(
74-
# these commands are run inside the container
75-
cat <<EOF
76-
apt update
77-
apt -y upgrade
78-
apt -y full-upgrade
79-
apt -y install debos
80-
EOF
81-
) | sudo incus exec "${INCUS_NAME}" -- sh
73+
74+
# commands are piped to be run inside the container
75+
sudo incus exec "${INCUS_NAME}" -- sh -e -x <<EOF
76+
apt update
77+
apt -y upgrade
78+
apt -y full-upgrade
79+
apt -y install debos
80+
EOF
8281
8382
- name: Build debos recipe
8483
run: |
8584
set -x
8685
# mount current directory under /build
8786
sudo incus config device add "${INCUS_NAME}" build-dir \
8887
disk "source=${PWD}" path=/build shift=true
89-
(
90-
# these commands are run inside the container
91-
cat <<EOF
92-
cd /build
93-
# debos tries KVM and UML as backends, and falls back to building
94-
# directly on the host, but that requires loop devices; use
95-
# qemu backend explicitly even if it's slower
96-
# qemu backend also requires to set scratchsize, otherwise
97-
# the whole build is done from memory and the out of memory
98-
# killer gets triggered
99-
debos -b qemu --scratchsize 4GiB qualcomm-linux-debian.yaml
88+
89+
# commands are piped to be run inside the container
90+
sudo incus exec "${INCUS_NAME}" -- sh -e -x <<EOF
91+
cd /build
92+
# start by building the root filesystem
93+
debos qualcomm-linux-debian-rootfs.yaml
94+
# debos tries KVM and UML as backends, and falls back to
95+
# building directly on the host, but that requires loop
96+
# devices; use qemu backend explicitly even if it's slower
97+
# qemu backend also requires to set scratchsize, otherwise the
98+
# whole build is done from memory and the out of memory killer
99+
# gets triggered
100+
debos -b qemu --scratchsize 4GiB -t imagetype:ufs \
101+
qualcomm-linux-debian-image.yaml
102+
debos -b qemu --scratchsize 4GiB -t imagetype:sdcard \
103+
qualcomm-linux-debian-image.yaml
100104
EOF
101-
) | sudo incus exec "${INCUS_NAME}" -- sh
102105
103106
- name: Upload artifacts to fileserver
104107
run: |
@@ -113,7 +116,8 @@ jobs:
113116
dir="${FILESERVER_DIR}/${id}"
114117
mkdir -vp "${dir}"
115118
# copy output files
116-
cp -v disk.img "${dir}"
119+
cp -v disk-ufs.img.gz "${dir}"
120+
cp -v disk-sdcard.img.gz "${dir}"
117121
# instruct fileserver to publish this directory
118122
url="${FILESERVER_URL}/${id}/"
119123
curl -X POST -H 'Accept: text/event-stream' "${url}"

README.md

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,19 @@ main: Primary development branch. Contributors should develop submissions based
1313
## Requirements
1414

1515
[debos](https://github.com/go-debos/debos) is required to build the debos recipes. Recent debos packages should be available in Debian and Ubuntu repositories; there are
16-
[debos installation instructions](https://github.com/go-debos/debos?tab=readme-ov-file#installation-from-source-under-debian) on the project's page, notably for Docker images and to build debos from source.
16+
[debos installation instructions](https://github.com/go-debos/debos?tab=readme-ov-file#installation-from-source-under-debian) on the project's page, notably for Docker images and to build debos from source. Make sure to use at least version 1.1.5 which supports setting the sector size.
1717

1818
[qdl](https://github.com/linux-msm/qdl) is typically used for flashing. While recent versions are available in Debian and Ubuntu, make sure you have at least version 2.1 as it contains important fixes.
1919

2020
## Usage
2121

2222
To build a disk image, run debos as follows:
2323
```bash
24-
debos debos-recipes/qualcomm-linux-debian.yaml
24+
# build a root filesystem tarball
25+
debos debos-recipes/qualcomm-linux-debian-rootfs.yaml
26+
27+
# build a disk image from the root filesystem
28+
debos debos-recipes/qualcomm-linux-debian-image.yaml
2529
```
2630

2731
### Build backends
@@ -30,21 +34,25 @@ By default, debos will try to pick a fast build backend; it will try to use its
3034

3135
To build large images, the debos resource defaults might not be sufficient. Consider raising the default debos memory and scratchsize settings. This should provide a good set of minimum defaults:
3236
```bash
33-
debos --fakemachine-backend qemu --memory 1GiB --scratchsize 4GiB debos-recipes/qualcomm-linux-debian.yaml
37+
debos --fakemachine-backend qemu --memory 1GiB --scratchsize 4GiB debos-recipes/qualcomm-linux-debian-image.yaml
3438
```
3539

3640
### Build options
3741

38-
A few options are provided in the debos recipe:
39-
- image: set the output disk image filename; default: `disk.img`
40-
- imagesize: set the output disk image size; default: `4GiB`
41-
- dtb: override the firmware provided device tree with one from the linux kernel, e.g. `qcom/qcs6490-rb3gen2.dtb`; default: don't override
42-
- xfcedesktop: install a Xfce desktop environment; default: console only environment
42+
A few options are provided in the debos recipes; for the root filesystem recipe:
4343
- experimentalkernel: update the linux kernel to the version from experimental; default: don't update the kernel
44+
- xfcedesktop: install a Xfce desktop environment; default: console only environment
45+
46+
For the image recipe:
47+
- dtb: override the firmware provided device tree with one from the linux kernel, e.g. `qcom/qcs6490-rb3gen2.dtb`; default: don't override
48+
- imagetype: either `ufs` (the default) or (`sdcard`); UFS uses 4096 bytes sectors and SD card 512 bytes
49+
- image: set the output disk image filename; default is to suffix it with the imagetype: `disk-ufs.img`
50+
- imagesize: set the output disk image size; default: `4GiB`
4451

4552
These can be passed as follows:
4653
```bash
47-
debos -t dtb:qcom/qcs6490-rb3gen2.dtb -t xfcedesktop:true -t experimentalkernel:true debos-recipes/qualcomm-linux-debian.yaml
54+
debos -t xfcedesktop:true -t experimentalkernel:true debos-recipes/qualcomm-linux-debian-rootfs.yaml
55+
debos -t dtb:qcom/qcs6490-rb3gen2.dtb debos-recipes/qualcomm-linux-debian-image.yaml
4856
```
4957

5058
## Flashing Instructions
@@ -54,16 +62,12 @@ Once a disk image is created, it is suitable for putting on an SD card, albeit m
5462

5563
These images don't currently ambition to provide early boot assets such as boot firmware or data for other partitions containing board specific configuration or coprocessor firmware. Instead, start by provisioning an image with these early boot assets, such as the Yocto-based Qualcomm Linux images, and then flashing a debos generated image on top. Standalone, ready to flash (but probably not Debian based) images of the boot assets are planned to be made available publicly – stay tuned!
5664

57-
Depending on the target board and target boot media, it's also necessary to use the right sector size for the image: typically 512B vs 4096B. SD cards and eMMC typically use the historical 512B sector size, while UFS storage uses 4096B sector size. debos has just gained support for configurable sector sizes, but that requires building it from source; alernatively, you can post-process the image with a conversation script as explained below.
65+
Depending on the target board and target boot media, it's also necessary to use the right sector size for the image: typically 512B vs 4096B. SD cards and eMMC typically use the historical 512B sector size, while UFS storage uses 4096B sector size. debos has gained support for configurable sector sizes in version 1.1.5.
5866

5967
### RB3 Gen2 instructions
6068

6169
The RB3 Gen2 board boots from UFS by default. To flash a disk image to the UFS storage of the RB3 Gen2 board:
6270
1. provision some known good early boot assets by flashing the Yocto edition of [Qualcomm Linux](https://www.qualcomm.com/developer/software/qualcomm-linux)
63-
1. unless you've got a recent debos that supports creating images with a 4096B sector size, convert the debos disk image from 512B to 4096B sector sizes; this sample script can be used as a workaround until [debos gains support for setting the sector size](https://github.com/go-debos/debos/issues/537) but it's a britle approach which requires root, the workaround script is also full of hardcoded expectations and might need local tweaks:
64-
```bash
65-
sudo scripts/workaround-convert-sector-size disk.img disk-4096.img 4096
66-
```
6771
1. create a `rawprogram-ufs.xml` file instructing QDL to flash to the first UFS LUN (LUN0):
6872
```xml
6973
<?xml version="1.0" ?>
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
{{- $dtb := or .dtb "firmware" }}
2+
{{- $imagesize := or .imagesize "4GiB" }}
3+
{{- $imagetype := or .imagetype "ufs" }}
4+
{{- $image := or .image (printf "disk-%s.img" $imagetype) }}
5+
6+
architecture: arm64
7+
sectorsize: {{if eq $imagetype "ufs"}} 4096 {{else}} 512 {{end}}
8+
9+
actions:
10+
- action: unpack
11+
description: Unpack root filesystem
12+
compression: gz
13+
file: rootfs.tar.gz
14+
15+
{{- if ne $dtb "firmware" }}
16+
- action: run
17+
description: Use OS device tree override (board specific)
18+
chroot: true
19+
command: |
20+
set -eu
21+
mkdir -p /etc/kernel
22+
echo {{ $dtb }} >/etc/kernel/devicetree
23+
{{- end }}
24+
25+
# parttype values are from:
26+
# https://www.freedesktop.org/wiki/Specifications/DiscoverablePartitionsSpec/
27+
- action: image-partition
28+
description: Create an image file
29+
imagename: {{ $image }}
30+
imagesize: {{ $imagesize }}
31+
partitiontype: gpt
32+
partitions:
33+
- name: esp
34+
partlabel: ESP
35+
flags: [ boot, esp ]
36+
# EFI System Partition
37+
parttype: c12a7328-f81f-11d2-ba4b-00a0c93ec93b
38+
fs: vfat
39+
start: 4MiB
40+
# size of 512MiB
41+
end: 516MiB
42+
fsck: true
43+
- name: root
44+
# Root Partition (64-bit ARM/AArch64)
45+
parttype: b921b045-1df0-41c3-af44-4c6f280d3fae
46+
fs: ext4
47+
# 4MiB after ESP
48+
start: 520MiB
49+
end: 100%
50+
fsck: true
51+
mountpoints:
52+
- mountpoint: /boot/efi/
53+
partition: esp
54+
- mountpoint: /
55+
partition: root
56+
57+
# XXX these kernel options might be specific to a kernel version or board
58+
- action: filesystem-deploy
59+
setup-fstab: true
60+
append-kernel-cmdline: clk_ignore_unused pd_ignore_unused audit=0 deferred_probe_timeout=30
61+
62+
- action: apt
63+
recommends: true
64+
description: Make system bootable with systemd-boot
65+
packages:
66+
- systemd-boot
67+
# TODO investigate why systemd-boot Recommends: shim-signed which
68+
# Depends on grub packages
69+
- shim-signed-
70+
71+
- action: run
72+
description: Create task to grow root filesystem on first boot
73+
chroot: true
74+
command: |
75+
set -eu
76+
# for growpart
77+
apt -y install cloud-guest-utils
78+
# extract the dev of the root filesystem from fstab; change UUID=id into
79+
# /dev/disk/by-uuid/id
80+
ROOTFS_DEV=$(
81+
awk '$2 == "/" {gsub("UUID=", "/dev/disk/by-uuid/"); print $1}' \
82+
/etc/fstab
83+
)
84+
# generate systemd unit to grow the second partition with above UUID
85+
cat >/etc/systemd/system/debos-grow-rootfs.service <<EOF
86+
[Unit]
87+
Description=Grow root partition and filesystem (debos)
88+
[Service]
89+
Type=oneshot
90+
ExecStartPre=-sh -c 'growpart /dev/\`lsblk -n -o pkname $ROOTFS_DEV\` 2'
91+
ExecStart=resize2fs $ROOTFS_DEV
92+
[Install]
93+
WantedBy=default.target
94+
EOF
95+
# enable unit
96+
systemctl enable debos-grow-rootfs
97+
98+
- action: run
99+
postprocess: true
100+
command: gzip -f "${ARTIFACTDIR}/{{ $image }}"
101+

debos-recipes/qualcomm-linux-debian.yaml renamed to debos-recipes/qualcomm-linux-debian-rootfs.yaml

Lines changed: 3 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
{{- $image := or .image "disk.img" }}
2-
{{- $imagesize := or .imagesize "4GiB" }}
3-
{{- $dtb := or .dtb "firmware" }}
41
{{- $xfcedesktop := or .xfcedesktop "false" }}
52
{{- $experimentalkernel := or .experimentalkernel "false" }}
63

@@ -154,16 +151,6 @@ actions:
154151
update-locale LANG=en_US.UTF-8
155152
fi
156153
157-
{{- if ne $dtb "firmware" }}
158-
- action: run
159-
description: Use OS device tree override (board specific)
160-
chroot: true
161-
command: |
162-
set -eu
163-
mkdir -p /etc/kernel
164-
echo {{ $dtb }} >/etc/kernel/devicetree
165-
{{- end }}
166-
167154
- action: apt
168155
description: Install kernel and firmware packages
169156
recommends: true
@@ -197,76 +184,7 @@ actions:
197184
/etc/apt/sources.list.d/debian-experimental.sources
198185
{{- end }}
199186

200-
# parttype values are from:
201-
# https://www.freedesktop.org/wiki/Specifications/DiscoverablePartitionsSpec/
202-
- action: image-partition
203-
description: Create an image file
204-
imagename: {{ $image }}
205-
imagesize: {{ $imagesize }}
206-
partitiontype: gpt
207-
partitions:
208-
- name: esp
209-
partlabel: ESP
210-
flags: [ boot, esp ]
211-
# EFI System Partition
212-
parttype: c12a7328-f81f-11d2-ba4b-00a0c93ec93b
213-
fs: vfat
214-
start: 4MiB
215-
# size of 512MiB
216-
end: 516MiB
217-
fsck: true
218-
- name: root
219-
# Root Partition (64-bit ARM/AArch64)
220-
parttype: b921b045-1df0-41c3-af44-4c6f280d3fae
221-
fs: ext4
222-
# 4MiB after ESP
223-
start: 520MiB
224-
end: 100%
225-
fsck: true
226-
mountpoints:
227-
- mountpoint: /boot/efi/
228-
partition: esp
229-
- mountpoint: /
230-
partition: root
231-
232-
# XXX these kernel options might be specific to a kernel version or board
233-
- action: filesystem-deploy
234-
setup-fstab: true
235-
append-kernel-cmdline: clk_ignore_unused pd_ignore_unused audit=0 deferred_probe_timeout=30
236-
237-
- action: apt
238-
recommends: true
239-
description: Make system bootable with systemd-boot
240-
packages:
241-
- systemd-boot
242-
# TODO investigate why systemd-boot Recommends: shim-signed which
243-
# Depends on grub packages
244-
- shim-signed-
245-
246-
- action: run
247-
description: Create task to grow root filesystem on first boot
248-
chroot: true
249-
command: |
250-
set -eu
251-
# for growpart
252-
apt -y install cloud-guest-utils
253-
# extract the dev of the root filesystem from fstab; change UUID=id into
254-
# /dev/disk/by-uuid/id
255-
ROOTFS_DEV=$(
256-
awk '$2 == "/" {gsub("UUID=", "/dev/disk/by-uuid/"); print $1}' \
257-
/etc/fstab
258-
)
259-
# generate systemd unit to grow the second partition with above UUID
260-
cat >/etc/systemd/system/debos-grow-rootfs.service <<EOF
261-
[Unit]
262-
Description=Grow root partition and filesystem (debos)
263-
[Service]
264-
Type=oneshot
265-
ExecStartPre=-sh -c 'growpart /dev/\`lsblk -n -o pkname $ROOTFS_DEV\` 2'
266-
ExecStart=resize2fs $ROOTFS_DEV
267-
[Install]
268-
WantedBy=default.target
269-
EOF
270-
# enable unit
271-
systemctl enable debos-grow-rootfs
187+
- action: pack
188+
file: rootfs.tar.gz
189+
compression: gz
272190

0 commit comments

Comments
 (0)