Initial commit

This commit is contained in:
Your Name
2026-04-23 17:07:55 +08:00
commit b7e39e063b
16725 changed files with 1625565 additions and 0 deletions
@@ -0,0 +1,3 @@
SRC_URI = "file://luxshare-eeprom.tar.gz"
S = "${WORKDIR}"
@@ -0,0 +1,20 @@
[
{
"bus": 1,
"address": 84,
"path": "/com/luxshare/eeprom/baseboard",
"interface": "com.luxshare.eeprom",
"properties": [
{
"name": "Eth0MAC",
"offset": 512,
"size": 8
},
{
"name": "Eth1MAC",
"offset": 520,
"size": 8
}
]
}
]
@@ -0,0 +1,66 @@
#!/usr/bin/env python3
import argparse
import json
import sys
def parse_config(path):
eeproms = {}
with open(path, 'r') as f:
config = json.load(f)
for eeprom in config:
eeproms[eeprom['path']] = eeprom['properties']
return eeproms
'''
[
{
"bus": 1,
"address": 84,
"path": "/com/luxshare/eeprom/1",
"interface": "com.luxshare.eeprom",
"properties": [
{
"name": "ETH0MAC",
"offset": 0,
"size": 6
},
{
"name": "ETH1MAC",
"offset": 8,
"size": 6
}
]
}
]
'''
def check_overlap(properties):
# sort by offset
properties.sort(key=lambda x: x['offset'])
for i in range(len(properties) - 1):
if properties[i]['offset'] + properties[i]['size'] > properties[i + 1]['offset']:
print('overlap found: {} {} {} {} {} {}'.format(
properties[i]['name'],
properties[i]['offset'],
properties[i]['size'],
properties[i + 1]['name'],
properties[i + 1]['offset'],
properties[i + 1]['size'],
))
sys.exit(1)
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Check if eeprom properties overlap')
parser.add_argument('path', help='path to json config')
args = parser.parse_args()
path = args.path
eeproms = parse_config(path)
for path, properties in eeproms.items():
print(properties)
check_overlap(properties)
@@ -0,0 +1,35 @@
LICENSE = "CLOSED"
SUMMARY = "Luxshare eeprom"
inherit meson systemd pkgconfig
require ${BPN}.inc
SRC_URI += " \
file://overlap.py \
file://eeprom.json \
"
DEPENDS = " \
sdbusplus \
nlohmann-json \
${PYTHON_PN}-native \
"
RDEPENDS:${PN} += "bash"
SYSTEMD_SERVICE:${PN} = "eeprom-manager.service"
do_install:append() {
install -d ${D}/usr/share/luxshare-eeprom
install -m 0644 ${WORKDIR}/eeprom.json ${D}/usr/share/luxshare-eeprom
}
# add a new task to check if the eeprom is valid
# after do_install
do_check_eeprom() {
python3 ${WORKDIR}/overlap.py ${D}/usr/share/luxshare-eeprom/eeprom.json
}
addtask check_eeprom after do_install before do_package
@@ -0,0 +1,20 @@
SUMMARY = "Read GUID from eeprom"
PR = "r1"
LICENSE = "Apache-2.0"
LIC_FILES_CHKSUM = "file://${COREBASE}/meta/files/common-licenses/Apache-2.0;md5=89aea4e17d99a7cacdbeed46a0096b10"
inherit allarch
inherit obmc-phosphor-systemd
RDEPENDS:${PN} += "bash"
S = "${WORKDIR}"
SRC_URI += "file://read-guid-from-eeprom.sh"
do_install() {
install -d ${D}${bindir}
install -m 0755 ${S}/read-guid-from-eeprom.sh ${D}${bindir}/read-guid-from-eeprom.sh
}
SYSTEMD_SERVICE:${PN} += "read-guid-from-eeprom.service"
@@ -0,0 +1,12 @@
[Unit]
Description=Read GUID from eeprom
After=xyz.openbmc_project.Settings.service
After=com.luxshare.eeprom.service
[Service]
Type=oneshot
ExecStart=/usr/bin/read-guid-from-eeprom.sh
ExecStartPost=touch /run/initramfs/read-guid-from-eeprom.done
[Install]
WantedBy=multi-user.target
@@ -0,0 +1,60 @@
#!/bin/bash
set -e
SETTINGS_SERVICE="xyz.openbmc_project.Settings"
GUID_OBJPATH="/xyz/openbmc_project/inventory/item/bmc"
GUID_INTERFACE="xyz.openbmc_project.Common.UUID"
BMC_INTERFACE="xyz.openbmc_project.Inventory.Item.Bmc"
SYSTEM_GUID_PROPERTY="UUID"
DEVICE_GUID_PROPERTY="DeviceGUID"
EEPROM_SERVICE="com.luxshare.eeprom"
EEPROM_OBJPATH="/com/luxshare/eeprom/baseboard"
EEPROM_INTERFACE="com.luxshare.eeprom"
EEPROM_SYSTEM_GUID_PROPERTY="SystemGUID"
EEPROM_DEVICE_GUID_PROPERTY="DeviceGUID"
echo "generate device&system guid from machine-id"
guid_str=$(systemd-id128 machine-id --app-specific=e0e17376646147daa50cd0cc64124578)
system_data_raw=$(busctl get-property ${EEPROM_SERVICE} ${EEPROM_OBJPATH} ${EEPROM_INTERFACE} ${EEPROM_SYSTEM_GUID_PROPERTY})
#remove ay 16
system_GUID=$(echo $system_data_raw | sed 's/ay [0-9]\+ //')
read -a data <<< "$system_GUID"
hex_data=()
#dec==>hex
for decimal_value in "${data[@]}"; do
hex_value=$(printf "%02x" "$decimal_value")
hex_data+=("$hex_value")
done
echo "Read system GUID from eeprom service : ${system_GUID}"
if [[ "$system_GUID" == "255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255" ]];then
busctl set-property "${SETTINGS_SERVICE}" "${GUID_OBJPATH}" "${GUID_INTERFACE}" "${SYSTEM_GUID_PROPERTY}" s "${guid_str:0:8}"-"${guid_str:8:4}"-"${guid_str:12:4}"-"${guid_str:16:4}"-"${guid_str:20:12}"
else
busctl set-property "${SETTINGS_SERVICE}" "${GUID_OBJPATH}" "${GUID_INTERFACE}" "${SYSTEM_GUID_PROPERTY}" s "${hex_data[0]}""${hex_data[1]}""${hex_data[2]}""${hex_data[3]}"-"${hex_data[4]}""${hex_data[5]}"-"${hex_data[6]}""${hex_data[7]}"-"${hex_data[8]}""${hex_data[9]}"-"${hex_data[10]}""${hex_data[11]}""${hex_data[12]}""${hex_data[13]}""${hex_data[14]}""${hex_data[15]}"
fi
device_data_raw=$(busctl get-property ${EEPROM_SERVICE} ${EEPROM_OBJPATH} ${EEPROM_INTERFACE} ${EEPROM_DEVICE_GUID_PROPERTY})
device_GUID=$(echo $device_data_raw | sed 's/ay [0-9]\+ //')
read -a data <<< "$device_GUID"
hex_data=()
#dec==>hex
for decimal_value in "${data[@]}"; do
hex_value=$(printf "%02x" "$decimal_value")
hex_data+=("$hex_value")
done
echo "Read device GUID from eeprom : ${device_GUID}"
if [[ "$device_GUID" == "255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255" ]];then
busctl set-property "${SETTINGS_SERVICE}" "${GUID_OBJPATH}" "${BMC_INTERFACE}" "${DEVICE_GUID_PROPERTY}" s "${guid_str:0:8}"-"${guid_str:8:4}"-"${guid_str:12:4}"-"${guid_str:16:4}"-"${guid_str:20:12}"
else
busctl set-property "${SETTINGS_SERVICE}" "${GUID_OBJPATH}" "${BMC_INTERFACE}" "${DEVICE_GUID_PROPERTY}" s "${hex_data[0]}""${hex_data[1]}""${hex_data[2]}""${hex_data[3]}"-"${hex_data[4]}""${hex_data[5]}"-"${hex_data[6]}""${hex_data[7]}"-"${hex_data[8]}""${hex_data[9]}"-"${hex_data[10]}""${hex_data[11]}""${hex_data[12]}""${hex_data[13]}""${hex_data[14]}""${hex_data[15]}"
fi
@@ -0,0 +1,20 @@
UMMARY = "Write GUID to eeprom"
PR = "r1"
LICENSE = "Apache-2.0"
LIC_FILES_CHKSUM = "file://${COREBASE}/meta/files/common-licenses/Apache-2.0;md5=89aea4e17d99a7cacdbeed46a0096b10"
inherit allarch
inherit obmc-phosphor-systemd
RDEPENDS:${PN} += "bash"
S = "${WORKDIR}"
SRC_URI += "file://write-guid-to-eeprom.sh"
do_install() {
install -d ${D}${bindir}
install -m 0755 ${S}/write-guid-to-eeprom.sh ${D}${bindir}/write-guid-to-eeprom.sh
}
SYSTEMD_SERVICE:${PN} += "write-guid-to-eeprom.service"
@@ -0,0 +1,10 @@
[Unit]
Description=Write GUID to eeprom
After=xyz.openbmc_project.Settings.service
After=com.luxshare.eeprom.service
Wants=xyz.openbmc_project.Settings.service
ConditionPathExists=/run/initramfs/read-guid-from-eeprom.done
[Service]
Type=oneshot
ExecStart=/usr/bin/write-guid-to-eeprom.sh
@@ -0,0 +1,55 @@
#!/bin/bash
set -e
SETTINGS_SERVICE="xyz.openbmc_project.Settings"
GUID_OBJPATH="/xyz/openbmc_project/inventory/item/bmc"
GUID_INTERFACE="xyz.openbmc_project.Common.UUID"
BMC_INTERFACE="xyz.openbmc_project.Inventory.Item.Bmc"
SYSTEM_GUID_PROPERTY="UUID"
DEVICE_GUID_PROPERTY="DeviceGUID"
EEPROM_SERVICE="com.luxshare.eeprom"
EEPROM_OBJPATH="/com/luxshare/eeprom/baseboard"
EEPROM_INTERFACE="com.luxshare.eeprom"
EEPROM_SYSTEM_GUID_PROPERTY="SystemGUID"
EEPROM_DEVICE_GUID_PROPERTY="DeviceGUID"
creat_GUID_str()
{
GUID=$1
for((i=0;i<4;i++));
do
data[i]=${GUID:i*2+1:2}
done
for((i=4;i<6;i++));
do
data[i]=${GUID:i*2+2:2}
done
for((i=6;i<8;i++));
do
data[i]=${GUID:i*2+3:2}
done
for((i=8;i<10;i++));
do
data[i]=${GUID:i*2+4:2}
done
for((i=10;i<16;i++));
do
data[i]=${GUID:i*2+5:2}
done
}
system_GUID=$(busctl get-property ${SETTINGS_SERVICE} ${GUID_OBJPATH} ${GUID_INTERFACE} ${SYSTEM_GUID_PROPERTY} | awk '{print $2}')
creat_GUID_str "${system_GUID}"
echo "Write system GUID to eeprom : ${system_GUID}"
busctl set-property ${EEPROM_SERVICE} ${EEPROM_OBJPATH} ${EEPROM_INTERFACE} ${EEPROM_SYSTEM_GUID_PROPERTY} ay 16 0x"${data[0]}" 0x"${data[1]}" 0x"${data[2]}" 0x"${data[3]}" 0x"${data[4]}" 0x"${data[5]}" 0x"${data[6]}" 0x"${data[7]}" 0x"${data[8]}" 0x"${data[9]}" 0x"${data[10]}" 0x"${data[11]}" 0x"${data[12]}" 0x"${data[13]}" 0x"${data[14]}" 0x"${data[15]}"
device_GUID=$(busctl get-property ${SETTINGS_SERVICE} ${GUID_OBJPATH} ${BMC_INTERFACE} ${DEVICE_GUID_PROPERTY} | awk '{print $2}')
creat_GUID_str "${device_GUID}"
echo "Write device GUID to eeprom : ${device_GUID}"
busctl set-property ${EEPROM_SERVICE} ${EEPROM_OBJPATH} ${EEPROM_INTERFACE} ${EEPROM_DEVICE_GUID_PROPERTY} ay 16 0x"${data[0]}" 0x"${data[1]}" 0x"${data[2]}" 0x"${data[3]}" 0x"${data[4]}" 0x"${data[5]}" 0x"${data[6]}" 0x"${data[7]}" 0x"${data[8]}" 0x"${data[9]}" 0x"${data[10]}" 0x"${data[11]}" 0x"${data[12]}" 0x"${data[13]}" 0x"${data[14]}" 0x"${data[15]}"