EraseFlashMemory1.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*====================================================================*
  2. *
  3. * Copyright (c) 2013 Qualcomm Atheros, Inc.
  4. *
  5. * All rights reserved.
  6. *
  7. *====================================================================*/
  8. /*====================================================================*
  9. *
  10. * signed EraseFlashMemory1 (struct plc * plc);
  11. *
  12. * plc.h
  13. *
  14. * commit downloaded firmware and/or parameters to NVRAM using a
  15. * VS_PTS_NVM message; flash-less devices will attempt to upload
  16. * to their local host because they have no NVRAM; the host must
  17. * be prepared to handle this situation;
  18. *
  19. * See the Atheros HomePlug AV Firmware Technical Reference Manual
  20. * for more information;
  21. *
  22. * Contributor(s):
  23. * Charles Maier <cmaier@qca.qualcomm.com>
  24. *
  25. *--------------------------------------------------------------------*/
  26. #ifndef ERASEFLASHMEMORY1_SOURCE
  27. #define ERASEFLASHMEMORY1_SOURCE
  28. #include <stdint.h>
  29. #include <memory.h>
  30. #include "../tools/memory.h"
  31. #include "../tools/error.h"
  32. #include "../tools/flags.h"
  33. #include "../plc/plc.h"
  34. signed EraseFlashMemory1 (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_pts_nvm_request
  42. {
  43. struct ethernet_hdr ethernet;
  44. struct qualcomm_hdr qualcomm;
  45. uint8_t MODULEID;
  46. uint8_t RESERVED;
  47. uint8_t DAK [HPAVKEY_DAK_LEN];
  48. }
  49. * request = (struct vs_pts_nvm_request *) (message);
  50. struct __packed vs_pts_nvm_confirm
  51. {
  52. struct ethernet_hdr ethernet;
  53. struct qualcomm_hdr qualcomm;
  54. uint8_t MSTATUS;
  55. uint8_t MODULEID;
  56. }
  57. * confirm = (struct vs_pts_nvm_confirm *) (message);
  58. #ifndef __GNUC__
  59. #pragma pack (pop)
  60. #endif
  61. Request (plc, "Erasing Flash Memory (PTS)");
  62. memset (message, 0, sizeof (* message));
  63. EthernetHeader (& request->ethernet, channel->peer, channel->host, channel->type);
  64. QualcommHeader (& request->qualcomm, 0, (VS_PTS_NVM | MMTYPE_REQ));
  65. request->MODULEID = 0x0C;
  66. memcpy (request->DAK, plc->DAK, sizeof (request->DAK));
  67. plc->packetsize = (ETHER_MIN_LEN - ETHER_CRC_LEN);
  68. if (SendMME (plc) <= 0)
  69. {
  70. error (PLC_EXIT (plc), ECANCELED, CHANNEL_CANTSEND);
  71. return (-1);
  72. }
  73. if (ReadMME (plc, 0, (VS_PTS_NVM | MMTYPE_CNF)) <= 0)
  74. {
  75. error (PLC_EXIT (plc), ECANCELED, CHANNEL_CANTREAD);
  76. return (-1);
  77. }
  78. if (confirm->MSTATUS)
  79. {
  80. Failure (plc, PLC_WONTDOIT);
  81. return (-1);
  82. }
  83. #if 1
  84. /*
  85. * this code is needed because the AR7400 behaves differently than the INT6x00 after flash
  86. * memory is erased; the AR7400 returns to bootloader and sends HARs but ignores VS_SW_VER
  87. * requests; consequently, if we are erasing flash memory and have not requested immediate
  88. * return then we wait indefinitely for a VS_HOST_ACTION.IND before proceding;
  89. */
  90. if (_allclr (plc->flags, PLC_QUICK_FLASH))
  91. {
  92. while (ReadMME (plc, 0, (VS_HOST_ACTION | MMTYPE_IND)) <= 0);
  93. _setbits (plc->flags, PLC_QUICK_FLASH);
  94. }
  95. #endif
  96. return (0);
  97. }
  98. #endif