uboot/lib/libavb/avb_footer.c
<<
>>
Prefs
   1// SPDX-License-Identifier: MIT
   2/*
   3 * Copyright (C) 2016 The Android Open Source Project
   4 */
   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}
  36