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

This commit is contained in:
Alessandro Ros 2023-04-13 20:20:21 +02:00 committed by GitHub
parent bf8e69875e
commit 02af80ed4e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 35 deletions

View File

@ -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)
@ -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
}
}
@ -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
@ -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
}