Programmatically load device tree overlay in Go

43 views
Skip to first unread message

Frank Davidson

unread,
Dec 15, 2013, 2:43:21 PM12/15/13
to beagl...@googlegroups.com
Hi,

I am having a hard time understanding the nature of the "echo cape-bone-iio > /sys/devices/bone_capemgr.*/slots"

I have written the following program in Go:

package bbbdevtreeovly

import (
// "io"
// "bytes"
// "fmt"
"io/ioutil"
"log"
"os"
// "os/exec"
// "strings"
"path/filepath"
)

const (
slotsDir string = `/sys/devices/` // Find BBB's slots
)

func Load_dto(dtoFileName string, dtoFilePath string) (err error) {

log.SetPrefix(`BBB Device Tree Overlay: `)

slotFiles := make([]os.FileInfo, 100)

slotFiles, err = ioutil.ReadDir(slotsDir)

var i int

for i = 0; i < len(slotFiles); i++ {
found, _ := filepath.Match(`bone_capemgr.*`, slotFiles[i].Name())
if found {
break
}
}

log.Println("This is the new program...", "\n")

slotsLoc := filepath.Join(slotsDir, slotFiles[i].Name(), `slots`)

log.Println("DTO File: ", dtoFileName, "\n")

slots, err := os.Open(slotsLoc)
if err != nil {
log.Println(err)
return err
}
defer slots.Close()

log.Println("Slots location: ", slots.Name(), "\n")

slots.Write([]byte(dtoFileName))

// slots.Write([]byte("cape_bone_iio"))

return nil

}

/*
 *
 */

package main

import (
"davidsonff/fmserve/bbbdevtreeovly"
"fmt"
)

func main() {

err := bbbdevtreeovly.Load_dto("cape-bone-iio", "/lib/firmware/")
if err != nil {
panic(err)
}

fmt.Println("Success!")

}


The result is no error and no change in the system:

root@beaglebone:~# ./fmserve
BBB Device Tree Overlay: 2013/12/15 19:25:15 This is the new program...

BBB Device Tree Overlay: 2013/12/15 19:25:15 DTO File:  cape-bone-iio

BBB Device Tree Overlay: 2013/12/15 19:25:15 Slots location:  /sys/devices/bone_capemgr.9/slots

Success!
root@beaglebone:~# cat /sys/devices/bone_capemgr.9/slots
 0: 54:PF---
 1: 55:PF---
 2: 56:PF---
 3: 57:PF---
 4: ff:P-O-L Bone-LT-eMMC-2G,00A0,Texas Instrument,BB-BONE-EMMC-2G
 5: ff:P-O-L Bone-Black-HDMI,00A0,Texas Instrument,BB-BONELT-HDMI

It seems to me that the $SLOTS "file" is not a normal file and that I am not understanding it properly.

I've seen posts on loading this at boot in a script file, but nothing about changing it programmatically... Any help would be appreciated!

Thanks,

Frank

Thorsten von Eicken

unread,
Dec 15, 2013, 10:46:09 PM12/15/13
to beagl...@googlegroups.com
Do you perhaps need a newline terminator for the line you're writing to the slots "file"?

Frank Davidson

unread,
Jan 3, 2014, 12:52:02 PM1/3/14
to beagl...@googlegroups.com
Thanks, Thorsten, but that didn't see to help, unfortunately... It doesn't generate any errors, it just doesn't actually load the dto... Any other ideas?

Frank

Thorsten von Eicken

unread,
Jan 3, 2014, 1:09:38 PM1/3/14
to beagl...@googlegroups.com
What does dmesg say? That's where you'd find any error messages.
--
For more options, visit http://beagleboard.org/discuss
---
You received this message because you are subscribed to a topic in the Google Groups "BeagleBoard" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/beagleboard/XVvVjpvfll8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to beagleboard...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages