#!/bin/sh

# Set the LD_LIBRARY_PATH for the interdependency
export PATH=$PATH:/bin:/sbin:/mnt/bin:/mnt/sbin

IMAGE=$1
if [ -z "$IMAGE" ]; then
	echo "update_uimage: no image file."
	exit 1
fi

# HV will load the image from GOS0'0 area to boot GOS0 as well as GOS1.
# So no need to load the image on GOS1 in order to alleviate the DRAM
# contention (big memory write block) and eliminate unnecessary I/O.
#
if [ "`cat /proc/device-tree/label 2>/dev/null`" = "p1-linux" ]; then
	echo "update uimage from $IMAGE..."
	node="uImage"
	major=`grep $node\$ /proc/devices | cut -d ' ' -f 1`
	if [ $major ]; then
		rm -f /dev/$node
    		mknod  /dev/$node c $major 0
	else
		echo "update_uimage: no device."
		exit 1
	fi
	cat $IMAGE>/dev/$node
fi

if bootenv bootargs 2>/dev/null | grep quiet; then
	mode=quiet
fi
root=`bootenv OSRootPartition 2>/dev/null | cut -d ';' -f 1`
partman setprop -h -1 -p /chosen -n bootargs -t "root=/dev/$root $mode"

exit 0
