BootFirmware1.c 2.3 KB

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