luat_fs_air101.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. extern const struct luat_vfs_filesystem vfs_fs_ram;
  31. extern size_t luat_luadb_act_size;
  32. #ifdef LUAT_USE_LVGL
  33. #include "lvgl.h"
  34. void luat_lv_fs_init(void);
  35. // void lv_bmp_init(void);
  36. // void lv_png_init(void);
  37. void lv_split_jpeg_init(void);
  38. #endif
  39. // 调整LUADB文件系统大小, 必须是 48+64*N, N为整数. 例如 48+64, 48+128
  40. #ifndef LUAT_LUADB_ZONE_SIZE
  41. #define LUAT_LUADB_ZONE_SIZE (48)
  42. #endif
  43. int luat_fs_init(void) {
  44. //luat_timer_mdelay(1000);
  45. #ifdef AIR103
  46. luadb_addr = 0x0E0000 - (FLASH_FS_REGION_SIZE - 112) * 1024U;
  47. #else
  48. luadb_addr = 0x1E0000 - (FLASH_FS_REGION_SIZE - 112) * 1024U;
  49. #endif
  50. //LLOGD("luadb_addr 0x%08X", luadb_addr);
  51. uint8_t *ptr = (uint8_t*)(luadb_addr + 0x8000000); //0x80E0000
  52. //LLOGD("luadb_addr ptr %p", ptr);
  53. // 兼容老的LuaTools, 并提示更新
  54. static const uint8_t luadb_magic[] = {0x01, 0x04, 0x5A, 0xA5};
  55. uint8_t header[4];
  56. memcpy(header, ptr, 4);
  57. //LLOGD(">> %02X %02X %02X %02X", header[0], header[1], header[2], header[3]);
  58. if (memcmp(header, luadb_magic, 4)) {
  59. // 老的布局
  60. LLOGW("Legacy non-LuaDB download, please upgrade your LuatIDE or LuatTools %p", ptr);
  61. // lfs_addr = luadb_addr;
  62. // kv_addr = lfs_addr - kv_size_kb*1024U;
  63. // lfs_size_kb = FLASH_FS_REGION_SIZE;
  64. // luadb_addr = 0;
  65. }
  66. // else {
  67. //LLOGI("Using LuaDB as script zone format %p", ptr);
  68. #ifdef AIR103
  69. lfs_addr = 0x0FC000 - (LUAT_LUADB_ZONE_SIZE*1024);
  70. lfs_size_kb = LUAT_LUADB_ZONE_SIZE;
  71. #else
  72. lfs_addr = 0x1FC000 - (LUAT_LUADB_ZONE_SIZE*1024);
  73. lfs_size_kb = LUAT_LUADB_ZONE_SIZE;
  74. #endif
  75. kv_addr = luadb_addr - kv_size_kb*1024U;
  76. // }
  77. //LLOGD("lfs addr4 %p", &lfs_addr);
  78. //LLOGD("lfs addr5 0x%08X", lfs_addr);
  79. //LLOGD("luadb_addr 0x%08X", luadb_addr);
  80. LFS_Init();
  81. luat_vfs_reg(&vfs_fs_lfs2);
  82. luat_fs_conf_t conf = {
  83. .busname = &lfs,
  84. .type = "lfs2",
  85. .filesystem = "lfs2",
  86. .mount_point = "/"
  87. };
  88. luat_fs_mount(&conf);
  89. luat_vfs_reg(&vfs_fs_ram);
  90. luat_fs_conf_t conf3 = {
  91. .busname = NULL,
  92. .type = "ram",
  93. .filesystem = "ram",
  94. .mount_point = "/ram/"
  95. };
  96. luat_fs_mount(&conf3);
  97. luat_vfs_reg(&vfs_fs_luadb);
  98. luat_fs_conf_t conf2 = {
  99. .busname = (char*)(ptr),
  100. .type = "luadb",
  101. .filesystem = "luadb",
  102. .mount_point = "/luadb/",
  103. };
  104. luat_fs_mount(&conf2);
  105. luat_luadb_act_size = (FLASH_FS_REGION_SIZE - 112);
  106. #ifdef LUAT_USE_LVGL
  107. luat_lv_fs_init();
  108. // lv_bmp_init();
  109. // lv_png_init();
  110. lv_split_jpeg_init();
  111. #endif
  112. return 0;
  113. }