Skip to content

Commit 8b6cd76

Browse files
committed
Allow a cape to provide a device tree overlay
1 parent 3b7ab03 commit 8b6cd76

File tree

1 file changed

+49
-25
lines changed

1 file changed

+49
-25
lines changed

src/non-gpl/CapeUtils/CapeUtils.cpp

Lines changed: 49 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ static void disableOutputs(Json::Value& disables) {
357357
}
358358
}
359359
}
360-
static void processBootConfig(Json::Value& bootConfig) {
360+
static bool processBootConfig(Json::Value& bootConfig) {
361361
#if defined(PLATFORM_PI)
362362
const std::string fileName = FPP_BOOT_DIR "/config.txt";
363363
#elif defined(PLATFORM_BBB)
@@ -373,13 +373,12 @@ static void processBootConfig(Json::Value& bootConfig) {
373373
#endif
374374

375375
if (fileName.empty())
376-
return;
376+
return false;
377377

378378
int len = 0;
379379
uint8_t* data = get_file_contents(fileName, len);
380380
if (len == 0) {
381-
remove("/.fppcapereboot");
382-
return;
381+
return false;
383382
}
384383
std::string current = (char*)data;
385384
std::string orig = current;
@@ -406,21 +405,20 @@ static void processBootConfig(Json::Value& bootConfig) {
406405
}
407406
}
408407
}
409-
if (current != orig) {
410-
put_file_contents(fileName, (const uint8_t*)current.c_str(), current.size());
408+
free(data);
409+
return current != orig;
410+
}
411+
static void handleReboot(bool r) {
412+
if (r) {
413+
const uint8_t data[2] = { 32, 0 };
414+
put_file_contents("/.fppcapereboot", data, 1);
411415
sync();
412-
if (!file_exists("/.fppcapereboot")) {
413-
const uint8_t data[2] = { 32, 0 };
414-
put_file_contents("/.fppcapereboot", data, 1);
415-
sync();
416-
setuid(0);
417-
reboot(RB_AUTOBOOT);
418-
exit(0);
419-
}
416+
setuid(0);
417+
reboot(RB_AUTOBOOT);
418+
exit(0);
420419
} else {
421420
remove("/.fppcapereboot");
422421
}
423-
free(data);
424422
}
425423
static void copyFile(const std::string& src, const std::string& target) {
426424
int s, t;
@@ -488,6 +486,29 @@ bool setFilePerms(const std::string& filename) {
488486
return true;
489487
}
490488

489+
static bool handleCapeOverlay() {
490+
#if defined(PLATFORM_BB64)
491+
static std::string src = "/home/fpp/media/tmp/fpp-cape-overlay.dtb";
492+
if (file_exists("/home/fpp/media/tmp/fpp-cape-overlay.dtb")) {
493+
std::string target = "/boot/firmware/overlays/fpp-cape-overlay.dtb";
494+
495+
int slen = 0;
496+
int tlen = 0;
497+
uint8_t* sd = get_file_contents(src, slen);
498+
uint8_t* td = get_file_contents(target, tlen);
499+
if (slen != tlen || memcmp(sd, td, slen) != 0) {
500+
copyFile(src, target);
501+
free(sd);
502+
free(td);
503+
return true;
504+
}
505+
free(sd);
506+
free(td);
507+
}
508+
#endif
509+
return false;
510+
}
511+
491512
#ifdef PLATFORM_BBB
492513
bool isPocketBeagle() {
493514
bool ret = false;
@@ -996,20 +1017,12 @@ class CapeInfo {
9961017
}
9971018
}
9981019

1020+
bool reboot = false;
9991021
if (result.isMember("bootConfig")) {
10001022
// if the cape requires changes/update to config.txt (Pi) or uEnv.txt (BBB)
10011023
// we need to process them and see if we have to apply the changes and reboot or not
10021024
processBootConfig(result["bootConfig"]);
10031025
}
1004-
1005-
if (result.isMember("modules")) {
1006-
// if the cape requires kernel modules, load them at this
1007-
// time so they will be available later
1008-
for (int x = 0; x < result["modules"].size(); x++) {
1009-
std::string v = "/sbin/modprobe " + result["modules"][x].asString() + " 2> /dev/null > /dev/null";
1010-
exec(v.c_str());
1011-
}
1012-
}
10131026
if (result.isMember("copyFiles")) {
10141027
// if the cape requires certain files copied into place (asoundrc for example)
10151028
for (auto src : result["copyFiles"].getMemberNames()) {
@@ -1025,6 +1038,17 @@ class CapeInfo {
10251038
setFilePerms(target);
10261039
}
10271040
}
1041+
reboot = handleCapeOverlay();
1042+
handleReboot(reboot);
1043+
if (result.isMember("modules")) {
1044+
// if the cape requires kernel modules, load them at this
1045+
// time so they will be available later
1046+
for (int x = 0; x < result["modules"].size(); x++) {
1047+
std::string v = "/sbin/modprobe " + result["modules"][x].asString() + " 2> /dev/null > /dev/null";
1048+
exec(v.c_str());
1049+
}
1050+
}
1051+
10281052
if (result.isMember("i2cDevices") && !readOnly) {
10291053
// if the cape has i2c devices on it that need to be registered, load them at this
10301054
// time so they will be available later
@@ -1125,7 +1149,7 @@ class CapeInfo {
11251149
std::string mapV5Config(const std::string& orig) {
11261150
std::string stringsConfigFile = "";
11271151
std::string platformDir = "/opt/fpp/capes/" + getPlatformCapeDir();
1128-
#if defined(PLATFORM_BBB) || defined(PLATFORM_BB64)
1152+
#if defined(PLATFORM_BBB) || defined(PLATFORM_BB64)
11291153
stringsConfigFile = "/home/fpp/media/config/co-bbbStrings.json";
11301154
#elif defined(PLATFORM_PI)
11311155
stringsConfigFile = "/home/fpp/media/config/co-pixelStrings.json";

0 commit comments

Comments
 (0)