xiaoxiang781216 commented on code in PR #16848:
URL: https://github.com/apache/nuttx/pull/16848#discussion_r2273789408


##########
boards/risc-v/rp23xx-rv/common/src/rp23xx_reset.c:
##########
@@ -60,11 +61,20 @@ int board_reset(int status)
 {
   syslog(LOG_INFO, "reboot status=%d\n", status);
 
-  putreg32(RP23XX_PSM_WDSEL_BITS & ~(RP23XX_PSM_XOSC | RP23XX_PSM_ROSC),
-           RP23XX_PSM_WDSEL);
+  rom_reboot_fn func = (rom_reboot_fn)rom_func_lookup(ROM_FUNC_REBOOT);

Review Comment:
   func->reboot



##########
boards/risc-v/rp23xx-rv/common/src/rp23xx_reset.c:
##########
@@ -60,11 +61,20 @@ int board_reset(int status)
 {
   syslog(LOG_INFO, "reboot status=%d\n", status);
 
-  putreg32(RP23XX_PSM_WDSEL_BITS & ~(RP23XX_PSM_XOSC | RP23XX_PSM_ROSC),
-           RP23XX_PSM_WDSEL);
+  rom_reboot_fn func = (rom_reboot_fn)rom_func_lookup(ROM_FUNC_REBOOT);
 
-  putreg32(RP23XX_WATCHDOG_ENABLE_BITS | RP23XX_WATCHDOG_CTRL_TRIGGER,
-           RP23XX_WATCHDOG_CTRL);
+  if (status == 3)
+    {
+      func(REBOOT2_FLAG_REBOOT_TYPE_BOOTSEL |
+          REBOOT2_FLAG_NO_RETURN_ON_SUCCESS,
+          10, 0, 0);
+    }
+  else
+    {
+      func(REBOOT2_FLAG_REBOOT_TYPE_NORMAL |
+          REBOOT2_FLAG_NO_RETURN_ON_SUCCESS,

Review Comment:
   ```suggestion
              REBOOT2_FLAG_NO_RETURN_ON_SUCCESS,
   ```



##########
arch/risc-v/src/rp23xx-rv/rp23xx_rom.h:
##########
@@ -78,53 +78,60 @@
 /* reserved for 32-bit pointer: 0x0008 */
 #define RT_FLAG_FUNC_ARM_NONSEC 0x0010
 
-#define BOOTROM_FUNC_TABLE_OFFSET 0x14
-
-#define BOOTROM_IS_A2() ((*(volatile uint8_t *)0x13) == 2)
-#define BOOTROM_WELL_KNOWN_PTR_SIZE (BOOTROM_IS_A2() ? 2 : 4)
-
-#if defined(__riscv)
+#define BOOTROM_WELL_KNOWN_PTR_SIZE 2
 #define BOOTROM_ENTRY_OFFSET            0x7dfc
 #define BOOTROM_TABLE_LOOKUP_ENTRY_OFFSET (BOOTROM_ENTRY_OFFSET - 
BOOTROM_WELL_KNOWN_PTR_SIZE)
 #define BOOTROM_TABLE_LOOKUP_OFFSET     (BOOTROM_ENTRY_OFFSET - 
BOOTROM_WELL_KNOWN_PTR_SIZE*2)
-#else
-#define BOOTROM_VTABLE_OFFSET 0x00
-#define BOOTROM_TABLE_LOOKUP_OFFSET     (BOOTROM_FUNC_TABLE_OFFSET + 
BOOTROM_WELL_KNOWN_PTR_SIZE)
-#endif
 
 #define ROM_TABLE_CODE(c1, c2) ((c1) | ((c2) << 8))
 
+#define REBOOT2_TYPE_MASK  0x0f
+
+/* note these match REBOOT_TYPE  */
+
+/* values 0-7 are secure/non-secure */
+#define REBOOT2_FLAG_REBOOT_TYPE_NORMAL       0x0 /* param0 = diagnostic 
partition */
+#define REBOOT2_FLAG_REBOOT_TYPE_BOOTSEL      0x2 /* param0 = gpio_pin_number, 
param1 = flags */
+#define REBOOT2_FLAG_REBOOT_TYPE_RAM_IMAGE    0x3 /* param0 = 
image_region_base, param1 = image_region_size */
+#define REBOOT2_FLAG_REBOOT_TYPE_FLASH_UPDATE 0x4 /* param0 = update_base */
+
+/* values 8-15 are secure only */
+#define REBOOT2_FLAG_REBOOT_TYPE_PC_SP        0xd
+
+#define REBOOT2_FLAG_REBOOT_TO_ARM            0x10
+#define REBOOT2_FLAG_REBOOT_TO_RISCV          0x20
+
+#define REBOOT2_FLAG_NO_RETURN_ON_SUCCESS    0x100
+
+#define BOOTSEL_FLAG_DISABLE_MSD_INTERFACE      0x01
+#define BOOTSEL_FLAG_DISABLE_PICOBOOT_INTERFACE 0x02
+#define BOOTSEL_FLAG_GPIO_PIN_ACTIVE_LOW        0x10
+#define BOOTSEL_FLAG_GPIO_PIN_SPECIFIED         0x20
+
+#define PICOBOOT_GET_INFO_SYS              1
+#define PICOBOOT_GET_INFO_PARTTION_TABLE   2
+#define PICOBOOT_GET_INFO_UF2_TARGET_PARTITION 3
+#define PICOBOOT_GET_INFO_UF2_STATUS       4
+
+#define UF2_STATUS_IGNORED_FAMILY             0x01
+#define UF2_STATUS_ABORT_EXCLUSIVELY_LOCKED   0x10
+#define UF2_STATUS_ABORT_BAD_ADDRESS          0x20
+#define UF2_STATUS_ABORT_WRITE_ERROR          0x40
+#define UF2_STATUS_ABORT_REBOOT_FAILED        0x80
+
 /****************************************************************************
  * Public Type Definitions
  ****************************************************************************/
 
 typedef void *(*rom_table_lookup_fn)(uint32_t code, uint32_t mask);
 
-static __inline void *rom_func_lookup(uint32_t code)
-{
-#ifdef __riscv
-  uint32_t rom_offset_adjust = rom_size_is_64k() ? 32 * 1024 : 0;
-
-  /* on RISC-V the code (a jmp) is actually embedded in the table */
+typedef int (*rom_reboot_fn)(uint32_t flags, uint32_t delay_ms,
+            uint32_t p0, uint32_t p1);
 
+static void *rom_func_lookup(uint32_t code)
+{
   rom_table_lookup_fn rom_table_lookup = (rom_table_lookup_fn) (uintptr_t)

Review Comment:
   ```suggestion
     rom_table_lookup_fn rom_table_lookup = (rom_table_lookup_fn)(uintptr_t)
   ```



##########
boards/risc-v/rp23xx-rv/common/src/rp23xx_reset.c:
##########
@@ -60,11 +61,20 @@ int board_reset(int status)
 {
   syslog(LOG_INFO, "reboot status=%d\n", status);
 
-  putreg32(RP23XX_PSM_WDSEL_BITS & ~(RP23XX_PSM_XOSC | RP23XX_PSM_ROSC),
-           RP23XX_PSM_WDSEL);
+  rom_reboot_fn func = (rom_reboot_fn)rom_func_lookup(ROM_FUNC_REBOOT);
 
-  putreg32(RP23XX_WATCHDOG_ENABLE_BITS | RP23XX_WATCHDOG_CTRL_TRIGGER,
-           RP23XX_WATCHDOG_CTRL);
+  if (status == 3)
+    {
+      func(REBOOT2_FLAG_REBOOT_TYPE_BOOTSEL |
+          REBOOT2_FLAG_NO_RETURN_ON_SUCCESS,

Review Comment:
   ```suggestion
              REBOOT2_FLAG_NO_RETURN_ON_SUCCESS,
   ```



##########
arch/risc-v/src/rp23xx-rv/rp23xx_rom.h:
##########
@@ -78,53 +78,60 @@
 /* reserved for 32-bit pointer: 0x0008 */
 #define RT_FLAG_FUNC_ARM_NONSEC 0x0010
 
-#define BOOTROM_FUNC_TABLE_OFFSET 0x14
-
-#define BOOTROM_IS_A2() ((*(volatile uint8_t *)0x13) == 2)
-#define BOOTROM_WELL_KNOWN_PTR_SIZE (BOOTROM_IS_A2() ? 2 : 4)
-
-#if defined(__riscv)
+#define BOOTROM_WELL_KNOWN_PTR_SIZE 2
 #define BOOTROM_ENTRY_OFFSET            0x7dfc
 #define BOOTROM_TABLE_LOOKUP_ENTRY_OFFSET (BOOTROM_ENTRY_OFFSET - 
BOOTROM_WELL_KNOWN_PTR_SIZE)
 #define BOOTROM_TABLE_LOOKUP_OFFSET     (BOOTROM_ENTRY_OFFSET - 
BOOTROM_WELL_KNOWN_PTR_SIZE*2)
-#else
-#define BOOTROM_VTABLE_OFFSET 0x00
-#define BOOTROM_TABLE_LOOKUP_OFFSET     (BOOTROM_FUNC_TABLE_OFFSET + 
BOOTROM_WELL_KNOWN_PTR_SIZE)
-#endif
 
 #define ROM_TABLE_CODE(c1, c2) ((c1) | ((c2) << 8))
 
+#define REBOOT2_TYPE_MASK  0x0f
+
+/* note these match REBOOT_TYPE  */
+
+/* values 0-7 are secure/non-secure */
+#define REBOOT2_FLAG_REBOOT_TYPE_NORMAL       0x0 /* param0 = diagnostic 
partition */
+#define REBOOT2_FLAG_REBOOT_TYPE_BOOTSEL      0x2 /* param0 = gpio_pin_number, 
param1 = flags */
+#define REBOOT2_FLAG_REBOOT_TYPE_RAM_IMAGE    0x3 /* param0 = 
image_region_base, param1 = image_region_size */
+#define REBOOT2_FLAG_REBOOT_TYPE_FLASH_UPDATE 0x4 /* param0 = update_base */
+
+/* values 8-15 are secure only */
+#define REBOOT2_FLAG_REBOOT_TYPE_PC_SP        0xd
+
+#define REBOOT2_FLAG_REBOOT_TO_ARM            0x10
+#define REBOOT2_FLAG_REBOOT_TO_RISCV          0x20
+
+#define REBOOT2_FLAG_NO_RETURN_ON_SUCCESS    0x100
+
+#define BOOTSEL_FLAG_DISABLE_MSD_INTERFACE      0x01
+#define BOOTSEL_FLAG_DISABLE_PICOBOOT_INTERFACE 0x02
+#define BOOTSEL_FLAG_GPIO_PIN_ACTIVE_LOW        0x10
+#define BOOTSEL_FLAG_GPIO_PIN_SPECIFIED         0x20
+
+#define PICOBOOT_GET_INFO_SYS              1
+#define PICOBOOT_GET_INFO_PARTTION_TABLE   2
+#define PICOBOOT_GET_INFO_UF2_TARGET_PARTITION 3
+#define PICOBOOT_GET_INFO_UF2_STATUS       4
+
+#define UF2_STATUS_IGNORED_FAMILY             0x01
+#define UF2_STATUS_ABORT_EXCLUSIVELY_LOCKED   0x10
+#define UF2_STATUS_ABORT_BAD_ADDRESS          0x20
+#define UF2_STATUS_ABORT_WRITE_ERROR          0x40
+#define UF2_STATUS_ABORT_REBOOT_FAILED        0x80
+
 /****************************************************************************
  * Public Type Definitions
  ****************************************************************************/
 
 typedef void *(*rom_table_lookup_fn)(uint32_t code, uint32_t mask);
 
-static __inline void *rom_func_lookup(uint32_t code)
-{
-#ifdef __riscv
-  uint32_t rom_offset_adjust = rom_size_is_64k() ? 32 * 1024 : 0;
-
-  /* on RISC-V the code (a jmp) is actually embedded in the table */
+typedef int (*rom_reboot_fn)(uint32_t flags, uint32_t delay_ms,
+            uint32_t p0, uint32_t p1);

Review Comment:
   ```suggestion
                                uint32_t p0, uint32_t p1);
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to