Peng Fan | 7b86cd4 | 2019-08-22 07:42:33 +0000 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
| 2 | /* |
| 3 | * Copyright 2018-2019 NXP |
| 4 | */ |
| 5 | |
| 6 | #ifndef __CONTAINER_HEADER_H_ |
| 7 | #define __CONTAINER_HEADER_H_ |
| 8 | |
| 9 | #include <linux/sizes.h> |
| 10 | #include <linux/types.h> |
| 11 | |
| 12 | #define IV_MAX_LEN 32 |
| 13 | #define HASH_MAX_LEN 64 |
| 14 | |
| 15 | #define CONTAINER_HDR_ALIGNMENT 0x400 |
| 16 | #define CONTAINER_HDR_EMMC_OFFSET 0 |
| 17 | #define CONTAINER_HDR_MMCSD_OFFSET SZ_32K |
| 18 | #define CONTAINER_HDR_QSPI_OFFSET SZ_4K |
| 19 | #define CONTAINER_HDR_NAND_OFFSET SZ_128M |
| 20 | |
Sean Anderson | d401e0b | 2023-10-14 16:47:43 -0400 | [diff] [blame] | 21 | #define CONTAINER_HDR_TAG 0x87 |
| 22 | #define CONTAINER_HDR_VERSION 0 |
| 23 | |
Peng Fan | 7b86cd4 | 2019-08-22 07:42:33 +0000 | [diff] [blame] | 24 | struct container_hdr { |
| 25 | u8 version; |
| 26 | u8 length_lsb; |
| 27 | u8 length_msb; |
| 28 | u8 tag; |
| 29 | u32 flags; |
| 30 | u16 sw_version; |
| 31 | u8 fuse_version; |
| 32 | u8 num_images; |
| 33 | u16 sig_blk_offset; |
| 34 | u16 reserved; |
| 35 | } __packed; |
| 36 | |
| 37 | struct boot_img_t { |
| 38 | u32 offset; |
| 39 | u32 size; |
| 40 | u64 dst; |
| 41 | u64 entry; |
| 42 | u32 hab_flags; |
| 43 | u32 meta; |
| 44 | u8 hash[HASH_MAX_LEN]; |
| 45 | u8 iv[IV_MAX_LEN]; |
| 46 | } __packed; |
| 47 | |
| 48 | struct signature_block_hdr { |
| 49 | u8 version; |
| 50 | u8 length_lsb; |
| 51 | u8 length_msb; |
| 52 | u8 tag; |
| 53 | u16 srk_table_offset; |
| 54 | u16 cert_offset; |
| 55 | u16 blob_offset; |
| 56 | u16 signature_offset; |
| 57 | u32 reserved; |
| 58 | } __packed; |
Clement Faure | 69f542c | 2021-03-25 17:30:34 +0800 | [diff] [blame] | 59 | |
| 60 | struct generate_key_blob_hdr { |
| 61 | u8 version; |
| 62 | u8 length_lsb; |
| 63 | u8 length_msb; |
| 64 | u8 tag; |
| 65 | u8 flags; |
| 66 | u8 size; |
| 67 | u8 algorithm; |
| 68 | u8 mode; |
| 69 | } __packed; |
Ye Li | 6f3858d | 2021-08-07 16:00:39 +0800 | [diff] [blame] | 70 | |
| 71 | int get_container_size(ulong addr, u16 *header_length); |
Sean Anderson | d401e0b | 2023-10-14 16:47:43 -0400 | [diff] [blame] | 72 | |
| 73 | static inline bool valid_container_hdr(struct container_hdr *container) |
| 74 | { |
| 75 | return container->tag == CONTAINER_HDR_TAG && |
| 76 | container->version == CONTAINER_HDR_VERSION; |
| 77 | } |
Peng Fan | 7b86cd4 | 2019-08-22 07:42:33 +0000 | [diff] [blame] | 78 | #endif |