Skip to content

Commit

Permalink
optimize uuid usage in init script
Browse files Browse the repository at this point in the history
  • Loading branch information
Neutree committed Jan 11, 2025
1 parent c4bd8d0 commit 48724b1
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 51 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*.ko
*.d
host-tools/
host-tools
*.sqfs
build/tools/common/sd_tools/genimage.cfg.tmp
fsbl/build/*
Expand Down
5 changes: 0 additions & 5 deletions buildroot/board/cvitek/SG200X/overlay/etc/init.d/S02devicekey
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@

if [ "$1" = "start" ]
then
# Cache uid to prevent deadlock during cvi_base operation
if [ ! -e /boot/cvi_base_uid ]; then
$(cat /sys/class/cvi-base/base_uid > /boot/cvi_base_uid)
fi

str_value=$(cat /sys/class/cvi-base/base_uid | awk '{print $2}')
first_uint=$(echo $str_value | cut -d'_' -f1)
second_uint=$(echo $str_value | cut -d'_' -f2)
Expand Down
12 changes: 2 additions & 10 deletions buildroot/board/cvitek/SG200X/overlay/etc/init.d/S10uuid
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@ then
prefix=$(cat /boot/hostname.prefix)
fi
old_hostname=$(cat /etc/hostname)
if [ -e /boot/cvi_base_uid ]; then
new_hostname=${prefix}-$(sha512sum /boot/cvi_base_uid | head -c 4)
else
new_hostname=${prefix}-$(sha512sum /sys/class/cvi-base/base_uid | head -c 4)
fi
new_hostname=${prefix}-$(sha512sum /device_key | head -c 4)

if [ -e /boot/hostname ]
then
Expand All @@ -42,11 +38,7 @@ then
then
new_ethmac=$(cat /boot/ethmac)
else
if [ -e /boot/cvi_base_uid ]; then
new_ethmac=$(hex2mac 48da356f$(sha512sum /boot/cvi_base_uid | head -c 4))
else
new_ethmac=$(hex2mac 48da356f$(sha512sum /sys/class/cvi-base/base_uid | head -c 4))
fi
new_ethmac=$(hex2mac 48da356f$(sha512sum /device_key | head -c 4))
fi

ifconfig eth0 down
Expand Down
30 changes: 6 additions & 24 deletions buildroot/board/cvitek/SG200X/overlay/etc/init.d/S30gadget_nic
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,7 @@ start() {
then
new_rndismac=$(cat /boot/usb.rndis.mac)
else
if [ -e /boot/cvi_base_uid ]; then
new_rndismac=$(hex2mac 48da356f$(sha512sum /boot/cvi_base_uid | head -c 4))
else
new_rndismac=$(hex2mac 48da356f$(sha512sum /sys/class/cvi-base/base_uid | head -c 4))
fi
new_rndismac=$(hex2mac 48da356f$(sha512sum /device_key | head -c 4))
fi
ip link set $rndis_ifname address ${new_rndismac}
ifconfig $rndis_ifname up
Expand All @@ -56,13 +52,8 @@ start() {
then
ipv4_prefix=`cat /boot/rndis.ipv4_prefix`
else
if [ -e /boot/cvi_base_uid ]; then
id2=$(printf "%d" 0x$(sha512sum /boot/cvi_base_uid | head -c 2))
id3=$(printf "%d" 0x$(sha512sum /boot/cvi_base_uid | head -c 4 | tail -c 2))
else
id2=$(printf "%d" 0x$(sha512sum /sys/class/cvi-base/base_uid | head -c 2))
id3=$(printf "%d" 0x$(sha512sum /sys/class/cvi-base/base_uid | head -c 4 | tail -c 2))
fi
id2=$(printf "%d" 0x$(sha512sum /device_key | head -c 2))
id3=$(printf "%d" 0x$(sha512sum /device_key | head -c 4 | tail -c 2))
id3=$((id3 + 1))
if [ "$id2" = "$id3" ]
then
Expand Down Expand Up @@ -94,11 +85,7 @@ start() {
then
new_mac=$(cat /boot/usb.ncm.mac)
else
if [ -e /boot/cvi_base_uid ]; then
new_mac=$(hex2mac 48da356e$(sha512sum /boot/cvi_base_uid | head -c 4))
else
new_mac=$(hex2mac 48da356e$(sha512sum /sys/class/cvi-base/base_uid | head -c 4))
fi
new_mac=$(hex2mac 48da356e$(sha512sum /device_key | head -c 4))
fi
ip link set $rndis_ifname address ${new_mac}
ifconfig $rndis_ifname up
Expand All @@ -111,13 +98,8 @@ start() {
then
ipv4_prefix=`cat /boot/ncm.ipv4_prefix`
else
if [ -e /boot/cvi_base_uid ]; then
id2=$(printf "%d" 0x$(sha512sum /boot/cvi_base_uid | head -c 2))
id3=$(printf "%d" 0x$(sha512sum /boot/cvi_base_uid | head -c 4 | tail -c 2))
else
id2=$(printf "%d" 0x$(sha512sum /sys/class/cvi-base/base_uid | head -c 2))
id3=$(printf "%d" 0x$(sha512sum /sys/class/cvi-base/base_uid | head -c 4 | tail -c 2))
fi
id2=$(printf "%d" 0x$(sha512sum /device_key | head -c 2))
id3=$(printf "%d" 0x$(sha512sum /device_key | head -c 4 | tail -c 2))
if [ "$id2" = "$id3" ]
then
id2=$((id2 + 1))
Expand Down
9 changes: 2 additions & 7 deletions buildroot/board/cvitek/SG200X/overlay/etc/init.d/S30wifi
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,8 @@ start() {
then
cp /boot/hostapd.conf /etc/hostapd.conf
else
if [ -e /boot/cvi_base_uid ]; then
id2=$(printf "%d" 0x$(sha512sum /boot/cvi_base_uid | head -c 2))
id3=$(printf "%d" 0x$(sha512sum /boot/cvi_base_uid | head -c 4 | tail -c 2))
else
id2=$(printf "%d" 0x$(sha512sum /sys/class/cvi-base/base_uid | head -c 2))
id3=$(printf "%d" 0x$(sha512sum /sys/class/cvi-base/base_uid | head -c 4 | tail -c 2))
fi
id2=$(printf "%d" 0x$(sha512sum /device_key | head -c 2))
id3=$(printf "%d" 0x$(sha512sum /device_key | head -c 4 | tail -c 2))
if [ "$id2" = "$id3" ]
then
id2=$((id2 + 1))
Expand Down
6 changes: 1 addition & 5 deletions buildroot/board/cvitek/SG200X/overlay/etc/init.d/S99temptest
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,7 @@ case "$1" in
fi
echo "soc temp: $soc_temp" | fbbar 32 $colorfg $colorbg
colorfg=0xFFFFFFFF
if [ -e /boot/cvi_base_uid ]; then
echo "soc id: $(cat /boot/cvi_base_uid)" | fbbar 48 $colorfg $colorbg
else
echo "soc id: $(cat /sys/class/cvi-base/base_uid)" | fbbar 48 $colorfg $colorbg
fi
echo "soc id: $(cat /device_key)" | fbbar 48 $colorfg $colorbg
sleep 1
done
) &
Expand Down

0 comments on commit 48724b1

Please sign in to comment.