luat_fs_air101.c 2.9 KB

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