xref: /OK3568_Linux_fs/external/rkwifibt/drivers/infineon/include/trxhdr.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2  * TRX image file header format.
3  *
4  * Portions of this code are copyright (c) 2021 Cypress Semiconductor Corporation
5  *
6  * Copyright (C) 1999-2017, Broadcom Corporation
7  *
8  *      Unless you and Broadcom execute a separate written software license
9  * agreement governing use of this software, this software is licensed to you
10  * under the terms of the GNU General Public License version 2 (the "GPL"),
11  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
12  * following added to such license:
13  *
14  *      As a special exception, the copyright holders of this software give you
15  * permission to link this software with independent modules, and to copy and
16  * distribute the resulting executable under terms of your choice, provided that
17  * you also meet, for each linked independent module, the terms and conditions of
18  * the license of that module.  An independent module is a module which is not
19  * derived from this software.  The special exception does not apply to any
20  * modifications of the software.
21  *
22  *      Notwithstanding the above, under no circumstances may you combine this
23  * software in any way with any other Broadcom software provided under a license
24  * other than the GPL, without Broadcom's express prior written consent.
25  *
26  *
27  * <<Broadcom-WL-IPTag/Open:>>
28  *
29  * $Id: trxhdr.h 520026 2014-12-10 01:29:40Z $
30  */
31 
32 #ifndef _TRX_HDR_H
33 #define _TRX_HDR_H
34 
35 #include <typedefs.h>
36 
37 #define TRX_MAGIC	0x30524448	/* "HDR0" */
38 #define TRX_MAX_LEN	0x3B0000	/* Max length */
39 #define TRX_NO_HEADER	1		/* Do not write TRX header */
40 #define TRX_GZ_FILES	0x2     /* Contains up to TRX_MAX_OFFSET individual gzip files */
41 #define TRX_EMBED_UCODE	0x8	/* Trx contains embedded ucode image */
42 #define TRX_ROMSIM_IMAGE	0x10	/* Trx contains ROM simulation image */
43 #define TRX_UNCOMP_IMAGE	0x20	/* Trx contains uncompressed rtecdc.bin image */
44 #define TRX_BOOTLOADER		0x40	/* the image is a bootloader */
45 
46 #define TRX_VERSION_BIT_OFFSET  16
47 #define R_COMP_SIZE             32	/* R component - 32 bytes */
48 #define S_COMP_SIZE             32	/* S component - 32 bytes */
49 #define ECDSA_SIGNATURE_SIZE (R_COMP_SIZE + S_COMP_SIZE) /* r[32bytes] and s[32bytes] components */
50 
51 enum {
52 	TRX_V4_OFFS_SIGN_INFO_IDX                   = 0,
53 	TRX_V4_OFFS_DATA_FOR_SIGN1_IDX              = 1,
54 	TRX_V4_OFFS_DATA_FOR_SIGN2_IDX              = 2,
55 	TRX_V4_OFFS_ROOT_MODULUS_IDX                = 3,
56 	TRX_V4_OFFS_ROOT_EXPONENT_IDX               = 67,
57 	TRX_V4_OFFS_CONT_MODULUS_IDX                = 68,
58 	TRX_V4_OFFS_CONT_EXPONENT_IDX               = 132,
59 	TRX_V4_OFFS_HASH_FW_IDX                     = 133,
60 	TRX_V4_OFFS_FW_LEN_IDX                      = 149,
61 	TRX_V4_OFFS_TR_RST_IDX                      = 150,
62 	TRX_V4_OFFS_FW_VER_FOR_ANTIROOLBACK_IDX     = 151,
63 	TRX_V4_OFFS_IV_IDX                          = 152,
64 	TRX_V4_OFFS_NONCE_IDX                       = 160,
65 	TRX_V4_OFFS_SIGN_INFO2_IDX                  = 168,
66 	TRX_V4_OFFS_MAX_IDX
67 };
68 
69 #if defined BCMTRXV4
70 #define TRX_VERSION     4                       /* Version 4 */
71 #define TRX_MAX_OFFSET  (TRX_V4_OFFS_MAX_IDX)
72 
73 #elif defined BCMTRXV3
74 #define TRX_VERSION     3		/* Version 3 */
75 #define TRX_MAX_OFFSET  4		/* FW size + Jump_addr + NVRAM size[if exist]
76 					 * + signature size
77 					 */
78 #elif defined BCMTRXV2
79 #define TRX_VERSION     2		/* Version 2 */
80 #define TRX_MAX_OFFSET  5		/* Max number of individual files
81 					 * to support SDR signature + Config data region
82 					 */
83 #else
84 #define TRX_VERSION     1		/* Version 1 */
85 #define TRX_MAX_OFFSET  3		/* Max number of individual files */
86 #endif /* BCMTRXV3 BCMTRXV2 BCMTRXV4 */
87 
88 /* BMAC Host driver/application like bcmdl need to support both Ver 1 as well as
89  * Ver 2 of trx header. To make it generic, trx_header is structure is modified
90  * as below where size of "offsets" field will vary as per the TRX version.
91  * Currently, BMAC host driver and bcmdl are modified to support TRXV2 as well.
92  * To make sure, other applications like "dhdl" which are yet to be enhanced to support
93  * TRXV2 are not broken, new macro and structure defintion take effect only when BCMTRXV2
94  * is defined.
95  */
96 struct trx_header {
97 	uint32 magic;		/* "HDR0" */
98 	uint32 len;		/* Length of file including header */
99 	uint32 crc32;		/* 32-bit CRC from flag_version to end of file */
100 	uint32 flag_version;	/* 0:15 flags, 16:31 version */
101 	uint32 offsets[TRX_MAX_OFFSET];	/* Offsets of partitions from start of header */
102 };
103 
104 /* bootloader makes special use of trx header "offsets" array */
105 enum {
106 	TRX_OFFS_FW_LEN_IDX     = 0,	/* Size of the fw; used in uncompressed case */
107 	TRX_OFFS_TR_RST_IDX     = 1,	/* RAM address[tr_rst] for jump to after download */
108 	TRX_OFFS_DSG_LEN_IDX    = 2,	/* Len of digital signature */
109 	TRX_OFFS_CFG_LEN_IDX    = 3	/* Len of config region */
110 };
111 
112 /* Compatibility */
113 typedef struct trx_header TRXHDR, *PTRXHDR;
114 
115 #endif /* _TRX_HDR_H */
116