Skip to content

Commit

Permalink
[update] More Flex porting, with tests & (some) corner cases managed
Browse files Browse the repository at this point in the history
  • Loading branch information
lpascal-ledger committed Jul 18, 2024
1 parent 9ef1a28 commit e952e7b
Show file tree
Hide file tree
Showing 76 changed files with 183 additions and 225 deletions.
113 changes: 22 additions & 91 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,127 +18,58 @@
ifeq ($(BOLOS_SDK),)
$(error Environment variable BOLOS_SDK is not set)
endif

include $(BOLOS_SDK)/Makefile.defines

all: default

# Main app configuration

APPNAME = "Recovery Check"
APPVERSION_M = 1
APPVERSION_N = 2
APPVERSION_P = 3
APPVERSION_N = 4
APPVERSION_P = 0
APPVERSION = "$(APPVERSION_M).$(APPVERSION_N).$(APPVERSION_P)"

APP_LOAD_PARAMS = --appFlags 0x10 $(COMMON_LOAD_PARAMS) --curve secp256k1 --path ""
VARIANT_PARAM = NONE
VARIANT_VALUES = recovery_check

ifeq ($(TARGET_NAME), TARGET_NANOS)
ICONNAME=icons/nanos_app_recovery_check.gif
else ifeq ($(TARGET_NAME), $(filter $(TARGET_NAME), TARGET_STAX TARGET_EUROPA))
ICONNAME=icons/stax_recovery_check_32px.gif
else
ICONNAME=icons/nanox_app_recovery_check.gif
endif
CURVE_APP_LOAD_PARAMS = secp256k1
PATH_APP_LOAD_PARAMS = ""
HAVE_APPLICATION_FLAG_DERIVE_MASTER = 1

# Build configuration
ICON_NANOS = icons/nanos_recovery_check.gif
ICON_NANOSP = icons/nanox_recovery_check.gif
ICON_NANOX = icons/nanox_recovery_check.gif
ICON_STAX = icons/stax_recovery_check.gif
ICON_FLEX = icons/flex_recovery_check.gif

DEFINES += APPVERSION=\"$(APPVERSION)\"
DEFINES += LEDGER_MAJOR_VERSION=$(APPVERSION_M)
DEFINES += LEDGER_MINOR_VERSION=$(APPVERSION_N)
DEFINES += LEDGER_PATCH_VERSION=$(APPVERSION_P)
DEFINES += OS_IO_SEPROXYHAL
DEFINES += HAVE_WEBUSB WEBUSB_URL_SIZE_B=0 WEBUSB_URL=""

DEFINES += BOLOS_APP_ICON_SIZE_B=\(9+32\)
#DEFINES += HAVE_ELECTRUM
DEFINES += IO_USB_MAX_ENDPOINTS=4 IO_HID_EP_LENGTH=64
DEFINES += HAVE_SPRINTF

ifneq ($(TARGET_NAME), $(filter $(TARGET_NAME), TARGET_STAX TARGET_EUROPA))
ifneq ($(TARGET_NAME), $(filter $(TARGET_NAME), TARGET_STAX TARGET_FLEX))
$(info Using BAGL)
DEFINES += HAVE_BAGL HAVE_UX_FLOW
else
$(info Using NBGL)
DEFINES += NBGL_KEYBOARD
endif

ifeq ($(TARGET_NAME), TARGET_NANOS)
DEFINES += IO_SEPROXYHAL_BUFFER_SIZE_B=128
else
DEFINES += IO_SEPROXYHAL_BUFFER_SIZE_B=300
ifneq ($(TARGET_NAME), $(filter $(TARGET_NAME), TARGET_STAX TARGET_EUROPA))
DEFINES += HAVE_BAGL
ifneq ($(TARGET_NAME), TARGET_NANOS)
DEFINES += IO_SEPROXYHAL_BUFFER_SIZE_B=300
DEFINES += HAVE_GLO096
DEFINES += BAGL_WIDTH=128 BAGL_HEIGHT=64
DEFINES += HAVE_BAGL_ELLIPSIS # long label truncation feature
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_KEYBOARD_UX
endif
endif

DEBUG = 0

ifneq ($(DEBUG), 0)
$(info DEBUG enabled)
DEFINES += HAVE_IO_USB HAVE_USB_APDU
SDK_SOURCE_PATH += lib_stusb lib_stusb_impl
DEFINES += HAVE_PRINTF
ifeq ($(TARGET_NAME), TARGET_NANOS)
DEFINES += PRINTF=screen_printf
else
DEFINES += PRINTF=mcu_usb_printf
DEFINES += IO_SEPROXYHAL_BUFFER_SIZE_B=128
endif
else
DEFINES += PRINTF\(...\)=
endif

##############
# Compiler #
##############
ifneq ($(BOLOS_ENV),)
$(info BOLOS_ENV=$(BOLOS_ENV))
CLANGPATH := $(BOLOS_ENV)/clang-arm-fropi/bin/
GCCPATH := $(BOLOS_ENV)/gcc-arm-none-eabi-5_3-2016q1/bin/
else
$(info BOLOS_ENV is not set: falling back to CLANGPATH and GCCPATH)
endif
ifeq ($(CLANGPATH),)
$(info CLANGPATH is not set: clang will be used from PATH)
endif
ifeq ($(GCCPATH),)
$(info GCCPATH is not set: arm-none-eabi-* will be used from PATH)
$(info Using NBGL)
DEFINES += IO_SEPROXYHAL_BUFFER_SIZE_B=300
DEFINES += NBGL_KEYBOARD
endif

CC := $(CLANGPATH)clang
CFLAGS += -Wshadow -Wformat
AS := $(GCCPATH)arm-none-eabi-gcc
LD := $(GCCPATH)arm-none-eabi-gcc
LDLIBS += -lm -lgcc -lc

include $(BOLOS_SDK)/Makefile.glyphs
DEBUG = 0

APP_SOURCE_PATH += src

ifneq ($(TARGET_NAME), TARGET_NANOS)
ifneq ($(TARGET_NAME), $(filter $(TARGET_NAME), TARGET_STAX TARGET_EUROPA))
SDK_SOURCE_PATH += lib_ux
endif
endif

# Main rules

load: all
python -m ledgerblue.loadApp $(APP_LOAD_PARAMS)

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

# Import generic rules from the SDK

include $(BOLOS_SDK)/Makefile.rules


listvariants:
@echo VARIANTS APP recovery_check
include $(BOLOS_SDK)/Makefile.standard_app
Binary file added icons/flex_recovery_check.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
File renamed without changes
Binary file removed icons/recovery_check.png
Binary file not shown.
File renamed without changes
2 changes: 1 addition & 1 deletion ledger_app.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[app]
build_directory = "./"
sdk = "C"
devices = ["nanos", "nanox", "nanos+", "stax"]
devices = ["nanos", "nanox", "nanos+", "stax", "flex"]

[tests]
unit_directory = "./tests/unit"
Expand Down
75 changes: 13 additions & 62 deletions src/main.c → src/app_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,43 +25,26 @@
extern enum UI_STATE uiState;
#endif

bolos_ux_params_t G_ux_params;
unsigned char G_io_seproxyhal_spi_buffer[IO_SEPROXYHAL_BUFFER_SIZE_B];

static unsigned int current_text_pos; // parsing cursor in the text to display
static unsigned int text_y; // current location of the displayed text

// UI currently displayed
enum UI_STATE { UI_IDLE, UI_TEXT, UI_APPROVAL };

unsigned short io_exchange_al(unsigned char channel, unsigned short tx_len) {
switch (channel & ~(IO_FLAGS)) {
case CHANNEL_KEYBOARD:
break;

// multiplexed io exchange over a SPI channel and TLV encapsulated protocol
case CHANNEL_SPI:
if (tx_len) {
io_seproxyhal_spi_send(G_io_apdu_buffer, tx_len);

if (channel & IO_RESET_AFTER_REPLIED) {
reset();
}
return 0; // nothing received from the master so far (it's a tx
// transaction)
} else {
return io_seproxyhal_spi_recv(G_io_apdu_buffer, sizeof(G_io_apdu_buffer), 0);
}
void app_main(void) {
current_text_pos = 0;
text_y = 60;
#if defined(HAVE_BAGL)
uiState = UI_IDLE;
#endif

default:
THROW(INVALID_PARAMETER);
}
return 0;
}
#if defined(HAVE_NBGL)
nbgl_objInit();
#elif defined(HAVE_BAGL)
UX_INIT();
#endif

static void sample_main(void) {
// next timer callback in 500 ms
// UX_CALLBACK_SET_INTERVAL(500);
ui_idle_init();

uint8_t flags = 0;

Expand Down Expand Up @@ -99,7 +82,7 @@ unsigned char io_event(unsigned char channel __attribute__((unused))) {
UX_DISPLAYED_EVENT();
}
}
#elif defined(TARGET_NANOX) || defined(TARGET_NANOS2)
#elif defined(TARGET_NANOX) || defined(TARGET_NANOS2) || defined(TARGET_FATSTACKS)
UX_DISPLAYED_EVENT({});
#elif defined(HAVE_NBGL)
UX_DEFAULT_EVENT();
Expand Down Expand Up @@ -129,35 +112,3 @@ unsigned char io_event(unsigned char channel __attribute__((unused))) {
// command has been processed, DO NOT reset the current APDU transport
return 1;
}

__attribute__((section(".boot"))) int main(void) {
// exit critical section
__asm volatile("cpsie i");

current_text_pos = 0;
text_y = 60;
#if defined(HAVE_BAGL)
uiState = UI_IDLE;
#endif
// ensure exception will work as planned
os_boot();

#if defined(HAVE_NBGL)
nbgl_objInit();
#elif defined(HAVE_BAGL)
UX_INIT();
#endif

BEGIN_TRY {
TRY {
io_seproxyhal_init();
ui_idle_init();
sample_main();
}
CATCH_OTHER(e) {
}
FINALLY {
}
}
END_TRY;
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "../constants.h"
#include "../ui.h"

#if defined(TARGET_NANOX) || defined(TARGET_NANOS2)
#if defined(TARGET_NANOX) || defined(TARGET_NANOS2) || defined(TARGET_FATSTACKS)

const bagl_element_t* screen_onboarding_4_restore_word_before_element_display_callback(
const bagl_element_t* element);
Expand Down
4 changes: 1 addition & 3 deletions src/nano/ui_nano.c → src/bagl/ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ enum UI_STATE { UI_IDLE, UI_TEXT, UI_APPROVAL };

enum UI_STATE uiState;

ux_state_t G_ux;

#if defined(TARGET_NANOS)

UX_STEP_CB(restore_3_1_1, bb, G_bolos_ux_context.onboarding_kind = MNEMONIC_SIZE_24;
Expand Down Expand Up @@ -68,7 +66,7 @@ UX_STEP_VALID(ux_idle_flow_4_step,

UX_FLOW(ux_idle_flow, &ux_idle_flow_1_step, &ux_idle_flow_3_step, &ux_idle_flow_4_step);

#elif defined(TARGET_NANOX) || defined(TARGET_NANOS2)
#elif defined(TARGET_NANOX) || defined(TARGET_NANOS2) || defined(TARGET_FATSTACKS)

//////////////////////////////////////////////////////////////////////

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include "constants.h"
#include "ui.h"

#if defined(TARGET_NANOX) || defined(TARGET_NANOS2)
#if defined(TARGET_NANOX) || defined(TARGET_NANOS2) || defined(TARGET_FATSTACKS)

#ifdef OS_IO_SEPROXYHAL

Expand Down
2 changes: 1 addition & 1 deletion src/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ enum {
// displayed and using the common string buffer as string parameter
#define KEYBOARD_RENDER_WORD \
3 // callback is called with a -1 when requesting complete word, or the char index else,
// returnin 0 implies no char is to be displayed
// returning 0 implies no char is to be displayed

#define RESTORE_WORD_ACTION_REENTER_WORD 0
#define RESTORE_WORD_ACTION_FIRST_WORD 1
Expand Down
2 changes: 1 addition & 1 deletion src/stax/mnemonic.c → src/nbgl/mnemonic.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ bool remove_word_from_mnemonic() {
mnemonic.current_word_index--;
// removing previous word from mnemonic buffer (+ 1 blank space)
mnemonic_shrink(current_length + 1);
PRINTF("Number of remaining words in the mnemonic: '%ld'\n", mnemonic.current_word_index + 1);
PRINTF("Number of remaining words in the mnemonic: '%d'\n", mnemonic.current_word_index + 1);
return true;
}

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

#include <nbgl_obj.h>

#define UPPER_MARGIN 4
#define ICON_X 0
#define ICON_Y 148
#define UPPER_MARGIN 4
#define ICON_X 0
#define ICON_Y 148

nbgl_image_t *passphrase_length_set_icon() {
nbgl_image_t *image = (nbgl_image_t *) nbgl_objPoolGet(IMAGE, 0);
Expand Down
File renamed without changes.
Loading

0 comments on commit e952e7b

Please sign in to comment.