TI OAD API Documentation  9.14.00
oad_image_header.h
Go to the documentation of this file.
1 /******************************************************************************
2 
3  @file oad_image_header.h
4 
5  @brief This file contains the image header definition and structures.
6 
7  Group: WCS, BTS
8  $Target Device: DEVICES $
9 
10  ******************************************************************************
11  $License: BSD3 2017 $
12  ******************************************************************************
13  $Release Name: PACKAGE NAME $
14  $Release Date: PACKAGE RELEASE DATE $
15  ******************************************************************************/
16 
92 #ifndef OAD_IMAGE_HEADER_H
93 #define OAD_IMAGE_HEADER_H
94 
95 #ifdef __cplusplus
96 extern "C" {
97 #endif
98 
99 /*******************************************************************************
100  * INCLUDES
101  ******************************************************************************/
102 #include <stddef.h>
103 #include <stdint.h>
104 
105 /*******************************************************************************
106  * CONSTANTS
107  ******************************************************************************/
108 
109 #ifdef OAD_ONCHIP
110 
125  #define BIM_VAR_ADDR 0x20000400
126 
132 extern uint32_t _bim_var;
133 #endif // OAD_ONCHIP
134 
135 #if defined(BIM_DUAL_ONCHIP_IMAGE) && !defined(SECURITY)
136  // DUAL Image BIM is considered a strictly production ready variant. DEBUG_BIM cannot be used as
137  // it would skip key security steps.
138  #error "Error: DUAL ON CHIP BIM needs the macro SECURITY to be enabled"
139 #endif
140 
141 #if defined(DeviceFamily_CC23X0R2)
142  #define SIGN_FN_PTR 0x37fc
143 #else
144  #define SIGN_FN_PTR 0x57fa0
145 #endif
146 extern uint32_t _sign_fnPtr;
147 
159 #define OAD_IMG_TYPE_PERSISTENT_APP 0
160 
166 #define OAD_IMG_TYPE_APP 1
167 
173 #define OAD_IMG_TYPE_STACK 2
174 
181 #define OAD_IMG_TYPE_APP_STACK 3
182 
189 #define OAD_IMG_TYPE_NP 4
190 
197 #define OAD_IMG_TYPE_FACTORY 5
198 
205 #define OAD_IMG_TYPE_BIM 6
206 
215 #define OAD_IMG_TYPE_APPSTACKLIB 7
216 
222 #define OAD_IMG_TYPE_RSVD_BEGIN 64
223 
229 #define OAD_IMG_TYPE_RSVD_END 255
230 
241 #define OAD_WIRELESS_TECH_BLE 0xFFFE
242 
246 #define OAD_WIRELESS_TECH_TIMAC_SUBG 0xFFFD
247 
251 #define OAD_WIRELESS_TECH_TIMAC_2_4G 0xFFFB
252 
256 #define OAD_WIRELESS_TECH_ZIGBEE 0xFFF7
257 
261 #define OAD_WIRELESS_TECH_RF4CE 0xFFEF
262 
266 #define OAD_WIRELESS_TECH_THREAD 0xFFDF
267 
271 #define OAD_WIRELESS_TECH_PROPRF 0xFFBF
272 
276 #define OAD_WIRELESS_TECH_MIOTY 0xFF7F
277 
281 #define OAD_WIRELESS_TECH_WBMS_WD 0xFEFF
282 
286 #define OAD_WIRELESS_TECH_WBMS_WM 0xFDFF
287 
290 #if defined(DeviceFamily_CC26X2) || defined(DeviceFamily_CC26X2_V2) || defined(DeviceFamily_CC26X2X7) || \
291  defined(DeviceFamily_CC26X1)
292  #define OAD_IMG_ID_VAL \
293  { \
294  'C', 'C', '2', '6', 'x', '2', 'R', '1' \
295  }
296 #elif defined(DeviceFamily_CC13X2) || defined(DeviceFamily_CC13X2X7) || defined(DeviceFamily_CC13X1) || \
297  defined(DeviceFamily_CC13X2_V1) || defined(DeviceFamily_CC13X2_V2)
298  #define OAD_IMG_ID_VAL \
299  { \
300  'C', 'C', '1', '3', 'x', '2', 'R', '1' \
301  }
302 #elif defined(DeviceFamily_CC13X4)
303  #define OAD_IMG_ID_VAL \
304  { \
305  'C', 'C', '1', '3', 'x', '4', ' ', ' ' \
306  }
307 #elif defined(DeviceFamily_CC26X3)
308  #define OAD_IMG_ID_VAL \
309  { \
310  'C', 'C', '2', '6', 'x', '3', ' ', ' ' \
311  }
312 #elif defined(DeviceFamily_CC26X4)
313  #define OAD_IMG_ID_VAL \
314  { \
315  'C', 'C', '2', '6', 'x', '4', ' ', ' ' \
316  }
317 #elif defined(DeviceFamily_CC26X0R2)
318  #define OAD_IMG_ID_VAL \
319  { \
320  'O', 'A', 'D', ' ', 'I', 'M', 'G', ' ' \
321  }
322 #elif defined(DeviceFamily_CC23X0R2)
323  #define OAD_IMG_ID_VAL \
324  { \
325  'C', 'C', '2', '3', 'x', '0', 'R', '2' \
326  }
327 #elif defined(DOXYGEN)
328 
338  #define OAD_IMG_ID_VAL
339 #else
340  #error "Unknown Device Family"
341 #endif // DeviceFamily_CC26X2
342 
351 #define OAD_EXTFL_ID_VAL \
352  { \
353  'O', 'A', 'D', ' ', 'N', 'V', 'M', '1' \
354  }
355 
364 #define CRC_OFFSET offsetof(imgHdr_t, fixedHdr.crc32)
365 
369 #define BIM_VER_OFFSET offsetof(imgHdr_t, fixedHdr.bimVer)
370 
375 #define IMG_DATA_OFFSET BIM_VER_OFFSET
376 
380 #define IMG_INFO_OFFSET offsetof(imgHdr_t, fixedHdr.imgCpStat)
381 
385 #define IMG_COPY_STAT_OFFSET IMG_INFO_OFFSET
386 
390 #define CRC_STAT_OFFSET offsetof(imgHdr_t, fixedHdr.crcStat)
391 
395 #define IMG_TYPE_OFFSET offsetof(imgHdr_t, fixedHdr.imgType)
396 
400 #define IMG_VALIDATION_OFFSET offsetof(imgHdr_t, fixedHdr.imgVld)
401 
405 #define IMG_COMMIT_FLAG_OFFSET offsetof(imgHdr_t, fixedHdr.commitFlag)
406 
410 #define BOUNDARY_SEG_OFFSET offsetof(imgHdr_t, fixedHdr.segTypeBd)
411 
415 #define SEG_LEN_OFFSET 4
416 
422 #define SEG_SIGERINFO_OFFSET offsetof(imgHdr_t, secInfoSeg.secSignerInfo)
423 
427 #define SEG_SIGNR_OFFSET offsetof(imgHdr_t, secInfoSeg.eccSign.sign_r)
428 
432 #define SEG_SIGNS_OFFSET offsetof(imgHdr_t, secInfoSeg.eccSign.sign_s)
433 
437 #define SEC_VERIF_STAT_OFFSET offsetof(imgHdr_t, secInfoSeg.verifStat)
438 
442 #define HDR_LEN_WITH_SECURITY_INFO offsetof(imgHdr_t, secInfoSeg.segTypeSecure) + sizeof(securityInfoSeg_t)
443 
447 #define IMG_START_ADDR_OFFSET offsetof(imgHdr_t, imgPayload.startAddr)
448 
459 #define SEG_HDR_LEN 12
460 
465 #define OAD_IMG_ID_LEN 8
466 
470 #define OAD_SW_VER_LEN 4
471 
475 #define OAD_IMG_HDR_LEN sizeof(imgFixedHdr_t)
476 
487 #define IMG_BOUNDARY_SEG_ID 0x00
488 
492 #define IMG_PAYLOAD_SEG_ID 0x01
493 
497 #define IMG_NONCOUNT_SEG_ID 0x02
498 
502 #define IMG_SECURITY_SEG_ID 0x03
503 
506 #define OAD_IMG_FULL_HDR_LEN sizeof(imgHdr_t)
507 #define OAD_IMG_ID_LEN 8
508 #define OAD_SW_VER_LEN 4
509 
510 #ifndef STACK_LIBRARY
511  #define BOUNDARY_SEG_LEN 0x18
512 #endif
513 #define SECURITY_SEG_LEN 0x55
514 
515 #define IMG_COPY_STAT_OFFSET IMG_INFO_OFFSET /* Image copy status */
516 
517 #define SEG_LEN_OFFSET 4 /* Offset from seg header to seg len */
518 #define SIG_OFFSET offsetof(securityInfoSeg_t, eccSign.sign_r)
519 
520 #define ECDSA_KEY_LEN 32
521 
522 #define ECDSA_SHA_TEMPWORKZONE_LEN \
523  ECDSA_KEY_LEN * 6
524 
525 
530 #define BIM_VER 0x3
531 
537 #define META_VER 0x1
538 
544 #define SECURITY_VER 0x1
545 
549 #define DEFAULT_STATE 0xFF
550 
555 #define CRC_VALID 0xFE
556 
561 #define CRC_INVALID 0xFC
562 
566 #define NEED_COPY 0xFE
567 
571 #define COPY_DONE 0xFC
572 
573 #ifdef BIM_DUAL_ONCHIP_IMAGE
574 
578  #define VERIFY_PASS_CURRENT 0xFE
579 
584  #define VERIFY_PASS_NOT_CURRENT 0xFC
585 
590  #define VERIFY_FAIL 0xF8
591 
592 #else
593 
597  #define VERIFY_FAIL 0xFC
598 
599 #endif // BIM_DUAL_ONCHIP_IMAGE
600 
604 #define VERIFY_PASS 0xFE
605 
606 #ifdef BIM_RESTRICTED_ROLLBACK_VERIFY_COMMIT_IMAGE
607 
611  #define COMMIT_PENDING 0XFF
612 
617  #define COMMIT_ACCEPTED 0XFE
618 
623  #define COMMIT_REJECTED 0XEF
624 
625 #endif
626 
630 #define EFL_MATADATA_HDR_LEN OAD_IMG_HDR_LEN + 8
631 
635 #define INVALID_ADDR 0xFFFFFFFF
636 
640 #define INVALID_LEN INVALID_ADDR
641 
645 #define DEFAULT_CRC 0xFFFFFFFF
646 
647 #if (defined(SECURITY))
648 
651  #define SIGNER_INFO_SIZE 8
652 
656  #define SIGNATURE_SIZE 64
657 #endif
658 
659 /*******************************************************************************
660  * Typedefs
661  */
662 
664 #if defined(__IAR_SYSTEMS_ICC__)
665  #define TYPEDEF_STRUCT_PACKED __packed typedef struct
666 #elif defined __TI_COMPILER_VERSION || defined __TI_COMPILER_VERSION__ || __clang__
667  #define TYPEDEF_STRUCT_PACKED typedef struct __attribute__((packed))
668 #elif defined(__GNUC__)
669  #define TYPEDEF_STRUCT_PACKED typedef struct __attribute__((__packed__))
670 #endif
671 
673 #if (defined(SECURITY))
674 
678 {
679  uint8_t signerInfo[SIGNER_INFO_SIZE];
680  uint8_t signature[SIGNATURE_SIZE];
681 }
682 signPld_ECDSA_P256_t;
683 #endif
684 
690 {
691  uint8_t imgID[8];
692  uint32_t crc32;
693  uint8_t bimVer;
694  uint8_t metaVer;
695  uint16_t techType;
696  uint8_t imgCpStat;
697  uint8_t crcStat;
698  uint8_t imgType;
699  uint8_t imgNo;
700  uint32_t imgVld;
701  uint32_t len;
702  uint32_t prgEntry;
703 #ifdef BIM_VERIFY_VERSION_IMAGE
704  uint32_t softVer;
705 #else
706  uint8_t softVer[4];
707 #endif
708  uint32_t imgEndAddr;
709  uint16_t hdrLen;
710 #ifdef BIM_RESTRICTED_ROLLBACK_VERIFY_COMMIT_IMAGE
711  uint8_t commitFlag;
712  uint8_t rfu;
713 #else
714  uint16_t rfu;
715 #endif
716 }
717 imgFixedHdr_t;
718 
726 {
727  uint8_t segTypeImg;
728  uint16_t wirelessTech;
729  uint8_t rfu;
730  uint32_t imgSegLen;
731  uint32_t startAddr;
732 }
733 imgPayloadSeg_t;
734 
745 {
746  uint8_t segTypeBd;
747  uint16_t wirelessTech;
748  uint8_t rfu;
749  uint32_t boundarySegLen;
750  uint32_t stackStartAddr;
751  uint32_t stackEntryAddr;
752  uint32_t ram0StartAddr;
753  uint32_t ram0EndAddr;
754 }
755 boundarySeg_t;
756 
758 typedef struct
759 {
760  uint8_t sign_r[32];
761  uint8_t sign_s[32];
763 
771 {
772  uint8_t segTypeSecure;
773  uint16_t wirelessTech;
774  uint8_t verifStat;
775  uint32_t secSegLen;
776  uint8_t secVer;
777  uint32_t secTimestamp;
778  uint8_t secSignerInfo[8];
780 }
781 securityInfoSeg_t;
782 
792 {
793  imgFixedHdr_t fixedHdr;
794 #if (defined(SECURITY))
795  securityInfoSeg_t secInfoSeg;
796 #endif
797 #if (!defined(STACK_LIBRARY) && (defined(SPLIT_APP_STACK_IMAGE)))
798  boundarySeg_t boundarySeg;
799 #endif
800  imgPayloadSeg_t imgPayload;
801 }
802 imgHdr_t;
803 
805 {
806  uint32_t *eccWorkzone;
807  uint8_t *SHAWorkzone;
809  uint8_t *tempWorkzone;
810  uint8_t *SHADataBuf;
811  uint8_t SHADataBufLen;
813 }
814 ecdsaSigVerifyBuf_t;
815 
818 /*******************************************************************************
819  * Typedefs
820  */
821 
827 typedef uint8_t (*bimSignFnPtr_t)(uint8_t, uint32_t, uint32_t, uint8_t *, uint8_t *, ecdsaSigVerifyBuf_t *);
828 
829 #ifdef __cplusplus
830 }
831 #endif
832 
833 #endif /* OAD_IMAGE_HEADER_H */
uint16_t wirelessTech
Wireless technology type.
Definition: oad_image_header.h:728
uint16_t hdrLen
Total length of the image header.
Definition: oad_image_header.h:709
uint8_t crcStat
CRC status.
Definition: oad_image_header.h:697
uint32_t _sign_fnPtr
Variable for Pointer to BIM Function.
uint32_t secTimestamp
Security timestamp */.
Definition: oad_image_header.h:777
uint32_t ram0EndAddr
RAM entry end address.
Definition: oad_image_header.h:753
uint8_t * tempWorkzone
Should be size 6*ECDSA_KEY_LEN bytes.
Definition: oad_image_header.h:809
uint8_t metaVer
Metadata version.
Definition: oad_image_header.h:694
uint8_t imgCpStat
Image copy status.
Definition: oad_image_header.h:696
uint8_t secSignerInfo[8]
Security signer info */.
Definition: oad_image_header.h:778
uint8_t verifStat
Verification status.
Definition: oad_image_header.h:774
uint32_t startAddr
Start address of image on internal flash.
Definition: oad_image_header.h:731
uint16_t techType
Wireless protocol type BLE/TI-MAC/ZIGBEE etc.
Definition: oad_image_header.h:695
uint8_t imgType
Image Type.
Definition: oad_image_header.h:698
uint32_t imgEndAddr
Address of the last byte of a contiguous image.
Definition: oad_image_header.h:708
uint8_t * SHADataBuf
Definition: oad_image_header.h:810
TYPEDEF_STRUCT_PACKED
User-defined Image Identification bytes.
Definition: oad_image_header.h:690
eccSignature_t eccSign
Security signature */.
Definition: oad_image_header.h:779
uint32_t secSegLen
Payload segment length.
Definition: oad_image_header.h:775
uint8_t softVer[4]
Software version of the image.
Definition: oad_image_header.h:706
uint32_t ram0StartAddr
RAM entry start address.
Definition: oad_image_header.h:752
uint8_t * SHAWorkzone
SHA workzone buffer should be of size(SHA256_memory_t) bytes.
Definition: oad_image_header.h:808
uint8_t bimVer
BIM version.
Definition: oad_image_header.h:693
uint32_t imgVld
Image validation bytes, used by BIM.
Definition: oad_image_header.h:700
uint16_t rfu
Reserved bytes.
Definition: oad_image_header.h:714
uint32_t len
Image length in bytes.
Definition: oad_image_header.h:701
uint32_t boundarySegLen
Boundary segment length.
Definition: oad_image_header.h:749
uint32_t stackStartAddr
Start address of stack image on internal flash.
Definition: oad_image_header.h:750
Definition: oad_image_header.h:758
uint32_t stackEntryAddr
Stack start address.
Definition: oad_image_header.h:751
uint32_t imgSegLen
Payload segment length.
Definition: oad_image_header.h:730
uint8_t(* bimSignFnPtr_t)(uint8_t, uint32_t, uint32_t, uint8_t *, uint8_t *, ecdsaSigVerifyBuf_t *)
OAD Image Pointer to BIM Function.
Definition: oad_image_header.h:827
*uint8_t SHADataBufLen
length of allocate SHA data buffer
Definition: oad_image_header.h:812
uint8_t secVer
Security version */.
Definition: oad_image_header.h:776
uint32_t crc32
Image&#39;s 32-bit CRC value.
Definition: oad_image_header.h:692
imgPayloadSeg_t imgPayload
Required contiguous image segment.
Definition: oad_image_header.h:800
uint32_t prgEntry
Program entry address.
Definition: oad_image_header.h:702
uint8_t imgNo
Image number of &#39;image type&#39;.
Definition: oad_image_header.h:699