Skip to content

Commit f9d7c22

Browse files
committed
rpiboot: Lookup files in device specific folders first
Add file lookup in device specific folders like 2712/ before looking for the file in the top directory. This allows overriding specific file for certain devices types (eg. use a common target with custom firmware for pi4 and pi5). Signed-off-by: Nicolai Buchwitz <n.buchwitz@kunbus.com>
1 parent 38b5eb7 commit f9d7c22

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

main.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,7 @@ FILE * check_file(const char * dir, const char *fname, int use_fmem)
687687
{
688688
FILE * fp = NULL;
689689
char path[MAX_PATH_LEN];
690+
const char *prefix = bcm2712 ? "2712" : bcm2711 ? "2711" : "2710";
690691

691692
// Prevent USB device from requesting files in parent directories
692693
if(strstr(fname, ".."))
@@ -697,7 +698,6 @@ FILE * check_file(const char * dir, const char *fname, int use_fmem)
697698

698699
if (use_bootfiles && use_fmem)
699700
{
700-
const char *prefix = bcm2712 ? "2712" : bcm2711 ? "2711" : "2710";
701701
unsigned long length = 0;
702702

703703
// If 'dir' is specified and the file exists then load this in preference
@@ -740,13 +740,25 @@ FILE * check_file(const char * dir, const char *fname, int use_fmem)
740740
if (fp)
741741
printf("Loading: %s\n", path);
742742
memset(path, 0, sizeof(path));
743+
744+
printf("PATH: %s\n", path);
743745
}
744746

745747
if (fp == NULL)
746748
{
747-
snprintf(path, sizeof(path), "%s/%s", dir, fname);
749+
// try to open file in device specific sub folder first (eg. 2712/...)
750+
snprintf(path, sizeof(path), "%s/%s/%s", dir, prefix, fname);
748751
path[sizeof(path) - 1] = 0;
749752
fp = fopen(path, "rb");
753+
754+
// fallback to top level and look for requested file
755+
if (fp == NULL)
756+
{
757+
snprintf(path, sizeof(path), "%s/%s", dir, fname);
758+
path[sizeof(path) - 1] = 0;
759+
fp = fopen(path, "rb");
760+
}
761+
750762
if (fp)
751763
printf("Loading: %s\n", path);
752764
}

0 commit comments

Comments
 (0)