From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from wes1-so2.wedos.net (wes1-so2.wedos.net [46.28.106.16]) by dpdk.org (Postfix) with ESMTP id F0AA6532C for ; Fri, 6 May 2016 12:50:49 +0200 (CEST) Received: from pcviktorin.fit.vutbr.cz (pcviktorin.fit.vutbr.cz [147.229.13.147]) by wes1-so2.wedos.net (Postfix) with ESMTPSA id 3r1T8R5njnzv0; Fri, 6 May 2016 12:50:47 +0200 (CEST) From: Jan Viktorin To: dev@dpdk.org Cc: Jan Viktorin , Bruce Richardson , Thomas Monjalon , David Marchand Date: Fri, 6 May 2016 12:48:32 +0200 Message-Id: <1462531720-26217-3-git-send-email-viktorin@rehivetech.com> X-Mailer: git-send-email 2.8.0 In-Reply-To: <1462531720-26217-1-git-send-email-viktorin@rehivetech.com> References: <1462531720-26217-1-git-send-email-viktorin@rehivetech.com> In-Reply-To: <1461935496-20367-1-git-send-email-viktorin@rehivetech.com> References: <1461935496-20367-1-git-send-email-viktorin@rehivetech.com> Subject: [dpdk-dev] [PATCH v1 02/10] app/test: support resources externally linked X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 06 May 2016 10:50:50 -0000 To include resources from other source that the C source code we can take advantage of the objcopy behaviour, i.e. packing of an arbitrary file as an object file that is linked to the target program. A linked object file is always accessible as a pair extern const char beg_; extern const char end_; (extern const char siz_;) The objcopy however accepts architecture parameters in a very tricky way. Try to translate as many arguments as possible from the RTE_ARCH into the objcopy specific names. We pack the resource.c source file as an example for testing. *** CAUTION: *** The objcopy and resource creation is a subject of change. Any comments of how to integrate those are welcome. Signed-off-by: Jan Viktorin --- app/test/Makefile | 32 ++++++++++++++++++++++++++++++++ app/test/resource.h | 5 +++++ app/test/test_resource.c | 18 ++++++++++++++++++ 3 files changed, 55 insertions(+) diff --git a/app/test/Makefile b/app/test/Makefile index 7fbdd18..a9502f1 100644 --- a/app/test/Makefile +++ b/app/test/Makefile @@ -33,6 +33,37 @@ include $(RTE_SDK)/mk/rte.vars.mk ifeq ($(CONFIG_RTE_APP_TEST),y) +ifeq ($(RTE_ARCH),arm) +RTE_OBJCOPY_O = elf32-littlearm +RTE_OBJCOPY_B = arm +else ifeq ($(RTE_ARCH),arm64) +RTE_OBJCOPY_O = elf64-littleaarch64 +RTE_OBJCOPY_B = aarch64 +else ifeq ($(RTE_ARCH),i686) +RTE_OBJCOPY_O = elf32-i386 +RTE_OBJCOPY_B = i386 +else ifeq ($(RTE_ARCH),x86_64) +RTE_OBJCOPY_O = elf64-x86-64 +RTE_OBJCOPY_B = i386:x86-64 +else ifeq ($(RTE_ARCH),x86_x32) +RTE_OBJCOPY_O = elf32-x86-64 +RTE_OBJCOPY_B = i386:x86-64 +else +$(error Unrecognized RTE_ARCH: $(RTE_ARCH)) +endif + +define resource +SRCS-y += $(1).res.o +$(1).res.o: $(2) + $(OBJCOPY) -I binary -B $(RTE_OBJCOPY_B) -O $(RTE_OBJCOPY_O) \ + --rename-section \ + .data=.rodata,alloc,load,data,contents,readonly \ + --redefine-sym _binary__dev_stdin_start=beg_$(1) \ + --redefine-sym _binary__dev_stdin_end=end_$(1) \ + --redefine-sym _binary__dev_stdin_size=siz_$(1) \ + /dev/stdin $$@ < $$< +endef + # # library name # @@ -45,6 +76,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_CMDLINE) := commands.c SRCS-y += test.c SRCS-y += resource.c SRCS-y += test_resource.c +$(eval $(call resource,test_resource_c,resource.c)) SRCS-y += test_pci.c SRCS-y += test_prefetch.c SRCS-y += test_byteorder.c diff --git a/app/test/resource.h b/app/test/resource.h index ce9588e..84ee6b5 100644 --- a/app/test/resource.h +++ b/app/test/resource.h @@ -59,6 +59,11 @@ const struct resource *resource_find(const char *name); void __resource_register(struct resource *r); +#define REGISTER_LINKED_RESOURCE(_n) \ +extern const char beg_ ##_n; \ +extern const char end_ ##_n; \ +REGISTER_RESOURCE(_n, &beg_ ##_n, &end_ ##_n); \ + #define REGISTER_RESOURCE(_n, _b, _e) \ static struct resource linkres_ ##_n = { \ .name = RTE_STR(_n), \ diff --git a/app/test/test_resource.c b/app/test/test_resource.c index e3d2486..7752522 100644 --- a/app/test/test_resource.c +++ b/app/test/test_resource.c @@ -60,11 +60,29 @@ static int test_resource_dpdk(void) return 0; } +REGISTER_LINKED_RESOURCE(test_resource_c); + +static int test_resource_c(void) +{ + const struct resource *r; + + r = resource_find("test_resource_c"); + TEST_ASSERT_NOT_NULL(r, "No test_resource_c found"); + TEST_ASSERT(!strcmp(r->name, "test_resource_c"), + "Found resource %s, expected test_resource_c", + r->name); + + return 0; +} + static int test_resource(void) { if (test_resource_dpdk()) return -1; + if (test_resource_c()) + return -1; + return 0; } -- 2.8.0