Skip to content

Commit

Permalink
Merge pull request #2 from openbouffalo/opensbi
Browse files Browse the repository at this point in the history
update d0 low_load to use VRAM so we can copy opensbi into DRAM
  • Loading branch information
Fishwaldo authored Jan 21, 2023
2 parents 431f33b + ac63041 commit bd6ea74
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 63 deletions.
8 changes: 5 additions & 3 deletions apps/d0_lowload/bl808_flash_d0.ld
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ ENTRY(__start)
StackSize = 0x0400; /* 1KB */
HeapMinSize = 0x1000; /* 4KB */

/* put everything in VRAM, so we can load opensbi into DRAM */

MEMORY
{
xip_memory (rx) : ORIGIN = 0x58000000, LENGTH = 1M
itcm_memory (rx) : ORIGIN = 0x3effc000, LENGTH = 17K
dtcm_memory (rx) : ORIGIN = 0x3f000400, LENGTH = 4K
itcm_memory (rx) : ORIGIN = 0x3F000000, LENGTH = 12K
dtcm_memory (rx) : ORIGIN = 0x3F003000, LENGTH = 4K
nocache_ram_memory (!rx) : ORIGIN = 0x3ef80000, LENGTH = 0K
ram_memory (!rx) : ORIGIN = 0x3ef80000, LENGTH = 32K
ram_memory (!rx) : ORIGIN = 0x3F004000, LENGTH = 16K
xram_memory (!rx) : ORIGIN = 0x40000000, LENGTH = 16K
}

Expand Down
80 changes: 20 additions & 60 deletions apps/d0_lowload/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*
*/

#define DBG_TAG "MAIN"
#define DBG_TAG "LowLoad"

#include <stdint.h>
#include <string.h>
Expand All @@ -31,22 +31,14 @@
#include <csi_core.h>
#include <bflb_uart.h>
#include <bflb_gpio.h>
#include "board.h"

extern void unlz4(const void *aSource, void *aDestination, uint32_t FileLen);

#define PSRAM_BASIC_ADDR 0x50000000
#define VRAM_BASIC_ADDR 0x3f008000

#define VM_LINUX_SRC_ADDR 0x580A0000 // 4M 3980268
#define VM_LINUX_DST_ADDR 0x50000000

#define OPENSBI_SRC_ADDR 0x58090000 // 64K 0xc000
#define OPENSBI_DST_ADDR 0x3eff0000

#define DTB_SRC_ADDR 0x58080000 // 64k
#define OPENSBI_DST_ADDR 0x3EF80000
#define DTB_DST_ADDR 0x51ff8000

#define BOOT_HDR_SRC_ADDR 0x58080000 // 64k
#define BOOT_HDR_SRC_ADDR 0x58080000

static struct bflb_device_s *uart0;

Expand All @@ -67,8 +59,8 @@ const pmp_config_entry_t pmp_entry_tab[8] = {

[2] = {
.entry_flag = ENTRY_FLAG_ADDR_NAPOT | ENTRY_FLAG_PERM_X | ENTRY_FLAG_PERM_W | ENTRY_FLAG_PERM_R,
.entry_pa_base = 0x3eff0000,
.entry_pa_length = 0x10000,
.entry_pa_base = 0x3ef80000,
.entry_pa_length = 0x10000
},

[3] = {
Expand Down Expand Up @@ -142,10 +134,9 @@ static char *get_sectionstr(uint32_t type)
return sections[VM_BOOT_SECTION_MAX];
}


void linux_load()
{
LOG_I("linux load start... \r\n");
LOG_I("low_load start... \r\n");

vm_boot_header_t *header = (vm_boot_header_t *)BOOT_HDR_SRC_ADDR;
if (header->magic != 0x4c4d5642) {
Expand All @@ -171,18 +162,18 @@ void linux_load()
LOG_I("Section %s(%d) - Start 0x%08x, Size %ld\r\n", get_sectionstr(header->section[i].type), header->section[i].type, BOOT_HDR_SRC_ADDR + header->section[i].offset, header->section[i].size);
switch (header->section[i].type) {
case VM_BOOT_SECTION_DTB:
LOG_I("Copying DTB to 0x%08x...\r\n", DTB_DST_ADDR);
memcpy((void *)DTB_DST_ADDR, (void *)(BOOT_HDR_SRC_ADDR + header->section[i].offset), header->section[i].size);
LOG_I("Copying DTB to 0x%08x...0x%08x\r\n", DTB_DST_ADDR, DTB_DST_ADDR + header->section[i].size);
memcpy((void *)DTB_DST_ADDR, (void *)(BOOT_HDR_SRC_ADDR + (uintptr_t)header->section[i].offset), header->section[i].size);
LOG_I("Done!\r\n");
break;
case VM_BOOT_SECTION_OPENSBI:
LOG_I("Copying OpenSBI to 0x%08x...\r\n", OPENSBI_DST_ADDR);
memcpy((void *)OPENSBI_DST_ADDR, (void *)(BOOT_HDR_SRC_ADDR + header->section[i].offset), header->section[i].size);
LOG_I("Copying OpenSBI to 0x%08x...0x%08x\r\n", OPENSBI_DST_ADDR, OPENSBI_DST_ADDR + header->section[i].size);
memcpy((void *)OPENSBI_DST_ADDR, (void *)(BOOT_HDR_SRC_ADDR + (uintptr_t)header->section[i].offset), header->section[i].size);
LOG_I("Done!\r\n");
break;
case VM_BOOT_SECTION_KERNEL:
LOG_I("Uncompressing Kernel to 0x%08x...\r\n", VM_LINUX_DST_ADDR);
unlz4((const void *)(BOOT_HDR_SRC_ADDR + header->section[i].offset), (void *)VM_LINUX_DST_ADDR, header->section[i].size);
unlz4((const void *)(BOOT_HDR_SRC_ADDR + (uintptr_t)header->section[i].offset), (void *)VM_LINUX_DST_ADDR, header->section[i].size);
LOG_I("Done!\r\n");
break;
default:
Expand All @@ -196,42 +187,6 @@ void linux_load()
csi_dcache_clean_invalid();

return;



uint32_t *pSrc, *pDest;
uint32_t header_kernel_len = 0;
header_kernel_len = *(volatile uint32_t *)(VM_LINUX_SRC_ADDR - 4);
/* Copy and unlz4 vm linux code */
LOG_I("len:0x%08x\r\n", header_kernel_len);
__DMB();

unlz4((const void *)VM_LINUX_SRC_ADDR, (void *)VM_LINUX_DST_ADDR, header_kernel_len /*3980268*/ /*3993116 v0.3.0*/ /*4010168*/);

/* let's start */
/* there are 7bytes file head that lz4d HW IP does not need, skip! */
// LZ4D_Decompress((const void *)(VM_LINUX_SRC_ADDR + 7), (void *)VM_LINUX_DST_ADDR);

/* method 1: wait when done */
// while (!LZ4D_GetStatus(LZ4D_STATUS_DONE))
// ;
// __ISB();
LOG_I("vm linux load done!\r\n");

/* Copy dtb code */
pSrc = (uint32_t *)DTB_SRC_ADDR;
pDest = (uint32_t *)DTB_DST_ADDR;
memcpy((void *)pDest, (void *)pSrc, 0x10000);
LOG_I("dtb load done!\r\n");

/* Copy opensbi code */
pSrc = (uint32_t *)OPENSBI_SRC_ADDR;
pDest = (uint32_t *)OPENSBI_DST_ADDR;
memcpy((void *)pDest, (void *)pSrc, 0xc000);
LOG_I("opensbi load done!\r\n");

csi_dcache_clean_invalid();
// csi_dcache_clean();
}

extern void bflb_uart_set_console(struct bflb_device_s *dev);
Expand All @@ -258,7 +213,6 @@ int main(void)
bflb_uart_init(uart0, &cfg);
bflb_uart_set_console(uart0);


LOG_I("D0 start...\r\n");
uint64_t start_time, stop_time;

Expand All @@ -274,9 +228,15 @@ int main(void)
: "r"(0x30013));

LOG_I("Setting PMP\r\n");
rvpmp_init(pmp_entry_tab, sizeof(pmp_entry_tab) / sizeof(pmp_config_entry_t));
pmp_status_type_e ret = rvpmp_init(pmp_entry_tab, sizeof(pmp_entry_tab) / sizeof(pmp_config_entry_t));
if (ret != PMP_STATUS_OK) {
LOG_E("PMP init failed: %d\r\n", ret);
while (1) {
/* dead? */
}
}
__ISB();
LOG_I("Running OpenSBI\r\n");
LOG_I("Booting OpenSBI at %p with DTB at 0x%08x\r\n", opensbi, DTB_DST_ADDR);
opensbi(0, DTB_DST_ADDR);
while (1) {
LOG_W("Return from OpenSBI!!!\r\n");
Expand Down

0 comments on commit bd6ea74

Please sign in to comment.