Skip to content

Commit 4baa2b2

Browse files
committed
k3-vendor-image: add initramfs task deps, fix filenames
- depend on core-image-minimal-initramfs being complete - use core-image-minimal-initramfs instead of custom initramfs image - work on wic.gz (default in BSP) rather than .wic Signed-off-by: Trevor Gamblin <tgamblin@baylibre.com>
1 parent 3e2df71 commit 4baa2b2

1 file changed

Lines changed: 38 additions & 18 deletions

File tree

classes/k3-vendor-image.bbclass

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
# Create bootfs partition with kernel, env, Initramfs and dtbs
55
# Layout matches the reference titan image (Bianbu-GNOME-K3)
66
# Triggered before ext4 rootfs generation and WIC image generation
7+
do_image_ext4[depends] += "core-image-minimal-initramfs:do_image_complete"
8+
do_image_wic[depends] += "core-image-minimal-initramfs:do_image_complete"
79
do_image_ext4[prefuncs] += "do_create_bootfs"
810
do_image_wic[prefuncs] += "do_create_bootfs"
911

@@ -54,7 +56,7 @@ python do_create_bootfs() {
5456
# 3. Initramfs (rename to initrd.img-<version>)
5557
initrd_name = f"initrd.img-{kver_generic}"
5658
initramfs = next((f for f in os.listdir(deploydir)
57-
if f.startswith('initramfs-image-') and f.endswith('.cpio.gz')), None)
59+
if f.startswith('core-image-minimal-initramfs-') and f.endswith('.cpio.gz')), None)
5860
if initramfs:
5961
copy_file(initramfs, os.path.join(bootfs_dir, initrd_name))
6062
else:
@@ -114,35 +116,53 @@ commonargs=setenv bootargs plymouth.prefer-fbcon plymouth.ignore-serial-consoles
114116
do_image_wic[postfuncs] += "write_bootinfo_to_wic"
115117

116118
python write_bootinfo_to_wic() {
117-
import subprocess
118-
import os
119+
import subprocess, os, gzip, shutil
119120

120-
# 1. Retrieve Yocto path variables
121121
imgdeploydir = d.getVar('IMGDEPLOYDIR')
122122
image_name = d.getVar('IMAGE_NAME')
123123
deploy_dir = d.getVar('DEPLOY_DIR_IMAGE')
124124

125-
# K3 uses bootinfo_block.bin (from u-boot-k3)
126125
bootinfo_path = os.path.join(deploy_dir, 'bootinfo_block.bin')
126+
wic_gz_path = os.path.join(imgdeploydir, image_name + '.wic.gz')
127+
wic_bmap_path = os.path.join(imgdeploydir, image_name + '.wic.bmap')
127128

128-
# Define the physical path of the generated .wic file
129-
wic_path = os.path.join(imgdeploydir, image_name + '.wic')
130-
131-
# 2. Safety checks
132129
if not os.path.exists(bootinfo_path):
133-
bb.warn(f"[Post-WIC] bootinfo file not found: {bootinfo_path} - skipping injection")
130+
bb.warn(f"[Post-WIC] bootinfo not found: {bootinfo_path} - skipping")
134131
return
135132

136-
if not os.path.exists(wic_path):
137-
bb.error(f"[Post-WIC] Target WIC file not found: {wic_path}")
133+
if not os.path.exists(wic_gz_path):
134+
bb.error(f"[Post-WIC] WIC file not found: {wic_gz_path}")
138135
return
139136

140-
# 3. Perform the dd injection
137+
tmp_wic = wic_gz_path[:-3] # strip .gz
138+
139+
with gzip.open(wic_gz_path, 'rb') as f_in:
140+
with open(tmp_wic, 'wb') as f_out:
141+
shutil.copyfileobj(f_in, f_out)
142+
141143
try:
142-
# Write bootinfo at 1M offset (128K size) - K3 specific
143-
cmd = ['dd', f'if={bootinfo_path}', f'of={wic_path}', 'bs=1K', 'seek=1024', 'count=128', 'conv=notrunc']
144-
subprocess.run(cmd, check=True, capture_output=True)
145-
bb.note(f"[Post-WIC] Successfully injected bootinfo (128K @ 1M) into {os.path.basename(wic_path)}")
144+
subprocess.run(
145+
['dd', f'if={bootinfo_path}', f'of={tmp_wic}',
146+
'bs=1K', 'seek=1024', 'count=128', 'conv=notrunc'],
147+
check=True, capture_output=True)
148+
bb.note(f"[Post-WIC] Injected bootinfo (128K @ 1M)")
146149
except subprocess.CalledProcessError as e:
147-
bb.error(f"[Post-WIC] dd command failed: {e.stderr.decode()}")
150+
os.unlink(tmp_wic)
151+
bb.error(f"[Post-WIC] dd failed: {e.stderr.decode()}")
152+
return
153+
154+
with open(tmp_wic, 'rb') as f_in:
155+
with gzip.open(wic_gz_path, 'wb', compresslevel=9) as f_out:
156+
shutil.copyfileobj(f_in, f_out)
157+
158+
if os.path.exists(wic_bmap_path):
159+
try:
160+
subprocess.run(
161+
['bmaptool', 'create', tmp_wic, '-o', wic_bmap_path],
162+
check=True, capture_output=True)
163+
bb.note(f"[Post-WIC] Regenerated bmap")
164+
except subprocess.CalledProcessError as e:
165+
bb.warn(f"[Post-WIC] bmaptool failed: {e.stderr.decode()}")
166+
167+
os.unlink(tmp_wic)
148168
}

0 commit comments

Comments
 (0)