Skip to content

Commit 759d3c6

Browse files
committed
Add RP2350 target
1 parent 4bfd68b commit 759d3c6

File tree

3 files changed

+62
-50
lines changed

3 files changed

+62
-50
lines changed

.github/workflows/update.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on:
44
schedule:
55
- cron: '08 8 * * 3'
66
workflow_dispatch:
7+
pull_request:
78

89
jobs:
910
update:
@@ -25,5 +26,6 @@ jobs:
2526
wget -qL https://raw.githubusercontent.com/modm-ext/partial/main/partial.py
2627
python3 update.py
2728
- name: Git push
29+
if: github.ref == 'refs/heads/main'
2830
run: |
2931
git push origin main

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@ The following paths are extracted:
88
- `LICENSE.TXT`
99
- `src/rp2040/hardware_regs/include`
1010
- `src/rp2040/hardware_structs/include`
11-
- `src/rp2_common/cmsis/stub/CMSIS/Device/RaspberryPi/RP2040/Include`
11+
- `src/rp2_common/cmsis/stub/CMSIS/Device/RP2040/Include`
12+
- `src/rp2350/hardware_regs/include`
13+
- `src/rp2350/hardware_structs/include`
14+
- `src/rp2_common/cmsis/stub/CMSIS/Device/RP2350/Include`
1215
- `tools/pioasm/`
1316

14-
Boot2 variants are built from `src/rp2_common/boot_stage2`.
17+
Boot2 variants are built from `src/rp2040/boot_stage2` and `src/rp2350/boot_stage2`.
1518
The stand-alone `pioasm` can be compiled as such:
1619

1720
```sh

update.py

Lines changed: 55 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env python3
22

3-
import os
43
import sys
4+
import shutil
55
import subprocess
66
import binascii
77
import struct
@@ -13,25 +13,31 @@
1313

1414
repo = "raspberrypi/pico-sdk"
1515
src = Path("pico_sdk_src")
16+
platforms = {
17+
"rp2040": "rp2040",
18+
"rp2350": "rp2350-arm-s"
19+
}
1620

1721
tag = partial.latest_release_tag(repo)
1822
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+
shutil.rmtree("src", ignore_errors=True)
24+
files = [Path("src")]
25+
files += partial.copy_files(src, ["LICENSE.TXT"])
2326
files += partial.copy_files(Path("pico_sdk_src/tools"), ["pioasm/**/*.[hct]*"])
24-
files += [Path("src")]
27+
for target in platforms:
28+
files += partial.copy_files(Path(f"pico_sdk_src/src/{target}/hardware_regs/include/"), ["**/*.h"], dest=target)
29+
files += partial.copy_files(Path(f"pico_sdk_src/src/{target}/hardware_structs/include/"), ["**/*.h"], dest=target, delete=False)
30+
files += partial.copy_files(Path(f"pico_sdk_src/src/rp2_common/cmsis/stub/CMSIS/Device/{target.upper()}/Include/"), ["*.h"], dest=target, delete=False)
2531

26-
print("Building boot2 variants...")
27-
boot2_variants = [
28-
"generic_03h",
29-
"at25sf128a",
30-
"is25lp080",
31-
"w25q080",
32-
"w25x10cl"
33-
]
3432

33+
print("Building boot2 variants...")
34+
boot2_variants = {
35+
"generic_03h": ["rp2040", "rp2350"],
36+
"at25sf128a": ["rp2040"],
37+
"is25lp080": ["rp2040"],
38+
"w25q080": ["rp2040", "rp2350"],
39+
"w25x10cl": ["rp2040"],
40+
}
3541
def run(where, command, stdin=None):
3642
print(command)
3743
result = subprocess.run(command, shell=True, cwd=where, input=stdin, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
@@ -46,41 +52,42 @@ def run(where, command, stdin=None):
4652
def bitrev(x, width):
4753
return int("{:0{w}b}".format(x, w=width)[::-1], 2)
4854

49-
for variant in boot2_variants:
50-
builddir = Path(f"build/boot2_{variant}")
51-
builddir.mkdir(parents=True, exist_ok=True)
55+
for variant, targets in boot2_variants:
56+
for target in targets:
57+
builddir = Path(f"build/boot2_{variant}_{target}")
58+
builddir.mkdir(parents=True, exist_ok=True)
5259

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
55-
#run(builddir,'make bs2_default_bin')
56-
ifile = builddir / "src/rp2040/boot_stage2/bs2_default.bin"
57-
try:
58-
idata = open(ifile, "rb").read()
59-
except:
60-
sys.exit(f"Could not open input file '{ifile}'")
61-
pad = 256
62-
if len(idata) >= pad - 4:
63-
sys.exit(f"Input file size ({len(idata)} bytes) too large for final size ({pad} bytes)")
64-
idata_padded = idata + bytes(pad - 4 - len(idata))
65-
seed = 0xffffffff
66-
# Our bootrom CRC32 is slightly bass-ackward but it's best to work around for now (FIXME)
67-
# 100% worth it to save two Thumb instructions
68-
checksum = bitrev(
69-
(binascii.crc32(bytes(bitrev(b, 8) for b in idata_padded), seed ^ 0xffffffff) ^ 0xffffffff) & 0xffffffff, 32)
70-
odata = idata_padded + struct.pack("<L", checksum)
60+
run(builddir, f'cmake ../../pico_sdk_src -G "Unix Makefiles" -DPICO_DEFAULT_BOOT_STAGE2=boot2_{variant} -DPICO_PLATFORM={platforms[target]}')
61+
run(builddir, "make bs2_default_bin") # for validate
62+
#run(builddir,'make bs2_default_bin')
63+
ifile = builddir / f"src/{target}/boot_stage2/bs2_default.bin"
64+
try:
65+
idata = open(ifile, "rb").read()
66+
except:
67+
sys.exit(f"Could not open input file '{ifile}'")
68+
pad = 256
69+
if len(idata) >= pad - 4:
70+
sys.exit(f"Input file size ({len(idata)} bytes) too large for final size ({pad} bytes)")
71+
idata_padded = idata + bytes(pad - 4 - len(idata))
72+
seed = 0xffffffff
73+
# Our bootrom CRC32 is slightly bass-ackward but it's best to work around for now (FIXME)
74+
# 100% worth it to save two Thumb instructions
75+
checksum = bitrev(
76+
(binascii.crc32(bytes(bitrev(b, 8) for b in idata_padded), seed ^ 0xffffffff) ^ 0xffffffff) & 0xffffffff, 32)
77+
odata = idata_padded + struct.pack("<L", checksum)
7178

72-
ofilename = Path(f"src/boot2_{variant}.cpp")
73-
try:
74-
ofilename.parent.mkdir(parents=True, exist_ok=True)
75-
with ofilename.open("w") as ofile:
76-
ofile.write("// Stage2 bootloader\n\n")
77-
ofile.write("#include <cstdint>\n")
78-
ofile.write('extern "C" __attribute__((section(".boot2"))) const uint8_t boot2[256] = {\n')
79-
for offs in range(0, len(odata), 16):
80-
chunk = odata[offs:min(offs + 16, len(odata))]
81-
ofile.write("\t {},\n".format(", ".join(f"0x{b:02x}" for b in chunk)))
82-
ofile.write("};\n")
83-
except:
84-
sys.exit("Could not open output file '{}'".format(ofilename))
79+
ofilename = Path(f"src/boot2_{target}_{variant}.cpp")
80+
try:
81+
ofilename.parent.mkdir(parents=True, exist_ok=True)
82+
with ofilename.open("w") as ofile:
83+
ofile.write("// Stage2 bootloader\n\n")
84+
ofile.write("#include <cstdint>\n")
85+
ofile.write('extern "C" __attribute__((section(".boot2"))) const uint8_t boot2[256] = {\n')
86+
for offs in range(0, len(odata), 16):
87+
chunk = odata[offs:min(offs + 16, len(odata))]
88+
ofile.write("\t {},\n".format(", ".join(f"0x{b:02x}" for b in chunk)))
89+
ofile.write("};\n")
90+
except:
91+
sys.exit("Could not open output file '{}'".format(ofilename))
8592

8693
partial.commit(files, tag)

0 commit comments

Comments
 (0)