From b22f0e6a0918f6deefb1ccd95e0a21ca0e38f802 Mon Sep 17 00:00:00 2001 From: Ludwig Ortmann Date: Sun, 20 Apr 2014 07:26:12 +0200 Subject: [PATCH 1/3] native/make: set all binutils with ?= instead of = --- boards/native/Makefile.include | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/boards/native/Makefile.include b/boards/native/Makefile.include index e23dcdf11765..1e1fe3360cc2 100644 --- a/boards/native/Makefile.include +++ b/boards/native/Makefile.include @@ -10,10 +10,10 @@ export ELF = $(BINDIR)$(PROJECT).elf # toolchain: export PREFIX = export CC ?= $(PREFIX)gcc -export AR = $(PREFIX)ar -export AS = $(PREFIX)as -export LINK = $(PREFIX)gcc -export SIZE = $(PREFIX)size +export AR ?= $(PREFIX)ar +export AS ?= $(PREFIX)as +export LINK ?= $(PREFIX)gcc +export SIZE ?= $(PREFIX)size export OBJCOPY = true export DEBUGGER = gdb From 42aa3d9f5b26c6689d5f2525027b8475c67c555e Mon Sep 17 00:00:00 2001 From: Ludwig Ortmann Date: Thu, 10 Apr 2014 14:58:12 +0200 Subject: [PATCH 2/3] native: update support for FreeBSD works with FreeBSD 10.0 amd64/i386 fixes: #505 --- boards/native/Makefile.include | 15 +++++++++- cpu/native/include/native_internal.h | 44 ++++++++++++++-------------- cpu/native/irq_cpu.c | 2 +- cpu/native/net/tap.c | 12 +++++++- cpu/native/syscalls.c | 3 ++ 5 files changed, 51 insertions(+), 25 deletions(-) diff --git a/boards/native/Makefile.include b/boards/native/Makefile.include index 1e1fe3360cc2..a9daa0183e1e 100644 --- a/boards/native/Makefile.include +++ b/boards/native/Makefile.include @@ -25,7 +25,20 @@ export GPROF ?= gprof # flags: export CFLAGS += -Wall -Wextra -pedantic -m32 -export LINKFLAGS += -m32 -gc -ldl +ifeq ($(shell uname -s),FreeBSD) +ifeq ($(shell uname -m),amd64) +export CFLAGS += -DCOMPAT_32BIT -L/usr/lib32 -B/usr/lib32 +endif +endif +export LINKFLAGS += -m32 -gc +ifeq ($(shell uname -s),FreeBSD) +ifeq ($(shell uname -m),amd64) +export LINKFLAGS += -DCOMPAT_32BIT -L/usr/lib32 -B/usr/lib32 +endif +export LINKFLAGS += -L $(BINDIR) +else +export LINKFLAGS += -ldl +endif export ASFLAGS = export DEBUGGER_FLAGS = $(ELF) term-memcheck: export VALGRIND_FLAGS ?= --track-origins=yes diff --git a/cpu/native/include/native_internal.h b/cpu/native/include/native_internal.h index a55f20edd017..cf9bf042416f 100644 --- a/cpu/native/include/native_internal.h +++ b/cpu/native/include/native_internal.h @@ -13,6 +13,28 @@ #define _NATIVE_INTERNAL_H #include +/* enable signal handler register access on different platforms + * check here for more: + * http://sourceforge.net/p/predef/wiki/OperatingSystems/ + */ +#if (defined(__FreeBSD__) || defined(__MACH__)) +#ifndef _XOPEN_SOURCE +#define _XOPEN_SOURCE +#include +#undef _XOPEN_SOURCE +#else +#include +#endif +#elif defined(__linux__) +#ifndef _GNU_SOURCE +#define GNU_SOURCE +#include +#undef GNU_SOURCE +#else +#include +#endif +#endif // BSD/Linux + /** * internal functions @@ -76,28 +98,6 @@ int unregister_interrupt(int sig); //#include -/* enable signal handler register access on different platforms - * check here for more: - * http://sourceforge.net/p/predef/wiki/OperatingSystems/ - */ -#ifdef BSD // BSD = (FreeBSD, Darwin, ...) -#ifndef _XOPEN_SOURCE -#define _XOPEN_SOURCE -#include -#undef _XOPEN_SOURCE -#else -#include -#endif -#elif defined(__linux__) -#ifndef _GNU_SOURCE -#define GNU_SOURCE -#include -#undef GNU_SOURCE -#else -#include -#endif -#endif // BSD/Linux - #include "kernel_internal.h" #include "sched.h" diff --git a/cpu/native/irq_cpu.c b/cpu/native/irq_cpu.c index 2de537835cbc..8d8785c37191 100644 --- a/cpu/native/irq_cpu.c +++ b/cpu/native/irq_cpu.c @@ -340,7 +340,7 @@ void native_isr_entry(int sig, siginfo_t *info, void *context) #ifdef __MACH__ _native_saved_eip = ((ucontext_t *)context)->uc_mcontext->__ss.__eip; ((ucontext_t *)context)->uc_mcontext->__ss.__eip = (unsigned int)&_native_sig_leave_tramp; -#elif BSD +#elif defined(__FreeBSD__) _native_saved_eip = ((struct sigcontext *)context)->sc_eip; ((struct sigcontext *)context)->sc_eip = (unsigned int)&_native_sig_leave_tramp; #else diff --git a/cpu/native/net/tap.c b/cpu/native/net/tap.c index 03920dc21177..52ed19da21ab 100644 --- a/cpu/native/net/tap.c +++ b/cpu/native/net/tap.c @@ -31,6 +31,13 @@ #undef _POSIX_C_SOURCE #include #include + +#elif defined(__FreeBSD__) +#include +#include +#include +#include + #else #include #include @@ -232,6 +239,9 @@ int tap_init(char *name) #ifdef __MACH__ /* OSX */ char clonedev[255] = "/dev/"; /* XXX bad size */ strncpy(clonedev+5, name, 250); +#elif defined(__FreeBSD__) + char clonedev[255] = "/dev/"; /* XXX bad size */ + strncpy(clonedev+5, name, 250); #else /* Linux */ struct ifreq ifr; const char *clonedev = "/dev/net/tun"; @@ -242,7 +252,7 @@ int tap_init(char *name) err(EXIT_FAILURE, "open(%s)", clonedev); } -#ifdef __MACH__ /* OSX */ +#if (defined(__MACH__) || defined(__FreeBSD__)) /* OSX/FreeBSD */ struct ifaddrs* iflist; if (getifaddrs(&iflist) == 0) { for (struct ifaddrs *cur = iflist; cur; cur = cur->ifa_next) { diff --git a/cpu/native/syscalls.c b/cpu/native/syscalls.c index 6e94aeba1bcb..dd827dabeed6 100644 --- a/cpu/native/syscalls.c +++ b/cpu/native/syscalls.c @@ -163,6 +163,9 @@ ssize_t _native_write(int fd, const void *buf, size_t count) return r; } +#if defined(__FreeBSD__) +#undef putchar +#endif int putchar(int c) { _native_write(STDOUT_FILENO, &c, 1); return 0; From c2b9d94a0c2b7354ba4c4f2c976bd0c3e4af403b Mon Sep 17 00:00:00 2001 From: Ludwig Ortmann Date: Thu, 17 Apr 2014 18:18:54 +0200 Subject: [PATCH 3/3] native: add tapsetup-freebsd.sh --- cpu/native/tapsetup-freebsd.sh | 54 ++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 cpu/native/tapsetup-freebsd.sh diff --git a/cpu/native/tapsetup-freebsd.sh b/cpu/native/tapsetup-freebsd.sh new file mode 100644 index 000000000000..9b4ab39f9722 --- /dev/null +++ b/cpu/native/tapsetup-freebsd.sh @@ -0,0 +1,54 @@ +#!/bin/sh + +COMMAND=${1} +COUNT=${2} + +DEFCOUNT="2" + +if [ -z "${USER}" ]; then + echo 'need to export $USER' + exit 1 +fi +if [ -z "${COMMAND}" ]; then + echo "usage: $(basename $0) " + exit 1 +fi + +if [ "${COMMAND}" = 'create' ]; then + if [ -z "${COUNT}" ]; then + COUNT="${DEFCOUNT}" + fi + + # load kernel modules + sudo kldload if_tap + sudo kldload if_bridge + + # set permissions + sudo sysctl net.link.tap.user_open=1 + + # create network + echo "creating ${BRNAME} ..." + sudo ifconfig bridge0 create + sudo ifconfig bridge0 up + + for N in $(seq 0 "$((COUNT - 1))"); do + sudo ifconfig tap${N} create + sudo chown ${USER} /dev/tap${N} + sudo ifconfig tap${N} up + sudo ifconfig bridge0 addm tap${N} + done + +elif [ "${COMMAND}" = 'delete' ]; then + # reset permissions (devices already destroyed) + sudo sysctl net.link.tap.user_open=0 + + # unload kernel modules + sudo kldunload if_tap + sudo kldunload if_bridge + +else + echo 'unknown command' + exit 1 +fi + +exit 0