Skip to content

Commit 2437771

Browse files
shtirlicacassis
authored andcommitted
boards/risc-v/rp23xx-rv/common: update board reset via BOOTROM functions
Update board reset with BOOTROM functions calls - normal reboot - reboot to bootloader normal reboot and reboot bootloader now possible from nsh Signed-off-by: Serg Podtynnyi <[email protected]>
1 parent 1013faa commit 2437771

File tree

2 files changed

+55
-38
lines changed

2 files changed

+55
-38
lines changed

arch/risc-v/src/rp23xx-rv/rp23xx_rom.h

Lines changed: 41 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -78,53 +78,60 @@
7878
/* reserved for 32-bit pointer: 0x0008 */
7979
#define RT_FLAG_FUNC_ARM_NONSEC 0x0010
8080

81-
#define BOOTROM_FUNC_TABLE_OFFSET 0x14
82-
83-
#define BOOTROM_IS_A2() ((*(volatile uint8_t *)0x13) == 2)
84-
#define BOOTROM_WELL_KNOWN_PTR_SIZE (BOOTROM_IS_A2() ? 2 : 4)
85-
86-
#if defined(__riscv)
81+
#define BOOTROM_WELL_KNOWN_PTR_SIZE 2
8782
#define BOOTROM_ENTRY_OFFSET 0x7dfc
8883
#define BOOTROM_TABLE_LOOKUP_ENTRY_OFFSET (BOOTROM_ENTRY_OFFSET - BOOTROM_WELL_KNOWN_PTR_SIZE)
8984
#define BOOTROM_TABLE_LOOKUP_OFFSET (BOOTROM_ENTRY_OFFSET - BOOTROM_WELL_KNOWN_PTR_SIZE*2)
90-
#else
91-
#define BOOTROM_VTABLE_OFFSET 0x00
92-
#define BOOTROM_TABLE_LOOKUP_OFFSET (BOOTROM_FUNC_TABLE_OFFSET + BOOTROM_WELL_KNOWN_PTR_SIZE)
93-
#endif
9485

9586
#define ROM_TABLE_CODE(c1, c2) ((c1) | ((c2) << 8))
9687

88+
#define REBOOT2_TYPE_MASK 0x0f
89+
90+
/* note these match REBOOT_TYPE */
91+
92+
/* values 0-7 are secure/non-secure */
93+
#define REBOOT2_FLAG_REBOOT_TYPE_NORMAL 0x0 /* param0 = diagnostic partition */
94+
#define REBOOT2_FLAG_REBOOT_TYPE_BOOTSEL 0x2 /* param0 = gpio_pin_number, param1 = flags */
95+
#define REBOOT2_FLAG_REBOOT_TYPE_RAM_IMAGE 0x3 /* param0 = image_region_base, param1 = image_region_size */
96+
#define REBOOT2_FLAG_REBOOT_TYPE_FLASH_UPDATE 0x4 /* param0 = update_base */
97+
98+
/* values 8-15 are secure only */
99+
#define REBOOT2_FLAG_REBOOT_TYPE_PC_SP 0xd
100+
101+
#define REBOOT2_FLAG_REBOOT_TO_ARM 0x10
102+
#define REBOOT2_FLAG_REBOOT_TO_RISCV 0x20
103+
104+
#define REBOOT2_FLAG_NO_RETURN_ON_SUCCESS 0x100
105+
106+
#define BOOTSEL_FLAG_DISABLE_MSD_INTERFACE 0x01
107+
#define BOOTSEL_FLAG_DISABLE_PICOBOOT_INTERFACE 0x02
108+
#define BOOTSEL_FLAG_GPIO_PIN_ACTIVE_LOW 0x10
109+
#define BOOTSEL_FLAG_GPIO_PIN_SPECIFIED 0x20
110+
111+
#define PICOBOOT_GET_INFO_SYS 1
112+
#define PICOBOOT_GET_INFO_PARTTION_TABLE 2
113+
#define PICOBOOT_GET_INFO_UF2_TARGET_PARTITION 3
114+
#define PICOBOOT_GET_INFO_UF2_STATUS 4
115+
116+
#define UF2_STATUS_IGNORED_FAMILY 0x01
117+
#define UF2_STATUS_ABORT_EXCLUSIVELY_LOCKED 0x10
118+
#define UF2_STATUS_ABORT_BAD_ADDRESS 0x20
119+
#define UF2_STATUS_ABORT_WRITE_ERROR 0x40
120+
#define UF2_STATUS_ABORT_REBOOT_FAILED 0x80
121+
97122
/****************************************************************************
98123
* Public Type Definitions
99124
****************************************************************************/
100125

101126
typedef void *(*rom_table_lookup_fn)(uint32_t code, uint32_t mask);
102127

103-
static __inline void *rom_func_lookup(uint32_t code)
104-
{
105-
#ifdef __riscv
106-
uint32_t rom_offset_adjust = rom_size_is_64k() ? 32 * 1024 : 0;
107-
108-
/* on RISC-V the code (a jmp) is actually embedded in the table */
128+
typedef int (*rom_reboot_fn)(uint32_t flags, uint32_t delay_ms,
129+
uint32_t p0, uint32_t p1);
109130

110-
rom_table_lookup_fn rom_table_lookup = (rom_table_lookup_fn) (uintptr_t)
111-
*(uint16_t *)(BOOTROM_TABLE_LOOKUP_ENTRY_OFFSET + rom_offset_adjust);
131+
static void *rom_func_lookup(uint32_t code)
132+
{
133+
rom_table_lookup_fn rom_table_lookup = (rom_table_lookup_fn)(uintptr_t)
134+
*(uint16_t *)(BOOTROM_TABLE_LOOKUP_ENTRY_OFFSET);
112135

113136
return rom_table_lookup(code, RT_FLAG_FUNC_RISCV);
114-
#else
115-
/* on ARM the function pointer is stored in the table, so we dereference
116-
* it via lookup() rather than lookup_entry()
117-
*/
118-
119-
rom_table_lookup_fn rom_table_lookup = (rom_table_lookup_fn) (uintptr_t)
120-
*(uint16_t *)(BOOTROM_TABLE_LOOKUP_OFFSET);
121-
if (pico_processor_state_is_nonsecure())
122-
{
123-
return rom_table_lookup(code, RT_FLAG_FUNC_ARM_NONSEC);
124-
}
125-
else
126-
{
127-
return rom_table_lookup(code, RT_FLAG_FUNC_ARM_SEC);
128-
}
129-
#endif
130137
}

boards/risc-v/rp23xx-rv/common/src/rp23xx_reset.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
#include <hardware/rp23xx_watchdog.h>
3131
#include "hardware/rp23xx_psm.h"
32+
#include "rp23xx_rom.h"
3233

3334
#ifdef CONFIG_BOARDCTL_RESET
3435

@@ -60,11 +61,20 @@ int board_reset(int status)
6061
{
6162
syslog(LOG_INFO, "reboot status=%d\n", status);
6263

63-
putreg32(RP23XX_PSM_WDSEL_BITS & ~(RP23XX_PSM_XOSC | RP23XX_PSM_ROSC),
64-
RP23XX_PSM_WDSEL);
64+
rom_reboot_fn reboot = (rom_reboot_fn)rom_func_lookup(ROM_FUNC_REBOOT);
6565

66-
putreg32(RP23XX_WATCHDOG_ENABLE_BITS | RP23XX_WATCHDOG_CTRL_TRIGGER,
67-
RP23XX_WATCHDOG_CTRL);
66+
if (status == 3)
67+
{
68+
reboot(REBOOT2_FLAG_REBOOT_TYPE_BOOTSEL |
69+
REBOOT2_FLAG_NO_RETURN_ON_SUCCESS,
70+
10, 0, 0);
71+
}
72+
else
73+
{
74+
reboot(REBOOT2_FLAG_REBOOT_TYPE_NORMAL |
75+
REBOOT2_FLAG_NO_RETURN_ON_SUCCESS,
76+
10, 0, 0);
77+
}
6878

6979
/* Wait for the reset */
7080

0 commit comments

Comments
 (0)