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