stages/grub2.legacy: replace arch with platform

The `architecture` served two purposes: 1) the selection of the loader
and 2) the selection of the platform. Instead of inferring the latter
from `architecture`, it is now explicitly specified as a property of
the `bios` value, which in turn was transformed into an object.
The loader is still inferred but since `bios` is an object now there
is the option of adding an explicit `loader` option to it.
All this should make it more transparent what is happening and is
also more in line with the normal `grub2` stage.
This commit is contained in:
Christian Kellner 2022-05-28 20:14:04 +02:00
parent dcc56d083f
commit e1c2d642dc

View file

@ -89,21 +89,25 @@ SCHEMA = """
} }
}, },
"additionalProperties": false, "additionalProperties": false,
"required": ["rootfs", "architecture", "entries"], "required": ["rootfs", "entries"],
"anyOf": [{ "anyOf": [{
"required": ["bios"] "required": ["bios"]
}, { }, {
"required": ["uefi"] "required": ["uefi"]
}], }],
"properties": { "properties": {
"architecture": {
"enum": ["x86", "aarch64", "ppc64le"]
},
"rootfs": { "$ref": "#/definitions/filesystem" }, "rootfs": { "$ref": "#/definitions/filesystem" },
"bootfs": { "$ref": "#/definitions/filesystem" }, "bootfs": { "$ref": "#/definitions/filesystem" },
"bios": { "bios": {
"description": "Include bios boot support", "description": "Include bios boot support",
"type": "boolean" "type": "object",
"required": ["platform"],
"properties": {
"platform": {
"type": "string",
"enum": ["i386-pc", "powerpc-ieee1275"]
}
}
}, },
"uefi": { "uefi": {
"description": "Include UEFI boot support", "description": "Include UEFI boot support",
@ -285,19 +289,6 @@ def copy_efi_data(tree, vendor):
symlinks=False) symlinks=False)
def architecture_to_platform(architecture):
platform_map = {
"x86": "i386-pc",
"ppc64le": "powerpc-ieee1275"
}
platform = platform_map.get(architecture)
if not platform:
raise ValueError(f"Unsupported architecture: {architecture}")
return platform
class GrubEntry: class GrubEntry:
class Product: class Product:
@ -342,8 +333,8 @@ class GrubEntry:
class GrubConfig: class GrubConfig:
def __init__(self, architecture, rootfs, bootfs): def __init__(self, bios, rootfs, bootfs):
self.architecture = architecture self.bios = bios
self.rootfs = rootfs self.rootfs = rootfs
self.bootfs = bootfs self.bootfs = bootfs
self.entries = [] self.entries = []
@ -398,8 +389,8 @@ class GrubConfig:
fs_type, fs_id = fs_spec_decode(self.rootfs) fs_type, fs_id = fs_spec_decode(self.rootfs)
rootfs = f"{fs_type}={fs_id}" if fs_type else fs_id rootfs = f"{fs_type}={fs_id}" if fs_type else fs_id
loader = "" loader = "" # default to `linux`, i.e. no suffix
if self.architecture == "x64": if self.bios.get("platform", "") == "i386-pc":
loader = "efi" if uefi else "16" loader = "efi" if uefi else "16"
# configuration options for the main template # configuration options for the main template
@ -467,7 +458,6 @@ class GrubConfig:
# pylint: disable=too-many-statements # pylint: disable=too-many-statements
def main(tree, options): def main(tree, options):
architecture = options["architecture"]
root_fs = options["rootfs"] root_fs = options["rootfs"]
boot_fs = options.get("bootfs") boot_fs = options.get("bootfs")
bios = options.get("bios") bios = options.get("bios")
@ -476,7 +466,7 @@ def main(tree, options):
# Prepare the actual grub configuration file, will be written further down # Prepare the actual grub configuration file, will be written further down
cfg = options.get("config", {}) cfg = options.get("config", {})
config = GrubConfig(architecture, root_fs, boot_fs) config = GrubConfig(bios, root_fs, boot_fs)
config.cmdline = cfg.get("cmdline", "") config.cmdline = cfg.get("cmdline", "")
config.distributor = cfg.get("distributor") config.distributor = cfg.get("distributor")
config.serial = cfg.get("serial") config.serial = cfg.get("serial")
@ -532,8 +522,7 @@ def main(tree, options):
if bios: if bios:
# Now actually write the main grub.cfg file # Now actually write the main grub.cfg file
config.write(tree, "boot/grub2/grub.cfg", False) config.write(tree, "boot/grub2/grub.cfg", False)
platform = architecture_to_platform(architecture) copy_modules(tree, bios["platform"])
copy_modules(tree, platform)
copy_font(tree) copy_font(tree)
return 0 return 0