1 /* 2 * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #ifndef __HAL_LOCATION_H__ 16 #define __HAL_LOCATION_H__ 17 18 #ifdef __cplusplus 19 extern "C" { 20 #endif 21 22 #define HAL_SEC_CONCAT_2(a, b) a.b 23 #define HAL_SEC_CONCAT_3(a, b, c) a.b.c 24 25 #define HAL_SEC_TO_STR_A(s) #s 26 #define HAL_SEC_TO_STR(s) HAL_SEC_TO_STR_A(s) 27 28 #define HAL_SEC_NAME_ATTR(s) __attribute__((section(s))) 29 30 #define HAL_SEC_DEF(section, name) HAL_SEC_NAME_ATTR(HAL_SEC_TO_STR(HAL_SEC_CONCAT_2(section, name))) name 31 #ifdef __COUNTER__ 32 #define HAL_SEC_LOC(section) HAL_SEC_NAME_ATTR(HAL_SEC_TO_STR(HAL_SEC_CONCAT_3(section, __LINE__, __COUNTER__))) 33 #else 34 #define HAL_SEC_LOC(section) HAL_SEC_NAME_ATTR(HAL_SEC_TO_STR(HAL_SEC_CONCAT_2(section, __LINE__))) 35 #endif 36 37 #if defined(__GNUC__) && !((defined(ROM_BUILD) && !defined(ROM_IN_FLASH) && !defined(CP_BUILD)) || defined(PROGRAMMER)) && !defined(NANDFLASH_BUILD) 38 39 #define BOOT_TEXT_SRAM_LOC HAL_SEC_LOC(.boot_text_sram) 40 #define BOOT_TEXT_SRAM_DEF(n) HAL_SEC_DEF(.boot_text_sram, n) 41 #define BOOT_TEXT_FLASH_LOC HAL_SEC_LOC(.boot_text_flash) 42 #define BOOT_TEXT_FLASH_DEF(n) HAL_SEC_DEF(.boot_text_flash, n) 43 #define BOOT_RODATA_SRAM_LOC HAL_SEC_LOC(.boot_rodata_sram) 44 #define BOOT_RODATA_SRAM_DEF(n) HAL_SEC_DEF(.boot_rodata_sram, n) 45 #define BOOT_RODATA_FLASH_LOC HAL_SEC_LOC(.boot_rodata_flash) 46 #define BOOT_RODATA_FLASH_DEF(n) HAL_SEC_DEF(.boot_rodata_flash, n) 47 #define BOOT_DATA_LOC HAL_SEC_LOC(.boot_data) 48 #define BOOT_DATA_DEF(n) HAL_SEC_DEF(.boot_data, n) 49 #ifdef __ARMCC_VERSION 50 #define BOOT_BSS_LOC HAL_SEC_LOC(.bss.boot_bss) 51 #define BOOT_BSS_DEF(n) HAL_SEC_DEF(.bss.boot_bss, n) 52 #else 53 #define BOOT_BSS_LOC HAL_SEC_LOC(.boot_bss) 54 #define BOOT_BSS_DEF(n) HAL_SEC_DEF(.boot_bss, n) 55 #endif 56 57 #define SRAM_TEXT_LOC HAL_SEC_LOC(.sram_text) 58 #define SRAM_TEXT_DEF(n) HAL_SEC_DEF(.sram_text, n) 59 #define SRAM_DATA_LOC HAL_SEC_LOC(.sram_data) 60 #define SRAM_DATA_DEF(n) HAL_SEC_DEF(.sram_data, n) 61 #define SRAM_STACK_LOC ALIGNED(8) HAL_SEC_LOC(.sram_data) 62 #define SRAM_STACK_DEF(n) ALIGNED(8) HAL_SEC_LOC(.sram_data, n) 63 #ifdef __ARMCC_VERSION 64 #define SRAM_BSS_LOC HAL_SEC_LOC(.bss.sram_bss) 65 #define SRAM_BSS_DEF(n) HAL_SEC_DEF(.bss.sram_bss, n) 66 #else 67 #define SRAM_BSS_LOC HAL_SEC_LOC(.sram_bss) 68 #define SRAM_BSS_DEF(n) HAL_SEC_DEF(.sram_bss, n) 69 #endif 70 71 #define VRAM_BSS_LOC HAL_SEC_LOC(.vram_bss) 72 #define VRAM_BSS_DEF(n) HAL_SEC_DEF(.vram_bss, n) 73 74 #define FRAM_TEXT_LOC HAL_SEC_LOC(.fast_text_sram) 75 #define FRAM_TEXT_DEF(n) HAL_SEC_DEF(.fast_text_sram, n) 76 77 #define CP_TEXT_SRAM_LOC HAL_SEC_LOC(.cp_text_sram) 78 #define CP_TEXT_SRAM_DEF(n) HAL_SEC_DEF(.cp_text_sram, n) 79 #define CP_DATA_LOC HAL_SEC_LOC(.cp_data) 80 #define CP_DATA_DEF(n) HAL_SEC_DEF(.cp_data, n) 81 #ifdef __ARMCC_VERSION 82 #define CP_BSS_LOC HAL_SEC_LOC(.bss.cp_bss) 83 #define CP_BSS_DEF(n) HAL_SEC_DEF(.bss.cp_bss, n) 84 #else 85 #define CP_BSS_LOC HAL_SEC_LOC(.cp_bss) 86 #define CP_BSS_DEF(n) HAL_SEC_DEF(.cp_bss, n) 87 #endif 88 89 #define FLASH_TEXT_LOC HAL_SEC_LOC(.flash_text) 90 #define FLASH_TEXT_DEF(n) HAL_SEC_DEF(.flash_text, n) 91 #define FLASH_RODATA_LOC HAL_SEC_LOC(.flash_rodata) 92 #define FLASH_RODATA_DEF(n) HAL_SEC_DEF(.flash_rodata, n) 93 94 #define REBOOT_CUSTOM_PARAM_LOC HAL_SEC_LOC(.reboot_custom_param) 95 #define REBOOT_CUSTOM_PARAM_DEF HAL_SEC_DEF(.reboot_custom_param) 96 97 #else 98 99 #if defined(__GNUC__) && defined(ROM_SRAM_TEXT_SIMU) 100 #define BOOT_TEXT_SRAM_LOC HAL_SEC_LOC(.rom_ramx) 101 #define BOOT_TEXT_SRAM_DEF(n) HAL_SEC_DEF(.rom_ramx, n) 102 #else 103 #define BOOT_TEXT_SRAM_LOC 104 #define BOOT_TEXT_SRAM_DEF(n) n 105 #endif 106 #if defined(__GNUC__) && defined(PROGRAMMER_INFLASH) 107 #define BOOT_TEXT_FLASH_LOC HAL_SEC_LOC(.boot_text_flash) 108 #define BOOT_TEXT_FLASH_DEF(n) HAL_SEC_DEF(.boot_text_flash, n) 109 #define BOOT_RODATA_FLASH_LOC HAL_SEC_LOC(.boot_rodata_flash) 110 #define BOOT_RODATA_FLASH_DEF(n) HAL_SEC_DEF(.boot_rodata_flash, n) 111 #else 112 #define BOOT_TEXT_FLASH_LOC 113 #define BOOT_TEXT_FLASH_DEF(n) n 114 #define BOOT_RODATA_FLASH_LOC 115 #define BOOT_RODATA_FLASH_DEF(n) n 116 #endif 117 #if defined(__GNUC__) && defined(ROM_SRAM_TEXT_SIMU) 118 #define BOOT_RODATA_SRAM_LOC HAL_SEC_LOC(.data) 119 #define BOOT_RODATA_SRAM_DEF(n) HAL_SEC_DEF(.data, n) 120 #else 121 #define BOOT_RODATA_SRAM_LOC 122 #define BOOT_RODATA_SRAM_DEF(n) n 123 #endif 124 #define BOOT_DATA_LOC 125 #define BOOT_DATA_DEF(n) n 126 #define BOOT_BSS_LOC 127 #define BOOT_BSS_DEF(n) n 128 129 #if defined(__GNUC__) && defined(ROM_SRAM_TEXT_SIMU) 130 #define SRAM_TEXT_LOC HAL_SEC_LOC(.rom_ramx) 131 #define SRAM_TEXT_DEF(n) HAL_SEC_DEF(.rom_ramx, n) 132 #else 133 #define SRAM_TEXT_LOC 134 #define SRAM_TEXT_DEF(n) n 135 #endif 136 #define SRAM_DATA_LOC 137 #define SRAM_DATA_DEF(n) n 138 #define SRAM_STACK_LOC 139 #define SRAM_STACK_DEF(n) n 140 #define SRAM_BSS_LOC 141 #define SRAM_BSS_DEF(n) n 142 143 #define FRAM_TEXT_LOC 144 #define FRAM_TEXT_DEF(n) n 145 146 #define CP_TEXT_SRAM_LOC 147 #define CP_TEXT_SRAM_DEF(n) n 148 #define CP_DATA_LOC 149 #define CP_DATA_DEF(n) n 150 #define CP_BSS_LOC 151 #define CP_BSS_DEF(n) n 152 153 #define FLASH_TEXT_LOC 154 #define FLASH_TEXT_DEF(n) n 155 #define FLASH_RODATA_LOC 156 #define FLASH_RODATA_DEF(n) n 157 158 #define REBOOT_CUSTOM_PARAM_LOC 159 #define REBOOT_CUSTOM_PARAM_DEF(n) n 160 161 #endif // !__GNUC__ || ROM_BUILD || PROGRAMMER 162 163 #if defined(__GNUC__) && defined(__ARM_ARCH_ISA_ARM) && !defined(NUTTX_BUILD) 164 #define SYNC_FLAGS_LOC HAL_SEC_LOC(.sync_flags) 165 #define SYNC_FLAGS_DEF(n) HAL_SEC_DEF(.sync_flags, n) 166 #else 167 #define SYNC_FLAGS_LOC HAL_SEC_LOC(.sram_bss) 168 #define SYNC_FLAGS_DEF(n) HAL_SEC_DEF(.sram_bss, n) 169 #endif 170 171 #if defined(__ARM_ARCH_ISA_ARM) 172 #define PSRAMUHS_TEXT_LOC HAL_SEC_LOC(.psramuhs_text) 173 #define PSRAMUHS_TEXT_DEF(n) HAL_SEC_DEF(.psramuhs_text, n) 174 #else 175 #define PSRAMUHS_TEXT_LOC 176 #define PSRAMUHS_TEXT_DEF(n) n 177 #endif 178 179 #ifdef __cplusplus 180 } 181 #endif 182 183 #endif 184