luat_fs_air101.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. // #include "luat_conf_bsp.h"
  2. #include "luat_base.h"
  3. #include "luat_fs.h"
  4. #define LUAT_LOG_TAG "fs"
  5. #include "luat_log.h"
  6. #include "lfs_port.h"
  7. #include "wm_include.h"
  8. #include "luat_timer.h"
  9. #include "stdio.h"
  10. #include "luat_ota.h"
  11. #include "wm_internal_flash.h"
  12. extern struct lfs_config lfs_cfg;
  13. extern lfs_t lfs;
  14. // 分区信息
  15. // KV -- 64k
  16. // luadb -- N k
  17. // lfs - (112 + 64 - N)k
  18. uint32_t kv_addr;
  19. uint32_t kv_size_kb = 64;
  20. uint32_t luadb_addr;
  21. uint32_t luadb_size_kb;
  22. uint32_t lfs_addr;
  23. uint32_t lfs_size_kb;
  24. #ifndef FLASH_FS_REGION_SIZE
  25. #define FLASH_FS_REGION_SIZE 112
  26. #endif
  27. extern const struct luat_vfs_filesystem vfs_fs_lfs2;
  28. extern const char luadb_inline_sys[];
  29. extern const struct luat_vfs_filesystem vfs_fs_luadb;
  30. #ifdef LUAT_USE_LVGL
  31. #include "lvgl.h"
  32. void luat_lv_fs_init(void);
  33. // void lv_bmp_init(void);
  34. // void lv_png_init(void);
  35. void lv_split_jpeg_init(void);
  36. #endif
  37. // 调整LUADB文件系统大小, 必须是 48+64*N, N为整数. 例如 48+64, 48+128
  38. #ifndef LUAT_LUADB_ZONE_SIZE
  39. #define LUAT_LUADB_ZONE_SIZE (48)
  40. #endif
  41. int luat_fs_init(void) {
  42. //luat_timer_mdelay(1000);
  43. #ifdef AIR103
  44. luadb_addr = 0x0E0000 - (FLASH_FS_REGION_SIZE - 112) * 1024U;
  45. #else
  46. luadb_addr = 0x1E0000 - (FLASH_FS_REGION_SIZE - 112) * 1024U;
  47. #endif
  48. //LLOGD("luadb_addr 0x%08X", luadb_addr);
  49. uint8_t *ptr = (uint8_t*)(luadb_addr + 0x8000000); //0x80E0000
  50. //LLOGD("luadb_addr ptr %p", ptr);
  51. // 兼容老的LuaTools, 并提示更新
  52. static const uint8_t luadb_magic[] = {0x01, 0x04, 0x5A, 0xA5};
  53. uint8_t header[4];
  54. memcpy(header, ptr, 4);
  55. //LLOGD(">> %02X %02X %02X %02X", header[0], header[1], header[2], header[3]);
  56. if (memcmp(header, luadb_magic, 4)) {
  57. // 老的布局
  58. LLOGW("Legacy non-LuaDB download, please upgrade your LuatIDE or LuatTools %p", ptr);
  59. // lfs_addr = luadb_addr;
  60. // kv_addr = lfs_addr - kv_size_kb*1024U;
  61. // lfs_size_kb = FLASH_FS_REGION_SIZE;
  62. // luadb_addr = 0;
  63. }
  64. // else {
  65. //LLOGI("Using LuaDB as script zone format %p", ptr);
  66. #ifdef AIR103
  67. lfs_addr = 0x0FC000 - (LUAT_LUADB_ZONE_SIZE*1024);
  68. lfs_size_kb = LUAT_LUADB_ZONE_SIZE;
  69. #else
  70. lfs_addr = 0x1FC000 - (LUAT_LUADB_ZONE_SIZE*1024);
  71. lfs_size_kb = LUAT_LUADB_ZONE_SIZE;
  72. #endif
  73. kv_addr = luadb_addr - kv_size_kb*1024U;
  74. // }
  75. //LLOGD("lfs addr4 %p", &lfs_addr);
  76. //LLOGD("lfs addr5 0x%08X", lfs_addr);
  77. //LLOGD("luadb_addr 0x%08X", luadb_addr);
  78. LFS_Init();
  79. luat_vfs_reg(&vfs_fs_lfs2);
  80. luat_fs_conf_t conf = {
  81. .busname = &lfs,
  82. .type = "lfs2",
  83. .filesystem = "lfs2",
  84. .mount_point = "/"
  85. };
  86. luat_fs_mount(&conf);
  87. #ifdef LUAT_USE_OTA
  88. //OTA检测升级
  89. luat_ota(luadb_addr);
  90. #endif
  91. luat_vfs_reg(&vfs_fs_luadb);
  92. luat_fs_conf_t conf2 = {
  93. .busname = (char*)(ptr),
  94. .type = "luadb",
  95. .filesystem = "luadb",
  96. .mount_point = "/luadb/",
  97. };
  98. luat_fs_mount(&conf2);
  99. #ifdef LUAT_USE_LVGL
  100. luat_lv_fs_init();
  101. // lv_bmp_init();
  102. // lv_png_init();
  103. lv_split_jpeg_init();
  104. #endif
  105. return 0;
  106. }
  107. #ifdef LUAT_USE_OTA
  108. int luat_flash_write(uint32_t addr, uint8_t * buf, uint32_t len){
  109. return tls_fls_write(addr, buf, len);
  110. }
  111. #endif