Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rpi camera: support running on 32-bit OS with 64-bit kernel (#1644) #1700

Merged
merged 1 commit into from
Apr 13, 2023
Merged
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
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