FlashPTS.c 2.9 KB

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