Skip to content

Commit

Permalink
<RP2040> Add memory layout config and platform files
Browse files Browse the repository at this point in the history
Issue: #231
  • Loading branch information
akashkollipara committed Mar 18, 2024
1 parent c637ff8 commit 3d24883
Show file tree
Hide file tree
Showing 12 changed files with 120 additions and 129 deletions.
2 changes: 1 addition & 1 deletion src/arch/riscv/32/i/terravisor/include/riscv.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* CYANCORE LICENSE
* Copyrights (C) 2019, Cyancore Team
* Copyrights (C) 2024, Cyancore Team
*
* File Name : riscv.h
* Description : This file prototypes riscv arch related functions and
Expand Down
14 changes: 14 additions & 0 deletions src/platform/rpi/common_rp2/arch/build.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#
# CYANCORE LICENSE
# Copyrights (C) 2024, Cyancore Team
#
# File Name : build.mk
# Description : This file accumulates the build rp2 series
# platform arch sources
# Primary Author : Akash Kollipara [[email protected]]
# Organisation : Cyancore Core-Team
#

DIR := $(GET_PATH)

include mk/obj.mk
2 changes: 1 addition & 1 deletion src/platform/rpi/common_rp2/arch/platform_mem.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* CYANCORE LICENSE
* Copyrights (C) 2019, Cyancore Team
* Copyrights (C) 2024, Cyancore Team
*
* File Name : platform_mem.c
* Description : This file contains implementation of platform early setup APIs.
Expand Down
4 changes: 2 additions & 2 deletions src/platform/rpi/common_rp2/build.mk
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ USE_DEFAULT_RESOURCES ?= 1
LOCAL_INTERRUPT_DEVICE ?= 0
PLAT_INTERRUPT_DEVICE ?= 0

#include $(RP2_COMMON_DIR)/arch/build.mk
include $(RP2_COMMON_DIR)/arch/build.mk
#include $(RP2_COMMON_DIR)/hal/build.mk
#include $(RP2_COMMON_DIR)/platform/build.mk
include $(RP2_COMMON_DIR)/platform/build.mk
21 changes: 21 additions & 0 deletions src/platform/rpi/common_rp2/include/platform.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* CYANCORE LICENSE
* Copyrights (C) 2024, Cyancore Team
*
* File Name : platform.h
* Description : This file contains prototypes of platform apis
* Primary Author : Akash Kollipara [[email protected]]
* Organisation : Cyancore Core-Team
*/

#pragma once
#define _RP2_PLATFORM_H_

#include <status.h>

void plat_panic_handler(void);
void platform_print_cpu_info(void);
status_t platform_copy_data(void);
status_t platform_bss_clear(void);
status_t platform_resources_setup(void);
status_t platform_sysclk_reset(void);
17 changes: 17 additions & 0 deletions src/platform/rpi/common_rp2/platform/build.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#
# CYANCORE LICENSE
# Copyrights (C) 2024, Cyancore Team
#
# File Name : build.mk
# Description : This file builds sources from rp2 common
# platform directory
# Primary Author : Akash Kollipara [[email protected]]
# Organisation : Cyancore Core-Team
#

DIR := $(GET_PATH)

PRINT_MEMORY_LAYOUT ?= 0
$(eval $(call add_define,PRINT_MEMORY_LAYOUT))

include mk/obj.mk
99 changes: 51 additions & 48 deletions src/platform/rpi/common_rp2/platform/platform.c
Original file line number Diff line number Diff line change
@@ -1,42 +1,43 @@
/*
* CYANCORE LICENSE
* Copyrights (C) 2019, Cyancore Team
* Copyrights (C) 2024, Cyancore Team
*
* File Name : platform.c
* Description : This file contains sources for platform apis
* Description : This file contains sources for platform functions
* Primary Author : Akash Kollipara [[email protected]]
* Organisation : Cyancore Core-Team
*/

#include <status.h>
#include <stdint.h>
#include <status.h>
#include <stdlib.h>
#include <rand.h>
#include <arch.h>
#include <driver.h>
#include <syslog.h>
#include <driver/sysclk.h>
#include <insignia.h>
#include <terravisor/platform.h>
#include <visor/workers.h>
#include <platform.h>
#include <syslog.h>

uint32_t reset_syndrome;

void platform_early_setup()
{
status_t ret = success;

/* Setup platform memories*/
#if USE_PRNG
unsigned int temp_randomnumber = rand();
#endif
ret |= platform_copy_data();
ret |= platform_bss_clear();
ret |= platform_init_heap();
ret |= platform_resources_setup();

/* Setup memory syslogger*/
#if USE_PRNG
srand(temp_randomnumber);
#endif
syslog_stdout_disable();
driver_setup("mslog");

reset_syndrome = MMIO32(CHIP_RESET) & 0x01110100;
MMIO32(CHIP_RESET) = 0;

ret |= platform_clk_reset();

if(ret != success)
exit(EXIT_FAILURE);
return;
Expand All @@ -46,67 +47,69 @@ void platform_early_setup()
static void platform_memory_layout()
{
extern uint32_t _text_start, _text_size, _text_end,
_data_vstart, _data_size, _data_end,
_stack_start, _stack_size, _stack_end,
_rodata_start, _rodata_size, _rodata_end,
_data_vstart, _data_size, _data_vend,
_stack_start, _stack_end, _stack_size,
_bss_start, _bss_size, _bss_end,
_heap_start, _heap_size, _heap_end,
_itim_vstart, _itim_size, _itim_vend,
_flash_size, _ram_size;

syslog(info, "Memory Info >\n");
syslog(info, "Flash Size : %u\n", &_flash_size);
syslog(info, "RAM Size : %u\n", &_ram_size);
syslog(info, "\n");
syslog(info, "Program Memory Layout >\n");
syslog(info, "text Region\t: %06p - %06p : Size: %u\n",
syslog(info, "Flash Size\t: %u\n", &_flash_size);
syslog(info, "RAM Size\t: %u\n", &_ram_size);
syslog(info, "text Region\t: %010p - %010p : Size: %u\n",
&_text_start, &_text_end, &_text_size);
syslog(info, "bss Region\t: %06p - %06p : Size: %u\n",
syslog(info, "rodata Region\t: %010p - %010p : Size: %u\n",
&_rodata_start, &_rodata_end, &_rodata_size);
syslog(info, "ITIM Region\t: %010p - %010p : Size: %u\n",
&_itim_vstart, &_itim_vend, &_itim_size);
syslog(info, "bss Region\t: %010p - %010p : Size: %u\n",
&_bss_start, &_bss_end, &_bss_size);
syslog(info, "data Region\t: %06p - %06p : Size: %u\n",
syslog(info, "data Region\t: %010p - %010p : Size: %u\n",
&_data_vstart, &_data_vend, &_data_size);
syslog(info, "stack Region\t: %06p - %06p : Size: %u\n",
&_stack_start, &_stack_end, &_stack_size);
syslog(info, "heap Region\t: %06p - %06p : Size: %u\n",
syslog(info, "stack Region\t: %010p - %010p : Size: %u\n",
&_stack_end, &_stack_start, &_stack_size);
syslog(info, "heap Region\t: %010p - %010p : Size: %u\n",
&_heap_start, &_heap_end, &_heap_size);
syslog(info, "\n");
}
#endif

/**
* platform_setup - Executes functions to make platform read to init
*
* @brief This function performs calls to function which make the
* framework ready to execute. This function should be made to run on boot core only.
*/
void platform_setup()
{
sysdbg3("In %s\n", __func__);
/*
status_t ret = success;
*/

#if PRCI_CLK
status_t ret = success;
if(ret != success)
exit(EXIT_FAILURE);
#endif

driver_setup("earlycon");
bootmsgs_enable();
#ifdef BOOTLOADER
cyancore_insignia_lite();
#else
cyancore_insignia();
#endif

#if PRINT_MEMORY_LAYOUT
platform_memory_layout();
#endif
/* Uncomment this and remove above check if more conditions
* are introduced.
if(ret != success)
exit(EXIT_FAILURE);
*/
return;
}

/**
* platform_cpu_setup - Perform platform setup calls on all cpus
*
* @brief This function performs calls to functions that should be executed
* on all cores to make the cpu ready for the platform drivers.
*/
void platform_cpu_setup()
{
sysdbg3("In %s\n", __func__);
arch_ei();
return;
}

void _NAKED plat_panic_handler_callback()
{
context_frame_t *frame;
sysdbg3("In %s\n", __func__);
frame = get_context_frame();
syslog(info, "SP=%p \tSREG = %P\n", frame, frame->sreg);
exit(EXIT_FAILURE);
}
64 changes: 0 additions & 64 deletions src/platform/rpi/common_rp2/platform/platform_reset.c

This file was deleted.

2 changes: 1 addition & 1 deletion src/platform/rpi/common_rp2/platform/platform_resource.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* CYANCORE LICENSE
* Copyrights (C) 2019-2022, Cyancore Team
* Copyrights (C) 2024, Cyancore Team
*
* File Name : platform_resource.c
* Description : This file contains sources for platform
Expand Down
9 changes: 5 additions & 4 deletions src/platform/rpi/common_rp2/sections.ld.sx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ MEMORY
/* VM Addresses */
vma_imem (irx!aw) : ORIGIN = V_IMEM_START, LENGTH = IMEM_LENGTH
vma_dmem (arw!xi) : ORIGIN = V_DMEM_START, LENGTH = DMEM_LENGTH
vma_stak (rw!axi) : ORIGIN = V_STAK_START, LENGTH = STACK_SIZE

/* LM Addresses */
lma_mem : ORIGIN = L_MEM_START, LENGTH = L_MEM_LENGTH
Expand All @@ -32,7 +33,7 @@ SECTIONS
{
.text : ALIGN(4)
{
KEEP(*(.text.entry))
KEEP(*(.text.arch))
*(.text)
*(.text.*)
. = ALIGN(8);
Expand Down Expand Up @@ -71,7 +72,7 @@ SECTIONS
*(.data.*)
KEEP(*(.data))
DRIVER_TABLE
ECALL_TABLE
VCALL_TABLE
} > vma_dmem AT > lma_mem

.heap : ALIGN(HEAP_ALIGN)
Expand All @@ -86,7 +87,7 @@ SECTIONS
*(.stack)
KEEP(*(.stack))
. = . + STACK_SIZE;
} > vma_dmem
} > vma_stak

PROVIDE(_text_start = ADDR(.text));
PROVIDE(_text_size = SIZEOF(.text));
Expand All @@ -113,7 +114,7 @@ SECTIONS
PROVIDE(_heap_size = SIZEOF(.heap));
PROVIDE(_heap_end = _heap_start + _heap_size - 1);

PROVIDE(_flash_size = _data_size + SIZEOF(.text) + _itim_size + SIZEOF(.rodata));
PROVIDE(_flash_size = _data_size + SIZEOF(.text) + SIZEOF(.rodata));
PROVIDE(_ram_size = _bss_size + _data_size + SIZEOF(.stack) + SIZEOF(.heap));

ASSERT((_flash_size < FLASH_SIZE), "< x > Flash size exceeded ...")
Expand Down
8 changes: 4 additions & 4 deletions src/platform/rpi/rp2040/config.mk
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ FLASH_SIZE := 0x1000000 # 16M
RAM_START := 0x20000000
RAM_SIZE := 0x42000 # 264K
HEAP_SIZE ?= 16K
STACK_SIZE ?= 16K
STACK_SIZE_PCPU ?= 8K
STACK_SIZE ?= 8K
STACK_SIZE_PCPU ?= 4K

$(eval $(call add_define,HEAP_SIZE))
$(eval $(call add_define,STACK_SIZE))
Expand All @@ -48,8 +48,8 @@ $(eval $(call add_define,ICLK))
N_EXCEP := 15
$(eval $(call add_define,N_EXCEP))

N_PLAT_IRQS := 32
$(eval $(call add_define,N_PLAT_IRQS))
N_IRQ := 26
$(eval $(call add_define,N_IRQ))

MAX_INTERRUPTS_PER_DEVICE := 1
$(eval $(call add_define,MAX_INTERRUPTS_PER_DEVICE))
Expand Down
7 changes: 3 additions & 4 deletions src/platform/rpi/rp2040/include/plat_mem.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
#define RAM_SIZE 264K

#define V_IMEM_START 0x10000000
#define V_DMEM_START 0x20000000
#define V_DMEM_START 0x21000000
#define V_STAK_START 0x20040000

#define L_MEM_START 0x10000000
#define L_MEM_LENGTH 16M
Expand All @@ -23,6 +24,4 @@
#define IMEM_LENGTH 16M

#define ALIGN_BOUND 4

#define STACK_SIZE 16K
#define STACK_SIZE_PCPU 8K
#define HEAP_ALIGN ALIGN_BOUND

0 comments on commit 3d24883

Please sign in to comment.