ethosn_big_fw.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * Copyright (c) 2023, Arm Limited. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <common/debug.h>
  7. #include "ethosn_big_fw.h"
  8. /* Magic (FourCC) number to identify the big firmware binary */
  9. #define ETHOSN_BIG_FW_MAGIC ('E' | ('N' << 8) | ('F' << 16) | ('W' << 24))
  10. /* Supported big firmware version */
  11. #define ETHOSN_BIG_FW_VERSION_MAJOR 15
  12. #define ETHOSN_ARCH_VER_MAJOR_MASK U(0xF000)
  13. #define ETHOSN_ARCH_VER_MAJOR_SHIFT U(0xC)
  14. #define ETHOSN_ARCH_VER_MINOR_MASK U(0xF00)
  15. #define ETHOSN_ARCH_VER_MINOR_SHIFT U(0x8)
  16. #define ETHOSN_ARCH_VER_REV_MASK U(0xFF)
  17. /* Convert Arm(R) Ethos(TM)-N NPU architecture version to big firmware format */
  18. #define ETHOSN_BIG_FW_FORMAT_ARCH_VER(arch_ver) \
  19. (arch_ver & ETHOSN_ARCH_VER_MAJOR_MASK) << ETHOSN_ARCH_VER_MAJOR_SHIFT | \
  20. (arch_ver & ETHOSN_ARCH_VER_MINOR_MASK) << ETHOSN_ARCH_VER_MINOR_SHIFT | \
  21. (arch_ver & ETHOSN_ARCH_VER_REV_MASK)
  22. bool ethosn_big_fw_verify_header(const struct ethosn_big_fw *big_fw,
  23. uint32_t npu_arch_ver)
  24. {
  25. const uint32_t arch_ver = ETHOSN_BIG_FW_FORMAT_ARCH_VER(npu_arch_ver);
  26. if (big_fw->fw_magic != ETHOSN_BIG_FW_MAGIC) {
  27. ERROR("ETHOSN: Unable to find firmware. Invalid magic value: 0x%02x\n",
  28. big_fw->fw_magic);
  29. return false;
  30. }
  31. if (big_fw->fw_ver_major != ETHOSN_BIG_FW_VERSION_MAJOR) {
  32. ERROR("ETHOSN: Unsupported firmware version: %u.%u.%u. Expected Version %u.x.x.\n",
  33. big_fw->fw_ver_major, big_fw->fw_ver_minor,
  34. big_fw->fw_ver_patch, ETHOSN_BIG_FW_VERSION_MAJOR);
  35. return false;
  36. }
  37. if (big_fw->arch_min > arch_ver || arch_ver > big_fw->arch_max) {
  38. ERROR("ETHOSN: Firmware is not compatbile with architecture version: 0x%02x\n",
  39. npu_arch_ver);
  40. return false;
  41. }
  42. return true;
  43. }