fal.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * Copyright (c) 2006-2018, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2018-05-17 armink the first version
  9. */
  10. #include <fal.h>
  11. static uint8_t init_ok = 0;
  12. /**
  13. * FAL (Flash Abstraction Layer) initialization.
  14. * It will initialize all flash device and all flash partition.
  15. *
  16. * @return >= 0: partitions total number
  17. */
  18. int fal_init(void)
  19. {
  20. extern int fal_flash_init(void);
  21. extern int fal_partition_init(void);
  22. int result;
  23. /* initialize all flash device on FAL flash table */
  24. result = fal_flash_init();
  25. if (result < 0) {
  26. goto __exit;
  27. }
  28. /* initialize all flash partition on FAL partition table */
  29. result = fal_partition_init();
  30. __exit:
  31. if ((result > 0) && (!init_ok))
  32. {
  33. init_ok = 1;
  34. log_i("RT-Thread Flash Abstraction Layer initialize success.");
  35. }
  36. else if(result <= 0)
  37. {
  38. init_ok = 0;
  39. log_e("RT-Thread Flash Abstraction Layer initialize failed.");
  40. }
  41. return result;
  42. }
  43. /**
  44. * Check if the FAL is initialized successfully
  45. *
  46. * @return 0: not init or init failed; 1: init success
  47. */
  48. int fal_init_check(void)
  49. {
  50. return init_ok;
  51. }