summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTrevor Woerner <trevor.woerner@amd.com>2025-03-20 02:26:17 -0400
committerMark Hatle <mark.hatle@amd.com>2025-03-30 14:16:15 -0600
commitdbf2b43bf0ec8a2206a3542d46de08d82b36884f (patch)
tree9d1bdcff790847865cb661c9b2feb87f392294ae
parent17d0c589cb8fe91688fa141c4f804e90ce24fcef (diff)
downloadmeta-xilinx-dbf2b43bf0ec8a2206a3542d46de08d82b36884f.tar.gz
meta-xilinx-core: add ufs wic support
Add the ability to create *.wic.ufs (etc.) images that use a 4096-byte sector/block size. This solution uses the local layer version of wic and passing in --sector-size 4096 when calling the fork of wic in this layer. (currently only supports ext and vfat) Signed-off-by: Trevor Woerner <trevor.woerner@amd.com> Revised commit message and some integration details Signed-off-by: Mark Hatle <mark.hatle@amd.com>
-rw-r--r--meta-xilinx-core/classes-recipe/image_types_ufs.bbclass209
1 files changed, 209 insertions, 0 deletions
diff --git a/meta-xilinx-core/classes-recipe/image_types_ufs.bbclass b/meta-xilinx-core/classes-recipe/image_types_ufs.bbclass
new file mode 100644
index 00000000..0ead2b51
--- /dev/null
+++ b/meta-xilinx-core/classes-recipe/image_types_ufs.bbclass
@@ -0,0 +1,209 @@
1#
2# Copyright OpenEmbedded Contributors
3#
4# SPDX-License-Identifier: MIT
5#
6
7# The WICVARS variable is used to define list of bitbake variables used in wic code
8# variables from this list is written to <image>.env file
9WICUFSVARS ?= "\
10 APPEND \
11 ASSUME_PROVIDED \
12 BBLAYERS \
13 DEPLOY_DIR_IMAGE \
14 FAKEROOTCMD \
15 HOSTTOOLS_DIR \
16 IMAGE_BASENAME \
17 IMAGE_BOOT_FILES \
18 IMAGE_EFI_BOOT_FILES \
19 IMAGE_LINK_NAME \
20 IMAGE_ROOTFS \
21 IMGDEPLOYDIR \
22 INITRAMFS_FSTYPES \
23 INITRAMFS_IMAGE \
24 INITRAMFS_IMAGE_BUNDLE \
25 INITRAMFS_LINK_NAME \
26 INITRD \
27 INITRD_LIVE \
28 ISODIR \
29 KERNEL_IMAGETYPE \
30 MACHINE \
31 PSEUDO_IGNORE_PATHS \
32 RECIPE_SYSROOT_NATIVE \
33 ROOTFS_SIZE \
34 STAGING_DATADIR \
35 STAGING_DIR \
36 STAGING_DIR_HOST \
37 STAGING_LIBDIR \
38 TARGET_SYS \
39"
40
41inherit_defer ${@bb.utils.contains('INITRAMFS_IMAGE_BUNDLE', '1', 'kernel-artifact-names', '', d)}
42
43WKS_FILE ??= "${IMAGE_BASENAME}.${MACHINE}.wks"
44WKS_FILES ?= "${WKS_FILE} ${IMAGE_BASENAME}.wks"
45WKS_SEARCH_PATH ?= "${THISDIR}:${@':'.join('%s/wic' % p for p in '${BBPATH}'.split(':'))}:${@':'.join('%s/scripts/lib/wic/canned-wks' % l for l in '${BBPATH}:${COREBASE}'.split(':'))}"
46WKS_FULL_PATH = "${@wks_search(d.getVar('WKS_FILES').split(), d.getVar('WKS_SEARCH_PATH')) or ''}"
47
48def wks_search(files, search_path):
49 for f in files:
50 if os.path.isabs(f):
51 if os.path.exists(f):
52 return f
53 else:
54 searched = bb.utils.which(search_path, f)
55 if searched:
56 return searched
57
58WIC_CREATE_EXTRA_ARGS ?= ""
59
60IMAGE_CMD:wic.ufs () {
61 out="${IMGDEPLOYDIR}/${IMAGE_NAME}"
62 build_wic_ufs="${WORKDIR}/build-wic-ufs"
63 tmp_wic_ufs="${WORKDIR}/tmp-wic-ufs"
64 wks="${WKS_FULL_PATH}"
65 if [ -e "$tmp_wic_ufs" ]; then
66 # Ensure we don't have any junk leftover from a previously interrupted
67 # do_image_wic_ufs execution
68 rm -rf "$tmp_wic_ufs"
69 fi
70 if [ -z "$wks" ]; then
71 bbfatal "No kickstart files from WKS_FILES were found: ${WKS_FILES}. Please set WKS_FILE or WKS_FILES appropriately."
72 fi
73 BUILDDIR="${TOPDIR}" PSEUDO_UNLOAD=1 ${LAYERPATH_xilinx}/scripts/wic --version
74 BUILDDIR="${TOPDIR}" PSEUDO_UNLOAD=1 ${LAYERPATH_xilinx}/scripts/wic create "$wks" --vars "${STAGING_DIR}/${MACHINE}/imgdata/" --sector-size 4096 -e "${IMAGE_BASENAME}" -o "$build_wic_ufs/" -w "$tmp_wic_ufs" ${WIC_CREATE_EXTRA_ARGS}
75
76 # look to see if the user specifies a custom imager
77 IMAGER=direct
78 eval set -- "${WIC_CREATE_EXTRA_ARGS} --"
79 while [ 1 ]; do
80 case "$1" in
81 --imager|-i)
82 shift
83 IMAGER=$1
84 ;;
85 --)
86 shift
87 break
88 ;;
89 esac
90 shift
91 done
92 mv "$build_wic_ufs/$(basename "${wks%.wks}")"*.${IMAGER} "$out.wic.ufs"
93}
94IMAGE_CMD:wic.ufs[vardepsexclude] = "WKS_FULL_PATH WKS_FILES TOPDIR"
95do_image_wic_ufs[cleandirs] = "${WORKDIR}/build-wic-ufs"
96
97PSEUDO_IGNORE_PATHS .= ",${WORKDIR}/build-wic-ufs"
98
99# Rebuild when the wks file or vars in WICUFSVARS change
100USING_WIC_UFS = "${@bb.utils.contains_any('IMAGE_FSTYPES', 'wic.ufs ' + ' '.join('wic.ufs.%s' % c for c in '${CONVERSIONTYPES}'.split()), '1', '', d)}"
101WKS_FILE_CHECKSUM = "${@'${WKS_FULL_PATH}:%s' % os.path.exists('${WKS_FULL_PATH}') if '${USING_WIC_UFS}' else ''}"
102do_image_wic_ufs[file-checksums] += "${WKS_FILE_CHECKSUM}"
103do_image_wic_ufs[depends] += "${@' '.join('%s-native:do_populate_sysroot' % r for r in ('parted', 'gptfdisk', 'dosfstools', 'mtools'))}"
104
105# We ensure all artfacts are deployed (e.g virtual/bootloader)
106do_image_wic_ufs[recrdeptask] += "do_deploy"
107do_image_wic_ufs[deptask] += "do_image_complete"
108
109## Keep the following WKS_FILE_* and do_write_wks_template in sync with poky image_types_wic
110WKS_FILE_DEPENDS_DEFAULT = '${@bb.utils.contains_any("BUILD_ARCH", [ 'x86_64', 'i686' ], "syslinux-native", "",d)}'
111WKS_FILE_DEPENDS_DEFAULT += "bmaptool-native cdrtools-native btrfs-tools-native squashfs-tools-native e2fsprogs-native erofs-utils-native"
112# Unified kernel images need objcopy
113WKS_FILE_DEPENDS_DEFAULT += "virtual/${TARGET_PREFIX}binutils"
114WKS_FILE_DEPENDS_BOOTLOADERS = ""
115WKS_FILE_DEPENDS_BOOTLOADERS:x86 = "syslinux grub-efi systemd-boot os-release"
116WKS_FILE_DEPENDS_BOOTLOADERS:x86-64 = "syslinux grub-efi systemd-boot os-release"
117WKS_FILE_DEPENDS_BOOTLOADERS:x86-x32 = "syslinux grub-efi"
118
119WKS_FILE_DEPENDS ??= "${WKS_FILE_DEPENDS_DEFAULT} ${WKS_FILE_DEPENDS_BOOTLOADERS}"
120
121DEPENDS += "${@ '${WKS_FILE_DEPENDS}' if d.getVar('USING_WIC_UFS') else '' }"
122
123python do_write_wks_template () {
124 """Write out expanded template contents to WKS_FULL_PATH."""
125 import re
126
127 template_body = d.getVar('_WKS_TEMPLATE')
128
129 # Remove any remnant variable references left behind by the expansion
130 # due to undefined variables
131 expand_var_regexp = re.compile(r"\${[^{}@\n\t :]+}")
132 while True:
133 new_body = re.sub(expand_var_regexp, '', template_body)
134 if new_body == template_body:
135 break
136 else:
137 template_body = new_body
138
139 wks_file = d.getVar('WKS_FULL_PATH')
140 with open(wks_file, 'w') as f:
141 f.write(template_body)
142 f.close()
143 # Copy the finalized wks file to the deploy directory for later use
144 depdir = d.getVar('IMGDEPLOYDIR')
145 basename = d.getVar('IMAGE_BASENAME')
146 bb.utils.copyfile(wks_file, "%s/%s" % (depdir, basename + '-' + os.path.basename(wks_file)))
147}
148
149do_flush_pseudodb() {
150 ${FAKEROOTENV} ${FAKEROOTCMD} -S
151}
152
153python () {
154 if d.getVar('USING_WIC_UFS'):
155 wks_file_u = d.getVar('WKS_FULL_PATH', False)
156 wks_file = d.expand(wks_file_u)
157 base, ext = os.path.splitext(wks_file)
158 if ext == '.in' and os.path.exists(wks_file):
159 wks_out_file = os.path.join(d.getVar('WORKDIR'), os.path.basename(base))
160 d.setVar('WKS_FULL_PATH', wks_out_file)
161 d.setVar('WKS_TEMPLATE_PATH', wks_file_u)
162 d.setVar('WKS_FILE_CHECKSUM', '${WKS_TEMPLATE_PATH}:True')
163
164 # We need to re-parse each time the file changes, and bitbake
165 # needs to be told about that explicitly.
166 bb.parse.mark_dependency(d, wks_file)
167
168 try:
169 with open(wks_file, 'r') as f:
170 body = f.read()
171 except (IOError, OSError) as exc:
172 pass
173 else:
174 # Previously, I used expandWithRefs to get the dependency list
175 # and add it to WICUFSVARS, but there's no point re-parsing the
176 # file in process_wks_template as well, so just put it in
177 # a variable and let the metadata deal with the deps.
178 d.setVar('_WKS_TEMPLATE', body)
179 bb.build.addtask('do_write_wks_template', 'do_image_wic_ufs', 'do_image', d)
180 bb.build.addtask('do_image_wic_ufs', 'do_image_complete', None, d)
181}
182
183#
184# Write environment variables used by wic
185# to tmp/sysroots/<machine>/imgdata/<image>.env
186#
187python do_rootfs_wicufsenv () {
188 wicvars = d.getVar('WICUFSVARS')
189 if not wicvars:
190 return
191
192 stdir = d.getVar('STAGING_DIR')
193 outdir = os.path.join(stdir, d.getVar('MACHINE'), 'imgdata')
194 bb.utils.mkdirhier(outdir)
195 basename = d.getVar('IMAGE_BASENAME')
196 with open(os.path.join(outdir, basename) + '.env', 'w') as envf:
197 for var in wicvars.split():
198 value = d.getVar(var)
199 if value:
200 envf.write('%s="%s"\n' % (var, value.strip()))
201 envf.close()
202 # Copy .env file to deploy directory for later use with stand alone wic
203 depdir = d.getVar('IMGDEPLOYDIR')
204 bb.utils.copyfile(os.path.join(outdir, basename) + '.env', os.path.join(depdir, basename) + '.env')
205}
206addtask do_flush_pseudodb after do_rootfs before do_image do_image_qa
207addtask do_rootfs_wicufsenv after do_image before do_image_wic_ufs
208do_rootfs_wicufsenv[vardeps] += "${WICUFSVARS}"
209do_rootfs_wicufsenv[prefuncs] = 'set_image_size'