flip_store_firmwares.c 5.0 KB

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