xref: /openbmc/u-boot/lib/libavb/avb_footer.h (revision cbd2fba1)
1 /* SPDX-License-Identifier: MIT */
2 /*
3  * Copyright (C) 2016 The Android Open Source Project
4  */
5 
6 #if !defined(AVB_INSIDE_LIBAVB_H) && !defined(AVB_COMPILATION)
7 #error "Never include this file directly, include libavb.h instead."
8 #endif
9 
10 #ifndef AVB_FOOTER_H_
11 #define AVB_FOOTER_H_
12 
13 #include "avb_sysdeps.h"
14 
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18 
19 /* Magic for the footer. */
20 #define AVB_FOOTER_MAGIC "AVBf"
21 #define AVB_FOOTER_MAGIC_LEN 4
22 
23 /* Size of the footer. */
24 #define AVB_FOOTER_SIZE 64
25 
26 /* The current footer version used - keep in sync with avbtool. */
27 #define AVB_FOOTER_VERSION_MAJOR 1
28 #define AVB_FOOTER_VERSION_MINOR 0
29 
30 /* The struct used as a footer used on partitions, used to find the
31  * AvbVBMetaImageHeader struct. This struct is always stored at the
32  * end of a partition.
33  */
34 typedef struct AvbFooter {
35   /*   0: Four bytes equal to "AVBf" (AVB_FOOTER_MAGIC). */
36   uint8_t magic[AVB_FOOTER_MAGIC_LEN];
37   /*   4: The major version of the footer struct. */
38   uint32_t version_major;
39   /*   8: The minor version of the footer struct. */
40   uint32_t version_minor;
41 
42   /*  12: The original size of the image on the partition. */
43   uint64_t original_image_size;
44 
45   /*  20: The offset of the |AvbVBMetaImageHeader| struct. */
46   uint64_t vbmeta_offset;
47 
48   /*  28: The size of the vbmeta block (header + auth + aux blocks). */
49   uint64_t vbmeta_size;
50 
51   /*  36: Padding to ensure struct is size AVB_FOOTER_SIZE bytes. This
52    * must be set to zeroes.
53    */
54   uint8_t reserved[28];
55 } AVB_ATTR_PACKED AvbFooter;
56 
57 /* Copies |src| to |dest| and validates, byte-swapping fields in the
58  * process if needed. Returns true if valid, false if invalid.
59  */
60 bool avb_footer_validate_and_byteswap(const AvbFooter* src, AvbFooter* dest)
61     AVB_ATTR_WARN_UNUSED_RESULT;
62 
63 #ifdef __cplusplus
64 }
65 #endif
66 
67 #endif /* AVB_FOOTER_H_ */
68