#!/bin/bash

set -x

diskname=$1

#==========================================
# install MLO as raw
#------------------------------------------
if [ -f "boot/MLO" ];then
    opt="count=1 seek=1 conv=notrunc"
    if ! dd if=boot/MLO of=$diskname bs=128k $opt; then
        echo "Couldn't install MLO on $diskname"
        exit 1
    fi
    # /.../
    # To avoid any issues when parted leaves x86 boot code
    # in the MBR we better clear that part of the image
    # ----
    dd if=/dev/zero of=$diskname bs=440 count=1 conv=notrunc
fi

#==========================================
# install Origen SPL & u-boot as raw
#------------------------------------------
if [ -f "boot/origen-spl.bin" ];then
    if ! dd if=boot/origen-spl.bin of=$diskname seek=1 conv=notrunc; then
        echo "Couldn't install SPL on $diskname"
        exit 1
    fi
    if ! dd if=boot/u-boot.bin of=$diskname seek=65 conv=notrunc; then
        echo "Couldn't install u-boot on $diskname"
        exit 1
    fi
fi
