mnt_cromfs.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. * Copyright (c) 2006-2023, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2024-06-18 Shell add cromfs support
  9. */
  10. #define DBG_TAG "app.filesystem"
  11. #define DBG_LVL DBG_LOG
  12. #include <rtdbg.h>
  13. #include <dfs_cromfs.h>
  14. #include <dfs_posix.h>
  15. #include <dfs_fs.h>
  16. #include <ioremap.h>
  17. #include <mmu.h>
  18. #include <rtthread.h>
  19. #include <unistd.h>
  20. struct _mount_table
  21. {
  22. char *dev_name;
  23. char *mount_point;
  24. char *fs_name;
  25. long rwflag;
  26. void *data;
  27. };
  28. struct _mount_table _mount_table[] = {
  29. [0] = {NULL, "/", "crom", 0, 0},
  30. };
  31. static int _wait_device_ready(const char* devname)
  32. {
  33. int k;
  34. for(k = 0; k < 10; k++)
  35. {
  36. if (rt_device_find(devname) != RT_NULL)
  37. {
  38. return 1;
  39. }
  40. rt_thread_mdelay(50);
  41. }
  42. return 0;
  43. }
  44. int mnt_init(void)
  45. {
  46. int i;
  47. uint32_t crom_data_len = 0;
  48. uint32_t length;
  49. _mount_table[0].data = cromfs_get_partition_data(&length);
  50. crom_data_len = length;
  51. if (_mount_table[0].data && (crom_data_len > 0))
  52. {
  53. for (i = 0; i < sizeof(_mount_table) / sizeof(_mount_table[0]); i++)
  54. {
  55. if (_mount_table[i].dev_name && !_wait_device_ready(_mount_table[i].dev_name))
  56. {
  57. LOG_E("device %s find timeout", _mount_table[i].dev_name);
  58. continue;
  59. }
  60. if (dfs_mount(_mount_table[i].dev_name, _mount_table[i].mount_point,
  61. _mount_table[i].fs_name, _mount_table[i].rwflag, _mount_table[i].data) != 0)
  62. {
  63. LOG_E("Dir %s %s mount failed!", _mount_table[i].mount_point,
  64. _mount_table[i].dev_name ? _mount_table[i].dev_name : _mount_table[i].fs_name);
  65. }
  66. else
  67. {
  68. LOG_I("Dir %s %s mount ok!", _mount_table[i].mount_point,
  69. _mount_table[i].dev_name ? _mount_table[i].dev_name : _mount_table[i].fs_name);
  70. }
  71. }
  72. }
  73. else
  74. {
  75. LOG_E("No mount data found!");
  76. }
  77. mkdir("/dev/shm", 0777);
  78. if (dfs_mount(NULL, "/dev/shm", "tmp", 0, 0) != 0)
  79. {
  80. LOG_E("Dir %s %s mount failed!", "/dev/shm", "tmp");
  81. }
  82. else
  83. {
  84. LOG_I("Dir %s %s mount ok!", "/dev/shm", "tmp");
  85. }
  86. LOG_I("file system initialization done!\n");
  87. return 0;
  88. }
  89. INIT_ENV_EXPORT(mnt_init);