#!/bin/sh
# OPTIONAL GRUB entry (not installed by default): delay the host kernel so the
# board's PL is configured before the host scans PCIe.
#
# WHEN TO USE
#   Only if a host's BIOS POST is fast enough that its kernel PCI scan beats
#   the board's bitstream load. Measured 2026-10-23 on .124 (H81U) + .234:
#     board power-on  -> PL operating   ~5-7 s  (dekrelease logs uptime 4.01 s)
#     host power-on   -> kernel PCI scan ~12-15 s (POST + GRUB)
#   The board normally wins that race, so the delay is insurance, not the
#   default path. Re-measure before relying on it on different hardware.
#
# WHAT IT DOES NOT FIX
#   Restarting the board while the host is already running leaves the link at
#   2.5 GT/s and the endpoint not answering config; rescan and Secondary Bus
#   Reset both fail there — the host must be rebooted. No boot delay helps.
#
# INSTALL (keeps the default entry untouched)
#   cp 42_dek_test_delay /etc/grub.d/ && chmod +x /etc/grub.d/42_dek_test_delay
#   update-grub
# ONE-TIME BOOT
#   grub-reboot "DEK-PCIE TEST (delay 90)"
#
# Adjust the kernel version / boot UUID / initrd path for the target host.
exec tail -n +3 $0
menuentry "DEK-PCIE TEST (delay 90)" {
    load_video
    insmod gzio
    insmod part_gpt
    insmod ext2
    search --no-floppy --fs-uuid --set=root 2af2f69c-100c-46ac-86e2-cc4af3c678af
    insmod sleep
    sleep 90
    linux   /vmlinuz-5.15.0-198-generic root=/dev/mapper/ubuntu--vg-ubuntu--lv ro dek=1 panic=0
    initrd  /dek_test/initrd.img-5.15.0-198-generic
}
