Skip to content

Commit

Permalink
Merge pull request #9 from pan-apple/lwip-branch
Browse files Browse the repository at this point in the history
Import LwIP code to CHIP
  • Loading branch information
woody-apple authored Mar 4, 2020
2 parents 0692fac + 2a1d1dd commit 250616d
Show file tree
Hide file tree
Showing 303 changed files with 123,262 additions and 3 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
# - name: Run Build
# run: make
- uses: actions/checkout@v2
- name: Run Build
run: make
82 changes: 82 additions & 0 deletions .yams/cpp_rules.min
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
Common_C_Flags = -DHAVE_CONFIG_H -g -O2

Module_C_Flags += $(Common_C_Flags) $(Module_Includes)
Module_Test_C_Flags += $(Common_C_Flags) $(Module_Test_Includes)

C_Objects = $(C_Files:.c=.o)
CPP_Objects = $(CPP_Files:.cpp=.o)

Tests_C_Files = $(wildcard $(Test_Dir)/*.c)
Tests_C_Exe = $(Tests_C_Files:.c=_q)

Tests_CPP_Files = $(wildcard $(Test_Dir)/*.cpp)
Tests_CPP_Exe = $(Tests_CPP_Files:.cpp=_q)

VALGRIND := $(shell command -v valgrind 2> /dev/null)

ifdef VALGRIND
VALGRIND += --leak-check=yes -q
endif

CPPCHECK := $(shell command -v cppcheck 2> /dev/null)
ifdef CPPCHECK
CPPCHECK += -q --error-exitcode=1
endif

CLANG_FORMAT := $(shell command -v clang-format 2> /dev/null)
ifdef CLANG_FORMAT
CLANG_FORMAT += -style=Chromium -i
endif

GCOV := $(shell command -v gcov 2> /dev/null)

%.o: %.c
@$(CC) $(Module_C_Flags) -c $< -o $@
ifdef CPPCHECK
@$(CPPCHECK) $(Module_Includes) $<
endif
@echo "CC <= $<"

%.o: %.cpp
@$(CXX) $(Module_C_Flags) -c $< -o $@
ifdef CPPCHECK
@$(CPPCHECK) $(Module_Includes) $<
endif
@echo "CXX <= $<"

$(Test_Dir)/%_q: $(Test_Dir)/%.c
ifdef CLANG_FORMAT
@$(CLANG_FORMAT) $<
endif
@$(CC) $< -o $@ $(Module_Test_C_Flags) -L/usr/local/lib $($(*F)_FLAGS) -fprofile-arcs -ftest-coverage -fprofile-dir="$(Test_Dir)"
ifdef CPPCHECK
@$(CPPCHECK) $(Module_Test_Includes) $($(*F)_Inc_FLAGS) $<
endif
@mv $(*F).gc* $(Test_Dir)
@echo "Building tests <= $<"

$(Test_Dir)/%_q: $(Test_Dir)/%.cpp
ifdef CLANG_FORMAT
@$(CLANG_FORMAT) $<
endif
@$(CXX) $< -o $@ $(Module_Test_C_Flags) -L/usr/local/lib $($(*F)_FLAGS) -fprofile-arcs -ftest-coverage -fprofile-dir="$(Test_Dir)"
ifdef CPPCHECK
@$(CPPCHECK) $(Module_Test_Includes) $($(*F)_Inc_FLAGS) $<
endif
@mv $(*F).gc* $(Test_Dir)
@echo "Building tests <= $<"

run_tests: $(Tests_C_Exe) $(Tests_CPP_Exe)
@echo "Running tests <= $<"
@$(foreach f,$^,$(VALGRIND) ./$(f);)
ifneq ($(and $(GCOV),$(Tests_C_Files)),)
@$(GCOV) $(Tests_C_Files)
endif
ifneq ($(and $(GCOV),$(Tests_CPP_Files)),)
@$(GCOV) $(Tests_CPP_Files)
endif

my_clean:
@rm -f $(C_Objects) $(CPP_Objects)
@rm -f $(Tests_C_Exe) $(Tests_CPP_Exe) $(Test_Dir)/*.gcda $(Test_Dir)/*.gcno $(Test_Dir)/*.gcov
@rm -rf $(Test_Dir)/*.dSYM
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
SUB_DIRS=src

.PHONY: all clean test

all test clean:
$(foreach dir,$(SUB_DIRS), $(MAKE) $@ -C $(dir))
9 changes: 9 additions & 0 deletions src/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
TOPTARGETS := all clean run_tests

SUBDIRS = lwip

$(TOPTARGETS): $(SUBDIRS)
$(SUBDIRS):
$(MAKE) -C $@ $(MAKECMDGOALS)

.PHONY: $(TOPTARGETS) $(SUBDIRS)
75 changes: 75 additions & 0 deletions src/lwip/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
TOP_DIR = ../..
Test_Dir = tests

.PHONY: all

all: liblwip.a run_tests

include $(TOP_DIR)/.yams/cpp_rules.min

Module_Includes = \
-I. \
-I$(TOP_DIR) \
-I$(TOP_DIR)/third_party/lwip/repo/lwip/src/include \
-I$(TOP_DIR)/third_party/lwip/repo/lwip/src/include/ipv4 \
-I$(TOP_DIR)/third_party/lwip/repo/lwip/src/include/ipv6 \
-I$(TOP_DIR)/src/lwip \
-I$(TOP_DIR)/src/lwip/standalone

Module_Test_Includes = $(Module_Includes)

C_Files = \
$(TOP_DIR)/third_party/lwip/repo/lwip/src/api/api_lib.c \
$(TOP_DIR)/third_party/lwip/repo/lwip/src/api/api_msg.c \
$(TOP_DIR)/third_party/lwip/repo/lwip/src/api/err.c \
$(TOP_DIR)/third_party/lwip/repo/lwip/src/api/netbuf.c \
$(TOP_DIR)/third_party/lwip/repo/lwip/src/api/netdb.c \
$(TOP_DIR)/third_party/lwip/repo/lwip/src/api/netifapi.c \
$(TOP_DIR)/third_party/lwip/repo/lwip/src/api/sockets.c \
$(TOP_DIR)/third_party/lwip/repo/lwip/src/api/tcpip.c \
$(TOP_DIR)/third_party/lwip/repo/lwip/src/core/def.c \
$(TOP_DIR)/third_party/lwip/repo/lwip/src/core/dns.c \
$(TOP_DIR)/third_party/lwip/repo/lwip/src/core/inet_chksum.c \
$(TOP_DIR)/third_party/lwip/repo/lwip/src/core/init.c \
$(TOP_DIR)/third_party/lwip/repo/lwip/src/core/ipv4/autoip.c \
$(TOP_DIR)/third_party/lwip/repo/lwip/src/core/ipv4/icmp.c \
$(TOP_DIR)/third_party/lwip/repo/lwip/src/core/ipv4/igmp.c \
$(TOP_DIR)/third_party/lwip/repo/lwip/src/core/ipv4/ip4.c \
$(TOP_DIR)/third_party/lwip/repo/lwip/src/core/ipv4/ip4_addr.c \
$(TOP_DIR)/third_party/lwip/repo/lwip/src/core/ipv4/etharp.c \
$(TOP_DIR)/third_party/lwip/repo/lwip/src/core/ipv4/ip4_frag.c \
$(TOP_DIR)/third_party/lwip/repo/lwip/src/core/ipv4/dhcp.c \
$(TOP_DIR)/third_party/lwip/repo/lwip/src/core/ipv6/ip6_route_table.c \
$(TOP_DIR)/third_party/lwip/repo/lwip/src/core/ipv6/dhcp6.c \
$(TOP_DIR)/third_party/lwip/repo/lwip/src/core/ipv6/ethip6.c \
$(TOP_DIR)/third_party/lwip/repo/lwip/src/core/ipv6/icmp6.c \
$(TOP_DIR)/third_party/lwip/repo/lwip/src/core/ipv6/inet6.c \
$(TOP_DIR)/third_party/lwip/repo/lwip/src/core/ipv6/ip6.c \
$(TOP_DIR)/third_party/lwip/repo/lwip/src/core/ipv6/ip6_addr.c \
$(TOP_DIR)/third_party/lwip/repo/lwip/src/core/ipv6/ip6_frag.c \
$(TOP_DIR)/third_party/lwip/repo/lwip/src/core/ipv6/mld6.c \
$(TOP_DIR)/third_party/lwip/repo/lwip/src/core/ipv6/nd6.c \
$(TOP_DIR)/third_party/lwip/repo/lwip/src/core/mem.c \
$(TOP_DIR)/third_party/lwip/repo/lwip/src/core/memp.c \
$(TOP_DIR)/third_party/lwip/repo/lwip/src/core/netif.c \
$(TOP_DIR)/third_party/lwip/repo/lwip/src/core/pbuf.c \
$(TOP_DIR)/third_party/lwip/repo/lwip/src/core/raw.c \
$(TOP_DIR)/third_party/lwip/repo/lwip/src/core/stats.c \
$(TOP_DIR)/third_party/lwip/repo/lwip/src/core/sys.c \
$(TOP_DIR)/third_party/lwip/repo/lwip/src/core/tcp.c \
$(TOP_DIR)/third_party/lwip/repo/lwip/src/core/tcp_in.c \
$(TOP_DIR)/third_party/lwip/repo/lwip/src/core/tcp_out.c \
$(TOP_DIR)/third_party/lwip/repo/lwip/src/core/udp.c \
$(TOP_DIR)/third_party/lwip/repo/lwip/src/core/ip.c \
$(TOP_DIR)/third_party/lwip/repo/lwip/src/core/timeouts.c \
standalone/sys_arch.c \
standalone/TapInterface.c

liblwip.a: $(C_Objects)
@ar cru $@ $^
@echo "LINK => $@"

.PHONY: clean

clean: my_clean
@rm -f liblwip.a *.gcda *.gcno *.gcov
74 changes: 74 additions & 0 deletions src/lwip/efr32/arch/cc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
*
* <COPYRIGHT>
*
*/

#ifndef CHIP_LWIP_FREERTOS_ARCH_CC_H
#define CHIP_LWIP_FREERTOS_ARCH_CC_H

#include <errno.h>
#include <malloc.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <sys/time.h>

#if __cplusplus
extern "C" {
#endif

#ifndef LWIP_NOASSERT
#ifdef DEBUG
#define LWIP_PLATFORM_ASSERT(MSG) assert(MSG);
#else
#define LWIP_PLATFORM_ASSERT(MSG)
#endif
#else
#define LWIP_PLATFORM_ASSERT(message)
#endif

#ifndef BYTE_ORDER
#if defined(__LITTLE_ENDIAN__)
#define BYTE_ORDER LITTLE_ENDIAN
#elif defined(__BIG_ENDIAN__)
#define BYTE_ORDER BIG_ENDIAN
#elif defined(__BYTE_ORDER__)
#define BYTE_ORDER __BYTE_ORDER__
#endif
#endif // BYTE_ORDER

#define PACK_STRUCT_STRUCT __attribute__((__packed__))
#define PACK_STRUCT_FIELD(x) x

extern void LwIPLog(const char *fmt, ...);
#define LWIP_PLATFORM_DIAG(x) \
do \
{ \
LwIPLog x; \
} while (0)

// Place LwIP pools into their own subsections of .bss to make it easier to see
// their sizes in the linker map file.
extern uint8_t __attribute__((section(".bss.lwip_ND6_QUEUE"))) memp_memory_ND6_QUEUE_base[];
extern uint8_t __attribute__((section(".bss.lwip_IP6_REASSDATA"))) memp_memory_IP6_REASSDATA_base[];
extern uint8_t __attribute__((section(".bss.lwip_RAW_PCB"))) memp_memory_RAW_PCB_base[];
extern uint8_t __attribute__((section(".bss.lwip_TCP_SEG"))) memp_memory_TCP_SEG_base[];
extern uint8_t __attribute__((section(".bss.lwip_PBUF_POOL"))) memp_memory_PBUF_POOL_base[];
extern uint8_t __attribute__((section(".bss.lwip_FRAG_PBUF"))) memp_memory_FRAG_PBUF_base[];
extern uint8_t __attribute__((section(".bss.lwip_PBUF"))) memp_memory_PBUF_base[];
extern uint8_t __attribute__((section(".bss.lwip_TCP_PCB_LISTEN"))) memp_memory_TCP_PCB_LISTEN_base[];
extern uint8_t __attribute__((section(".bss.lwip_REASSDATA"))) memp_memory_REASSDATA_base[];
extern uint8_t __attribute__((section(".bss.lwip_UDP_PCB"))) memp_memory_UDP_PCB_base[];
extern uint8_t __attribute__((section(".bss.lwip_MLD6_GROUP"))) memp_memory_MLD6_GROUP_base[];
extern uint8_t __attribute__((section(".bss.lwip_IGMP_GROUP"))) memp_memory_IGMP_GROUP_base[];
extern uint8_t __attribute__((section(".bss.lwip_TCP_PCB"))) memp_memory_TCP_PCB_base[];
extern uint8_t __attribute__((section(".bss.lwip_SYS_TIMEOUT"))) memp_memory_SYS_TIMEOUT_base[];

#if __cplusplus
}
#endif

#endif /* CHIP_LWIP_FREERTOS_ARCH_CC_H */
13 changes: 13 additions & 0 deletions src/lwip/efr32/arch/perf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
*
* <COPYRIGHT>
*
*/

#ifndef CHIP_LWIP_FREERTOS_ARCH_PERF_H
#define CHIP_LWIP_FREERTOS_ARCH_PERF_H

#define PERF_START
#define PERF_STOP(s)

#endif /* CHIP_LWIP_FREERTOS_ARCH_PERF_H */
Loading

0 comments on commit 250616d

Please sign in to comment.