|
| 1 | +#ifndef IMAGE_H |
| 2 | +#define IMAGE_H |
| 3 | +#include <stdint.h> |
| 4 | +#include <target.h> |
| 5 | + |
| 6 | +#define IMAGE_HEADER_SIZE 256 |
| 7 | +#define IMAGE_HEADER_OFFSET (2 * sizeof(uint32_t)) |
| 8 | + |
| 9 | +#define WOLFBOOT_MAGIC 0x464C4F57 /* WOLF */ |
| 10 | +#define WOLFBOOT_MAGIC_TRAIL 0x544F4F42 /* BOOT */ |
| 11 | + |
| 12 | +#define HDR_END 0x00 |
| 13 | +#define HDR_VERSION 0x01 |
| 14 | +#define HDR_TIMESTAMP 0x02 |
| 15 | +#define HDR_SHA256 0x03 |
| 16 | +#define HDR_PUBKEY 0x10 |
| 17 | +#define HDR_SIGNATURE 0x20 |
| 18 | +#define HDR_PADDING 0xFF |
| 19 | + |
| 20 | +#define PART_BOOT 0 |
| 21 | +#define PART_UPDATE 1 |
| 22 | +#define PART_SWAP 2 |
| 23 | + |
| 24 | +#define IMG_STATE_NEW 0xFF |
| 25 | +#define IMG_STATE_UPDATING 0x70 |
| 26 | +#define IMG_STATE_TESTING 0x10 |
| 27 | +#define IMG_STATE_SUCCESS 0x00 |
| 28 | + |
| 29 | +#define SECT_FLAG_NEW 0x0F |
| 30 | +#define SECT_FLAG_SWAPPING 0x07 |
| 31 | +#define SECT_FLAG_BACKUP 0x03 |
| 32 | +#define SECT_FLAG_UPDATED 0x00 |
| 33 | + |
| 34 | + |
| 35 | +struct wolfBoot_image { |
| 36 | + uint8_t *hdr; |
| 37 | + uint8_t *trailer; |
| 38 | + int hdr_ok; |
| 39 | + int signature_ok; |
| 40 | + int sha_ok; |
| 41 | + uint8_t *fw_base; |
| 42 | + uint32_t fw_size; |
| 43 | + uint8_t part; |
| 44 | +}; |
| 45 | + |
| 46 | + |
| 47 | +int wolfBoot_open_image(struct wolfBoot_image *img, uint8_t part); |
| 48 | +int wolfBoot_verify_integrity(struct wolfBoot_image *img); |
| 49 | +int wolfBoot_verify_authenticity(struct wolfBoot_image *img); |
| 50 | +int wolfBoot_set_partition_state(uint8_t part, uint8_t newst); |
| 51 | +int wolfBoot_set_sector_flag(uint8_t part, uint8_t sector, uint8_t newflag); |
| 52 | +int wolfBoot_get_partition_state(uint8_t part, uint8_t *st); |
| 53 | +int wolfBoot_get_sector_flag(uint8_t part, uint8_t sector, uint8_t *flag); |
| 54 | +int wolfBoot_copy(uint32_t src, uint32_t dst, uint32_t size); |
| 55 | +void wolfBoot_erase_partition(uint8_t part); |
| 56 | +void wolfBoot_update_trigger(void); |
| 57 | +void wolfBoot_success(void); |
| 58 | + |
| 59 | +#endif /* IMAGE_H */ |
0 commit comments