1 # Copyright (C) 2018-2019 Intel Corporation <www.intel.com>
3 # SPDX-License-Identifier: GPL-2.0
8 This is file system firmware loader for U-Boot framework, which has very close
9 to some Linux Firmware API. For the details of Linux Firmware API, you can refer
10 to https://01.org/linuxgraphics/gfx-docs/drm/driver-api/firmware/index.html.
12 File system firmware loader can be used to load whatever(firmware, image,
13 and binary) from the storage device in file system format into target location
14 such as memory, then consumer driver such as FPGA driver can program FPGA image
15 from the target location into FPGA.
17 To enable firmware loader, CONFIG_FS_LOADER need to be set at
18 <board_name>_defconfig such as "CONFIG_FS_LOADER=y".
20 Firmware Loader API core features
21 ---------------------------------
23 Firmware storage device described in device tree source
24 -------------------------------------------------------
25 For passing data like storage device phandle and partition where the
26 firmware loading from to the firmware loader driver, those data could be
27 defined in fs-loader node as shown in below:
29 Example for block device:
30 fs_loader0: fs-loader {
32 compatible = "u-boot,fs-loader";
33 phandlepart = <&mmc 1>;
36 <&mmc 1> means block storage device pointer and its partition.
38 Above example is a description for block storage, but for UBI storage
39 device, it can be described in FDT as shown in below:
42 fs_loader1: fs-loader {
44 compatible = "u-boot,fs-loader";
49 Then, firmware-loader property can be added with any device node, which
50 driver would use the firmware loader for loading.
52 The value of the firmware-loader property should be set with phandle
53 of the fs-loader node.
55 firmware-loader = <&fs_loader0>;
57 If there are majority of devices using the same fs-loader node, then
58 firmware-loader property can be added under /chosen node instead of
59 adding to each of device node.
64 firmware-loader = <&fs_loader0>;
68 In each respective driver of devices using firmware loader, the firmware
69 loaded instance should be created by DT phandle.
71 For example of getting DT phandle from /chosen and creating instance:
72 chosen_node = ofnode_path("/chosen");
73 if (!ofnode_valid(chosen_node)) {
74 debug("/chosen node was not found.\n");
78 phandle_p = ofnode_get_property(chosen_node, "firmware-loader", &size);
80 debug("firmware-loader property was not found.\n");
84 phandle = fdt32_to_cpu(*phandle_p);
85 ret = uclass_get_device_by_phandle_id(UCLASS_FS_FIRMWARE_LOADER,
90 Firmware loader driver is also designed to support U-boot environment
91 variables, so all these data from FDT can be overwritten
92 through the U-boot environment variable during run time.
94 "storage_interface" - Storage interface, it can be "mmc", "usb", "sata"
96 "fw_dev_part" - Block device number and its partition, it can be "0:1".
97 "fw_ubi_mtdpart" - UBI device mtd partition, it can be "UBI".
98 "fw_ubi_volume" - UBI volume, it can be "ubi0".
100 When above environment variables are set, environment values would be
101 used instead of data from FDT.
102 The benefit of this design allows user to change storage attribute data
103 at run time through U-boot console and saving the setting as default
104 environment values in the storage for the next power cycle, so no
105 compilation is required for both driver and FDT.
107 File system firmware Loader API
108 -------------------------------
110 int request_firmware_into_buf(struct udevice *dev,
112 void *buf, size_t size, u32 offset)
113 --------------------------------------------------------------------
114 Load firmware into a previously allocated buffer
118 1. struct udevice *dev
119 An instance of a driver
122 name of firmware file
125 address of buffer to load firmware into
131 offset of a file for start reading into buffer
138 The firmware is loaded directly into the buffer pointed to by buf
140 Example of calling request_firmware_into_buf API after creating firmware loader
142 ret = uclass_get_device_by_phandle_id(UCLASS_FS_FIRMWARE_LOADER,
147 request_firmware_into_buf(dev, filename, buffer_location, buffer_size,