Skip to content

Commit f811062

Browse files
authored
Merge pull request #147 from adafruit/uboot-overlays
Check if u-boot overlays are enabled
2 parents 451d50c + feb3c63 commit f811062

File tree

1 file changed

+49
-3
lines changed

1 file changed

+49
-3
lines changed

source/common.c

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -437,19 +437,57 @@ int get_spi_bus_path_number(unsigned int spi)
437437
}
438438
}
439439

440+
/*
441+
Refer to: http://elinux.org/Beagleboard:BeagleBoneBlack_Debian#U-Boot_Overlays
442+
443+
Robert C. Nelson maintains the BeagleBoard.org Debian images and
444+
suggested adding this check to see if u-boot overlays are enabled.
445+
446+
If u-boot overlays are enabled, then device tree overlays should not
447+
be loaded with the cape manager by writing to the slots file. There
448+
is currently a kernel bug that causes the write to hang.
449+
*/
450+
int uboot_overlay_enabled(void) {
451+
const char *cmd = "/bin/grep -c bone_capemgr.uboot_capemgr_enabled=1 /proc/cmdline";
452+
char uboot_overlay;
453+
FILE *file = NULL;
454+
455+
file = popen(cmd, "r");
456+
if (file == NULL) {
457+
fprintf(stderr, "error: uboot_overlay_enabled() failed to run cmd=%s\n", cmd);
458+
return -1;
459+
}
460+
uboot_overlay = fgetc(file);
461+
pclose(file);
462+
463+
if(uboot_overlay == '1') {
464+
return 1;
465+
} else {
466+
return 0;
467+
}
468+
}
469+
440470

441471
BBIO_err load_device_tree(const char *name)
442472
{
473+
char line[256];
443474
FILE *file = NULL;
475+
444476
#ifdef BBBVERSION41
445477
char slots[41];
446478
snprintf(ctrl_dir, sizeof(ctrl_dir), "/sys/devices/platform/bone_capemgr");
447479
#else
448-
char slots[40];
449-
build_path("/sys/devices", "bone_capemgr", ctrl_dir, sizeof(ctrl_dir));
480+
char slots[40];
481+
build_path("/sys/devices", "bone_capemgr", ctrl_dir, sizeof(ctrl_dir));
450482
#endif
451483

452-
char line[256];
484+
/* Check if the Linux kernel booted with u-boot overlays enabled.
485+
If enabled, do not load overlays via slots file as the write
486+
will hang due to kernel bug in cape manager driver. Just return
487+
BBIO_OK in order to avoid cape manager bug. */
488+
if(uboot_overlay_enabled()) {
489+
return BBIO_OK;
490+
}
453491

454492
snprintf(slots, sizeof(slots), "%s/slots", ctrl_dir);
455493

@@ -493,6 +531,14 @@ int device_tree_loaded(const char *name)
493531
#endif
494532
char line[256];
495533

534+
/* Check if the Linux kernel booted with u-boot overlays enabled.
535+
If enabled, do not load overlays via slots file as the write
536+
will hang due to kernel bug in cape manager driver. Return 1
537+
to fake the device tree is loaded to avoid cape manager bug */
538+
if(uboot_overlay_enabled()) {
539+
return 1;
540+
}
541+
496542
snprintf(slots, sizeof(slots), "%s/slots", ctrl_dir);
497543

498544

0 commit comments

Comments
 (0)