soc_boot.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * Copyright (c) 2021 Actions Semiconductor Co., Ltd
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. /**
  7. * @file
  8. * @brief Actions LARK family boot related infomation public interfaces.
  9. */
  10. #ifndef __SOC_BOOT_H
  11. #define __SOC_BOOT_H
  12. /* The macro to define the mapping address of SPI1 cache for PSRAM which configured by bootloader stage */
  13. #define SOC_BOOT_PSRAM_MAPPING_ADDRESS (0x18000000)
  14. /* The total size of ROM data that range from TEXT to RODATA sections */
  15. extern uint32_t z_rom_data_size;
  16. #define SOC_BOOT_FIRMWARE_VERSION_OFFSET (0x2e8) /* The offset of firmware version table within system parameter paritition */
  17. /*!
  18. * struct boot_info_t
  19. * @brief The boot infomation that transfer from bootloader to system.
  20. */
  21. typedef struct {
  22. uint32_t mbrec_phy_addr; /* The physical address of MBREC that current system running */
  23. uint32_t param_phy_addr; /* The physical address of PARAM that current system using */
  24. uint32_t system_phy_addr; /* The physical address of SYSTEM that current using */
  25. uint32_t reboot_reason; /* Reboot reason */
  26. uint32_t nand_id_offs; /* nand id table offset */
  27. uint32_t nand_id_len; /* nand id table length */
  28. uint32_t watchdog_reboot : 1; /* The reboot event that occured from bootrom watchdog expired */
  29. uint32_t is_mirror : 1; /* The indicator of launching system is a mirror partition */
  30. uint32_t bit_res : 30; /* The indicator of launching system is a mirror partition */
  31. uint32_t reserved[3];
  32. uint32_t nor_offset; /*cur code mapping off nor offset*/
  33. uint32_t code_len; // code in psram len(nand boot/emmc boot use)
  34. uint32_t reserved0[1];
  35. uint32_t dvfs;
  36. uint32_t reserved1[2];
  37. } boot_info_t;
  38. #define IMAGE_TLV_KEYHASH 0x01 /* hash of the public key */
  39. #define IMAGE_TLV_PUBKEY 0x02 /* public key */
  40. #define IMAGE_TLV_SHA256 0x04 /* SHA256 of image hdr and body */
  41. #define IMAGE_TLV_RSA2048_PSS 0x08 /* RSA2048 of hash output */
  42. #define IMAGE_MAGIC0 0x48544341
  43. #define IMAGE_MAGIC1 0x41435448
  44. typedef struct image_head {
  45. uint32_t ih_magic0;
  46. uint32_t ih_magic1; //
  47. uint32_t ih_load_addr; /*load addr, include header*/
  48. uint8_t ih_name[8]; //
  49. uint32_t ih_entry;
  50. uint32_t ih_img_size;
  51. uint32_t ih_img_chksum; /*if not sign, use check sum��ih_img_size not include header */
  52. uint32_t ih_hdr_chksum; /* include header. */
  53. uint16_t ih_hdr_size; /* Size of image header (bytes). */
  54. uint16_t ih_ptlv_size; /* Size of protected TLV area (bytes). */
  55. uint16_t ih_tlv_size; /*tlv size*/
  56. uint16_t ih_version;
  57. uint32_t ih_flags;
  58. uint8_t ih_ext_ictype[7];
  59. uint8_t ih_storage_type; // mbrec
  60. }image_head_t;
  61. /* @brief The function to get the address of current partition table */
  62. uint32_t soc_boot_get_part_tbl_addr(void);
  63. /* @brief The function to get the address of current firmware version */
  64. uint32_t soc_boot_get_fw_ver_addr(void);
  65. /* @brief The function to get the current boot infomation */
  66. const boot_info_t *soc_boot_get_info(void);
  67. /* @brief The function to get the reboot reason */
  68. u32_t soc_boot_get_reboot_reason(void);
  69. /* @brief The function to get the indicator of watchdog reboot */
  70. bool soc_boot_get_watchdog_is_reboot(void);
  71. /* @brief The function to get the address of nand id table */
  72. uint32_t soc_boot_get_nandid_tbl_addr(void);
  73. #define BOOT_FLASH_ID_NOR 0
  74. #define BOOT_FLASH_ID_EXTNOR 1
  75. #define BOOT_FLASH_ID_NAND 2
  76. /* @brief run app
  77. mirror_id: defualt 0 is boot app, if have A&B app, 0 is A, 1 is B
  78. flashid: 0 is nor, 1 is ext nor
  79. */
  80. int boot_to_app(int mirror_id, int flashid);
  81. /* @brief boot from ext nor
  82. */
  83. int boot_ext_nor(uint32_t offset, int enable_crc, uint32_t head_len);
  84. /* @brief boot from nor
  85. */
  86. int boot_nor(uint32_t offset, int enable_crc, uint32_t head_len);
  87. /* @brief boot from nand
  88. */
  89. int boot_nand(uint32_t offset, uint32_t head_len);
  90. /* @brief check app by signature verification
  91. */
  92. int image_security_data_check(image_head_t *ih_app);
  93. #endif