esp_init_data.c 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * This file is part of the MicroPython project, http://micropython.org/
  3. *
  4. * The MIT License (MIT)
  5. *
  6. * Copyright (c) 2016 Paul Sokolovsky
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy
  9. * of this software and associated documentation files (the "Software"), to deal
  10. * in the Software without restriction, including without limitation the rights
  11. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. * copies of the Software, and to permit persons to whom the Software is
  13. * furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in
  16. * all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  24. * THE SOFTWARE.
  25. */
  26. #include <stdio.h>
  27. #include "ets_sys.h"
  28. #include "etshal.h"
  29. #include "esp_mphal.h"
  30. #include "user_interface.h"
  31. #include "extmod/misc.h"
  32. NORETURN void call_user_start(void);
  33. void ets_printf(const char *fmt, ...);
  34. extern char flashchip;
  35. static const uint8_t default_init_data[] __attribute__((aligned(4))) = {
  36. 0x05, 0x00, 0x04, 0x02, 0x05, 0x05, 0x05, 0x02, 0x05, 0x00, 0x04, 0x05, 0x05, 0x04, 0x05, 0x05,
  37. 0x04, 0xfe, 0xfd, 0xff, 0xf0, 0xf0, 0xf0, 0xe0, 0xe0, 0xe0, 0xe1, 0x0a, 0xff, 0xff, 0xf8, 0x00,
  38. 0xf8, 0xf8, 0x52, 0x4e, 0x4a, 0x44, 0x40, 0x38, 0x00, 0x00, 0x01, 0x01, 0x02, 0x03, 0x04, 0x05,
  39. 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  40. 0xe1, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x93, 0x43, 0x00, 0x00, 0x00,
  41. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  42. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  43. 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  44. };
  45. void firmware_start(void) {
  46. // For SDK 1.5.2, either address has shifted and not mirrored in
  47. // eagle.rom.addr.v6.ld, or extra initial member was added.
  48. SpiFlashChip *flash = (SpiFlashChip*)(&flashchip + 4);
  49. char buf[128];
  50. SPIRead(flash->chip_size - 4 * 0x1000, buf, sizeof(buf));
  51. /*for (int i = 0; i < sizeof(buf); i++) {
  52. static char hexf[] = "%x ";
  53. ets_printf(hexf, buf[i]);
  54. }*/
  55. bool inited = false;
  56. for (int i = 0; i < sizeof(buf); i++) {
  57. if (buf[i] != 0xff) {
  58. inited = true;
  59. break;
  60. }
  61. }
  62. if (!inited) {
  63. static char msg[] = "Writing init data\n";
  64. ets_printf(msg);
  65. SPIRead((uint32_t)&default_init_data - 0x40200000, buf, sizeof(buf));
  66. SPIWrite(flash->chip_size - 4 * 0x1000, buf, sizeof(buf));
  67. }
  68. asm("j call_user_start");
  69. }