Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions detect.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func parseVersion(str string) (major, minor, patch int, err error) {
return major, minor, patch, err
}

func kernelVersion() (major, minor, patch int, err error) {
func KernelVersion() (major, minor, patch int, err error) {
output, err := execOutput("uname", "-r")
if err != nil {
return 0, 0, 0, err
Expand Down Expand Up @@ -105,7 +105,7 @@ func cpuInfo() (model, hardware string, revision int, err error) {

// DetectHost returns the detected host and its revision number.
func DetectHost() (host Host, rev int, err error) {
major, minor, patch, err := kernelVersion()
major, minor, patch, err := KernelVersion()
if err != nil {
return HostNull, 0, err
}
Expand Down
32 changes: 24 additions & 8 deletions host/bbb/bbb.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"io/ioutil"
"os"
"strings"

"github.com/golang/glog"
"github.com/kidoman/embd"
"github.com/kidoman/embd/host/generic"
Expand Down Expand Up @@ -99,12 +98,12 @@ var spiDeviceMinor int = 1

func ensureFeatureEnabled(id string) error {
glog.V(3).Infof("bbb: enabling feature %v", id)
pattern := "/sys/devices/bone_capemgr.*/slots"
file, err := embd.FindFirstMatchingFile(pattern)

slotsFile, err := slotsFilename()
if err != nil {
return err
}
bytes, err := ioutil.ReadFile(file)
bytes, err := ioutil.ReadFile(slotsFile)
if err != nil {
return err
}
Expand All @@ -113,7 +112,7 @@ func ensureFeatureEnabled(id string) error {
glog.V(3).Infof("bbb: feature %v already enabled", id)
return nil
}
slots, err := os.OpenFile(file, os.O_WRONLY, os.ModeExclusive)
slots, err := os.OpenFile(slotsFile, os.O_WRONLY, os.ModeExclusive)
if err != nil {
return err
}
Expand All @@ -128,12 +127,12 @@ func ensureFeatureEnabled(id string) error {
// potentially cause a kernel panic and unsettle things. So the
// recommended thing to do is to simply reboot.
func ensureFeatureDisabled(id string) error {
pattern := "/sys/devices/bone_capemgr.*/slots"
file, err := embd.FindFirstMatchingFile(pattern)

slotsFile, err := slotsFilename()
if err != nil {
return err
}
slots, err := os.OpenFile(file, os.O_RDWR, os.ModeExclusive)
slots, err := os.OpenFile(slotsFile, os.O_RDWR, os.ModeExclusive)
if err != nil {
return err
}
Expand Down Expand Up @@ -184,3 +183,20 @@ func init() {
}
})
}
// slotsFilename returns the full path and filename of the Capemgr slots file
func slotsFilename() (filename string, err error) {
major, _, _, err := embd.KernelVersion()
if err != nil {
return "", err
}
if major > 3 {
filename = "/sys/devices/platform/bone_capemgr/slots"
} else {
pattern := "/sys/devices/bone_capemgr.*/slots"
filename, err = embd.FindFirstMatchingFile(pattern)
if err != nil {
return "", err
}
}
return filename, err
}