EraseFlashMemory2.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*====================================================================*
  2. *
  3. * Copyright (c) 2013 Qualcomm Atheros, Inc.
  4. *
  5. * All rights reserved.
  6. *
  7. *====================================================================*/
  8. /*====================================================================*
  9. *
  10. * signed EraseFlashMemory2 (struct plc * plc);
  11. *
  12. * plc.h
  13. *
  14. * determine the overall size of flash memory with VS_GET_NVM then
  15. * erase flash memory by writing 0xFF to all of flash memory using
  16. * VS_MODULE_OPERATION messages; force flash but do not reset;
  17. *
  18. * struct vs_module_spec is defined in plc.h;
  19. *
  20. * Contributor(s):
  21. * Charles Maier <cmaier@qca.qualcomm.com>
  22. *
  23. *--------------------------------------------------------------------*/
  24. #ifndef ERASEFLASHMEMORY2_SOURCE
  25. #define ERASEFLASHMEMORY2_SOURCE
  26. #include <stdint.h>
  27. #include <memory.h>
  28. #include "../tools/error.h"
  29. #include "../tools/memory.h"
  30. #include "../tools/symbol.h"
  31. #include "../ram/nvram.h"
  32. #include "../plc/plc.h"
  33. #include "../nda/nda.h"
  34. signed EraseFlashMemory2 (struct plc * plc)
  35. {
  36. struct channel * channel = (struct channel *) (plc->channel);
  37. struct message * message = (struct message *) (plc->message);
  38. #ifndef __GNUC__
  39. #pragma pack (push,1)
  40. #endif
  41. struct __packed vs_get_nvm_request
  42. {
  43. struct ethernet_hdr ethernet;
  44. struct qualcomm_hdr qualcomm;
  45. }
  46. * request = (struct vs_get_nvm_request *) (message);
  47. struct __packed vs_get_nvm_confirm
  48. {
  49. struct ethernet_hdr ethernet;
  50. struct qualcomm_hdr qualcomm;
  51. uint8_t MSTATUS;
  52. struct config_nvram config_nvram;
  53. }
  54. * confirm = (struct vs_get_nvm_confirm *) (message);
  55. #ifndef __GNUC__
  56. #pragma pack (pop)
  57. #endif
  58. struct vs_module_spec vs_module_spec =
  59. {
  60. PLC_MODULEID_RESERVED1,
  61. 0,
  62. 0,
  63. 0
  64. };
  65. struct config_nvram * config_nvram = (struct config_nvram *) (& confirm->config_nvram);
  66. memcpy (channel->peer, message->ethernet.OSA, sizeof (channel->peer));
  67. Request (plc, "Probe Flash Memory");
  68. memset (message, 0, sizeof (* message));
  69. EthernetHeader (& request->ethernet, channel->peer, channel->host, channel->type);
  70. QualcommHeader (& request->qualcomm, 0, (VS_GET_NVM | MMTYPE_REQ));
  71. plc->packetsize = (ETHER_MIN_LEN - ETHER_CRC_LEN);
  72. if (SendMME (plc) <= 0)
  73. {
  74. error (PLC_EXIT (plc), errno, CHANNEL_CANTSEND);
  75. return (-1);
  76. }
  77. if (ReadMME (plc, 0, (VS_GET_NVM | MMTYPE_CNF)) <= 0)
  78. {
  79. error (PLC_EXIT (plc), errno, CHANNEL_CANTSEND);
  80. return (-1);
  81. }
  82. if (confirm->MSTATUS)
  83. {
  84. Failure (plc, PLC_WONTDOIT);
  85. return (-1);
  86. }
  87. vs_module_spec.MODULE_LENGTH = LE32TOH (config_nvram->NVRAMSIZE);
  88. if (vs_module_spec.MODULE_LENGTH & sizeof (uint32_t))
  89. {
  90. vs_module_spec.MODULE_CHKSUM = 0;
  91. }
  92. else
  93. {
  94. vs_module_spec.MODULE_CHKSUM = ~ 0;
  95. }
  96. if (ModuleSession (plc, 1, & vs_module_spec))
  97. {
  98. return (-1);
  99. }
  100. if (ModuleErase (plc, & vs_module_spec))
  101. {
  102. return (-1);
  103. }
  104. if (ModuleCommit (plc, 0))
  105. {
  106. return (-1);
  107. }
  108. return (0);
  109. }
  110. #endif