1*5b69db07SJason Zhu /* 2*5b69db07SJason Zhu * Copyright (C) 2016 The Android Open Source Project 3*5b69db07SJason Zhu * 4*5b69db07SJason Zhu * Permission is hereby granted, free of charge, to any person 5*5b69db07SJason Zhu * obtaining a copy of this software and associated documentation 6*5b69db07SJason Zhu * files (the "Software"), to deal in the Software without 7*5b69db07SJason Zhu * restriction, including without limitation the rights to use, copy, 8*5b69db07SJason Zhu * modify, merge, publish, distribute, sublicense, and/or sell copies 9*5b69db07SJason Zhu * of the Software, and to permit persons to whom the Software is 10*5b69db07SJason Zhu * furnished to do so, subject to the following conditions: 11*5b69db07SJason Zhu * 12*5b69db07SJason Zhu * The above copyright notice and this permission notice shall be 13*5b69db07SJason Zhu * included in all copies or substantial portions of the Software. 14*5b69db07SJason Zhu * 15*5b69db07SJason Zhu * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16*5b69db07SJason Zhu * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17*5b69db07SJason Zhu * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18*5b69db07SJason Zhu * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19*5b69db07SJason Zhu * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20*5b69db07SJason Zhu * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21*5b69db07SJason Zhu * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22*5b69db07SJason Zhu * SOFTWARE. 23*5b69db07SJason Zhu */ 24*5b69db07SJason Zhu 25*5b69db07SJason Zhu /* 26*5b69db07SJason Zhu #if !defined(AVB_INSIDE_LIBAVB_H) && !defined(AVB_COMPILATION) 27*5b69db07SJason Zhu #error "Never include this file directly, include libavb.h instead." 28*5b69db07SJason Zhu #endif 29*5b69db07SJason Zhu */ 30*5b69db07SJason Zhu 31*5b69db07SJason Zhu #ifndef AVB_FOOTER_H_ 32*5b69db07SJason Zhu #define AVB_FOOTER_H_ 33*5b69db07SJason Zhu 34*5b69db07SJason Zhu #include <android_avb/avb_sysdeps.h> 35*5b69db07SJason Zhu 36*5b69db07SJason Zhu #ifdef __cplusplus 37*5b69db07SJason Zhu extern "C" { 38*5b69db07SJason Zhu #endif 39*5b69db07SJason Zhu 40*5b69db07SJason Zhu /* Magic for the footer. */ 41*5b69db07SJason Zhu #define AVB_FOOTER_MAGIC "AVBf" 42*5b69db07SJason Zhu #define AVB_FOOTER_MAGIC_LEN 4 43*5b69db07SJason Zhu 44*5b69db07SJason Zhu /* Size of the footer. */ 45*5b69db07SJason Zhu #define AVB_FOOTER_SIZE 64 46*5b69db07SJason Zhu 47*5b69db07SJason Zhu /* The current footer version used - keep in sync with avbtool. */ 48*5b69db07SJason Zhu #define AVB_FOOTER_VERSION_MAJOR 1 49*5b69db07SJason Zhu #define AVB_FOOTER_VERSION_MINOR 0 50*5b69db07SJason Zhu 51*5b69db07SJason Zhu /* The struct used as a footer used on partitions, used to find the 52*5b69db07SJason Zhu * AvbVBMetaImageHeader struct. This struct is always stored at the 53*5b69db07SJason Zhu * end of a partition. 54*5b69db07SJason Zhu */ 55*5b69db07SJason Zhu typedef struct AvbFooter { 56*5b69db07SJason Zhu /* 0: Four bytes equal to "AVBf" (AVB_FOOTER_MAGIC). */ 57*5b69db07SJason Zhu uint8_t magic[AVB_FOOTER_MAGIC_LEN]; 58*5b69db07SJason Zhu /* 4: The major version of the footer struct. */ 59*5b69db07SJason Zhu uint32_t version_major; 60*5b69db07SJason Zhu /* 8: The minor version of the footer struct. */ 61*5b69db07SJason Zhu uint32_t version_minor; 62*5b69db07SJason Zhu 63*5b69db07SJason Zhu /* 12: The original size of the image on the partition. */ 64*5b69db07SJason Zhu uint64_t original_image_size; 65*5b69db07SJason Zhu 66*5b69db07SJason Zhu /* 20: The offset of the |AvbVBMetaImageHeader| struct. */ 67*5b69db07SJason Zhu uint64_t vbmeta_offset; 68*5b69db07SJason Zhu 69*5b69db07SJason Zhu /* 28: The size of the vbmeta block (header + auth + aux blocks). */ 70*5b69db07SJason Zhu uint64_t vbmeta_size; 71*5b69db07SJason Zhu 72*5b69db07SJason Zhu /* 36: Padding to ensure struct is size AVB_FOOTER_SIZE bytes. This 73*5b69db07SJason Zhu * must be set to zeroes. 74*5b69db07SJason Zhu */ 75*5b69db07SJason Zhu uint8_t reserved[28]; 76*5b69db07SJason Zhu } AVB_ATTR_PACKED AvbFooter; 77*5b69db07SJason Zhu 78*5b69db07SJason Zhu /* Copies |src| to |dest| and validates, byte-swapping fields in the 79*5b69db07SJason Zhu * process if needed. Returns true if valid, false if invalid. 80*5b69db07SJason Zhu */ 81*5b69db07SJason Zhu bool avb_footer_validate_and_byteswap(const AvbFooter* src, AvbFooter* dest) 82*5b69db07SJason Zhu AVB_ATTR_WARN_UNUSED_RESULT; 83*5b69db07SJason Zhu 84*5b69db07SJason Zhu #ifdef __cplusplus 85*5b69db07SJason Zhu } 86*5b69db07SJason Zhu #endif 87*5b69db07SJason Zhu 88*5b69db07SJason Zhu #endif /* AVB_FOOTER_H_ */ 89