Skip to content

Commit ae38e86

Browse files
committed
check if kernel cmdline for uboot overlay
Test on Debian Jessie 2017-06-18 image: debian@beaglebone:~$ cat /proc/cmdline console=ttyO0,115200n8 bone_capemgr.uboot_capemgr_enabled=1 root=/dev/mmcblk0p1 ro rootfstype=ext4 rootwait coherent_pool=1M net.ifnames=0 quiet debian@beaglebone:~$ grep -c bone_capemgr.uboot_capemgr_enabled=1 /proc/cmdline 1 debian@beaglebone:~$ sudo python ~/read_adc.py load_device_tree: cmd=grep -c bone_capemgr.uboot_capemgr_enabled=1 /proc/cmdline load_device_tree: uboot_overlay=1 load_device_tree: uboot_overlay is 1
1 parent d93466f commit ae38e86

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

source/common.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,10 @@ int get_spi_bus_path_number(unsigned int spi)
441441
BBIO_err load_device_tree(const char *name)
442442
{
443443
FILE *file = NULL;
444+
char line[256];
445+
char uboot_overlay;
446+
const char *cmd = "grep -c bone_capemgr.uboot_capemgr_enabled=1 /proc/cmdline";
447+
444448
#ifdef BBBVERSION41
445449
char slots[41];
446450
snprintf(ctrl_dir, sizeof(ctrl_dir), "/sys/devices/platform/bone_capemgr");
@@ -449,28 +453,25 @@ BBIO_err load_device_tree(const char *name)
449453
build_path("/sys/devices", "bone_capemgr", ctrl_dir, sizeof(ctrl_dir));
450454
#endif
451455

452-
char line[256];
453-
char buf[1035];
454-
const char *cmd = "grep -c bone_capemgr.uboot_capemgr_enabled=1 /proc/cmdline";
455-
FILE *fp;
456-
457456
fprintf(stderr, "load_device_tree: cmd=%s\n", cmd);
458-
fp = popen(cmd, "r");
459-
if (fp == NULL) {
457+
file = popen(cmd, "r");
458+
if (file == NULL) {
460459
fprintf(stderr, "load_device_tree: failed to run command\n");
461460
#ifndef NO_PYTHON
462461
PyErr_SetFromErrnoWithFilename(PyExc_IOError, cmd);
463462
#endif // !NO_PYTHON
464463
return BBIO_CAPE;
465464
}
466-
while (fgets(buf, sizeof(buf)-1, fp) != NULL) {
467-
fprintf(stderr, "load_device_tree: %s\n", buf);
465+
uboot_overlay = fgetc(file);
466+
fprintf(stderr, "load_device_tree: uboot_overlay=%c\n", uboot_overlay);
467+
if(uboot_overlay == '1') {
468+
fprintf(stderr, "load_device_tree: uboot_overlay is 1\n");
469+
} else {
470+
fprintf(stderr, "load_device_tree: uboot_overlay is NOT 1\n");
468471
}
469-
pclose(fp);
470-
472+
pclose(file);
471473

472474
snprintf(slots, sizeof(slots), "%s/slots", ctrl_dir);
473-
fprintf(stderr, "load_device_tree: slots=%s\n", slots);
474475

475476
file = fopen(slots, "r+");
476477
if (!file) {
@@ -481,7 +482,6 @@ BBIO_err load_device_tree(const char *name)
481482
}
482483

483484
while (fgets(line, sizeof(line), file)) {
484-
fprintf(stderr, "load_device_tree: line=%s\n", slots);
485485
//the device is already loaded, return 1
486486
if (strstr(line, name)) {
487487
fclose(file);

0 commit comments

Comments
 (0)