flip_store_firmwares.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #include <firmwares/flip_store_firmwares.h>
  2. Firmware *firmwares = NULL;
  3. VGMFirmware *vgm_firmwares = NULL;
  4. bool is_esp32_firmware = true;
  5. Firmware *firmware_alloc()
  6. {
  7. Firmware *fw = (Firmware *)malloc(FIRMWARE_COUNT * sizeof(Firmware));
  8. if (!fw)
  9. {
  10. FURI_LOG_E(TAG, "Failed to allocate memory for Firmware");
  11. return NULL;
  12. }
  13. // Black Magic
  14. snprintf(fw[0].name, sizeof(fw[0].name), "%s", "Black Magic");
  15. snprintf(fw[0].links[0], sizeof(fw[0].links[0]), "%s", "https://raw.githubusercontent.com/FZEEFlasher/fzeeflasher.github.io/main/resources/STATIC/BM/bootloader.bin");
  16. snprintf(fw[0].links[1], sizeof(fw[0].links[1]), "%s", "https://raw.githubusercontent.com/FZEEFlasher/fzeeflasher.github.io/main/resources/STATIC/BM/partition-table.bin");
  17. snprintf(fw[0].links[2], sizeof(fw[0].links[2]), "%s", "https://raw.githubusercontent.com/FZEEFlasher/fzeeflasher.github.io/main/resources/STATIC/BM/blackmagic.bin");
  18. // FlipperHTTP
  19. snprintf(fw[1].name, sizeof(fw[1].name), "%s", "FlipperHTTP");
  20. snprintf(fw[1].links[0], sizeof(fw[1].links[0]), "%s", "https://raw.githubusercontent.com/jblanked/FlipperHTTP/main/WiFi%20Developer%20Board%20(ESP32S2)/flipper_http_bootloader.bin");
  21. snprintf(fw[1].links[1], sizeof(fw[1].links[1]), "%s", "https://raw.githubusercontent.com/jblanked/FlipperHTTP/main/WiFi%20Developer%20Board%20(ESP32S2)/flipper_http_firmware_a.bin");
  22. snprintf(fw[1].links[2], sizeof(fw[1].links[2]), "%s", "https://raw.githubusercontent.com/jblanked/FlipperHTTP/main/WiFi%20Developer%20Board%20(ESP32S2)/flipper_http_partitions.bin");
  23. // Marauder
  24. snprintf(fw[2].name, sizeof(fw[2].name), "%s", "Marauder");
  25. snprintf(fw[2].links[0], sizeof(fw[2].links[0]), "%s", "https://raw.githubusercontent.com/FZEEFlasher/fzeeflasher.github.io/main/resources/STATIC/M/FLIPDEV/esp32_marauder.ino.bootloader.bin");
  26. snprintf(fw[2].links[1], sizeof(fw[2].links[1]), "%s", "https://raw.githubusercontent.com/FZEEFlasher/fzeeflasher.github.io/main/resources/STATIC/M/FLIPDEV/esp32_marauder.ino.partitions.bin");
  27. snprintf(fw[2].links[2], sizeof(fw[2].links[2]), "%s", "https://raw.githubusercontent.com/FZEEFlasher/fzeeflasher.github.io/main/resources/CURRENT/esp32_marauder_v1_2_0_12192024_flipper.bin");
  28. return fw;
  29. }
  30. VGMFirmware *vgm_firmware_alloc()
  31. {
  32. VGMFirmware *fw = (VGMFirmware *)malloc(VGM_FIRMWARE_COUNT * sizeof(VGMFirmware));
  33. if (!fw)
  34. {
  35. FURI_LOG_E(TAG, "Failed to allocate memory for VGM Firmware");
  36. return NULL;
  37. }
  38. // FlipperHTTP
  39. snprintf(fw[0].name, sizeof(fw[0].name), "%s", "FlipperHTTP");
  40. snprintf(fw[0].link, sizeof(fw[0].link), "%s", "https://raw.githubusercontent.com/jblanked/FlipperHTTP/main/Video%20Game%20Module/MicroPython/flipper_http_vgm_micro_python.uf2");
  41. return fw;
  42. }
  43. void firmware_free()
  44. {
  45. if (firmwares)
  46. {
  47. free(firmwares);
  48. firmwares = NULL;
  49. }
  50. }
  51. void vgm_firmware_free()
  52. {
  53. if (vgm_firmwares)
  54. {
  55. free(vgm_firmwares);
  56. vgm_firmwares = NULL;
  57. }
  58. }
  59. bool flip_store_get_firmware_file(FlipperHTTP *fhttp, char *link, char *name, char *filename)
  60. {
  61. if (!fhttp)
  62. {
  63. FURI_LOG_E(TAG, "FlipperHTTP is NULL");
  64. return false;
  65. }
  66. if (fhttp->state == INACTIVE)
  67. {
  68. return false;
  69. }
  70. Storage *storage = furi_record_open(RECORD_STORAGE);
  71. char directory_path[64];
  72. // save in ESP32 flasher directory
  73. if (is_esp32_firmware)
  74. {
  75. snprintf(directory_path, sizeof(directory_path), STORAGE_EXT_PATH_PREFIX "/apps_data/esp_flasher");
  76. storage_common_mkdir(storage, directory_path);
  77. snprintf(directory_path, sizeof(directory_path), STORAGE_EXT_PATH_PREFIX "/apps_data/esp_flasher/%s", firmwares[selected_firmware_index].name);
  78. storage_common_mkdir(storage, directory_path);
  79. snprintf(fhttp->file_path, sizeof(fhttp->file_path), STORAGE_EXT_PATH_PREFIX "/apps_data/esp_flasher/%s/%s", name, filename);
  80. }
  81. else // install in app_data directory
  82. {
  83. snprintf(directory_path, sizeof(directory_path), STORAGE_EXT_PATH_PREFIX "/apps_data/vgm");
  84. storage_common_mkdir(storage, directory_path);
  85. snprintf(directory_path, sizeof(directory_path), STORAGE_EXT_PATH_PREFIX "/apps_data/vgm/%s", name);
  86. storage_common_mkdir(storage, directory_path);
  87. snprintf(fhttp->file_path, sizeof(fhttp->file_path), STORAGE_EXT_PATH_PREFIX "/apps_data/vgm/%s/%s", name, filename);
  88. }
  89. furi_record_close(RECORD_STORAGE);
  90. fhttp->save_received_data = false;
  91. fhttp->is_bytes_request = true;
  92. return flipper_http_get_request_bytes(fhttp, link, "{\"Content-Type\":\"application/octet-stream\"}");
  93. }