From 4989cfd8cbf814ecb0800289e3f14020dc6cf24f Mon Sep 17 00:00:00 2001 From: Ian Gulliver Date: Sun, 5 Apr 2026 21:30:21 +0900 Subject: [PATCH] Use pico_rand for DHCP xid, run cmake in load command --- CMakeLists.txt | 2 +- cmd/load/main.go | 8 ++++++++ dhcp.cpp | 3 ++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 993cd4a..a6f9adc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,4 +31,4 @@ pico_enable_stdio_uart(picomap 0) pico_add_extra_outputs(picomap) -target_link_libraries(picomap pico_stdlib tinyusb_device tinyusb_board hardware_pio hardware_spi hardware_dma hardware_clocks) +target_link_libraries(picomap pico_stdlib pico_rand tinyusb_device tinyusb_board hardware_pio hardware_spi hardware_dma hardware_clocks) diff --git a/cmd/load/main.go b/cmd/load/main.go index 541deaf..9a095e5 100644 --- a/cmd/load/main.go +++ b/cmd/load/main.go @@ -26,6 +26,14 @@ func main() { } func run(buildDir string) error { + fmt.Println("Configuring...") + cmake := exec.Command("cmake", "-B", buildDir) + cmake.Stdout = os.Stdout + cmake.Stderr = os.Stderr + if err := cmake.Run(); err != nil { + return fmt.Errorf("cmake failed: %w", err) + } + fmt.Println("Building...") cmd := exec.Command("make", "-C", buildDir) cmd.Stdout = os.Stdout diff --git a/dhcp.cpp b/dhcp.cpp index 45e9c94..d323ec7 100644 --- a/dhcp.cpp +++ b/dhcp.cpp @@ -1,5 +1,6 @@ #include "dhcp.h" #include +#include "pico/rand.h" #include "w6300.h" namespace dhcp_opt { @@ -15,7 +16,7 @@ struct __attribute__((packed)) dhcp_discover { uint8_t htype = 1; uint8_t hlen = 6; uint8_t hops = 0; - uint32_t xid = __builtin_bswap32(0x12345678); + uint32_t xid = __builtin_bswap32(static_cast(get_rand_64())); uint16_t secs = 0; uint16_t flags = __builtin_bswap16(0x8000); std::array ciaddr = {};