Dominik Ermel | 23a7a2e | 2023-02-10 11:15:17 +0000 | [diff] [blame] | 1 | /* |
| 2 | * SPDX-License-Identifier: Apache-2.0 |
| 3 | * |
| 4 | * Copyright (c) 2023 Nordic Semiconductor ASA |
| 5 | * |
| 6 | */ |
| 7 | #ifndef H_BOOTUTIL_MISC_ |
| 8 | #define H_BOOTUTIL_MISC_ |
| 9 | |
| 10 | #include <string.h> |
| 11 | #include <inttypes.h> |
| 12 | #include <stddef.h> |
| 13 | |
| 14 | #include "bootutil/bootutil_public.h" |
| 15 | #ifdef MCUBOOT_ENC_IMAGES |
| 16 | #include "bootutil/enc_key.h" |
| 17 | #endif |
| 18 | |
| 19 | static int |
| 20 | boot_magic_decode(const uint8_t *magic) |
| 21 | { |
| 22 | if (memcmp(magic, BOOT_IMG_MAGIC, BOOT_MAGIC_SZ) == 0) { |
| 23 | return BOOT_MAGIC_GOOD; |
| 24 | } |
| 25 | return BOOT_MAGIC_BAD; |
| 26 | } |
| 27 | |
| 28 | static inline uint32_t |
| 29 | boot_magic_off(const struct flash_area *fap) |
| 30 | { |
| 31 | return flash_area_get_size(fap) - BOOT_MAGIC_SZ; |
| 32 | } |
| 33 | |
| 34 | static inline uint32_t |
| 35 | boot_image_ok_off(const struct flash_area *fap) |
| 36 | { |
| 37 | return ALIGN_DOWN(boot_magic_off(fap) - BOOT_MAX_ALIGN, BOOT_MAX_ALIGN); |
| 38 | } |
| 39 | |
| 40 | static inline uint32_t |
| 41 | boot_copy_done_off(const struct flash_area *fap) |
| 42 | { |
| 43 | return boot_image_ok_off(fap) - BOOT_MAX_ALIGN; |
| 44 | } |
| 45 | |
| 46 | static inline uint32_t |
| 47 | boot_swap_size_off(const struct flash_area *fap) |
| 48 | { |
| 49 | return boot_swap_info_off(fap) - BOOT_MAX_ALIGN; |
| 50 | } |
| 51 | |
| 52 | #endif /* H_BOOTUTIL_MISC_ */ |