Skip to content

Commit f96280f

Browse files
committed
Fix align exception when startup
1 parent b5a130e commit f96280f

File tree

10 files changed

+73
-106
lines changed

10 files changed

+73
-106
lines changed

bsp/nxp/imx/imx91/.config

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,14 @@ CONFIG_RT_KLIBC_USING_VSNPRINTF_LOG10_TAYLOR_TERMS=4
116116
# end of rt_strnlen options
117117
# end of klibc options
118118

119-
CONFIG_RT_NAME_MAX=8
119+
CONFIG_RT_NAME_MAX=16
120120
# CONFIG_RT_USING_ARCH_DATA_TYPE is not set
121121
# CONFIG_RT_USING_NANO is not set
122122
# CONFIG_RT_USING_SMART is not set
123123
# CONFIG_RT_USING_AMP is not set
124124
# CONFIG_RT_USING_SMP is not set
125125
CONFIG_RT_CPUS_NR=1
126-
CONFIG_RT_ALIGN_SIZE=8
126+
CONFIG_RT_ALIGN_SIZE=16
127127
# CONFIG_RT_THREAD_PRIORITY_8 is not set
128128
CONFIG_RT_THREAD_PRIORITY_32=y
129129
# CONFIG_RT_THREAD_PRIORITY_256 is not set
@@ -135,10 +135,10 @@ CONFIG_RT_HOOK_USING_FUNC_PTR=y
135135
# CONFIG_RT_USING_HOOKLIST is not set
136136
CONFIG_RT_USING_IDLE_HOOK=y
137137
CONFIG_RT_IDLE_HOOK_LIST_SIZE=4
138-
CONFIG_IDLE_THREAD_STACK_SIZE=1024
138+
CONFIG_IDLE_THREAD_STACK_SIZE=8192
139139
CONFIG_RT_USING_TIMER_SOFT=y
140140
CONFIG_RT_TIMER_THREAD_PRIO=4
141-
CONFIG_RT_TIMER_THREAD_STACK_SIZE=2048
141+
CONFIG_RT_TIMER_THREAD_STACK_SIZE=8192
142142
# CONFIG_RT_USING_TIMER_ALL_SOFT is not set
143143
# CONFIG_RT_USING_CPU_USAGE_TRACER is not set
144144

@@ -201,11 +201,11 @@ CONFIG_RT_BACKTRACE_LEVEL_MAX_NR=32
201201
#
202202
CONFIG_ARCH_TEXT_OFFSET=0x100000
203203
CONFIG_ARCH_RAM_OFFSET=0x80000000
204-
CONFIG_ARCH_SECONDARY_CPU_STACK_SIZE=16384
204+
CONFIG_ARCH_SECONDARY_CPU_STACK_SIZE=4096
205205
CONFIG_ARCH_HAVE_EFFICIENT_UNALIGNED_ACCESS=y
206206
CONFIG_ARCH_USING_GENERIC_CPUID=y
207-
CONFIG_ARCH_HEAP_SIZE=0x4000000
208-
CONFIG_ARCH_INIT_PAGE_SIZE=0x200000
207+
CONFIG_ARCH_HEAP_SIZE=0x2000000
208+
CONFIG_ARCH_INIT_PAGE_SIZE=0x8000000
209209
# end of AArch64 Architecture Configuration
210210

211211
CONFIG_ARCH_CPU_64BIT=y
@@ -239,10 +239,11 @@ CONFIG_RT_USING_FINSH=y
239239
CONFIG_FINSH_USING_MSH=y
240240
CONFIG_FINSH_THREAD_NAME="tshell"
241241
CONFIG_FINSH_THREAD_PRIORITY=20
242-
CONFIG_FINSH_THREAD_STACK_SIZE=4096
242+
CONFIG_FINSH_THREAD_STACK_SIZE=8092
243243
CONFIG_FINSH_USING_HISTORY=y
244244
CONFIG_FINSH_HISTORY_LINES=5
245245
# CONFIG_FINSH_USING_WORD_OPERATION is not set
246+
# CONFIG_FINSH_USING_FUNC_EXT is not set
246247
CONFIG_FINSH_USING_SYMTAB=y
247248
CONFIG_FINSH_CMD_SIZE=80
248249
CONFIG_MSH_USING_BUILT_IN_COMMANDS=y
@@ -1468,7 +1469,9 @@ CONFIG_SOC_MIMX91X1D=y
14681469
#
14691470
# Hardware Drivers Config
14701471
#
1472+
# CONFIG_BSP_USING_EARLY_CONSOLE is not set
14711473
CONFIG_BSP_USING_UART1=y
14721474
CONFIG_BSP_USING_GIC=y
14731475
CONFIG_BSP_USING_GICV3=y
1476+
CONFIG_KERNEL_ASPACE_START=0x80100000
14741477
# end of Hardware Drivers Config

bsp/nxp/imx/imx91/addr2line.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash
2+
aarch64-none-elf-addr2line -e rtthread.elf -a -f $*

bsp/nxp/imx/imx91/drivers/Kconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
menu "Hardware Drivers Config"
22

3+
config BSP_USING_EARLY_CONSOLE
4+
bool "Enable early console"
5+
default n
6+
37
config BSP_USING_UART1
48
bool "Enable UART1"
59
default y
@@ -12,4 +16,8 @@ config BSP_USING_GICV3
1216
bool "Enable GICv3"
1317
default y
1418

19+
config KERNEL_ASPACE_START
20+
hex "Kernel aspace start address"
21+
default 0x80100000
22+
1523
endmenu

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

Lines changed: 13 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,20 @@
2222

2323
#include <limits.h>
2424

25+
#define DRAM_MAP_START 0x80100000
26+
#define DRAM_MAP_SIZE (64 * 1024 * 1024) // part of DRAM
27+
28+
#define PERIPH_MAP_START 0x44000000
29+
#define PERIPH_MAP_SIZE (0x10000000)
30+
31+
#define PERIPH_VADDR_START 0xD4000000
32+
33+
#define MEM_DESC(vaddr_start, size, paddr_start, attr) \
34+
vaddr_start, (vaddr_start + size - 1uL), paddr_start, attr
2535

2636
struct mem_desc platform_mem_desc[] = {
27-
{0x80100000, 0x8FFFFFFF, 0x80000000, NORMAL_MEM},
28-
{0xD4000000, 0xDFFFFFFF, 0x44380000, DEVICE_MEM},
37+
{MEM_DESC(KERNEL_VADDR_START, DRAM_MAP_SIZE, DRAM_MAP_START, NORMAL_MEM)},
38+
{MEM_DESC(PERIPH_VADDR_START, PERIPH_MAP_SIZE, PERIPH_MAP_START, DEVICE_MEM)},
2939
};
3040

3141
const rt_uint32_t platform_mem_desc_size = sizeof(platform_mem_desc)/sizeof(platform_mem_desc[0]);
@@ -37,52 +47,11 @@ rt_region_t init_page_region = {
3747

3848
extern unsigned long MMUTable[];
3949

40-
static void rt_hw_timer_isr(int vector, void *param)
41-
{
42-
rt_tick_increase();
43-
// epit_get_compare_event(HW_EPIT1);
44-
}
45-
46-
int rt_hw_timer_init(void)
47-
{
48-
uint32_t freq;
49-
50-
// Make sure the timer is off.
51-
// HW_ARMGLOBALTIMER_CONTROL.B.TIMER_ENABLE = 0;
52-
53-
// HW_ARMGLOBALTIMER_CONTROL.B.FCR0 =1;
54-
55-
// HW_ARMGLOBALTIMER_CONTROL.B.FCR1 =0;
56-
57-
// HW_ARMGLOBALTIMER_CONTROL.B.DBG_ENABLE =0;
58-
59-
// // Clear counter.
60-
// HW_ARMGLOBALTIMER_COUNTER_HI_WR(0);
61-
// HW_ARMGLOBALTIMER_COUNTER_LO_WR(0);
62-
63-
// // Now turn on the timer.
64-
// HW_ARMGLOBALTIMER_CONTROL.B.TIMER_ENABLE = 1;
65-
66-
// freq = get_main_clock(IPG_CLK);
67-
68-
// epit_init(HW_EPIT1, CLKSRC_IPG_CLK, freq / 1000000,
69-
// SET_AND_FORGET, 10000, WAIT_MODE_EN | STOP_MODE_EN);
70-
71-
// epit_counter_enable(HW_EPIT1, 10000, IRQ_MODE);
72-
73-
// rt_hw_interrupt_install(IMX_INT_EPIT1, rt_hw_timer_isr, RT_NULL, "tick");
74-
// rt_hw_interrupt_umask(IMX_INT_EPIT1);
75-
76-
return 0;
77-
}
78-
INIT_BOARD_EXPORT(rt_hw_timer_init);
79-
8050
/**
8151
* This function will initialize hardware board
8252
*/
8353
void rt_hw_board_init(void)
8454
{
85-
// enable_neon_fpu();
8655
// disable_strict_align_check();
8756
rt_hw_earlycon_ioremap();
8857

@@ -120,10 +89,9 @@ void rt_hw_board_init(void)
12089

12190
rt_components_board_init();
12291
rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
92+
rt_hw_console_output("[rt_hw_board_init] rt_console_set_device done!\n");
12393

124-
rt_hw_console_output("[rt_hw_board_init] rt_hw_board_init done!\n");
12594
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");
12795
}
12896

12997
/*@}*/

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ extern int __bss_end;
2525
#define HEAP_BEGIN ((void*)&__bss_end)
2626
#endif
2727

28+
#ifndef KERNEL_VADDR_START
29+
#define KERNEL_VADDR_START (ARCH_RAM_OFFSET + ARCH_TEXT_OFFSET)
30+
#endif
31+
2832
#define HEAP_END (void*)(HEAP_BEGIN + 32 * 1024 * 1024)
2933
#define PAGE_START HEAP_END
3034
#define PAGE_END ((size_t)PAGE_START + 128 * 1024 * 1024)

bsp/nxp/imx/imx91/drivers/sdk/drivers/lpuart/fsl_lpuart.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,6 @@ void LPUART_GetDefaultConfig(lpuart_config_t *config)
660660
{
661661
assert(NULL != config);
662662

663-
rt_hw_console_output("LPUART_GetDefaultConfig start!\n");
664663
/* Initializes the configure structure to zero. */
665664
(void)memset(config, 0, sizeof(*config));
666665

@@ -688,7 +687,6 @@ void LPUART_GetDefaultConfig(lpuart_config_t *config)
688687
#if defined(FSL_FEATURE_LPUART_HAS_CTRL_SWAP) && FSL_FEATURE_LPUART_HAS_CTRL_SWAP
689688
config->swapTxdRxd = false;
690689
#endif
691-
rt_hw_console_output("LPUART_GetDefaultConfig done!\n");
692690
}
693691

694692
/*!

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

Lines changed: 8 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -64,49 +64,16 @@ static void rt_hw_uart_isr(int irqn, void *param)
6464

6565
static rt_err_t uart_configure(struct rt_serial_device *serial, struct serial_configure *cfg)
6666
{
67-
// struct hw_uart_device *uart;
68-
// uint32_t baudrate;
69-
// uint8_t parity, stopbits, datasize, flowcontrol;
70-
71-
// RT_ASSERT(serial != RT_NULL);
72-
// uart = (struct hw_uart_device *)serial->parent.user_data;
73-
74-
// baudrate = cfg->baud_rate;
75-
// switch (cfg->data_bits)
76-
// {
77-
// case DATA_BITS_8:
78-
// datasize = EIGHTBITS;
79-
// break;
80-
// case DATA_BITS_7:
81-
// datasize = SEVENBITS;
82-
// break;
83-
// }
84-
// if (cfg->stop_bits == STOP_BITS_1) stopbits = STOPBITS_ONE;
85-
// else if (cfg->stop_bits == STOP_BITS_2) stopbits = STOPBITS_TWO;
86-
87-
// parity = PARITY_NONE;
88-
// flowcontrol = FLOWCTRL_OFF;
89-
90-
// /* Initialize UART */
91-
// uart_init(uart->uart_base, baudrate, parity, stopbits, datasize, flowcontrol);
92-
93-
// rt_hw_interrupt_install(uart->irqn, rt_hw_uart_isr, serial, "uart");
94-
// rt_hw_interrupt_mask(uart->irqn);
95-
96-
// /* Set the IRQ mode for the Rx FIFO */
97-
// uart_set_FIFO_mode(uart->uart_base, RX_FIFO, 1, IRQ_MODE);
98-
9967
struct hw_uart_device *uart = RT_NULL;
10068
static lpuart_config_t config;
10169

102-
rt_hw_console_output("uart_configure start ...\n");
10370
RT_ASSERT(serial != RT_NULL);
10471
uart = (struct hw_uart_device *)serial->parent.user_data;
10572

106-
rt_hw_console_output("uart_configure LPUART_GetDefaultConfig ...\n");
73+
rt_hw_console_output("uart_configure start ...\n");
10774
LPUART_GetDefaultConfig(&config);
108-
rt_hw_console_output("uart_configure LPUART_GetDefaultConfig done!\n");
10975

76+
// baud rate
11077
config.baudRate_Bps = cfg->baud_rate;
11178

11279
// data bits
@@ -240,8 +207,9 @@ static int uart_putc(struct rt_serial_device *serial, char c)
240207
return 1;
241208
}
242209

243-
volatile LPUART_Type *earlycon_base = LPUART1;
244-
const size_t earlycon_size = 4096; // sizeof(LPUART_Type);
210+
#if USING_EARLY_CONSOLE
211+
LPUART_Type *earlycon_base = LPUART1;
212+
const size_t earlycon_size = 4096;
245213

246214
void rt_hw_earlycon_ioremap(void)
247215
{
@@ -282,6 +250,7 @@ void rt_hw_earlycon_print_hex(const char *str, rt_base_t hex)
282250
rt_hw_earlycon_putc('\r');
283251
rt_hw_earlycon_putc('\n');
284252
}
253+
#endif
285254

286255
void rt_hw_console_putc(char c)
287256
{
@@ -352,7 +321,8 @@ int rt_hw_uart_init(void)
352321
hw_uart_devices[i]->serial.ops = &_uart_ops;
353322
hw_uart_devices[i]->serial.config = config;
354323
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);
324+
// hw_uart_devices[i]->uart_base = rt_ioremap((void *)hw_uart_devices[i]->uart_instance, 0x1000);
325+
hw_uart_devices[i]->uart_base = rt_ioremap_early((void *)hw_uart_devices[i]->uart_instance, 0x1000);
356326

357327
rt_hw_serial_register(&hw_uart_devices[i]->serial, hw_uart_devices[i]->device_name,
358328
RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX, hw_uart_devices[i]);
@@ -361,4 +331,3 @@ int rt_hw_uart_init(void)
361331

362332
return 0;
363333
}
364-
// INIT_BOARD_EXPORT(rt_hw_uart_init);

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,23 @@
1717

1818
int rt_hw_uart_init(void);
1919

20+
#ifdef BSP_USING_EARLY_CONSOLE
21+
#define USING_EARLY_CONSOLE 1
22+
#else
23+
#define USING_EARLY_CONSOLE 0
24+
#endif
25+
26+
#if USING_EARLY_CONSOLE
2027
void rt_hw_earlycon_ioremap(void);
2128
void rt_hw_earlycon_putc(char c);
2229
void rt_hw_earlycon_puts(const char *str);
2330
void rt_hw_earlycon_print_hex(const char *str, rt_base_t hex);
31+
#else
32+
static inline void rt_hw_earlycon_ioremap(void) {}
33+
static inline void rt_hw_earlycon_putc(char) {}
34+
static inline void rt_hw_earlycon_puts(const char *) {}
35+
static inline void rt_hw_earlycon_print_hex(const char *, rt_base_t) {}
36+
#endif
2437

2538
void rt_hw_console_putc(char c);
2639
void rt_hw_console_output(const char *str);

bsp/nxp/imx/imx91/rtconfig.h

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@
7272

7373
/* end of rt_strnlen options */
7474
/* end of klibc options */
75-
#define RT_NAME_MAX 8
75+
#define RT_NAME_MAX 16
7676
#define RT_CPUS_NR 1
77-
#define RT_ALIGN_SIZE 8
77+
#define RT_ALIGN_SIZE 16
7878
#define RT_THREAD_PRIORITY_32
7979
#define RT_THREAD_PRIORITY_MAX 32
8080
#define RT_TICK_PER_SECOND 1000
@@ -83,10 +83,10 @@
8383
#define RT_HOOK_USING_FUNC_PTR
8484
#define RT_USING_IDLE_HOOK
8585
#define RT_IDLE_HOOK_LIST_SIZE 4
86-
#define IDLE_THREAD_STACK_SIZE 1024
86+
#define IDLE_THREAD_STACK_SIZE 8192
8787
#define RT_USING_TIMER_SOFT
8888
#define RT_TIMER_THREAD_PRIO 4
89-
#define RT_TIMER_THREAD_STACK_SIZE 2048
89+
#define RT_TIMER_THREAD_STACK_SIZE 8192
9090

9191
/* kservice options */
9292

@@ -125,11 +125,11 @@
125125

126126
#define ARCH_TEXT_OFFSET 0x100000
127127
#define ARCH_RAM_OFFSET 0x80000000
128-
#define ARCH_SECONDARY_CPU_STACK_SIZE 16384
128+
#define ARCH_SECONDARY_CPU_STACK_SIZE 4096
129129
#define ARCH_HAVE_EFFICIENT_UNALIGNED_ACCESS
130130
#define ARCH_USING_GENERIC_CPUID
131-
#define ARCH_HEAP_SIZE 0x4000000
132-
#define ARCH_INIT_PAGE_SIZE 0x200000
131+
#define ARCH_HEAP_SIZE 0x2000000
132+
#define ARCH_INIT_PAGE_SIZE 0x8000000
133133
/* end of AArch64 Architecture Configuration */
134134
#define ARCH_CPU_64BIT
135135
#define RT_USING_CACHE
@@ -159,7 +159,7 @@
159159
#define FINSH_USING_MSH
160160
#define FINSH_THREAD_NAME "tshell"
161161
#define FINSH_THREAD_PRIORITY 20
162-
#define FINSH_THREAD_STACK_SIZE 4096
162+
#define FINSH_THREAD_STACK_SIZE 8092
163163
#define FINSH_USING_HISTORY
164164
#define FINSH_HISTORY_LINES 5
165165
#define FINSH_USING_SYMTAB
@@ -461,6 +461,7 @@
461461
#define BSP_USING_UART1
462462
#define BSP_USING_GIC
463463
#define BSP_USING_GICV3
464+
#define KERNEL_ASPACE_START 0x80100000
464465
/* end of Hardware Drivers Config */
465466

466467
#endif

bsp/nxp/imx/imx91/rtconfig.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,13 @@
3939
OBJCPY = PREFIX + 'objcopy'
4040

4141
DEVICE = ' -march=armv8-a -mtune=cortex-a55'
42+
DEVICE += ' -fno-omit-frame-pointer -ffunction-sections -fdata-sections'
4243
CPPFLAGS = ' -E -P -x assembler-with-cpp'
43-
CFLAGS = DEVICE + ' -Wall -Wno-cpp -D_POSIX_SOURCE'
44+
CFLAGS = DEVICE + ' -Wall -Wno-cpp'
45+
CFLAGS += ' -mstrict-align' # disable unaligned access
46+
CFLAGS += ' -Dmemcmp=rt_memcmp -Dstrcmp=rt_strcmp -Dstrcpy=rt_strcpy -Dstrlen=rt_strlen' # use rtthread string operations
4447
AFLAGS = ' -c' + DEVICE + ' -x assembler-with-cpp -D__ASSEMBLY__'
45-
LINK_SCRIPT = 'link.lds'
46-
LFLAGS = DEVICE + ' -Wl,--gc-sections,-Map=rtthread.map,-cref,-u,system_vectors'+\
47-
' -T %s' % LINK_SCRIPT
48+
LFLAGS = DEVICE + ' -Wl,--gc-sections,-Map=rtthread.map,-cref,-u,system_vectors -T link.lds'
4849

4950
CPATH = ''
5051
LPATH = ''

0 commit comments

Comments
 (0)