This is an automated email from the ASF dual-hosted git repository.
acassis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new 2477914ea62 board/arm/rp2040: implement "board_boot_image" for
bootloader support
2477914ea62 is described below
commit 2477914ea62b6baf1f7dcc4950ea28f689fbe919
Author: Lars Kruse <[email protected]>
AuthorDate: Fri Sep 12 17:33:48 2025 +0200
board/arm/rp2040: implement "board_boot_image" for bootloader support
This function is required by the bootloaders (nxboot and mcuboot).
Signed-off-by: Lars Kruse <[email protected]>
---
boards/arm/rp2040/common/src/Make.defs | 4 +
boards/arm/rp2040/common/src/rp2040_boot_image.c | 166 +++++++++++++++++++++++
2 files changed, 170 insertions(+)
diff --git a/boards/arm/rp2040/common/src/Make.defs
b/boards/arm/rp2040/common/src/Make.defs
index 187e9aa1028..202a2a95abf 100644
--- a/boards/arm/rp2040/common/src/Make.defs
+++ b/boards/arm/rp2040/common/src/Make.defs
@@ -29,6 +29,10 @@ ifeq ($(CONFIG_BOARDCTL_RESET),y)
CSRCS += rp2040_reset.c
endif
+ifeq ($(CONFIG_BOARDCTL_BOOT_IMAGE),y)
+CSRCS += rp2040_boot_image.c
+endif
+
ifeq ($(CONFIG_SPI),y)
CSRCS += rp2040_spi.c
endif
diff --git a/boards/arm/rp2040/common/src/rp2040_boot_image.c
b/boards/arm/rp2040/common/src/rp2040_boot_image.c
new file mode 100644
index 00000000000..a716078fc2d
--- /dev/null
+++ b/boards/arm/rp2040/common/src/rp2040_boot_image.c
@@ -0,0 +1,166 @@
+/****************************************************************************
+ * boards/arm/rp2040/common/src/rp2040_boot_image.c
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <debug.h>
+#include <stdio.h>
+#include <fcntl.h>
+
+#include <sys/boardctl.h>
+#include <nuttx/irq.h>
+#include <arch/barriers.h>
+
+#include "nvic.h"
+#include "arm_internal.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/* This structure represents the first two entries on NVIC vector table */
+
+struct arm_vector_table
+{
+ uint32_t spr; /* Stack pointer on reset */
+ uint32_t reset; /* Pointer to reset exception handler */
+};
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static void cleanup_arm_nvic(void);
+static void systick_disable(void);
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: cleanup_arm_nvic
+ *
+ * Description:
+ * Acknowledge and disable all interrupts in NVIC
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static void cleanup_arm_nvic(void)
+{
+ /* Allow any pending interrupts to be recognized */
+
+ UP_ISB();
+ up_irq_disable();
+
+ /* Disable all interrupts */
+
+ putreg32(0xffffffff, ARMV6M_NVIC_ICER);
+
+ /* Clear all pending interrupts */
+
+ putreg32(0xffffffff, ARMV6M_NVIC_ICPR);
+}
+
+/****************************************************************************
+ * Name: systick_disable
+ *
+ * Description:
+ * Disable the SysTick system timer
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static void systick_disable(void)
+{
+ putreg32(0, ARMV6M_SYSTICK_CSR);
+ putreg32(SYSTICK_RVR_MASK, ARMV6M_SYSTICK_RVR);
+ putreg32(0, ARMV6M_SYSTICK_CVR);
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: board_boot_image
+ *
+ * Description:
+ * This entry point is called by bootloader to jump to application image.
+ *
+ ****************************************************************************/
+
+int board_boot_image(const char *path, uint32_t hdr_size)
+{
+ static struct arm_vector_table vt;
+ struct file file;
+ ssize_t bytes;
+ int ret;
+
+ ret = file_open(&file, path, O_RDONLY | O_CLOEXEC);
+ if (ret < 0)
+ {
+ syslog(LOG_ERR, "Failed to open %s with: %d", path, ret);
+ return ret;
+ }
+
+ bytes = file_pread(&file, &vt, sizeof(vt), hdr_size);
+ if (bytes != sizeof(vt))
+ {
+ syslog(LOG_ERR, "Failed to read ARM vector table: %d", bytes);
+ return bytes < 0 ? bytes : -1;
+ }
+
+ systick_disable();
+
+ cleanup_arm_nvic();
+
+ /* Set main and process stack pointers */
+
+ __asm__ __volatile__(
+ "\tmsr msp, %0\n"
+ "\tmsr control, %1\n"
+ "\tisb\n"
+ "\tmov pc, %2\n"
+ :
+ : "r" (vt.spr), "r" (0), "r" (vt.reset));
+
+ return 0;
+}