Newer
Older
Mick Michalski
committed
#!/bin/sh
Mick Michalski
committed
get_fuse () {
local name=$1
local pad=$2
# read the fuse and pad the left with zeros to the size of $pad
local fuse="0000000000"$(cat /sys/fsl_otp/$name | cut -b 3-)
Mick Michalski
committed
len=$(( ${#fuse} - $pad ))
echo ${fuse:$len}
}
get_sn () {
local base=$1
local arena=$(get_fuse HW_OCOTP_GP$base 7)
if [[ ${arena:0:2} == "00" ]] ; then
# starts with "00", so doesn't start with ascii hex value
Mick Michalski
committed
arena=${arena:2}
else
# doesn't start with "00", so starts with ascii hex value
Mick Michalski
committed
arena=$(printf "\x${arena:0:2}${arena:2}")
fi
local build=$(get_fuse HW_OCOTP_GP$(( $base + 1)) 4)
local unit=$(get_fuse HW_OCOTP_GP$(( $base + 2)) 5)
echo "$arena$build-$unit"
}
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#Read create custom serial number from fuses
get_custom_sn() {
local fuse_70=`cat /sys/fsl_otp/HW_OCOTP_GP70`
local fuse_71=`cat /sys/fsl_otp/HW_OCOTP_GP71`
local fuse_72=`cat /sys/fsl_otp/HW_OCOTP_GP72`
local strhex
#Check for empty fuse bank
if [ ${fuse_72} != "0x0" ]; then
strhex=${fuse_72:2:8}
fi
#Check for empty fuse bank
if [ ${fuse_71} != "0x0" ]; then
strhex=${strhex}${fuse_71:2:8}
fi
strhex=${strhex}${fuse_70:2:8}
local i=1
max=$(( ${#strhex} + 1 ))
#convert hex string to ascii string
while [ $i -lt $max ]
do
hex='\x'`echo $strhex | cut -c $i-$(( i + 1 ))`
custom_sn=$custom_sn$hex
i=$(( i + 2 ))
done
echo -e $custom_sn
}
if [[ "$(cat /sys/fsl_otp/HW_OCOTP_GP70)" != "0x0" ]] ; then
hostname $(get_custom_sn)
elif [[ "$(cat /sys/fsl_otp/HW_OCOTP_GP37)" == "0x0" ]] ; then
# No unit serial number set, use board serial number
Mick Michalski
committed
hostname $(get_sn 34).$url
Mick Michalski
committed
hostname $(get_sn 37).$url

Pete Tucker
committed

Pete Tucker
committed
NAME=$(hostname)
SHORTNAME=$(hostname | cut -b -16)
NEWLINE="127.0.0.0 $NAME $SHORTNAME"