Skip to content

Commit 480a62e

Browse files
committed
Fix rt_hw_board_init
1 parent 00c2f2d commit 480a62e

File tree

5 files changed

+62
-45
lines changed

5 files changed

+62
-45
lines changed

bsp/nxp/imx/imx91/drivers/board.c

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,18 @@
1414
#include <gtimer.h>
1515
#include <mm_aspace.h>
1616
#include <mm_page.h>
17+
18+
#include <rtconfig.h>
1719
#include <rtdevice.h>
1820

1921
#include <mmu.h>
2022

21-
#define BOARD_DRAM_SIZE (256 * 1024 * 1024)
23+
#include <limits.h>
24+
2225

2326
struct mem_desc platform_mem_desc[] = {
24-
{0x00200000, 0x00200000 + BOARD_DRAM_SIZE - 1, 0x80000000, NORMAL_MEM}, // 256MB DRAM
25-
{0xD0000000, 0xFFFFFFFF, 0x38000000, DEVICE_MEM},
27+
{0x80100000, 0x8FFFFFFF, 0x80000000, NORMAL_MEM},
28+
{0xD4000000, 0xDFFFFFFF, 0x44380000, DEVICE_MEM},
2629
};
2730

2831
const rt_uint32_t platform_mem_desc_size = sizeof(platform_mem_desc)/sizeof(platform_mem_desc[0]);
@@ -81,38 +84,46 @@ void rt_hw_board_init(void)
8184
{
8285
// enable_neon_fpu();
8386
// disable_strict_align_check();
87+
rt_hw_earlycon_ioremap();
88+
89+
rt_hw_earlycon_puts("rt_hw_board_init!\n");
90+
rt_hw_mmu_map_init(&rt_kernel_space, (void*)0x080000000000, 0x10000000, MMUTable, 0);
91+
rt_hw_earlycon_puts("[rt_hw_board_init] rt_hw_mmu_map_init done!\n");
8492

85-
imx_uart1_puts("rt_hw_board_init!\n");
86-
// rt_hw_mmu_map_init(&rt_kernel_space, (void*)0x080000000000, 0x10000000, MMUTable, 0);
93+
rt_hw_earlycon_print_hex("[rt_hw_board_init] rt_kernel_space.start: ", (rt_base_t) rt_kernel_space.start);
94+
rt_hw_earlycon_print_hex("[rt_hw_board_init] rt_kernel_space.size: ", (rt_base_t) rt_kernel_space.size);
8795

88-
// imx_uart1_puts("rt_page_init!\n");
89-
// imx_uart1_print_hex("PAGE_START: ", (rt_base_t) PAGE_START);
90-
// imx_uart1_print_hex("PAGE_END: ", (rt_base_t) PAGE_END);
91-
// rt_page_init(init_page_region);
96+
rt_hw_earlycon_print_hex("[rt_hw_board_init] PAGE_START: ", (rt_base_t) PAGE_START);
97+
rt_hw_earlycon_print_hex("[rt_hw_board_init] PAGE_END: ", (rt_base_t) PAGE_END);
98+
rt_page_init(init_page_region);
9299

93-
// imx_uart1_puts("rt_hw_mmu_setup!\n");
94-
// rt_hw_mmu_setup(&rt_kernel_space, platform_mem_desc, platform_mem_desc_size);
100+
rt_hw_earlycon_puts("[rt_hw_board_init] rt_hw_mmu_setup!\n");
101+
rt_hw_mmu_setup(&rt_kernel_space, platform_mem_desc, platform_mem_desc_size);
95102

96103
#ifdef RT_USING_HEAP
97104
/* initialize system heap */
105+
rt_hw_earlycon_puts("[rt_hw_board_init] rt_system_heap_init!\n");
98106
rt_system_heap_init((void *)HEAP_BEGIN, (void *)HEAP_END);
99107
#endif
100108

101109
/* initialize hardware interrupt */
110+
rt_hw_earlycon_puts("[rt_hw_board_init] rt_hw_interrupt_init!\n");
102111
rt_hw_interrupt_init();
103112

113+
/* initialize uart */
114+
rt_hw_earlycon_puts("[rt_hw_board_init] rt_hw_uart_init!\n");
104115
rt_hw_uart_init();
105-
rt_hw_console_output("rt_hw_uart_init done!\n");
116+
rt_hw_console_output("[rt_hw_board_init] rt_hw_uart_init done!\n");
106117

107118
/* initialize timer for os tick */
108119
rt_hw_gtimer_init();
109120

110121
rt_components_board_init();
111122
rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
112123

113-
rt_hw_console_output("rt_hw_board_init done!\n");
114-
rt_kprintf("rt_kprintf works!\n");
115-
rt_hw_console_output("rt_hw_board_init done!!\n");
124+
rt_hw_console_output("[rt_hw_board_init] rt_hw_board_init done!\n");
125+
rt_kprintf("[rt_hw_board_init] rt_kprintf works!\n");
126+
rt_hw_console_output("[rt_hw_board_init] rt_hw_board_init done!!\n");
116127
}
117128

118129
/*@}*/

bsp/nxp/imx/imx91/drivers/board.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,7 @@ extern int __bss_end;
2525
#define HEAP_BEGIN ((void*)&__bss_end)
2626
#endif
2727

28-
// #define KERNEL_VADDR_START 0x0
29-
#ifndef KERNEL_VADDR_START
30-
#define KERNEL_VADDR_START (ARCH_RAM_OFFSET + ARCH_TEXT_OFFSET)
31-
#endif
32-
33-
#define HEAP_END (KERNEL_VADDR_START + 32 * 1024 * 1024)
34-
35-
// #define HEAP_END (void*)(HEAP_BEGIN + 32 * 1024 * 1024)
28+
#define HEAP_END (void*)(HEAP_BEGIN + 32 * 1024 * 1024)
3629
#define PAGE_START HEAP_END
3730
#define PAGE_END ((size_t)PAGE_START + 128 * 1024 * 1024)
3831

bsp/nxp/imx/imx91/drivers/serial.c

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ struct hw_uart_device
2626
const char *device_name; /* serial device name */
2727

2828
LPUART_Type* uart_base;
29+
LPUART_Type* uart_instance;
2930
int irqn;
3031

3132
clock_root_t clock_root; /* clock root */
@@ -38,7 +39,8 @@ struct hw_uart_device
3839
static struct hw_uart_device _uart1_device =
3940
{
4041
.device_name = "uart1",
41-
.uart_base = LPUART1,
42+
.uart_base = RT_NULL,
43+
.uart_instance = LPUART1,
4244
.irqn = LPUART1_IRQn,
4345
.clock_root = kCLOCK_Root_Lpuart1,
4446
.clock_mux = kCLOCK_LPUART1_ClockRoot_MuxOsc24M,
@@ -238,38 +240,47 @@ static int uart_putc(struct rt_serial_device *serial, char c)
238240
return 1;
239241
}
240242

241-
void imx_uart1_putc(char c)
243+
volatile LPUART_Type *earlycon_base = LPUART1;
244+
const size_t earlycon_size = 4096; // sizeof(LPUART_Type);
245+
246+
void rt_hw_earlycon_ioremap(void)
247+
{
248+
earlycon_base = rt_ioremap_early((void *)earlycon_base, earlycon_size);
249+
rt_hw_earlycon_print_hex("earlycon_base: ", (rt_base_t)earlycon_base);
250+
}
251+
252+
void rt_hw_earlycon_putc(char c)
242253
{
243-
LPUART_WriteByte(LPUART1, c);
244-
while (!(LPUART_GetStatusFlags(LPUART1) & kLPUART_TxDataRegEmptyFlag));
254+
LPUART_WriteByte(earlycon_base, c);
255+
while (!(LPUART_GetStatusFlags(earlycon_base) & kLPUART_TxDataRegEmptyFlag));
245256
}
246257

247-
void imx_uart1_puts(const char *str)
258+
void rt_hw_earlycon_puts(const char *str)
248259
{
249260
int has_cr = 0;
250261
while (*str) {
251262
if (*str == '\r') {
252263
has_cr = 1;
253264
} else if (*str == '\n') {
254265
if (!has_cr) {
255-
imx_uart1_putc('\r');
266+
rt_hw_earlycon_putc('\r');
256267
}
257268
}
258-
imx_uart1_putc(*str++);
269+
rt_hw_earlycon_putc(*str++);
259270
}
260271
}
261272

262-
void imx_uart1_print_hex(const char *str, rt_base_t hex)
273+
void rt_hw_earlycon_print_hex(const char *str, rt_base_t hex)
263274
{
264-
imx_uart1_puts(str);
265-
imx_uart1_putc('0');
266-
imx_uart1_putc('x');
275+
rt_hw_earlycon_puts(str);
276+
rt_hw_earlycon_putc('0');
277+
rt_hw_earlycon_putc('x');
267278
for (int i = 60; i >= 0; i -= 4) {
268279
rt_base_t h = (hex >> i) & 0xF;
269-
imx_uart1_putc(h < 10 ? '0' + h : 'A' + h - 10);
280+
rt_hw_earlycon_putc(h < 10 ? '0' + h : 'A' + h - 10);
270281
}
271-
imx_uart1_putc('\r');
272-
imx_uart1_putc('\n');
282+
rt_hw_earlycon_putc('\r');
283+
rt_hw_earlycon_putc('\n');
273284
}
274285

275286
void rt_hw_console_putc(char c)
@@ -340,7 +351,8 @@ int rt_hw_uart_init(void)
340351
{
341352
hw_uart_devices[i]->serial.ops = &_uart_ops;
342353
hw_uart_devices[i]->serial.config = config;
343-
// hw_uart_devices[i]->uart_base = rt_ioremap((void *)hw_uart_devices[i]->uart_base, sizeof(LPUART_Type));
354+
rt_hw_earlycon_print_hex("ioremap uart_instance: ", (rt_base_t)hw_uart_devices[i]->uart_instance);
355+
hw_uart_devices[i]->uart_base = rt_ioremap((void *)hw_uart_devices[i]->uart_instance, 0x1000);
344356

345357
rt_hw_serial_register(&hw_uart_devices[i]->serial, hw_uart_devices[i]->device_name,
346358
RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX, hw_uart_devices[i]);

bsp/nxp/imx/imx91/drivers/serial.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@
1717

1818
int rt_hw_uart_init(void);
1919

20-
void imx_uart1_putc(char c);
21-
void imx_uart1_puts(const char *str);
22-
void imx_uart1_print_hex(const char *str, rt_base_t hex);
20+
void rt_hw_earlycon_ioremap(void);
21+
void rt_hw_earlycon_putc(char c);
22+
void rt_hw_earlycon_puts(const char *str);
23+
void rt_hw_earlycon_print_hex(const char *str, rt_base_t hex);
2324

2425
void rt_hw_console_putc(char c);
2526
void rt_hw_console_output(const char *str);

bsp/nxp/imx/imx91/rtconfig.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
OBJDUMP = PREFIX + 'objdump'
3939
OBJCPY = PREFIX + 'objcopy'
4040

41-
DEVICE = ' -march=armv8-a -mtune=cortex-a55 -fno-omit-frame-pointer'
41+
DEVICE = ' -march=armv8-a -mtune=cortex-a55'
4242
CPPFLAGS = ' -E -P -x assembler-with-cpp'
4343
CFLAGS = DEVICE + ' -Wall -Wno-cpp -D_POSIX_SOURCE'
4444
AFLAGS = ' -c' + DEVICE + ' -x assembler-with-cpp -D__ASSEMBLY__'
@@ -50,10 +50,10 @@
5050
LPATH = ''
5151

5252
if BUILD == 'debug':
53-
CFLAGS += ' -O0'
54-
CPPFLAGS += ' -O0 -ggdb -gdwarf-2'
53+
CFLAGS += ' -O0 -ggdb'
54+
CPPFLAGS += ' -O0 -ggdb'
5555
else:
56-
CFLAGS += ' -O2'
56+
CFLAGS += ' -O2 -ggdb'
5757
CPPFLAGS += ' -O2 -ggdb'
5858

5959
POST_ACTION = OBJCPY + ' -O binary $TARGET rtthread.bin\n' +\

0 commit comments

Comments
 (0)