Debian: support multi kernels in single image

Introduce a new function change_default_kernel() to change the default
boot kernel, which is defined as "default-kernel" in lat.yaml file.

Either build-image --std or build-image --rt uses the same pkg list
file(stx-std.lst), no longer maintain stx-rt.lst. All the rt packages
are merged into stx-std.lst, so always pass "std" to function
check_stx_patched() to select stx-std.lst file.

The --std or --rt of build-image changes to set the default booting
kernel.

Test Plan:

Pass: build-image --std
Pass: boot up, uname -a shows up std kernel
Pass: change to rt kernel in /boot/1/kernel.env
Pass: reboot, uname -a shows up rt kernel

Pass: build-image --rt
Pass: boot up, uname -a shows up rt kernel
Pass: change to std kernel in /boot/1/kernel.env
Pass: reboot, uname -a shows up std kernel

Story: 2008846
Task: 45417

Signed-off-by: Yue Tao <Yue.Tao@windriver.com>
Change-Id: I784aefd540ab334c460e9f136910da9ac6b86209
This commit is contained in:
Yue Tao 2022-05-19 15:05:12 +08:00 committed by Yue Tao
parent d8aed3766b
commit 21edf8072c

View File

@ -19,6 +19,7 @@ import discovery
import getopt
import logging
import os
import re
import repo_manage
import shutil
import subprocess
@ -109,6 +110,53 @@ def update_ostree_osname(img_yaml):
return True
def change_default_kernel(img_yaml, ktype):
rt_kernel = std_kernel = None
try:
with open(img_yaml) as f:
yaml_doc = yaml.safe_load(f)
multi_kernels = yaml_doc["multiple-kernels"].split(" ")
default_kernel = yaml_doc["default-kernel"]
if len(multi_kernels) == 1:
return False
for kernel in multi_kernels:
if re.search("-rt-", kernel):
rt_kernel = kernel
else:
std_kernel = kernel
if ktype == "rt":
if re.search("-rt-", default_kernel):
return True
elif rt_kernel != None:
yaml_doc["default-kernel"] = rt_kernel
else:
logger.error(f"No rt kernel is found in {multiple-kernels}")
return False
elif ktype == "std":
if not re.search("-rt-", default_kernel):
return True
elif std_kernel != None:
yaml_doc["default-kernel"] = std_kernel
else:
logger.error(f"No std kernel is found in {multiple-kernels}")
return False
logger.debug(f'Set default kernel as {yaml_doc["default-kernel"]}')
try:
with open(img_yaml, 'w') as f:
yaml.safe_dump(yaml_doc, f, default_flow_style=False, sort_keys=False)
except IOError as e:
logger.error(str(e))
return False
except IOError as e:
logger.error(str(e))
return False
return True
def replace_in_yaml(dst_yaml, field, field_type, src_str, dst_str):
logger.debug("Start to replace %s in field %s of yaml %s", src_str, field, dst_yaml)
@ -364,10 +412,10 @@ if __name__ == "__main__":
base_bins_ready = check_base_os_binaries(repo_manager)
logger.info("\nchecking STX binary packages ......")
stx_bins_ready = check_stx_binaries(repo_manager, kernel_type)
stx_bins_ready = check_stx_binaries(repo_manager, "std")
logger.info("\nchecking STX patched packages ......")
stx_patched_ready = check_stx_patched(repo_manager, kernel_type)
stx_patched_ready = check_stx_patched(repo_manager, "std")
if not base_bins_ready or not stx_bins_ready or not stx_patched_ready:
logger.error("Fail to get prepared to build image")
@ -420,13 +468,9 @@ if __name__ == "__main__":
update_ostree_osname(lat_yaml)
if kernel_type == 'rt':
if not update_rt_kernel_in_main_yaml(lat_yaml):
logger.error("Failed to update LAT yaml file for rt type")
sys.exit(1)
if not update_rt_kernel_in_initramfs_yaml(lat_initramfs_yaml):
logger.error("Failed to update LAT initramfs yaml file for rt type")
sys.exit(1)
if not change_default_kernel(lat_yaml, kernel_type):
logger.error("Failed to change the default boot kernel")
sys.exit(1)
if add_lat_packages(lat_yaml, img_pkgs):
os.system(' '.join(['latc --file=' + lat_yaml, '-t', kernel_type, 'build']))