Loading...
# SPDX-License-Identifier: GPL-2.0+
# Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.

"""Create Ubuntu test disk images"""

from img.common import setup_extlinux_image


def setup_ubuntu_image(config, log, devnum, basename, version='24.04.1 LTS',
                       use_fde=0, luks_kdf='pbkdf2'):
    """Create a Ubuntu disk image with a FAT partition and ext4 partition

    This creates a FAT partition containing extlinux files, kernel, etc. and a
    separate ext4 partition containing the root disk

    Args:
        config (ArbitraryAttributeContainer): Configuration
        log (multiplexed_log.Logfile): Log to write to
        devnum (int): Device number to use, e.g. 1
        basename (str): Base name to use in the filename, e.g. 'mmc'
        use_fde (int): LUKS version for full-disk encryption (0=none, 1=LUKS1, 2=LUKS2)
        luks_kdf (str): Key derivation function for LUKS2: 'pbkdf2' or 'argon2id'.
            Defaults to 'pbkdf2'. Ignored for LUKS1.
    """
    vmlinux = 'vmlinuz-6.8.0-53-generic'
    initrd = 'initrd.img-6.8.0-53-generic'
    dtbdir = None
    script = '''## /boot/extlinux/extlinux.conf
##
## IMPORTANT WARNING
##
## The configuration of this file is generated automatically.
## Do not edit this file manually, use: u-boot-update

default l0
menu title U-Boot menu
prompt 1
timeout 50


label l0
	menu label Ubuntu %s 6.8.0-53-generic
	linux /boot/%s
	initrd /boot/%s

	append root=/dev/disk/by-uuid/bcfdda4a-8249-4f40-9f0f-7c1a76b6cbe8 ro earlycon

label l0r
	menu label Ubuntu %s 6.8.0-53-generic (rescue target)
	linux /boot/%s
	initrd /boot/%s
''' % ((version, vmlinux, initrd) * 2)
    setup_extlinux_image(config, log, devnum, basename, vmlinux, initrd, dtbdir,
                         script, part2_size=60 if use_fde else 1,
                         use_fde=use_fde, luks_kdf=luks_kdf)