mirror of
https://github.com/freebsd/freebsd-src
synced 2024-10-15 04:43:53 +00:00
USB boot library improvements:
- Make the USB boot library more configurable. - Resolve compile issues when cross building. - Allow use of separate malloc. - Allow use of separate endian macros. Sponsored by: DARPA, AFRL
This commit is contained in:
parent
6eda7f75c1
commit
ccc29eb1b9
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=266882
|
@ -30,6 +30,7 @@ S=${.CURDIR}/../..
|
|||
|
||||
.PATH: \
|
||||
${.CURDIR} \
|
||||
${.CURDIR}/storage \
|
||||
${S}/dev/usb \
|
||||
${S}/dev/usb/controller \
|
||||
${S}/dev/usb/serial \
|
||||
|
@ -39,7 +40,7 @@ S=${.CURDIR}/../..
|
|||
LIB= usbboot
|
||||
INTERNALLIB=
|
||||
OBJCOPY?= objcopy
|
||||
SYSCC?= cc
|
||||
SYSCC?= /usr/bin/cc
|
||||
|
||||
CFLAGS+= -DBOOTPROG=\"usbloader\"
|
||||
CFLAGS+= -DUSB_GLOBAL_INCLUDE_FILE=\"bsd_global.h\"
|
||||
|
@ -49,7 +50,13 @@ CFLAGS+= -Wformat -Wall
|
|||
CFLAGS+= -I${S}
|
||||
CFLAGS+= -I${T}
|
||||
CFLAGS+= -I${.CURDIR}
|
||||
CFLAGS+= -I${.CURDIR}/../common
|
||||
CFLAGS+= -g
|
||||
CFLAGS+= -DUSB_MSCTEST_BULK_SIZE=65536
|
||||
CFLAGS+= -DUSB_POOL_SIZE=262144
|
||||
CFLAGS+= -fno-pic
|
||||
CFLAGS+= -DHAVE_ENDIAN_DEFS
|
||||
CFLAGS+= -DHAVE_MALLOC
|
||||
|
||||
.if ${MACHINE_CPUARCH} == "i386" || ${MACHINE_CPUARCH} == "amd64"
|
||||
CFLAGS+= -march=i386
|
||||
|
@ -58,6 +65,9 @@ CFLAGS.gcc+= -mpreferred-stack-boundary=2
|
|||
.if ${MACHINE_CPUARCH} == "amd64"
|
||||
CFLAGS+= -m32
|
||||
.endif
|
||||
.if ${MACHINE_CPUARCH} == "mips"
|
||||
CFLAGS+= -mno-abicalls
|
||||
.endif
|
||||
|
||||
#
|
||||
# Single threaded BSD kernel
|
||||
|
@ -77,19 +87,66 @@ SRCS+= usb_busdma_loader.c
|
|||
#
|
||||
# USB controller drivers
|
||||
#
|
||||
SRCS+= at91dci.c
|
||||
SRCS+= atmegadci.c
|
||||
SRCS+= avr32dci.c
|
||||
SRCS+= dwc_otg.c
|
||||
SRCS+= ehci.c
|
||||
SRCS+= musb_otg.c
|
||||
SRCS+= ohci.c
|
||||
SRCS+= uhci.c
|
||||
SRCS+= uss820dci.c
|
||||
SRCS+= xhci.c
|
||||
|
||||
SRCS+= usb_controller.c
|
||||
|
||||
CFLAGS += -DUSB_PROBE_LIST="\"xhci\", \"ehci\", \"uhci\", \"ohci\""
|
||||
.if defined(HAVE_AT91DCI)
|
||||
CFLAGS += -DUSB_PCI_PROBE_LIST="\"at91dci\""
|
||||
SRCS+= at91dci.c
|
||||
.endif
|
||||
|
||||
.if defined(HAVE_ATMEGADCI)
|
||||
CFLAGS += -DUSB_PCI_PROBE_LIST="\"atmegadci\""
|
||||
SRCS+= atmegadci.c
|
||||
.endif
|
||||
|
||||
.if defined(HAVE_AVR32DCI)
|
||||
CFLAGS += -DUSB_PCI_PROBE_LIST="\"avr32dci\""
|
||||
SRCS+= avr32dci.c
|
||||
.endif
|
||||
|
||||
.if defined(HAVE_DWCOTG)
|
||||
CFLAGS += -DUSB_PCI_PROBE_LIST="\"dwcotg\""
|
||||
SRCS+= dwcotg.c
|
||||
.endif
|
||||
|
||||
.if defined(HAVE_MUSBOTG)
|
||||
CFLAGS += -DUSB_PCI_PROBE_LIST="\"musbotg\""
|
||||
SRCS+= musbotg.c
|
||||
.endif
|
||||
|
||||
.if defined(HAVE_EHCI)
|
||||
CFLAGS += -DUSB_PCI_PROBE_LIST="\"ehci\""
|
||||
SRCS+= ehci.c
|
||||
.endif
|
||||
|
||||
.if defined(HAVE_OHCI)
|
||||
CFLAGS += -DUSB_PCI_PROBE_LIST="\"ohci\""
|
||||
SRCS+= ohci.c
|
||||
.endif
|
||||
|
||||
.if defined(HAVE_UHCI)
|
||||
CFLAGS += -DUSB_PCI_PROBE_LIST="\"uhci\""
|
||||
SRCS+= uhci.c
|
||||
.endif
|
||||
|
||||
.if defined(HAVE_XHCI)
|
||||
CFLAGS += -DUSB_PCI_PROBE_LIST="\"xhci\""
|
||||
SRCS+= xhci.c
|
||||
.endif
|
||||
|
||||
.if defined(HAVE_USS820DCI)
|
||||
CFLAGS += -DUSB_PCI_PROBE_LIST="\"uss820dci\""
|
||||
SRCS+= uss820dci.c
|
||||
.endif
|
||||
|
||||
.if defined(HAVE_SAF1761OTG)
|
||||
CFLAGS += -DUSB_PCI_PROBE_LIST="\"saf1761otg\""
|
||||
CFLAGS += -DUSB_PCI_MEMORY_ADDRESS=0x900000007f100000ULL
|
||||
CFLAGS += -DUSB_PCI_MEMORY_SIZE=0x40000U
|
||||
SRCS+= saf1761_otg.c
|
||||
SRCS+= saf1761_otg_boot.c
|
||||
.endif
|
||||
|
||||
#
|
||||
# USB core and templates
|
||||
|
@ -119,6 +176,15 @@ SRCS+= usb_template_audio.c
|
|||
SRCS+= sysinit_data.c
|
||||
SRCS+= sysuninit_data.c
|
||||
|
||||
#
|
||||
# USB mass storage support
|
||||
#
|
||||
SRCS+= umass_common.c
|
||||
|
||||
.if defined(HAVE_UMASS_LOADER)
|
||||
SRCS+= umass_loader.c
|
||||
.endif
|
||||
|
||||
CLEANFILES+= sysinit
|
||||
CLEANFILES+= sysinit.bin
|
||||
CLEANFILES+= sysinit_data.c
|
||||
|
|
|
@ -1091,6 +1091,7 @@ usb_proc_mwait(struct usb_process *up, void *_pm0, void *_pm1)
|
|||
* SYSTEM attach
|
||||
*------------------------------------------------------------------------*/
|
||||
|
||||
#ifdef USB_PCI_PROBE_LIST
|
||||
static device_method_t pci_methods[] = {
|
||||
DEVMETHOD_END
|
||||
};
|
||||
|
@ -1105,9 +1106,7 @@ static devclass_t pci_devclass;
|
|||
DRIVER_MODULE(pci, pci, pci_driver, pci_devclass, 0, 0);
|
||||
|
||||
static const char *usb_pci_devices[] = {
|
||||
#ifdef USB_PROBE_LIST
|
||||
USB_PROBE_LIST
|
||||
#endif
|
||||
USB_PCI_PROBE_LIST
|
||||
};
|
||||
|
||||
#define USB_PCI_USB_MAX (sizeof(usb_pci_devices) / sizeof(void *))
|
||||
|
@ -1150,11 +1149,13 @@ usb_pci_mod_unload(void *arg)
|
|||
device_delete_child(NULL, usb_pci_root);
|
||||
}
|
||||
SYSUNINIT(usb_pci_mod_unload, SI_SUB_RUN_SCHEDULER, SI_ORDER_MIDDLE, usb_pci_mod_unload, 0);
|
||||
#endif
|
||||
|
||||
/*------------------------------------------------------------------------*
|
||||
* MALLOC API
|
||||
*------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef HAVE_MALLOC
|
||||
#define USB_POOL_ALIGN 8
|
||||
|
||||
static uint8_t usb_pool[USB_POOL_SIZE] __aligned(USB_POOL_ALIGN);
|
||||
|
@ -1183,7 +1184,7 @@ usb_malloc(unsigned long size)
|
|||
}
|
||||
|
||||
if (hdr) {
|
||||
printf("MALLOC: Entries = %d; Remainder = %d; Size = %d\n",
|
||||
DPRINTF("MALLOC: Entries = %d; Remainder = %d; Size = %d\n",
|
||||
(int)usb_pool_entries, (int)usb_pool_rem, (int)size);
|
||||
|
||||
TAILQ_REMOVE(&malloc_head, hdr, entry);
|
||||
|
@ -1197,7 +1198,7 @@ usb_malloc(unsigned long size)
|
|||
usb_pool_rem -= size;
|
||||
usb_pool_entries++;
|
||||
|
||||
printf("MALLOC: Entries = %d; Remainder = %d; Size = %d\n",
|
||||
DPRINTF("MALLOC: Entries = %d; Remainder = %d; Size = %d\n",
|
||||
(int)usb_pool_entries, (int)usb_pool_rem, (int)size);
|
||||
|
||||
memset(hdr + 1, 0, hdr->size - sizeof(*hdr));
|
||||
|
@ -1219,6 +1220,7 @@ usb_free(void *arg)
|
|||
|
||||
TAILQ_INSERT_TAIL(&malloc_head, hdr, entry);
|
||||
}
|
||||
#endif
|
||||
|
||||
char *
|
||||
usb_strdup(const char *str)
|
||||
|
@ -1228,7 +1230,7 @@ usb_strdup(const char *str)
|
|||
|
||||
len = 1 + strlen(str);
|
||||
|
||||
tmp = usb_malloc(len);
|
||||
tmp = malloc(len,XXX,XXX);
|
||||
if (tmp == NULL)
|
||||
return (NULL);
|
||||
|
||||
|
|
|
@ -28,7 +28,8 @@
|
|||
#define _BSD_KERNEL_H_
|
||||
|
||||
#define _KERNEL
|
||||
#define __FreeBSD_version 1000000
|
||||
#undef __FreeBSD_version
|
||||
#define __FreeBSD_version 1100000
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#include <sys/queue.h>
|
||||
|
@ -92,8 +93,11 @@ SYSINIT_ENTRY(uniq##_entry, "sysuninit", (subs), \
|
|||
#define BUS_SPACE_BARRIER_READ 0x01
|
||||
#define BUS_SPACE_BARRIER_WRITE 0x02
|
||||
#define hz 1000
|
||||
#undef PAGE_SIZE
|
||||
#define PAGE_SIZE 4096
|
||||
#undef MIN
|
||||
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
|
||||
#undef MAX
|
||||
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
|
||||
#define MTX_DEF 0
|
||||
#define MTX_SPIN 0
|
||||
|
@ -104,10 +108,15 @@ SYSINIT_ENTRY(uniq##_entry, "sysuninit", (subs), \
|
|||
#define cold 0
|
||||
#define BUS_PROBE_GENERIC 0
|
||||
#define CALLOUT_RETURNUNLOCKED 0x1
|
||||
#undef va_list
|
||||
#define va_list __builtin_va_list
|
||||
#undef va_size
|
||||
#define va_size(type) __builtin_va_size(type)
|
||||
#undef va_start
|
||||
#define va_start(ap, last) __builtin_va_start(ap, last)
|
||||
#undef va_end
|
||||
#define va_end(ap) __builtin_va_end(ap)
|
||||
#undef va_arg
|
||||
#define va_arg(ap, type) __builtin_va_arg((ap), type)
|
||||
#define DEVICE_ATTACH(dev, ...) \
|
||||
(((device_attach_t *)(device_get_method(dev, "device_attach")))(dev,## __VA_ARGS__))
|
||||
|
@ -150,30 +159,24 @@ struct thread;
|
|||
struct malloc_type;
|
||||
struct usb_process;
|
||||
|
||||
#ifndef HAVE_STANDARD_DEFS
|
||||
#define _UINT8_T_DECLARED
|
||||
typedef unsigned char uint8_t;
|
||||
#define _INT8_T_DECLARED
|
||||
typedef signed char int8_t;
|
||||
|
||||
#define _UINT16_T_DECLARED
|
||||
typedef unsigned short uint16_t;
|
||||
#define _INT16_T_DECLARED
|
||||
typedef signed short int16_t;
|
||||
|
||||
#define _UINT32_T_DECLARED
|
||||
typedef unsigned int uint32_t;
|
||||
#define _INT32_T_DECLARED
|
||||
typedef signed int int32_t;
|
||||
|
||||
#define _UINT64_T_DECLARED
|
||||
typedef unsigned long long uint64_t;
|
||||
#define _INT16_T_DECLARED
|
||||
typedef signed long long int64_t;
|
||||
|
||||
typedef unsigned long bus_addr_t;
|
||||
typedef unsigned long bus_size_t;
|
||||
|
||||
typedef unsigned long size_t;
|
||||
typedef unsigned long u_long;
|
||||
|
||||
typedef void *bus_dmamap_t;
|
||||
typedef void *bus_dma_tag_t;
|
||||
|
||||
typedef void *bus_space_tag_t;
|
||||
typedef uint8_t *bus_space_handle_t;
|
||||
|
||||
typedef uint16_t uid_t;
|
||||
typedef uint16_t gid_t;
|
||||
typedef uint16_t mode_t;
|
||||
|
@ -182,6 +185,19 @@ typedef uint8_t *caddr_t;
|
|||
typedef unsigned long __uintptr_t;
|
||||
typedef unsigned long uintptr_t;
|
||||
|
||||
typedef unsigned long size_t;
|
||||
typedef unsigned long u_long;
|
||||
#endif
|
||||
|
||||
typedef unsigned long bus_addr_t;
|
||||
typedef unsigned long bus_size_t;
|
||||
|
||||
typedef void *bus_dmamap_t;
|
||||
typedef void *bus_dma_tag_t;
|
||||
|
||||
typedef void *bus_space_tag_t;
|
||||
typedef uint8_t *bus_space_handle_t;
|
||||
|
||||
/* SYSINIT API */
|
||||
|
||||
#include <sysinit.h>
|
||||
|
@ -414,17 +430,31 @@ size_t strlen(const char *s);
|
|||
|
||||
/* MALLOC API */
|
||||
|
||||
#ifndef HAVE_MALLOC
|
||||
#undef malloc
|
||||
#define malloc(s,x,f) usb_malloc(s)
|
||||
void *usb_malloc(size_t);
|
||||
|
||||
#undef free
|
||||
#define free(p,x) usb_free(p)
|
||||
void usb_free(void *);
|
||||
#else
|
||||
#undef malloc
|
||||
void *malloc(size_t);
|
||||
#define malloc(s,x,f) malloc(s)
|
||||
|
||||
#undef free
|
||||
void free(void *);
|
||||
#define free(p,x) free(p)
|
||||
#endif
|
||||
|
||||
#define strdup(p,x) usb_strdup(p)
|
||||
char *usb_strdup(const char *str);
|
||||
|
||||
/* ENDIANNESS */
|
||||
|
||||
#ifndef HAVE_ENDIAN_DEFS
|
||||
|
||||
/* Assume little endian */
|
||||
|
||||
#define htole64(x) ((uint64_t)(x))
|
||||
|
@ -439,6 +469,10 @@ char *usb_strdup(const char *str);
|
|||
#define be32toh(x) ((uint32_t)(x))
|
||||
#define htobe32(x) ((uint32_t)(x))
|
||||
|
||||
#else
|
||||
#include <sys/endian.h>
|
||||
#endif
|
||||
|
||||
/* USB */
|
||||
|
||||
typedef int usb_handle_request_t (device_t dev, const void *req, void **pptr, uint16_t *plen, uint16_t offset, uint8_t *pstate);
|
||||
|
|
|
@ -211,13 +211,13 @@ usb_pc_alloc_mem(struct usb_page_cache *pc, struct usb_page *pg,
|
|||
/* allocate zeroed memory */
|
||||
|
||||
if (align != 1) {
|
||||
ptr = usb_malloc(size + align);
|
||||
ptr = malloc(size + align, XXX, XXX);
|
||||
if (ptr == NULL)
|
||||
goto error;
|
||||
|
||||
rem = (-((uintptr_t)ptr)) & (align - 1);
|
||||
} else {
|
||||
ptr = usb_malloc(size);
|
||||
ptr = malloc(size, XXX, XXX);
|
||||
if (ptr == NULL)
|
||||
goto error;
|
||||
rem = 0;
|
||||
|
@ -258,7 +258,7 @@ void
|
|||
usb_pc_free_mem(struct usb_page_cache *pc)
|
||||
{
|
||||
if (pc != NULL && pc->buffer != NULL) {
|
||||
usb_free(pc->tag);
|
||||
free(pc->tag, XXX);
|
||||
pc->buffer = NULL;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue