From d04d9e8ab02748a49893b6d6e2716ce16b70a8d5 Mon Sep 17 00:00:00 2001 From: Jozef Henzl Date: Mon, 10 Jun 2019 19:32:24 +0200 Subject: [PATCH] fix build + sawtooth fixes --- .circleci/build_zephyr_nrf52840_pca10056.sh | 25 ++++-- .circleci/images/primary/Dockerfile | 25 ------ .circleci/images/ubuntu_1804/Dockerfile | 7 +- .circleci/install_zephyr_env.sh | 14 +++- cmake/nanopb.cmake | 2 + cmake/zephyr.cmake | 1 + examples/sawtooth-fish-supply/CMakeLists.txt | 2 +- .../sawtooth-fish-supply/app/demo_shell.c | 32 +++---- examples/sawtooth-fish-supply/app/main.c | 4 + helpers/fp2str.c | 2 +- helpers/stdint_compat.h | 83 +++++++++++++++++++ prj.conf | 3 + prj_qemu_x86.conf | 2 + zephyr-wallet/http_service.c | 2 +- zephyr-wallet/wallet.c | 6 +- zephyr-wallet/web3_rpc.c | 2 +- 16 files changed, 152 insertions(+), 60 deletions(-) delete mode 100644 .circleci/images/primary/Dockerfile create mode 100644 helpers/stdint_compat.h diff --git a/.circleci/build_zephyr_nrf52840_pca10056.sh b/.circleci/build_zephyr_nrf52840_pca10056.sh index 30800d9..18233b2 100755 --- a/.circleci/build_zephyr_nrf52840_pca10056.sh +++ b/.circleci/build_zephyr_nrf52840_pca10056.sh @@ -1,5 +1,6 @@ #!/bin/bash set -e +set -x update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1 update-alternatives --install /usr/bin/python python /usr/bin/python3 2 @@ -7,6 +8,7 @@ pip install protobuf Zephyr_RTOS=zephyr_rtos Zephyr_SDK=zephyr_sdk +PROJECT_DIR=/home/circleci/project #Reset to the home directoryy cd ~ @@ -16,12 +18,25 @@ source ${Zephyr_RTOS}/zephyr/zephyr-env.sh export ZEPHYR_TOOLCHAIN_VARIANT=zephyr export ZEPHYR_SDK_INSTALL_DIR=/opt/sdk/zephyr-sdk +# cd to the samples directory cd ${Zephyr_RTOS}/zephyr/samples/ -# clone the repo -git clone /home/circleci/project anyledger-wallet -cd anyledger-wallet +# clone the anyledger repo +if [ -d $PROJECT_DIR ];then + # for CI use directory which contains already cloned source + git clone /home/circleci/project anyledger-wallet +else + git clone -b st_fixes https://github.com/pcppcp/anyledger-wallet.git anyledger-wallet +fi +WALLET_DIR=`pwd`/anyledger-wallet/examples/wallet +BUILD_DIR=$WALLET_DIR/build +mkdir -p $BUILD_DIR -cd examples/wallet/ && mkdir build && cd build/ -cmake -DCMAKE_CXX_FLAGS="-Werror $CMAKE_CXX_FLAGS" -DCMAKE_C_FLAGS="-Werror $CMAKE_C_FLAGS" -GNinja -DBOARD=nrf52840_pca10056 -DBUILD_XCOMPILE=1 ../ +# build the wallet for x86 +cd $BUILD_DIR && mkdir x86 && cd x86 +cmake -DCMAKE_CXX_FLAGS="-Werror $CMAKE_CXX_FLAGS" -DCMAKE_C_FLAGS="-Werror $CMAKE_C_FLAGS" -GNinja -DBOARD=qemu_x86 -DBUILD_XCOMPILE=1 $WALLET_DIR +ninja +# build the wallet for nrf52 +cd $BUILD_DIR && mkdir nrf52 && cd nrf52 +cmake -DCMAKE_CXX_FLAGS="-Werror $CMAKE_CXX_FLAGS" -DCMAKE_C_FLAGS="-Werror $CMAKE_C_FLAGS" -GNinja -DBOARD=nrf52840_pca10056 -DBUILD_XCOMPILE=1 $WALLET_DIR ninja diff --git a/.circleci/images/primary/Dockerfile b/.circleci/images/primary/Dockerfile deleted file mode 100644 index fd81c81..0000000 --- a/.circleci/images/primary/Dockerfile +++ /dev/null @@ -1,25 +0,0 @@ -FROM circleci/python:3.6.6-jessie-browsers - -MAINTAINER WonJong Shin "shinonejong@gmail.com" - -WORKDIR /home/circleci -ENV HOME /home/circleci - -RUN sudo apt-get -qq update && sudo apt-get -qqy upgrade && \ - sudo apt-get install -y libgtest-dev g++ make cmake wget build-essential clang clang-tidy-3.8 ninja-build && \ - sudo apt-get autoremove && sudo apt-get autoclean && sudo rm -rf /var/lib/apt/lists/* -RUN cd /usr/src/gtest && \ - sudo mkdir -p build && cd build && \ - sudo cmake .. && sudo make -j8 && \ - sudo cp *.a /usr/local/lib/ && \ - sudo rm -rf ../build -RUN sudo pip3 install --no-cache-dir --upgrade pip - -ARG SOLC_URL=https://github.com/ethereum/solidity/releases/download/v0.4.23/solc-static-linux -ARG SOLC_VERSION=v0.4.23 -RUN sudo curl -L ${SOLC_URL} > /tmp/solc-${SOLC_VERSION} && \ - sudo chmod 775 /tmp/solc-${SOLC_VERSION} && \ - sudo mv /tmp/solc-${SOLC_VERSION} /usr/local/bin/ && \ - sudo ln -s /usr/local/bin/solc-${SOLC_VERSION} /usr/local/bin/solc - -RUN sudo pip3 install --no-cache-dir web3 eth_abi eth_utils click diff --git a/.circleci/images/ubuntu_1804/Dockerfile b/.circleci/images/ubuntu_1804/Dockerfile index b37283a..21ef5c0 100644 --- a/.circleci/images/ubuntu_1804/Dockerfile +++ b/.circleci/images/ubuntu_1804/Dockerfile @@ -1,7 +1,8 @@ +# +# this image installs all necessary requirements to build zephyr +# FROM phusion/baseimage:0.11 -MAINTAINER Mohit Agnihotri "mohitkumar39@gmail.com" - WORKDIR /home/circleci ENV HOME /home/circleci @@ -29,8 +30,6 @@ RUN curl -L ${SOLC_URL} > /tmp/solc-${SOLC_VERSION} && \ mv /tmp/solc-${SOLC_VERSION} /usr/local/bin/ && \ ln -s /usr/local/bin/solc-${SOLC_VERSION} /usr/local/bin/solc -#RUN wget http://pyyaml.org/download/pyyaml/PyYAML-3.13.tar.gz && tar -xvf PyYAML-3.13.tar.gz && cd PyYAML-3.13 && python setup.py install - RUN pip3 install --no-cache-dir web3 eth_abi eth_utils click pyaml protobuf RUN ssh-keyscan -H github.com >> /root/.ssh/known_hosts diff --git a/.circleci/install_zephyr_env.sh b/.circleci/install_zephyr_env.sh index a8ef918..b1d414a 100755 --- a/.circleci/install_zephyr_env.sh +++ b/.circleci/install_zephyr_env.sh @@ -4,11 +4,19 @@ set -e Zephyr_RTOS=zephyr_rtos Zephyr_SDK=zephyr_sdk -# Clone the Zephyr and install required dependencies +# Clone the Zephyr mkdir ${Zephyr_RTOS} && cd ${Zephyr_RTOS} git clone https://github.com/zephyrproject-rtos/zephyr.git -pip3 install -r zephyr/scripts/requirements.txt -cd ../ + +# until Zephyr fixes http client, we work with this revision +cd zephyr +git checkout bec74121f6 + +# install requirements +pip3 install -r scripts/requirements.txt + +# go back to the source root +cd ../../ # Get the Zephyr SDK mkdir ${Zephyr_SDK} && cd ${Zephyr_SDK} diff --git a/cmake/nanopb.cmake b/cmake/nanopb.cmake index 14b69bc..8cd67e9 100644 --- a/cmake/nanopb.cmake +++ b/cmake/nanopb.cmake @@ -3,6 +3,8 @@ include(ExternalProject) set(mylib_build_dir ${CMAKE_CURRENT_BINARY_DIR}/nanopb) set(mylib_source_dir ${CMAKE_CURRENT_BINARY_DIR}/thirdparty/nanopb) +#set(NANOPB_C_FLAGS "${CMAKE_C_FLAGS} -DPB_SYSTEM_HEADER=\\\"pb_syshdr.h\\\" -I${mylib_source_dir}/extra") +#list(REMOVE_ITEM ${NANOPB_C_FLAGS} "-Werror") ExternalProject_Add( nanopb diff --git a/cmake/zephyr.cmake b/cmake/zephyr.cmake index 008ec2c..2e297fb 100644 --- a/cmake/zephyr.cmake +++ b/cmake/zephyr.cmake @@ -3,6 +3,7 @@ # https://github.com/zephyrproject-rtos/zephyr/blob/master/samples/application_development/external_lib/CMakeLists.txt#L17 set_property(GLOBAL PROPERTY CSTD c11) include(ExternalProject) +#include($ENV{ZEPHYR_BASE}/cmake/extensions.cmake NO_POLICY_SCOPE) zephyr_get_include_directories_for_lang_as_string( C includes) zephyr_get_system_include_directories_for_lang_as_string(C system_includes) diff --git a/examples/sawtooth-fish-supply/CMakeLists.txt b/examples/sawtooth-fish-supply/CMakeLists.txt index 1fdeed9..da23599 100644 --- a/examples/sawtooth-fish-supply/CMakeLists.txt +++ b/examples/sawtooth-fish-supply/CMakeLists.txt @@ -7,7 +7,7 @@ if(BUILD_XCOMPILE) file(GLOB APP_SOURCES "app/*.c") add_subdirectory(payload/) target_sources(app PRIVATE ${APP_SOURCES}) - target_link_libraries(app PUBLIC fish-demo al-zephyr) + target_link_libraries(app PUBLIC fish-demo al-zephyr gcc) target_include_directories(app PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) else() message(STATUS "x86 build") diff --git a/examples/sawtooth-fish-supply/app/demo_shell.c b/examples/sawtooth-fish-supply/app/demo_shell.c index 49ec742..be7a8bf 100644 --- a/examples/sawtooth-fish-supply/app/demo_shell.c +++ b/examples/sawtooth-fish-supply/app/demo_shell.c @@ -20,7 +20,7 @@ // // thread stack #define UPLOAD_STACK_SIZE 512 -K_THREAD_STACK_DEFINE(upload_stack, UPLOAD_STACK_SIZE); +K_THREAD_STACK_DEFINE(st_upload_stack, UPLOAD_STACK_SIZE); static struct k_thread upload_thread_data; // interval (seconds) @@ -28,14 +28,14 @@ static struct k_thread upload_thread_data; static uint16_t _upload_interval = DEFAULT_UPLOAD_INTERVAL; // thread semaphore. it is taken when the thread is spawned and released on exit -K_SEM_DEFINE(upload_thread_sem, 1, 1); -K_SEM_DEFINE(upload_thread_exit_sem, 0, 1); +K_SEM_DEFINE(st_upload_thread_sem, 1, 1); +K_SEM_DEFINE(st_upload_thread_exit_sem, 0, 1); static void upload_main() { - int ret __attribute__((unused)) = k_sem_take(&upload_thread_sem, K_MSEC(1)); + int ret __attribute__((unused)) = k_sem_take(&st_upload_thread_sem, K_MSEC(1)); assert(ret == 0); - char cmdbuf[64]; + char cmdbuf[32]; // register an account snprintf(cmdbuf, sizeof(cmdbuf), "st create_agent A-%d", sys_rand32_get() % 10000); shell_execute_cmd(NULL, cmdbuf); @@ -50,10 +50,10 @@ static void upload_main() // periodically update the record N times or until stop signal is caught while(true) { shell_execute_cmd(NULL, "st update_record"); - if(k_sem_take(&upload_thread_exit_sem, _upload_interval * 1000) == 0) { break; } + if(k_sem_take(&st_upload_thread_exit_sem, _upload_interval * 1000) == 0) { break; } } - k_sem_give(&upload_thread_exit_sem); - k_sem_give(&upload_thread_sem); + k_sem_give(&st_upload_thread_exit_sem); + k_sem_give(&st_upload_thread_sem); } @@ -62,18 +62,18 @@ static int upload_stop(const struct shell *shell, size_t argc, char *argv[]) ARG_UNUSED(argc); ARG_UNUSED(argv); ARG_UNUSED(shell); - if(k_sem_take(&upload_thread_sem, K_MSEC(5)) == 0) { + if(k_sem_take(&st_upload_thread_sem, K_MSEC(5)) == 0) { printk("thread not running\n"); - k_sem_give(&upload_thread_sem); + k_sem_give(&st_upload_thread_sem); return 0; } // signal thread to exit - k_sem_give(&upload_thread_exit_sem); + k_sem_give(&st_upload_thread_exit_sem); // wait for the exit - k_sem_take(&upload_thread_sem, K_FOREVER); + k_sem_take(&st_upload_thread_sem, K_FOREVER); // reset the semaphores - k_sem_give(&upload_thread_sem); - k_sem_take(&upload_thread_exit_sem, K_FOREVER); + k_sem_give(&st_upload_thread_sem); + k_sem_take(&st_upload_thread_exit_sem, K_FOREVER); return 0; } @@ -89,13 +89,13 @@ static int upload_start(const struct shell *shell, size_t argc, char *argv[]) } else { _upload_interval = DEFAULT_UPLOAD_INTERVAL; } - if(k_sem_take(&upload_thread_sem, K_MSEC(5)) != 0) { + if(k_sem_take(&st_upload_thread_sem, K_MSEC(5)) != 0) { printk("thread already started\n"); return 0; } k_thread_create( &upload_thread_data, - upload_stack, K_THREAD_STACK_SIZEOF(upload_stack), + st_upload_stack, K_THREAD_STACK_SIZEOF(st_upload_stack), (k_thread_entry_t)upload_main, NULL, NULL, NULL, 5, 0, K_NO_WAIT); return 0; diff --git a/examples/sawtooth-fish-supply/app/main.c b/examples/sawtooth-fish-supply/app/main.c index d0bd5a1..7e22f33 100644 --- a/examples/sawtooth-fish-supply/app/main.c +++ b/examples/sawtooth-fish-supply/app/main.c @@ -8,9 +8,11 @@ /* system includes */ #include #include +#include /* local includes */ #include "zephyr-wallet/wallet.h" +#include "zephyr-wallet/shell_modules.h" extern uint8_t g_zephyr_private_key[32]; @@ -18,6 +20,8 @@ void main(void) { privkey_t pk; memcpy(&pk.k, g_zephyr_private_key, 32); + wallet_register_shell_modules(); wallet_set_global_privkey(&pk); + shell_execute_cmd(NULL, "help"); } diff --git a/helpers/fp2str.c b/helpers/fp2str.c index 18d5881..2f4aa2d 100644 --- a/helpers/fp2str.c +++ b/helpers/fp2str.c @@ -15,7 +15,7 @@ int fp2str(uint32_t val, uint8_t digits, char *buf, size_t buf_len) { char *buf_p = buf; - int ret = snprintf(buf_p, buf_len, "%d", val >> digits); + int ret = snprintf(buf_p, buf_len, "%lu", val >> digits); if(ret < 0) { return ret; } diff --git a/helpers/stdint_compat.h b/helpers/stdint_compat.h new file mode 100644 index 0000000..75095e4 --- /dev/null +++ b/helpers/stdint_compat.h @@ -0,0 +1,83 @@ +/* stdint.h */ + +/* + * Copyright (c) 2014 Wind River Systems, Inc. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +// +// note - this is a compatibility file to support uint64_t and uint_least8_t on zephyr 1.12 +// + +#ifndef STDINT_COMPAT_H_ +#define STDINT_COMPAT_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#define INT8_MAX 0x7F +#define INT16_MAX 0x7FFF +#define INT32_MAX 0x7FFFFFFF +#define INT64_MAX 0x7FFFFFFFFFFFFFFFLL + +#define INT8_MIN (-INT8_MAX - 1) +#define INT16_MIN (-INT16_MAX - 1) +#define INT32_MIN (-INT32_MAX - 1) +#define INT64_MIN (-INT64_MAX - 1LL) + +#define UINT8_MAX 0xFF +#define UINT16_MAX 0xFFFF +#define UINT32_MAX 0xFFFFFFFFU +#define UINT64_MAX 0xFFFFFFFFFFFFFFFFULL + +#define INTPTR_MIN INT32_MIN +#define INTPTR_MAX INT32_MAX +#define UINTPTR_MAX UINT32_MAX + +#define PTRDIFF_MIN INT32_MIN +#define PTRDIFF_MAX INT32_MAX + +#define SIZE_MAX UINT32_MAX + +typedef signed char int8_t; +typedef signed short int16_t; +typedef signed int int32_t; +typedef signed long long int64_t; + +/* Assume int to be the fastest type for all types except 64bit ones */ + +typedef signed int int_fast8_t; +typedef signed int int_fast16_t; +typedef signed int int_fast32_t; +typedef signed long long int_fast64_t; + +typedef signed char int_least8_t; +typedef signed short int_least16_t; +typedef signed int int_least32_t; +typedef signed long long int_least64_t; + +typedef unsigned char uint8_t; +typedef unsigned short uint16_t; +typedef unsigned int uint32_t; +typedef unsigned long long uint64_t; + +typedef unsigned int uint_fast8_t; +typedef unsigned int uint_fast16_t; +typedef unsigned int uint_fast32_t; +typedef unsigned long long uint_fast64_t; + +typedef unsigned char uint_least8_t; +typedef unsigned short uint_least16_t; +typedef unsigned int uint_least32_t; +typedef unsigned long long uint_least64_t; + +typedef int intptr_t; +typedef unsigned int uintptr_t; + +#ifdef __cplusplus +} +#endif + +#endif /* STDINT_COMPAT_H_ */ diff --git a/prj.conf b/prj.conf index cbdf1e2..ddf35db 100644 --- a/prj.conf +++ b/prj.conf @@ -1,4 +1,5 @@ CONFIG_SHELL=y +CONFIG_SHELL_BACKEND_DUMMY=y CONFIG_SHELL_BACKEND_SERIAL_RX_RING_BUFFER_SIZE=128 CONFIG_KERNEL_SHELL=y CONFIG_LOG=y @@ -43,3 +44,5 @@ CONFIG_DHT_GPIO_PIN_NUM=10 CONFIG_SENSOR=y CONFIG_SNTP=y CONFIG_POSIX_API=y + +CONFIG_NEWLIB_LIBC=y diff --git a/prj_qemu_x86.conf b/prj_qemu_x86.conf index 2f9e5a2..e7dfb1b 100644 --- a/prj_qemu_x86.conf +++ b/prj_qemu_x86.conf @@ -1,4 +1,5 @@ CONFIG_SHELL=y +CONFIG_SHELL_BACKEND_DUMMY=y CONFIG_SHELL_STACK_SIZE=3072 CONFIG_KERNEL_SHELL=y CONFIG_LOG=y @@ -35,5 +36,6 @@ CONFIG_LWM2M_IPSO_SUPPORT=y CONFIG_LWM2M_IPSO_TEMP_SENSOR=y CONFIG_POSIX_API=y +CONFIG_NEWLIB_LIBC=y CONFIG_SNTP=y diff --git a/zephyr-wallet/http_service.c b/zephyr-wallet/http_service.c index 8037906..34aa2c7 100644 --- a/zephyr-wallet/http_service.c +++ b/zephyr-wallet/http_service.c @@ -38,7 +38,7 @@ static u8_t result[RESULT_BUF_SIZE]; static void __assert_nfo(const http_nfo_t *nfo) { assert(nfo->host != NULL); - assert(nfo->port != NULL); + assert(nfo->port != 0); assert(nfo->url != NULL); assert(nfo->content_type != NULL); assert(nfo->_priv == NULL); diff --git a/zephyr-wallet/wallet.c b/zephyr-wallet/wallet.c index 1968833..4a5a6b1 100644 --- a/zephyr-wallet/wallet.c +++ b/zephyr-wallet/wallet.c @@ -83,7 +83,7 @@ static int wallet_set_nonce(const struct shell *shell, size_t argc, char *argv[] { ARG_UNUSED(shell); if(argc <= 1) { - printk("%u\n", _account.nonce); + printk("%lu\n", _account.nonce); return 0; } return __convert_ulong(argv[1], "set_nonce", &_account.nonce); @@ -93,7 +93,7 @@ static int wallet_set_gas_price(const struct shell *shell, size_t argc, char *ar { ARG_UNUSED(shell); if(argc <= 1) { - printk("%u\n", _account.gas_price); + printk("%lu\n", _account.gas_price); return 0; } return __convert_ulong(argv[1], "gas_price", &_account.gas_price); @@ -103,7 +103,7 @@ static int wallet_set_gas_limit(const struct shell *shell, size_t argc, char *ar { ARG_UNUSED(shell); if(argc <= 1) { - printk("%u\n", _account.gas_limit); + printk("%lu\n", _account.gas_limit); return 0; } return __convert_ulong(argv[1], "gas_limit", &_account.gas_limit); diff --git a/zephyr-wallet/web3_rpc.c b/zephyr-wallet/web3_rpc.c index c8b31f7..f2f665f 100644 --- a/zephyr-wallet/web3_rpc.c +++ b/zephyr-wallet/web3_rpc.c @@ -108,7 +108,7 @@ static int web3_eth_address_block_hex(const char *method, const address_t *addre rpc_call_fp rpc_call = NULL; for(size_t i = 0; i < sizeof(call_map); i++) { - assert(call_map[i]->call != NULL); + assert(call_map[i].call != NULL); if(strcmp(call_map[i].name, method) == 0) { rpc_call = call_map[i].call; break;