ExecuteApplets1.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*====================================================================*
  2. *
  3. * Copyright (c) 2013 Qualcomm Atheros, Inc.
  4. *
  5. * All rights reserved.
  6. *
  7. *====================================================================*/
  8. /*====================================================================*
  9. *
  10. * signed ExecuteApplets1 (struct plc * plc);
  11. *
  12. * plc.h
  13. *
  14. * download and execute all modules in an older nvm file chain;
  15. *
  16. * Contributor(s):
  17. * Charles Maier <cmaier@qca.qualcomm.com>
  18. *
  19. *--------------------------------------------------------------------*/
  20. #ifndef EXECUTEAPPLETS1_SOURCE
  21. #define EXECUTEAPPLETS1_SOURCE
  22. #include "../tools/flags.h"
  23. #include "../tools/files.h"
  24. #include "../tools/error.h"
  25. #include "../plc/plc.h"
  26. signed ExecuteApplets1 (struct plc * plc)
  27. {
  28. unsigned module = 0;
  29. struct lightning_nvm_header nvm_header;
  30. if (lseek (plc->NVM.file, 0, SEEK_SET))
  31. {
  32. if (_allclr (plc->flags, PLC_SILENCE))
  33. {
  34. error (PLC_EXIT (plc), errno, FILE_CANTHOME, plc->NVM.name);
  35. }
  36. return (-1);
  37. }
  38. do
  39. {
  40. if (read (plc->NVM.file, & nvm_header, sizeof (nvm_header)) != sizeof (nvm_header))
  41. {
  42. if (_allclr (plc->flags, PLC_SILENCE))
  43. {
  44. error (PLC_EXIT (plc), errno, NVM_HDR_CANTREAD, plc->NVM.name, module);
  45. }
  46. return (-1);
  47. }
  48. if (LE32TOH (nvm_header.HEADERVERSION) != 0x60000000)
  49. {
  50. if (_allclr (plc->flags, PLC_SILENCE))
  51. {
  52. error (PLC_EXIT (plc), 0, NVM_HDR_VERSION, plc->NVM.name, module);
  53. }
  54. return (-1);
  55. }
  56. if (checksum32 (& nvm_header, sizeof (nvm_header), 0))
  57. {
  58. if (_allclr (plc->flags, PLC_SILENCE))
  59. {
  60. error (PLC_EXIT (plc), 0, NVM_HDR_CHECKSUM, plc->NVM.name, module);
  61. }
  62. return (-1);
  63. }
  64. if (plc->hardwareID < CHIPSET_AR7400)
  65. {
  66. if (WriteFirmware1 (plc, module, & nvm_header))
  67. {
  68. return (-1);
  69. }
  70. if (StartFirmware1 (plc, module, & nvm_header))
  71. {
  72. return (-1);
  73. }
  74. }
  75. else
  76. {
  77. if (WriteExecuteFirmware1 (plc, module, & nvm_header))
  78. {
  79. return (-1);
  80. }
  81. }
  82. if (_anyset (plc->flags, PLC_QUICK_FLASH))
  83. {
  84. break;
  85. }
  86. while (! ReadMME (plc, 0, (VS_HOST_ACTION | MMTYPE_IND)));
  87. module++;
  88. }
  89. while (nvm_header.NEXTHEADER);
  90. return (0);
  91. }
  92. #endif