#!/bin/sh

SCRIPT_DIR="$(dirname $0)"
BOARD_DIR="${SCRIPT_DIR}/board/raspmx"

mkdir -p ${BOARD_DIR}

## create 2-types boot.scr
(
  echo 'setenv finduuid "part uuid mmc 0:1 uuid"'
  echo 'run finduuid'
  echo 'setenv bootargs "console=ttymxc0,115200 root=PARTUUID=${uuid} rootwait rootfstype=ext4"'
  echo 'load mmc 0:1 ${fdt_addr} boot/${fdtfile}'
  echo 'load mmc 0:1 ${loadaddr} boot/zImage'
  echo 'bootz ${loadaddr} - ${fdt_addr}'
) > ${BOARD_DIR}/boot.scr.ext.txt

(
  #echo 'setenv finduuid "part uuid mmc 0:1 uuid"'
  #echo 'run finduuid'
  #echo 'setenv bootargs "console=ttymxc0,115200 root=PARTUUID=${uuid} rootwait rootfstype=ext4"'
  echo 'setenv bootargs "console=ttymxc0,115200 root=/dev/ram0 rootwait rootfstype=ext4"'
  echo 'fatload mmc 0:1 ${fdt_addr} boot/${fdtfile}'
  echo 'fatload mmc 0:1 ${ramdiskaddr} boot/rootfs.ext4.gz'
  echo 'fatload mmc 0:1 ${loadaddr} boot/zImage'
  echo 'bootz ${loadaddr} ${ramdiskaddr} ${fdt_addr}'
) > ${BOARD_DIR}/boot.scr.fat.txt

${HOST_DIR}/usr/bin/mkimage -A arm -O linux -T script -C none  \
-n "boot script" -d ${BOARD_DIR}/boot.scr.ext.txt ${BOARD_DIR}/boot.scr

${HOST_DIR}/usr/bin/mkimage -A arm -O linux -T script -C none  \
-n "boot script" -d ${BOARD_DIR}/boot.scr.fat.txt ${BOARD_DIR}/boot.scr.fat

install -m 0644 -D ${BOARD_DIR}/boot.scr ${TARGET_DIR}/boot/boot.scr

