#!/bin/sh
# init-premount script: C2H DMA key retrieval
# Runs before root mount in initramfs.
# NOTE: do NOT add "exit" — this file is sourced by init, not executed.
echo "P0: C2H start" > /dev/kmsg
/bin/c2h_getkey 40 > /tmp/p0_key 2>/tmp/p0_log
echo "P0: exit=$?" > /dev/kmsg
if [ -s /tmp/p0_key ]; then
    mkdir -p /mnt/boot
    mount /dev/sda2 /mnt/boot 2>/dev/null && cp /tmp/p0_key /mnt/boot/p0_key.bin && cp /tmp/p0_log /mnt/boot/p0_log.txt && umount /mnt/boot && echo "P0: saved" > /dev/kmsg
fi
