Skip to content

Commit

Permalink
mps3-an547:let ap build with pic,and use bootloader boot it
Browse files Browse the repository at this point in the history
Implement PIC loading in armv8-m qemu,
for example: load address-independent AP ELF in the bootloader,
and the text segment in AP ELF is XIP,
no need to apply for memory and modify it.

Two config:

bootloader abbreviation bl:
  use romfs to load ap elf, use the boot command to parse and jump to ap

application abbreviation ap:
  run os test

We need to compile ap first, then compile bl.

compile step:
  ./tools/configure.sh mps3-an547:ap
  make -j20
  mkdir -p pic
  cp boot pic/.
  genromfs -a 128 -f ../romfs.img -d pic
  make distclean -j20
  ./tools/configure.sh mps3-an547:bl
  make -j20

run qemu:
  qemu-system-arm -M mps3-an547 -m 2G -nographic -kernel nuttx.bin \
    -gdb tcp::1127 -device loader,file=../romfs.img,addr=0x60000000

  nsh> boot /etc/boot
  ap> ostest

Signed-off-by: anjiahao <[email protected]>
  • Loading branch information
anjiahao1 committed Oct 15, 2024
1 parent 7e3f631 commit 391590f
Show file tree
Hide file tree
Showing 7 changed files with 263 additions and 15 deletions.
18 changes: 18 additions & 0 deletions Documentation/platforms/arm/mps/boards/mps3-an547/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,24 @@ Configuring and Running
$ nsh> /pic/ostest
```

4. **Pic bootloader boot to ap, and run ostest:**

```bash
$ ./tools/configure.sh mps3-an547:ap
$ make -j20
$ mkdir -p pic
$ arm-none-eabi-strip --remove-section=.rel.text --remove-section=.comment --strip-unneeded nuttx -o pic/boot
$ genromfs -a -f 128 ../romfs.img -d pic
$ make distclean -j20
$ ./tools/configure.sh mps3-an547:bl
$ make -j20
$ qemu-system-arm -M mps3-an547 -m 2G -nographic \
-kernel nuttx.bin -gdb tcp::1127 \
-device loader,file=../romfs.img,addr=0x60000000
$ bl> boot /pic/boot
$ ap> ostest
```

Debugging with QEMU
===================

Expand Down
5 changes: 5 additions & 0 deletions arch/arm/src/mps/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ config ARCH_CHIP_MPS3_AN524
config ARCH_CHIP_MPS3_AN547
bool "MPS3 AN547 Processor Cortexm55"
select ARCH_CORTEXM55
select ARCH_HAVE_FPU
select ARCH_HAVE_TEXT_HEAP
select ARCH_HAVE_DATA_HEAP
select ARM_HAVE_MVE
select ARCH_HAVE_FPU

endchoice

Expand Down
134 changes: 120 additions & 14 deletions arch/arm/src/mps/mps_allocateheap.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
* Pre-processor Definitions
****************************************************************************/

#define ALIGN_UP(x, a) (((x) + (a) - 1) & ~((a) - 1))

/* Configuration ************************************************************/

/* Terminology.
Expand Down Expand Up @@ -76,21 +78,12 @@
*/

/****************************************************************************
* Public Data
* Private Data
****************************************************************************/

/* _sbss is the start of the BSS region (see the linker script) _ebss is the
* end of the BSS regions (see the linker script). The idle task stack starts
* at the end of BSS and is of size CONFIG_IDLETHREAD_STACKSIZE. The IDLE
* thread is the thread that the system boots on and, eventually, becomes the
* idle, do nothing task that runs only when there is nothing else to run.
* The heap continues from there until the configured end of memory.
* g_idle_topstack is the beginning of this heap region (not necessarily
* aligned).
*/

const uintptr_t g_idle_topstack = (uintptr_t)_ebss +
CONFIG_IDLETHREAD_STACKSIZE;
#if defined(CONFIG_ARCH_USE_TEXT_HEAP) || defined(CONFIG_ARCH_USE_DATA_HEAP)
static uintptr_t g_alloc_count;
#endif

/****************************************************************************
* Public Functions
Expand Down Expand Up @@ -169,8 +162,13 @@ void up_allocate_heap(void **heap_start, size_t *heap_size)
/* Allow user-mode access to the user heap memory */

mpu_user_intsram(ubase, usize);
#else
#elif defined(CONFIG_BUILD_PIC)

/* Use different heap useful to debug */

*heap_start = (void *)MPS_SRAM1_START;
*heap_size = MPS_SRAM1_SIZE;
#else
/* Return the heap settings */

*heap_start = (void *)g_idle_topstack;
Expand Down Expand Up @@ -271,3 +269,111 @@ void arm_addregion(void)
#endif /* CONFIG_MM_REGIONS > 2 */
}
#endif /* CONFIG_MM_REGIONS > 1 */

/****************************************************************************
* Name: up_textheap_memalign
*
* Description:
* Allocate memory for text with the specified alignment and sectname.
*
****************************************************************************/

#if defined(CONFIG_ARCH_USE_TEXT_HEAP)
# if defined(CONFIG_ARCH_USE_SEPARATED_SECTION)
void *up_textheap_memalign(const char *sectname,
size_t align, size_t size)
# else
void *up_textheap_memalign(size_t align, size_t size)
# endif
{
uintptr_t base = (uintptr_t)MPS_SRAM2_START + g_alloc_count;
uintptr_t ret = ALIGN_UP(base, align);

g_alloc_count += ret - base + size;
return (void *)ret;
}
#endif

/****************************************************************************
* Name: up_textheap_free
*
* Description:
* Free memory allocated for text sections.
*
****************************************************************************/

#if defined(CONFIG_ARCH_USE_TEXT_HEAP)
void up_textheap_free(void *p)
{
}
#endif

/****************************************************************************
* Name: up_textheap_heapmember
*
* Description:
* Test if memory is from text heap.
*
****************************************************************************/

#if defined(CONFIG_ARCH_USE_TEXT_HEAP)
bool up_textheap_heapmember(void *p)
{
return (uintptr_t)p >= MPS_SRAM2_START &&
(uintptr_t)p < MPS_SRAM2_START + MPS_SRAM2_SIZE;
}
#endif

/****************************************************************************
* Name: up_dataheap_memalign
*
* Description:
* Allocate memory for data with the specified alignment and sectname.
*
****************************************************************************/

#if defined(CONFIG_ARCH_USE_DATA_HEAP)
# if defined(CONFIG_ARCH_USE_SEPARATED_SECTION)
void *up_dataheap_memalign(const char *sectname,
size_t align, size_t size)
# else
void *up_dataheap_memalign(size_t align, size_t size)
# endif
{
uintptr_t base = (uintptr_t)MPS_SRAM2_START + g_alloc_count;
uintptr_t ret = ALIGN_UP(base, align);

g_alloc_count += ret - base + size;
return (void *)ret;
}
#endif

/****************************************************************************
* Name: up_dataheap_free
*
* Description:
* Free memory allocated for data sections.
*
****************************************************************************/

#if defined(CONFIG_ARCH_USE_DATA_HEAP)
void up_dataheap_free(void *p)
{
}
#endif

/****************************************************************************
* Name: up_dataheap_heapmember
*
* Description:
* Test if memory is from data heap.
*
****************************************************************************/

#if defined(CONFIG_ARCH_USE_DATA_HEAP)
bool up_dataheap_heapmember(void *p)
{
return (uintptr_t)p >= MPS_SRAM2_START &&
(uintptr_t)p < MPS_SRAM2_START + MPS_SRAM2_SIZE;
}
#endif
29 changes: 29 additions & 0 deletions arch/arm/src/mps/mps_start.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,28 @@
#include "mps_userspace.h"
#include "mpu.h"

/****************************************************************************
* Public Functions
****************************************************************************/

#define HEAP_BASE ((uintptr_t)_ebss + CONFIG_IDLETHREAD_STACKSIZE)

/****************************************************************************
* Public Data
****************************************************************************/

/* g_idle_topstack: _sbss is the start of the BSS region as defined by the
* linker script. _ebss lies at the end of the BSS region. The idle task
* stack starts at the end of BSS and is of size CONFIG_IDLETHREAD_STACKSIZE.
* The IDLE thread is the thread that the system boots on and, eventually,
* becomes the IDLE, do nothing task that runs only when there is nothing
* else to run. The heap continues from there until the end of memory.
* g_idle_topstack is a read-only variable the provides this computed
* address.
*/

const uintptr_t g_idle_topstack = HEAP_BASE;

/****************************************************************************
* Private Functions
****************************************************************************/
Expand Down Expand Up @@ -94,8 +116,10 @@ static inline void mps_tcmenable(void)

void __start(void)
{
#ifndef CONFIG_BUILD_PIC
const uint32_t *src;
uint32_t *dest;
#endif

/* If enabled reset the MPU */

Expand All @@ -105,6 +129,10 @@ void __start(void)
#endif
arm_fpuconfig();

/* If used the PIC, then the PIC will have already been configured */

#ifndef CONFIG_BUILD_PIC

/* Set bss to zero */

for (dest = (uint32_t *)_sbss; dest < (uint32_t *)_ebss; )
Expand All @@ -120,6 +148,7 @@ void __start(void)
{
*dest++ = *src++;
}
#endif

/* Perform early serial initialization */

Expand Down
2 changes: 2 additions & 0 deletions boards/arm/mps/mps3-an547/configs/bl/defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ CONFIG_ARCH_CHIP_MPS3_AN547=y
CONFIG_ARCH_CHIP_MPS=y
CONFIG_ARCH_INTERRUPTSTACK=2048
CONFIG_ARCH_STACKDUMP=y
CONFIG_ARCH_USE_DATA_HEAP=y
CONFIG_ARCH_USE_SEPARATED_SECTION=y
CONFIG_ARMV8M_SYSTICK=y
CONFIG_BOARDCTL_APP_SYMTAB=y
CONFIG_BOARDCTL_BOOT_IMAGE=y
Expand Down
10 changes: 9 additions & 1 deletion boards/arm/mps/mps3-an547/scripts/flash.ld
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*
****************************************************************************/

#include "nuttx/config.h"

MEMORY
{
flash (rx) : ORIGIN = 0x00000000, LENGTH = 512K
Expand All @@ -33,15 +35,16 @@ SECTIONS
{
.text : {
_stext = ABSOLUTE(.);
#ifndef CONFIG_BUILD_PIC /* We need change vectors use pic */
*(.vectors)
#endif
*(.text .text.*)
*(.fixup)
*(.gnu.warning)
*(.rodata .rodata.*)
*(.gnu.linkonce.t.*)
*(.glue_7)
*(.glue_7t)
*(.got)
*(.gcc_except_table)
*(.gnu.linkonce.r.*)
_etext = ABSOLUTE(.);
Expand Down Expand Up @@ -93,6 +96,11 @@ SECTIONS
_edata = ABSOLUTE(.);
} > sram1 AT > flash

.got :
{
*(.got*)
} > sram1

.bss : ALIGN(4) {
_sbss = ABSOLUTE(.);
*(.bss .bss.*)
Expand Down
Loading

0 comments on commit 391590f

Please sign in to comment.