Skip to content

Commit 02165fe

Browse files
anjiahao1extinguish
authored andcommitted
apps:modify examples elf compile method
rearrange the elf test directory, make the sub-testcase in separate directory Signed-off-by: anjiahao <[email protected]>
1 parent 947acda commit 02165fe

File tree

31 files changed

+327
-692
lines changed

31 files changed

+327
-692
lines changed

examples/elf/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/Kconfig

examples/elf/CMakeLists.txt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,5 @@
2020
#
2121
# ##############################################################################
2222

23-
if(CONFIG_EXAMPLES_ELF)
24-
nuttx_add_application(NAME elf SRCS elf_main.c)
25-
26-
# TODO: tests
27-
28-
endif()
23+
nuttx_add_subdirectory()
24+
nuttx_generate_kconfig(MENUDESC "Elf")

examples/elf/Make.defs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,4 @@
2020
#
2121
############################################################################
2222

23-
ifneq ($(CONFIG_EXAMPLES_ELF),)
24-
CONFIGURED_APPS += $(APPDIR)/examples/elf
25-
endif
23+
include $(wildcard $(APPDIR)/examples/elf/*/Make.defs)

examples/elf/Makefile

Lines changed: 2 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -20,47 +20,6 @@
2020
#
2121
############################################################################
2222

23-
include $(APPDIR)/Make.defs
23+
MENUDESC = "Elf example"
2424

25-
# ELF Example
26-
27-
ifeq ($(CONFIG_EXAMPLES_ELF_ROMFS),y)
28-
CSRCS = romfs.c
29-
endif
30-
ifeq ($(CONFIG_EXAMPLES_ELF_CROMFS),y)
31-
CSRCS = cromfs.c
32-
endif
33-
CSRCS += dirlist.c
34-
CSRCS += symtab.c
35-
tests$(DELIM)symtab.c_CFLAGS = -fno-builtin
36-
tests$(DELIM)symtab.c_CELFFLAGS = -fno-builtin
37-
MAINSRC = elf_main.c
38-
39-
PROGNAME = elf
40-
PRIORITY = SCHED_PRIORITY_DEFAULT
41-
STACKSIZE = $(CONFIG_DEFAULT_TASK_STACKSIZE)
42-
MODULE = $(CONFIG_EXAMPLES_ELF)
43-
44-
DEPPATH := --dep-path tests
45-
46-
# Build targets
47-
48-
VPATH += :tests
49-
50-
ifeq ($(CONFIG_EXAMPLES_ELF_ROMFS),y)
51-
tests/romfs.c: build
52-
endif
53-
ifeq ($(CONFIG_EXAMPLES_ELF_CROMFS),y)
54-
tests/cromfs.c: build
55-
endif
56-
tests/dirlist.c: build
57-
tests/symtab.c: build
58-
59-
.PHONY: build
60-
build:
61-
+$(Q) $(MAKE) -C tests TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)" CROSSDEV=$(CROSSDEV)
62-
63-
clean::
64-
+$(Q) $(MAKE) -C tests TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)" CROSSDEV=$(CROSSDEV) clean
65-
66-
include $(APPDIR)/Application.mk
25+
include $(APPDIR)/Directory.mk

examples/elf/main/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/elf_romfs.c
2+
/elf_romfs.img
3+
/cromfs.c
4+
/test_symtab.c

examples/elf/main/CMakeLists.txt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# ##############################################################################
2+
# apps/examples/elf/main/CMakeLists.txt
3+
#
4+
# Licensed to the Apache Software Foundation (ASF) under one or more contributor
5+
# license agreements. See the NOTICE file distributed with this work for
6+
# additional information regarding copyright ownership. The ASF licenses this
7+
# file to you under the Apache License, Version 2.0 (the "License"); you may not
8+
# use this file except in compliance with the License. You may obtain a copy of
9+
# the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16+
# License for the specific language governing permissions and limitations under
17+
# the License.
18+
#
19+
# ##############################################################################
20+
21+
if(CONFIG_EXAMPLES_ELF)
22+
nuttx_add_application(NAME elf SRCS elf_main.c)
23+
24+
# TODO: tests
25+
26+
endif()
File renamed without changes.

examples/elf/main/Make.defs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
############################################################################
2+
# apps/examples/elf/main/Make.defs
3+
#
4+
# Licensed to the Apache Software Foundation (ASF) under one or more
5+
# contributor license agreements. See the NOTICE file distributed with
6+
# this work for additional information regarding copyright ownership. The
7+
# ASF licenses this file to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance with the
9+
# License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16+
# License for the specific language governing permissions and limitations
17+
# under the License.
18+
#
19+
############################################################################
20+
21+
ifneq ($(CONFIG_EXAMPLES_ELF),)
22+
CONFIGURED_APPS += $(APPDIR)/examples/elf/main
23+
endif

examples/elf/main/Makefile

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
############################################################################
2+
# apps/examples/elf/main/Makefile
3+
#
4+
# Licensed to the Apache Software Foundation (ASF) under one or more
5+
# contributor license agreements. See the NOTICE file distributed with
6+
# this work for additional information regarding copyright ownership. The
7+
# ASF licenses this file to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance with the
9+
# License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14+
# License for the specific language governing permissions and limitations
15+
# under the License.
16+
#
17+
############################################################################
18+
19+
include $(APPDIR)/Make.defs
20+
21+
# Module example built-in application info
22+
23+
PROGNAME = elf
24+
PRIORITY = SCHED_PRIORITY_DEFAULT
25+
STACKSIZE = $(CONFIG_DEFAULT_TASK_STACKSIZE)
26+
MODULE = $(CONFIG_EXAMPLES_ELF)
27+
28+
MAINSRC = elf_main.c
29+
30+
SYMTABSRC = test_symtab.c
31+
SYMTABOBJ = $(SYMTABSRC:.c=$(OBJEXT))
32+
33+
34+
ifneq ($(CONFIG_BUILD_FLAT),y)
35+
PASS1_SYMTAB = $(TOPDIR)/pass1/mod_symtab.c
36+
MODLUE_NAME = tests
37+
endif
38+
39+
$(SYMTABSRC):
40+
$(Q) $(APPDIR)$(DELIM)tools$(DELIM)mksymtab.sh $(BINDIR) g_elf >$@.tmp
41+
$(Q) $(call TESTANDREPLACEFILE, $@.tmp, $@)
42+
43+
44+
$(SYMTABOBJ): %$(OBJEXT): %.c
45+
$(call COMPILE, $<, $@, -fno-lto -fno-builtin)
46+
47+
ifeq ($(CONFIG_EXAMPLES_ELF_ROMFS),y)
48+
49+
ROMFSIMG = elf_romfs.img
50+
ROMFSSRC = elf_romfs.c
51+
ROMFSOBJ = $(ROMFSSRC:.c=$(OBJEXT))
52+
53+
$(ROMFSIMG):
54+
$(Q) genromfs -d $(BINDIR) -f $@
55+
56+
$(ROMFSSRC): $(ROMFSIMG)
57+
$(Q) (echo "#include <nuttx/compiler.h>" >$@ && \
58+
xxd -i $(ROMFSIMG) | sed -e "s/^unsigned char/const unsigned char aligned_data(4)/g" >>$@)
59+
60+
$(ROMFSOBJ): %$(OBJEXT): %.c
61+
$(call COMPILE, $<, $@, -fno-lto -fno-builtin)
62+
63+
else ifeq ($(CONFIG_EXAMPLES_ELF_CROMFS),y)
64+
NXTOOLDIR = $(TOPDIR)/tools
65+
GENCROMFSSRC = gencromfs.c
66+
GENCROMFSEXE = gencromfs$(HOSTEXEEXT)
67+
68+
FSIMG_SRC = cromfs.c
69+
FSIMG_OBJ = $(FSIMG_SRC:.c=$(OBJEXT))
70+
71+
$(NXTOOLDIR)/$(GENCROMFSEXE): $(NXTOOLDIR)/$(GENCROMFSSRC)
72+
$(Q) $(MAKE) -C $(NXTOOLDIR) -f Makefile.host $(GENCROMFSEXE)
73+
74+
# Create the cromfs.c file from the populated cromfs directory
75+
76+
$(FSIMG_SRC):$(NXTOOLDIR)/$(GENCROMFSEXE)
77+
$(Q) $(NXTOOLDIR)/$(GENCROMFSEXE) $(BINDIR) $@.tmp
78+
$(Q) $(call TESTANDREPLACEFILE, $@.tmp, $@)
79+
80+
$(FSIMG_OBJ): %$(OBJEXT): %.c
81+
$(call COMPILE, $<, $@, -fno-lto -fno-builtin)
82+
83+
endif
84+
85+
# Copy the symbol table into the kernel pass1/ build directory
86+
87+
ifneq ($(CONFIG_BUILD_FLAT),y)
88+
$(PASS1_SYMTAB): $(SYMTABSRC)
89+
$(Q) install -m 0644 $(SYMTABSRC) $(PASS1_SYMTAB)
90+
$(Q) mv $(BINDIR)$(DELIM)$(MODLUE_NAME) .
91+
endif
92+
93+
postinstall:: $(ROMFSOBJ) $(SYMTABOBJ) $(FSIMG_OBJ) $(PASS1_SYMTAB)
94+
$(call ARLOCK, $(call CONVERT_PATH,$(BIN)), $^)
95+
96+
distclean::
97+
$(Q) $(call DELFILE, $(SYMTABSRC) $(SYMTABOBJ) $(ROMFSSRC) $(ROMFSIMG) $(ROMFSOBJ) $(MODLUE_NAME))
98+
99+
100+
include $(APPDIR)/Application.mk

examples/elf/elf_main.c renamed to examples/elf/main/elf_main.c

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/****************************************************************************
2-
* apps/examples/elf/elf_main.c
2+
* apps/examples/elf/main/elf_main.c
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*
@@ -132,8 +132,35 @@ extern const unsigned int elf_romfs_img_len;
132132
# error "No file system selected"
133133
#endif
134134

135-
extern const char *dirlist[];
136-
135+
const char *dirlist[] =
136+
{
137+
"errno",
138+
"hello",
139+
"signal",
140+
"struct",
141+
#ifdef CONFIG_HAVE_CXX
142+
"hello++1",
143+
"hello++2",
144+
# ifdef CONFIG_HAVE_CXXINITIALIZE
145+
"hello++3",
146+
# endif
147+
# ifdef CONFIG_EXAMPLES_ELF_CXX
148+
"hello++4",
149+
"hello++5",
150+
# endif
151+
#endif
152+
#ifdef CONFIG_EXAMPLES_ELF_LONGJMP
153+
"longjmp"
154+
#endif
155+
#ifndef CONFIG_DISABLE_PTHREAD
156+
"mutex",
157+
"pthread",
158+
#endif
159+
#ifndef CONFIG_ARCH_ADDRENV
160+
"task",
161+
#endif
162+
NULL
163+
};
137164
extern const struct symtab_s g_elf_exports[];
138165
extern const int g_elf_nexports;
139166

0 commit comments

Comments
 (0)