From d551647f3bce231df4a90504e6d3ccb3b38a6f7a Mon Sep 17 00:00:00 2001 From: Prasad Sodagudi Date: Tue, 10 May 2022 13:47:07 -0700 Subject: [PATCH] ANDROID: firmware_loader: Add support for customer firmware paths Currently firmware_class.patch commandline can take a single path for loading firmwares on custom paths. SoC vendors and oems can have firmwares in multiple file system paths. So add support for paassing multiple paths through command line for firmware loader. For example - firmware_class.path="/vendor,/vendor/firmware_mnt, /oem/firmware". firmware_class.path can take upto 10 file system paths with ',' separation. Bug: 202192667 Change-Id: I31d1470d7dd0255c7aefd856f3c129bdb4b7f2e8 Signed-off-by: Prasad Sodagudi --- drivers/base/firmware_loader/main.c | 57 ++++++++++++++++++++++++++--- 1 file changed, 51 insertions(+), 6 deletions(-) diff --git a/drivers/base/firmware_loader/main.c b/drivers/base/firmware_loader/main.c index ef904b8b112e..31006da3840a 100644 --- a/drivers/base/firmware_loader/main.c +++ b/drivers/base/firmware_loader/main.c @@ -464,22 +464,67 @@ static int fw_decompress_xz(struct device *dev, struct fw_priv *fw_priv, #endif /* CONFIG_FW_LOADER_COMPRESS */ /* direct firmware loading support */ -static char fw_path_para[256]; +#define CUSTOM_FW_PATH_COUNT 10 +#define PATH_SIZE 255 +static char fw_path_para[CUSTOM_FW_PATH_COUNT][PATH_SIZE]; static const char * const fw_path[] = { - fw_path_para, + fw_path_para[0], + fw_path_para[1], + fw_path_para[2], + fw_path_para[3], + fw_path_para[4], + fw_path_para[5], + fw_path_para[6], + fw_path_para[7], + fw_path_para[8], + fw_path_para[9], "/lib/firmware/updates/" UTS_RELEASE, "/lib/firmware/updates", "/lib/firmware/" UTS_RELEASE, "/lib/firmware" }; +static char strpath[PATH_SIZE * CUSTOM_FW_PATH_COUNT]; +static int __init firmware_param_path_set(char *val) +{ + int i; + char *path, *end; + + strcpy(strpath, val); + /* Remove leading and trailing spaces from path */ + path = strim(strpath); + for (i = 0; path && i < CUSTOM_FW_PATH_COUNT; i++) { + end = strchr(path, ','); + + /* Skip continuous token case, for example ',,,' */ + if (end == path) { + i--; + path = ++end; + continue; + } + + if (end != NULL) + *end = '\0'; + else { + /* end of the string reached and no other tockens ',' */ + strncpy(fw_path_para[i], path, PATH_SIZE); + break; + } + + strncpy(fw_path_para[i], path, PATH_SIZE); + path = ++end; + } + + return 1; +} + /* - * Typical usage is that passing 'firmware_class.path=$CUSTOMIZED_PATH' + * Typical usage is that passing 'firmware_class.path=/vendor,/firwmare_mnt' * from kernel command line because firmware_class is generally built in - * kernel instead of module. + * kernel instead of module. ',' is used as delimiter for setting 10 + * custom paths for firmware loader. */ -module_param_string(path, fw_path_para, sizeof(fw_path_para), 0644); -MODULE_PARM_DESC(path, "customized firmware image search path with a higher priority than default path"); +__setup("firmware_class.path=", firmware_param_path_set); static int fw_get_filesystem_firmware(struct device *device, struct fw_priv *fw_priv,