Skip to content
This repository has been archived by the owner on Oct 18, 2024. It is now read-only.

Commit

Permalink
Adjustments/Bug fixes (#22)
Browse files Browse the repository at this point in the history
* upgrade zxlib

* adjust validatorPrefs

* updating makefile

* updating zemu screenshots
  • Loading branch information
jleni authored Jun 25, 2020
1 parent eb909a7 commit 23ef2c0
Show file tree
Hide file tree
Showing 18 changed files with 2,320 additions and 2,053 deletions.
52 changes: 31 additions & 21 deletions app/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,24 @@ endif

MY_DIR := $(dir $(lastword $(MAKEFILE_LIST)))

ifeq ($(APP_TESTING),1)
DEFINES += APP_TESTING
DEFINES += ZEMU_LOGGING
endif

all: bin/app.elf
@echo "#!/usr/bin/env bash" > $(CURDIR)/pkg/zxtool.sh
@echo "APPNAME=\"${APPNAME}\"" >> $(CURDIR)/pkg/zxtool.sh
@echo "APPVERSION=\"${APPVERSION}\"" >> $(CURDIR)/pkg/zxtool.sh
@echo "APPPATH=\""${APPPATH}"\"" >> $(CURDIR)/pkg/zxtool.sh
@echo "LOAD_PARAMS=\"${COMMON_LOAD_PARAMS}\"" >> $(CURDIR)/pkg/zxtool.sh
@echo "DELETE_PARAMS=\"${COMMON_DELETE_PARAMS}\"" >> $(CURDIR)/pkg/zxtool.sh
@echo "APPHEX=\"" >> $(CURDIR)/pkg/zxtool.sh
@cat $(CURDIR)/bin/app.hex >> $(CURDIR)/pkg/zxtool.sh
@echo "\"" >> $(CURDIR)/pkg/zxtool.sh
@cat $(CURDIR)/../deps/ledger-zxlib/scripts/template.sh >> $(CURDIR)/pkg/zxtool.sh
@chmod +x $(CURDIR)/pkg/zxtool.sh

include $(BOLOS_SDK)/Makefile.defines

ifndef COIN
Expand Down Expand Up @@ -68,19 +86,6 @@ ifndef ICONNAME
$(error ICONNAME is not set)
endif

all: default
@echo "#!/usr/bin/env bash" > $(CURDIR)/pkg/zxtool.sh
@echo "APPNAME=\"${APPNAME}\"" >> $(CURDIR)/pkg/zxtool.sh
@echo "APPVERSION=\"${APPVERSION}\"" >> $(CURDIR)/pkg/zxtool.sh
@echo "APPPATH=\""${APPPATH}"\"" >> $(CURDIR)/pkg/zxtool.sh
@echo "LOAD_PARAMS=\"${COMMON_LOAD_PARAMS}\"" >> $(CURDIR)/pkg/zxtool.sh
@echo "DELETE_PARAMS=\"${COMMON_DELETE_PARAMS}\"" >> $(CURDIR)/pkg/zxtool.sh
@echo "APPHEX=\"" >> $(CURDIR)/pkg/zxtool.sh
@cat $(CURDIR)/bin/app.hex >> $(CURDIR)/pkg/zxtool.sh
@echo "\"" >> $(CURDIR)/pkg/zxtool.sh
@cat $(CURDIR)/../deps/ledger-zxlib/scripts/template.sh >> $(CURDIR)/pkg/zxtool.sh
@chmod +x $(CURDIR)/pkg/zxtool.sh

############
# Platform

Expand All @@ -96,8 +101,8 @@ DEFINES += HAVE_IO_USB HAVE_L4_USBLIB IO_USB_MAX_ENDPOINTS=7 IO_HID_EP_LEN

DEFINES += LEDGER_MAJOR_VERSION=$(APPVERSION_M) LEDGER_MINOR_VERSION=$(APPVERSION_N) LEDGER_PATCH_VERSION=$(APPVERSION_P)

DEFINES += USB_SEGMENT_SIZE=64
DEFINES += HAVE_BOLOS_APP_STACK_CANARY
DEFINES += USB_SEGMENT_SIZE=64
DEFINES += HAVE_BOLOS_APP_STACK_CANARY

DEFINES += HAVE_WEBUSB WEBUSB_URL_SIZE_B=0 WEBUSB_URL=""

Expand All @@ -113,7 +118,6 @@ DEFINES += HAVE_BAGL_FONT_OPEN_SANS_LIGHT_16PX

DEFINES += HAVE_UX_FLOW

#SDK_SOURCE_PATH += lib_blewbxx lib_blewbxx_impl
else
# Assume Nano S
DEFINES += IO_SEPROXYHAL_BUFFER_SIZE_B=128
Expand Down Expand Up @@ -165,34 +169,40 @@ APP_SOURCE_PATH += $(MY_DIR)/../deps/ledger-zxlib/include
APP_SOURCE_PATH += $(MY_DIR)/../deps/ledger-zxlib/src
APP_SOURCE_PATH += $(MY_DIR)/../deps/ledger-zxlib/app/common

SDK_SOURCE_PATH += lib_stusb lib_u2f lib_stusb_impl
SDK_SOURCE_PATH += lib_stusb lib_stusb_impl

#SDK_SOURCE_PATH += lib_blewbxx lib_blewbxx_impl
SDK_SOURCE_PATH += lib_ux

.PHONY: rust
rust:
cd rust && CARGO_HOME="$(CURDIR)/rust/.cargo" cargo build --target thumbv6m-none-eabi --release

# Before linking, we need to be sure rust lib is there
bin/app.elf: rust

.PHONY: rust_clean
rust_clean:
cd rust && CARGO_HOME="$(CURDIR)/rust/.cargo" cargo clean

clean: rust_clean

# load, delete and listvariants are provided to comply with Ledger requirements
.PHONY: load
load:
python -m ledgerblue.loadApp $(APP_LOAD_PARAMS)

.PHONY: delete
delete:
python -m ledgerblue.deleteApp $(COMMON_DELETE_PARAMS)

.PHONY: rust

all: default rust

# Import generic rules from the SDK
include $(BOLOS_SDK)/Makefile.rules

#add dependency on custom makefile filename
dep/%.d: %.c Makefile

.PHONY: listvariants
listvariants:
@echo VARIANTS COIN KSM
@echo VARIANTS COIN Ledgeracio
2 changes: 1 addition & 1 deletion app/Makefile.version
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
APPVERSION_M=1
APPVERSION_N=2011
APPVERSION_P=2
APPVERSION_P=3
17 changes: 15 additions & 2 deletions app/src/substrate_types.c
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ parser_error_t _readValidatorIndex(parser_context_t *c, pd_ValidatorIndex_t *v)

parser_error_t _readValidatorPrefs(parser_context_t *c, pd_ValidatorPrefs_t *v) {
CHECK_INPUT();
return _readCompactBalance(c, &v->balance);
return _readCompactPerBill(c, &v->commission);
}

parser_error_t _readVestingInfo(parser_context_t *c, pd_VestingInfo_t *v) {
Expand Down Expand Up @@ -1536,7 +1536,7 @@ parser_error_t _toStringValidatorPrefs(
uint16_t outValueLen,
uint8_t pageIdx,
uint8_t *pageCount) {
return _toStringCompactBalance(&v->balance, outValue, outValueLen, pageIdx, pageCount);
return _toStringCompactPerBill(&v->commission, outValue, outValueLen, pageIdx, pageCount);
}

parser_error_t _toStringVestingInfo(
Expand Down Expand Up @@ -1933,6 +1933,10 @@ parser_error_t _readCompactBalanceOf(parser_context_t *c, pd_CompactBalanceOf_t
return _readCompactBalance(c, v);
}

parser_error_t _readCompactPerBill(parser_context_t *c, pd_CompactPerBill_t *v) {
return _readCompactInt(c, v);
}

parser_error_t _readKeys(parser_context_t *c, pd_Keys_t *v) {
GEN_DEF_READARRAY(5 * 32);
}
Expand Down Expand Up @@ -2019,6 +2023,15 @@ parser_error_t _toStringCompactBalanceOf(
return _toStringCompactBalance(v, outValue, outValueLen, pageIdx, pageCount);
}

parser_error_t _toStringCompactPerBill(
const pd_CompactPerBill_t *v,
char *outValue,
uint16_t outValueLen,
uint8_t pageIdx,
uint8_t *pageCount) {
return _toStringCompactInt(v, 9, outValue, outValueLen, pageIdx, pageCount);
}

parser_error_t _toStringCompactu32(
const pd_Compactu32_t *v,
char *outValue,
Expand Down
12 changes: 11 additions & 1 deletion app/src/substrate_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ typedef compactInt_t pd_CompactMoment_t;

typedef compactInt_t pd_CompactParaId_t;

typedef compactInt_t pd_CompactPerBill_t;

typedef compactInt_t pd_CompactPropIndex_t;

typedef compactInt_t pd_CompactProposalIndex_t;
Expand Down Expand Up @@ -418,7 +420,7 @@ typedef struct {
} pd_ValidatorIndex_t;

typedef struct {
pd_CompactBalance_t balance;
pd_CompactPerBill_t commission;
} pd_ValidatorPrefs_t;

typedef struct {
Expand Down Expand Up @@ -559,6 +561,7 @@ parser_error_t _readCompactLeasePeriodOf(parser_context_t *c, pd_CompactLeasePer
parser_error_t _readCompactMemberCount(parser_context_t *c, pd_CompactMemberCount_t *v);
parser_error_t _readCompactMoment(parser_context_t *c, pd_CompactMoment_t *v);
parser_error_t _readCompactParaId(parser_context_t *c, pd_CompactParaId_t *v);
parser_error_t _readCompactPerBill(parser_context_t *c, pd_CompactPerBill_t *v);
parser_error_t _readCompactPropIndex(parser_context_t *c, pd_CompactPropIndex_t *v);
parser_error_t _readCompactProposalIndex(parser_context_t *c, pd_CompactProposalIndex_t *v);
parser_error_t _readCompactReferendumIndex(parser_context_t *c, pd_CompactReferendumIndex_t *v);
Expand Down Expand Up @@ -787,6 +790,13 @@ parser_error_t _toStringCompactParaId(
uint8_t pageIdx,
uint8_t *pageCount);

parser_error_t _toStringCompactPerBill(
const pd_CompactPerBill_t *v,
char *outValue,
uint16_t outValueLen,
uint8_t pageIdx,
uint8_t *pageCount);

parser_error_t _toStringCompactPropIndex(
const pd_CompactPropIndex_t *v,
char *outValue,
Expand Down
6 changes: 4 additions & 2 deletions deps/ledger-zxlib/app/common/view_s.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,10 @@ static unsigned int view_error_button(unsigned int button_mask, unsigned int but
static unsigned int view_review_button(unsigned int button_mask, unsigned int button_mask_counter) {
switch (button_mask) {
case BUTTON_EVT_RELEASED | BUTTON_LEFT | BUTTON_RIGHT:
// Press both left and right buttons to quit
view_sign_show_s();
if (app_mode_expert()) {
// Press both left and right buttons to quit
view_sign_show_s();
}
break;
case BUTTON_EVT_RELEASED | BUTTON_LEFT:
// Press left to progress to the previous element
Expand Down
14 changes: 12 additions & 2 deletions deps/ledger-zxlib/app/common/view_x.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,13 @@ UX_STEP_NOCB_INIT(ux_addr_flow_2_step, bnnn_paging,
UX_STEP_VALID(ux_addr_flow_3_step, pb, h_address_accept(0), { &C_icon_validate_14, "Ok"});

UX_FLOW(
ux_addr_flow,
ux_addr_flow_no_path,
&ux_addr_flow_1_step,
&ux_addr_flow_3_step
);

UX_FLOW(
ux_addr_flow_with_path,
&ux_addr_flow_1_step,
&ux_addr_flow_2_step,
&ux_addr_flow_3_step
Expand Down Expand Up @@ -225,7 +231,11 @@ void view_address_show_impl() {
if(G_ux.stack_count == 0) {
ux_stack_push();
}
ux_flow_init(0, ux_addr_flow, NULL);
if (app_mode_expert()) {
ux_flow_init(0, ux_addr_flow_with_path, NULL);
} else {
ux_flow_init(0, ux_addr_flow_no_path, NULL);
}
}

void view_error_show_impl() {
Expand Down
80 changes: 80 additions & 0 deletions deps/ledger-zxlib/app/common/zbuffer.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*******************************************************************************
* (c) 2020 Zondax GmbH
*
* 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.
********************************************************************************/

#include "zbuffer.h"
#include "zxmacros.h"

typedef struct {
uint8_t *ptr;
uint16_t size;
} zbuffer_t;

zbuffer_t _internal;

#define CANARY_EXPECTED 0x987def82u

zbuffer_error_e zb_get(uint8_t **buffer) {
*buffer = NULL;
if (_internal.size == 0 || _internal.ptr == NULL) {
return zb_not_allocated;
}
*buffer = _internal.ptr;
return zb_no_error;
}

zbuffer_error_e zb_init() {
_internal.size = 0;
_internal.ptr = NULL;
return zb_no_error;
}

zbuffer_error_e zb_allocate(uint16_t size) {
if (size % 4 != 0) {
return zb_misaligned_buffer;
}
_internal.size = size;
_internal.ptr = (uint8_t *) (&app_stack_canary + 4);

uint32_t *zb_canary = (uint32_t *) (_internal.ptr + _internal.size + 4);
*zb_canary = CANARY_EXPECTED;

return zb_no_error;
}

zbuffer_error_e zb_deallocate() {
if (_internal.size == 0) {
return zb_not_allocated;
}

// Flush any information
MEMZERO(_internal.ptr, _internal.size);

zb_init();
return zb_no_error;
}

zbuffer_error_e zb_check_canary() {
CHECK_APP_CANARY();
if (_internal.size != 0) {
// allocated
uint32_t *zb_canary = (uint32_t *) (_internal.ptr + _internal.size + 4);
if (*zb_canary != CANARY_EXPECTED) {
handle_stack_overflow();
}
}

return zb_no_error;
}
37 changes: 37 additions & 0 deletions deps/ledger-zxlib/app/common/zbuffer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*******************************************************************************
* (c) 2020 Zondax GmbH
*
* 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.
********************************************************************************/

#include <inttypes.h>
#include <stdint.h>

typedef enum {
zb_no_error,
zb_misaligned_buffer,
zb_not_allocated
} zbuffer_error_e;

// allocate a block at the end of the stack
// maximum size will not be checked
zbuffer_error_e zb_allocate(uint16_t size);

// deallocate memory block as the end of the stack
zbuffer_error_e zb_deallocate();

// obtain a pointer to the allocated block
zbuffer_error_e zb_get(uint8_t **buffer);

// check that the block boundary has not been corrupted
zbuffer_error_e zb_check_canary();
Loading

0 comments on commit 23ef2c0

Please sign in to comment.