# vim: filetype=sh

# bootloader management
# ---------------------

# configure the bootloader appropriately, given the variable $kernel_bootargs
# and any other target-specific requirements.

configure_bootloader()
{
    # get existing conf in chroot environment if any...
    # sample code:
    # if [ -f /boot/cmdline.txt ]
    # then
    #    existing_bootargs=$(cat /boot/cmdline.txt)
    # fi

    # our mandatory options
    mandatory_bootargs="root=<some-device> rootfstype=ext4 rootwait"

    # The user may specify more bootarg customization by giving
    # them on the command line (option --config-kernel-bootargs).
    # Specifying "<bootarg>[=<value>]" or "+<bootarg>[=<value>]"
    # allows to add or overwrite any previous definition of <bootarg>.
    # Specifying "-<bootarg>" allows to remove any definition of
    # <bootarg> from the kernel cmdline.
    explicit_bootargs=$kernel_bootargs

    # order of precedence is:
    # explicit_bootargs > mandatory_bootargs > existing_bootargs
    applied_kernel_cmdline="$(aggregate_kernel_cmdline $existing_bootargs \
                        $mandatory_bootargs $explicit_bootargs)"

    # write computed $applied_kernel_cmdline in appropriate configuration file...
}

# install the bootloader on $loop_device

install_bootloader()
{
    my_bootloader_install $loop_device
}
