Skip to content

Commit 01beb09

Browse files
committed
extra: add post_build tool and ancillary scripts
1 parent 99d1c9d commit 01beb09

File tree

4 files changed

+85
-0
lines changed

4 files changed

+85
-0
lines changed

extra/install_pyocd.sh

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
python3 -m pip install pyocd
3+
# add install dir to PATH
4+
# echo /Users/$USER/Library/Python/3.9/bin > /etc/paths.d/pyocd
5+
pyocd pack update
6+
pyocd pack install R7FA8D1AH
7+
pyocd pack install mcxn947

extra/post_build_tool/build.sh

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
VERSION=$1
2+
3+
mkdir -p distrib/linux_amd64
4+
GOOS=linux GOARCH=amd64 go build && mv zephyr-post-build-tool distrib/linux_amd64/post_build
5+
6+
mkdir -p distrib/linux_arm64
7+
GOOS=linux GOARCH=arm64 go build && mv zephyr-post-build-tool distrib/linux_arm64/post_build
8+
9+
mkdir -p distrib/macos_amd64
10+
GOOS=darwin GOARCH=amd64 go build && mv zephyr-post-build-tool distrib/macos_amd64/post_build
11+
12+
mkdir -p distrib/windows_386
13+
GOOS=windows GOARCH=386 go build && mv zephyr-post-build-tool* distrib/windows_386/post_build.exe
14+
15+
cd distrib
16+
17+
tar -czf zephyr-post-build-tool-${VERSION}-linux_amd64.tar.gz linux_amd64
18+
tar -czf zephyr-post-build-tool-${VERSION}-linux_arm64.tar.gz linux_arm64
19+
tar -czf zephyr-post-build-tool-${VERSION}-macos_amd64.tar.gz macos_amd64
20+
zip -r zephyr-post-build-tool-${VERSION}-windows_386.zip windows_386

extra/post_build_tool/go.mod

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module github.com/arduino/zephyr-post-build-tool
2+
3+
go 1.22.5

extra/post_build_tool/main.go

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"os"
6+
)
7+
8+
func main() {
9+
if len(os.Args) < 2 {
10+
fmt.Println("Please provide a filename")
11+
return
12+
}
13+
14+
filename := os.Args[1]
15+
debug := 0
16+
17+
if len(os.Args) == 3 {
18+
if os.Args[2] == "debug" {
19+
debug = 1
20+
}
21+
}
22+
23+
// Read the file content
24+
content, err := os.ReadFile(filename)
25+
if err != nil {
26+
fmt.Printf("Error reading file: %v\n", err)
27+
return
28+
}
29+
30+
// Get the length of the file content
31+
length := len(content)
32+
33+
// Create a new filename for the copy
34+
newFilename := filename + ".dfu"
35+
36+
// Create the new content with the length in front
37+
len_str := fmt.Sprintf("%d", length)
38+
newContent := append([]byte(len_str), 0, byte(debug))
39+
newContent = append(newContent, content...)
40+
41+
// Write the new content to the new file
42+
err = os.WriteFile(newFilename, []byte(newContent), 0644)
43+
if err != nil {
44+
fmt.Printf("Error writing to file: %v\n", err)
45+
return
46+
}
47+
// Copy in .bin
48+
err = os.WriteFile(newFilename+".bin", []byte(newContent), 0644)
49+
if err != nil {
50+
fmt.Printf("Error writing to file: %v\n", err)
51+
return
52+
}
53+
54+
fmt.Printf("File copied and saved as %s\n", newFilename)
55+
}

0 commit comments

Comments
 (0)