forked from irungentoo/toxcore
-
Notifications
You must be signed in to change notification settings - Fork 292
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Make esp32 build actually try to instantiate tox.
It doesn't work, because esp32 has too little RAM (320KB). DHT is a 240KB struct, so even just allocating that immediately fails. We'll need to think carefully about trimming that if we ever want this to work on embedded devices.
- Loading branch information
Showing
17 changed files
with
2,019 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,30 @@ | ||
FROM toxchat/c-toxcore:sources AS src | ||
FROM ubuntu:18.04 | ||
FROM mluis/qemu-esp32:latest | ||
SHELL ["/bin/bash", "-o", "pipefail", "-c"] | ||
ENV IDF_TARGET=esp32 | ||
|
||
RUN apt-get update && \ | ||
DEBIAN_FRONTEND="noninteractive" apt-get install -y --no-install-recommends \ | ||
bison \ | ||
ccache \ | ||
cmake \ | ||
flex \ | ||
git \ | ||
gperf \ | ||
libncurses-dev \ | ||
ninja-build \ | ||
python \ | ||
python-cryptography \ | ||
python-future \ | ||
python-pip \ | ||
python-pyparsing \ | ||
python-serial \ | ||
python-setuptools \ | ||
wget \ | ||
&& apt-get clean \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
WORKDIR /root/toxcore | ||
|
||
ENV ESP32_TARBALL=xtensa-esp32-elf-linux64-1.22.0-80-g6c4433a-5.2.0 \ | ||
IDF_PATH="/root/esp/esp-idf" \ | ||
PATH="/root/esp/esp-idf/tools:/root/esp/xtensa-esp32-elf/bin:$PATH" | ||
WORKDIR /root/esp | ||
RUN wget -q https://dl.espressif.com/dl/$ESP32_TARBALL.tar.gz \ | ||
&& tar zxf $ESP32_TARBALL.tar.gz \ | ||
&& rm -f $ESP32_TARBALL.tar.gz \ | ||
&& git clone -b v3.3 --recursive --depth=1 --shallow-submodules https://github.com/espressif/esp-idf | ||
# Build an initial bootstrap hello world just to compile libsodium and other | ||
# system level dependencies. | ||
COPY other/docker/esp32/CMakeLists.txt /root/toxcore/ | ||
COPY other/docker/esp32/bootstrap/ \ | ||
/root/toxcore/main/ | ||
RUN . /root/esp/esp-idf/export.sh && idf.py build | ||
|
||
# Build a hello world first, so the OS and libsodium etc. are compiled. | ||
WORKDIR /root/esp/toxcore | ||
COPY other/docker/esp32/CMakeLists.txt /root/esp/toxcore/ | ||
COPY other/docker/esp32/hello/ /root/esp/toxcore/main/ | ||
RUN idf.py build | ||
|
||
# Then copy over the actual toxcore sources and build those. | ||
COPY --from=src /src/third_party/cmp/ /root/esp/toxcore/main/third_party/cmp/ | ||
COPY --from=src /src/toxencryptsave/defines.h /root/esp/toxcore/main/toxencryptsave/ | ||
COPY --from=src /src/toxcore/ /root/esp/toxcore/main/toxcore/ | ||
COPY other/docker/esp32/toxcore/CMakeLists.txt /root/esp/toxcore/main/ | ||
COPY other/docker/esp32/toxcore/toxcore_main.cc /root/esp/toxcore/main/other/docker/esp32/main/ | ||
RUN idf.py build | ||
# Copy over toxcore sources and build those. | ||
COPY third_party/cmp/ /root/toxcore/main/third_party/cmp/ | ||
COPY toxencryptsave/defines.h /root/toxcore/main/toxencryptsave/ | ||
COPY toxcore/ /root/toxcore/main/toxcore/ | ||
COPY other/docker/esp32/main/CMakeLists.txt \ | ||
/root/toxcore/main/ | ||
COPY other/docker/esp32/main/*.cc \ | ||
other/docker/esp32/main/*.h \ | ||
/root/toxcore/main/other/docker/esp32/main/ | ||
RUN touch /root/toxcore/main/CMakeLists.txt \ | ||
&& . /root/esp/esp-idf/export.sh && idf.py build | ||
RUN ls -lh build/toxcore.bin \ | ||
&& shasum build/toxcore.bin | ||
&& sha512sum build/toxcore.bin | ||
RUN /root/flash.sh build/toxcore.bin | ||
|
||
COPY other/docker/esp32/qemu-test /root/toxcore/ | ||
RUN ["/root/toxcore/qemu-test"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
cmake_minimum_required(VERSION 3.5) | ||
|
||
set(COMPONENT_SRCS | ||
hello_main.cc) | ||
set(COMPONENT_ADD_INCLUDEDIRS "") | ||
|
||
register_component() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#include <stdio.h> | ||
|
||
// Bootstrap main. Only writes hello world. See ../main/* for the real thing. | ||
extern "C" void app_main(void) | ||
{ | ||
printf("Hello world!\n"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
dependencies: | ||
espressif/libsodium: "==1.0.20" |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
8 changes: 6 additions & 2 deletions
8
other/docker/esp32/toxcore/CMakeLists.txt → other/docker/esp32/main/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include <esp_netif.h> | ||
|
||
#include "tox_main.h" | ||
|
||
// Does all the esp32-specific init before running generic tox code. | ||
extern "C" void app_main(void) | ||
{ | ||
esp_netif_init(); | ||
|
||
tox_main(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#include "../main/tox_main.h" | ||
|
||
#include <assert.h> | ||
#include <stdio.h> | ||
|
||
#include "../../../../toxcore/ccompat.h" | ||
#include "../../../../toxcore/tox.h" | ||
#include "../../../../toxcore/tox_events.h" | ||
|
||
static char tox_log_level_name(Tox_Log_Level level) | ||
{ | ||
switch (level) { | ||
case TOX_LOG_LEVEL_TRACE: return 'T'; | ||
case TOX_LOG_LEVEL_DEBUG: return 'D'; | ||
case TOX_LOG_LEVEL_INFO: return 'I'; | ||
case TOX_LOG_LEVEL_WARNING: return 'W'; | ||
case TOX_LOG_LEVEL_ERROR: return 'E'; | ||
} | ||
|
||
return '?'; | ||
} | ||
|
||
static const char *tox_err_new_name(Tox_Err_New err) | ||
{ | ||
switch (err) { | ||
case TOX_ERR_NEW_OK: return "OK"; | ||
case TOX_ERR_NEW_NULL: return "NULL"; | ||
case TOX_ERR_NEW_MALLOC: return "MALLOC"; | ||
case TOX_ERR_NEW_PORT_ALLOC: return "PORT_ALLOC"; | ||
case TOX_ERR_NEW_PROXY_BAD_TYPE: return "PROXY_BAD_TYPE"; | ||
case TOX_ERR_NEW_PROXY_BAD_HOST: return "PROXY_BAD_HOST"; | ||
case TOX_ERR_NEW_PROXY_BAD_PORT: return "PROXY_BAD_PORT"; | ||
case TOX_ERR_NEW_PROXY_NOT_FOUND: return "PROXY_NOT_FOUND"; | ||
case TOX_ERR_NEW_LOAD_ENCRYPTED: return "LOAD_ENCRYPTED"; | ||
case TOX_ERR_NEW_LOAD_BAD_FORMAT: return "LOAD_BAD_FORMAT"; | ||
} | ||
|
||
return "<unknown>"; | ||
} | ||
|
||
static tox_log_cb log_handler; | ||
static void log_handler(Tox *tox, Tox_Log_Level level, const char *file, uint32_t line, const char *func, const char *msg, void *user_data) | ||
{ | ||
printf("[%c] %s:%u(%s): %s\n", tox_log_level_name(level), file, (unsigned int)line, func, msg); | ||
} | ||
|
||
void tox_main() | ||
{ | ||
printf("Hello Tox!\n"); | ||
|
||
Tox_Options *opts = tox_options_new(nullptr); | ||
assert(opts != nullptr); | ||
|
||
tox_options_set_log_callback(opts, log_handler); | ||
|
||
Tox_Err_New err; | ||
Tox *tox = tox_new(opts, &err); | ||
|
||
if (err == TOX_ERR_NEW_OK) { | ||
tox_events_free(tox_events_iterate(tox, true, nullptr)); | ||
} else { | ||
printf("tox_new(): %s\n", tox_err_new_name(err)); | ||
} | ||
|
||
tox_kill(tox); | ||
|
||
tox_options_free(opts); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#ifndef TOX_MAIN_H | ||
#define TOX_MAIN_H | ||
|
||
void tox_main(); | ||
|
||
#endif // TOX_MAIN_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/bin/bash | ||
|
||
set -eu | ||
|
||
qemu-system-xtensa \ | ||
-nographic \ | ||
-M esp32 \ | ||
-m 4 \ | ||
-drive file=flash.bin,if=mtd,format=raw \ | ||
-nic user,model=open_eth,hostfwd=tcp::80-:80 \ | ||
-s \ | ||
| tee qemu.log & | ||
|
||
echo "Waiting for program to complete" | ||
while ! grep 'Returned from app_main' qemu.log > /dev/null; do | ||
sleep 1 | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
#!/bin/sh | ||
|
||
docker build -t toxchat/c-toxcore:sources -f other/docker/sources/Dockerfile . | ||
docker build -t toxchat/c-toxcore:esp32 -f other/docker/esp32/Dockerfile . |
Oops, something went wrong.