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