BootFirmware2.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*====================================================================*
  2. *
  3. * Copyright (c) 2013 Qualcomm Atheros, Inc.
  4. *
  5. * All rights reserved.
  6. *
  7. *====================================================================*/
  8. /*====================================================================*
  9. *
  10. * signed BootFirmware2 (struct plc * plc)
  11. *
  12. * plc.h
  13. *
  14. * Contributor(s):
  15. * Charles Maier <cmaier@qca.qualcomm.com>
  16. *
  17. *--------------------------------------------------------------------*/
  18. #ifndef BOOTFIRMWARE2_SOURCE
  19. #define BOOTFIRMWARE2_SOURCE
  20. #include <stdint.h>
  21. #include <unistd.h>
  22. #include <memory.h>
  23. #include <errno.h>
  24. #include "../tools/files.h"
  25. #include "../tools/error.h"
  26. #include "../tools/flags.h"
  27. #include "../plc/plc.h"
  28. #include "../nvm/nvm.h"
  29. signed BootFirmware2 (struct plc * plc)
  30. {
  31. unsigned module = 0;
  32. struct panther_nvm_header nvm_header;
  33. if (lseek (plc->NVM.file, 0, SEEK_SET))
  34. {
  35. error (1, errno, FILE_CANTHOME, plc->NVM.name);
  36. }
  37. do
  38. {
  39. if (read (plc->NVM.file, & nvm_header, sizeof (nvm_header)) != sizeof (nvm_header))
  40. {
  41. error (1, errno, NVM_HDR_CANTREAD, plc->NVM.name, module);
  42. }
  43. if (LE16TOH (nvm_header.MajorVersion) != 1)
  44. {
  45. error (1, ECANCELED, NVM_HDR_VERSION, plc->NVM.name, module);
  46. }
  47. if (LE16TOH (nvm_header.MinorVersion) != 1)
  48. {
  49. error (1, ECANCELED, NVM_HDR_VERSION, plc->NVM.name, module);
  50. }
  51. if (checksum32 (& nvm_header, sizeof (nvm_header), 0))
  52. {
  53. error (1, ECANCELED, NVM_HDR_CHECKSUM, plc->NVM.name, module);
  54. }
  55. #if 0
  56. if (_allclr (LE16TOH (nvm_header.ExecuteMask), (1 << (plc->hardwareID -1))))
  57. {
  58. if (lseek (plc->NVM.file, LE32TOH (nvm_header.NextHeader), SEEK_SET) == -1)
  59. {
  60. error (1, errno, "Can't skip module: %s (%d)", plc->NVM.name, module);
  61. }
  62. }
  63. else
  64. #endif
  65. if (LE32TOH (nvm_header.ImageType) == NVM_IMAGE_FIRMWARE)
  66. {
  67. if (WriteExecuteFirmware2 (plc, module, & nvm_header))
  68. {
  69. return (-1);
  70. }
  71. break;
  72. }
  73. if (lseek (plc->NVM.file, LE32TOH (nvm_header.NextHeader), SEEK_SET) == -1)
  74. {
  75. error (1, errno, "Can't skip module: %s (%d)", plc->NVM.name, module);
  76. }
  77. module++;
  78. }
  79. while (~ nvm_header.NextHeader);
  80. return (0);
  81. }
  82. #endif