luat_fs_air101.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. extern struct lfs_config lfs_cfg;
  11. extern lfs_t lfs;
  12. // 分区信息
  13. // KV -- 64k
  14. // luadb -- N k
  15. // lfs - (112 + 64 - N)k
  16. uint32_t kv_addr;
  17. uint32_t kv_size_kb = 64;
  18. uint32_t luadb_addr;
  19. uint32_t luadb_size_kb;
  20. uint32_t lfs_addr;
  21. uint32_t lfs_size_kb;
  22. #ifndef FLASH_FS_REGION_SIZE
  23. #define FLASH_FS_REGION_SIZE 112
  24. #endif
  25. extern const struct luat_vfs_filesystem vfs_fs_lfs2;
  26. extern const char luadb_inline_sys[];
  27. extern const struct luat_vfs_filesystem vfs_fs_luadb;
  28. #ifdef LUAT_USE_LVGL
  29. #include "lvgl.h"
  30. void luat_lv_fs_init(void);
  31. // void lv_bmp_init(void);
  32. // void lv_png_init(void);
  33. void lv_split_jpeg_init(void);
  34. #endif
  35. int luat_fs_init(void) {
  36. //luat_timer_mdelay(1000);
  37. #ifdef AIR103
  38. luadb_addr = 0x0E0000;
  39. #else
  40. luadb_addr = 0x1E0000;
  41. #endif
  42. //LLOGD("luadb_addr 0x%08X", luadb_addr);
  43. uint8_t *ptr = (uint8_t*)(luadb_addr + 0x8000000); //0x80E0000
  44. //LLOGD("luadb_addr ptr %p", ptr);
  45. // 兼容老的LuaTools, 并提示更新
  46. static const uint8_t luadb_magic[] = {0x01, 0x04, 0x5A, 0xA5};
  47. uint8_t header[4];
  48. memcpy(header, ptr, 4);
  49. //LLOGD(">> %02X %02X %02X %02X", header[0], header[1], header[2], header[3]);
  50. if (memcmp(header, luadb_magic, 4)) {
  51. // 老的布局
  52. LLOGW("Legacy non-LuaDB download, please upgrade your LuatIDE or LuatTools %p", ptr);
  53. lfs_addr = luadb_addr;
  54. kv_addr = lfs_addr - 64*1024;
  55. lfs_size_kb = FLASH_FS_REGION_SIZE;
  56. luadb_addr = 0;
  57. }
  58. else {
  59. LLOGI("Using LuaDB as script zone format %p", ptr);
  60. // TODO 根据LuaDB的区域动态调整?
  61. #ifdef AIR103
  62. lfs_addr = luadb_addr + 64*1024;
  63. lfs_size_kb = 48;
  64. #else
  65. lfs_addr = luadb_addr + 64*1024;
  66. lfs_size_kb = 48;
  67. #endif
  68. }
  69. //LLOGD("lfs addr4 %p", &lfs_addr);
  70. //LLOGD("lfs addr5 0x%08X", lfs_addr);
  71. //LLOGD("luadb_addr 0x%08X", luadb_addr);
  72. LFS_Init();
  73. luat_vfs_reg(&vfs_fs_lfs2);
  74. luat_fs_conf_t conf = {
  75. .busname = &lfs,
  76. .type = "lfs2",
  77. .filesystem = "lfs2",
  78. .mount_point = "/"
  79. };
  80. luat_fs_mount(&conf);
  81. luat_vfs_reg(&vfs_fs_luadb);
  82. luat_fs_conf_t conf2 = {
  83. .busname = (char*)(luadb_addr == 0 ? luadb_inline_sys : ptr),
  84. .type = "luadb",
  85. .filesystem = "luadb",
  86. .mount_point = "/luadb/",
  87. };
  88. luat_fs_mount(&conf2);
  89. #ifdef LUAT_USE_LVGL
  90. luat_lv_fs_init();
  91. // lv_bmp_init();
  92. // lv_png_init();
  93. lv_split_jpeg_init();
  94. #endif
  95. return 0;
  96. }