]> git.sur5r.net Git - u-boot/blob - lib/libavb/avb_footer.c
f8b687394221d23ccab2035bd58dacfcfbaf5939
[u-boot] / lib / libavb / avb_footer.c
1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * SPDX-License-Identifier:     MIT
5  */
6
7 #include "avb_footer.h"
8 #include "avb_util.h"
9
10 bool avb_footer_validate_and_byteswap(const AvbFooter* src, AvbFooter* dest) {
11   avb_memcpy(dest, src, sizeof(AvbFooter));
12
13   dest->version_major = avb_be32toh(dest->version_major);
14   dest->version_minor = avb_be32toh(dest->version_minor);
15
16   dest->original_image_size = avb_be64toh(dest->original_image_size);
17   dest->vbmeta_offset = avb_be64toh(dest->vbmeta_offset);
18   dest->vbmeta_size = avb_be64toh(dest->vbmeta_size);
19
20   /* Check that magic is correct. */
21   if (avb_safe_memcmp(dest->magic, AVB_FOOTER_MAGIC, AVB_FOOTER_MAGIC_LEN) !=
22       0) {
23     avb_error("Footer magic is incorrect.\n");
24     return false;
25   }
26
27   /* Ensure we don't attempt to access any fields if the footer major
28    * version is not supported.
29    */
30   if (dest->version_major > AVB_FOOTER_VERSION_MAJOR) {
31     avb_error("No support for footer version.\n");
32     return false;
33   }
34
35   return true;
36 }