xref: /openbmc/u-boot/doc/driver-model/fs_firmware_loader.txt (revision e807f6b5f9a164dc1fc35e1c733fa343acf335c0)
145029758STien Fong Chee# Copyright (C) 2018 Intel Corporation <www.intel.com>
245029758STien Fong Chee#
345029758STien Fong Chee# SPDX-License-Identifier:    GPL-2.0
445029758STien Fong Chee
545029758STien Fong CheeIntroduction
645029758STien Fong Chee============
745029758STien Fong Chee
845029758STien Fong CheeThis is file system firmware loader for U-Boot framework, which has very close
945029758STien Fong Cheeto some Linux Firmware API. For the details of Linux Firmware API, you can refer
1045029758STien Fong Cheeto https://01.org/linuxgraphics/gfx-docs/drm/driver-api/firmware/index.html.
1145029758STien Fong Chee
1245029758STien Fong CheeFile system firmware loader can be used to load whatever(firmware, image,
1345029758STien Fong Cheeand binary) from the storage device in file system format into target location
1445029758STien Fong Cheesuch as memory, then consumer driver such as FPGA driver can program FPGA image
1545029758STien Fong Cheefrom the target location into FPGA.
1645029758STien Fong Chee
1745029758STien Fong CheeTo enable firmware loader, CONFIG_FS_LOADER need to be set at
1845029758STien Fong Chee<board_name>_defconfig such as "CONFIG_FS_LOADER=y".
1945029758STien Fong Chee
2045029758STien Fong CheeFirmware Loader API core features
2145029758STien Fong Chee---------------------------------
2245029758STien Fong Chee
2345029758STien Fong CheeFirmware storage device described in device tree source
2445029758STien Fong Chee-------------------------------------------------------
2545029758STien Fong Chee	For passing data like storage device phandle and partition where the
2645029758STien Fong Chee	firmware loading from to the firmware loader driver, those data could be
2745029758STien Fong Chee	defined in fs-loader node as shown in below:
2845029758STien Fong Chee
2945029758STien Fong Chee	Example for block device:
3045029758STien Fong Chee	fs_loader0: fs-loader@0 {
3145029758STien Fong Chee		u-boot,dm-pre-reloc;
3245029758STien Fong Chee		compatible = "u-boot,fs-loader";
3345029758STien Fong Chee		phandlepart = <&mmc 1>;
3445029758STien Fong Chee	};
3545029758STien Fong Chee
3645029758STien Fong Chee	<&mmc 1> means block storage device pointer and its partition.
3745029758STien Fong Chee
3845029758STien Fong Chee	Above example is a description for block storage, but for UBI storage
3945029758STien Fong Chee	device, it can be described in FDT as shown in below:
4045029758STien Fong Chee
4145029758STien Fong Chee	Example for ubi:
4245029758STien Fong Chee	fs_loader1: fs-loader@1 {
4345029758STien Fong Chee		u-boot,dm-pre-reloc;
4445029758STien Fong Chee		compatible = "u-boot,fs-loader";
4545029758STien Fong Chee		mtdpart = "UBI",
4645029758STien Fong Chee		ubivol = "ubi0";
4745029758STien Fong Chee	};
4845029758STien Fong Chee
4945029758STien Fong Chee	Then, firmware_loader property would be set with the path of fs_loader
5045029758STien Fong Chee	node under /chosen node such as:
5145029758STien Fong Chee	/{
5245029758STien Fong Chee		chosen {
5345029758STien Fong Chee			firmware_loader = &fs_loader0;
5445029758STien Fong Chee		};
5545029758STien Fong Chee	};
5645029758STien Fong Chee
5745029758STien Fong Chee	However, this driver is also designed to support U-boot environment
5845029758STien Fong Chee	variables, so all these data from FDT can be overwritten
5945029758STien Fong Chee	through the U-boot environment variable during run time.
6045029758STien Fong Chee	For examples:
6145029758STien Fong Chee	"storage_interface" - Storage interface, it can be "mmc", "usb", "sata"
6245029758STien Fong Chee						  or "ubi".
6345029758STien Fong Chee	"fw_dev_part" - Block device number and its partition, it can be "0:1".
6445029758STien Fong Chee	"fw_ubi_mtdpart" - UBI device mtd partition, it can be "UBI".
6545029758STien Fong Chee	"fw_ubi_volume" - UBI volume, it can be "ubi0".
6645029758STien Fong Chee
6745029758STien Fong Chee	When above environment variables are set, environment values would be
6845029758STien Fong Chee	used instead of data from FDT.
6945029758STien Fong Chee	The benefit of this design allows user to change storage attribute data
7045029758STien Fong Chee	at run time through U-boot console and saving the setting as default
7145029758STien Fong Chee	environment values in the storage for the next power cycle, so no
7245029758STien Fong Chee	compilation is required for both driver and FDT.
7345029758STien Fong Chee
7445029758STien Fong CheeFile system firmware Loader API
7545029758STien Fong Chee-------------------------------
7645029758STien Fong Chee
77*31a2cf1cSTien Fong Cheeint request_firmware_into_buf(struct udevice *dev,
7845029758STien Fong Chee				 const char *name,
79*31a2cf1cSTien Fong Chee				 void *buf, size_t size, u32 offset)
8045029758STien Fong Chee--------------------------------------------------------------------
8145029758STien Fong CheeLoad firmware into a previously allocated buffer
8245029758STien Fong Chee
8345029758STien Fong CheeParameters:
8445029758STien Fong Chee
85*31a2cf1cSTien Fong Chee1. struct udevice *dev
86*31a2cf1cSTien Fong Chee	An instance of a driver
8745029758STien Fong Chee
8845029758STien Fong Chee2. const char *name
8945029758STien Fong Chee	name of firmware file
9045029758STien Fong Chee
9145029758STien Fong Chee3. void *buf
9245029758STien Fong Chee	address of buffer to load firmware into
9345029758STien Fong Chee
9445029758STien Fong Chee4. size_t size
9545029758STien Fong Chee	size of buffer
9645029758STien Fong Chee
9745029758STien Fong Chee5. u32 offset
9845029758STien Fong Chee	offset of a file for start reading into buffer
9945029758STien Fong Chee
10045029758STien Fong Cheereturn:
10145029758STien Fong Chee	size of total read
10245029758STien Fong Chee	-ve when error
10345029758STien Fong Chee
10445029758STien Fong CheeDescription:
105*31a2cf1cSTien Fong Chee	The firmware is loaded directly into the buffer pointed to by buf
10645029758STien Fong Chee
10745029758STien Fong CheeExample of creating firmware loader instance and calling
10845029758STien Fong Cheerequest_firmware_into_buf API:
10945029758STien Fong Chee	if (uclass_get_device(UCLASS_FS_FIRMWARE_LOADER, 0, &dev)) {
110*31a2cf1cSTien Fong Chee		request_firmware_into_buf(dev, filename, buffer_location,
111*31a2cf1cSTien Fong Chee					 buffer_size, offset_ofreading);
11245029758STien Fong Chee	}
113