From owner-p4-projects@FreeBSD.ORG Tue Jul 31 15:21:52 2007 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 017EF16A420; Tue, 31 Jul 2007 15:21:52 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id AF7FD16A41A for ; Tue, 31 Jul 2007 15:21:51 +0000 (UTC) (envelope-from taleks@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 939A313C4B0 for ; Tue, 31 Jul 2007 15:21:51 +0000 (UTC) (envelope-from taleks@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.1/8.14.1) with ESMTP id l6VFLpId052583 for ; Tue, 31 Jul 2007 15:21:51 GMT (envelope-from taleks@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.1/8.14.1/Submit) id l6VFLodp052580 for perforce@freebsd.org; Tue, 31 Jul 2007 15:21:50 GMT (envelope-from taleks@FreeBSD.org) Date: Tue, 31 Jul 2007 15:21:50 GMT Message-Id: <200707311521.l6VFLodp052580@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to taleks@FreeBSD.org using -f From: Alexey Tarasov To: Perforce Change Reviews Cc: Subject: PERFORCE change 124428 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 31 Jul 2007 15:21:52 -0000 http://perforce.freebsd.org/chv.cgi?CH=124428 Change 124428 by taleks@taleks_th on 2007/07/31 15:21:33 all: added PXE_MORE macro, to remove many testing and unused code from binary. Size of binary has influence on workability of code (and available space for buffers), so all that is not needed for working of project code gone to PXE_MORE blocks. pxe_mutex: module was unused, deleted pxe_conv: module functions were dublicates of htons() and etc. deleted pxe.c: made it working. PXEHTTP_UDP_FOR_LIBSTAND macro used to use pxehhtp functions for udpread/udpsend, otherwise old versions of functions (updated to cal pxe_core_call()) are called. Old versions are not robustely tested. New versions are working good for NFS, not tested for TFTP. loader: conf.c: addes some preprocessor directives to remove unused filesystems in PXE booting. main.c - updates with PXE_MORE and heapsize (redused it in order not corrupt memory used by PXE). Makefile - updates for LOADER_HTTP_SUPPORT. pxe_buffer: ability to support statical allocation of buffes if define PXE_POOL_SLOTS. Otherwise memory for buffers allocated dynamically. pxe_core: remove unused function, buffers are now allocated dynamically. Need to do it optional and statical variant primary. pxe_dhcp: updates for rootpath option. Added PXE_BOOTP_USE_LIBSTAND macro, that instructs to use bootp() function of libstand instead of own code. Need to add coorect update of gateway/nameserver in case of bootp(), which called in code later, then this values are inited in pxe_core_init() pxe_icmp: whole module is disabled when PXE_MORE undefined pxe_isr: minor updates with chained handler, it's ignored for testing purposes. pxe_sock: updates in pxe_recvfrom() needed after pxe_udp_read() update. pxe_udp: added "default socket" which gains all that was not taken by other sockets. Was needed for udpread/udpwrite. Other update in parameter count of pxe_udp_read(). Affected files ... .. //depot/projects/soc2007/taleks-pxe_http/Makefile#12 edit .. //depot/projects/soc2007/taleks-pxe_http/httpfs.c#5 edit .. //depot/projects/soc2007/taleks-pxe_http/libi386_mod/pxe.c#2 edit .. //depot/projects/soc2007/taleks-pxe_http/loader_mod/Makefile#2 edit .. //depot/projects/soc2007/taleks-pxe_http/loader_mod/conf.c#2 edit .. //depot/projects/soc2007/taleks-pxe_http/loader_mod/main.c#2 edit .. //depot/projects/soc2007/taleks-pxe_http/pxe_arp.c#14 edit .. //depot/projects/soc2007/taleks-pxe_http/pxe_buffer.c#8 edit .. //depot/projects/soc2007/taleks-pxe_http/pxe_buffer.h#8 edit .. //depot/projects/soc2007/taleks-pxe_http/pxe_connection.c#11 edit .. //depot/projects/soc2007/taleks-pxe_http/pxe_connection.h#8 edit .. //depot/projects/soc2007/taleks-pxe_http/pxe_core.c#24 edit .. //depot/projects/soc2007/taleks-pxe_http/pxe_core.h#20 edit .. //depot/projects/soc2007/taleks-pxe_http/pxe_dhcp.c#7 edit .. //depot/projects/soc2007/taleks-pxe_http/pxe_dhcp.h#7 edit .. //depot/projects/soc2007/taleks-pxe_http/pxe_dns.c#6 edit .. //depot/projects/soc2007/taleks-pxe_http/pxe_filter.c#7 edit .. //depot/projects/soc2007/taleks-pxe_http/pxe_filter.h#5 edit .. //depot/projects/soc2007/taleks-pxe_http/pxe_http.c#9 edit .. //depot/projects/soc2007/taleks-pxe_http/pxe_icmp.c#13 edit .. //depot/projects/soc2007/taleks-pxe_http/pxe_ip.c#14 edit .. //depot/projects/soc2007/taleks-pxe_http/pxe_isr.S#6 edit .. //depot/projects/soc2007/taleks-pxe_http/pxe_isr.h#5 edit .. //depot/projects/soc2007/taleks-pxe_http/pxe_mem.c#4 edit .. //depot/projects/soc2007/taleks-pxe_http/pxe_segment.c#9 edit .. //depot/projects/soc2007/taleks-pxe_http/pxe_sock.c#17 edit .. //depot/projects/soc2007/taleks-pxe_http/pxe_sock.h#15 edit .. //depot/projects/soc2007/taleks-pxe_http/pxe_tcp.c#12 edit .. //depot/projects/soc2007/taleks-pxe_http/pxe_udp.c#9 edit .. //depot/projects/soc2007/taleks-pxe_http/pxe_udp.h#6 edit Differences ... ==== //depot/projects/soc2007/taleks-pxe_http/Makefile#12 (text+ko) ==== @@ -3,8 +3,9 @@ LIB= pxe_http INTERNALLIB= -SRCS= pxe_conv.c pxe_isr.S pxe_mem.c pxe_buffer.c pxe_await.c pxe_arp.c pxe_ip.c pxe_mutex.c \ - pxe_core.c pxe_icmp.c pxe_udp.c pxe_filter.c pxe_dns.c pxe_dhcp.c pxe_segment.c pxe_tcp.c pxe_sock.c \ +SRCS= pxe_isr.S pxe_mem.c pxe_buffer.c pxe_await.c pxe_arp.c pxe_ip.c \ + pxe_core.c pxe_icmp.c pxe_udp.c pxe_filter.c pxe_dns.c \ + pxe_dhcp.c pxe_segment.c pxe_tcp.c pxe_sock.c \ pxe_connection.c pxe_http.c httpfs.c CFLAGS+= -I${.CURDIR}/../../common -I${.CURDIR}/../btx/lib \ @@ -30,7 +31,7 @@ #CFLAGS+= -DPXE_ARP_DEBUG #CFLAGS+= -DPXE_ARP_DEBUG_HELL # httpfs module -CFLAGS+= -DPXE_HTTP_DEBUG +#CFLAGS+= -DPXE_HTTP_DEBUG #CFLAGS+= -DPXE_HTTP_DEBUG_HELL .include ==== //depot/projects/soc2007/taleks-pxe_http/httpfs.c#5 (text+ko) ==== @@ -126,8 +126,8 @@ f->f_fsdata = (void *) httpfile; #ifdef PXE_HTTP_DEBUG - printf("http_open(): success\n"); -#endif + printf("http_open(): %s opened\n", httpfile->filename); +#endif return (0); } @@ -169,13 +169,13 @@ httpfile->offset += result; -#ifdef PXE_HTTP_DEBUG +/* #ifdef PXE_HTTP_DEBUG */ if (httpfile->size != PXE_HTTP_SIZE_UNKNOWN) - printf("http_read(): %llu bytes read (%llu %% read)\n", - httpfile->offset, 100LL * httpfile->offset / httpfile->size); + printf("%3llu%%\b\b\b\b", + 100LL * httpfile->offset / httpfile->size); else printf("http_read(): %llu byte(s) read\n", httpfile->offset); -#endif +/* #endif */ if (resid) *resid = size - result; ==== //depot/projects/soc2007/taleks-pxe_http/libi386_mod/pxe.c#2 (text+ko) ==== @@ -47,23 +47,22 @@ #include "btxv86.h" #include "pxe.h" #include "pxe_core.h" -#include "pxe_arp.h" +#include "pxe_dhcp.h" #include "pxe_isr.h" +#include "pxe_ip.h" +#include "pxe_udp.h" -/* - * Allocate the PXE buffers statically instead of sticking grimy fingers into - * BTX's private data area. The scratch buffer is used to send information to - * the PXE BIOS, and the data buffer is used to receive data from the PXE BIOS. - */ -#define PXE_BUFFER_SIZE 0x2000 #define PXE_TFTP_BUFFER_SIZE 512 -static char scratch_buffer[PXE_BUFFER_SIZE]; -static char data_buffer[PXE_BUFFER_SIZE]; + +#ifndef PXEHTTP_UDP_FOR_LIBSTAND +extern uint8_t *scratch_buffer; +extern uint8_t *data_buffer; +#endif static pxenv_t *pxenv_p = NULL; /* PXENV+ */ static pxe_t *pxe_p = NULL; /* !PXE */ -static int pxe_sock = -1; +int pxe_sock = -1; static int pxe_opens = 0; void pxe_enable(void *pxeinfo); @@ -71,6 +70,7 @@ static int pxe_init(void); static int pxe_strategy(void *devdata, int flag, daddr_t dblk, size_t size, char *buf, size_t *rsize); + static int pxe_open(struct open_file *f, ...); static int pxe_close(struct open_file *f); static void pxe_cleanup(void); @@ -87,8 +87,6 @@ extern struct netif_stats pxe_st[]; -void pxe_isr_install(); - struct netif_dif pxe_ifs[] = { /* dif_unit dif_nsel dif_stats dif_private */ {0, 1, &pxe_st[0], 0} @@ -171,17 +169,21 @@ static void pxe_print(int verbose) { - printf("PXE module (type 'pxe' for more information)\n"); + printf(" pxenet0: MAC %6D\n", pxe_get_mymac(), ":"); + printf(" ISR: at %x:%x (chained at: %x:%x)\n", + __pxe_entry_seg, __pxe_entry_off, + __chained_irq_seg, __chained_irq_off); + return; } static int pxe_open(struct open_file *f, ...) { - return (0); - va_list args; - char *devname; /* Device part of file name (or NULL). */ + char *devname = NULL; + char temp[FNAME_SIZE]; + int i = 0; va_start(args, f); devname = va_arg(args, char*); @@ -190,7 +192,6 @@ if (pxe_opens == 0) { /* Find network interface. */ if (pxe_sock < 0) { - pxe_sock = netif_open(devname); if (pxe_sock < 0) { @@ -199,30 +200,74 @@ } } - - if (rootip.s_addr == 0) - rootip.s_addr = pxe_get_ip32(PXE_IP_SERVER); + + if (pxe_get_ip32(PXE_IP_ROOT) == 0) { +#ifdef PXE_BOOTP_USE_LIBSTAND + pxe_dhcp_query(0); + + if (pxe_get_ip32(PXE_IP_ROOT) == 0) + pxe_set_ip32(PXE_IP_ROOT, + pxe_get_ip32(PXE_IP_SERVER)); +#endif + + if (!rootpath[1]) + strcpy(rootpath, PXENFSROOTPATH); + + for (i = 0; rootpath[i] != '\0' && i < FNAME_SIZE; i++) + if (rootpath[i] == ':') + break; + + if (i && i != FNAME_SIZE && rootpath[i] == ':') { + rootpath[i++] = '\0'; + + if (inet_addr(&rootpath[0]) != INADDR_NONE) + pxe_set_ip32(PXE_IP_ROOT, + inet_addr(&rootpath[0])); + + pxe_memcpy(&rootpath[i], &temp[0], + strlen(&rootpath[i])+1); + + pxe_memcpy(&temp[0], &rootpath[0], + strlen(&rootpath[i])+1); + } - gateip.s_addr = pxe_get_ip32(PXE_IP_GATEWAY); - - printf("pxe_open: server addr: %s\n", inet_ntoa(rootip)); - printf("pxe_open: gateway ip: %s\n", inet_ntoa(gateip)); + struct in_addr tmp_in; + + tmp_in.s_addr = pxe_get_ip32(PXE_IP_ROOT); +#ifdef PXE_DEBUG + printf("pxe_open: server addr: %s\n", + inet_ntoa(tmp_in)); +#endif + setenv("boot.nfsroot.server", + inet_ntoa(tmp_in), 1); -/* setenv("boot.netif.ip", inet_ntoa(myip), 1); - setenv("boot.netif.netmask", intoa(netmask), 1); - setenv("boot.netif.gateway", inet_ntoa(gateip), 1); - - if (bootplayer.Hardware == ETHER_TYPE) { - sprintf(temp, "%6D", bootplayer.CAddr, ":"); - setenv("boot.netif.hwaddr", temp, 1); + tmp_in.s_addr = pxe_get_ip32(PXE_IP_GATEWAY); + setenv("boot.netif.gateway", inet_ntoa(tmp_in), 1); +#ifdef PXE_DEBUG + printf("pxe_open: server path: %s\n", rootpath); + printf("pxe_open: gateway ip: %s\n", + inet_ntoa(tmp_in)); +#endif + tmp_in.s_addr = pxe_get_ip32(PXE_IP_MY); + setenv("boot.netif.ip", inet_ntoa(tmp_in), 1); + + tmp_in.s_addr = pxe_get_ip32(PXE_IP_NETMASK); + setenv("boot.netif.netmask", inet_ntoa(tmp_in), 1); + + sprintf(temp, "%6D", pxe_get_mymac(), ":"); + setenv("boot.netif.hwaddr", temp, 1); + + setenv("boot.nfsroot.path", rootpath, 1); + +#ifdef PXEHTTP_UDP_FOR_LIBSTAND + gateip.s_addr = pxe_get_ip32(PXE_IP_GATEWAY); + rootip.s_addr = pxe_get_ip32(PXE_IP_ROOT); + netmask = pxe_get_ip32(PXE_IP_NETMASK); + myip.s_addr = pxe_get_ip32(PXE_IP_MY); + nameip.s_addr = pxe_get_ip32(PXE_IP_NAMESERVER); +#endif } - - setenv("boot.nfsroot.server", inet_ntoa(rootip), 1); - setenv("boot.nfsroot.path", rootpath, 1); - setenv("dhcp.host-name", hostname, 1); -*/ } - ++pxe_opens; f->f_devdata = &pxe_sock; @@ -232,7 +277,6 @@ static int pxe_close(struct open_file *f) { - return (0); /* On last close, do netif close, etc. */ f->f_devdata = NULL; @@ -257,8 +301,6 @@ static void pxe_cleanup(void) { - return (0); - pxe_core_shutdown(); } @@ -278,10 +320,23 @@ #ifdef PXE_DEBUG printf("pxe_netif_probe() called."); #endif - if (__pxe_nic_irq != 0) - return (0); + +#ifdef PXEHTTP_UDP_FOR_LIBSTAND + if (__pxe_nic_irq == 0) + return (-1); +#else + t_PXENV_UDP_OPEN *udpopen_p = (t_PXENV_UDP_OPEN *)scratch_buffer; + + bzero(udpopen_p, sizeof(*udpopen_p)); + udpopen_p->src_ip = pxe_get_ip32(PXE_IP_MY); + pxe_core_call(PXENV_UDP_OPEN); - return (-1); + if (udpopen_p->status != 0) { + printf("pxe_netif_probe: failed %x\n", udpopen_p->status); + return (-1); + } +#endif + return (0); } static void @@ -290,12 +345,22 @@ #ifdef PXE_DEBUG printf("pxe_netif_end() called."); #endif + +#ifndef PXEHTTP_UDP_FOR_LIBSTAND + t_PXENV_UDP_CLOSE *udpclose_p = (t_PXENV_UDP_CLOSE *)scratch_buffer; + + bzero(udpclose_p, sizeof(*udpclose_p)); + + pxe_core_call(PXENV_UDP_CLOSE); + + if (udpclose_p->status != 0) + printf("pxe_end failed %x\n", udpclose_p->status); +#endif } static void pxe_netif_init(struct iodesc *desc, void *machdep_hint) { - return; #ifdef PXE_DEBUG printf("pxe_netif_init(): called.\n"); @@ -305,7 +370,7 @@ int i; for (i = 0; i < 6; ++i) desc->myea[i] = mac[i]; - + desc->xid = pxe_get_ip32(PXE_IP_MY); } @@ -327,18 +392,18 @@ return (len); } -/*************** to modify **********************/ - +#if defined(LOADER_NFS_SUPPORT) /* * Reach inside the libstand NFS code and dig out an NFS handle * for the root filesystem. */ -/* struct nfs_iodesc { +struct nfs_iodesc { struct iodesc *iodesc; off_t off; u_char fh[NFS_FHSIZE]; /* structure truncated here */ -/* }; +}; + extern struct nfs_iodesc nfs_root_node; extern int rpc_port; @@ -369,7 +434,7 @@ * ourselves. Use nfs_root_node.iodesc as flag indicating * previous NFS usage. */ -/* if (nfs_root_node.iodesc == NULL) + if (nfs_root_node.iodesc == NULL) pxe_rpcmountcall(); fh = &nfs_root_node.fh[0]; @@ -380,68 +445,124 @@ sprintf(cp, "X"); setenv("boot.nfsroot.nfshandle", buf, 1); } +#endif +#ifdef PXEHTTP_UDP_FOR_LIBSTAND +/* new versions of udp send/recv functions */ ssize_t sendudp(struct iodesc *h, void *pkt, size_t len) { - t_PXENV_UDP_WRITE *udpwrite_p = (t_PXENV_UDP_WRITE *)scratch_buffer; - bzero(udpwrite_p, sizeof(*udpwrite_p)); +#ifdef PXE_DEBUG_HELL + printf("sendudp(): sending %u bytes from me:%u -> %s:%u\n", + len, ntohs(h->myport), + inet_ntoa(h->destip), ntohs(h->destport)); +#endif + void *ipdata = pkt - sizeof(PXE_UDP_PACKET); + + if (!pxe_udp_send(ipdata, h->destip.s_addr, ntohs(h->destport), + ntohs(h->myport), len + sizeof(PXE_UDP_PACKET))) + { + printf("sendudp(): failed\n"); + return (-1); + } + + return (len); +} + +ssize_t +readudp(struct iodesc *h, void *pkt, size_t len, time_t timeout) +{ + PXE_UDP_DGRAM dgram; + struct udphdr *uh = (struct udphdr *) pkt - 1; - udpwrite_p->ip = h->destip.s_addr; - udpwrite_p->dst_port = h->destport; - udpwrite_p->src_port = h->myport; - udpwrite_p->buffer_size = len; - udpwrite_p->buffer.segment = VTOPSEG(pkt); - udpwrite_p->buffer.offset = VTOPOFF(pkt); + /* process any queued incoming packets */ + pxe_core_recv_packets(); - if (netmask == 0 || SAMENET(myip, h->destip, netmask)) - udpwrite_p->gw = 0; - else - udpwrite_p->gw = gateip.s_addr; + /* reading from default socket */ + int recv = pxe_udp_read(NULL, pkt, len, &dgram); + + if (recv == -1) { + printf("readudp(): failed\n"); + return (-1); + } +#ifdef PXE_DEBUG_HELL + printf("readudp(): received %d(%u/%u) bytes from %u port\n", + recv, len, dgram.size, dgram.src_port); +#endif + uh->uh_sport = htons(dgram.src_port); + + return (recv); +} - pxe_call(PXENV_UDP_WRITE); +#else /* !defined(PXEHTTP_UDP_FOR_LIBSTAND) */ +/* old variants of udp send/recv functions */ +ssize_t +sendudp(struct iodesc *h, void *pkt, size_t len) +{ + t_PXENV_UDP_WRITE *udpwrite_p = (t_PXENV_UDP_WRITE *)scratch_buffer; + bzero(udpwrite_p, sizeof(*udpwrite_p)); + + udpwrite_p->ip = h->destip.s_addr; + udpwrite_p->dst_port = h->destport; + udpwrite_p->src_port = h->myport; + udpwrite_p->buffer_size = len; + udpwrite_p->buffer.segment = VTOPSEG(pkt); + udpwrite_p->buffer.offset = VTOPOFF(pkt); + + if (netmask == 0 || SAMENET(myip, h->destip, netmask)) + udpwrite_p->gw = 0; + else + udpwrite_p->gw = gateip.s_addr; + pxe_core_call(PXENV_UDP_WRITE); #if 0 - /* XXX - I dont know why we need this. */ -/* delay(1000); + /* XXX - I dont know why we need this. */ + delay(1000); #endif - if (udpwrite_p->status != 0) { - /* XXX: This happens a lot. It shouldn't. */ -/* if (udpwrite_p->status != 1) - printf("sendudp failed %x\n", udpwrite_p->status); - return -1; + if (udpwrite_p->status != 0) { + /* XXX: This happens a lot. It shouldn't. */ + if (udpwrite_p->status != 1) + printf("sendudp failed %x\n", udpwrite_p->status); + + return (-1); } - return len; + + return (len); } ssize_t readudp(struct iodesc *h, void *pkt, size_t len, time_t timeout) { - t_PXENV_UDP_READ *udpread_p = (t_PXENV_UDP_READ *)scratch_buffer; - struct udphdr *uh = NULL; - - uh = (struct udphdr *) pkt - 1; - bzero(udpread_p, sizeof(*udpread_p)); - - udpread_p->dest_ip = h->myip.s_addr; - udpread_p->d_port = h->myport; - udpread_p->buffer_size = len; - udpread_p->buffer.segment = VTOPSEG(data_buffer); - udpread_p->buffer.offset = VTOPOFF(data_buffer); - - pxe_call(PXENV_UDP_READ); - + t_PXENV_UDP_READ *udpread_p = (t_PXENV_UDP_READ *)scratch_buffer; + struct udphdr *uh = NULL; + + uh = (struct udphdr *) pkt - 1; + bzero(udpread_p, sizeof(*udpread_p)); + + udpread_p->dest_ip = h->myip.s_addr; + udpread_p->d_port = h->myport; + udpread_p->buffer_size = len; + udpread_p->buffer.segment = VTOPSEG(data_buffer); + udpread_p->buffer.offset = VTOPOFF(data_buffer); + + pxe_core_call(PXENV_UDP_READ); + #if 0 - /* XXX - I dont know why we need this. */ -/* delay(1000); + /* XXX - I dont know why we need this. */ + delay(1000); #endif - if (udpread_p->status != 0) { - /* XXX: This happens a lot. It shouldn't. */ -/* if (udpread_p->status != 1) - printf("readudp failed %x\n", udpread_p->status); - return -1; + if (udpread_p->status != 0) { + /* XXX: This happens a lot. It shouldn't. */ + if (udpread_p->status != 1) + printf("readudp failed %x\n", udpread_p->status); + + return (-1); } - bcopy(data_buffer, pkt, udpread_p->buffer_size); - uh->uh_sport = udpread_p->s_port; - return udpread_p->buffer_size; -} */ + + bcopy(data_buffer, pkt, udpread_p->buffer_size); + uh->uh_sport = udpread_p->s_port; + + return (udpread_p->buffer_size); +} + +#endif /* PXEHTTP_UDP_FOR_LIBSTAND */ ==== //depot/projects/soc2007/taleks-pxe_http/loader_mod/Makefile#2 (text+ko) ==== @@ -7,13 +7,25 @@ # architecture-specific loader code SRCS= main.c conf.c vers.c +CFLAGS+= -DLOADER_HTTP_SUPPORT + +# Enable HTTP support for PXE +.if !defined(LOADER_HTTP_SUPPORT) + # Enable PXE TFTP or NFS support, not both. -#.if defined(LOADER_TFTP_SUPPORT) -#CFLAGS+= -DLOADER_TFTP_SUPPORT -#.else -#CFLAGS+= -DLOADER_NFS_SUPPORT -#.endif +.if defined(LOADER_TFTP_SUPPORT) +CFLAGS+= -DLOADER_TFTP_SUPPORT +.else +CFLAGS+= -DLOADER_NFS_SUPPORT +.endif + +.else CFLAGS+= -DLOADER_HTTP_SUPPORT +.endif + +.if ${MACHINE_ARCH} == "amd64" +CFLAGS+= -DLOADER_AMD64_ELF_SUPPORT +.endif # Enable PnP and ISA-PnP code. HAVE_PNP= yes ==== //depot/projects/soc2007/taleks-pxe_http/loader_mod/conf.c#2 (text+ko) ==== @@ -42,6 +42,10 @@ * * XXX as libi386 and biosboot merge, some of these can become linker sets. */ +#ifdef LOADER_HTTP_SUPPORT +#undef LOADER_NFS_SUPPORT +#undef LOADER_TFTP_SUPPORT +#endif #if defined(LOADER_NFS_SUPPORT) && defined(LOADER_TFTP_SUPPORT) #error "Cannot have both tftp and nfs support yet." @@ -51,18 +55,39 @@ struct devsw *devsw[] = { &bioscd, &biosdisk, -#if defined(LOADER_NFS_SUPPORT) || defined(LOADER_TFTP_SUPPORT) || defined(LOADER_HTTP_SUPPORT) +#if defined(LOADER_NFS_SUPPORT) || defined(LOADER_TFTP_SUPPORT) || \ + defined(LOADER_HTTP_SUPPORT) &pxedisk, #endif NULL }; +#ifdef LOADER_HTTP_SUPPORT +/* free as much as possible memory, by removing unused by PXE filesystems */ +#undef LOADER_EXT2_SUPPORT +#undef LOADER_DOS_SUPPORT +#undef LOADER_CD9660_SUPPORT +#undef LOADER_SPLITFS_SUPPORT +#undef LOADER_NFS_SUPPORT +#undef LOADER_TFTP_SUPPORT +#else +#define LOADER_NFS_SUPPORT +#endif + struct fs_ops *file_system[] = { &ufs_fsops, +#ifdef LOADER_EXT2_SUPPORT &ext2fs_fsops, +#endif +#ifdef LOADER_DOS_SUPPORT &dosfs_fsops, +#endif +#ifdef LOADER_CD9660_SUPPORT &cd9660_fsops, +#endif +#ifdef LOADER_SPLITFS_SUPPORT &splitfs_fsops, +#endif #ifdef LOADER_GZIP_SUPPORT &gzipfs_fsops, #endif @@ -76,7 +101,7 @@ &tftp_fsops, #endif #ifdef LOADER_HTTP_SUPPORT -/* &http_fsops, */ + &http_fsops, #endif NULL }; @@ -88,14 +113,18 @@ */ extern struct file_format i386_elf; extern struct file_format i386_elf_obj; +#ifdef LOADER_AMD64_ELF_SUPPORT extern struct file_format amd64_elf; extern struct file_format amd64_elf_obj; +#endif struct file_format *file_formats[] = { &i386_elf, &i386_elf_obj, +#ifdef LOADER_AMD64_ELF_SUPPORT &amd64_elf, &amd64_elf_obj, +#endif NULL }; @@ -111,7 +140,9 @@ struct console *consoles[] = { &vidconsole, +#ifdef LOADER_COMCONSOLE_SUPPORT &comconsole, +#endif &nullconsole, NULL }; ==== //depot/projects/soc2007/taleks-pxe_http/loader_mod/main.c#2 (text+ko) ==== @@ -41,15 +41,18 @@ #include "libi386/libi386.h" #include "btxv86.h" +#ifdef PXE_MORE #include "pxe_arp.h" #include "pxe_connection.h" #include "pxe_dns.h" #include "pxe_filter.h" +#include "pxe_http.h" #include "pxe_icmp.h" #include "pxe_ip.h" #include "pxe_sock.h" #include "pxe_tcp.h" #include "pxe_udp.h" +#endif #define KARGS_FLAGS_CD 0x1 #define KARGS_FLAGS_PXE 0x2 @@ -98,8 +101,16 @@ */ bios_getmem(); +#if defined(LOADER_HTTP_SUPPORT) || defined (LOADER_TFTP_SUPPORT) || \ + defined(LOADER_NFS_SUPPORT) + /* 0x8d000-0x9f800 memory area is used by UNDI/BC data/code segments + * and PXE stack + */ + setheap((void *)end, 0x8d000); +#else setheap((void *)end, (void *)bios_basemem); - +#endif + /* * XXX Chicken-and-egg problem; we want to have console output early, but some * console attributes may depend on reading from eg. the boot device, which we @@ -281,6 +292,7 @@ } /* added for pxe_http */ +#ifdef PXE_MORE static int command_route(int argc, char *argv[]) { @@ -538,8 +550,6 @@ static int command_fetch(int argc, char *argv[]) { - PXE_IPADDR ip; - if (argc == 1) { printf("usage: fetch server/path/to/file.ext\n"); return (CMD_OK); @@ -558,7 +568,7 @@ } /* retrieve all file */ - pxe_fetch(server_name, filename, 0, 0); + pxe_fetch(server_name, filename, 0LL, 0L); return (CMD_OK); } @@ -616,6 +626,7 @@ return (CMD_OK); } /* pxe_http add end */ +#endif /* ISA bus access functions for PnP, derived from */ static int ==== //depot/projects/soc2007/taleks-pxe_http/pxe_arp.c#14 (text+ko) ==== @@ -29,7 +29,6 @@ #include "pxe_arp.h" #include "pxe_await.h" -#include "pxe_conv.h" #include "pxe_core.h" #include "pxe_mem.h" @@ -61,11 +60,11 @@ pxe_memset(arp_table, 0, sizeof(arp_table)); /* filling packet_to_send, it will not change ever */ - packet_to_send.hdr.hwtype =le2be16(ETHER_TYPE); - packet_to_send.hdr.ptype = le2be16(PXE_PTYPE_IP); + packet_to_send.hdr.hwtype =htons(ETHER_TYPE); + packet_to_send.hdr.ptype = htons(PXE_PTYPE_IP); packet_to_send.hdr.hsize = 6; /* Ethernet MAC size */ packet_to_send.hdr.psize = 4; /* ip4 size */ - packet_to_send.hdr.operation = le2be16(PXE_ARPOP_REQUEST); + packet_to_send.hdr.operation = htons(PXE_ARPOP_REQUEST); /* filling source related data: client ip & MAC */ pxe_memcpy(pxe_get_mymac(), packet_to_send.body.src_hwaddr, 6); @@ -110,6 +109,7 @@ return (NULL); } +#ifdef PXE_MORE /* pxe_arp_stats() - show arp current table state * in/out: * none @@ -138,7 +138,7 @@ } } - +#endif /* * pxe_arp_protocol() - process received arp packet, this function is called in * style of pxe_protocol_call function type, but last @@ -157,7 +157,7 @@ #endif PXE_ARP_PACK_DATA *arp_reply = (PXE_ARP_PACK_DATA *)pack->raw_data; - if (arp_reply->hdr.operation == le2be16(PXE_ARPOP_REQUEST) ) { + if (arp_reply->hdr.operation == htons(PXE_ARPOP_REQUEST) ) { uint8_t *mac_src = arp_reply->body.src_hwaddr; uint8_t *mac_dst = arp_reply->body.target_hwaddr; @@ -198,7 +198,7 @@ packet_to_send.body.target_paddr = arp_reply->body.src_paddr; - packet_to_send.hdr.operation = le2be16(PXE_ARPOP_REPLY); + packet_to_send.hdr.operation = htons(PXE_ARPOP_REPLY); PXE_PACKET pack; @@ -220,20 +220,20 @@ /* cleaning packet_to_send back to initiakl state */ pxe_memset(packet_to_send.body.target_hwaddr, 0xff, 6); - packet_to_send.hdr.operation = le2be16(PXE_ARPOP_REQUEST); + packet_to_send.hdr.operation = htons(PXE_ARPOP_REQUEST); } /* we may cache information about packet sender */ #ifdef PXE_ARP_SNIFF /* just to skip operation filter below */ - arp_reply->hdr.operation = le2be16(PXE_ARPOP_REPLY); + arp_reply->hdr.operation = htons(PXE_ARPOP_REPLY); #else return (0); #endif } /* we don't need anything except replies on that stage */ - if (arp_reply->hdr.operation != le2be16(PXE_ARPOP_REPLY) ) + if (arp_reply->hdr.operation != htons(PXE_ARPOP_REPLY) ) return (0); /* if arp_usage exceeds MAX_ARP_ENTRIES, occurs rewriting of earlier @@ -376,17 +376,17 @@ if (res != NULL) return (res); - -/* pxe_core_exclusive(PXE_PROTOCOL_ARP); */ - +#ifdef PXE_EXCLUSIVE + pxe_core_exclusive(PXE_PROTOCOL_ARP); +#endif PXE_ARP_WAIT_DATA wait_data; wait_data.ip = ip; wait_data.mac = NULL; pxe_await(pxe_arp_await, PXE_MAX_ARP_TRY, PXE_TIME_TO_DIE, &wait_data); - -/* pxe_core_exclusive(0); */ - +#ifdef PXE_EXCLUSIVE + pxe_core_exclusive(0); +#endif return (wait_data.mac); } ==== //depot/projects/soc2007/taleks-pxe_http/pxe_buffer.c#8 (text+ko) ==== @@ -30,6 +30,31 @@ #include "pxe_buffer.h" #include "pxe_mem.h" +#ifdef PXE_POOL_SLOTS +/* statically allocated space, used for buffer allocating */ +static uint8_t send_pool[PXE_DEFAULT_SEND_BUFSIZE * PXE_POOL_SLOTS]; +static uint8_t recv_pool[PXE_DEFAULT_RECV_BUFSIZE * PXE_POOL_SLOTS]; +/* pool slot usage 0 - unused, 1 - used */ +static uint8_t send_pool_slots[PXE_POOL_SLOTS]; +static uint8_t recv_pool_slots[PXE_POOL_SLOTS]; + +/* pxe_buffer_init() - initializes slots for statically allocated buffers + * in/ out: + * none + */ +void +pxe_buffer_init() +{ + + int slot = 0; + + for ( ; slot < PXE_POOL_SLOTS; ++slot) { + send_pool_slots[slot] = 0; + recv_pool_slots[slot] = 0; + } +} +#endif + /* pxe_buffer_write() - write data to buffer, if possible * in: * buf - pointer to buffer structure @@ -187,6 +212,147 @@ return (buffer->bufleft); } +#ifdef PXE_POOL_SLOTS +int +alloc_free_slot(uint8_t *slots, int slot_count) +{ + int slot = 0; + + for ( ; slot < slot_count; ++slot) + if (slots[slot] == 0) { + slots[slot] = 1; + return (slot); + } + + return (-1); +} + +/* pxe_buffer_memalloc() - allocates memory for buffer + * in: + * buffer - pointer to buffer structure + * size - bytes to allocate + * out: + * 0 - failed + * 1 - success + */ +int +pxe_buffer_memalloc(PXE_BUFFER *buffer, uint16_t size) +{ + + if (buffer == NULL) { +#ifdef PXE_DEBUG + printf("pxe_buffer_memalloc(): NULL buffer\n"); +#endif + return (0); + } + + if (buffer->data != NULL) { + /* buffer has same size */ + if (buffer->bufsize == size) + return (1); + + /* theoretically we never must get here, cause of + * current method of allocating buffers for sockets. + */ + printf("pxe_buffer_memalloc(): Unhandled alloc case.\n"); + return (0); + } + + int slot = -1; + uint8_t *data = NULL; + + switch (size) { + case PXE_DEFAULT_RECV_BUFSIZE: + slot = alloc_free_slot(recv_pool_slots, PXE_POOL_SLOTS); + data = recv_pool + slot * size; + break; + + case PXE_DEFAULT_SEND_BUFSIZE: + slot = alloc_free_slot(send_pool_slots, PXE_POOL_SLOTS); + data = send_pool + slot * size; + break; + + default: + printf("pxe_buffer_memalloc(): unsupported size (%u bytes).\n", + size); + break; + } + + if (slot == -1) /* failed to find free slot */ + return (0); + + buffer->bufsize = size; + buffer->bufleft = size; + buffer->fstart = 0; + buffer->fend = size; + buffer->data = data; + +#ifdef PXE_DEBUG_HELL + printf("pxe_buffer_memalloc(): buffer 0x%x, data 0x%x, bufleft %u.\n", + buffer, buffer->data, buffer->bufleft + ); +#endif + return (1); +} + +/* pxe_buffer_memfree() - release memory used by buffer >>> TRUNCATED FOR MAIL (1000 lines) <<<