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