|
5 | 5 | import shutil |
6 | 6 | import json |
7 | 7 | import multiprocessing |
| 8 | +import configparser |
| 9 | +import platform |
8 | 10 |
|
9 | 11 | from pico_project import GenerateCMake |
10 | 12 |
|
| 13 | +# This script is designed to be run on Linux |
| 14 | +assert platform.system() == "Linux" |
| 15 | + |
11 | 16 | boards = ["pico", "pico_w", "pico2", "pico2_w"] |
12 | 17 |
|
13 | 18 | platforms = { |
|
32 | 37 |
|
33 | 38 | CURRENT_DATA_VERSION = "0.17.0" |
34 | 39 |
|
35 | | -SDK_VERSION = "2.1.1" |
| 40 | +SDK_VERSION = os.environ.get("SDK_VERSION", "2.1.1") |
| 41 | +ARM_TOOLCHAIN_VERSION = os.environ.get("ARM_TOOLCHAIN_VERSION", "14_2_Rel1") |
| 42 | +RISCV_TOOLCHAIN_VERSION = os.environ.get( |
| 43 | + "RISCV_TOOLCHAIN_VERSION", "RISCV_ZCB_RPI_2_1_1_3" |
| 44 | +) |
| 45 | + |
| 46 | +# To test with develop SDK, uncomment the line below - this will clone the SDK & picotool, and build picotool & pioasm |
| 47 | +# note: the 2- is required due to a VERSION_LESS check in pico-vscode.cmake |
| 48 | +# SDK_VERSION = "2-develop" |
| 49 | + |
| 50 | +BUILD_TOOLS = not os.path.exists(os.path.expanduser(f"~/.pico-sdk/sdk/{SDK_VERSION}")) |
| 51 | + |
| 52 | +if "develop" in SDK_VERSION: |
| 53 | + SDK_BRANCH = "develop" |
| 54 | + PICOTOOL_BRANCH = "develop" |
| 55 | + EXAMPLES_BRANCH = "develop" |
| 56 | + BUILD_TOOLS = True # Always clone & build the latest when using develop |
| 57 | +else: |
| 58 | + SDK_BRANCH = SDK_VERSION |
| 59 | + PICOTOOL_BRANCH = SDK_VERSION |
| 60 | + EXAMPLES_BRANCH = f"sdk-{SDK_VERSION}" |
| 61 | + |
| 62 | +# Platform & toolchain setup |
| 63 | +platform = "linux_x64" if platform.machine() == "x86_64" else "linux_arm64" |
| 64 | +config = configparser.ConfigParser() |
| 65 | +config.read( |
| 66 | + f"{os.path.dirname(os.path.realpath(__file__))}/../data/{CURRENT_DATA_VERSION}/supportedToolchains.ini" |
| 67 | +) |
| 68 | + |
| 69 | +# Download arm toolchain if not already downloaded |
| 70 | +if not os.path.exists( |
| 71 | + os.path.expanduser(f"~/.pico-sdk/toolchain/{ARM_TOOLCHAIN_VERSION}") |
| 72 | +): |
| 73 | + toolchain_url = config[ARM_TOOLCHAIN_VERSION][platform] |
| 74 | + os.mkdir(os.path.expanduser(f"~/.pico-sdk/toolchain/{ARM_TOOLCHAIN_VERSION}")) |
| 75 | + os.system(f"wget {toolchain_url}") |
| 76 | + os.system( |
| 77 | + f"tar -xf {toolchain_url.split('/')[-1]} --strip-components 1 -C ~/.pico-sdk/toolchain/{ARM_TOOLCHAIN_VERSION}" |
| 78 | + ) |
| 79 | + os.system(f"rm {toolchain_url.split('/')[-1]}") |
| 80 | + |
| 81 | +# Download riscv toolchain if not already downloaded |
| 82 | +if not os.path.exists( |
| 83 | + os.path.expanduser(f"~/.pico-sdk/toolchain/{RISCV_TOOLCHAIN_VERSION}") |
| 84 | +): |
| 85 | + toolchain_url = config[RISCV_TOOLCHAIN_VERSION][platform] |
| 86 | + os.mkdir(os.path.expanduser(f"~/.pico-sdk/toolchain/{RISCV_TOOLCHAIN_VERSION}")) |
| 87 | + os.system(f"wget {toolchain_url}") |
| 88 | + os.system( |
| 89 | + f"tar -xf {toolchain_url.split('/')[-1]} -C ~/.pico-sdk/toolchain/{RISCV_TOOLCHAIN_VERSION}" |
| 90 | + ) |
| 91 | + os.system(f"rm {toolchain_url.split('/')[-1]}") |
| 92 | + |
| 93 | +if BUILD_TOOLS: |
| 94 | + # Clone pico-sdk |
| 95 | + try: |
| 96 | + shutil.rmtree(os.path.expanduser(f"~/.pico-sdk/sdk/{SDK_VERSION}")) |
| 97 | + except FileNotFoundError: |
| 98 | + pass |
| 99 | + os.system( |
| 100 | + f"git -c advice.detachedHead=false clone https://github.com/raspberrypi/pico-sdk.git --depth=1 --branch {SDK_BRANCH} --recurse-submodules --shallow-submodules ~/.pico-sdk/sdk/{SDK_VERSION}" |
| 101 | + ) |
| 102 | + |
| 103 | + # Clone & build picotool |
| 104 | + try: |
| 105 | + shutil.rmtree("picotool") |
| 106 | + except FileNotFoundError: |
| 107 | + pass |
| 108 | + try: |
| 109 | + shutil.rmtree("picotool-build") |
| 110 | + except FileNotFoundError: |
| 111 | + pass |
| 112 | + try: |
| 113 | + shutil.rmtree(os.path.expanduser(f"~/.pico-sdk/picotool/{SDK_VERSION}")) |
| 114 | + except FileNotFoundError: |
| 115 | + pass |
| 116 | + os.system( |
| 117 | + f"git -c advice.detachedHead=false clone https://github.com/raspberrypi/picotool.git --depth=1 --branch {PICOTOOL_BRANCH}" |
| 118 | + ) |
| 119 | + os.system( |
| 120 | + f"cmake -S picotool -B picotool-build -GNinja -DPICO_SDK_PATH=~/.pico-sdk/sdk/{SDK_VERSION} -DPICOTOOL_FLAT_INSTALL=1 -DPICOTOOL_NO_LIBUSB=1" |
| 121 | + ) |
| 122 | + os.system(f"cmake --build picotool-build") |
| 123 | + os.system( |
| 124 | + f"cmake --install picotool-build --prefix ~/.pico-sdk/picotool/{SDK_VERSION}" |
| 125 | + ) |
| 126 | + |
| 127 | + # Build pioasm |
| 128 | + try: |
| 129 | + shutil.rmtree("pioasm-build") |
| 130 | + except FileNotFoundError: |
| 131 | + pass |
| 132 | + try: |
| 133 | + shutil.rmtree(os.path.expanduser(f"~/.pico-sdk/tools/{SDK_VERSION}")) |
| 134 | + except FileNotFoundError: |
| 135 | + pass |
| 136 | + os.system( |
| 137 | + f"cmake -S ~/.pico-sdk/sdk/{SDK_VERSION}/tools/pioasm -B pioasm-build -GNinja -DPIOASM_FLAT_INSTALL=1 -DPIOASM_VERSION_STRING={SDK_VERSION}" |
| 138 | + ) |
| 139 | + os.system(f"cmake --build pioasm-build") |
| 140 | + os.system(f"cmake --install pioasm-build --prefix ~/.pico-sdk/tools/{SDK_VERSION}") |
36 | 141 |
|
37 | 142 | try: |
38 | 143 | shutil.rmtree("pico-examples") |
|
44 | 149 | except FileNotFoundError: |
45 | 150 | pass |
46 | 151 | os.system( |
47 | | - f"git -c advice.detachedHead=false clone https://github.com/raspberrypi/pico-examples.git --depth=1 --branch sdk-{SDK_VERSION}" |
| 152 | + f"git -c advice.detachedHead=false clone https://github.com/raspberrypi/pico-examples.git --depth=1 --branch {EXAMPLES_BRANCH}" |
48 | 153 | ) |
49 | 154 | os.environ["PICO_SDK_PATH"] = f"~/.pico-sdk/sdk/{SDK_VERSION}" |
50 | 155 | os.environ["WIFI_SSID"] = "Your Wi-Fi SSID" |
|
65 | 170 | except FileNotFoundError: |
66 | 171 | pass |
67 | 172 | toolchainVersion = ( |
68 | | - "RISCV_ZCB_RPI_2_1_1_3" if "riscv" in platform else "14_2_Rel1" |
| 173 | + RISCV_TOOLCHAIN_VERSION if "riscv" in platform else ARM_TOOLCHAIN_VERSION |
69 | 174 | ) |
70 | 175 | toolchainPath = f"~/.pico-sdk/toolchain/{toolchainVersion}" |
71 | 176 | picotoolDir = f"~/.pico-sdk/picotool/{SDK_VERSION}/picotool" |
@@ -148,6 +253,9 @@ def test_build(target, v): |
148 | 253 | dir = f"tmp-{target}" |
149 | 254 | try: |
150 | 255 | shutil.rmtree(dir) |
| 256 | + except FileNotFoundError: |
| 257 | + pass |
| 258 | + try: |
151 | 259 | shutil.rmtree(f"{dir}-build") |
152 | 260 | except FileNotFoundError: |
153 | 261 | pass |
@@ -210,7 +318,7 @@ def test_build(target, v): |
210 | 318 |
|
211 | 319 | ordered_targets.extend(target_locs.keys()) |
212 | 320 |
|
213 | | - with multiprocessing.Pool(processes=22) as pool: |
| 321 | + with multiprocessing.Pool(processes=os.cpu_count()) as pool: |
214 | 322 | ret = pool.starmap( |
215 | 323 | test_build, |
216 | 324 | [(target, v) for target, v in target_locs.items()], |
|
0 commit comments