diff --git a/edge-ai-platform/tools/test_driver_install/go.mod b/edge-ai-platform/tools/test_driver_install/go.mod new file mode 100644 index 0000000..edb9766 --- /dev/null +++ b/edge-ai-platform/tools/test_driver_install/go.mod @@ -0,0 +1,3 @@ +module test_driver_install + +go 1.25.0 diff --git a/edge-ai-platform/tools/test_driver_install/main.go b/edge-ai-platform/tools/test_driver_install/main.go index 29aebb0..79bb6d5 100644 --- a/edge-ai-platform/tools/test_driver_install/main.go +++ b/edge-ai-platform/tools/test_driver_install/main.go @@ -1,6 +1,7 @@ -// Small test tool to call DiInstallDriverW and print the result. +// Test tool for Windows USB driver installation. // Build: GOOS=windows GOARCH=amd64 go build -o test_driver_install.exe . -// Run on Windows: .\test_driver_install.exe "C:\Users\User\AppData\Local\EdgeAIPlatform\drivers\kneron_winusb.inf" +// Run on Windows (as admin): +// .\test_driver_install.exe "C:\Users\User\AppData\Local\EdgeAIPlatform\drivers\kneron_winusb.inf" package main @@ -20,55 +21,100 @@ func main() { infPath := os.Args[1] fmt.Printf("INF path: %s\n", infPath) - // Check file exists if _, err := os.Stat(infPath); err != nil { fmt.Printf("ERROR: file not found: %v\n", err) os.Exit(1) } + // Hardware ID for Kneron KL520 + hardwareID := "USB\\VID_3231&PID_0100" + + fmt.Println("") + fmt.Println("=== Method 1: UpdateDriverForPlugAndPlayDevicesW ===") + tryUpdateDriver(infPath, hardwareID) + + fmt.Println("") + fmt.Println("=== Method 2: DiInstallDriverW ===") + tryDiInstallDriver(infPath) +} + +func tryUpdateDriver(infPath, hardwareID string) { newdev, err := syscall.LoadDLL("newdev.dll") if err != nil { - fmt.Printf("ERROR: LoadDLL(newdev.dll): %v\n", err) - os.Exit(1) + fmt.Printf("ERROR: LoadDLL: %v\n", err) + return } defer newdev.Release() - fmt.Println("newdev.dll loaded OK") - proc, err := newdev.FindProc("DiInstallDriverW") + proc, err := newdev.FindProc("UpdateDriverForPlugAndPlayDevicesW") if err != nil { - fmt.Printf("ERROR: FindProc(DiInstallDriverW): %v\n", err) - os.Exit(1) - } - fmt.Println("DiInstallDriverW found OK") - - infPathUTF16, err := syscall.UTF16PtrFromString(infPath) - if err != nil { - fmt.Printf("ERROR: UTF16PtrFromString: %v\n", err) - os.Exit(1) + fmt.Printf("ERROR: FindProc: %v\n", err) + return } - const DIIRFLAG_FORCE_INF = 0x00000002 + infUTF16, _ := syscall.UTF16PtrFromString(infPath) + hwIDUTF16, _ := syscall.UTF16PtrFromString(hardwareID) + + const INSTALLFLAG_FORCE = 0x00000001 var needReboot int32 - fmt.Println("Calling DiInstallDriverW...") + fmt.Printf("Hardware ID: %s\n", hardwareID) + fmt.Println("Calling UpdateDriverForPlugAndPlayDevicesW...") fmt.Println("(If a Windows Security dialog appears, click 'Install this driver software anyway')") ret, _, lastErr := proc.Call( 0, // hwndParent = NULL - uintptr(unsafe.Pointer(infPathUTF16)), + uintptr(unsafe.Pointer(hwIDUTF16)), + uintptr(unsafe.Pointer(infUTF16)), + INSTALLFLAG_FORCE, + uintptr(unsafe.Pointer(&needReboot)), + ) + + fmt.Printf("Return value: %d\n", ret) + fmt.Printf("NeedReboot: %d\n", needReboot) + + if ret == 0 { + errno := lastErr.(syscall.Errno) + fmt.Printf("FAILED - error: %v (code: %d / 0x%08X)\n", lastErr, uint32(errno), uint32(errno)) + } else { + fmt.Println("SUCCESS - driver installed!") + } +} + +func tryDiInstallDriver(infPath string) { + newdev, err := syscall.LoadDLL("newdev.dll") + if err != nil { + fmt.Printf("ERROR: LoadDLL: %v\n", err) + return + } + defer newdev.Release() + + proc, err := newdev.FindProc("DiInstallDriverW") + if err != nil { + fmt.Printf("ERROR: FindProc: %v\n", err) + return + } + + infUTF16, _ := syscall.UTF16PtrFromString(infPath) + + const DIIRFLAG_FORCE_INF = 0x00000002 + var needReboot int32 + + fmt.Println("Calling DiInstallDriverW (DIIRFLAG_FORCE_INF)...") + + ret, _, lastErr := proc.Call( + 0, // hwndParent = NULL + uintptr(unsafe.Pointer(infUTF16)), DIIRFLAG_FORCE_INF, uintptr(unsafe.Pointer(&needReboot)), ) fmt.Printf("Return value: %d\n", ret) fmt.Printf("NeedReboot: %d\n", needReboot) - fmt.Printf("LastError: %v\n", lastErr) if ret == 0 { - fmt.Println("FAILED - DiInstallDriverW returned FALSE") - // Get actual error code - errCode := lastErr.(syscall.Errno) - fmt.Printf("Error code: %d (0x%X)\n", errCode, errCode) + errno := lastErr.(syscall.Errno) + fmt.Printf("FAILED - error: %v (code: %d / 0x%08X)\n", lastErr, uint32(errno), uint32(errno)) } else { fmt.Println("SUCCESS - driver installed!") } diff --git a/edge-ai-platform/tools/test_driver_install/test_driver_install.exe b/edge-ai-platform/tools/test_driver_install/test_driver_install.exe index 02b6528..3c3af70 100755 Binary files a/edge-ai-platform/tools/test_driver_install/test_driver_install.exe and b/edge-ai-platform/tools/test_driver_install/test_driver_install.exe differ