Skip to content

Commit

Permalink
Merge pull request #83 from Zondax/update_zemu_zxlib
Browse files Browse the repository at this point in the history
Update zemu zxlib
  • Loading branch information
ftheirs authored Oct 25, 2021
2 parents 3c5dad7 + 02e32d8 commit c265a4d
Show file tree
Hide file tree
Showing 109 changed files with 474 additions and 307 deletions.
14 changes: 7 additions & 7 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ jobs:
steps:
- checkout
- run: git submodule update --init --recursive
- run: conan config install https://github.com/conan-io/conanclientcert.git
- run: cmake -DCMAKE_BUILD_TYPE=Debug . && make
# Unfortunately need to disable leak sanitizer https://github.com/google/sanitizers/issues/916
# Still run all other ASAN components
Expand Down Expand Up @@ -49,25 +50,24 @@ jobs:
- run:
name: Install node + yarn
command: |
nvm install 14.4.0
nvm use 14.4.0
nvm install 14.17.0
nvm use 14.17.0
npm install -g yarn
- run:
name: Build Ledger app
command: |
make buildS
make clean
make buildX
make clean_build && make buildS
make clean_build && make buildX
- run:
name: Build/Install build js deps
command: |
nvm use 14.4.0
nvm use 14.17.0
export PATH=~/.cargo/bin:$PATH
make zemu_install
- run:
name: Run zemu tests
command: |
nvm use 14.4.0
nvm use 14.17.0
export PATH=~/.cargo/bin:$PATH
make zemu_test
Expand Down
8 changes: 8 additions & 0 deletions app/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ DEFINES += IO_SEPROXYHAL_BUFFER_SIZE_B=300

DEFINES += HAVE_GLO096
DEFINES += HAVE_BAGL BAGL_WIDTH=128 BAGL_HEIGHT=64
DEFINES += BAGL_WIDTH_MARGIN=0
DEFINES += HAVE_BAGL_ELLIPSIS # long label truncation feature
DEFINES += HAVE_BAGL_FONT_OPEN_SANS_REGULAR_11PX
DEFINES += HAVE_BAGL_FONT_OPEN_SANS_EXTRABOLD_11PX
Expand All @@ -134,7 +135,14 @@ DEFINES += HAVE_BLE_APDU BLE_COMMAND_TIMEOUT_MS=2000
SDK_SOURCE_PATH += lib_blewbxx lib_blewbxx_impl
else
# Assume Nano S
DEFINES += HAVE_BAGL_FONT_OPEN_SANS_REGULAR_11PX
DEFINES += HAVE_BAGL_FONT_OPEN_SANS_EXTRABOLD_11PX
DEFINES += HAVE_BAGL_FONT_OPEN_SANS_LIGHT_16PX
DEFINES += HAVE_BAGL BAGL_WIDTH=128 BAGL_HEIGHT=32
DEFINES += BAGL_WIDTH_MARGIN=5
DEFINES += IO_SEPROXYHAL_BUFFER_SIZE_B=128

SDK_SOURCE_PATH += lib_bagl
endif

# X specific
Expand Down
1 change: 1 addition & 0 deletions app/src/addr.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "zxmacros.h"
#include "app_mode.h"
#include "crypto.h"
#include "zxformat.h"

zxerr_t addr_getNumItems(uint8_t *num_items) {
zemu_log_stack("addr_getNumItems");
Expand Down
1 change: 1 addition & 0 deletions app/src/crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "coin.h"
#include "zxmacros.h"
#include "base32.h"
#include "zxformat.h"

uint32_t hdPath[HDPATH_LEN_DEFAULT];

Expand Down
1 change: 1 addition & 0 deletions app/src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "parser.h"
#include "parser_txdef.h"
#include "coin.h"
#include "zxformat.h"

#if defined(TARGET_NANOX)
// For some reason NanoX requires this function
Expand Down
1 change: 1 addition & 0 deletions app/src/parser_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "parser_txdef.h"
#include "cbor.h"
#include "app_mode.h"
#include "zxformat.h"

parser_tx_t parser_tx_obj;

Expand Down
27 changes: 16 additions & 11 deletions deps/ledger-zxlib/app/common/view.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,28 +37,25 @@

view_t viewdata;

void h_approve(unsigned int _) {
void h_approve(__Z_UNUSED unsigned int _) {
zemu_log_stack("h_approve");

UNUSED(_);
view_idle_show(0, NULL);
UX_WAIT();
if (viewdata.viewfuncAccept != NULL) {
viewdata.viewfuncAccept();
}
}

void h_reject(unsigned int _) {
void h_reject(__Z_UNUSED unsigned int _) {
zemu_log_stack("h_reject");

UNUSED(_);
view_idle_show(0, NULL);
UX_WAIT();
app_reject();
}

void h_error_accept(unsigned int _) {
UNUSED(_);
void h_error_accept(__Z_UNUSED unsigned int _) {
view_idle_show(0, NULL);
UX_WAIT();
app_reply_error();
Expand Down Expand Up @@ -215,23 +212,31 @@ zxerr_t h_review_update_data() {
#endif

do {
viewdata.pageCount = 1;
CHECK_ZXERR(viewdata.viewfuncGetNumItems(&viewdata.itemCount))

// be sure we are not out of bounds
//Verify how many chars fit in display (nanos)
CHECK_ZXERR(viewdata.viewfuncGetItem(
viewdata.itemIdx,
viewdata.key, MAX_CHARS_PER_KEY_LINE,
viewdata.value, MAX_CHARS_PER_VALUE1_LINE,
0, &viewdata.pageCount))
viewdata.pageCount = 1;
const max_char_display dyn_max_char_per_line1 = get_max_char_per_line();

// be sure we are not out of bounds
CHECK_ZXERR(viewdata.viewfuncGetItem(
viewdata.itemIdx,
viewdata.key, MAX_CHARS_PER_KEY_LINE,
viewdata.value, dyn_max_char_per_line1,
0, &viewdata.pageCount))
if (viewdata.pageCount != 0 && viewdata.pageIdx > viewdata.pageCount) {
// try again and get last page
viewdata.pageIdx = viewdata.pageCount - 1;
}
CHECK_ZXERR(viewdata.viewfuncGetItem(
viewdata.itemIdx,
viewdata.key, MAX_CHARS_PER_KEY_LINE,
viewdata.value, MAX_CHARS_PER_VALUE1_LINE,
viewdata.value, dyn_max_char_per_line1,
viewdata.pageIdx, &viewdata.pageCount))

viewdata.itemCount++;
Expand All @@ -241,7 +246,7 @@ zxerr_t h_review_update_data() {
if (keyLen < MAX_CHARS_PER_KEY_LINE) {
snprintf(viewdata.key + keyLen,
MAX_CHARS_PER_KEY_LINE - keyLen,
"[%d/%d]",
" [%d/%d]",
viewdata.pageIdx + 1,
viewdata.pageCount);
}
Expand All @@ -252,7 +257,7 @@ zxerr_t h_review_update_data() {
}
} while (viewdata.pageCount == 0);

splitValueField();
splitValueAddress();
return zxerr_ok;
}

Expand Down
6 changes: 5 additions & 1 deletion deps/ledger-zxlib/app/common/view_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#define MAX_CHARS_HEXMESSAGE 160
#else
#define MAX_CHARS_PER_KEY_LINE (17+1)
#define MAX_CHARS_PER_VALUE_LINE (18)
#define MAX_CHARS_PER_VALUE_LINE (17)
#define MAX_CHARS_PER_VALUE1_LINE (2*MAX_CHARS_PER_VALUE_LINE+1)
#define MAX_CHARS_PER_VALUE2_LINE (MAX_CHARS_PER_VALUE_LINE+1)
#define MAX_CHARS_HEXMESSAGE 40
Expand All @@ -44,8 +44,10 @@
#if defined(TARGET_NANOS)
#define INCLUDE_ACTIONS_AS_ITEMS 2
#define INCLUDE_ACTIONS_COUNT (INCLUDE_ACTIONS_AS_ITEMS-1)
typedef uint8_t max_char_display;
#else
#define INCLUDE_ACTIONS_COUNT 0
typedef int max_char_display;
#endif

typedef struct {
Expand Down Expand Up @@ -86,6 +88,8 @@ extern view_t viewdata;
#endif

void splitValueField();
void splitValueAddress();
max_char_display get_max_char_per_line();

///////////////////////////////////////////////
///////////////////////////////////////////////
Expand Down
48 changes: 39 additions & 9 deletions deps/ledger-zxlib/app/common/view_s.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ void h_review_button_left();
void h_review_button_right();
void h_review_button_both();

bool exceed_pixel_in_display(const uint8_t length);

#ifdef APP_SECRET_MODE_ENABLED
void h_secret_click();
#endif
Expand All @@ -59,7 +61,6 @@ const ux_menu_entry_t menu_main[] = {
#endif
0, &C_icon_app, "Developed by:", "Zondax.ch", 33, 12},

{NULL, NULL, 0, &C_icon_app, "Developed by:", "Zondax.ch", 33, 12},
{NULL, NULL, 0, &C_icon_app, "License: ", "Apache 2.0", 33, 12},
{NULL, os_exit, 0, &C_icon_dashboard, "Quit", NULL, 50, 29},
UX_MENU_END
Expand All @@ -86,8 +87,7 @@ static const bagl_element_t view_error[] = {
UI_LabelLineScrolling(UIID_LABELSCROLL, 0, 30, 128, UI_11PX, UI_WHITE, UI_BLACK, viewdata.value2),
};

static unsigned int view_error_button(unsigned int button_mask, unsigned int button_mask_counter) {
UNUSED(button_mask_counter);
static unsigned int view_error_button(unsigned int button_mask, __Z_UNUSED unsigned int button_mask_counter) {
switch (button_mask) {
case BUTTON_EVT_RELEASED | BUTTON_LEFT | BUTTON_RIGHT:
case BUTTON_EVT_RELEASED | BUTTON_LEFT:
Expand All @@ -99,8 +99,7 @@ static unsigned int view_error_button(unsigned int button_mask, unsigned int but
return 0;
}

static unsigned int view_message_button(unsigned int button_mask, unsigned int button_mask_counter) {
UNUSED(button_mask_counter);
static unsigned int view_message_button(unsigned int button_mask, __Z_UNUSED unsigned int button_mask_counter) {
switch (button_mask) {
case BUTTON_EVT_RELEASED | BUTTON_LEFT | BUTTON_RIGHT:
case BUTTON_EVT_RELEASED | BUTTON_LEFT:
Expand All @@ -110,8 +109,7 @@ static unsigned int view_message_button(unsigned int button_mask, unsigned int b
return 0;
}

static unsigned int view_review_button(unsigned int button_mask, unsigned int button_mask_counter) {
UNUSED(button_mask_counter);
static unsigned int view_review_button(unsigned int button_mask, __Z_UNUSED unsigned int button_mask_counter) {
switch (button_mask) {
case BUTTON_EVT_RELEASED | BUTTON_LEFT | BUTTON_RIGHT:
h_review_button_both();
Expand Down Expand Up @@ -193,12 +191,44 @@ void h_review_button_both() {

void splitValueField() {
print_value2("");
uint16_t vlen = strlen(viewdata.value);
const uint16_t vlen = strlen(viewdata.value);
if (vlen > MAX_CHARS_PER_VALUE2_LINE - 1) {
strcpy(viewdata.value2, viewdata.value + MAX_CHARS_PER_VALUE_LINE);
snprintf(viewdata.value2, MAX_CHARS_PER_VALUE2_LINE, "%s", viewdata.value + MAX_CHARS_PER_VALUE_LINE);
viewdata.value[MAX_CHARS_PER_VALUE_LINE] = 0;
}
}
void splitValueAddress() {
uint8_t len = MAX_CHARS_PER_VALUE_LINE;
bool exceeding_max = exceed_pixel_in_display(len);
while(exceeding_max) {
len--;
exceeding_max = exceed_pixel_in_display(len);
}
print_value2("");
const uint16_t vlen = strlen(viewdata.value);
if (vlen > len) {
snprintf(viewdata.value2, MAX_CHARS_PER_VALUE2_LINE, "%s", viewdata.value + len);
viewdata.value[len] = 0;
}
}

max_char_display get_max_char_per_line() {
uint8_t len = MAX_CHARS_PER_VALUE_LINE;
bool exceeding_max = exceed_pixel_in_display(len);
while(exceeding_max) {
len--;
exceeding_max = exceed_pixel_in_display(len);
}
//MAX_CHARS_PER_VALUE1_LINE is defined this way
return 2 * len + 1;
}

bool exceed_pixel_in_display(const uint8_t length) {
unsigned short strWidth = bagl_compute_line_width((BAGL_FONT_OPEN_SANS_EXTRABOLD_11px
| BAGL_FONT_ALIGNMENT_CENTER |BAGL_FONT_ALIGNMENT_MIDDLE),
200, viewdata.value, length, BAGL_ENCODING_LATIN1);
return (strWidth >= (BAGL_WIDTH - BAGL_WIDTH_MARGIN));
}

//////////////////////////
//////////////////////////
Expand Down
10 changes: 9 additions & 1 deletion deps/ledger-zxlib/app/common/view_x.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,18 @@ void h_review_loop_end() {
void splitValueField() {
uint16_t vlen = strlen(viewdata.value);
if (vlen == 0 ) {
strcpy(viewdata.value, " ");
snprintf(viewdata.value, MAX_CHARS_PER_VALUE1_LINE, " ");
}
}

void splitValueAddress() {
splitValueField();
}

max_char_display get_max_char_per_line() {
return MAX_CHARS_PER_VALUE1_LINE;
}

void h_expert_toggle() {
app_mode_set_expert(!app_mode_expert());
ux_flow_init(0, ux_idle_flow, &ux_idle_flow_2_step);
Expand Down
Loading

0 comments on commit c265a4d

Please sign in to comment.