Skip to content

Commit

Permalink
Merge branch 'develop' into actions-test
Browse files Browse the repository at this point in the history
  • Loading branch information
will-v-pi authored Sep 9, 2024
2 parents 9274b8c + 971ee85 commit dd54102
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 56 deletions.
21 changes: 6 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,15 @@ No need to download libusb separately or set `LIBUSB_ROOT`.
pacman -S $MINGW_PACKAGE_PREFIX-{toolchain,cmake,libusb}
mkdir build
cd build
MSYS2_ARG_CONV_EXCL=- cmake .. -G"MSYS Makefiles" -DCMAKE_INSTALL_PREFIX=$MINGW_PREFIX
make
make install DESTDIR=/ # optional
cmake .. -DCMAKE_INSTALL_PREFIX=$MINGW_PREFIX
cmake --build .
```

## Usage by the Raspberry Pi Pico SDK

The Raspberry Pi Pico SDK ([pico-sdk](https://github.com/raspberrypi/pico-sdk)) version 2.0.0 and above, uses `picotool` to do the ELF->UF2 conversion previously handled by the `elf2uf2` tool in the SDK. `picotool` is also used by the SDK for hashing and/or signing binaries.

Whilst the SDK can download picotool on its own per project, if you have multiple projects or build configurations, it is preferable to install a single copy of `picotool` locally.
The Raspberry Pi Pico SDK ([pico-sdk](https://github.com/raspberrypi/pico-sdk)) version 2.0.0 and above uses `picotool` to do the ELF-to-UF2 conversion previously handled by the `elf2uf2` tool in the SDK. The SDK also uses `picotool` to hash and sign binaries.

This can be done most simply with `make install`, using `sudo` if required; the SDK will use this installed version by default.
Whilst the SDK can download picotool on its own per project, if you have multiple projects or build configurations, it is preferable to install a single copy of `picotool` locally. This can be done most simply with `make install` or `cmake --install .`, using `sudo` if required; the SDK will use this installed version by default.

> On some Linux systems, the `~/.local` prefix may be used for an install without `sudo`; from your build directory simply run
> ```console
Expand All @@ -88,20 +85,14 @@ This can be done most simply with `make install`, using `sudo` if required; the
> ```
> This will only work if `~/.local` is included in your `PATH`
Alternatively you can install into any custom folder via:
Alternatively, you can install to a custom path via:
```console
cmake -DCMAKE_INSTALL_PREFIX=$MY_INSTALL_DIR -DPICOTOOL_FLAT_INSTALL=1 ..
make install
```
In order for the SDK to find `picotool` in this custom folder, you will usually need to set the `picotool_DIR` variable in your project. This can be achieved either by setting the `picotool_DIR` environment variable to `$MY_INSTALL_DIR/picotool`, by passing `-Dpicotool_DIR=$MY_INSTALL_DIR/picotool` to your SDK `cmake` command, or by adding

```CMake
set(picotool_DIR $MY_INSTALL_DIR/picotool)
```

to your CMakeLists.txt file.
In order for the SDK to find `picotool` in this custom folder, you will usually need to set the `picotool_DIR` variable in your project. This can be achieved either by setting the `picotool_DIR` environment variable to `$MY_INSTALL_DIR/picotool`, by passing `-Dpicotool_DIR=$MY_INSTALL_DIR/picotool` to your `cmake` command, or by adding `set(picotool_DIR $MY_INSTALL_DIR/picotool)` to your CMakeLists.txt file.

> See the [find_package documentation](https://cmake.org/cmake/help/latest/command/find_package.html#config-mode-search-procedure) for more details
Expand Down
2 changes: 1 addition & 1 deletion main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
#endif

// missing __builtins on windows
#ifdef _MSC_VER
#if defined(_MSC_VER) && !defined(__clang__)
# include <intrin.h>
# define __builtin_popcount __popcnt
static __forceinline int __builtin_ctz(unsigned x) {
Expand Down
2 changes: 1 addition & 1 deletion otp_header_parser/otp_header_parse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "nlohmann/json.hpp"

// missing __builtins on windows
#ifdef _MSC_VER
#if defined(_MSC_VER) && !defined(__clang__)
# include <intrin.h>
# define __builtin_popcount __popcnt
static __forceinline int __builtin_ctz(unsigned x) {
Expand Down
78 changes: 39 additions & 39 deletions xip_ram_perms/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
cmake_minimum_required(VERSION 3.12)

if (NOT USE_PRECOMPILED)
set(PICO_NO_PICOTOOL 1)

set(PICO_PLATFORM rp2350-arm-s)

# Pull in SDK (must be before project)
include(${PICO_SDK_PATH}/external/pico_sdk_import.cmake)

project(xip_ram_perms C CXX ASM)
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)

if (PICO_SDK_VERSION_STRING VERSION_LESS "2.0.0")
message(FATAL_ERROR "Raspberry Pi Pico SDK version 2.0.0 (or later) required. Your version is ${PICO_SDK_VERSION_STRING}")
endif()

# Initialize the SDK
pico_sdk_init()

# XIP Ram OTP Perm Setter
add_executable(xip_ram_perms
set_perms.c
)

target_link_libraries(xip_ram_perms
pico_stdlib
)

pico_set_binary_type(xip_ram_perms no_flash)
# create linker script to run from 0x20070000
file(READ ${PICO_LINKER_SCRIPT_PATH}/memmap_no_flash.ld LINKER_SCRIPT)
string(REPLACE "RAM(rwx) : ORIGIN = 0x20000000, LENGTH = 512k" "RAM(rwx) : ORIGIN = 0x13ffc000, LENGTH = 16k" LINKER_SCRIPT "${LINKER_SCRIPT}")
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/memmap_xip_ram.ld "${LINKER_SCRIPT}")
pico_set_linker_script(xip_ram_perms ${CMAKE_CURRENT_BINARY_DIR}/memmap_xip_ram.ld)
set(PICO_PLATFORM rp2350-arm-s)
set(PICO_NO_PICOTOOL 1)

# Pull in SDK (must be before project)
include(${PICO_SDK_PATH}/external/pico_sdk_import.cmake)

project(xip_ram_perms C CXX ASM)
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)

if (PICO_SDK_VERSION_STRING VERSION_LESS "2.0.0")
message(FATAL_ERROR "Raspberry Pi Pico SDK version 2.0.0 (or later) required. Your version is ${PICO_SDK_VERSION_STRING}")
endif()

# Initialize the SDK
pico_sdk_init()

# XIP Ram OTP Perm Setter
add_executable(xip_ram_perms
set_perms.c
)

target_link_libraries(xip_ram_perms
pico_stdlib
)

pico_set_binary_type(xip_ram_perms no_flash)
# create linker script to run from 0x20070000
file(READ ${PICO_LINKER_SCRIPT_PATH}/memmap_no_flash.ld LINKER_SCRIPT)
string(REPLACE "RAM(rwx) : ORIGIN = 0x20000000, LENGTH = 512k" "RAM(rwx) : ORIGIN = 0x13ffc000, LENGTH = 16k" LINKER_SCRIPT "${LINKER_SCRIPT}")
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/memmap_xip_ram.ld "${LINKER_SCRIPT}")
pico_set_linker_script(xip_ram_perms ${CMAKE_CURRENT_BINARY_DIR}/memmap_xip_ram.ld)
else()
project(xip_ram_perms C CXX ASM)
message("Using precompiled xip_ram_perms.elf")
configure_file(${CMAKE_CURRENT_LIST_DIR}/xip_ram_perms.elf ${CMAKE_CURRENT_BINARY_DIR}/xip_ram_perms.elf COPYONLY)
# Use manually specified variables
set(NULL ${CMAKE_MAKE_PROGRAM})
set(NULL ${PICO_SDK_PATH})
project(xip_ram_perms C CXX ASM)
message("Using precompiled xip_ram_perms.elf")
configure_file(${CMAKE_CURRENT_LIST_DIR}/xip_ram_perms.elf ${CMAKE_CURRENT_BINARY_DIR}/xip_ram_perms.elf COPYONLY)
# Use manually specified variables
set(NULL ${CMAKE_MAKE_PROGRAM})
set(NULL ${PICO_SDK_PATH})
endif()

0 comments on commit dd54102

Please sign in to comment.