From 14dc70e6937cc0111d394f3c38978a9206eb0fa3 Mon Sep 17 00:00:00 2001 From: Pim van Pelt Date: Sun, 5 Apr 2020 22:04:49 +0200 Subject: [PATCH 1/6] Fix size_t casting Using %zu allows to cast size_t on 32bit and 64bit machine types. This prepares for cross-compiled builds in and was found in: https://github.com/cesanta/mongoose-os/issues/533 --- platforms/ubuntu/src/ubuntu_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platforms/ubuntu/src/ubuntu_main.c b/platforms/ubuntu/src/ubuntu_main.c index d16f8f320..5d359eefe 100644 --- a/platforms/ubuntu/src/ubuntu_main.c +++ b/platforms/ubuntu/src/ubuntu_main.c @@ -230,7 +230,7 @@ enum mgos_init_result mongoose_init(void) { cpu_freq = (int) (mgos_get_cpu_freq() / 1000000); heap_size = mgos_get_heap_size(); free_heap_size = mgos_get_free_heap_size(); - LOG(LL_INFO, ("CPU: %d MHz, heap: %lu total, %lu free", cpu_freq, heap_size, + LOG(LL_INFO, ("CPU: %d MHz, heap: %u total, %zu free", cpu_freq, heap_size, free_heap_size)); mgos_invoke_cb(ubuntu_net_up, NULL, false /* from_isr */); From 8d5fd87766c66b322926627003e98e164348ae07 Mon Sep 17 00:00:00 2001 From: Pim van Pelt Date: Sun, 5 Apr 2020 22:06:05 +0200 Subject: [PATCH 2/6] Allow for EABIHF cross compiling, add to docker and Makefile. See https://github.com/cesanta/mongoose-os/issues/533 --- platforms/ubuntu/Makefile.build | 7 +++++++ tools/docker/ubuntu/Dockerfile-ubuntu-build | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/platforms/ubuntu/Makefile.build b/platforms/ubuntu/Makefile.build index bd13bdd60..7805dc325 100644 --- a/platforms/ubuntu/Makefile.build +++ b/platforms/ubuntu/Makefile.build @@ -23,6 +23,7 @@ APP_EXTRA_FW_PARTS ?= ASAN ?= 0 PROF ?= 0 +ARMHF ?= 1 # Explicitly disable updater, it's not supported on POSIX build yet. MGOS_ENABLE_DEBUG_UDP = 0 @@ -74,6 +75,12 @@ CXX = clang++ C_CXX_FLAGS += -fprofile-instr-generate -fcoverage-mapping LDFLAGS += -fprofile-instr-generate endif +ifeq "$(ARMHF)" "1" +CC = arm-linux-gnueabihf-gcc +CXX = arm-linux-gnueabihf-g++ +AR = arm-linux-gnueabihf-ar +LD = arm-linux-gnueabihf-ld +endif ifdef MGOS_HAVE_DNS_SD LDFLAGS += -lavahi-client -lavahi-common -lstdc++ diff --git a/tools/docker/ubuntu/Dockerfile-ubuntu-build b/tools/docker/ubuntu/Dockerfile-ubuntu-build index 6f6b03f39..831d5f0fc 100644 --- a/tools/docker/ubuntu/Dockerfile-ubuntu-build +++ b/tools/docker/ubuntu/Dockerfile-ubuntu-build @@ -6,7 +6,7 @@ RUN DEBIAN_FRONTEND=noninteractive apt-get update && \ libexpat-dev libncurses5-dev libtool-bin \ python python-dev python-git python-pyelftools python-serial python-six python-yaml \ python3 python3-dev python3-git python3-pyelftools python3-serial python3-six python3-yaml \ - software-properties-common texinfo unzip wget zip && \ + software-properties-common texinfo unzip wget zip gcc-multilib-arm-linux-gnueabihf g++-arm-linux-gnueabihf && \ apt-get clean RUN DEBIAN_FRONTEND=noninteractive apt-get update && \ From 07b2403c6f5ae9888b3e9beddca01770bc59fbb5 Mon Sep 17 00:00:00 2001 From: Pim van Pelt Date: Sun, 5 Apr 2020 23:05:17 +0200 Subject: [PATCH 3/6] Add EABI w/o hard floating point, and add ARM64 cross compilers --- tools/docker/ubuntu/Dockerfile-ubuntu-build | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/docker/ubuntu/Dockerfile-ubuntu-build b/tools/docker/ubuntu/Dockerfile-ubuntu-build index 831d5f0fc..1a9c704c7 100644 --- a/tools/docker/ubuntu/Dockerfile-ubuntu-build +++ b/tools/docker/ubuntu/Dockerfile-ubuntu-build @@ -6,7 +6,10 @@ RUN DEBIAN_FRONTEND=noninteractive apt-get update && \ libexpat-dev libncurses5-dev libtool-bin \ python python-dev python-git python-pyelftools python-serial python-six python-yaml \ python3 python3-dev python3-git python3-pyelftools python3-serial python3-six python3-yaml \ - software-properties-common texinfo unzip wget zip gcc-multilib-arm-linux-gnueabihf g++-arm-linux-gnueabihf && \ + software-properties-common texinfo unzip wget zip \ + gcc-multilib-arm-linux-gnueabi g++-arm-linux-gnueabi \ + gcc-multilib-arm-linux-gnueabihf g++-arm-linux-gnueabihf \ + gcc-aarch64-linux-gnu g++-aarch64-linux-gnu && \ apt-get clean RUN DEBIAN_FRONTEND=noninteractive apt-get update && \ From f8bb88b84c1f5b1da706aa3d2fff1235832903f1 Mon Sep 17 00:00:00 2001 From: Pim van Pelt Date: Sun, 5 Apr 2020 23:16:10 +0200 Subject: [PATCH 4/6] Cast size_t to %zu --- platforms/ubuntu/src/ubuntu_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platforms/ubuntu/src/ubuntu_main.c b/platforms/ubuntu/src/ubuntu_main.c index 5d359eefe..862b949f8 100644 --- a/platforms/ubuntu/src/ubuntu_main.c +++ b/platforms/ubuntu/src/ubuntu_main.c @@ -230,7 +230,7 @@ enum mgos_init_result mongoose_init(void) { cpu_freq = (int) (mgos_get_cpu_freq() / 1000000); heap_size = mgos_get_heap_size(); free_heap_size = mgos_get_free_heap_size(); - LOG(LL_INFO, ("CPU: %d MHz, heap: %u total, %zu free", cpu_freq, heap_size, + LOG(LL_INFO, ("CPU: %d MHz, heap: %zu total, %zu free", cpu_freq, heap_size, free_heap_size)); mgos_invoke_cb(ubuntu_net_up, NULL, false /* from_isr */); From 06534b2ed9d5d4f692efa122cdfa6e54e303edb8 Mon Sep 17 00:00:00 2001 From: Pim van Pelt Date: Sun, 5 Apr 2020 23:16:48 +0200 Subject: [PATCH 5/6] Add ability to set --build-var=COMPILER_TOOLKIT=arm-linux-gnueabihf et al --- platforms/ubuntu/Makefile.build | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/platforms/ubuntu/Makefile.build b/platforms/ubuntu/Makefile.build index 7805dc325..ebb79d817 100644 --- a/platforms/ubuntu/Makefile.build +++ b/platforms/ubuntu/Makefile.build @@ -23,7 +23,12 @@ APP_EXTRA_FW_PARTS ?= ASAN ?= 0 PROF ?= 0 -ARMHF ?= 1 +# COMPILER_TOOLKIT, valid options: +# aarch64-linux-gnu +# arm-linux-gnueabi +# arm-linux-gnueabihf +# x86_64-linux-gnu (the default) +COMPILER_TOOLKIT ?= x86_64-linux-gnu # Explicitly disable updater, it's not supported on POSIX build yet. MGOS_ENABLE_DEBUG_UDP = 0 @@ -63,6 +68,12 @@ C_CXX_FLAGS = -ggdb -MD -Wall -Wextra -Werror -pipe \ $(MONGOOSE_FEATURES) LDFLAGS ?= +# Select compiler toolkit +CC = $(COMPILER_TOOLKIT)-gcc +CXX = $(COMPILER_TOOLKIT)-g++ +AR = $(COMPILER_TOOLKIT)-ar +LD = $(COMPILER_TOOLKIT)-ld + ifeq "$(ASAN)" "1" CC = clang CXX = clang++ @@ -75,12 +86,6 @@ CXX = clang++ C_CXX_FLAGS += -fprofile-instr-generate -fcoverage-mapping LDFLAGS += -fprofile-instr-generate endif -ifeq "$(ARMHF)" "1" -CC = arm-linux-gnueabihf-gcc -CXX = arm-linux-gnueabihf-g++ -AR = arm-linux-gnueabihf-ar -LD = arm-linux-gnueabihf-ld -endif ifdef MGOS_HAVE_DNS_SD LDFLAGS += -lavahi-client -lavahi-common -lstdc++ @@ -93,7 +98,6 @@ CXXFLAGS = -std=gnu++11 -fno-exceptions $(C_CXX_FLAGS) $(APP_CXXFLAGS) LDFLAGS += -lstdc++ INCDIRS = $(addprefix -I,$(INCLUDES)) -AR ?= ar APP_BIN_LIBS ?= LIBS ?= pthread cap LDLIBS = $(addprefix -l,$(LIBS)) From 12cc868af5b6979e0ca83e555433b7c3490addc5 Mon Sep 17 00:00:00 2001 From: Pim van Pelt Date: Sun, 5 Apr 2020 23:43:13 +0200 Subject: [PATCH 6/6] Cast to (unsigned long) because not all libc's support %zu --- platforms/ubuntu/src/ubuntu_main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/platforms/ubuntu/src/ubuntu_main.c b/platforms/ubuntu/src/ubuntu_main.c index 862b949f8..a185ed3d8 100644 --- a/platforms/ubuntu/src/ubuntu_main.c +++ b/platforms/ubuntu/src/ubuntu_main.c @@ -230,8 +230,8 @@ enum mgos_init_result mongoose_init(void) { cpu_freq = (int) (mgos_get_cpu_freq() / 1000000); heap_size = mgos_get_heap_size(); free_heap_size = mgos_get_free_heap_size(); - LOG(LL_INFO, ("CPU: %d MHz, heap: %zu total, %zu free", cpu_freq, heap_size, - free_heap_size)); + LOG(LL_INFO, ("CPU: %d MHz, heap: %lu total, %lu free", cpu_freq, + (unsigned long) heap_size, (unsigned long) free_heap_size)); mgos_invoke_cb(ubuntu_net_up, NULL, false /* from_isr */);