# 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
    if [ -f /boot/cmdline.txt ]
    then
        existing_bootargs=$(cat /boot/cmdline.txt)
    fi

    # our mandatory options
    mandatory_bootargs="root=/dev/mmcblk0p2 rootfstype=ext4 rootwait"

    # and the user may specify more bootarg customization by giving
    # them on the command line
    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)"

    echo $applied_kernel_cmdline > /boot/cmdline.txt
}

# install the bootloader on $loop_device

install_bootloader()
{
    # nothing to do here, package raspberrypi-bootloader should have installed the
    # appropriate files in /boot.
    :   # colon is no-op in shell
}
