Skip to content

Commit 9aad9de

Browse files
committed
Update for repo changes and partial helper script
1 parent fa907da commit 9aad9de

File tree

3 files changed

+38
-80
lines changed

3 files changed

+38
-80
lines changed

.github/workflows/update.yml

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,23 @@ on:
77

88
jobs:
99
update:
10-
runs-on: ubuntu-22.04
10+
runs-on: ubuntu-latest
1111
container:
1212
image: ghcr.io/modm-ext/modm-build-cortex-m:latest
1313
steps:
1414
- name: Check out repository
15-
uses: actions/checkout@v3
15+
uses: actions/checkout@v4
1616
- name: Configure Git
1717
run: |
1818
git config --global user.email "[email protected]"
1919
git config --global user.name "modm update bot"
2020
git config --global --add safe.directory /__w/pico-sdk-partial/pico-sdk-partial
2121
- name: Run update.py script
22+
env:
23+
GITHUB_TOKEN: ${{ github.token }}
2224
run: |
25+
wget -qL https://raw.githubusercontent.com/modm-ext/partial/main/partial.py
2326
python3 update.py
2427
- name: Git push
2528
run: |
2629
git push origin main
27-
- name: Keep Alive
28-
if: always()
29-
uses: gautamkrishnar/keepalive-workflow@v1
30-
with:
31-
committer_username: modm update bot
32-
committer_email: [email protected]

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
/pico_sdk_src
1+
/*_src
2+
/partial.py*
23
/build
34
/pioasm/build

update.py

Lines changed: 31 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,28 @@
22

33
import os
44
import sys
5-
import json
6-
import shutil
7-
import fnmatch
85
import subprocess
96
import binascii
107
import struct
11-
import re
128
from pathlib import Path
13-
import urllib.request
149

15-
source_paths = [
16-
["","LICENSE.TXT"],
17-
["src/rp2040/hardware_regs","include/**/*.h"],
18-
["src/rp2040/hardware_structs","include/**/*.h"],
19-
["src/rp2_common/cmsis/stub/CMSIS/Device/RaspberryPi/RP2040/Include","*.h","include"],
20-
["tools/","pioasm/**/*.[hct]*"],
21-
]
10+
# wget -qL https://raw.githubusercontent.com/modm-ext/partial/main/partial.py
11+
import partial
12+
partial.keepalive()
13+
14+
repo = "raspberrypi/pico-sdk"
15+
src = Path("pico_sdk_src")
2216

17+
tag = partial.latest_release_tag(repo)
18+
partial.clone_repo(repo, src, branch=tag, overwrite="--fast" not in sys.argv)
19+
files = partial.copy_files(src, ["LICENSE.TXT"])
20+
files += partial.copy_files(Path("pico_sdk_src/src/rp2040/hardware_regs"), ["include/**/*.h"])
21+
files += partial.copy_files(Path("pico_sdk_src/src/rp2040/hardware_structs"), ["include/**/*.h"], delete=False)
22+
files += partial.copy_files(Path("pico_sdk_src/src/rp2_common/cmsis/stub/CMSIS/Device/RP2040/Include"), ["*.h"], dest=Path("include"), delete=False)
23+
files += partial.copy_files(Path("pico_sdk_src/tools"), ["pioasm/**/*.[hct]*"])
24+
files += [Path("src")]
25+
26+
print("Building boot2 variants...")
2327
boot2_variants = [
2428
"generic_03h",
2529
"at25sf128a",
@@ -32,7 +36,7 @@ def run(where, command, stdin=None):
3236
print(command)
3337
result = subprocess.run(command, shell=True, cwd=where, input=stdin, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
3438
if result.returncode != 0:
35-
print('failed exec command ' + command)
39+
print(f"Failed exec command: '{command}'")
3640
print(result.stderr.decode("utf-8").strip(" \n"))
3741
exit(1)
3842
return (result.returncode,
@@ -42,63 +46,21 @@ def run(where, command, stdin=None):
4246
def bitrev(x, width):
4347
return int("{:0{w}b}".format(x, w=width)[::-1], 2)
4448

45-
hw_def_re = re.compile(r'#define (.+)_hw \(\((.+)_hw_t \*const\)(.+)_BASE\)')
46-
def process(l):
47-
hw_def = hw_def_re.match(l)
48-
if hw_def:
49-
print("replace hw def {}".format(hw_def[1]))
50-
return "#define {}_hw (({}_hw_t*){}_BASE)".format(hw_def[1],hw_def[2],hw_def[3])
51-
return l
52-
53-
with urllib.request.urlopen("https://api.github.com/repos/raspberrypi/pico-sdk/releases/latest") as response:
54-
tag = json.loads(response.read())["tag_name"]
55-
56-
# clone the repository
57-
if "--fast" not in sys.argv:
58-
print("Cloning pico-sdk repository at tag v{}...".format(tag))
59-
shutil.rmtree("pico_sdk_src", ignore_errors=True)
60-
subprocess.run("git clone --depth=1 --branch {} ".format(tag) +
61-
"https://github.com/raspberrypi/pico-sdk.git pico_sdk_src", shell=True)
62-
63-
# remove the sources in this repo
64-
shutil.rmtree("include", ignore_errors=True)
65-
shutil.rmtree("src", ignore_errors=True)
66-
shutil.rmtree("pioasm", ignore_errors=True)
67-
68-
69-
print("Copying pico-sdk headers...")
70-
for pattern_conf in source_paths:
71-
src_path = os.path.join("pico_sdk_src",pattern_conf[0])
72-
pattern = pattern_conf[1]
73-
for path in Path(src_path).glob(pattern):
74-
if not path.is_file(): continue
75-
dest = path.relative_to(src_path)
76-
if len(pattern_conf) > 2:
77-
dest = Path(pattern_conf[2]) / dest
78-
dest.parent.mkdir(parents=True, exist_ok=True)
79-
print(dest)
80-
# Copy, normalize newline and remove trailing whitespace
81-
with path.open("r", newline=None, encoding="utf-8", errors="replace") as rfile, \
82-
dest.open("w", encoding="utf-8") as wfile:
83-
wfile.writelines(process(l.rstrip())+"\n" for l in rfile.readlines())
84-
85-
print("Building boot2 variants...")
86-
8749
for variant in boot2_variants:
88-
builddir = Path('build/boot2_' + variant)
89-
if not builddir.exists():
90-
builddir.mkdir(parents=True, exist_ok=True)
91-
run(builddir,"cmake ../../pico_sdk_src -G \"Unix Makefiles\" -DPICO_DEFAULT_BOOT_STAGE2=boot2_" + variant)
92-
run(builddir,'make bs2_default_padded_checksummed_asm') # for validate
50+
builddir = Path(f"build/boot2_{variant}")
51+
builddir.mkdir(parents=True, exist_ok=True)
52+
53+
run(builddir, f'cmake ../../pico_sdk_src -G "Unix Makefiles" -DPICO_DEFAULT_BOOT_STAGE2=boot2_{variant}')
54+
run(builddir, "make bs2_default_bin") # for validate
9355
#run(builddir,'make bs2_default_bin')
94-
ifile = os.path.join(builddir,'src/rp2_common/boot_stage2/bs2_default.bin')
56+
ifile = builddir / "src/rp2040/boot_stage2/bs2_default.bin"
9557
try:
9658
idata = open(ifile, "rb").read()
9759
except:
98-
sys.exit("Could not open input file '{}'".format(ifile))
60+
sys.exit(f"Could not open input file '{ifile}'")
9961
pad = 256
10062
if len(idata) >= pad - 4:
101-
sys.exit("Input file size ({} bytes) too large for final size ({} bytes)".format(len(idata), pad))
63+
sys.exit(f"Input file size ({len(idata)} bytes) too large for final size ({pad} bytes)")
10264
idata_padded = idata + bytes(pad - 4 - len(idata))
10365
seed = 0xffffffff
10466
# Our bootrom CRC32 is slightly bass-ackward but it's best to work around for now (FIXME)
@@ -107,20 +69,18 @@ def process(l):
10769
(binascii.crc32(bytes(bitrev(b, 8) for b in idata_padded), seed ^ 0xffffffff) ^ 0xffffffff) & 0xffffffff, 32)
10870
odata = idata_padded + struct.pack("<L", checksum)
10971

110-
ofilename = 'src/boot2_' + variant + '.cpp'
72+
ofilename = Path(f"src/boot2_{variant}.cpp")
11173
try:
112-
Path(ofilename).parent.mkdir(parents=True, exist_ok=True)
113-
with open(ofilename, "w") as ofile:
74+
ofilename.parent.mkdir(parents=True, exist_ok=True)
75+
with ofilename.open("w") as ofile:
11476
ofile.write("// Stage2 bootloader\n\n")
11577
ofile.write("#include <cstdint>\n")
116-
ofile.write("extern \"C\" __attribute__((section(\".boot2\"))) const uint8_t boot2[256] = {\n")
78+
ofile.write('extern "C" __attribute__((section(".boot2"))) const uint8_t boot2[256] = {\n')
11779
for offs in range(0, len(odata), 16):
11880
chunk = odata[offs:min(offs + 16, len(odata))]
119-
ofile.write("\t {},\n".format(", ".join("0x{:02x}".format(b) for b in chunk)))
81+
ofile.write("\t {},\n".format(", ".join(f"0x{b:02x}" for b in chunk)))
12082
ofile.write("};\n")
12183
except:
12284
sys.exit("Could not open output file '{}'".format(ofilename))
12385

124-
subprocess.run("git add src include pioasm LICENSE.TXT", shell=True)
125-
if subprocess.call("git diff-index --quiet HEAD --", shell=True):
126-
subprocess.run('git commit -m "Update pico-sdk to v{}"'.format(tag), shell=True)
86+
partial.commit(files, tag)

0 commit comments

Comments
 (0)