#!/bin/sh

legacy_machine_id() { # return the machine ID
	awk 'BEGIN { FS=": " } /Hardware/ \
		{ gsub(" ", "_", $2); print tolower($2) } ' </proc/cpuinfo
}

machine_id() { # return the machine ID
	cat /proc/cpuinfo | grep Hardware | awk -F" " '{ print $4 }'
}

if [ "$(machine_id)" = "ti8168evm" -o "$(legacy_machine_id)" = "ti8168evm" ] ; then
	echo TI816x
elif [ "$(machine_id)" = "AM33XX" -o "$(legacy_machine_id)" = "am335xevm" ] ; then
	echo TI33XX
elif [ "$(machine_id)" = "AM43" ] ; then
	echo TI43XX
else
	devmem2 0x4800244c | \
	grep 'Read at address' | \
	sed -e 's/.*): //' | \
	sed -e 's/0x00005C00/OMAP3503/' -e 's/0x00001C00/OMAP3515/' -e 's/0x00004C00/OMAP3525/' -e 's/0x00000C00/OMAP3530/' \
		-e 's/0x00005E00/OMAP3503/' -e 's/0x00001E00/OMAP3515/' -e 's/0x00004E00/OMAP3525/' -e 's/0x00000E00/OMAP3530/' \
		-e 's/0x00000CC0/OMAP3530/'
fi
