-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add helper code for supporting the RevolutionPi4 as revpi-firmware
Using factory assigned MAC address from EEPROM instead of compute module address Signed-off-by: Martin Schuessler <1407812+c0ffee@users.noreply.github.com>
- Loading branch information
Showing
8 changed files
with
143 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
version: v1alpha1 | ||
metadata: | ||
name: revpi-firmware | ||
version: "$VERSION" | ||
author: STACKIT | ||
description: | | ||
This system extension provides tools e.g. udev rules for the RevolutionPi platform. | ||
compatibility: | ||
talos: | ||
version: ">= v1.0.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
name: revpi-firmware | ||
variant: scratch | ||
shell: /bin/bash | ||
dependencies: | ||
- stage: base | ||
steps: | ||
- env: | ||
GOPATH: /tmp/go | ||
cachePaths: | ||
- /.cache/go-build | ||
- /tmp/go/pkg | ||
- network: default | ||
prepare: | ||
- | | ||
sed -i 's#$VERSION#{{ .VERSION }}#' /pkg/manifest.yaml | ||
cd /pkg/src | ||
go mod download | ||
build: | ||
- | | ||
cd /pkg/src | ||
CGO_ENABLED=0 go build -o ./revpi_mac . | ||
strip revpi_mac | ||
install: | ||
- | | ||
mkdir -p /rootfs/usr/lib/udev/rules.d/ | ||
cp -p /pkg/src/revpi_mac /rootfs/usr/lib/udev/rules.d/ | ||
echo 'ACTION=="add", SUBSYSTEM=="net", ATTR{type}=="1", DEVPATH=="*/fd580000.ethernet/net/*", PROGRAM="/usr/lib/udev/rules.d/revpi_mac %k 0"' > /rootfs/usr/lib/udev/rules.d/50-revpi.rules | ||
test: | ||
- | | ||
mkdir -p /extensions-validator-rootfs | ||
cp -r /rootfs/ /extensions-validator-rootfs/rootfs | ||
cp /pkg/manifest.yaml /extensions-validator-rootfs/manifest.yaml | ||
/extensions-validator validate --rootfs=/extensions-validator-rootfs --pkg-name="${PKG_NAME}" | ||
finalize: | ||
- from: /rootfs | ||
to: /rootfs | ||
- from: /pkg/manifest.yaml | ||
to: / |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module github.com/siderolabs/revpi-firmare | ||
|
||
go 1.22 | ||
|
||
require ( | ||
github.com/vishvananda/netlink v1.3.0 // indirect | ||
github.com/vishvananda/netns v0.0.4 // indirect | ||
golang.org/x/sys v0.10.0 // indirect | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
github.com/vishvananda/netlink v1.3.0 h1:X7l42GfcV4S6E4vHTsw48qbrV+9PVojNfIhZcwQdrZk= | ||
github.com/vishvananda/netlink v1.3.0/go.mod h1:i6NetklAujEcC6fK0JPjT8qSwWyO0HLn4UKG+hGqeJs= | ||
github.com/vishvananda/netns v0.0.4 h1:Oeaw1EM2JMxD51g9uhtC0D7erkIjgmj8+JZc26m1YX8= | ||
github.com/vishvananda/netns v0.0.4/go.mod h1:SpkAiCQRtJ6TvvxPnOSyH3BMl6unz3xZlaprSwhNNJM= | ||
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||
golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA= | ||
golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
package main | ||
|
||
import ( | ||
"bufio" | ||
"fmt" | ||
"log" | ||
"net" | ||
"os" | ||
"strconv" | ||
"strings" | ||
|
||
"github.com/vishvananda/netlink" | ||
) | ||
|
||
func main() { | ||
if len(os.Args) < 3 { | ||
log.Fatalf("Usage: %s <DEVNAME> <OFFSET>", os.Args) | ||
} | ||
|
||
devName := string(os.Args[1]) | ||
offset, err := strconv.ParseInt(os.Args[2], 10, 64) | ||
if err != nil { | ||
log.Fatalf("Invalid offset: %v", err) | ||
} | ||
|
||
if _, err := os.Stat("/sys/firmware/devicetree/base/hat/custom_5"); os.IsNotExist(err) { | ||
os.Exit(1) | ||
} | ||
|
||
file, err := os.Open("/sys/firmware/devicetree/base/hat/custom_5") | ||
if err != nil { | ||
log.Fatalf("Failed to open file: %v", err) | ||
} | ||
defer file.Close() | ||
|
||
scanner := bufio.NewScanner(file) | ||
scanner.Scan() | ||
baseMAC := scanner.Text() | ||
if err := scanner.Err(); err != nil { | ||
log.Fatalf("Failed to read file: %v", err) | ||
} | ||
|
||
if baseMAC == "" { | ||
os.Exit(2) | ||
} | ||
|
||
MAC := strings.Split(baseMAC, ":") | ||
lastNum, err := strconv.ParseInt(MAC[len(MAC)-1], 16, 16) | ||
if err != nil { | ||
log.Fatalf("Failed to parse last number: %v", err) | ||
} | ||
lastNum = lastNum + offset | ||
MAC[len(MAC)-1] = fmt.Sprintf("%02x", lastNum) | ||
|
||
link, err := netlink.LinkByName(devName) | ||
if err != nil { | ||
log.Fatalf("Failed to get interface: %v", err) | ||
} | ||
|
||
hwAddr, err := net.ParseMAC(strings.Join(MAC, ":")) | ||
if err != nil { | ||
log.Fatalf("Failed to parse MAC address: %v", err) | ||
} | ||
|
||
err = netlink.LinkSetHardwareAddr(link, hwAddr) | ||
if err != nil { | ||
log.Fatalf("Failed to set MAC address: %v", err) | ||
} | ||
|
||
fmt.Printf("MAC address of %s changed to %s\n", devName, MAC) | ||
os.Exit(0) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
VERSION: "v1.0.0" |