Skip to content

Commit

Permalink
fix build + sawtooth fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pcppcp committed Jun 17, 2019
1 parent 3bde08e commit d04d9e8
Show file tree
Hide file tree
Showing 16 changed files with 152 additions and 60 deletions.
25 changes: 20 additions & 5 deletions .circleci/build_zephyr_nrf52840_pca10056.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#!/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
pip install protobuf

Zephyr_RTOS=zephyr_rtos
Zephyr_SDK=zephyr_sdk
PROJECT_DIR=/home/circleci/project

#Reset to the home directoryy
cd ~
Expand All @@ -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
25 changes: 0 additions & 25 deletions .circleci/images/primary/Dockerfile

This file was deleted.

7 changes: 3 additions & 4 deletions .circleci/images/ubuntu_1804/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#
# this image installs all necessary requirements to build zephyr
#
FROM phusion/baseimage:0.11

MAINTAINER Mohit Agnihotri "[email protected]"

WORKDIR /home/circleci
ENV HOME /home/circleci

Expand Down Expand Up @@ -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

Expand Down
14 changes: 11 additions & 3 deletions .circleci/install_zephyr_env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
2 changes: 2 additions & 0 deletions cmake/nanopb.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions cmake/zephyr.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion examples/sawtooth-fish-supply/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
32 changes: 16 additions & 16 deletions examples/sawtooth-fish-supply/app/demo_shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,22 @@
//
// 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)
#define DEFAULT_UPLOAD_INTERVAL 30
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);
Expand All @@ -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);
}


Expand All @@ -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;
}

Expand All @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions examples/sawtooth-fish-supply/app/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,20 @@
/* system includes */
#include <stdint.h>
#include <string.h>
#include <shell/shell.h>

/* local includes */
#include "zephyr-wallet/wallet.h"
#include "zephyr-wallet/shell_modules.h"

extern uint8_t g_zephyr_private_key[32];

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");
}
2 changes: 1 addition & 1 deletion helpers/fp2str.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
83 changes: 83 additions & 0 deletions helpers/stdint_compat.h
Original file line number Diff line number Diff line change
@@ -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_ */
3 changes: 3 additions & 0 deletions prj.conf
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -43,3 +44,5 @@ CONFIG_DHT_GPIO_PIN_NUM=10
CONFIG_SENSOR=y
CONFIG_SNTP=y
CONFIG_POSIX_API=y

CONFIG_NEWLIB_LIBC=y
2 changes: 2 additions & 0 deletions prj_qemu_x86.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
CONFIG_SHELL=y
CONFIG_SHELL_BACKEND_DUMMY=y
CONFIG_SHELL_STACK_SIZE=3072
CONFIG_KERNEL_SHELL=y
CONFIG_LOG=y
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion zephyr-wallet/http_service.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions zephyr-wallet/wallet.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
Loading

0 comments on commit d04d9e8

Please sign in to comment.