Skip to content

Commit

Permalink
factory: burn mac based on factory serial
Browse files Browse the repository at this point in the history
  • Loading branch information
svenrademakers committed Aug 7, 2024
1 parent 27f0b97 commit 8c52636
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 16 deletions.
3 changes: 2 additions & 1 deletion tp2bmc/board/tp2bmc/factory_overlay/upper/factory/config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
PRODUCT_NAME="TuringPi2"
PRODUCT_SERIAL_PREFIX=""
# production month. format= 'YYmm'
PRODUCTION_TIME="2406"
PRODUCTION_TIME="2408"

RK1_USERNAME=ubuntu
RK1_PASSWORD=Turingpi123
Expand All @@ -19,3 +19,4 @@ NODE4_IP="192.168.0.104"
ASSERT_VERSION=4211
ASSERT_MODEL_NAME="Turing Pi 2 (v2.5.1)"

TPI_MAC_BASE="C4FF841"
Original file line number Diff line number Diff line change
@@ -1,20 +1,7 @@
#!/bin/bash

read -p "Enter the the last digits of product serial from the sticker: ${PRODUCT_SERIAL_PREFIX}${PRODUCTION_TIME}" serial

./install_firmware
if [[ $? -ne 0 ]]; then
echo -e "${RED} installation of firmware failed!${NC}"
exit 1
fi

# insert cookie to be picked up by bootloader.
# This signals the bootloader not load the factory image, but too boot from
# flash
install_magic=0x12341234
install_addr=0x0709010C
devmem $install_addr 32 $install_magic

source config.sh
read -p "Enter product serial from the sticker: ${PRODUCT_SERIAL_PREFIX}" serial

days_since_may() {
# Extract year and month from PRODUCTION_TIME
Expand All @@ -35,13 +22,47 @@ local diff_days=$((diff_seconds / 86400))
echo "$diff_days"
}

generate_mac() {
# its been told that the factory serial is composed out of the following
# elements:
# XZC:Our company name initial
# T: project name of Turing PI initial
# 2211:Production time November 2022
# 00605:Product serial number

# get the last five digits
local product_digits=$((10#${serial: -5}))
if ! [[ "$product_digits" =~ ^[0-9]+$ ]]; then
echo -e "${RED} ERROR: provided serial is not correct. Expected a serial ending with at least containing 5 digits${NC}"
exit 1
fi

eui_48=$(printf "%05X" "$product_digits")
echo "${TPI_MAC_BASE}${eui_48}"
}

generated_mac=$(generate_mac)

tpi_factory_serial="${PRODUCT_SERIAL_PREFIX}${serial}" \
tpi_product_name="$PRODUCT_NAME" \
tpi_production_time="$(days_since_may)" \
tpi_mac="$generated_mac" \
tpi eeprom set

if [[ $? -ne 0 ]]; then
echo -e "${RED} Error burning eeprom!${NC}"
exit 1
fi

./install_firmware
if [[ $? -ne 0 ]]; then
echo -e "${RED} installation of firmware failed!${NC}"
exit 1
fi

# insert cookie to be picked up by bootloader.
# This signals the bootloader not load the factory image, but too boot from
# flash
install_magic=0x12341234
install_addr=0x0709010C
devmem $install_addr 32 $install_magic

0 comments on commit 8c52636

Please sign in to comment.