Skip to content

Commit ca980ea

Browse files
authored
Merge pull request #14 from lool/flat-images
Recipes: add missing descriptions rootfs: create a tarball with DTBs image: extract partition images flash: new recipe to generate flat images workflows: Generate flashable assets and upload these to fileserver README: update Fixes #10
2 parents aafb0bb + f6403da commit ca980ea

File tree

5 files changed

+221
-31
lines changed

5 files changed

+221
-31
lines changed

.github/workflows/debos.yml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ jobs:
5252
apt update
5353
apt -y upgrade
5454
apt -y full-upgrade
55-
apt -y install debos
55+
# debos is needed to build recipes, mtools is needed for the flash
56+
# recipe
57+
apt -y install debos mtools
5658
5759
- name: Build debos recipe
5860
run: |
@@ -69,6 +71,8 @@ jobs:
6971
qualcomm-linux-debian-image.yaml
7072
debos -b qemu --scratchsize 4GiB -t imagetype:sdcard \
7173
qualcomm-linux-debian-image.yaml
74+
# build flashable files
75+
debos qualcomm-linux-debian-flash.yaml
7276
7377
- name: Upload artifacts to fileserver
7478
run: |
@@ -83,8 +87,11 @@ jobs:
8387
dir="/fileserver-builds/${id}"
8488
mkdir -vp "${dir}"
8589
# copy output files
86-
cp -v disk-ufs.img.gz "${dir}"
87-
cp -v disk-sdcard.img.gz "${dir}"
90+
cp -av rootfs.tar.gz "${dir}"
91+
cp -av dtbs.tar.gz "${dir}"
92+
cp -av disk-ufs.img.gz "${dir}"
93+
cp -av disk-sdcard.img.gz "${dir}"
94+
tar -cvf "${dir}"/flash.tar.gz disk-ufs.img1 disk-ufs.img2 flash_*
8895
# instruct fileserver to publish this directory
8996
url="${FILESERVER_URL}/${id}/"
9097
curl -X POST -H 'Accept: text/event-stream' "${url}"

README.md

Lines changed: 49 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,27 @@ main: Primary development branch. Contributors should develop submissions based
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
1616
[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

18-
[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.
18+
[qdl](https://github.com/linux-msm/qdl) is typically used for flashing. While recent versions are available in Debian and Ubuntu, make sure to use at least version 2.1 as it contains important fixes.
1919

2020
## Usage
2121

22-
To build a disk image, run debos as follows:
22+
To build flashable assets, run debos as follows:
2323
```bash
24-
# build a root filesystem tarball
24+
# build tarballs of the root filesystem and DTBs
2525
debos debos-recipes/qualcomm-linux-debian-rootfs.yaml
2626

27-
# build a disk image from the root filesystem
27+
# build disk and filesystem images from the root filesystem; the default is to
28+
# build an UFS image
2829
debos debos-recipes/qualcomm-linux-debian-image.yaml
30+
31+
# build flashable assets from the DTBs and UFS filesystem images; currently these
32+
# are only built for the RB3 Gen2 Vision Kit board
33+
debos debos-recipes/qualcomm-linux-debian-flash.yaml
2934
```
3035

31-
### Build backends
36+
### Debos tips
3237

33-
By default, debos will try to pick a fast build backend; it will try to use its KVM backend ("-b kvm") when available, and otherwise an UML environment ("-b uml"). If none of these work, a solid backend is QEMU ("-b qemu"). Because the target images are arm64, this can be really slow, especially when building from another architecture such as amd64.
38+
By default, debos will try to pick a fast build backend; it will try to use its KVM backend ("-b kvm") when available, and otherwise an UML environment ("-b uml"). If none of these work, a solid backend is QEMU ("-b qemu"); because the target images are arm64, this can be really slow when building from another architecture such as amd64.
3439

3540
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:
3641
```bash
@@ -48,39 +53,57 @@ For the image recipe:
4853
- imagetype: either `ufs` (the default) or (`sdcard`); UFS images are named disk-ufs.img and use 4096 bytes sectors and SD card images are named disk-sdcard.img and use 512 bytes sectors
4954
- imagesize: set the output disk image size; default: `4GiB`
5055

51-
These can be passed as follows:
56+
Here are some example invocations:
5257
```bash
58+
# build the root filesystem with Xfce and a kernel from experimental
5359
debos -t xfcedesktop:true -t experimentalkernel:true debos-recipes/qualcomm-linux-debian-rootfs.yaml
60+
61+
# build an image where systemd overrides the firmware device tree with the one
62+
# for RB3 Gen2
5463
debos -t dtb:qcom/qcs6490-rb3gen2.dtb debos-recipes/qualcomm-linux-debian-image.yaml
64+
65+
# build an SD card image
66+
debos -t imagetype:sdcard debos-recipes/qualcomm-linux-debian-image.yaml
5567
```
5668

5769
## Flashing Instructions
5870
### Overview
5971

60-
Once a disk image is created, it is suitable for putting on an SD card, albeit most Qualcomm boards boot from internal storage by default. The disk image can also be flashed on the internal storage of your board with [qdl](https://github.com/linux-msm/qdl).
72+
The `disk-sdcard.img` disk image can simply be written to a SD card, albeit most Qualcomm boards boot from internal storage by default. With an SD card, the board will use boot firmware from internal storage (eMMC or UFS) and do an EFI boot from the SD card if the firmware can't boot from internal storage.
73+
74+
If there is no need to update the boot firmware, the `disk-ufs.img` disk image can also be flashed on the first LUN of the internal UFS storage with [qdl](https://github.com/linux-msm/qdl). Create a `rawprogram-ufs.xml` file as follows:
75+
```xml
76+
<?xml version="1.0" ?>
77+
<data>
78+
<program SECTOR_SIZE_IN_BYTES="4096" file_sector_offset="0" filename="disk-ufs.img" label="image" num_partition_sectors="0" partofsingleimage="false" physical_partition_number="0" start_sector="0"/>
79+
</data>
80+
```
81+
Put the board in "emergency download mode" (EDL; see next section) and run:
82+
```bash
83+
qdl --storage ufs prog_firehose_ddr.elf rawprogram-ufs.xml
84+
```
85+
Make sure to use `prog_firehose_ddr.elf` for the target platform, such as this [version from the QCM6490 boot binaries](https://softwarecenter.qualcomm.com/download/software/chip/qualcomm_linux-spf-1-0/qualcomm-linux-spf-1-0_test_device_public/r1.0_00058.0/qcm6490-le-1-0/common/build/ufs/bin/QCM6490_bootbinaries.zip).
6186

62-
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!
87+
To flash a complete set of assets on UFS internal storage, put the board in EDL mode and run:
88+
```bash
89+
# use the RB3 Gen2 Vision Kit flashable assets
90+
cd flash_rb3gen2-vision-kit
91+
qdl --storage ufs prog_firehose_ddr.elf rawprogram[0-9].xml patch[0-9].xml
92+
```
6393

64-
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.
94+
### Emergency Download Mode (EDL)
6595

66-
### RB3 Gen2 instructions
96+
In EDL mode, the board will receive a flashing program over its USB type-C cable, and that program will receive data to flash on the internal storage. This is a lower level mode than fastboot which is implemented by a higher-level bootloader.
6797

68-
The RB3 Gen2 board boots from UFS by default. To flash a disk image to the UFS storage of the RB3 Gen2 board:
69-
1. provision some known good early boot assets by flashing the Yocto edition of [Qualcomm Linux](https://www.qualcomm.com/developer/software/qualcomm-linux)
70-
1. create a `rawprogram-ufs.xml` file instructing QDL to flash to the first UFS LUN (LUN0):
71-
```xml
72-
<?xml version="1.0" ?>
73-
<data>
74-
<program SECTOR_SIZE_IN_BYTES="4096" file_sector_offset="0" filename="disk-ufs.img" label="image" num_partition_sectors="0" partofsingleimage="false" physical_partition_number="0" start_sector="0"/>
75-
</data>
76-
```
77-
1. put the board in "emergency download" mode (EDL) by removing any cable from the USB type-C port, and pressing the `F_DL` button while turning the power on
98+
To enter EDL mode:
99+
1. remove power to the board
100+
1. remove any cable from the USB type-C port
101+
1. on some boards, it's necessary to set some DIP switches
102+
1. press the `F_DL` button while turning the power on
78103
1. connect a cable from the flashing host to the USB type-C port on the board
79-
1. run qdl to flash the image:
80-
```bash
81-
qdl prog_firehose_ddr.elf rawprogram-ufs.xml
82-
```
83-
The `prog_firehose_ddr.elf` payload is part of the the Yocto Qualcomm Linux image download.
104+
1. run qdl to flash the board
105+
106+
NB: It's also possible to run qdl from the host while the baord is not connected, and starting the board directly in EDL mode.
84107

85108
## Development
86109

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
architecture: arm64
2+
3+
actions:
4+
- action: download
5+
description: Download qcom-ptool
6+
url: https://github.com/qualcomm-linux/qcom-ptool/archive/refs/heads/main.tar.gz
7+
name: qcom-ptool
8+
filename: qcom-ptool.tar.gz
9+
unpack: true
10+
11+
- action: download
12+
description: Download QCM6490 boot binaries
13+
url: https://softwarecenter.qualcomm.com/download/software/chip/qualcomm_linux-spf-1-0/qualcomm-linux-spf-1-0_test_device_public/r1.0_00058.0/qcm6490-le-1-0/common/build/ufs/bin/QCM6490_bootbinaries.zip
14+
name: qcm6490_boot-binaries
15+
filename: qcm6490_boot-binaries.zip
16+
17+
- action: download
18+
description: Download RB3 Gen2 Vision Kit CDT
19+
url: https://artifacts.codelinaro.org/artifactory/codelinaro-le/Qualcomm_Linux/QCS6490/cdt/rb3gen2-vision-kit.zip
20+
name: rb3gen2-vision-kit_cdt
21+
filename: rb3gen2-vision-kit_cdt.zip
22+
23+
- action: run
24+
description: Generate flash directories for UFS boards
25+
chroot: false
26+
command: |
27+
set -eux
28+
# work dir that will be thrown away
29+
mkdir -v build
30+
31+
# path to unpacked qcom-ptool tarball
32+
QCOM_PTOOL="${ROOTDIR}/../qcom-ptool.tar.gz.d/qcom-ptool-main"
33+
34+
## platform: QCM6490
35+
# unpack boot binaries
36+
unzip -j "${ROOTDIR}/../qcm6490_boot-binaries.zip" \
37+
-d build/qcm6490_boot-binaries
38+
# generate partition files
39+
mkdir -v build/qcm6490_partitions
40+
(
41+
cd build/qcm6490_partitions
42+
conf="${QCOM_PTOOL}/platforms/qcm6490/partitions.conf"
43+
"${QCOM_PTOOL}/gen_partition.py" -i "$conf" \
44+
-o ptool-partitions.xml
45+
# partitions.conf sets --type=emmc, nand or ufs
46+
if grep -F '^--disk --type=ufs ' "${conf}"; then
47+
touch flash-ufs
48+
fi
49+
"${QCOM_PTOOL}/ptool.py" -x ptool-partitions.xml
50+
)
51+
52+
### board: RB3Gen2 Vision Kit
53+
flash_dir="${ARTIFACTDIR}/flash_rb3gen2-vision-kit"
54+
rm -rf "${flash_dir}"
55+
mkdir -v "${flash_dir}"
56+
# copy platform partition files
57+
cp --preserve=mode,timestamps -v build/qcm6490_partitions/* \
58+
"${flash_dir}"
59+
# copy platform boot binaries; these shouldn't ship partition files, but
60+
# make sure not to accidentally clobber any such file
61+
find build/qcm6490_boot-binaries \
62+
-not -name 'gpt_*' \
63+
-not -name 'patch*.xml' \
64+
-not -name 'rawprogram*.xml' \
65+
-not -name 'wipe*.xml' \
66+
-not -name 'zeros_*' \
67+
\( \
68+
-name Qualcomm-Technologies-Inc.-Proprietary \
69+
-or -name 'prog_*' \
70+
-or -name '*.bin' \
71+
-or -name '*.elf' \
72+
-or -name '*.fv' \
73+
-or -name '*.mbn' \
74+
\) \
75+
-exec cp --preserve=mode,timestamps -v '{}' "${flash_dir}" \;
76+
# unpack board CDT
77+
unzip -j "${ROOTDIR}/../rb3gen2-vision-kit_cdt.zip" \
78+
-d build/rb3gen2-vision-kit_cdt
79+
# copy just the CDT data; no partition or flashing files
80+
cp --preserve=mode,timestamps -v build/rb3gen2-vision-kit_cdt/cdt_vision_kit.bin \
81+
"${flash_dir}"
82+
83+
# update flashing files for CDT
84+
sed -i '/label="cdt"/s/filename=""/filename="cdt_vision_kit.bin"/' \
85+
"${flash_dir}"/rawprogram*.xml
86+
87+
# generate a dtb.bin FAT partition with just a single dtb for the current
88+
# board; long-term this should really be a set of dtbs and overlays as to
89+
# share dtb.bin across boards
90+
dtb_bin="${flash_dir}/dtb.bin"
91+
rm -f "${dtb_bin}"
92+
# dtb.bin is only used in UFS based boards at the moment and UFS uses a
93+
# 4k sector size, so pass -S 4096
94+
# in qcom-ptool/platforms/*/partitions.conf, dtb_a and _b partitions
95+
# are provisioned with 64MiB; create a 4MiB FAT that will comfortably fit
96+
# in these and hold the target device tree, which is 4096 KiB sized
97+
# blocks for mkfs.vfat's last argument
98+
mkfs.vfat -S 4096 -C "${dtb_bin}" 4096
99+
# RB3 Gen2 Vision Kit will probably have a more specific DTB (see
100+
# <[email protected]> on lore.kernel.org)
101+
# but for now use the core kit one
102+
dtb="qcom/qcs6490-rb3gen2.dtb"
103+
# extract board device tree from the root filesystem provided tarball
104+
tar -C build -xvf "${ARTIFACTDIR}/dtbs.tar.gz" "${dtb}"
105+
# copy into the FAT as combined-dtb.dtb
106+
mcopy -vmp -i "${dtb_bin}" "build/${dtb}" ::/combined-dtb.dtb
107+
108+
# (NB: flashing files already expect "dtb.bin" as a filename)
109+
110+
# update flashing files for ESP image;
111+
# qcom-ptool/platforms/*/partitions.conf uses filename=efi.bin for the
112+
# ESP partition on EFI capable platforms
113+
sed -i '/label="efi"/s#filename="[^"]*"#filename="../disk-ufs.img1"#' \
114+
"${flash_dir}"/rawprogram*.xml
115+
116+
# update flashing files for rootfs image;
117+
# qcom-ptool/platforms/*/partitions.conf uses filename=rootfs.img for the
118+
# rootfs partition
119+
sed -i \
120+
'/label="rootfs"/s#filename="[^"]*"#filename="../disk-ufs.img2"#' \
121+
"${flash_dir}"/rawprogram*.xml
122+
123+
# cleanup
124+
rm -rf build
125+

debos-recipes/qualcomm-linux-debian-image.yaml

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
{{- $image := printf "disk-%s.img" $imagetype }}
55

66
architecture: arm64
7-
sectorsize: {{if eq $imagetype "ufs"}} 4096 {{else}} 512 {{end}}
7+
sectorsize: {{if eq $imagetype "ufs"}}4096{{else}}512{{end}}
88

99
actions:
1010
- action: unpack
@@ -56,12 +56,13 @@ actions:
5656

5757
# XXX these kernel options might be specific to a kernel version or board
5858
- action: filesystem-deploy
59+
description: Deploy root filesystem to mounted image
5960
setup-fstab: true
6061
append-kernel-cmdline: clk_ignore_unused pd_ignore_unused audit=0 deferred_probe_timeout=30
6162

6263
- action: apt
63-
recommends: true
6464
description: Make system bootable with systemd-boot
65+
recommends: true
6566
packages:
6667
- systemd-boot
6768
# TODO investigate why systemd-boot Recommends: shim-signed which
@@ -96,6 +97,21 @@ actions:
9697
systemctl enable debos-grow-rootfs
9798
9899
- action: run
100+
description: Extract partition images
101+
postprocess: true
102+
command: |
103+
set -eux
104+
sector_size="{{if eq $imagetype "ufs"}}4096{{else}}512{{end}}"
105+
image="{{ $image }}"
106+
fdisk -b "${sector_size}" -l "${image}" |
107+
sed -n '1,/^Device/ d; p' |
108+
while read name start end sectors rest; do
109+
dd if="${image}" of="${ARTIFACTDIR}/${name}" \
110+
bs="${sector_size}" skip="${start}" count="${sectors}"
111+
done
112+
113+
- action: run
114+
description: Compress image file
99115
postprocess: true
100116
command: gzip -v -f "${ARTIFACTDIR}/{{ $image }}"
101117

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ architecture: arm64
55

66
actions:
77
- action: debootstrap
8+
description: Bootstrap initial filesystem
89
# NB: not currently configurable
910
suite: trixie
1011
components:
@@ -189,7 +190,25 @@ actions:
189190
/etc/apt/sources.list.d/debian-experimental.sources
190191
{{- end }}
191192

193+
- action: run
194+
description: Create DTBs tarball
195+
chroot: false
196+
command: |
197+
set -eux
198+
# find the highest kernel version installed; kernels are backwards
199+
# compatible with older dtbs, so it would make sense to take dtbs from
200+
# the oldest available kernel as to allow all kernels to boot, but if
201+
# this image has pulled a more recent kernel, it's probably to gain
202+
# support for new hardware which would happen through new or updated dtbs
203+
# only in that new kernel, so use the latest dtbs
204+
latest_kernel="$(
205+
ls -d "$ROOTDIR"/usr/lib/linux-image-* | sort -V | tail -1)"
206+
tar -C "${latest_kernel}" -cvzf "$ARTIFACTDIR/dtbs.tar.gz" \
207+
qcom/qcs6490-rb3gen2.dtb \
208+
qcom/qrb2210-rb1.dtb
209+
192210
- action: pack
211+
description: Create root filesystem tarball
193212
file: rootfs.tar.gz
194213
compression: gz
195214

0 commit comments

Comments
 (0)