Skip to content

Commit

Permalink
remove textual support from NanoS
Browse files Browse the repository at this point in the history
  • Loading branch information
chcmedeiros committed Mar 12, 2024
1 parent e0af516 commit 8cd6c6e
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 7 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ target_link_libraries(unittests PRIVATE

add_compile_definitions(TESTVECTORS_DIR="${CMAKE_CURRENT_SOURCE_DIR}/tests/")
add_compile_definitions(APP_TESTING=1)
add_compile_definitions(COMPILE_TEXTUAL=1)
add_test(unittests ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/unittests)
set_tests_properties(unittests PROPERTIES WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/tests)

Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,5 +205,8 @@ The Makefile will build the firmware in a docker container and leave the binary

## APDU Specifications

### DISCLAIMER
Ledger NanoS does not support Cosmos Textual Mode due to memory restriction

- [APDU Protocol](docs/APDUSPEC.md)
- [Transaction format](docs/TXSPEC.md)
9 changes: 9 additions & 0 deletions app/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@ ifndef ICONNAME
$(error ICONNAME is not set)
endif

# Compile textual mode for all devices excetpt Nano S,
# and define a Min stack size for Nano S with some margin
# to get an error if app grows too much
ifneq ($(TARGET_NAME),TARGET_NANOS)
DEFINES += COMPILE_TEXTUAL
endif

APP_STACK_MIN_SIZE := 1600

include $(CURDIR)/../deps/ledger-zxlib/makefiles/Makefile.platform
CFLAGS += -I$(MY_DIR)/../deps/tinycbor/src
APP_SOURCE_PATH += $(MY_DIR)/../deps/tinycbor-ledger
Expand Down
6 changes: 0 additions & 6 deletions app/src/common/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,13 @@ extern "C" {
#include "coin.h"

#define OUTPUT_HANDLER_SIZE 600
#if defined(TARGET_NANOS)
#undef OUTPUT_HANDLER_SIZE
#define OUTPUT_HANDLER_SIZE 450
#endif

#define MAX_CONTENT_SIZE 550
#define MAX_TITLE_SIZE 40
#define PRINTABLE_TITLE_SIZE 17
#define PRINTABLE_PAGINATED_TITLE_SIZE 10
#define SCREEN_BREAK ":"
#define SCREEN_INDENT ">"
#define TITLE_TRUNCATE_REPLACE "---"
#define END_OF_STRING_SIZE

const char *parser_getErrorDescription(parser_error_t err);

Expand Down
8 changes: 7 additions & 1 deletion app/src/common/tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#define RAM_BUFFER_SIZE 8192
#define FLASH_BUFFER_SIZE 16384
#elif defined(TARGET_NANOS)
#define RAM_BUFFER_SIZE 256
#define RAM_BUFFER_SIZE 0
#define FLASH_BUFFER_SIZE 8192
#endif

Expand Down Expand Up @@ -78,9 +78,15 @@ static parser_tx_t tx_obj;

const char *tx_parse(tx_type_e type)
{
#if defined(COMPILE_TEXTUAL)
if (type != tx_json && type != tx_textual) {
return parser_getErrorDescription(parser_value_out_of_range);
}
#else
if (type != tx_json) {
return parser_getErrorDescription(parser_value_out_of_range);
}
#endif

MEMZERO(&tx_obj, sizeof(tx_obj));
tx_obj.tx_type = type;
Expand Down
14 changes: 14 additions & 0 deletions app/src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ __Z_INLINE parser_error_t parser_formatAmount(uint16_t amountToken,
return parser_formatAmountItem(showItemTokenIdx, outVal, outValLen, showPageIdx, &dummy);
}

#if defined(COMPILE_TEXTUAL)
__Z_INLINE parser_error_t parser_screenPrint(const parser_context_t *ctx,
Cbor_container *container,
char *outKey, uint16_t outKeyLen,
Expand Down Expand Up @@ -433,12 +434,24 @@ __Z_INLINE parser_error_t parser_getNextNonExpert(const parser_context_t *ctx,
}
return parser_ok;
}
#endif

__Z_INLINE parser_error_t parser_getTextualItem(const parser_context_t *ctx,
uint8_t displayIdx,
char *outKey, uint16_t outKeyLen,
char *outVal, uint16_t outValLen,
uint8_t pageIdx, uint8_t *pageCount) {
#if !defined(COMPILE_TEXTUAL)
UNUSED(ctx);
UNUSED(displayIdx);
UNUSED(outKey);
UNUSED(outKeyLen);
UNUSED(outVal);
UNUSED(outValLen);
UNUSED(pageIdx);
UNUSED(pageCount);
return parser_value_out_of_range;
#else
*pageCount = 0;

MEMZERO(outKey, outKeyLen);
Expand Down Expand Up @@ -477,6 +490,7 @@ __Z_INLINE parser_error_t parser_getTextualItem(const parser_context_t *ctx,
CHECK_PARSER_ERR(parser_screenPrint(ctx, &container, outKey, outKeyLen, outVal, outValLen, pageIdx, pageCount))

return parser_ok;
#endif
}

__Z_INLINE parser_error_t parser_getJsonItem(const parser_context_t *ctx,
Expand Down
6 changes: 6 additions & 0 deletions app/src/parser_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ parser_error_t _read_json_tx(parser_context_t *c, __Z_UNUSED parser_tx_t *v) {
}

parser_error_t _read_text_tx(parser_context_t *c, parser_tx_t *v) {
#if !defined(COMPILE_TEXTUAL)
UNUSED(c);
UNUSED(v);
return parser_value_out_of_range;
#else
CborValue it;
CborValue mapStruct_ptr;
CHECK_APP_CANARY()
Expand Down Expand Up @@ -166,4 +171,5 @@ parser_error_t _read_text_tx(parser_context_t *c, parser_tx_t *v) {
PARSER_ASSERT_OR_ERROR(it.source.ptr == c->buffer + c->bufferLen, parser_cbor_unexpected_EOF)

return parser_ok;
#endif
}

0 comments on commit 8cd6c6e

Please sign in to comment.