Skip to content

Commit a993e5c

Browse files
nbuchwitztimg236
authored andcommitted
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 <[email protected]>
1 parent 38b5eb7 commit a993e5c

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

main.c

Lines changed: 12 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
@@ -744,9 +744,19 @@ FILE * check_file(const char * dir, const char *fname, int use_fmem)
744744

745745
if (fp == NULL)
746746
{
747-
snprintf(path, sizeof(path), "%s/%s", dir, fname);
747+
// try to open file in device specific sub folder first (eg. 2712/...)
748+
snprintf(path, sizeof(path), "%s/%s/%s", dir, prefix, fname);
748749
path[sizeof(path) - 1] = 0;
749750
fp = fopen(path, "rb");
751+
752+
// fallback to top level and look for requested file
753+
if (fp == NULL)
754+
{
755+
snprintf(path, sizeof(path), "%s/%s", dir, fname);
756+
path[sizeof(path) - 1] = 0;
757+
fp = fopen(path, "rb");
758+
}
759+
750760
if (fp)
751761
printf("Loading: %s\n", path);
752762
}

0 commit comments

Comments
 (0)