1 /* SPDX-License-Identifier: GPL-2.0+ */ 2 /* 3 * (C) Copyright 2018 Rockchip Electronics Co., Ltd 4 * 5 */ 6 7 #ifndef __RK_ATAGS_H_ 8 #define __RK_ATAGS_H_ 9 10 /* Tag magic */ 11 #define ATAG_CORE 0x54410001 12 #define ATAG_NONE 0x00000000 13 14 #define ATAG_SERIAL 0x54410050 15 #define ATAG_BOOTDEV 0x54410051 16 #define ATAG_DDR_MEM 0x54410052 17 #define ATAG_TOS_MEM 0x54410053 18 #define ATAG_RAM_PARTITION 0x54410054 19 #define ATAG_ATF_MEM 0x54410055 20 #define ATAG_PUB_KEY 0x54410056 21 #define ATAG_SOC_INFO 0x54410057 22 #define ATAG_BOOT1_PARAM 0x54410058 23 #define ATAG_PSTORE 0x54410059 24 #define ATAG_FWVER 0x5441005a 25 #define ATAG_MAX 0x544100ff 26 27 /* Tag size and offset */ 28 #ifndef ATAGS_SIZE 29 #define ATAGS_SIZE (0x2000) /* 8K */ 30 #endif 31 #ifndef ATAGS_OFFSET 32 #define ATAGS_OFFSET (0x200000 - ATAGS_SIZE)/* [2M-8K, 2M] */ 33 #endif 34 35 /* Tag sdram position!! */ 36 #define ATAGS_PHYS_BASE (CONFIG_SYS_SDRAM_BASE + ATAGS_OFFSET) 37 38 #ifndef ATAGS_PHYS_BASE 39 "ERROR: ATAGS_PHYS_BASE is not defined!!" 40 #endif 41 42 /* tag_bootdev.devtype */ 43 #define BOOT_TYPE_UNKNOWN 0 44 #define BOOT_TYPE_NAND (1 << 0) 45 #define BOOT_TYPE_EMMC (1 << 1) 46 #define BOOT_TYPE_SD0 (1 << 2) 47 #define BOOT_TYPE_SD1 (1 << 3) 48 #define BOOT_TYPE_SPI_NOR (1 << 4) 49 #define BOOT_TYPE_SPI_NAND (1 << 5) 50 #define BOOT_TYPE_RAM (1 << 6) 51 #define BOOT_TYPE_MTD_BLK_NAND (1 << 7) 52 #define BOOT_TYPE_MTD_BLK_SPI_NAND (1 << 8) 53 #define BOOT_TYPE_MTD_BLK_SPI_NOR (1 << 9) 54 #define BOOT_TYPE_SATA (1 << 10) 55 #define BOOT_TYPE_PCIE (1 << 11) 56 #define BOOT_TYPE_UFS (1 << 12) 57 58 /* define sd card function */ 59 #define SD_UNKNOWN_CARD 0 60 #define SD_UPDATE_CARD 1 61 62 /* tag_serial.m_mode */ 63 #define SERIAL_M_MODE_M0 0x0 64 #define SERIAL_M_MODE_M1 0x1 65 #define SERIAL_M_MODE_M2 0x2 66 67 /* tag_soc_info.flags */ 68 #define SOC_FLAGS_TDBT (1 << 0) 69 70 /* pub key programmed magic */ 71 #define PUBKEY_FUSE_PROGRAMMED 0x4B415352 72 73 /* 74 * boot1p.param[2] for ATF/OPTEE. The fields: 75 * 76 * [31:12]: reserved 77 * [4:0]: boot cpu hwid. 78 */ 79 #define B1P2_BOOT_CPU_MASK 0x00000fff 80 81 /* tag_ddr_mem.flags */ 82 #define DDR_MEM_FLG_EXT_TOP 1 83 84 /* tag_fwver.ver[fwid][] */ 85 #define FWVER_LEN 36 86 87 enum fwid { 88 FW_DDR, 89 FW_SPL, 90 FW_ATF, 91 FW_TEE, 92 FW_MAX, 93 }; 94 95 struct tag_serial { 96 u32 version; 97 u32 enable; 98 u64 addr; 99 u32 baudrate; 100 u32 m_mode; 101 u32 id; 102 u32 reserved[2]; 103 u32 hash; 104 } __packed; 105 106 struct tag_bootdev { 107 u32 version; 108 u32 devtype; 109 u32 devnum; 110 u32 mode; 111 u32 sdupdate; 112 u32 reserved[6]; 113 u32 hash; 114 } __packed; 115 116 struct tag_ddr_mem { 117 u32 count; 118 u32 version; 119 u64 bank[20]; 120 u32 flags; 121 u32 data[2]; 122 u32 hash; 123 } __packed; 124 125 struct tag_tos_mem { 126 u32 version; 127 struct { 128 char name[8]; 129 u64 phy_addr; 130 u32 size; 131 u32 flags; 132 } tee_mem; 133 134 struct { 135 char name[8]; 136 u64 phy_addr; 137 u32 size; 138 u32 flags; 139 } drm_mem; 140 141 u64 reserved[7]; 142 u32 reserved1; 143 u32 hash; 144 } __packed; 145 146 struct tag_atf_mem { 147 u32 version; 148 u64 phy_addr; 149 u32 size; 150 u32 flags; 151 u32 reserved[2]; 152 u32 hash; 153 } __packed; 154 155 struct tag_pub_key { 156 u32 version; 157 u32 len; 158 u8 data[768]; /* u32 rsa_n[64], rsa_e[64], rsa_c[64] */ 159 u32 flag; 160 u32 reserved[5]; 161 u32 hash; 162 } __packed; 163 164 struct tag_ram_partition { 165 u32 version; 166 u32 count; 167 u32 reserved[4]; 168 169 struct { 170 char name[16]; 171 u64 start; 172 u64 size; 173 } part[6]; 174 175 u32 reserved1[3]; 176 u32 hash; 177 } __packed; 178 179 struct tag_soc_info { 180 u32 version; 181 u32 name; /* Hex: 0x3288, 0x3399... */ 182 u32 flags; 183 u32 reserved[6]; 184 u32 hash; 185 } __packed; 186 187 struct tag_boot1p { 188 u32 version; 189 u32 param[8]; 190 u32 reserved[4]; 191 u32 hash; 192 } __packed; 193 194 struct tag_pstore { 195 u32 version; 196 struct { 197 u32 addr; 198 u32 size; 199 } buf[16]; 200 u32 hash; 201 } __packed; 202 203 struct tag_fwver { 204 u32 version; 205 char ver[8][FWVER_LEN]; 206 u32 hash; 207 } __packed; 208 209 struct tag_core { 210 u32 flags; 211 u32 pagesize; 212 u32 rootdev; 213 } __packed; 214 215 struct tag_header { 216 u32 size; /* bytes = size * 4 */ 217 u32 magic; 218 } __packed; 219 220 /* Must be 4 bytes align */ 221 struct tag { 222 struct tag_header hdr; 223 union { 224 struct tag_core core; 225 struct tag_serial serial; 226 struct tag_bootdev bootdev; 227 struct tag_ddr_mem ddr_mem; 228 struct tag_tos_mem tos_mem; 229 struct tag_ram_partition ram_part; 230 struct tag_atf_mem atf_mem; 231 struct tag_pub_key pub_key; 232 struct tag_soc_info soc; 233 struct tag_boot1p boot1p; 234 struct tag_pstore pstore; 235 struct tag_fwver fwver; 236 } u; 237 } __aligned(4); 238 239 #define tag_next(t) ((struct tag *)((u32 *)(t) + (t)->hdr.size)) 240 #define tag_size(type) ((sizeof(struct tag_header) + sizeof(struct type)) >> 2) 241 #define for_each_tag(t, base) \ 242 for (t = base; t->hdr.size; t = tag_next(t)) 243 /* 244 * Destroy atags 245 * 246 * first pre-loader who creates atags must call it before atags_set_tag(), 247 * because atags_set_tag() may detect last valid and existence ATAG_CORE 248 * tag in memory and lead a wrong setup, that is not what we expect. 249 */ 250 void atags_destroy(void); 251 252 /* 253 * atags_set_tag - set tag data 254 * 255 * @magic: tag magic, i.e. ATAG_SERIAL, ATAG_BOOTDEV, .... 256 * @tagdata: core data of struct, i.e. struct tag_serial/tag_bootdev ... 257 * 258 * return: 0 on success, others failed. 259 */ 260 int atags_set_tag(u32 magic, void *tagdata); 261 262 /* 263 * atags_get_tag - get tag by tag magic 264 * 265 * @magic: tag magic, i.e. ATAG_SERIAL, ATAG_BOOTDEV, ... 266 * 267 * return: NULL on failed, otherwise return the tag that we want. 268 */ 269 struct tag *atags_get_tag(u32 magic); 270 271 /* 272 * atags_is_available - check if atags is available, used for second or 273 * later pre-loaders. 274 * 275 * return: 0 is not available, otherwise available. 276 */ 277 int atags_is_available(void); 278 279 /* 280 * atags_overflow - check if atags is overflow 281 * 282 * return: 0 if not overflow, otherwise overflow. 283 */ 284 int atags_overflow(struct tag *t); 285 286 /* 287 * atags_bad_magic - check if atags magic is invalid. 288 * 289 * return: 1 if invalid, otherwise valid. 290 */ 291 int atags_bad_magic(u32 magic); 292 293 /* 294 * atags_set_shared_fwver - set fwver tag. 295 * 296 * return: 0 on success, otherwise failed. 297 */ 298 int atags_set_shared_fwver(u32 fwid, char *ver); 299 300 #ifdef CONFIG_SPL_BUILD 301 /* 302 * get_bootdev_by_brom_bootsource 303 * 304 * @magic: void 305 * 306 * return: boootdev, else 0 fail. 307 */ 308 int get_bootdev_by_brom_bootsource(void); 309 310 /* 311 * atags_set_bootdev_by_brom_bootsource 312 * 313 * @magic: void 314 * 315 * return: 0 success, others fail. 316 */ 317 int atags_set_bootdev_by_brom_bootsource(void); 318 319 /* 320 * get_bootdev_by_spl_bootdevice 321 * 322 * @bootdevice 323 * 324 * return: boootdev, else -ENODEV fail. 325 */ 326 int get_bootdev_by_spl_bootdevice(int bootdevice); 327 328 /* 329 * atags_set_bootdev_by_spl_bootdevice 330 * 331 * @bootdevice 332 * 333 * return: 0 success, others fail. 334 */ 335 int atags_set_bootdev_by_spl_bootdevice(int bootdevice); 336 337 /* 338 * atags_set_pub_key 339 * 340 * @data: public key data 341 * @len: public key len 342 * @flag: indicate the pulic key hash is burned or not 343 * 344 * return: 0 success, others fail. 345 */ 346 int atags_set_pub_key(void *data, int len, int flag); 347 #endif 348 349 #if CONFIG_IS_ENABLED(TINY_FRAMEWORK) && \ 350 !CONFIG_IS_ENABLED(LIBGENERIC_SUPPORT) && \ 351 !CONFIG_IS_ENABLED(USE_ARCH_MEMSET) 352 void *memset(void *s, int c, size_t count); 353 #endif 354 355 #if CONFIG_IS_ENABLED(TINY_FRAMEWORK) && \ 356 !CONFIG_IS_ENABLED(LIBGENERIC_SUPPORT) && \ 357 !CONFIG_IS_ENABLED(USE_ARCH_MEMCPY) 358 void *memcpy(void *dest, const void *src, size_t count); 359 #endif 360 361 #endif 362