AN 957: Time-Sensitive Networking for Drive-on-Chip Design Example

ID 683707
Date 10/30/2021
Public
Document Table of Contents

D. Script to read and change MAC addresses from Cyclone V SoC EEPROM

To check the physical addresses in the Cyclone V SoC development board, for the TSN Drive-on-Chip Design example.
#!/bin/sh
# Get a MAC address from the EEPROM from a given offset.
get_mac()
{
    ret_mac=""
    i2cset -y 0 0x51 0 $1 i
    for i in 0 1 2 3 4 5; do
        ret_mac=$ret_mac$(i2cget -y 0 0x51 | sed 's/0x/:/')
    done
    echo ${ret_mac#:}
}

help()
{
        echo " "
        echo "To read and write physical MAC addresses in the Cyclone V SoC"
        echo "To read type:"
        echo "     >> ./Read_Write_MAC_CVSX.sh read"
        echo "To write type:"
        echo "     >> ./Read_Write_MAC_CVSX.sh write <MAC address> <offset>"
        echo "Example"
        echo "     >> ./Read_Write_MAC_CVSX.sh write AA:BB:CC:DD:FF:GG 45"
        echo "This script does not validate the address, MAC addresses must be typed only in the prev
        echo " "

}

case "$1" in
    read)
        echo 'Reading the EEPROM...'
        echo 'MAC store in addres offset 45' $(get_mac 45)
        echo 'MAC store in addres offset 51' $(get_mac 51)
        echo 'MAC store in addres offset 57' $(get_mac 57)
        echo 'MAC store in addres offset 63' $(get_mac 63)
        echo 'MAC store in addres offset 69' $(get_mac 69)
        echo 'MAC store in addres offset 75' $(get_mac 75)
        echo ' '
    ;;

    write)
        echo " "
        echo "Writing EEPROM..."
        A1="$(cut -d':' -f1 <<< $2)"
        A2="$(cut -d':' -f2 <<< $2)"
        A3="$(cut -d':' -f3 <<< $2)"
        A4="$(cut -d':' -f4 <<< $2)"
        A5="$(cut -d':' -f5 <<< $2)"
        A6="$(cut -d':' -f6 <<< $2)"

        i2cset -y 0 0x51  0 $3 0x$A1 i
        i2cset -y 0 0x51  0 $(($3+1)) 0x$A2 i
        i2cset -y 0 0x51  0 $(($3+2)) 0x$A3 i
        i2cset -y 0 0x51  0 $(($3+3)) 0x$A4 i
        i2cset -y 0 0x51  0 $(($3+4)) 0x$A5 i
        i2cset -y 0 0x51  0 $(($3+5)) 0x$A6 i
        echo "Address $2 written to EEPROM offset $3"
        echo ' '
    ;;

    *)                                               
        help                                         
    ;;                                               
                                                       
esac        
exit 0