Skip to content

Commit

Permalink
rpi camera: support running on 32-bit OS with 64-bit kernel (#1644) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
aler9 authored Apr 13, 2023
1 parent bf8e698 commit 02af80e
Showing 1 changed file with 4 additions and 35 deletions.
39 changes: 4 additions & 35 deletions internal/rpicamera/rpicamera.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,6 @@ const (
//go:embed exe/exe
var exeContent []byte

func getKernelArch() (string, error) {
cmd := exec.Command("uname", "-m")

byts, err := cmd.Output()
if err != nil {
return "", err
}

return string(byts[:len(byts)-1]), nil
}

func startEmbeddedExe(content []byte, env []string) (*exec.Cmd, error) {
tempPath := tempPathPrefix + strconv.FormatInt(time.Now().UnixNano(), 10)

Expand Down Expand Up @@ -103,6 +92,9 @@ func findLibrary(name string) (string, error) {
for _, line := range strings.Split(string(byts), "\n") {
f := strings.Split(line, " => ")
if len(f) == 2 && strings.Contains(f[1], name+".so") {
if runtime.GOARCH == "arm" && !strings.Contains(f[1], "arm-linux-gnueabihf") {
return "", fmt.Errorf("libcamera is 64-bit, you need the 64-bit server version")
}
return f[1], nil
}
}
Expand All @@ -121,24 +113,6 @@ func setupSymlink(name string) error {
return os.Symlink(lib, "/dev/shm/"+name+".so.x.x.x")
}

// 32-bit embedded executables can't run on 64-bit.
func checkArch() error {
if runtime.GOARCH != "arm" {
return nil
}

arch, err := getKernelArch()
if err != nil {
return err
}

if arch == "aarch64" {
return fmt.Errorf("OS is 64-bit, you need the arm64 server version")
}

return nil
}

var (
mutex sync.Mutex
setupped bool
Expand All @@ -149,12 +123,7 @@ func setupLibcameraOnce() error {
defer mutex.Unlock()

if !setupped {
err := checkArch()
if err != nil {
return err
}

err = setupSymlink("libcamera")
err := setupSymlink("libcamera")
if err != nil {
return err
}
Expand Down

0 comments on commit 02af80e

Please sign in to comment.