From 8dbeccbe75061cf4e221b22f3b3673f7a7d3b50c Mon Sep 17 00:00:00 2001 From: Thomas Oltmann Date: Thu, 21 May 2026 15:57:46 +0200 Subject: [PATCH] Get sip,gip from bootph, call tftp_open --- run-qemu.sh | 2 +- src/main.c | 60 ++++++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 51 insertions(+), 11 deletions(-) diff --git a/run-qemu.sh b/run-qemu.sh index d82f8a1..afea150 100755 --- a/run-qemu.sh +++ b/run-qemu.sh @@ -1,2 +1,2 @@ #!/bin/sh -qemu-system-x86_64 -netdev user,id=n1,net=10.0.0.5/24,tftp=.,bootfile=/boot.bin -device virtio-net-pci,netdev=n1,bootindex=0 "$@" +qemu-system-x86_64 -netdev user,id=n1,net=10.0.0.5/24,tftp=serve/,bootfile=/boot.bin -device virtio-net-pci,netdev=n1,bootindex=0 "$@" diff --git a/src/main.c b/src/main.c index 3cc70a0..3ec0df6 100644 --- a/src/main.c +++ b/src/main.c @@ -159,6 +159,24 @@ struct exPXE { uint32_t pmentry; }; +struct bootph { + uint8_t opcode; + uint8_t hardware; + uint8_t hardlen; + uint8_t gatehops; + uint32_t ident; + uint16_t seconds; + uint16_t flags; + uint32_t cip; + uint32_t yip; + uint32_t sip; + uint32_t gip; + uint8_t caddr[16]; + uint8_t sname[64]; + uint8_t bootfile[128]; + uint8_t vendor[64]; +}; + extern uint32_t pxe_entry; extern uint32_t pxe_call(uint16_t func, uint16_t segment, uint16_t offset); @@ -224,16 +242,6 @@ main() pg_setup(); -#if 0 - t_PXENV_TFTP_OPEN *t_open = (void *)pxe_cmd_buf; - t_open->status = 0; - t_open->server_ip = 0x0100000Au; - t_open->gateway_ip = 0; - memcpy(t_open->filename, "/initrd", 8); - t_open->tftp_port = 69 << 8; - t_open->packet_size = 512; -#endif - #if 1 t_PXENV_GET_CACHED *t_get = (void *)pxe_cmd_buf; t_get->status = 0; @@ -249,6 +257,38 @@ main() debug_write_uint(ret); debug_write("\r\nstatus="); debug_write_uint(t_get->status); + debug_write("\r\n"); +#endif + + debug_write("buffer_off="); + debug_write_uint(t_get->buffer_offset); + debug_write("\r\nbuffer_seg="); + debug_write_uint(t_get->buffer_seg); + struct bootph *bootph = (void *)(t_get->buffer_offset + 16 * t_get->buffer_seg); + uint32_t sip = bootph->sip; + uint32_t gip = bootph->gip; + debug_write("\r\nsip="); + debug_write_uint(sip); + debug_write("\r\ngip="); + debug_write_uint(gip); + debug_write("\r\n"); + +#if 1 + t_PXENV_TFTP_OPEN *t_open = (void *)pxe_cmd_buf; + t_open->status = 0; + t_open->server_ip = sip; + t_open->gateway_ip = gip; + memcpy(t_open->filename, "/initrd", 8); + t_open->tftp_port = 69 << 8; + t_open->packet_size = 512; + debug_write("Performing PXE OPEN call\r\n"); + ret = pxe_call(PXENV_TFTP_OPEN, (uint16_t)(uintptr_t)pxe_cmd_buf, 0x0000); + debug_write("Still alive!\r\n"); + debug_write("ret="); + debug_write_uint(ret); + debug_write("\r\nstatus="); + debug_write_uint(t_open->status); + debug_write("\r\n"); #endif #if 0