InitDevice1.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*====================================================================*
  2. *
  3. * Copyright (c) 2013 Qualcomm Atheros, Inc.
  4. *
  5. * All rights reserved.
  6. *
  7. *====================================================================*/
  8. /*====================================================================*
  9. *
  10. * int InitDevice1 (struct plc * plc);
  11. *
  12. * plc.h
  13. *
  14. * configure volatile memory by finding the memctl applet in an
  15. * older .nvm file then downloading it and executing it;
  16. *
  17. * this implementation detects chipsets prior to INT6400 and uses
  18. * VS_WR_MEM/VS_ST_MAC messages instead of VS_WRITE_AND_EXECUTE
  19. * messages;
  20. *
  21. * Contributor(s):
  22. * Charles Maier <cmaier@qca.qualcomm.com>
  23. *
  24. *--------------------------------------------------------------------*/
  25. #ifndef INITDEVICE1_SOURCE
  26. #define INITDEVICE1_SOURCE
  27. #include <stdint.h>
  28. #include <unistd.h>
  29. #include <memory.h>
  30. #include <errno.h>
  31. #include "../tools/memory.h"
  32. #include "../tools/files.h"
  33. #include "../tools/flags.h"
  34. #include "../tools/error.h"
  35. #include "../plc/plc.h"
  36. #include "../nvm/nvm.h"
  37. int InitDevice1 (struct plc * plc)
  38. {
  39. unsigned module = 0;
  40. struct lightning_nvm_header nvm_header;
  41. if (lseek (plc->NVM.file, 0, SEEK_SET))
  42. {
  43. error (1, errno, FILE_CANTHOME, plc->NVM.name);
  44. }
  45. do
  46. {
  47. if (read (plc->NVM.file, & nvm_header, sizeof (nvm_header)) != sizeof (nvm_header))
  48. {
  49. error (1, errno, NVM_HDR_CANTREAD, plc->NVM.name, module);
  50. }
  51. if (LE32TOH (nvm_header.HEADERVERSION) != 0x60000000)
  52. {
  53. error (1, 0, NVM_HDR_VERSION, plc->NVM.name, module);
  54. }
  55. if (checksum32 (& nvm_header, sizeof (nvm_header), 0))
  56. {
  57. error (1, 0, NVM_HDR_CHECKSUM, plc->NVM.name, module);
  58. }
  59. #if 0
  60. if (_anyset (LE16TOH (nvm_header.IGNOREMASK), (1 << (plc->hardwareID -1))))
  61. {
  62. if (lseek (plc->NVM.file, LE32TOH (nvm_header.NEXTHEADER), SEEK_SET) == -1)
  63. {
  64. error (1, errno, "Can't skip module: %s (%d)", plc->NVM.name, module);
  65. }
  66. }
  67. else
  68. #endif
  69. if (nvm_header.IMAGETYPE == NVM_IMAGE_MEMCTL)
  70. {
  71. if (plc->hardwareID < CHIPSET_AR7400)
  72. {
  73. if (WriteFirmware1 (plc, module, & nvm_header))
  74. {
  75. return (-1);
  76. }
  77. if (StartFirmware1 (plc, module, & nvm_header))
  78. {
  79. return (-1);
  80. }
  81. break;
  82. }
  83. WriteExecuteFirmware1 (plc, module, & nvm_header);
  84. break;
  85. }
  86. if (lseek (plc->NVM.file, LE32TOH (nvm_header.NEXTHEADER), SEEK_SET) == -1)
  87. {
  88. error (1, errno, "Can't skip module: %s (%d)", plc->NVM.name, module);
  89. }
  90. module++;
  91. }
  92. while (nvm_header.NEXTHEADER);
  93. return (0);
  94. }
  95. #endif