flip_store_firmwares.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #include <firmwares/flip_store_firmwares.h>
  2. Firmware *firmwares = NULL;
  3. bool sent_firmware_request = false;
  4. bool sent_firmware_request_2 = false;
  5. bool sent_firmware_request_3 = false;
  6. //
  7. bool firmware_request_success = false;
  8. bool firmware_request_success_2 = false;
  9. bool firmware_request_success_3 = false;
  10. //
  11. bool firmware_download_success = false;
  12. bool firmware_download_success_2 = false;
  13. bool firmware_download_success_3 = false;
  14. Firmware *firmware_alloc()
  15. {
  16. Firmware *fw = (Firmware *)malloc(FIRMWARE_COUNT * sizeof(Firmware));
  17. if (!fw)
  18. {
  19. FURI_LOG_E(TAG, "Failed to allocate memory for Firmware");
  20. return NULL;
  21. }
  22. for (int i = 0; i < FIRMWARE_COUNT; i++)
  23. {
  24. if (fw[i].name == NULL)
  25. {
  26. fw[i].name = (char *)malloc(16);
  27. if (!fw[i].name)
  28. {
  29. FURI_LOG_E(TAG, "Failed to allocate memory for Firmware name");
  30. return NULL;
  31. }
  32. }
  33. for (int j = 0; j < FIRMWARE_LINKS; j++)
  34. {
  35. if (fw[i].links[j] == NULL)
  36. {
  37. fw[i].links[j] = (char *)malloc(256);
  38. if (!fw[i].links[j])
  39. {
  40. FURI_LOG_E(TAG, "Failed to allocate memory for Firmware links");
  41. return NULL;
  42. }
  43. }
  44. }
  45. }
  46. // Black Magic
  47. fw[0].name = "Black Magic";
  48. fw[0].links[0] = "https://raw.githubusercontent.com/FZEEFlasher/fzeeflasher.github.io/main/resources/STATIC/BM/bootloader.bin";
  49. fw[0].links[1] = "https://raw.githubusercontent.com/FZEEFlasher/fzeeflasher.github.io/main/resources/STATIC/BM/partition-table.bin";
  50. fw[0].links[2] = "https://raw.githubusercontent.com/FZEEFlasher/fzeeflasher.github.io/main/resources/STATIC/BM/blackmagic.bin";
  51. // FlipperHTTP
  52. fw[1].name = "FlipperHTTP";
  53. fw[1].links[0] = "https://raw.githubusercontent.com/jblanked/FlipperHTTP/main/WiFi%20Developer%20Board%20(ESP32S2)/flipper_http_bootloader.bin";
  54. fw[1].links[1] = "https://raw.githubusercontent.com/jblanked/FlipperHTTP/main/WiFi%20Developer%20Board%20(ESP32S2)/flipper_http_firmware_a.bin";
  55. fw[1].links[2] = "https://raw.githubusercontent.com/jblanked/FlipperHTTP/main/WiFi%20Developer%20Board%20(ESP32S2)/flipper_http_partitions.bin";
  56. // Marauder
  57. fw[2].name = "Marauder";
  58. fw[2].links[0] = "https://raw.githubusercontent.com/FZEEFlasher/fzeeflasher.github.io/main/resources/STATIC/M/FLIPDEV/esp32_marauder.ino.bootloader.bin";
  59. fw[2].links[1] = "https://raw.githubusercontent.com/FZEEFlasher/fzeeflasher.github.io/main/resources/STATIC/M/FLIPDEV/esp32_marauder.ino.partitions.bin";
  60. fw[2].links[2] = "https://raw.githubusercontent.com/FZEEFlasher/fzeeflasher.github.io/main/resources/CURRENT/esp32_marauder_v1_1_0_20241128_flipper.bin";
  61. // https://api.github.com/repos/FZEEFlasher/fzeeflasher.github.io/contents/resources/STATIC/BM/bootloader.bin
  62. // https://api.github.com/repos/FZEEFlasher/fzeeflasher.github.io/contents/resources/STATIC/BM/partition-table.bin
  63. // https://api.github.com/repos/FZEEFlasher/fzeeflasher.github.io/contents/resources/STATIC/BM/blackmagic.bin
  64. // https://api.github.com/repos/jblanked/FlipperHTTP/contents/flipper_http_bootloader.bin
  65. // https://api.github.com/repos/jblanked/FlipperHTTP/contents/flipper_http_firmware_a.bin
  66. // https://api.github.com/repos/jblanked/FlipperHTTP/contents/flipper_http_partitions.bin
  67. // https://api.github.com/repos/FZEEFlasher/fzeeflasher.github.io/contents/resources/STATIC/M/FLIPDEV/esp32_marauder.ino.bootloader.bin
  68. // https://api.github.com/repos/FZEEFlasher/fzeeflasher.github.io/contents/resources/STATIC/M/FLIPDEV/esp32_marauder.ino.partitions.bin
  69. // https://api.github.com/repos/FZEEFlasher/fzeeflasher.github.io/contents/resources/CURRENT/esp32_marauder_v1_0_0_20240626_flipper.bin
  70. return fw;
  71. }
  72. void firmware_free()
  73. {
  74. if (firmwares)
  75. {
  76. free(firmwares);
  77. firmwares = NULL;
  78. }
  79. }
  80. bool flip_store_get_firmware_file(FlipperHTTP *fhttp, char *link, char *name, char *filename)
  81. {
  82. if (!fhttp)
  83. {
  84. FURI_LOG_E(TAG, "FlipperHTTP is NULL");
  85. return false;
  86. }
  87. if (fhttp->state == INACTIVE)
  88. {
  89. return false;
  90. }
  91. Storage *storage = furi_record_open(RECORD_STORAGE);
  92. char directory_path[64];
  93. snprintf(directory_path, sizeof(directory_path), STORAGE_EXT_PATH_PREFIX "/apps_data/esp_flasher");
  94. storage_common_mkdir(storage, directory_path);
  95. snprintf(directory_path, sizeof(directory_path), STORAGE_EXT_PATH_PREFIX "/apps_data/esp_flasher/%s", firmwares[selected_firmware_index].name);
  96. storage_common_mkdir(storage, directory_path);
  97. snprintf(fhttp->file_path, sizeof(fhttp->file_path), STORAGE_EXT_PATH_PREFIX "/apps_data/esp_flasher/%s/%s", name, filename);
  98. furi_record_close(RECORD_STORAGE);
  99. fhttp->save_received_data = false;
  100. fhttp->is_bytes_request = true;
  101. bool sent_request = flipper_http_get_request_bytes(fhttp, link, "{\"Content-Type\":\"application/octet-stream\"}");
  102. if (sent_request)
  103. {
  104. fhttp->state = RECEIVING;
  105. return true;
  106. }
  107. fhttp->state = ISSUE;
  108. return false;
  109. }