ExecuteApplets2.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*====================================================================*
  2. *
  3. * Copyright (c) 2013 Qualcomm Atheros, Inc.
  4. *
  5. * All rights reserved.
  6. *
  7. *====================================================================*/
  8. /*====================================================================*
  9. *
  10. * signed ExecuteApplets2 (struct plc * plc);
  11. *
  12. * plc.h
  13. *
  14. * download and execute all modules in a new nvm image files;
  15. *
  16. * Contributor(s):
  17. * Charles Maier <cmaier@qca.qualcomm.com>
  18. *
  19. *--------------------------------------------------------------------*/
  20. #ifndef EXECUTEAPPLETS2_SOURCE
  21. #define EXECUTEAPPLETS2_SOURCE
  22. #include "../tools/flags.h"
  23. #include "../tools/files.h"
  24. #include "../tools/error.h"
  25. #include "../plc/plc.h"
  26. signed ExecuteApplets2 (struct plc * plc)
  27. {
  28. unsigned module = 0;
  29. struct panther_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 (LE16TOH (nvm_header.MajorVersion) != 1)
  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 (LE32TOH (nvm_header.MinorVersion) != 1)
  57. {
  58. if (_allclr (plc->flags, PLC_SILENCE))
  59. {
  60. error (PLC_EXIT (plc), 0, NVM_HDR_VERSION, plc->NVM.name, module);
  61. }
  62. return (-1);
  63. }
  64. if (checksum32 (& nvm_header, sizeof (nvm_header), 0))
  65. {
  66. if (_allclr (plc->flags, PLC_SILENCE))
  67. {
  68. error (PLC_EXIT (plc), 0, NVM_HDR_CHECKSUM, plc->NVM.name, module);
  69. }
  70. return (-1);
  71. }
  72. if (WriteExecuteApplet2 (plc, module, & nvm_header))
  73. {
  74. return (-1);
  75. }
  76. if (_anyset (plc->flags, PLC_QUICK_FLASH))
  77. {
  78. break;
  79. }
  80. while (! ReadMME (plc, 0, (VS_HOST_ACTION | MMTYPE_IND)));
  81. module++;
  82. }
  83. while (~ nvm_header.NextHeader);
  84. return (0);
  85. }
  86. #endif