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