Skip to content

Commit 3678af7

Browse files
committed
feat(tools): Add scripts for creating release packages and updating bootloader
- Implemented create_release.sh to automate the packaging of Arduino BSP and PlatformIO. - Added update_bootloader.py to fetch the latest bootloader versions and manage variant downloads. Signed-off-by: Chiho Sin <[email protected]>
1 parent 28ea791 commit 3678af7

File tree

2 files changed

+167
-0
lines changed

2 files changed

+167
-0
lines changed

tools/create_release.sh

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#!/bin/bash -e
2+
3+
VERSION=`grep version= platform.txt | sed 's/version=//g'`
4+
5+
PWD=`pwd`
6+
FOLDERNAME=`basename $PWD`
7+
THIS_SCRIPT_NAME=`basename $0`
8+
PACKAGE_FILES="
9+
$FOLDERNAME/boards.txt
10+
$FOLDERNAME/variants
11+
$FOLDERNAME/CMakeLists.txt
12+
$FOLDERNAME/idf_component.yml
13+
$FOLDERNAME/Kconfig.projbuild
14+
$FOLDERNAME/package.json
15+
$FOLDERNAME/platform.txt
16+
$FOLDERNAME/programmers.txt
17+
$FOLDERNAME/cores
18+
$FOLDERNAME/libraries
19+
$FOLDERNAME/tools/espota.exe
20+
$FOLDERNAME/tools/espota.py
21+
$FOLDERNAME/tools/gen_esp32part.py
22+
$FOLDERNAME/tools/gen_esp32part.exe
23+
$FOLDERNAME/tools/gen_insights_package.py
24+
$FOLDERNAME/tools/gen_insights_package.exe
25+
$FOLDERNAME/tools/partitions
26+
$FOLDERNAME/tools/ide-debug
27+
$FOLDERNAME/tools/pioarduino-build.py
28+
"
29+
30+
mkdir -p build
31+
rm -f build/$FOLDERNAME-$VERSION.tar.bz2
32+
rm -f build/framework-arduinoesp32@$VERSION.zip
33+
rm -f build/package_fobe_index.json
34+
35+
cd ..
36+
if [[ "$OSTYPE" == "darwin"* ]]; then
37+
# macOS
38+
tar -s "/$FOLDERNAME/$VERSION/g" \
39+
-cjf $FOLDERNAME-$VERSION.tar.bz2 \
40+
$PACKAGE_FILES
41+
else
42+
# Linux
43+
tar --transform "s|$FOLDERNAME|$VERSION|g" \
44+
-cjf $FOLDERNAME-$VERSION.tar.bz2 \
45+
$PACKAGE_FILES
46+
fi
47+
cd -
48+
49+
50+
mv ../$FOLDERNAME-$VERSION.tar.bz2 ./build/
51+
52+
cd ..
53+
zip -r framework-arduinoesp32@$VERSION.zip \
54+
$PACKAGE_FILES
55+
cd -
56+
mv ../framework-arduinoesp32@$VERSION.zip ./build/
57+
58+
echo ""
59+
echo "Package for Arduino BSP"
60+
echo "Path: `pwd`/build/$FOLDERNAME-$VERSION.tar.bz2"
61+
echo checksum: SHA-256:`sha256sum ./build/$FOLDERNAME-$VERSION.tar.bz2 | awk '{print $1}'`
62+
echo size: `wc -c ./build/$FOLDERNAME-$VERSION.tar.bz2 | awk '{print $1}'` bytes
63+
echo ""
64+
echo "Package for PlatformIO"
65+
echo "Path: `pwd`/build/framework-arduinoesp32@$VERSION.zip"
66+
echo checksum: SHA-256:`sha256sum ./build/framework-arduinoesp32@$VERSION.zip | awk '{print $1}'`
67+
echo size: `wc -c ./build/framework-arduinoesp32@$VERSION.zip | awk '{print $1}'` bytes
68+
69+
# Generate package_fobe_index.json based on template
70+
echo ""
71+
echo "Generating package_fobe_index.json..."
72+
73+
ARCHIVE_FILE="$FOLDERNAME-$VERSION.tar.bz2"
74+
ARCHIVE_CHECKSUM=`sha256sum ./build/$ARCHIVE_FILE | awk '{print $1}'`
75+
ARCHIVE_SIZE=`wc -c ./build/$ARCHIVE_FILE | awk '{print $1}'`
76+
77+
# Use sed to replace placeholders in template
78+
sed -e "s|\"version\": \"\"|\"version\": \"$VERSION\"|g" \
79+
-e "s|\"url\": \"\"|\"url\": \"https://github.com/fobe-projects/fobe-esp32-arduino/releases/download/$VERSION/$ARCHIVE_FILE\"|g" \
80+
-e "s|\"archiveFileName\": \"\"|\"archiveFileName\": \"$ARCHIVE_FILE\"|g" \
81+
-e "s|\"checksum\": \"\"|\"checksum\": \"SHA-256:$ARCHIVE_CHECKSUM\"|g" \
82+
-e "s|\"size\": \"\"|\"size\": \"$ARCHIVE_SIZE\"|g" \
83+
package/package_esp32_index.template.json > build/package_fobe_index.json
84+
85+
echo "Generated: `pwd`/build/package_fobe_index.json"
86+
echo "Version: $VERSION"
87+
echo "Archive: $ARCHIVE_FILE"
88+
echo "Checksum: SHA-256:$ARCHIVE_CHECKSUM"
89+
echo "Size: $ARCHIVE_SIZE bytes"
90+

tools/update_bootloader.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import os
2+
import urllib.request
3+
import json
4+
from multiprocessing import Pool
5+
import zipfile
6+
import re
7+
from functools import partial
8+
9+
# Get latest version from GitHub API
10+
def get_latest_version():
11+
api_url = "https://api.github.com/repos/fobe-projects/fobe-tinyuf2/releases/latest"
12+
try:
13+
with urllib.request.urlopen(api_url) as response:
14+
data = json.loads(response.read().decode())
15+
return data['tag_name']
16+
except Exception as e:
17+
print(f"Error fetching latest version: {e}")
18+
return None
19+
20+
# Download a variant's bootloader
21+
def download_variant(variant, version):
22+
23+
# Download from bootloader release
24+
f_zip = f"tinyuf2-{variant}-{version}.zip"
25+
url_prefix = (
26+
f"https://github.com/fobe-projects/fobe-tinyuf2/releases/download/{version}/"
27+
)
28+
29+
# remove existing bootloader files
30+
if os.path.exists(f"variants/{variant}/bootloader-tinyuf2.bin"):
31+
os.remove(f"variants/{variant}/bootloader-tinyuf2.bin")
32+
if os.path.exists(f"variants/{variant}/tinyuf2.uf2"):
33+
os.remove(f"variants/{variant}/tinyuf2.uf2")
34+
35+
print(f"Downloading {f_zip}")
36+
urllib.request.urlretrieve(url_prefix + f_zip, f"variants/{variant}/{f_zip}")
37+
if os.path.exists(f"variants/{variant}/{f_zip}"):
38+
print(f"Downloaded {f_zip}")
39+
with zipfile.ZipFile(f"variants/{variant}/{f_zip}", "r") as zip_ref:
40+
for member in zip_ref.namelist():
41+
if member.endswith('tinyuf2.bin'):
42+
# Extract and rename tinyuf2.bin
43+
zip_ref.extract(member, f"variants/{variant}/")
44+
extracted_path = f"variants/{variant}/{member}"
45+
new_name = f"variants/{variant}/tinyuf2.bin"
46+
os.rename(extracted_path, new_name)
47+
elif member.endswith('bootloader.bin'):
48+
# Extract and rename bootloader.bin
49+
zip_ref.extract(member, f"variants/{variant}/")
50+
extracted_path = f"variants/{variant}/{member}"
51+
new_name = f"variants/{variant}/bootloader-tinyuf2.bin"
52+
os.rename(extracted_path, new_name)
53+
54+
# Clean up the zip file
55+
os.remove(f"variants/{variant}/{f_zip}")
56+
print(f"Cleaned up {f_zip}")
57+
58+
59+
if __name__ == "__main__":
60+
# Get latest version from GitHub API
61+
version = get_latest_version()
62+
if not version:
63+
print("Failed to get latest version, exiting...")
64+
exit(1)
65+
66+
print(f"version {version}")
67+
68+
# Get all variants that start with "fobe_"
69+
all_variant = []
70+
for entry in os.scandir("variants"):
71+
if entry.is_dir() and entry.name.startswith("fobe_"):
72+
all_variant.append(entry.name)
73+
all_variant.sort()
74+
75+
download_with_version = partial(download_variant, version=version)
76+
with Pool() as p:
77+
p.map(download_with_version, all_variant)

0 commit comments

Comments
 (0)