panther_nvm_file.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*====================================================================*
  2. *
  3. * Copyright (c) 2013 Qualcomm Atheros, Inc.
  4. *
  5. * All rights reserved.
  6. *
  7. *====================================================================*/
  8. /*====================================================================*
  9. *
  10. * signed panther_nvm_file (struct _file_ const * file);
  11. *
  12. * validate a Panther/Lynx firmware module file;
  13. *
  14. * Contributor(s):
  15. * Charles Maier <cmaier@qca.qualcomm.com>
  16. *
  17. *--------------------------------------------------------------------*/
  18. #ifndef NVMFILE2_SOURCE
  19. #define NVMFILE2_SOURCE
  20. #include <memory.h>
  21. #include <errno.h>
  22. #include "../tools/memory.h"
  23. #include "../tools/files.h"
  24. #include "../tools/error.h"
  25. #include "../nvm/nvm.h"
  26. signed panther_nvm_file (struct _file_ const * file)
  27. {
  28. unsigned module = 0;
  29. struct panther_nvm_header nvm_header;
  30. if (lseek (file->file, 0, SEEK_SET))
  31. {
  32. error (1, errno, FILE_CANTHOME, file->name);
  33. }
  34. do
  35. {
  36. if (read (file->file, & nvm_header, sizeof (nvm_header)) != sizeof (nvm_header))
  37. {
  38. error (1, errno, NVM_HDR_CANTREAD, file->name, module);
  39. }
  40. if (LE16TOH (nvm_header.MajorVersion) != 1)
  41. {
  42. error (1, errno, NVM_HDR_VERSION, file->name, module);
  43. }
  44. if (LE16TOH (nvm_header.MinorVersion) != 1)
  45. {
  46. error (1, errno, NVM_HDR_VERSION, file->name, module);
  47. }
  48. if (checksum32 (& nvm_header, sizeof (nvm_header), 0))
  49. {
  50. error (1, errno, NVM_HDR_CHECKSUM, file->name, module);
  51. }
  52. if (fdchecksum32 (file->file, LE32TOH (nvm_header.ImageLength), nvm_header.ImageChecksum))
  53. {
  54. error (1, errno, NVM_IMG_CHECKSUM, file->name, module);
  55. }
  56. module++;
  57. }
  58. while (~ nvm_header.NextHeader);
  59. #if 0
  60. if (lseek (file->file, 0, SEEK_CUR) != lseek (file->file, 0, SEEK_END))
  61. {
  62. error (1, errno, NVM_HDR_LINK, file->name, module);
  63. }
  64. #endif
  65. return (0);
  66. }
  67. #endif