boot_start.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /* Copyright (C) 2018 RDA Technologies Limited and/or its affiliates("RDA").
  2. * All rights reserved.
  3. *
  4. * This software is supplied "AS IS" without any warranties.
  5. * RDA assumes no responsibility or liability for the use of the software,
  6. * conveys no license or title under any patent, copyright, or mask work
  7. * right to the product. RDA reserves the right to make changes in the
  8. * software without notification. RDA also make no representation or
  9. * warranty that such application will be suitable for the specified use
  10. * without further testing or modification.
  11. */
  12. #include <stdint.h>
  13. #include <machine/endian.h>
  14. #include "hal_config.h"
  15. #include "boot_config.h"
  16. #include "boot_platform.h"
  17. #include "boot_fdl.h"
  18. #include "hal_chip.h"
  19. #include "boot_debuguart.h"
  20. #include "boot_mem.h"
  21. #include "boot_entry.h"
  22. #include "cmsis_core.h"
  23. #include "boot_secure.h"
  24. #include "boot_spi_flash.h"
  25. #include "boot_vfs.h"
  26. #include "boot_mmu.h"
  27. #include "boot_timer.h"
  28. #include "boot_irq.h"
  29. #include "boot_bsl_cmd.h"
  30. #include "boot_pdl.h"
  31. #include "hal_adi_bus.h"
  32. #include "hal_spi_flash.h"
  33. #include "flash_block_device.h"
  34. #include "fupdate.h"
  35. #include "fs_mount.h"
  36. #include "osi_log.h"
  37. #include "osi_api.h"
  38. #include "drv_names.h"
  39. #include "calclib/simage.h"
  40. #include <sys/reent.h>
  41. #define PMU_BOOT_MODE_REG (hwp_pmicRtcAna->por_rst_monitor)
  42. #ifdef CONFIG_BOOT_UART1_PDL_ENABLE
  43. static void prvUart1Download(void)
  44. {
  45. bool download = false;
  46. uint32_t boot_mode_val = halAdiBusRead(&PMU_BOOT_MODE_REG);
  47. if (boot_mode_val == OSI_SHUTDOWN_BL_DOWNLOAD)
  48. {
  49. download = true;
  50. halAdiBusWrite(&PMU_BOOT_MODE_REG, 0);
  51. }
  52. uint32_t rom_flags = hwp_idleTimer->idle_res5;
  53. if (rom_flags == 0xdeadcafe)
  54. download = true;
  55. if (!download)
  56. return;
  57. OSI_LOGI(0x1000907a, "UART1 download, magic/0x%04x/0x%08x", boot_mode_val, rom_flags);
  58. fdlChannel_t *ch = fdlOpenUart(DRV_NAME_UART1, 115200, true);
  59. if (ch == NULL)
  60. {
  61. OSI_LOGE(0x1000907b, "Failed to open %4c", DRV_NAME_UART1);
  62. osiPanic();
  63. }
  64. if (!pdlDnldUimage(ch, BOOT_DOWNLOAD_UART1, CONFIG_NORFDL_IMAGE_START, CONFIG_NORFDL_IMAGE_SIZE, 20000))
  65. {
  66. OSI_LOGE(0x1000907c, "%4c PDL download failed", DRV_NAME_UART1);
  67. osiPanic();
  68. OSI_LOGI(0x1000907d, "%4c PDL download timeout", DRV_NAME_UART1);
  69. }
  70. //#endif
  71. }
  72. #endif
  73. void bootStart(uint32_t param)
  74. {
  75. OSI_CLEAR_SECTION(bss);
  76. halClockInit(HAL_CLOCK_INIT_BOOTLOADER);
  77. __FPU_Enable();
  78. _REENT_INIT_PTR_ZEROED(_impure_ptr);
  79. halAdiBusInit();
  80. bootResetPinEnable();
  81. #ifdef CONFIG_TRUSTZONE_SUPPORT
  82. if (bootIsFromPsmSleep())
  83. {
  84. simageHeader_t *header = (simageHeader_t *)CONFIG_APP_FLASH_ADDRESS;
  85. simageJumpEntry(header, OSI_SHUTDOWN_PSM_SLEEP); // never return
  86. }
  87. #endif
  88. bool trace_enable = false;
  89. #ifdef CONFIG_BOOT_LOG_ENABLED
  90. trace_enable = true;
  91. #endif
  92. bootTraceInit(trace_enable);
  93. extern unsigned __sram_heap_start[];
  94. extern unsigned __sram_heap_end[];
  95. unsigned sram_heap_size = OSI_PTR_DIFF(__sram_heap_end, __sram_heap_start);
  96. bootHeapInit((uint32_t *)__sram_heap_start, sram_heap_size,
  97. (uint32_t *)CONFIG_RAM_PHY_ADDRESS, CONFIG_RAM_SIZE);
  98. bootHeapDefaultExtRam();
  99. #ifdef CONFIG_BOOT_UART1_PDL_ENABLE
  100. prvUart1Download();
  101. #endif
  102. simageHeader_t *header = (simageHeader_t *)CONFIG_APP_FLASH_ADDRESS;
  103. simageJumpEntry(header, 0); // never return
  104. }