Skip to content

Commit

Permalink
feat: flex support
Browse files Browse the repository at this point in the history
  • Loading branch information
krigga committed Aug 9, 2024
1 parent b786b20 commit 4534d64
Show file tree
Hide file tree
Showing 300 changed files with 381 additions and 1,591 deletions.
142 changes: 33 additions & 109 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,129 +21,53 @@ endif

include $(BOLOS_SDK)/Makefile.defines

APP_LOAD_PARAMS = --curve ed25519
ifeq ($(TARGET_NAME),$(filter $(TARGET_NAME),TARGET_NANOX TARGET_STAX))
APP_LOAD_PARAMS += --appFlags 0x200 # APPLICATION_FLAG_BOLOS_SETTINGS
else
APP_LOAD_PARAMS += --appFlags 0x000
ifneq ($(TARGET_NAME),TARGET_NANOS)
DEFINES += HAVE_HARDCODED_JETTONS
endif
APP_LOAD_PARAMS += --path "44'/607'"
APP_LOAD_PARAMS += $(COMMON_LOAD_PARAMS)

APPNAME = "TON"
APPVERSION_M = 2
APPVERSION_N = 2
APPVERSION_N = 3
APPVERSION_P = 0
APPVERSION = "$(APPVERSION_M).$(APPVERSION_N).$(APPVERSION_P)"

ifeq ($(TARGET_NAME),TARGET_NANOS)
ICONNAME=icons/nanos_app_ton.gif
else ifeq ($(TARGET_NAME),TARGET_STAX)
ICONNAME=icons/ledger_stax_ton_32.gif
else
ICONNAME=icons/nanox_app_ton.gif
endif

all: default

DEFINES += $(DEFINES_LIB)
DEFINES += APPNAME=\"$(APPNAME)\"
DEFINES += APPVERSION=\"$(APPVERSION)\"
DEFINES += MAJOR_VERSION=$(APPVERSION_M) MINOR_VERSION=$(APPVERSION_N) PATCH_VERSION=$(APPVERSION_P)
DEFINES += OS_IO_SEPROXYHAL
DEFINES += HAVE_SPRINTF HAVE_SNPRINTF_FORMAT_U
DEFINES += HAVE_IO_USB HAVE_L4_USBLIB IO_USB_MAX_ENDPOINTS=6 IO_HID_EP_LENGTH=64 HAVE_USB_APDU
DEFINES += USB_SEGMENT_SIZE=64
DEFINES += BLE_SEGMENT_SIZE=32
DEFINES += HAVE_WEBUSB WEBUSB_URL_SIZE_B=0 WEBUSB_URL=""

ifeq ($(TARGET_NAME),$(filter $(TARGET_NAME),TARGET_NANOX TARGET_STAX))
DEFINES += HAVE_BLE BLE_COMMAND_TIMEOUT_MS=2000 HAVE_BLE_APDU
endif

ifeq ($(TARGET_NAME),TARGET_NANOS)
DEFINES += IO_SEPROXYHAL_BUFFER_SIZE_B=128
else
DEFINES += IO_SEPROXYHAL_BUFFER_SIZE_B=300
endif

ifeq ($(TARGET_NAME),TARGET_STAX)
DEFINES += NBGL_QRCODE
SDK_SOURCE_PATH += qrcode
else
DEFINES += HAVE_BAGL HAVE_UX_FLOW
ifneq ($(TARGET_NAME),TARGET_NANOS)
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
endif
endif

ifneq ($(TARGET_NAME),TARGET_NANOS)
DEFINES += HAVE_HARDCODED_JETTONS
endif

DEBUG = 0
ifneq ($(DEBUG),0)
DEFINES += HAVE_PRINTF
ifeq ($(TARGET_NAME),TARGET_NANOS)
DEFINES += PRINTF=screen_printf
else
DEFINES += PRINTF=mcu_usb_printf
endif
else
DEFINES += PRINTF\(...\)=
endif

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)
endif

CC := $(CLANGPATH)clang
CFLAGS += -O3 -Os
AS := $(GCCPATH)arm-none-eabi-gcc
LD := $(GCCPATH)arm-none-eabi-gcc
LDFLAGS += -O3 -Os
LDLIBS += -lm -lgcc -lc
APP_SOURCE_PATH += src

include $(BOLOS_SDK)/Makefile.glyphs
ICON_NANOX = icons/nanox_app_ton.gif
ICON_NANOSP = icons/nanox_app_ton.gif
ICON_NANOS = icons/nanos_app_ton.gif
ICON_STAX = icons/ledger_stax_ton_32.gif
ICON_FLEX = icons/ledger_flex_ton_40.gif

APP_SOURCE_PATH += src
SDK_SOURCE_PATH += lib_stusb lib_stusb_impl
CURVE_APP_LOAD_PARAMS = ed25519

ifneq ($(TARGET_NAME),TARGET_STAX)
SDK_SOURCE_PATH += lib_ux
endif
PATH_APP_LOAD_PARAMS = "44'/607'"

ifeq ($(TARGET_NAME),$(filter $(TARGET_NAME),TARGET_NANOX TARGET_STAX))
SDK_SOURCE_PATH += lib_blewbxx lib_blewbxx_impl
endif
VARIANT_PARAM = COIN
VARIANT_VALUES = TON

load: all
python3 -m ledgerblue.loadApp $(APP_LOAD_PARAMS)
# DEBUG = 1

load-offline: all
python3 -m ledgerblue.loadApp $(APP_LOAD_PARAMS) --offline
# HAVE_APPLICATION_FLAG_DERIVE_MASTER = 1
# HAVE_APPLICATION_FLAG_GLOBAL_PIN = 1
# HAVE_APPLICATION_FLAG_BOLOS_SETTINGS = 1
# HAVE_APPLICATION_FLAG_LIBRARY = 1

delete:
python3 -m ledgerblue.deleteApp $(COMMON_DELETE_PARAMS)
ENABLE_BLUETOOTH = 1
# ENABLE_NFC = 1

include $(BOLOS_SDK)/Makefile.rules
ENABLE_NBGL_QRCODE = 1
# ENABLE_NBGL_KEYBOARD = 1
# ENABLE_NBGL_KEYPAD = 1

dep/%.d: %.c Makefile
# DISABLE_STANDARD_APP_FILES = 1
# DISABLE_DEFAULT_IO_SEPROXY_BUFFER_SIZE = 1 # To allow custom size declaration
# DISABLE_STANDARD_APP_DEFINES = 1 # Will set all the following disablers
# DISABLE_STANDARD_SNPRINTF = 1
# DISABLE_STANDARD_USB = 1
# DISABLE_STANDARD_WEBUSB = 1
# DISABLE_STANDARD_BAGL_UX_FLOW = 1
# DISABLE_DEBUG_LEDGER_ASSERT = 1
# DISABLE_DEBUG_THROW = 1

listvariants:
@echo VARIANTS COIN TON
include $(BOLOS_SDK)/Makefile.standard_app
2 changes: 1 addition & 1 deletion fuzzing/fuzz_tx_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <sys/types.h>

extern "C" {
#include "common/buffer.h"
#include "common/mybuffer.h"
#include "transaction/deserialize.h"
#include "transaction/types.h"
}
Expand Down
Binary file added icons/ledger_flex_ton_40.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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"]

[use_cases]
debug = "DEBUG=1"
Expand Down
3 changes: 1 addition & 2 deletions src/apdu/dispatcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@
#include "../constants.h"
#include "../globals.h"
#include "../types.h"
#include "../io.h"
#include "../sw.h"
#include "../common/buffer.h"
#include "common/mybuffer.h"
#include "../handler/get_address_proof.h"
#include "../handler/get_version.h"
#include "../handler/get_app_name.h"
Expand Down
1 change: 1 addition & 0 deletions src/apdu/dispatcher.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include "../types.h"
#include "parser.h"

/**
* Dispatch APDU command received to the right handler.
Expand Down
40 changes: 0 additions & 40 deletions src/apdu/parser.c

This file was deleted.

22 changes: 0 additions & 22 deletions src/apdu/parser.h

This file was deleted.

92 changes: 92 additions & 0 deletions src/app_main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*****************************************************************************
* Ledger App Boilerplate.
* (c) 2020 Ledger SAS.
*
* 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 <stdint.h> // uint*_t
#include <string.h> // memset, explicit_bzero
#include <stdbool.h>

#include "os.h"
#include "ux.h"

#include "types.h"
#include "globals.h"
#include "io.h"
#include "sw.h"
#include "ui/menu.h"
#include "parser.h"
#include "apdu/dispatcher.h"

global_ctx_t G_context;

const internalStorage_t N_storage_real;

void nv_init() {
if (!N_storage.initialized) {
internalStorage_t storage;
storage.initialized = true;
storage.blind_signing_enabled = false;
storage.expert_mode = false;
nvm_write((void *) &N_storage, (void *) &storage, sizeof(internalStorage_t));
}
}

/**
* Handle APDU command received and send back APDU response using handlers.
*/
void app_main() {
// Length of APDU command received in G_io_apdu_buffer
int input_len = 0;
// Structured APDU command
command_t cmd;

io_init();

ui_menu_main();

// Reset context
explicit_bzero(&G_context, sizeof(G_context));

nv_init();

for (;;) {
// Receive command bytes in G_io_apdu_buffer
if ((input_len = io_recv_command()) < 0) {
return;
}

// Parse APDU command from G_io_apdu_buffer
if (!apdu_parser(&cmd, G_io_apdu_buffer, input_len)) {
PRINTF("=> /!\\ BAD LENGTH: %.*H\n", input_len, G_io_apdu_buffer);
io_send_sw(SW_WRONG_DATA_LENGTH);
continue;
}

PRINTF("=> CLA=%02X | INS=%02X | P1=%02X | P2=%02X | Lc=%02X | CData=%.*H\n",
cmd.cla,
cmd.ins,
cmd.p1,
cmd.p2,
cmd.lc,
cmd.lc,
cmd.data);

// Dispatch structured APDU command to handler
if (apdu_dispatcher(&cmd) < 0) {
return;
}
}
}
Loading

0 comments on commit 4534d64

Please sign in to comment.