luat_fs_air101.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. const uint32_t luat_rom_addr_start = 0x8010000;
  23. #ifdef AIR103
  24. const uint32_t luat_rom_addr_end = 0x80FFFFF;
  25. #else
  26. const uint32_t luat_rom_addr_end = 0x81FFFFF;
  27. #endif
  28. #ifndef FLASH_FS_REGION_SIZE
  29. #define FLASH_FS_REGION_SIZE 112
  30. #endif
  31. extern const struct luat_vfs_filesystem vfs_fs_lfs2;
  32. extern const char luadb_inline_sys[];
  33. extern const struct luat_vfs_filesystem vfs_fs_luadb;
  34. #ifdef LUAT_USE_LVGL
  35. #include "lvgl.h"
  36. void luat_lv_fs_init(void);
  37. // void lv_bmp_init(void);
  38. // void lv_png_init(void);
  39. void lv_split_jpeg_init(void);
  40. #endif
  41. int luat_fs_init(void) {
  42. //luat_timer_mdelay(1000);
  43. #ifdef AIR103
  44. luadb_addr = 0x0E0000;
  45. #else
  46. luadb_addr = 0x1E0000;
  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 - 64*1024;
  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. // TODO 根据LuaDB的区域动态调整?
  67. #ifdef AIR103
  68. lfs_addr = luadb_addr + 64*1024;
  69. lfs_size_kb = 48;
  70. #else
  71. lfs_addr = luadb_addr + 64*1024;
  72. lfs_size_kb = 48;
  73. #endif
  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. luat_vfs_reg(&vfs_fs_luadb);
  88. luat_fs_conf_t conf2 = {
  89. .busname = (char*)(luadb_addr == 0 ? luadb_inline_sys : ptr),
  90. .type = "luadb",
  91. .filesystem = "luadb",
  92. .mount_point = "/luadb/",
  93. };
  94. luat_fs_mount(&conf2);
  95. #ifdef LUAT_USE_LVGL
  96. luat_lv_fs_init();
  97. // lv_bmp_init();
  98. // lv_png_init();
  99. lv_split_jpeg_init();
  100. #endif
  101. return 0;
  102. }