Skip to content

Commit

Permalink
[bsp/rpi4] fixup startup failure (#8754)
Browse files Browse the repository at this point in the history
[bsp/rpi4] fixup startup issues

Signed-off-by: Shell <[email protected]>
  • Loading branch information
polarvid committed Apr 10, 2024
1 parent 48f83a5 commit b14e0c0
Show file tree
Hide file tree
Showing 16 changed files with 202 additions and 554 deletions.
352 changes: 110 additions & 242 deletions bsp/raspberry-pi/raspi4-64/.config

Large diffs are not rendered by default.

6 changes: 1 addition & 5 deletions bsp/raspberry-pi/raspi4-64/SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ DefaultEnvironment(tools=[])
env = Environment(tools = ['mingw'],
AS = rtconfig.AS, ASFLAGS = rtconfig.AFLAGS,
CC = rtconfig.CC, CFLAGS = rtconfig.CFLAGS,
CXX = rtconfig.CXX, CXXFLAGS = rtconfig.CXXFLAGS,
CPP = rtconfig.CPP, CXXFLAGS = rtconfig.CXXFLAGS,
AR = rtconfig.AR, ARFLAGS = '-rc',
LINK = rtconfig.LINK, LINKFLAGS = rtconfig.LFLAGS)
env.PrependENVPath('PATH', rtconfig.EXEC_PATH)
Expand All @@ -26,9 +26,5 @@ Export('rtconfig')
# prepare building environment
objs = PrepareBuilding(env, RTT_ROOT)

if GetDepend('RT_USING_SMART'):
# use smart link.lds
env['LINKFLAGS'] = env['LINKFLAGS'].replace('link.lds', 'link_smart.lds')

# make a building
DoBuilding(TARGET, objs)
19 changes: 16 additions & 3 deletions bsp/raspberry-pi/raspi4-64/applications/mnt.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,29 @@

#include <rtthread.h>

#ifdef BSP_USING_SDIO0
#ifdef BSP_USING_SDIO
#include <dfs_fs.h>

int mnt_init(void)
{
rt_thread_delay(RT_TICK_PER_SECOND);
if (dfs_mount("sd0", "/", "elm", 0, 0) == 0)
rt_thread_delay(RT_TICK_PER_SECOND/100);
if (dfs_mount("sd1", "/", "ext", 0, 0) == 0)
{
rt_kprintf("file system initialization done!\n");
}
else if (dfs_mount("sd0", "/", "elm", 0, 0) == 0)
{
rt_kprintf("file system initialization done!\n");
}

#ifdef RT_USING_DFS_ROMFS
mkdir("/rom", 0777);
extern const struct romfs_dirent romfs_root;
if (dfs_mount(RT_NULL, "/rom", "rom", 0, &romfs_root) == 0)
{
rt_kprintf("ROM File System initialized!\n");
}
#endif

return 0;
}
Expand Down
44 changes: 8 additions & 36 deletions bsp/raspberry-pi/raspi4-64/drivers/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
* 2023-03-28 WangXiaoyao sync works & memory layout fixups
* code formats
*/
#define DBG_TAG "board"
#define DBG_LVL DBG_INFO
#include <rtdbg.h>

#include <rthw.h>
#include <rtthread.h>
Expand Down Expand Up @@ -60,7 +63,7 @@ struct mem_desc platform_mem_desc[] = {
};
#else
struct mem_desc platform_mem_desc[] = {
{0x00200000, (128ul << 20) - 1, 0x00200000, NORMAL_MEM},
{0x00200000, (256ul << 20) - 1, 0x00200000, NORMAL_MEM},
{0xFC000000, 0x000100000000 - 1, 0xFC000000, DEVICE_MEM},
};
#endif
Expand Down Expand Up @@ -90,12 +93,14 @@ rt_region_t init_page_region = {
*/
void rt_hw_board_init(void)
{
rt_hw_earlycon_ioremap_early();

/* io device remap */
#ifdef RT_USING_SMART
rt_hw_mmu_map_init(&rt_kernel_space, (void*)0xfffffffff0000000, 0x10000000, MMUTable, PV_OFFSET);
#else
rt_hw_mmu_map_init(&rt_kernel_space, (void*)0x000400000000, 0x10000000, MMUTable, 0);
#endif
rt_hw_mmu_map_init(&rt_kernel_space, (void*)0x080000000000, 0x10000000, MMUTable, 0);
#endif /* RT_USING_SMART */
rt_page_init(init_page_region);
rt_hw_mmu_setup(&rt_kernel_space, platform_mem_desc, platform_mem_desc_size);

Expand Down Expand Up @@ -147,8 +152,6 @@ void rt_hw_board_init(void)
rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
#endif /* RT_USING_CONSOLE */

rt_kprintf("heap: 0x%08x - 0x%08x\n", HEAP_BEGIN, HEAP_END);

#ifdef RT_USING_COMPONENTS_INIT
rt_components_board_init();
#endif
Expand All @@ -170,45 +173,14 @@ static unsigned long cpu_release_paddr[] =
[4] = 0x00
};

#ifndef RT_USING_SMART
static void *_remap(void *paddr, size_t size)
{
int ret;
static void *va = 0;
size_t low_off = (size_t)paddr & ARCH_PAGE_MASK;
if (va)
return va + low_off;

va = rt_kernel_space.start;
while (1)
{
int rt_kmem_map_phy(void *va, void *pa, rt_size_t length, rt_size_t attr);
ret = rt_kmem_map_phy(va, 0x0, ARCH_PAGE_SIZE, MMU_MAP_K_DEVICE);
if (ret == RT_EOK)
{
break;
}
else
{
va += ARCH_PAGE_SIZE;
}
}
return va + low_off;
}
#endif /* RT_USING_SMART */

void rt_hw_secondary_cpu_up(void)
{
int i;
void *release_addr;

for (i = 1; i < RT_CPUS_NR && cpu_release_paddr[i]; ++i)
{
#ifdef RT_USING_SMART
release_addr = rt_ioremap((void *)cpu_release_paddr[i], sizeof(cpu_release_paddr[0]));
#else
release_addr = _remap((void *)cpu_release_paddr[i], sizeof(cpu_release_paddr[0]));
#endif
__asm__ volatile ("str %0, [%1]"::"rZ"((unsigned long)_secondary_cpu_entry + PV_OFFSET), "r"(release_addr));
rt_hw_cpu_dcache_ops(RT_HW_CACHE_FLUSH, release_addr, sizeof(release_addr));
asm volatile ("dsb sy");
Expand Down
4 changes: 2 additions & 2 deletions bsp/raspberry-pi/raspi4-64/drivers/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ extern int __bss_end;
#else
#define KERNEL_VADDR_START 0x0

#define HEAP_END (KERNEL_VADDR_START + 64 * 1024 * 1024)
#define HEAP_END (KERNEL_VADDR_START + 32 * 1024 * 1024)
#define PAGE_START HEAP_END
#define PAGE_END ((size_t)PAGE_START + 64 * 1024 * 1024)
#define PAGE_END ((size_t)PAGE_START + 128 * 1024 * 1024)
#endif

void rt_hw_board_init(void);
Expand Down
29 changes: 20 additions & 9 deletions bsp/raspberry-pi/raspi4-64/drivers/drv_eth.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
#include "raspi4.h"
#include "drv_eth.h"

#define DBG_LEVEL DBG_LOG
#define LOG_LVL DBG_LOG
#define LOG_TAG "drv.eth"
#include <rtdbg.h>
#define LOG_TAG "drv.eth"

static int link_speed = 0;
static int link_flag = 0;
Expand Down Expand Up @@ -536,17 +536,17 @@ static void link_task_entry(void *param)
if ((bcmgenet_mdio_read(1, BCM54213PE_STATUS) & (1 << 10)) || (bcmgenet_mdio_read(1, BCM54213PE_STATUS) & (1 << 11)))
{
link_speed = 1000;
rt_kprintf("Support link mode Speed 1000M\n");
LOG_I("Support link mode Speed 1000M\n");
}
else if ((bcmgenet_mdio_read(1, 0x05) & (1 << 7)) || (bcmgenet_mdio_read(1, 0x05) & (1 << 8)) || (bcmgenet_mdio_read(1, 0x05) & (1 << 9)))
{
link_speed = 100;
rt_kprintf("Support link mode Speed 100M\n");
LOG_I("Support link mode Speed 100M\n");
}
else
{
link_speed = 10;
rt_kprintf("Support link mode Speed 10M\n");
LOG_I("Support link mode Speed 10M\n");
}

bcmgenet_gmac_eth_start();
Expand All @@ -573,7 +573,7 @@ static rt_err_t bcmgenet_eth_init(rt_device_t device)
else if (major == 0)
major = 1;

rt_kprintf("Uns upported GENETv%d.%d\n", major, (hw_reg >> 16) & 0x0f);
LOG_W("Unsupported GENETv%d.%d\n", major, (hw_reg >> 16) & 0x0f);
return -RT_ERROR;
}
/* set interface */
Expand Down Expand Up @@ -623,15 +623,15 @@ rt_err_t rt_eth_tx(rt_device_t device, struct pbuf *p)
/* lock eth device */
if (link_flag != 1)
{
rt_kprintf("link disconnected\n");
LOG_I("link disconnected\n");
return -RT_ERROR;
}

copy_len = pbuf_copy_partial(p, eth_send_no_cache, p->tot_len, 0);
if (copy_len == 0)
{

rt_kprintf("copy len is zero\n");
LOG_I("copy len is zero\n");
return -RT_ERROR;
}
bcmgenet_gmac_eth_send((void *)eth_send_no_cache, p->tot_len);
Expand Down Expand Up @@ -664,9 +664,16 @@ struct pbuf *rt_eth_rx(rt_device_t device)
return pbuf;
}

#ifdef RT_USING_DEVICE_OPS
static struct rt_device_ops eth_devops = {
.init = bcmgenet_eth_init,
.control = bcmgenet_eth_control,
};
#endif /* RT_USING_DEVICE_OPS */

int rt_hw_eth_init(void)
{
rt_uint8_t mac_addr[6];
rt_uint8_t mac_addr[6] = {0xdc, 0xa6, 0x32, 0x28, 0x22, 0x50};

rt_sem_init(&link_ack, "link_ack", 0, RT_IPC_FLAG_FIFO);

Expand All @@ -685,12 +692,16 @@ int rt_hw_eth_init(void)
eth_dev.dev_addr[5] = mac_addr[5];

eth_dev.parent.parent.type = RT_Device_Class_NetIf;
#ifdef RT_USING_DEVICE_OPS
eth_dev.parent.parent.ops = &eth_devops;
#else /* !RT_USING_DEVICE_OPS */
eth_dev.parent.parent.init = bcmgenet_eth_init;
eth_dev.parent.parent.open = RT_NULL;
eth_dev.parent.parent.close = RT_NULL;
eth_dev.parent.parent.read = RT_NULL;
eth_dev.parent.parent.write = RT_NULL;
eth_dev.parent.parent.control = bcmgenet_eth_control;
#endif /* RT_USING_DEVICE_OPS */
eth_dev.parent.parent.user_data = RT_NULL;

eth_dev.parent.eth_tx = rt_eth_tx;
Expand Down
9 changes: 7 additions & 2 deletions bsp/raspberry-pi/raspi4-64/drivers/drv_uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ static const struct rt_uart_ops _uart_ops =
uart_getc,
};

void *earlycon_base = (void *)AUX_BASE;
size_t earlycon_size = 0x1000;
volatile void *earlycon_base = 0;
const size_t earlycon_size = 0x1000;

extern void early_putc(int c)
{
Expand All @@ -200,6 +200,11 @@ extern void early_putc(int c)
AUX_MU_IO_REG(earlycon_base) = c;
}

void rt_hw_earlycon_ioremap_early(void)
{
earlycon_base = rt_ioremap_early((void *)AUX_BASE, earlycon_size);
}

void rt_hw_console_output(const char *str)
{
if (earlycon_base)
Expand Down
1 change: 1 addition & 0 deletions bsp/raspberry-pi/raspi4-64/drivers/drv_uart.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,6 @@
#define AUX_SPI1_CNTL1_REG(BASE) HWREG32(BASE + 0xC4) /* SPI 2 Control register 1 8bit */

int rt_hw_uart_init(void);
void rt_hw_earlycon_ioremap_early(void);

#endif /* DRV_UART_H__ */
4 changes: 2 additions & 2 deletions bsp/raspberry-pi/raspi4-64/drivers/drv_wdt.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ int rt_hw_wdt_init(void)
}
INIT_DEVICE_EXPORT(rt_hw_wdt_init);

void reboot(void)
void rt_hw_cpu_reset(void)
{
unsigned int r;

Expand All @@ -131,5 +131,5 @@ void reboot(void)

while (1);
}
MSH_CMD_EXPORT(reboot,reboot system...);
MSH_CMD_EXPORT_ALIAS(rt_hw_cpu_reset, reboot, reboot system...);
#endif /*BSP_USING_WDT */
Loading

0 comments on commit b14e0c0

Please sign in to comment.