board.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * Copyright (c) 2006-2025, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2025-08-10 Siwei Xu Add i.MX91 SDK
  9. * 2025-09-15 Siwei Xu Fix LPUART driver
  10. * 2025-10-08 Siwei Xu Fix MMU Enable issues
  11. */
  12. #include "board.h"
  13. #include "serial.h"
  14. #include "MIMX9131.h"
  15. #include <gtimer.h>
  16. #include <mm_aspace.h>
  17. #include <mm_page.h>
  18. #include <ioremap.h>
  19. #include <mmu.h>
  20. #include <limits.h>
  21. #define DRAM_MAP_START KERNEL_BOOT_ADDR
  22. #define DRAM_MAP_SIZE MB_SIZE(256)
  23. #define MEM_DESC(vaddr_start, size, paddr_start, attr) \
  24. vaddr_start, (vaddr_start + size - 1uL), paddr_start, attr
  25. extern volatile unsigned long MMUTable[];
  26. static struct mem_desc platform_mem_desc[] = {
  27. { MEM_DESC(DRAM_MAP_START, DRAM_MAP_SIZE, DRAM_MAP_START, NORMAL_MEM) }, // 0x8000_0000
  28. { MEM_DESC(LPUART1_BASE, LPUART1_SIZE, LPUART1_BASE, DEVICE_MEM) }, // 0x4438_0000
  29. { MEM_DESC(CCM_CTRL_BASE, CCM_CTRL_SIZE, CCM_CTRL_BASE, DEVICE_MEM) }, // 0x4445_8000
  30. { MEM_DESC(GIC_DISTRIBUTOR_BASE, GIC_DISTRIBUTOR_SIZE, GIC_DISTRIBUTOR_BASE, DEVICE_MEM) }, // 0x4800_0000
  31. { MEM_DESC(GIC_REDISTRIBUTOR_BASE, GIC_REDISTRIBUTOR_SIZE, GIC_REDISTRIBUTOR_BASE, DEVICE_MEM) }, // 0x4804_0000
  32. };
  33. static const rt_uint32_t platform_mem_desc_size = sizeof(platform_mem_desc) / sizeof(platform_mem_desc[0]);
  34. static rt_region_t init_page_region;
  35. static rt_base_t get_sctlr_el1()
  36. {
  37. rt_base_t sctlr = 0;
  38. __asm__ volatile("mrs %0, sctlr_el1" : "=r"(sctlr));
  39. return sctlr;
  40. }
  41. /**
  42. * This function will initialize hardware board
  43. */
  44. void rt_hw_board_init(void)
  45. {
  46. rt_hw_earlycon_ioremap();
  47. rt_hw_earlycon_print_hex("sctlr_el1: ", get_sctlr_el1());
  48. rt_hw_mmu_map_init(&rt_kernel_space, (void *)0x080000000000, 0x10000000, (size_t *)MMUTable, 0);
  49. init_page_region.start = BOARD_PAGE_START;
  50. init_page_region.end = BOARD_PAGE_END;
  51. rt_page_init(init_page_region);
  52. rt_hw_mmu_setup(&rt_kernel_space, platform_mem_desc, platform_mem_desc_size);
  53. #ifdef RT_USING_HEAP
  54. /* initialize system heap */
  55. rt_system_heap_init((void *)BOARD_HEAP_BEGIN, (void *)BOARD_HEAP_END);
  56. #endif
  57. /* initialize hardware interrupt */
  58. rt_hw_interrupt_init();
  59. /* initialize uart */
  60. rt_hw_uart_init();
  61. /* initialize timer for os tick */
  62. rt_hw_gtimer_init();
  63. rt_components_board_init();
  64. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  65. }