Skip to content

Commit da93fc4

Browse files
committed
Add RP2350 target
1 parent 4bfd68b commit da93fc4

File tree

3 files changed

+63
-50
lines changed

3 files changed

+63
-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: 56 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,32 @@
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+
# See https://github.com/raspberrypi/pico-sdk/issues/2126
35+
boot2_variants = {
36+
"generic_03h": ["rp2040", "rp2350"],
37+
"at25sf128a": ["rp2040"],
38+
"is25lp080": ["rp2040"],
39+
"w25q080": ["rp2040", "rp2350"],
40+
"w25x10cl": ["rp2040"],
41+
}
3542
def run(where, command, stdin=None):
3643
print(command)
3744
result = subprocess.run(command, shell=True, cwd=where, input=stdin, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
@@ -46,41 +53,42 @@ def run(where, command, stdin=None):
4653
def bitrev(x, width):
4754
return int("{:0{w}b}".format(x, w=width)[::-1], 2)
4855

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

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

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

8694
partial.commit(files, tag)

0 commit comments

Comments
 (0)