Skip to content

Commit e0ec159

Browse files
authored
Merge pull request #361 from lool/glymur-axiom-love
Refactor flash recipe for Axiom
2 parents 68d5c9c + 539f97b commit e0ec159

File tree

4 files changed

+184
-200
lines changed

4 files changed

+184
-200
lines changed

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

Lines changed: 78 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,11 @@ actions:
262262
# work dir that will be thrown away
263263
mkdir -v build
264264
265+
# mirror template variables in shell variables to keep the action body
266+
# in shell syntax
267+
buildid="{{$buildid}}"
268+
target_boards="{{$target_boards}}"
269+
265270
# path to unpacked qcom-ptool tarball
266271
QCOM_PTOOL="$(ls -d "${ROOTDIR}/../qcom-ptool.tar.gz.d/qcom-ptool-"*)"
267272
@@ -276,7 +281,7 @@ actions:
276281
# optional list of board names to build
277282
targets_file="build/targets.txt"
278283
rm -f "${targets_file}"
279-
case "{{ $target_boards }}" in
284+
case "$target_boards" in
280285
all)
281286
# no override; build all possible boards (default)
282287
touch "${targets_file}"
@@ -285,7 +290,7 @@ actions:
285290
{{- end }}
286291
;;
287292
*)
288-
echo "{{ $target_boards }}" |
293+
echo "$target_boards" |
289294
tr ',' '\n' |
290295
sed '/^$/d' |
291296
sort -u >"${targets_file}"
@@ -296,96 +301,91 @@ actions:
296301
### board: {{ $board.name }}
297302
### silicon family: {{ $board.silicon_family }}
298303

304+
# mirror template variables in shell variables to keep the action body
305+
# in shell syntax
306+
board_name="{{$board.name}}"
307+
board_dtb="{{$board.dtb}}"
308+
boot_binaries_filename="{{$board.boot_binaries_download.filename}}"
309+
board_cdt_download_filename=""
310+
board_cdt_filename=""
311+
board_u_boot_file=""
312+
{{- if $board.cdt_download }}
313+
board_cdt_download_filename="{{$board.cdt_download.filename}}"
314+
board_cdt_filename="{{$board.cdt_filename}}"
315+
{{- end }}
316+
{{- if $board.u_boot_file }}
317+
board_u_boot_file="{{$board.u_boot_file}}"
318+
{{- end }}
319+
299320
# set skip_board if board isn't listed
300321
skip_board=false
301-
if ! grep -Fxq "{{ $board.name }}" "${targets_file}"; then
322+
if ! grep -Fxq "$board_name" "${targets_file}"; then
302323
skip_board=true
303-
echo "Skipping board {{ $board.name }}: not in target list"
324+
echo "Skipping board ${board_name}: not in target list"
304325
fi
305326

306327
# set skip_board if board dtb isn't present
307-
if ! grep -Fxq "{{ $board.dtb }}" "${dtbs_file}"; then
328+
if ! grep -Fxq "$board_dtb" "${dtbs_file}"; then
308329
skip_board=true
309-
echo "Skipping board {{ $board.name }}: dtb not available"
330+
echo "Skipping board ${board_name}: dtb ${board_dtb} not available"
310331
fi
311332

312-
313333
# unpack boot binaries
314-
mkdir -v build/{{ $board.name }}_boot-binaries
315-
unzip "${ROOTDIR}/../{{ $board.boot_binaries_download.filename }}" \
316-
-d build/{{ $board.name }}_boot-binaries/unpack
334+
mkdir -v "build/${board_name}_boot-binaries"
335+
unzip "${ROOTDIR}/../${boot_binaries_filename}" \
336+
-d build/${board_name}_boot-binaries/unpack
317337
# strip top directories
318-
mv build/{{ $board.name }}_boot-binaries/unpack/*/* build/{{ $board.name }}_boot-binaries
319-
rmdir -v build/{{ $board.name }}_boot-binaries/unpack/* build/{{ $board.name }}_boot-binaries/unpack
338+
mv "build/${board_name}_boot-binaries/unpack"/*/* \
339+
"build/${board_name}_boot-binaries"
340+
rmdir -v "build/${board_name}_boot-binaries/unpack"/* \
341+
"build/${board_name}_boot-binaries/unpack"
320342

321-
{{- if $board.cdt_download }}
322343
if [ "${skip_board}" = false ]; then
323-
# unpack board CDT
324-
unzip "${ROOTDIR}/../{{ $board.cdt_download.filename }}" \
325-
-d build/{{ $board.name }}_cdt
326-
fi
327-
{{- end }}
344+
if [ -n "$board_cdt_download_filename" ]; then
345+
# unpack board CDT
346+
unzip "${ROOTDIR}/../${board_cdt_download_filename}" \
347+
-d "build/${board_name}_cdt"
348+
fi
328349

329350
{{- range $platform := $board.ptool_platforms }}
330-
### platform: {{ $platform }}
331-
332-
# generate ptool files - various XML files for flashing, GPT data etc.
333-
mkdir -vp build/ptool/{{ $platform }}
334-
(
335-
cd build/ptool/{{ $platform }}
336-
conf="${QCOM_PTOOL}/platforms/{{ $platform }}/partitions.conf"
351+
### platform: {{ $platform }}
352+
platform="{{$platform}}"
353+
# infer storage from ptool platform dir; first strip leading directory
354+
storage_use_case="${platform#*/}"
355+
# then strip trailing use case (after first dash)
356+
disk_type="${storage_use_case%%-*}"
337357

338-
{{- if $board.cdt_download }}
339-
"${RECIPEDIR}/../scripts/override-partition-conf.sh" "{{ $board.cdt_filename }}" <"$conf" >partitions.conf
340-
{{- else }}
341-
"${RECIPEDIR}/../scripts/override-partition-conf.sh" "" <"$conf" >partitions.conf
342-
{{- end }}
358+
# generate ptool files - various XML files for flashing, GPT data etc.
359+
mkdir -vp "build/ptool/${platform}"
360+
(
361+
cd "build/ptool/${platform}"
362+
"${RECIPEDIR}/../scripts/gen-ptool.sh" \
363+
"$QCOM_PTOOL" \
364+
"$platform" \
365+
"$board_cdt_filename" \
366+
"$buildid" \
367+
"$disk_type" \
368+
)
343369

344-
contents="${QCOM_PTOOL}/platforms/{{ $platform }}/contents.xml.in"
345-
# generate ptool-partitions.xml from partitions.conf
346-
"${QCOM_PTOOL}/gen_partition.py" -i partitions.conf \
347-
-o ptool-partitions.xml
348-
# generate contents.xml from ptool-partitions.xml and contents.xml.in
349-
if [ -e "$contents" ]; then
350-
"${QCOM_PTOOL}/gen_contents.py" -p ptool-partitions.xml \
351-
-t "$contents" \
352-
-b "{{$buildid}}" \
353-
-o contents.xml
354-
fi
355-
# generate flashing files from qcom-partitions.xml
356-
"${QCOM_PTOOL}/ptool.py" -x ptool-partitions.xml
357-
)
358-
359-
if [ "${skip_board}" = false ]; then
360-
disk_type=$(cat build/ptool/{{ $platform }}/disk_type)
361370
# create board-specific flash directory
362-
flash_dir="${ARTIFACTDIR}/flash_{{ $board.name }}_${disk_type}"
371+
flash_dir="${ARTIFACTDIR}/flash_${board_name}_${disk_type}"
363372
rm -rf "${flash_dir}"
364373
mkdir -v "${flash_dir}"
365374
# copy platform partition files
366-
cp --preserve=mode,timestamps -v \
367-
build/ptool/{{ $platform }}/* "${flash_dir}"
368-
# adjust paths in contents.xml to use board-specific flash_* subdir
369-
if [ -e "${flash_dir}/contents.xml" ]; then
370-
# one set of backslashes for shell quoting, another one for sed
371-
# parsing
372-
windows_path=".\\\\flash_{{ $board.name }}_${disk_type}\\\\"
373-
linux_path="./flash_{{ $board.name }}_${disk_type}/"
374-
sed -i \
375-
-e "s:<windows_root_path>.*:<windows_root_path>${windows_path}</windows_root_path>:" \
376-
-e "s:<linux_root_path>.*:<linux_root_path>${linux_path}</linux_root_path>:" \
377-
"${flash_dir}/contents.xml"
378-
fi
375+
cp --preserve=all --no-dereference -v \
376+
"build/ptool/${platform}"/* "${flash_dir}"
377+
379378
# remove BLANK_GPT, WIPE_PARTITIONS and wipe_rawprogram files as
380379
# it's common for people to run "qdl rawprogram*.xml" or pcat,
381380
# mistakingly including these; perhaps ptool should have a flag
382381
# not to generate these
383382
rm -v "${flash_dir}"/rawprogram*_BLANK_GPT.xml
384383
rm -v "${flash_dir}"/rawprogram*_WIPE_PARTITIONS.xml
385384
rm -v "${flash_dir}"/wipe_rawprogram*.xml
385+
386386
# copy silicon family boot binaries; these shouldn't ship partition
387387
# files, but make sure not to accidentally clobber any such file
388-
find build/{{ $board.name }}_boot-binaries \
388+
find "build/${board_name}_boot-binaries" \
389389
-not -name 'gpt_*' \
390390
-not -name 'patch*.xml' \
391391
-not -name 'rawprogram*.xml' \
@@ -402,31 +402,22 @@ actions:
402402
-or -name '*.fv' \
403403
-or -name '*.mbn' \
404404
\) \
405-
-exec cp --preserve=mode,timestamps -v '{}' "${flash_dir}" \;
405+
-exec cp --preserve=all --no-dereference -v '{}' "${flash_dir}" \;
406406

407-
# remove the temporary disk_type file from the flash dir
408-
rm -f "${flash_dir}/disk_type"
409-
fi
410-
{{- if $board.u_boot_file }}
411-
if [ "${skip_board}" = false ]; then
412-
# copy U-Boot binary to boot.img;
413-
# qcom-ptool/platforms/*/partitions.conf uses filename=boot.img
414-
# boot_a and boot_b partitions
415-
cp --preserve=mode,timestamps -v \
416-
"${ARTIFACTDIR}/{{ $board.u_boot_file }}" "${flash_dir}/boot.img"
417-
fi
418-
{{- end }}
407+
if [ -n "${board_u_boot_file}" ]; then
408+
# copy U-Boot binary to boot.img; qcom-ptool partitions.conf
409+
# files use filename=boot.img for boot_a and boot_b partitions
410+
cp --preserve=all --no-dereference -v \
411+
"${ARTIFACTDIR}/${board_u_boot_file}" "${flash_dir}/boot.img"
412+
fi
419413

420-
{{- if $board.cdt_download }}
421-
if [ "${skip_board}" = false ]; then
422-
# copy just the CDT data; no partition or flashing files
423-
cp --preserve=mode,timestamps -v \
424-
build/{{ $board.name }}_cdt/{{ $board.cdt_filename }} \
425-
"${flash_dir}"
426-
fi
427-
{{- end }}
414+
if [ -n "$board_cdt_filename" ]; then
415+
# copy just the CDT data; no partition or flashing files
416+
cp --preserve=all --no-dereference -v \
417+
"build/${board_name}_cdt/${board_cdt_filename}" \
418+
"${flash_dir}"
419+
fi
428420

429-
if [ "${skip_board}" = false ]; then
430421
# generate a dtb.bin FAT partition with just a single dtb for the
431422
# current board; long-term this should really be a set of dtbs and
432423
# overlays as to share dtb.bin across boards
@@ -441,12 +432,11 @@ actions:
441432
mkfs.vfat -S 4096 -C "${dtb_bin}" 4096
442433
# extract board device tree from the root filesystem provided
443434
# tarball
444-
tar -C build -xvf "${ARTIFACTDIR}/dtbs.tar.gz" "{{ $board.dtb }}"
435+
tar -C build -xvf "${ARTIFACTDIR}/dtbs.tar.gz" "$board_dtb"
445436
# copy into the FAT as combined-dtb.dtb
446-
mcopy -vmp -i "${dtb_bin}" "build/{{ $board.dtb }}" \
447-
::/combined-dtb.dtb
448-
fi
437+
mcopy -vmp -i "${dtb_bin}" "build/${board_dtb}" ::/combined-dtb.dtb
449438
{{- end }}
439+
fi
450440
{{- end }}
451441

452442
# cleanup

scripts/bundle-flash-dirs.sh

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,31 @@ ufs_dirs=""
1313

1414
for d in flash_*
1515
do
16-
partitions_conf="$d/partitions.conf"
17-
echo "examining $partitions_conf"
18-
if grep disk-sdcard "$partitions_conf"
19-
then
20-
echo "partitions.conf refers to disk-sdcard, choosing emmc"
21-
target=emmc
22-
elif grep disk-ufs "$partitions_conf"
23-
then
24-
echo "partitions.conf refers to disk-ufs, choosing emmc"
25-
target=ufs
26-
else
27-
echo "partitions.conf has unknown format, putting in emmc by default"
28-
target=emmc
29-
fi
30-
31-
echo "choosen target $target for $d"
32-
33-
case "$target" in
34-
emmc)
35-
emmc_dirs="$emmc_dirs $d"
36-
;;
37-
ufs)
38-
ufs_dirs="$ufs_dirs $d"
39-
;;
40-
esac
16+
rawprogram0="$d/rawprogram0.xml"
17+
echo "examining $rawprogram0"
18+
if grep disk-sdcard "$rawprogram0"
19+
then
20+
echo "choosing emmc"
21+
target=emmc
22+
elif grep disk-ufs "$rawprogram0"
23+
then
24+
echo "choosing ufs"
25+
target=ufs
26+
else
27+
echo "couldn't find disk-ufs or disk-emmc, choosing emmc by default"
28+
target=emmc
29+
fi
30+
31+
echo "choosen target $target for $d"
32+
33+
case "$target" in
34+
emmc)
35+
emmc_dirs="$emmc_dirs $d"
36+
;;
37+
ufs)
38+
ufs_dirs="$ufs_dirs $d"
39+
;;
40+
esac
4141
done
4242

4343
echo "emmc_dirs: $emmc_dirs"

scripts/gen-ptool.sh

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#!/bin/sh
2+
# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
3+
# SPDX-License-Identifier: BSD-3-Clause
4+
5+
# generates a modified partitions.conf, a disk-type stamp,
6+
# ptool-partitions.xml, ptool files and contents.xml for target platform and
7+
# parameters
8+
9+
set -eux
10+
11+
# path to ptool tree
12+
QCOM_PTOOL="$1"
13+
# ptool subdir for a particular platform and storage, e.g.
14+
# "qrb2210/emmc-16GB-arduino"
15+
PLATFORM="$2"
16+
# relative path to CDT, to use as filename in the generated files
17+
CDT_FILENAME="$3"
18+
# build id for generated contents.xml
19+
BUILDID="$4"
20+
# disk storage, emmc, nvme, spinor or ufs
21+
DISK_TYPE="$5"
22+
23+
PARTITIONS_CONF="${QCOM_PTOOL}/platforms/${PLATFORM}/partitions.conf"
24+
25+
case "$DISK_TYPE" in
26+
emmc|nvme)
27+
esp="disk-sdcard.img1"
28+
rootfs="disk-sdcard.img2"
29+
;;
30+
ufs)
31+
esp="disk-ufs.img1"
32+
rootfs="disk-ufs.img2"
33+
;;
34+
spinor)
35+
# spinor carries firmware only; no OS efi/rootfs partitions
36+
esp=""
37+
rootfs=""
38+
;;
39+
*)
40+
echo "unsupported disk type $DISK_TYPE"
41+
exit 1
42+
;;
43+
esac
44+
45+
# build a map of partition names from partitions.conf to our names
46+
#
47+
# |--------|--------------|-------------------|-----------------|
48+
# | data | ptool name | ptool filename | debos filename |
49+
# |--------|--------------|-------------------|-----------------|
50+
# | ESP | efi | efi.bin | disk-media.img1 |
51+
# | rootfs | rootfs | rootfs.img | disk-media.img2 |
52+
# | DTBs | dtb_a, dtb_b | dtb.bin | dtb.bin |
53+
# | CDTs | cdt | unset / per board | from download |
54+
# |--------|--------------|-------------------|-----------------|
55+
partition_map="cdt=$(basename "${CDT_FILENAME}")"
56+
partition_map="${partition_map},dtb_a=dtb.bin"
57+
partition_map="${partition_map},dtb_b=dtb.bin"
58+
partition_map="${partition_map},efi=${esp}"
59+
partition_map="${partition_map},rootfs=${rootfs}"
60+
61+
# create symlinks from flat image to actual file
62+
ln -s "../${esp}" "$esp"
63+
ln -s "../${rootfs}" "$rootfs"
64+
65+
# generate ptool-partitions.xml from partitions.conf
66+
"${QCOM_PTOOL}/gen_partition.py" -i "${PARTITIONS_CONF}" \
67+
-o ptool-partitions.xml \
68+
-m "${partition_map}"
69+
70+
# generate contents.xml from ptool-partitions.xml and contents.xml.in
71+
CONTENTS="${QCOM_PTOOL}/platforms/${PLATFORM}/contents.xml.in"
72+
if [ -e "$CONTENTS" ]; then
73+
"${QCOM_PTOOL}/gen_contents.py" -p ptool-partitions.xml \
74+
-t "$CONTENTS" \
75+
-b "$BUILDID" \
76+
-o contents.xml
77+
fi
78+
79+
# generate flashing files from qcom-partitions.xml
80+
"${QCOM_PTOOL}/ptool.py" -x ptool-partitions.xml
81+

0 commit comments

Comments
 (0)