|
4 | 4 | # Create bootfs partition with kernel, env, Initramfs and dtbs |
5 | 5 | # Layout matches the reference titan image (Bianbu-GNOME-K3) |
6 | 6 | # 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" |
7 | 9 | do_image_ext4[prefuncs] += "do_create_bootfs" |
8 | 10 | do_image_wic[prefuncs] += "do_create_bootfs" |
9 | 11 |
|
@@ -54,7 +56,7 @@ python do_create_bootfs() { |
54 | 56 | # 3. Initramfs (rename to initrd.img-<version>) |
55 | 57 | initrd_name = f"initrd.img-{kver_generic}" |
56 | 58 | 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) |
58 | 60 | if initramfs: |
59 | 61 | copy_file(initramfs, os.path.join(bootfs_dir, initrd_name)) |
60 | 62 | else: |
@@ -114,35 +116,53 @@ commonargs=setenv bootargs plymouth.prefer-fbcon plymouth.ignore-serial-consoles |
114 | 116 | do_image_wic[postfuncs] += "write_bootinfo_to_wic" |
115 | 117 |
|
116 | 118 | python write_bootinfo_to_wic() { |
117 | | - import subprocess |
118 | | - import os |
| 119 | + import subprocess, os, gzip, shutil |
119 | 120 |
|
120 | | - # 1. Retrieve Yocto path variables |
121 | 121 | imgdeploydir = d.getVar('IMGDEPLOYDIR') |
122 | 122 | image_name = d.getVar('IMAGE_NAME') |
123 | 123 | deploy_dir = d.getVar('DEPLOY_DIR_IMAGE') |
124 | 124 |
|
125 | | - # K3 uses bootinfo_block.bin (from u-boot-k3) |
126 | 125 | 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') |
127 | 128 |
|
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 |
132 | 129 | 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") |
134 | 131 | return |
135 | 132 |
|
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}") |
138 | 135 | return |
139 | 136 |
|
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 | + |
141 | 143 | 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)") |
146 | 149 | 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) |
148 | 168 | } |
0 commit comments