#!/bin/sh
#
#    Copyright (c) 2003-2004 Brocade Communications Systems, Inc.
#    All rights reserved.
#
#    File name:	prominst_athena
#
#    The script will install prom package for Athena and Pulsar. 
#
PATH=/bin:/usr/bin:/sbin:/usr/sbin

OK=0
echo "Please avoid powering off the system during prom update."

#
# During HCL, /dev between new and older kernel
# are not synced so create prom/mtd nodes
# for prom install
#
/bin/ls /dev/mtd0 >/dev/null 2>&1
if [ $? -ne 0 ]; then
	mknod --mode=644 /dev/mtd0 c 90 0
fi

/bin/ls /dev/mtd1 >/dev/null 2>&1
if [ $? -ne 0 ]; then
	mknod --mode=644 /dev/mtd1 c 90 2
fi

/bin/ls /dev/prom0 >/dev/null 2>&1
if [ $? -ne 0 ]; then
	/bin/ln -s /dev/mtd0 /dev/prom0
fi

/bin/ls /dev/prom1 >/dev/null 2>&1
if [ $? -ne 0 ]; then
	/bin/ln -s /dev/mtd1 /dev/prom1
fi

for i in `seq 3`; do
        nohup /sbin/flash_write -i /boot/bootrom.bin \
		-o /dev/prom0 >/dev/null 2>&1

        if [ $? -eq 0 ]; then
        	nohup /sbin/flash_write -i /boot/bootrom.bin \
			-o /dev/prom1 >/dev/null 2>&1

        	if [ $? -eq 0 ]; then
        		OK=1	
			break;
		fi
	fi
done

if [ $OK -ne 1 ]; then
        echo "Failed to write to prom partition!"
        exit 1
fi
