From 62d3b0d9b79b5359077060c2c85b91e2a22eda68 Mon Sep 17 00:00:00 2001 From: Joachim Burket Date: Tue, 30 Jun 2020 11:40:30 +0200 Subject: [PATCH 1/3] removed names in path --- esp32/doc/detailed_build_procedure.md | 72 +++++++-------------------- 1 file changed, 18 insertions(+), 54 deletions(-) diff --git a/esp32/doc/detailed_build_procedure.md b/esp32/doc/detailed_build_procedure.md index aa917af..7220009 100644 --- a/esp32/doc/detailed_build_procedure.md +++ b/esp32/doc/detailed_build_procedure.md @@ -107,7 +107,7 @@ When the `cmake` command works, the following summary is given: -- C/C++: -- Built as dynamic libs?: NO -- C++ standard: 11 --- C++ Compiler: /home/joachim/.espressif/tools/xtensa-esp32-elf/esp-2019r2-8.2.0/xtensa-esp32-elf/bin/xtensa-esp32-elf-g++ (ver 8.2.0) +-- C++ Compiler: ~/.espressif/tools/xtensa-esp32-elf/esp-2019r2-8.2.0/xtensa-esp32-elf/bin/xtensa-esp32-elf-g++ (ver 8.2.0) -- C++ flags (Release): -mlongcalls -Wno-frame-address -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -fomit-frame-pointer -ffunction-sections -fdata-sections -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG -DNDEBUG -- C++ flags (Debug): -mlongcalls -Wno-frame-address -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -fomit-frame-pointer -ffunction-sections -fdata-sections -fvisibility=hidden -fvisibility-inlines-hidden -g -O0 -DDEBUG -D_DEBUG -- C Compiler: /home/joachim/.espressif/tools/xtensa-esp32-elf/esp-2019r2-8.2.0/xtensa-esp32-elf/bin/xtensa-esp32-elf-gcc @@ -152,14 +152,14 @@ When the `cmake` command works, the following summary is given: -- Other third-party libraries: -- Custom HAL: NO -- --- Python (for build): /home/joachim/.espressif/python_env/idf4.2_py2.7_env/bin/python2.7 +-- Python (for build): ~/.espressif/python_env/idf4.2_py2.7_env/bin/python2.7 -- --- Install to: /home/joachim/Documents/HES/02_MSE/22_master_thesis/esp32-opencv/build/install +-- Install to: ~/esp32-opencv/build/install -- ----------------------------------------------------------------- -- -- Configuring done -- Generating done --- Build files have been written to: /home/joachim/Documents/HES/02_MSE/22_master_thesis/esp32-opencv/build +-- Build files have been written to: ~/esp32-opencv/build ``` @@ -234,58 +234,22 @@ After these fixes, the command `make` is run, with some new errors: * When there is an `#if defined(ANDROID)`, add ` || defined(ESP32)` after, so that `malloc.h` is included and `memalign` is used -* *#error " not supported"* +* *glob.cpp: #error " not supported"* - The ESP32 doesn't support directories (which are emulated with the filenames, like `mydir/mysubdir/myfile.c`). - - **FIX:** Modify `modules/core/src/glob.cpp` - - * Add the following code after line 136: - - ```c++ - #if defined(ESP32) - #include - const char dir_separators[] = "/"; - - namespace { - struct dirent { - const char *d_name; - }; - - struct DIR { - dirent ent; - - DIR() { } - ~DIR() - { - if (ent.d_name) - delete[] ent.d_name; - } - }; - - DIR* opendir(const char* path) - { - DIR* dir = new DIR; - dir->ent.d_name = 0; - // TODO implement (point the first file starting with 'path' in its name) - return dir; - } - - dirent* readdir(DIR* dir) - { - // TODO: implement (point to the next file with 'path' in its name) - return &(dir->ent); - } - - void closedir(DIR* dir) - { - delete dir; - } - } - ``` - - The function are not implemented yet. Must be implemented if files reading/writing in SPIFFS needed. + The `glob.cpp` file includes the file `xtensa-esp32-elf/sys-include/dirent.h`, which includes `xtensa-esp32-elf/sys-include/sys/dirent.h`, which causes this error. This is because the filesystem related functions are defined in the ESP-IDF repository (in `components/vfs/`). The `vfs/include/sys/dirent.h` header must therefore be included in `glob.cpp:135` instead of ``: + ``` c++ +#if defined(ESP32) + #include +#include "esp_dirent.h" + #include + const char dir_separators[] = "/"; + #else + /* ... */ + ``` + + This `esp_dirent.h` file is the `vfs/include/sys/dirent.h` copied into `modules/core/src/` in OpenCV sources. + * *system.cpp:1002:20: error: 'mkstemp' was not declared in this scope* **FIX:** From 865644b64ec2de84708f33a4e1ab9c778a98ae7c Mon Sep 17 00:00:00 2001 From: Joachim Burket Date: Tue, 30 Jun 2020 14:34:39 +0200 Subject: [PATCH 2/3] directories functions header added (from esp-idf/components/vfs) --- CMakeLists.txt | 3 +- esp32/scripts/build_opencv_for_esp32.sh | 2 +- modules/core/src/glob.cpp | 38 ++----------------------- 3 files changed, 4 insertions(+), 39 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fe44cd2..05fd140 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -660,8 +660,7 @@ include(cmake/OpenCVModule.cmake) # Detect endianness of build platform # ---------------------------------------------------------------------------- -# if not working while compiling for esp32, change the next line in 'if(IOS OR ESP32)' -if(IOS) +if(IOS OR ESP32) # test_big_endian needs try_compile, which doesn't work for iOS # http://public.kitware.com/Bug/view.php?id=12288 set(WORDS_BIGENDIAN 0) diff --git a/esp32/scripts/build_opencv_for_esp32.sh b/esp32/scripts/build_opencv_for_esp32.sh index e1ffabd..1f3c756 100755 --- a/esp32/scripts/build_opencv_for_esp32.sh +++ b/esp32/scripts/build_opencv_for_esp32.sh @@ -67,7 +67,7 @@ cp $SCRIPTDIR/resources/alloc_fix.cpp ./3rdparty/ade/ade-0.1.1f/sources/ade/sour echo "================================================================================" echo "Compiling with make -j" echo "================================================================================" -make -j +make -j3 ### installing in output directory ### echo "================================================================================" diff --git a/modules/core/src/glob.cpp b/modules/core/src/glob.cpp index e6edf78..17c4733 100644 --- a/modules/core/src/glob.cpp +++ b/modules/core/src/glob.cpp @@ -133,44 +133,10 @@ namespace } #else #if defined(ESP32) +#include +#include "esp_dirent.h" #include const char dir_separators[] = "/"; - -namespace { - struct dirent { - const char *d_name; - }; - - struct DIR { - dirent ent; - - DIR() { } - ~DIR() - { - if (ent.d_name) - delete[] ent.d_name; - } - }; - - DIR* opendir(const char* path) - { - DIR* dir = new DIR; - dir->ent.d_name = 0; - // TODO implement (point the first file starting with 'path' in its name) - return dir; - } - - dirent* readdir(DIR* dir) - { - // TODO: implement (point to the next file with 'path' in its name) - return &(dir->ent); - } - - void closedir(DIR* dir) - { - delete dir; - } -} #else # include # include From 7ac7e155d7d625431ef046331de3e0f48b18e96d Mon Sep 17 00:00:00 2001 From: Joachim Burket Date: Tue, 30 Jun 2020 14:35:19 +0200 Subject: [PATCH 3/3] directories functions header added (from esp-idf/components/vfs) --- modules/core/src/esp_dirent.h | 55 +++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 modules/core/src/esp_dirent.h diff --git a/modules/core/src/esp_dirent.h b/modules/core/src/esp_dirent.h new file mode 100644 index 0000000..57b5be5 --- /dev/null +++ b/modules/core/src/esp_dirent.h @@ -0,0 +1,55 @@ +// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#pragma once + +#include +#include + +/** + * This header file provides POSIX-compatible definitions of directory + * access functions and related data types. + * See http://pubs.opengroup.org/onlinepubs/7908799/xsh/dirent.h.html + * for reference. + */ + +/** + * @brief Opaque directory structure + */ +typedef struct { + uint16_t dd_vfs_idx; /*!< VFS index, not to be used by applications */ + uint16_t dd_rsv; /*!< field reserved for future extension */ + /* remaining fields are defined by VFS implementation */ +} DIR; + +/** + * @brief Directory entry structure + */ +struct dirent { + int d_ino; /*!< file number */ + uint8_t d_type; /*!< not defined in POSIX, but present in BSD and Linux */ +#define DT_UNKNOWN 0 +#define DT_REG 1 +#define DT_DIR 2 + char d_name[256]; /*!< zero-terminated file name */ +}; + +DIR* opendir(const char* name); +struct dirent* readdir(DIR* pdir); +long telldir(DIR* pdir); +void seekdir(DIR* pdir, long loc); +void rewinddir(DIR* pdir); +int closedir(DIR* pdir); +int readdir_r(DIR* pdir, struct dirent* entry, struct dirent** out_dirent); +