kernel/uki_create_addons.py
Justin M. Forbes 10b8721114
kernel-6.15.1-200
* Wed Jun 04 2025 Justin M. Forbes <jforbes@fedoraproject.org> [6.15.1-0]
- arm64: dts: rockchip: Drop assigned-clock* from cpu nodes on rk3588 (Diederik de Haas)
- arm64: dts: rockchip: Improve LED config for NanoPi R5S (Diederik de Haas)
- arm64: dts: rockchip: Move rk3568 PCIe3 MSI to use GIC ITS (Chukun Pan)
- arm64: dts: rockchip: Update eMMC for NanoPi R5 series (Peter Robinson)
- arm64: dts: rockchip: Add vcc-supply to SPI flash on rk3566-rock3c (Peter Robinson)
- arm64: dts: rockchip: Add vcc-supply to SPI flash on rk3566-quartz64-b (Diederik de Haas)
- arm64: dts: rockchip: Add phy-supply to gmac0 on NanoPi R5S (Diederik de Haas)
- arm64: dts: rockchip: Add vcc-supply to SPI flash on rk3588-rock-5b (Diederik de Haas)
- arm64: dts: rockchip: Add vcc-supply to SPI flash on rk3399-rockpro64 (Diederik de Haas)
- arm64: dts: rockchip: Add vcc-supply to SPI flash on rk3328-rock64 (Diederik de Haas)
- arm64: dts: rockchip: Move SHMEM memory to reserved memory on rk3588 (Chukun Pan)
- arm64: dts: rockchip: Add gmac phy reset GPIO to QNAP TS433 (Uwe Kleine-König)
- arm64: dts: rockchip: Correct gmac phy address on QNAP TS433 (Uwe Kleine-König)
- Reset build id for fedora-srpm script (Justin M. Forbes)
- redhat/configs: Add configs for new ov02c10 and ov02e10 drivers (Hans de Goede)
- media: i2c: Add Omnivision OV02C10 sensor driver (Heimir Thor Sverrisson)
- media: i2c: ov02e10: add OV02E10 image sensor driver (Jingjing Xiong)
- platform/x86: int3472: Debug log when remapping pins (Hans de Goede)
- platform/x86: int3472: Add handshake pin support (Hans de Goede)
- platform/x86: int3472: Prepare for registering more than 1 GPIO regulator (Hans de Goede)
- platform/x86: int3472: Avoid GPIO regulator spikes (Hans de Goede)
- platform/x86: int3472: Make regulator supply name configurable (Hans de Goede)
- platform/x86: int3472: Rework AVDD second sensor quirk handling (Hans de Goede)
- platform/x86: int3472: Drop unused gpio field from struct int3472_gpio_regulator (Hans de Goede)
- platform/x86: int3472: Stop setting a supply-name for GPIO regulators (Hans de Goede)
- platform/x86: int3472: Add skl_int3472_register_clock() helper (Hans de Goede)
- powerpc: Fix struct termio related ioctl macros (Madhavan Srinivasan)
- Initial setup for stable Fedora releases (Justin M. Forbes)
- Reset RHEL_RELEASE for the 6.16 cycle (Justin M. Forbes)
- fedora: add 'fedora' SBAT suffix for UKI addons (Li Tian)
- redhat: add downstream SBAT for UKI addons (Emanuele Giuseppe Esposito)
- uki_addons: provide custom SBAT as input parameter (Emanuele Giuseppe Esposito)
- uki_addons: remove completely sbat/sbat.conf (Emanuele Giuseppe Esposito)
- Linux v6.15.1
Resolves:

Signed-off-by: Justin M. Forbes <jforbes@fedoraproject.org>
2025-06-04 22:54:37 -06:00

136 lines
4.3 KiB
Python
Executable file

#!/usr/bin/env python3
#
# This script inspects a given json proving a list of addons, and
# creates an addon for each key/value pair matching the given uki, distro and
# arch provided in input.
#
# Usage: python uki_create_addons.py input_json out_dir uki distro arch [sbat]
#
# This tool requires the systemd-ukify and systemd-boot packages.
#
# Addon file
#-----------
# Each addon terminates with .addon
# Each addon contains only two types of lines:
# Lines beginning with '#' are description and thus ignored
# All other lines are command line to be added.
# The name of the end resulting addon is taken from the json hierarchy.
# For example, and addon in json['virt']['rhel']['x86_64']['hello.addon'] will
# result in an UKI addon file generated in out_dir called
# hello-virt.rhel.x86_64.addon.efi
#
# The common key, present in any sub-dict in the provided json (except the leaf dict)
# is used as place for default addons when the same addon is not defined deep
# in the hierarchy. For example, if we define test.addon (text: 'test1\n') in
# json['common']['test.addon'] = ['test1\n'] and another test.addon (text: test2) in
# json['virt']['common']['test.addon'] = ['test2'], any other uki except virt
# will have a test.addon.efi with text "test1", and virt will have a
# test.addon.efi with "test2"
import os
import sys
import json
import collections
import subprocess
UKIFY_PATH = '/usr/lib/systemd/ukify'
def usage(err):
print(f'Usage: {os.path.basename(__file__)} input_json output_dir uki distro arch [sbat]')
print(f'Error:{err}')
sys.exit(1)
def check_clean_arguments(input_json, out_dir):
# Remove end '/'
if out_dir[-1:] == '/':
out_dir = out_dir[:-1]
if not os.path.isfile(input_json):
usage(f'input_json {input_json} is not a file, or does not exist!')
if not os.path.isdir(out_dir):
usage(f'out_dir_dir {out_dir} is not a dir, or does not exist!')
return out_dir
UKICmdlineAddon = collections.namedtuple('UKICmdlineAddon', ['name', 'cmdline'])
uki_addons_list = []
uki_addons = {}
def parse_lines(lines):
cmdline = ''
for l in lines:
l = l.lstrip()
if not l:
continue
if l[0] == '#':
continue
cmdline += l.rstrip() + ' '
if cmdline == '':
return ''
return cmdline
def parse_all_addons(in_obj):
for el in in_obj.keys():
# addon found: copy it in our global dict uki_addons
if el.endswith('.addon'):
uki_addons[el] = in_obj[el]
def recursively_find_addons(in_obj, folder_list):
# end of recursion, leaf directory. Search all addons here
if len(folder_list) == 0:
parse_all_addons(in_obj)
return
# first, check for common folder
if 'common' in in_obj:
parse_all_addons(in_obj['common'])
# second, check if there is a match with the searched folder
if folder_list[0] in in_obj:
folder_next = in_obj[folder_list[0]]
folder_list = folder_list[1:]
recursively_find_addons(folder_next, folder_list)
def parse_in_json(in_json, uki_name, distro, arch):
with open(in_json, 'r') as f:
in_obj = json.load(f)
recursively_find_addons(in_obj, [uki_name, distro, arch])
for addon_name, cmdline in uki_addons.items():
addon_name = addon_name.replace(".addon","")
addon_full_name = f'{addon_name}-{uki_name}.{distro}.{arch}.addon.efi'
cmdline = parse_lines(cmdline).rstrip()
if cmdline:
uki_addons_list.append(UKICmdlineAddon(addon_full_name, cmdline))
def create_addons(out_dir, sbat):
for uki_addon in uki_addons_list:
out_path = os.path.join(out_dir, uki_addon.name)
cmd = [
f'{UKIFY_PATH}', 'build',
'--cmdline', uki_addon.cmdline,
'--output', out_path]
if sbat:
cmd.extend(['--sbat', sbat.rstrip()])
subprocess.check_call(cmd, text=True)
if __name__ == "__main__":
argc = len(sys.argv) - 1
if argc < 5 or argc > 6:
usage('too few or too many parameters!')
input_json = sys.argv[1]
out_dir = sys.argv[2]
uki_name = sys.argv[3]
distro = sys.argv[4]
arch = sys.argv[5]
custom_sbat = None
if argc == 6:
custom_sbat = sys.argv[6]
out_dir = check_clean_arguments(input_json, out_dir)
parse_in_json(input_json, uki_name, distro, arch)
create_addons(out_dir, custom_sbat)