fs_firmware_loader.rst 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. .. SPDX-License-Identifier: GPL-2.0+
  2. .. Copyright (C) 2018-2019 Intel Corporation <www.intel.com>
  3. File System Firmware Loader
  4. ===========================
  5. This is file system firmware loader for U-Boot framework, which has very close
  6. to some Linux Firmware API. For the details of Linux Firmware API, you can refer
  7. to https://01.org/linuxgraphics/gfx-docs/drm/driver-api/firmware/index.html.
  8. File system firmware loader can be used to load whatever(firmware, image,
  9. and binary) from the storage device in file system format into target location
  10. such as memory, then consumer driver such as FPGA driver can program FPGA image
  11. from the target location into FPGA.
  12. To enable firmware loader, CONFIG_FS_LOADER need to be set at
  13. <board_name>_defconfig such as "CONFIG_FS_LOADER=y".
  14. Firmware Loader API core features
  15. ---------------------------------
  16. Firmware storage device described in device tree source
  17. -------------------------------------------------------
  18. For passing data like storage device phandle and partition where the
  19. firmware loading from to the firmware loader driver, those data could be
  20. defined in fs-loader node as shown in below:
  21. Example for block device::
  22. fs_loader0: fs-loader {
  23. u-boot,dm-pre-reloc;
  24. compatible = "u-boot,fs-loader";
  25. phandlepart = <&mmc 1>;
  26. };
  27. <&mmc 1> means block storage device pointer and its partition.
  28. Above example is a description for block storage, but for UBI storage
  29. device, it can be described in FDT as shown in below:
  30. Example for ubi::
  31. fs_loader1: fs-loader {
  32. u-boot,dm-pre-reloc;
  33. compatible = "u-boot,fs-loader";
  34. mtdpart = "UBI",
  35. ubivol = "ubi0";
  36. };
  37. Then, firmware-loader property can be added with any device node, which
  38. driver would use the firmware loader for loading.
  39. The value of the firmware-loader property should be set with phandle
  40. of the fs-loader node. For example::
  41. firmware-loader = <&fs_loader0>;
  42. If there are majority of devices using the same fs-loader node, then
  43. firmware-loader property can be added under /chosen node instead of
  44. adding to each of device node.
  45. For example::
  46. /{
  47. chosen {
  48. firmware-loader = <&fs_loader0>;
  49. };
  50. };
  51. In each respective driver of devices using firmware loader, the firmware
  52. loaded instance should be created by DT phandle.
  53. For example of getting DT phandle from /chosen and creating instance:
  54. .. code-block:: c
  55. chosen_node = ofnode_path("/chosen");
  56. if (!ofnode_valid(chosen_node)) {
  57. debug("/chosen node was not found.\n");
  58. return -ENOENT;
  59. }
  60. phandle_p = ofnode_get_property(chosen_node, "firmware-loader", &size);
  61. if (!phandle_p) {
  62. debug("firmware-loader property was not found.\n");
  63. return -ENOENT;
  64. }
  65. phandle = fdt32_to_cpu(*phandle_p);
  66. ret = uclass_get_device_by_phandle_id(UCLASS_FS_FIRMWARE_LOADER,
  67. phandle, &dev);
  68. if (ret)
  69. return ret;
  70. Firmware loader driver is also designed to support U-boot environment
  71. variables, so all these data from FDT can be overwritten
  72. through the U-boot environment variable during run time.
  73. For examples:
  74. storage_interface:
  75. Storage interface, it can be "mmc", "usb", "sata" or "ubi".
  76. fw_dev_part:
  77. Block device number and its partition, it can be "0:1".
  78. fw_ubi_mtdpart:
  79. UBI device mtd partition, it can be "UBI".
  80. fw_ubi_volume:
  81. UBI volume, it can be "ubi0".
  82. When above environment variables are set, environment values would be
  83. used instead of data from FDT.
  84. The benefit of this design allows user to change storage attribute data
  85. at run time through U-boot console and saving the setting as default
  86. environment values in the storage for the next power cycle, so no
  87. compilation is required for both driver and FDT.
  88. File system firmware Loader API
  89. -------------------------------
  90. .. code-block:: c
  91. int request_firmware_into_buf(struct udevice *dev,
  92. const char *name,
  93. void *buf, size_t size, u32 offset)
  94. Load firmware into a previously allocated buffer
  95. Parameters:
  96. * struct udevice \*dev: An instance of a driver
  97. * const char \*name: name of firmware file
  98. * void \*buf: address of buffer to load firmware into
  99. * size_t size: size of buffer
  100. * u32 offset: offset of a file for start reading into buffer
  101. Returns:
  102. size of total read
  103. -ve when error
  104. Description:
  105. The firmware is loaded directly into the buffer pointed to by buf
  106. Example of calling request_firmware_into_buf API after creating firmware loader
  107. instance:
  108. .. code-block:: c
  109. ret = uclass_get_device_by_phandle_id(UCLASS_FS_FIRMWARE_LOADER,
  110. phandle, &dev);
  111. if (ret)
  112. return ret;
  113. request_firmware_into_buf(dev, filename, buffer_location, buffer_size,
  114. offset_ofreading);