# shellcheck shell=sh

######### BEGIN /usr/share/flash-kernel/ubootenv.d/00reform2_ubootenv #########
# Default bootargs for Linux are set here and can be overwritten using
# LINUX_KERNEL_CMDLINE in /etc/default/flash-kernel or by setting ${bootargs}
# in u-boot itself via the setenv command.
# shellcheck disable=SC2154
setenv bootargs "ro no_console_suspend cryptomgr.notests plymouth.ignore-serial-consoles pcie_aspm=off ${bootargs}"

# Board-specific bootargs cannot be overwritten by above methods. If you
# really need to overwrite below lines, create
# /etc/flash-kernel/ubootenv.d/00reform2_ubootenv and fill it with what you
# would like to replace the contents of this file with.
#
# This block is only needed for boards which might still run with an older
# version of u-boot and thus might not yet set ${bootargs} correctly.
# shellcheck disable=SC2154
if test "${board}" = "nitrogen8m_som"; then
  setenv bootargs "${bootargs} console=ttymxc0,115200 cma=512M pci=nomsi"
elif test "${board}" = "MNT Reform 2.0"; then
  # some imx8mq Reforms have this board value
  setenv bootargs "${bootargs} console=ttymxc0,115200 cma=512M pci=nomsi"
elif test "${board}" = "u200"; then
  # amlogic internal name for a311d dev board
  setenv bootargs "${bootargs} console=ttyAML0,115200 pci=pcie_bus_perf libata.force=noncq nvme_core.default_ps_max_latency_us=0"
elif test "${board}" = "ls1028a"; then
  setenv bootargs "${bootargs} console=ttyS0,115200 cma=512M@3G iommu.passthrough=1 arm-smmu.disable_bypass=0"
elif test "${board}" = "nitrogen8mp"; then
  # If fdt_addr_r was the old offset, then extlinux probably failed to load the
  # kernel but u-boot remembers the kernel cmdline of the last entry and that
  # one was the rescue option which contains the term "single". Reset bootargs.
  if test "${fdt_addr_r}" = "0x43000000"; then
    setenv bootargs "ro no_console_suspend pci=pcie_bus_perf cryptomgr.notests plymouth.ignore-serial-consoles pcie_aspm=off fbcon=font:TER16x32 nvme_core.default_ps_max_latency_us=0 cma=256MB console=ttymxc1"
  fi

  # Fix up destination addresses for kernel, dtb and initrd on imx8m+
  # Updating u-boot on imx8m+ is risky because recovery is complicated if
  # something fails. Thus, many users will (for good reason) never update their
  # original u-boot on eMMC.
  # We perform fix-ups of the hardcoded loading addresess here. The default
  # offsets are:
  # ${kernel_addr_r}  = 0x40480000
  # ${fdt_addr_r}     = 0x43000000
  # ${ramdisk_addr_r} = 0x43800000

  # Avoid moving the kernel in RAM to the next 2 MiB boundary on every boot by
  # placing it at a 2 MiB offset from the beginning.
  setenv kernel_addr_r "0x40600000"

  # Starting with kernel 7.3, the image became so large that given the chosen
  # default offsets are not large enough anymore after the kernel was relocated
  # to the next 2 MiB boundary from from 0x40480000 to 0x40600000 it ended at
  # 0x43160000 thus overwriting the dtb.
  # We bump the offsets of dtb and initrd by another 4 MiB
  setenv fdt_addr_r "0x43400000"
  setenv ramdisk_addr_r "0x43c00000"
fi

# console=tty1 needs to go at the end of the kernel cmdline because the luks
# passphrase prompt will show up on the last console which must not be the
# serial terminal but the tty displayed to the screen
setenv bootargs "${bootargs} console=tty1"
########## END /usr/share/flash-kernel/ubootenv.d/00reform2_ubootenv ##########
