board.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*
  2. * Copyright (c) 2006-2024, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2024-04-15 liYony the first version
  9. */
  10. #include <mmu.h>
  11. #include <board.h>
  12. #include <mm_aspace.h>
  13. #include <mm_page.h>
  14. #include <drv_uart.h>
  15. #include <gtimer.h>
  16. #include <setup.h>
  17. extern size_t MMUTable[];
  18. #ifndef RT_USING_OFW
  19. void idle_wfi(void)
  20. {
  21. asm volatile("wfi");
  22. }
  23. #ifdef RT_USING_SMART
  24. struct mem_desc platform_mem_desc[] = {
  25. {KERNEL_VADDR_START, KERNEL_VADDR_START + 0x0FFFFFFF, (rt_size_t)ARCH_MAP_FAILED, NORMAL_MEM},
  26. };
  27. #else
  28. struct mem_desc platform_mem_desc[] =
  29. {
  30. {0x80200000, 0x90200000 - 1, 0x80200000, NORMAL_MEM}, /* memory size 256M */
  31. {0x01000000, 0x80000000 - 1, 0x01000000, DEVICE_MEM},
  32. };
  33. #endif
  34. const rt_uint32_t platform_mem_desc_size = sizeof(platform_mem_desc) / sizeof(platform_mem_desc[0]);
  35. void rt_hw_board_init(void)
  36. {
  37. #ifdef RT_USING_SMART
  38. rt_hw_mmu_map_init(&rt_kernel_space, (void *)0xfffffffff0000000, 0x10000000, MMUTable, PV_OFFSET);
  39. #else
  40. rt_hw_mmu_map_init(&rt_kernel_space, (void *)0xffffd0000000, 0x10000000, MMUTable, 0);
  41. #endif
  42. rt_region_t init_page_region;
  43. init_page_region.start = PAGE_START;
  44. init_page_region.end = PAGE_END;
  45. rt_page_init(init_page_region);
  46. rt_hw_mmu_setup(&rt_kernel_space, platform_mem_desc, platform_mem_desc_size);
  47. #ifdef RT_USING_HEAP
  48. /* initialize system heap */
  49. rt_system_heap_init((void *)HEAP_BEGIN, (void *)HEAP_END);
  50. #endif
  51. /* initialize hardware interrupt */
  52. rt_hw_interrupt_init();
  53. /* initialize uart */
  54. rt_hw_uart_init();
  55. /* initialize timer for os tick */
  56. rt_hw_gtimer_init();
  57. rt_thread_idle_sethook(idle_wfi);
  58. #if defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE)
  59. /* set console device */
  60. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  61. #endif
  62. rt_kprintf("heap: [0x%08x - 0x%08x]\n", HEAP_BEGIN, HEAP_END);
  63. #ifdef RT_USING_COMPONENTS_INIT
  64. rt_components_board_init();
  65. #endif
  66. }
  67. #else
  68. void rt_hw_board_init(void)
  69. {
  70. rt_hw_common_setup();
  71. }
  72. /*
  73. * FIXME: This is a temporary workaround.
  74. * When aarch bsp enables the device tree, the current u-boot will
  75. * pass in bootargs, which contains "root=/dev/mmcblk0p2 rootwait rw",
  76. * which means that the kernel is required to wait until the rootfs
  77. * in /dev/mmcblk0p2 loaded successfully. However, the current aarch64 bsp
  78. * default does not implement sdmmc device mounting, causing the kernel file
  79. * system mounting module (rootfs_mnt_init() of components/drivers/core/mnt.c)
  80. * to enter an infinite loop waiting.
  81. * Solution: At present, we do not plan to modify the startup parameters
  82. * of u-boot. The temporary solution adopted is to create a pseudo
  83. * /dev/mmcblk0p2 device during the board initialization process, and
  84. * then cancel the pseudo device after mnt is completed. This allows the
  85. * kernel boot to be completed successfully.
  86. */
  87. static struct rt_device *pseudo_mmcblk;
  88. static int pseudo_mmcblk_setup(void)
  89. {
  90. pseudo_mmcblk = rt_calloc(1, sizeof(*pseudo_mmcblk));
  91. RT_ASSERT(pseudo_mmcblk != RT_NULL);
  92. pseudo_mmcblk->type = RT_Device_Class_Graphic;
  93. return (int)rt_device_register(pseudo_mmcblk, "/dev/mmcblk0p2", RT_DEVICE_FLAG_DEACTIVATE);
  94. }
  95. INIT_BOARD_EXPORT(pseudo_mmcblk_setup);
  96. static int pseudo_mmcblk_remove(void)
  97. {
  98. if (pseudo_mmcblk)
  99. {
  100. return (int)rt_device_unregister(pseudo_mmcblk);
  101. }
  102. return 0;
  103. }
  104. INIT_FS_EXPORT(pseudo_mmcblk_remove);
  105. #endif /* RT_USING_OFW */
  106. static rt_ubase_t pinmux_base = RT_NULL;
  107. rt_ubase_t pinmux_base_ioremap(void)
  108. {
  109. if (pinmux_base == RT_NULL)
  110. {
  111. pinmux_base = (rt_size_t)rt_ioremap((void*)0x03001000, 0x1000);
  112. }
  113. return pinmux_base;
  114. }