#!/bin/sh
#
# DEV ONLY — inject the KTB1 K_tpm blob into DDR before dek-release runs.
#
# This is the runtime-injection shortcut: the blob comes from a file on the
# root filesystem, so anyone with root on the board can replace K_tpm. The
# production image must carry KTB1 inside BOOT.bin instead and must NOT
# install this script.
#
case "$1" in
  start)
    if [ ! -x /home/root/provision_dek ]; then
      echo "ktpm-dev-inject: /home/root/provision_dek missing, skipping" > /dev/kmsg 2>/dev/null
      exit 0
    fi
    if [ ! -f /home/root/k_tpm.inject ]; then
      echo "ktpm-dev-inject: /home/root/k_tpm.inject missing, skipping" > /dev/kmsg 2>/dev/null
      exit 0
    fi
    if /home/root/provision_dek /home/root/k_tpm.inject 0x01800000; then
      echo "ktpm-dev-inject: KTB1 injected at 0x01800000 (DEV SHORTCUT)" > /dev/kmsg 2>/dev/null
    else
      echo "ktpm-dev-inject: injection failed" > /dev/kmsg 2>/dev/null
      exit 1
    fi
    ;;
  stop) : ;;
  *)
    echo "usage: $0 {start|stop}"
    exit 1
    ;;
esac
