From 867362f0248e78f985f9eb29eb81aac33f926871 Mon Sep 17 00:00:00 2001 From: sidart Date: Tue, 15 Jul 2025 02:30:09 -0700 Subject: [PATCH] Summary: Add Initial support to pico2 (Arm Cortex M) Test Plan: TBD Reviewers: Subscribers: Tasks: Tags: --- CMakeLists.txt | 1 + examples/arm/rp_pi/CMakeLists.txt | 21 +++ examples/arm/rp_pi/README.md | 53 +++++++ .../rp_pi/arm-cortex-m0plus-toolchain.cmake | 33 ++++ examples/arm/rp_pi/pico2/CMakeLists.txt | 50 ++++++ examples/arm/rp_pi/pico2/main.cpp | 147 ++++++++++++++++++ .../arm/rp_pi/pico2/simple_addmodule_pte.c | 47 ++++++ .../arm/rp_pi/pico2/simple_addmodule_pte.h | 21 +++ examples/arm/rp_pi/syscall_stubs.c | 41 +++++ 9 files changed, 414 insertions(+) create mode 100644 examples/arm/rp_pi/CMakeLists.txt create mode 100644 examples/arm/rp_pi/README.md create mode 100644 examples/arm/rp_pi/arm-cortex-m0plus-toolchain.cmake create mode 100644 examples/arm/rp_pi/pico2/CMakeLists.txt create mode 100644 examples/arm/rp_pi/pico2/main.cpp create mode 100644 examples/arm/rp_pi/pico2/simple_addmodule_pte.c create mode 100644 examples/arm/rp_pi/pico2/simple_addmodule_pte.h create mode 100644 examples/arm/rp_pi/syscall_stubs.c diff --git a/CMakeLists.txt b/CMakeLists.txt index c17ff893830..c4fd8aa617f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -494,6 +494,7 @@ install(FILES tools/cmake/Utils.cmake tools/cmake/executorch-config.cmake if(EXECUTORCH_BUILD_ARM_BAREMETAL) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/backends/arm) + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/examples/arm/rp_pi) endif() if(EXECUTORCH_BUILD_CADENCE) diff --git a/examples/arm/rp_pi/CMakeLists.txt b/examples/arm/rp_pi/CMakeLists.txt new file mode 100644 index 00000000000..d1cedee4151 --- /dev/null +++ b/examples/arm/rp_pi/CMakeLists.txt @@ -0,0 +1,21 @@ +# Copyright (c) Meta Platforms, Inc. and affiliates. +# All rights reserved. +# Copyright 2023-2025 Arm Limited and/or its affiliates. +# +# This source code is licensed under the BSD-style license found in the +# LICENSE file in the root directory of this source tree. + +cmake_minimum_required(VERSION 3.10) +project(pico) + +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) +set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../../) + + +set(CMAKE_TOOLCHAIN_FILE ${CMAKE_CURRENT_SOURCE_DIR}/arm-cortex-m0plus-toolchain.cmake) + +# Only include here, NOT in arm-cortex-m0plus-toolchain.cmake +include(${CMAKE_SOURCE_DIR}/tools/cmake/Codegen.cmake) + +target_sources(executorch_core PRIVATE ${CMAKE_CURRENT_LIST_DIR}/syscall_stubs.c) +#gen_selected_ops(LIB_NAME "portable_ops_lib" ROOT_OPS "aten::add.out") diff --git a/examples/arm/rp_pi/README.md b/examples/arm/rp_pi/README.md new file mode 100644 index 00000000000..e2e0ea9cbaf --- /dev/null +++ b/examples/arm/rp_pi/README.md @@ -0,0 +1,53 @@ +## Overview +This document outlines the steps required to run a simple Add Module on the Pico2 microcontroller using executorch. +## Steps + +### (Pre-requisistes) Prepare the Environment for Arm +1. See for instructions on setting up the environment for Arm. +2. Make sure you have the toolchain configured correctly. +```bash +which arm-none-eabi-gcc +``` should return something like 'executorch/examples/arm/ethos-u-scratch/arm-gnu-toolchain-13.3.rel1-x86_64-arm-none-eabi/bin/arm-none-eabi-gcc' + +### 1. Cross Compile Executorch for Arm Cortex M Target +To begin, navigate to the executorch root directory and execute the following commands: +```bash +mkdir baremetal_build +cd baremetal_build +cmake .. -DCMAKE_TOOLCHAIN_FILE=./examples/arm/rp_pi/pico2/arm-cortex-m0plus-toolchain.cmake -DEXECUTORCH_BUILD_ARM_BAREMETAL=ON -DCMAKE_BUILD_TYPE=Release -DROOT_OPS=aten::add.out +cmake --build . -j$(nproc) +``` + +### 2. Export PICO_SDK_PATH +Download the Pico SDK from GitHub: https://github.com/raspberrypi/pico-sdk and set the PICO_SDK_PATH environment variable: +```bash +export PICO_SDK_PATH= +``` + +### 3. Build the example for Pico2 +Go to the example directory and initiate the build process: +```bash +cd examples/arm/rp_pi/pico2/ +rm -rf build +mkdir build +cd build +cmake .. -DPICO_BOARD=pico2 -DCMAKE_BUILD_TYPE=Release +cmake --build . -j$(nproc) +``` +This will generate the firmware file executorch_pico.uf2. + +### 4. Flash the Firmware +Press and hold the BOOTSEL button on the Pico2. +Connect the Pico2 to your computer; it should mount as RPI-RP2. +Copy the executorch_pico.uf2 file to the mounted drive. + +### 5. Verify the Firmware +Check that the Pico2's LED blinks 10 times to confirm successful firmware execution. + +### 6. (Optional) Check USB Logs on Mac +To view USB logs, use the following command (as an example): +```bash +screen /dev/tty.usbmodem1101 115200 +``` + +These steps complete the process required to run the simple Add Module on the Pico2 microcontroller using executorch. diff --git a/examples/arm/rp_pi/arm-cortex-m0plus-toolchain.cmake b/examples/arm/rp_pi/arm-cortex-m0plus-toolchain.cmake new file mode 100644 index 00000000000..c774347e09d --- /dev/null +++ b/examples/arm/rp_pi/arm-cortex-m0plus-toolchain.cmake @@ -0,0 +1,33 @@ +# Copyright (c) Meta Platforms, Inc. and affiliates. +# All rights reserved. +# Copyright 2023-2025 Arm Limited and/or its affiliates. +# +# This source code is licensed under the BSD-style license found in the +# LICENSE file in the root directory of this source tree. + +# cortex-m0plus cmake + +if(NOT DEFINED EXECUTORCH_BUILD_ARM_BAREMETAL) + # If not defined, assume we're building standalone + set(EXECUTORCH_BUILD_ARM_BAREMETAL ON) +endif() +set(CMAKE_SYSTEM_NAME Generic) +set(CMAKE_SYSTEM_PROCESSOR cortex-m0plus) + +if(NOT DEFINED CMAKE_C_COMPILER) + set(CMAKE_C_COMPILER arm-none-eabi-gcc CACHE STRING "C compiler") +endif() + +if(NOT DEFINED CMAKE_CXX_COMPILER) + set(CMAKE_CXX_COMPILER arm-none-eabi-g++ CACHE STRING "C++ compiler") +endif() + +set(CPU_FLAGS "-mcpu=cortex-m0plus -mthumb -mfloat-abi=soft") +# C flags (no RTTI or exceptions here, since RTTI is C++-only) +set(CMAKE_C_FLAGS "${CPU_FLAGS} -O2 -ffunction-sections -fdata-sections -fno-exceptions -fno-unwind-tables") + +# C++ flags (RTTI-related flags go here) +set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -fno-rtti -fno-use-cxa-atexit -ffunction-sections -fdata-sections") + +# Linker flags +set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections -nostartfiles -flto") diff --git a/examples/arm/rp_pi/pico2/CMakeLists.txt b/examples/arm/rp_pi/pico2/CMakeLists.txt new file mode 100644 index 00000000000..36c83b05177 --- /dev/null +++ b/examples/arm/rp_pi/pico2/CMakeLists.txt @@ -0,0 +1,50 @@ +cmake_minimum_required(VERSION 3.13) +include($ENV{PICO_SDK_PATH}/external/pico_sdk_import.cmake) +project(executorch_pico C CXX ASM) +pico_sdk_init() + +set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../../../..) +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + +# Replace xxx_pte.c with your model's pte file +add_executable(executorch_pico main.cpp simple_addmodule_pte.c) +pico_enable_stdio_usb(executorch_pico 1) +pico_enable_stdio_uart(executorch_pico 0) + +target_include_directories(executorch_pico PRIVATE + ${EXECUTORCH_ROOT}/executorch/runtime/core/portable_type/c10 +) +add_compile_definitions(C10_USING_CUSTOM_GENERATED_MACROS) + +# Set correct flags for Pico (Cortex-M0+) +target_compile_options(executorch_pico PRIVATE + -mcpu=cortex-m0plus + -mfloat-abi=soft + -mthumb +) + +set(BAREMETAL_BUILD_DIR ${EXECUTORCH_ROOT}/executorch/baremetal_build/) +# Link Executorch and Pico libraries +target_link_libraries(executorch_pico + PRIVATE + ${BAREMETAL_BUILD_DIR}/libexecutorch.a + ${BAREMETAL_BUILD_DIR}/libexecutorch_core.a + -Wl,--whole-archive + ${BAREMETAL_BUILD_DIR}/kernels/portable/libportable_ops_lib.a + -Wl,--no-whole-archive + ${BAREMETAL_BUILD_DIR}/kernels/portable/libportable_kernels.a + pico_stdlib + pico_stdio_usb +) + +# Include Executorch and third-party headers +target_include_directories(executorch_pico PRIVATE + ${EXECUTORCH_ROOT} + ${EXECUTORCH_ROOT}/executorch/third-party/ + # Add other include paths as needed +) + +#set(CMAKE_C_FLAGS "-Os -ffunction-sections -fdata-sections") +set(CMAKE_EXE_LINKER_FLAGS "-Wl,--gc-sections") + +pico_add_extra_outputs(executorch_pico) diff --git a/examples/arm/rp_pi/pico2/main.cpp b/examples/arm/rp_pi/pico2/main.cpp new file mode 100644 index 00000000000..2a261a72000 --- /dev/null +++ b/examples/arm/rp_pi/pico2/main.cpp @@ -0,0 +1,147 @@ +/* Copyright (c) Meta Platforms, Inc. and affiliates. + * All rights reserved. + * Copyright 2023-2025 Arm Limited and/or its affiliates. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. + */ + + // Model data +#include "simple_addmodule_pte.h" + +// Pico includes +#include "pico/stdio_usb.h" +#include "pico/stdlib.h" + +// Executorch includes +#include +#include +#include +#include +#include +#include + +// Std c++ includes +#include + +using namespace executorch::runtime; +using executorch::aten::Tensor; +using executorch::aten::TensorImpl; +using ScalarType = executorch::runtime::etensor::ScalarType; +using executorch::runtime::runtime_init; + +// Define GPIO pins for indicators +const uint INDICATOR_PIN_1 = 25; // Onboard LED +const uint INDICATOR_PIN_2 = 22; // External LED +const uint INDICATOR_PIN_3 = 23; // Onboard LED + +void wait_for_usb() { + const int kMaxRetryCount = 10; + int retry_usb_count = 0; + while (!stdio_usb_connected() && retry_usb_count++ < kMaxRetryCount) { + printf("Retry again! USB not connected \n"); + sleep_ms(100); + } +} + +// Make sure blink_indicator is defined somewhere, or add a stub if not +void blink_indicator(uint pin, int times, int delay_ms = 100) { + for (int i = 0; i < times; ++i) { + gpio_put(pin, 1); + sleep_ms(delay_ms); + gpio_put(pin, 0); + sleep_ms(delay_ms); + } +} + +bool load_and_prepare_model(std::unique_ptr& program_ptr, std::unique_ptr& method_ptr, MemoryManager& memory_manager) { + executorch::extension::BufferDataLoader loader(model_pte, model_pte_len); + auto program_result = Program::load(&loader); + if (!program_result.ok()) { + printf("Failed to load model: %d\n", (int)program_result.error()); + blink_indicator(INDICATOR_PIN_1, 10); + return false; + } + program_ptr = std::make_unique(std::move(*program_result)); + auto method_name_result = program_ptr->get_method_name(0); + if (!method_name_result.ok()) { + printf("Failed to get method name: %d\n", (int)method_name_result.error()); + blink_indicator(INDICATOR_PIN_1, 10); + return false; + } + auto method_result = program_ptr->load_method(*method_name_result, &memory_manager); + if (!method_result.ok()) { + printf("Failed to load method: %d\n", (int)method_result.error()); + blink_indicator(INDICATOR_PIN_1, 10); + return false; + } + method_ptr = std::make_unique(std::move(*method_result)); + printf("Method loaded [%s]\n", *method_name_result); + return true; +} + +bool run_inference(Method& method) { + float input_data_0[4] = {4.0, 109.0, 13.0, 123.0}; + float input_data_1[4] = {9.0, 27.0, 11.0, 8.0}; + TensorImpl::SizesType sizes[1] = {4}; + TensorImpl::DimOrderType dim_order[] = {0}; + TensorImpl impl0(ScalarType::Float, 1, sizes, input_data_0, dim_order); + TensorImpl impl1(ScalarType::Float, 1, sizes, input_data_1, dim_order); + Tensor input0(&impl0); + Tensor input1(&impl1); + + if (method.set_input(input0, 0) != Error::Ok || method.set_input(input1, 1) != Error::Ok) { + printf("Failed to set input(s)\n"); + blink_indicator(INDICATOR_PIN_1, 10); + return false; + } + if (method.execute() != Error::Ok) { + printf("Failed to execute\n"); + blink_indicator(INDICATOR_PIN_1, 10); + return false; + } + const EValue& output = method.get_output(0); + if (output.isTensor()) { + const float* out_data = output.toTensor().const_data_ptr(); + printf("Output: %f, %f, %f, %f\n", out_data[0], out_data[1], out_data[2], out_data[3]); + } else { + printf("Output is not a tensor!\n"); + blink_indicator(INDICATOR_PIN_1, 10); + return false; + } + return true; +} + +int executor_runner() { + stdio_init_all(); + sleep_ms(1000); + + wait_for_usb(); + runtime_init(); + + static uint8_t method_allocator_pool[1024]; + static uint8_t activation_pool[512]; + MemoryAllocator method_allocator(sizeof(method_allocator_pool), method_allocator_pool); + method_allocator.enable_profiling("method allocator"); + Span memory_planned_buffers[1]{{activation_pool, sizeof(activation_pool)}}; + HierarchicalAllocator planned_memory({memory_planned_buffers, 1}); + MemoryManager memory_manager(&method_allocator, &planned_memory); + + std::unique_ptr program_ptr; + std::unique_ptr method_ptr; + if (!load_and_prepare_model(program_ptr, method_ptr, memory_manager)) { + printf("Failed to load and prepare model\n"); + return 1; + } + if (!run_inference(*method_ptr)) { + printf("Failed to run inference\n"); + return 1; + } + + blink_indicator(INDICATOR_PIN_1, 100, 500); + return 0; +} + +int main() { + return executor_runner(); +} diff --git a/examples/arm/rp_pi/pico2/simple_addmodule_pte.c b/examples/arm/rp_pi/pico2/simple_addmodule_pte.c new file mode 100644 index 00000000000..8befb8e7037 --- /dev/null +++ b/examples/arm/rp_pi/pico2/simple_addmodule_pte.c @@ -0,0 +1,47 @@ +/* Copyright (c) Meta Platforms, Inc. and affiliates. + * All rights reserved. + * Copyright 2023-2025 Arm Limited and/or its affiliates. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. + */ + +#include "simple_addmodule_pte.h" + +const uint8_t model_pte[] __attribute__((aligned(8))) = { +0x1c, 0x00, 0x00, 0x00, 0x45, 0x54, 0x31, 0x32, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x18, 0x00, 0x00, 0x00, 0x04, 0x00, 0x08, 0x00, 0x0c, 0x00, 0x10, 0x00, 0x14, 0x00, 0x10, 0x00, 0x00, 0x00, +0x44, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x0c, 0xff, 0xff, 0xff, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x04, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, 0x00, 0x28, 0x00, 0x04, 0x00, 0x08, 0x00, 0x0c, 0x00, 0x10, 0x00, 0x14, 0x00, 0x18, 0x00, 0x1c, 0x00, +0x20, 0x00, 0x24, 0x00, 0x16, 0x00, 0x00, 0x00, 0x9c, 0x03, 0x00, 0x00, 0x10, 0x02, 0x00, 0x00, 0xdc, 0x00, 0x00, 0x00, 0xcc, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x54, 0x00, 0x00, 0x00, +0x24, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x38, 0xfe, 0xff, 0xff, 0x10, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x6f, 0x75, 0x74, 0x00, +0x09, 0x00, 0x00, 0x00, 0x61, 0x74, 0x65, 0x6e, 0x3a, 0x3a, 0x61, 0x64, 0x64, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x10, 0x00, 0x04, 0x00, +0x08, 0x00, 0x0c, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x4c, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x24, 0xff, 0xff, 0xff, +0x00, 0x00, 0x00, 0x01, 0x0c, 0x00, 0x00, 0x00, 0x08, 0x00, 0x08, 0x00, 0x00, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, +0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xd4, 0x00, 0x00, 0x00, 0x8c, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, +0x44, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x02, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x10, 0x00, 0x04, 0x00, 0x06, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x68, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x05, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x00, 0x16, 0x00, 0x07, 0x00, 0x00, 0x00, 0x08, 0x00, 0x0c, 0x00, 0x00, 0x00, +0x00, 0x00, 0x10, 0x00, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x24, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x08, 0x00, 0x04, 0x00, +0x06, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, 0x00, 0x0c, 0x00, 0x07, 0x00, 0x08, 0x00, +0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x04, 0x00, 0x00, 0x00, 0xba, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x06, 0x20, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, +0x8c, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, 0x00, 0x0e, 0x00, +0x07, 0x00, 0x08, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x00, 0x14, 0x00, 0x07, 0x00, 0x00, 0x00, 0x08, 0x00, 0x0c, 0x00, 0x00, 0x00, +0x00, 0x00, 0x10, 0x00, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x20, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xe4, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, +0x20, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, 0x00, 0x0c, 0x00, 0x04, 0x00, 0x08, 0x00, 0x08, 0x00, 0x00, 0x00, +0x48, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x39, 0x00, 0x00, 0x00, 0x5b, 0x31, 0x2c, 0x20, 0x7b, 0x22, 0x74, 0x79, 0x70, 0x65, 0x22, 0x3a, 0x20, 0x6e, 0x75, 0x6c, 0x6c, 0x2c, 0x20, 0x22, +0x63, 0x6f, 0x6e, 0x74, 0x65, 0x78, 0x74, 0x22, 0x3a, 0x20, 0x6e, 0x75, 0x6c, 0x6c, 0x2c, 0x20, 0x22, 0x63, 0x68, 0x69, 0x6c, 0x64, 0x72, 0x65, 0x6e, 0x5f, 0x73, 0x70, 0x65, 0x63, 0x22, 0x3a, +0x20, 0x5b, 0x5d, 0x7d, 0x5d, 0x00, 0x00, 0x00, 0x34, 0x01, 0x00, 0x00, 0x5b, 0x31, 0x2c, 0x20, 0x7b, 0x22, 0x74, 0x79, 0x70, 0x65, 0x22, 0x3a, 0x20, 0x22, 0x62, 0x75, 0x69, 0x6c, 0x74, 0x69, +0x6e, 0x73, 0x2e, 0x74, 0x75, 0x70, 0x6c, 0x65, 0x22, 0x2c, 0x20, 0x22, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x78, 0x74, 0x22, 0x3a, 0x20, 0x22, 0x6e, 0x75, 0x6c, 0x6c, 0x22, 0x2c, 0x20, 0x22, 0x63, +0x68, 0x69, 0x6c, 0x64, 0x72, 0x65, 0x6e, 0x5f, 0x73, 0x70, 0x65, 0x63, 0x22, 0x3a, 0x20, 0x5b, 0x7b, 0x22, 0x74, 0x79, 0x70, 0x65, 0x22, 0x3a, 0x20, 0x22, 0x62, 0x75, 0x69, 0x6c, 0x74, 0x69, +0x6e, 0x73, 0x2e, 0x74, 0x75, 0x70, 0x6c, 0x65, 0x22, 0x2c, 0x20, 0x22, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x78, 0x74, 0x22, 0x3a, 0x20, 0x22, 0x6e, 0x75, 0x6c, 0x6c, 0x22, 0x2c, 0x20, 0x22, 0x63, +0x68, 0x69, 0x6c, 0x64, 0x72, 0x65, 0x6e, 0x5f, 0x73, 0x70, 0x65, 0x63, 0x22, 0x3a, 0x20, 0x5b, 0x7b, 0x22, 0x74, 0x79, 0x70, 0x65, 0x22, 0x3a, 0x20, 0x6e, 0x75, 0x6c, 0x6c, 0x2c, 0x20, 0x22, +0x63, 0x6f, 0x6e, 0x74, 0x65, 0x78, 0x74, 0x22, 0x3a, 0x20, 0x6e, 0x75, 0x6c, 0x6c, 0x2c, 0x20, 0x22, 0x63, 0x68, 0x69, 0x6c, 0x64, 0x72, 0x65, 0x6e, 0x5f, 0x73, 0x70, 0x65, 0x63, 0x22, 0x3a, +0x20, 0x5b, 0x5d, 0x7d, 0x2c, 0x20, 0x7b, 0x22, 0x74, 0x79, 0x70, 0x65, 0x22, 0x3a, 0x20, 0x6e, 0x75, 0x6c, 0x6c, 0x2c, 0x20, 0x22, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x78, 0x74, 0x22, 0x3a, 0x20, +0x6e, 0x75, 0x6c, 0x6c, 0x2c, 0x20, 0x22, 0x63, 0x68, 0x69, 0x6c, 0x64, 0x72, 0x65, 0x6e, 0x5f, 0x73, 0x70, 0x65, 0x63, 0x22, 0x3a, 0x20, 0x5b, 0x5d, 0x7d, 0x5d, 0x7d, 0x2c, 0x20, 0x7b, 0x22, +0x74, 0x79, 0x70, 0x65, 0x22, 0x3a, 0x20, 0x22, 0x62, 0x75, 0x69, 0x6c, 0x74, 0x69, 0x6e, 0x73, 0x2e, 0x64, 0x69, 0x63, 0x74, 0x22, 0x2c, 0x20, 0x22, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x78, 0x74, +0x22, 0x3a, 0x20, 0x22, 0x5b, 0x5d, 0x22, 0x2c, 0x20, 0x22, 0x63, 0x68, 0x69, 0x6c, 0x64, 0x72, 0x65, 0x6e, 0x5f, 0x73, 0x70, 0x65, 0x63, 0x22, 0x3a, 0x20, 0x5b, 0x5d, 0x7d, 0x5d, 0x7d, 0x5d, +0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x66, 0x6f, 0x72, 0x77, 0x61, 0x72, 0x64, 0x00, }; + +const unsigned int model_pte_len = sizeof(model_pte); diff --git a/examples/arm/rp_pi/pico2/simple_addmodule_pte.h b/examples/arm/rp_pi/pico2/simple_addmodule_pte.h new file mode 100644 index 00000000000..af948056de3 --- /dev/null +++ b/examples/arm/rp_pi/pico2/simple_addmodule_pte.h @@ -0,0 +1,21 @@ +/* Copyright (c) Meta Platforms, Inc. and affiliates. + * All rights reserved. + * Copyright 2023-2025 Arm Limited and/or its affiliates. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. + */ + +#pragma once +#include + +#ifdef __cplusplus +extern "C" { +#endif + +extern const uint8_t model_pte[] __attribute__((aligned(8))); +extern const unsigned int model_pte_len; + +#ifdef __cplusplus +} +#endif diff --git a/examples/arm/rp_pi/syscall_stubs.c b/examples/arm/rp_pi/syscall_stubs.c new file mode 100644 index 00000000000..5b8195f2eea --- /dev/null +++ b/examples/arm/rp_pi/syscall_stubs.c @@ -0,0 +1,41 @@ +/* Copyright (c) Meta Platforms, Inc. and affiliates. + * All rights reserved. + * Copyright 2023-2025 Arm Limited and/or its affiliates. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. + */ + +#include +#include +#include + +/* + * We are adding a custom syscall_stubs.c file to provide dummy implementations for syscalls that are not + * available on the Pico platform. This is necessary because the Pico does not have an operating system, + * and therefore does not support standard C library functions like _exit, _sbrk, _read, etc. + * By adding these stubs, we can resolve linker errors that occur when building our project for the Pico. + * The stubs will be compiled and linked into our final executable, allowing it to run on the target hardware. +*/ +#ifdef __cplusplus +extern "C" { +#endif +void *__dso_handle = 0; +int fnmatch(const char *pattern, const char *string, int flags) { return 1; } +ssize_t pread(int fd, void *buf, size_t count, off_t offset) { return -1; } +void _fini(void) {} +void _exit(int status) { while (1) {} } +void* _sbrk(ptrdiff_t incr) { return (void*)-1; } +int _read(int file, char *ptr, int len) { return -1; } +int _write(int file, char *ptr, int len) { return -1; } +int _close(int file) { return -1; } +int _fstat(int file, void *st) { return 0; } +int _lseek(int file, int ptr, int dir) { return 0; } +int _isatty(int file) { return 1; } +int _kill(int pid, int sig) { return -1; } +int _getpid(void) { return 1; } +int _open(const char *name, int flags, int mode) { return -1; } +int _gettimeofday(void *tv, void *tz) { return -1; } +#ifdef __cplusplus +} +#endif