Skip to content

Commit

Permalink
Merge branch 'fix-detect-platform' of github.com:wimrijnders/QPULib i…
Browse files Browse the repository at this point in the history
…nto fix-detect-platform
  • Loading branch information
wimrijnders committed Jul 16, 2018
2 parents ef88ad1 + 302e80c commit b13025b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 41 deletions.
45 changes: 23 additions & 22 deletions Tools/detectPlatform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,36 +63,38 @@ bool detect_from_sys() {
* since it's the only thing to date(!) using this particular chip version.
*
* @return true if Pi detected, false otherwise
*
* --------------------------------------------------------------------------
* ## NOTES
*
* * The following are valid model numbers:
*
* - BCM2807
* - BCM2835 - This appears to be returned for all higher BCM versions
*
* * The following are also valid, but appear to be represented by 'BCM2835'
* in `/proc/cpuinfo`:
*
* - BCM2836 // If that's not the case, enable these as well
* - BCM2837
* - BCM2837B0
*/
bool detect_from_proc() {
// List of allowed model numbers
const char *BCM_VERSION[] = {
"BCM2807",
"BCM2835", // This appears to be returned for all higher BCM versions
//"BCM2836", // If that's not the case, enable these as well
//"BCM2837",
//BCM2837B0",
nullptr // end marker
};

const char *BCM_VERSION_PREFIX = "BCM28";
const char *filename = "/proc/cpuinfo";

std::ifstream t(filename);
if (!t.is_open()) {
return false;
}
if (!t.is_open()) return false;

std::string line;
while (getline(t, line)) {
if (!strstr(line.c_str(), "Hardware")) continue;

for (int i = 0; BCM_VERSION[i] != nullptr; ++i) {
if (strstr(line.c_str(), BCM_VERSION[i])) {
// For now, don't try to exactly specify the model.
// This could be done with field "Revision' in current input.
printf("This is a Pi platform\n");
return true;
}
if (strstr(line.c_str(), BCM_VERSION_PREFIX)) {
// For now, don't try to exactly specify the model.
// This could be done with field "Revision' in current input.
printf("This is a Pi platform\n");
return true;
}
}

Expand All @@ -106,8 +108,7 @@ bool detect_from_proc() {
* @returns 0 if this is so, 1 if it's a different platform.
*/
int main(int argc, char *argv[]) {
//if (!detect_from_sys() && !detect_from_proc()) {
if (!detect_from_proc()) {
if (!detect_from_sys() && !detect_from_proc()) {
printf("This is not a Pi platform\n");
return 1;
}
Expand Down
26 changes: 7 additions & 19 deletions Tools/detectPlatform.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,31 +36,19 @@ fi
# Detect if this is a VideoCore. This should be sufficient for detecting Pi,
# since it's the only thing to date(!) using this particular chip version.
#
# The hardware from Pi 2 onward is actually BCM2836, but the call still returns BCM2835
# There are several model numbers possible, but they should all start
# with 'BCM28'.
#

# List of allowed model numbers
knownModels=(
"BCM2807"
"BCM2835" # This appears to be returned for all higher BCM versions
#"BCM2836" # If that's not the case, enable these as well
#"BCM2837"
#"BCM2837B0"
)
# Prefix of allowed model numbers
modelPrefix=BCM28


model=$(cat /proc/cpuinfo | grep Hardware)
model=$(cat /proc/cpuinfo | grep Hardware | grep $modelPrefix)
ret=$?
if [ $ret -eq 0 ]
then
for knownModel in "${knownModels[@]}"
do
if echo $model | grep $knownModel
then
echo This is a Pi platform
exit 0
fi
done
echo This is a Pi platform
exit 0
fi


Expand Down

0 comments on commit b13025b

Please sign in to comment.