Skip to content

Commit feb3c63

Browse files
committed
Skip check for device tree loaded if u-boot overlays enabled
1 parent 344014d commit feb3c63

File tree

1 file changed

+46
-29
lines changed

1 file changed

+46
-29
lines changed

source/common.c

Lines changed: 46 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -437,46 +437,55 @@ 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
440442
441-
BBIO_err load_device_tree(const char *name)
442-
{
443-
FILE *file = NULL;
444-
char line[256];
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";
445452
char uboot_overlay;
446-
/*
447-
Refer to: http://elinux.org/Beagleboard:BeagleBoneBlack_Debian#U-Boot_Overlays
453+
FILE *file = NULL;
448454

449-
Robert C. Nelson maintains the BeagleBoard.org Debian images and
450-
suggested adding this check to see if u-boot overlays are enabled.
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);
451462

452-
If u-boot overlays are enabled, then device tree overlays should not
453-
be loaded with the cape manager by writing to the slots file. There
454-
is currently a kernel bug that causes the write to hang.
455-
*/
456-
const char *cmd = "/bin/grep -c bone_capemgr.uboot_capemgr_enabled=1 /proc/cmdline";
463+
if(uboot_overlay == '1') {
464+
return 1;
465+
} else {
466+
return 0;
467+
}
468+
}
469+
470+
471+
BBIO_err load_device_tree(const char *name)
472+
{
473+
char line[256];
474+
FILE *file = NULL;
457475

458476
#ifdef BBBVERSION41
459477
char slots[41];
460478
snprintf(ctrl_dir, sizeof(ctrl_dir), "/sys/devices/platform/bone_capemgr");
461479
#else
462-
char slots[40];
463-
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));
464482
#endif
465483

466-
file = popen(cmd, "r");
467-
if (file == NULL) {
468-
#ifndef NO_PYTHON
469-
PyErr_SetFromErrnoWithFilename(PyExc_IOError, "/proc/cmdline");
470-
#endif // !NO_PYTHON
471-
return BBIO_CAPE;
472-
}
473-
uboot_overlay = fgetc(file);
474-
pclose(file);
475-
if(uboot_overlay == '1') {
476-
/* Linux kernel booted with u-boot overlays enabled.
477-
Do not load overlays via slots file as the write
478-
will hang due to kernel bug in cape manager driver.
479-
Skip cape manager and just return BBIO_OK. */
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()) {
480489
return BBIO_OK;
481490
}
482491

@@ -522,6 +531,14 @@ int device_tree_loaded(const char *name)
522531
#endif
523532
char line[256];
524533

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+
525542
snprintf(slots, sizeof(slots), "%s/slots", ctrl_dir);
526543

527544

0 commit comments

Comments
 (0)