Use pico_rand for DHCP xid, run cmake in load command

This commit is contained in:
Ian Gulliver
2026-04-05 21:30:21 +09:00
parent 28caa2e590
commit 4989cfd8cb
3 changed files with 11 additions and 2 deletions

View File

@@ -31,4 +31,4 @@ pico_enable_stdio_uart(picomap 0)
pico_add_extra_outputs(picomap) 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)

View File

@@ -26,6 +26,14 @@ func main() {
} }
func run(buildDir string) error { 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...") fmt.Println("Building...")
cmd := exec.Command("make", "-C", buildDir) cmd := exec.Command("make", "-C", buildDir)
cmd.Stdout = os.Stdout cmd.Stdout = os.Stdout

View File

@@ -1,5 +1,6 @@
#include "dhcp.h" #include "dhcp.h"
#include <span> #include <span>
#include "pico/rand.h"
#include "w6300.h" #include "w6300.h"
namespace dhcp_opt { namespace dhcp_opt {
@@ -15,7 +16,7 @@ struct __attribute__((packed)) dhcp_discover {
uint8_t htype = 1; uint8_t htype = 1;
uint8_t hlen = 6; uint8_t hlen = 6;
uint8_t hops = 0; uint8_t hops = 0;
uint32_t xid = __builtin_bswap32(0x12345678); uint32_t xid = __builtin_bswap32(static_cast<uint32_t>(get_rand_64()));
uint16_t secs = 0; uint16_t secs = 0;
uint16_t flags = __builtin_bswap16(0x8000); uint16_t flags = __builtin_bswap16(0x8000);
std::array<uint8_t, 4> ciaddr = {}; std::array<uint8_t, 4> ciaddr = {};