luat_fs_air101.c 2.7 KB

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