Add cross-platform Windows and Linux CI builds

Introduce a reproducible CMake build and GitHub Actions matrix for Ubuntu Linux x64 and Windows x64. Each platform installs libusb, builds the usbboot executable, and publishes a platform-specific artifact containing the executable, required boot binaries, and documentation. The Windows artifact also includes libusb-1.0.dll.

Add a small Windows getopt_long compatibility layer because the Microsoft CRT does not provide the POSIX GNU option parser used by usbboot. Add Windows sleep support and make the source explicitly include the fixed-width integer and time headers needed by the cross-platform build.

Replace C99 variable-length arrays with checked heap allocations so the source compiles with MSVC, which does not support VLAs. Cast libusb request-type flags to avoid MSVC enum warnings, and use a conforming cleanup(void) callback signature for atexit(). Correct the existing cleanup NULL check so an open libusb handle is actually closed.

Document local CMake builds, CI artifacts, the Windows libusb DLL, and the requirement to bind the boot-mode device to WinUSB before use.

Credit: OpenAI Codex (GPT-5), collaborating with dark98 on the Windows port and CI implementation.
This commit is contained in:
dark98
2026-08-17 01:00:33 +01:00
parent c65eaa337c
commit 2324280493
6 changed files with 312 additions and 12 deletions
+37
View File
@@ -0,0 +1,37 @@
cmake_minimum_required(VERSION 3.20)
project(ingenic_usbboot C)
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS OFF)
find_path(LIBUSB_INCLUDE_DIR
NAMES libusb.h
PATH_SUFFIXES libusb-1.0
)
find_library(LIBUSB_LIBRARY
NAMES usb-1.0 libusb-1.0
)
if(NOT LIBUSB_INCLUDE_DIR OR NOT LIBUSB_LIBRARY)
message(FATAL_ERROR
"libusb-1.0 was not found. Install libusb-1.0-dev on Linux or "
"libusb through vcpkg on Windows.")
endif()
set(USBBOOT_SOURCES usbboot.c)
if(WIN32)
list(APPEND USBBOOT_SOURCES getopt_compat.c)
endif()
add_executable(usbboot ${USBBOOT_SOURCES})
target_include_directories(usbboot PRIVATE ${LIBUSB_INCLUDE_DIR})
target_link_libraries(usbboot PRIVATE ${LIBUSB_LIBRARY})
if(MSVC)
target_compile_definitions(usbboot PRIVATE _CRT_SECURE_NO_WARNINGS)
endif()
install(TARGETS usbboot RUNTIME DESTINATION . LIBRARY DESTINATION . ARCHIVE DESTINATION .)
install(FILES spl.bin uboot.bin README.md DESTINATION .)