Skip to content

Commit ac1a02d

Browse files
Prasad SodagudiTreehugger Robot
authored andcommitted
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. Add a getter function to read the class path. For example - firmware_class.path="/vendor,/vendor/firmware_mnt, /oem/firmware". firmware_class.path can take upto 10 file system paths with ',' separation. Bug: 259298396 Change-Id: I31d1470d7dd0255c7aefd856f3c129bdb4b7f2e8 Signed-off-by: Prasad Sodagudi <[email protected]> Signed-off-by: Vamsi Krishna Lanka <[email protected]> (cherry picked from commit ce17e29)
1 parent a06ae48 commit ac1a02d

File tree

1 file changed

+69
-5
lines changed
  • drivers/base/firmware_loader

1 file changed

+69
-5
lines changed

drivers/base/firmware_loader/main.c

Lines changed: 69 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -468,21 +468,85 @@ static int fw_decompress_xz(struct device *dev, struct fw_priv *fw_priv,
468468
#endif /* CONFIG_FW_LOADER_COMPRESS_XZ */
469469

470470
/* direct firmware loading support */
471-
static char fw_path_para[256];
471+
#define CUSTOM_FW_PATH_COUNT 10
472+
#define PATH_SIZE 255
473+
static char fw_path_para[CUSTOM_FW_PATH_COUNT][PATH_SIZE];
472474
static const char * const fw_path[] = {
473-
fw_path_para,
475+
fw_path_para[0],
476+
fw_path_para[1],
477+
fw_path_para[2],
478+
fw_path_para[3],
479+
fw_path_para[4],
480+
fw_path_para[5],
481+
fw_path_para[6],
482+
fw_path_para[7],
483+
fw_path_para[8],
484+
fw_path_para[9],
474485
"/lib/firmware/updates/" UTS_RELEASE,
475486
"/lib/firmware/updates",
476487
"/lib/firmware/" UTS_RELEASE,
477488
"/lib/firmware"
478489
};
479490

491+
static char strpath[PATH_SIZE * CUSTOM_FW_PATH_COUNT];
492+
static int firmware_param_path_set(const char *val, const struct kernel_param *kp)
493+
{
494+
int i;
495+
char *path, *end;
496+
497+
strscpy(strpath, val, sizeof(strpath));
498+
/* Remove leading and trailing spaces from path */
499+
path = strim(strpath);
500+
for (i = 0; path && i < CUSTOM_FW_PATH_COUNT; i++) {
501+
end = strchr(path, ',');
502+
503+
/* Skip continuous token case, for example ',,,' */
504+
if (end == path) {
505+
i--;
506+
path = ++end;
507+
continue;
508+
}
509+
510+
if (end != NULL)
511+
*end = '\0';
512+
else {
513+
/* end of the string reached and no other tockens ',' */
514+
strscpy(fw_path_para[i], path, PATH_SIZE);
515+
break;
516+
}
517+
518+
strscpy(fw_path_para[i], path, PATH_SIZE);
519+
path = ++end;
520+
}
521+
522+
return 0;
523+
}
524+
525+
static int firmware_param_path_get(char *buffer, const struct kernel_param *kp)
526+
{
527+
int count = 0, i;
528+
529+
for (i = 0; i < CUSTOM_FW_PATH_COUNT; i++) {
530+
if (strlen(fw_path_para[i]) != 0)
531+
count += scnprintf(buffer + count, PATH_SIZE, "%s%s", fw_path_para[i], ",");
532+
}
533+
534+
buffer[count - 1] = '\0';
535+
536+
return count - 1;
537+
}
480538
/*
481-
* Typical usage is that passing 'firmware_class.path=$CUSTOMIZED_PATH'
539+
* Typical usage is that passing 'firmware_class.path=/vendor,/firwmare_mnt'
482540
* from kernel command line because firmware_class is generally built in
483-
* kernel instead of module.
541+
* kernel instead of module. ',' is used as delimiter for setting 10
542+
* custom paths for firmware loader.
484543
*/
485-
module_param_string(path, fw_path_para, sizeof(fw_path_para), 0644);
544+
545+
static const struct kernel_param_ops firmware_param_ops = {
546+
.set = firmware_param_path_set,
547+
.get = firmware_param_path_get,
548+
};
549+
module_param_cb(path, &firmware_param_ops, NULL, 0644);
486550
MODULE_PARM_DESC(path, "customized firmware image search path with a higher priority than default path");
487551

488552
static int

0 commit comments

Comments
 (0)