Skip to content

Commit

Permalink
Merge pull request #404 from LedgerHQ/xch/cherry-pick12
Browse files Browse the repository at this point in the history
Cherry pick for API_LEVEL_12
  • Loading branch information
xchapron-ledger authored Aug 18, 2023
2 parents e6bbd8f + 3caaee0 commit 11fdad0
Show file tree
Hide file tree
Showing 21 changed files with 235 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .codespellrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[codespell]
ignore-words-list=ontop,clen
ignore-words-list=ontop,clen,habitant
10 changes: 8 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@
# pre-commit install --hook-type pre-commit
# pre-commit install --hook-type commit-msg

exclude: ^(lib_blewbxx/|lib_stusb/)
exclude: |
(?x)^(
lib_blewbxx/.*|
lib_stusb/.*|
lib_nbgl/include/.*.json|
lib_bagl/include/.*.json|
)$
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
Expand All @@ -13,6 +19,6 @@ repos:
- id: check-added-large-files

- repo: https://github.com/codespell-project/codespell
rev: v2.2.2
rev: v2.2.5
hooks:
- id: codespell
35 changes: 17 additions & 18 deletions Makefile.defines
Original file line number Diff line number Diff line change
Expand Up @@ -172,24 +172,8 @@ LDFLAGS += -L$(BOLOS_SDK)/arch/st33k1/lib/
AFLAGS += -mcpu=cortex-m35p+nodsp -mthumb
endif

ifeq ($(TARGET_NAME),TARGET_NANOS)
DEFINES += HAVE_BAGL
DEFINES += BAGL_WIDTH=128 BAGL_HEIGHT=32

LDFLAGS += -L$(BOLOS_SDK)/lib/
endif

ifeq ($(TARGET_NAME),$(filter $(TARGET_NAME),TARGET_NANOX TARGET_NANOS2))
DEFINES += HAVE_BAGL HAVE_UX_FLOW
DEFINES += BAGL_WIDTH=128 BAGL_HEIGHT=64
DEFINES += HAVE_BAGL_ELLIPSIS
DEFINES += HAVE_BAGL_FONT_OPEN_SANS_REGULAR_11PX
DEFINES += HAVE_BAGL_FONT_OPEN_SANS_EXTRABOLD_11PX
DEFINES += HAVE_BAGL_FONT_OPEN_SANS_LIGHT_16PX

LDFLAGS += -L$(BOLOS_SDK)/lib/
endif

NO_UI ?= 0
ifeq ($(NO_UI), 0)
ifeq ($(TARGET_NAME),TARGET_STAX)
DEFINES += HAVE_BAGL_FONT_INTER_REGULAR_24PX
DEFINES += HAVE_BAGL_FONT_INTER_SEMIBOLD_24PX
Expand All @@ -201,6 +185,21 @@ DEFINES += HAVE_SE_TOUCH
DEFINES += NBGL_PAGE
DEFINES += NBGL_USE_CASE
#DEFINES += HAVE_DISPLAY_FAST_MODE
else
DEFINES += HAVE_BAGL
DEFINES += BAGL_WIDTH=128
ifeq ($(TARGET_NAME),TARGET_NANOS)
DEFINES += BAGL_HEIGHT=32
endif
ifeq ($(TARGET_NAME),$(filter $(TARGET_NAME),TARGET_NANOX TARGET_NANOS2))
DEFINES += HAVE_UX_FLOW
DEFINES += BAGL_HEIGHT=64
DEFINES += HAVE_BAGL_ELLIPSIS
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
endif

ifeq ($(TARGET_NAME),$(filter $(TARGET_NAME),TARGET_NANOX TARGET_NANOS2))
Expand Down
6 changes: 5 additions & 1 deletion Makefile.rules
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@

# temporary redef, to ensure wider compliance of the SDK with pre-1.6 apps
ifeq ($(TARGET_NAME),$(filter $(TARGET_NAME),TARGET_NANOS TARGET_NANOX TARGET_NANOS2))
ifeq ($(NO_UI), 0)
SDK_SOURCE_PATH += lib_bagl lib_ux
endif
else ifeq ($(TARGET_NAME),TARGET_STAX)
SDK_SOURCE_PATH += lib_nbgl lib_ux_stax qrcode lib_nfc
ifeq ($(NO_UI), 0)
SDK_SOURCE_PATH += lib_nbgl lib_ux_stax
endif
endif

# adding the correct target header to sources
Expand Down
8 changes: 7 additions & 1 deletion Makefile.rules_generic
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,13 @@ $(OBJ_DIR)/%.o: %.S $(BUILD_DEPENDENCIES) prepare
$(L)$(call as_cmdline,$(INCLUDES_PATH), $(DEFINES),$<,$@)

ifeq ($(SCRIPT_LD),)
SCRIPT_LD:=$(BOLOS_SDK)/target/$(TARGET)/script.ld
LDFLAGS += -L$(BOLOS_SDK)/target/$(TARGET)
ifeq ($(IS_PLUGIN),)
SCRIPT_LD := $(BOLOS_SDK)/target/$(TARGET)/script.ld
else
SCRIPT_LD := $(BOLOS_SDK)/target/$(TARGET)/plugin_script.ld
$(info Using plugin link script: $(SCRIPT_LD))
endif
else
$(info Using custom link script: $(SCRIPT_LD))
endif
Expand Down
18 changes: 16 additions & 2 deletions Makefile.standard_app
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ 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 += IO_HID_EP_LENGTH=64

ifeq ($(DISABLE_STANDARD_APP_DEFINES), 1)
Expand All @@ -92,14 +91,24 @@ ifneq ($(DISABLE_STANDARD_SNPRINTF), 1)
DEFINES += HAVE_SPRINTF HAVE_SNPRINTF_FORMAT_U
endif

ifneq ($(TARGET_NAME),TARGET_NANOS)
# Since the PRINTF implementation uses the USB code
ifneq ($(DEBUG), 0)
DISABLE_STANDARD_USB = 0
endif
endif

ifneq ($(DISABLE_STANDARD_USB), 1)
DEFINES += HAVE_IO_USB HAVE_L4_USBLIB IO_USB_MAX_ENDPOINTS=4 HAVE_USB_APDU
DEFINES += USB_SEGMENT_SIZE=64
SDK_SOURCE_PATH += lib_stusb lib_stusb_impl
endif

ifneq ($(DISABLE_STANDARD_WEBUSB), 1)
DEFINES += HAVE_WEBUSB WEBUSB_URL_SIZE_B=0 WEBUSB_URL=""
APP_WEBUSB_URL ?= ""
WEBUSB_URL_SIZE_B = $(shell echo -n $(APP_WEBUSB_URL) | wc -c)
WEBUSB_URL=$(shell echo -n $(APP_WEBUSB_URL) | sed -e "s/./\\\'\0\\\',/g")
DEFINES += HAVE_WEBUSB WEBUSB_URL_SIZE_B=$(WEBUSB_URL_SIZE_B) WEBUSB_URL=$(WEBUSB_URL)
endif

ifneq ($(DISABLE_STANDARD_BAGL_UX_FLOW), 1)
Expand All @@ -108,6 +117,10 @@ ifneq ($(TARGET_NAME), TARGET_STAX)
endif
endif

ifneq ($(DISABLE_SEPROXYHAL), 1)
DEFINES += OS_IO_SEPROXYHAL
endif

ifneq ($(DISABLE_STANDARD_APP_FILES), 1)
SDK_SOURCE_PATH += lib_standard_app
endif
Expand All @@ -118,6 +131,7 @@ endif
ifeq ($(ENABLE_NBGL_QRCODE), 1)
ifeq ($(TARGET_NAME), TARGET_STAX)
DEFINES += NBGL_QRCODE
SDK_SOURCE_PATH += qrcode
endif
endif

Expand Down
4 changes: 4 additions & 0 deletions lib_nbgl/src/nbgl_draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
#include "nbgl_fonts.h"
#include "nbgl_debug.h"
#include "nbgl_side.h"
#ifdef NBGL_QRCODE
#include "qrcodegen.h"
#endif
#include "glyphs.h"
#include "os_pic.h"
#include "os_utils.h"
Expand All @@ -32,11 +34,13 @@
/**********************
* TYPEDEFS
**********************/
#ifdef NBGL_QRCODE
typedef struct {
uint8_t qrcode[qrcodegen_BUFFER_LEN_MAX];
uint8_t tempBuffer[qrcodegen_BUFFER_LEN_MAX];
uint8_t QrDrawBuffer[QR_PIXEL_WIDTH_HEIGHT * QR_PIXEL_WIDTH_HEIGHT * QR_MAX_PIX_SIZE / 8];
} QrCodeBuffer_t;
#endif

#define qrcode ((QrCodeBuffer_t*)ramBuffer)->qrcode
#define tempBuffer ((QrCodeBuffer_t*)ramBuffer)->tempBuffer
Expand Down
4 changes: 3 additions & 1 deletion lib_nbgl/tools/icon2glyph.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,9 @@ def print_glyphfile_top(add_include: bool):
"""\
#ifdef HAVE_NBGL
#include \"nbgl_types.h\"
#endif // HAVE_NBGL
#else
#include <stdint.h>
#endif
""")


Expand Down
4 changes: 2 additions & 2 deletions lib_standard_app/crypto_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ WARN_UNUSED_RESULT cx_err_t bip32_derive_with_seed_init_privkey_256(
CX_CHECK(cx_ecfp_init_private_key_no_throw(curve, raw_privkey, length, privkey));

end:
explicit_bzero(&raw_privkey, sizeof(raw_privkey));
explicit_bzero(raw_privkey, sizeof(raw_privkey));

if (error != CX_OK) {
// Make sure the caller doesn't use uninitialized data in case
// the return code is not checked.
explicit_bzero(&privkey, sizeof(privkey));
explicit_bzero(privkey, sizeof(cx_ecfp_256_private_key_t));
}
return error;
}
Expand Down
18 changes: 18 additions & 0 deletions lib_standard_app/format.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,24 @@ bool format_fpu64(char *dst, size_t dst_len, const uint64_t value, uint8_t decim
return true;
}

bool format_fpu64_trimmed(char *dst, size_t dst_len, const uint64_t value, uint8_t decimals) {
if (!format_fpu64(dst, dst_len, value, decimals)) {
return false;
}

size_t len = strlen(dst);

while (len > 0 && (dst[len - 1] == '0' || dst[len - 1] == '.')) {
if (dst[len - 1] == '.') {
dst[len - 1] = '\0';
return true;
}
len--;
}
dst[len] = '\0';
return true;
}

int format_hex(const uint8_t *in, size_t in_len, char *out, size_t out_len) {
if (out_len < 2 * in_len + 1) {
return -1;
Expand Down
17 changes: 17 additions & 0 deletions lib_standard_app/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,23 @@ bool format_u64(char *dst, size_t dst_len, uint64_t value);
*/
bool format_fpu64(char *dst, size_t dst_len, const uint64_t value, uint8_t decimals);

/**
* Format 64-bit unsigned integer as string with decimals and trimmed zeros and dot.
*
* @param[out] dst
* Pointer to output string.
* @param[in] dst_len
* Length of output string.
* @param[in] value
* 64-bit unsigned integer to format.
* @param[in] decimals
* Number of digits after decimal separator.
*
* @return true if success, false otherwise.
*
*/
bool format_fpu64_trimmed(char *dst, size_t dst_len, const uint64_t value, uint8_t decimals);

/**
* Format byte buffer to uppercase hexadecimal string.
*
Expand Down
8 changes: 8 additions & 0 deletions src/os_io_task.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,26 @@ void io_start(void) {
void bolos_init_ios(void) {
#endif // HAVE_IO_TASK

#ifdef OS_IO_SEPROXYHAL
io_seproxyhal_init();
#endif

#ifdef HAVE_IO_USB
USB_power(0);
#endif

#ifdef HAVE_BLE
memset(&G_io_asynch_ux_callback, 0, sizeof(G_io_asynch_ux_callback));
LEDGER_BLE_init();
#endif // HAVE_BLE

#ifdef OS_IO_SEPROXYHAL
io_seproxyhal_init();
#endif

#ifdef HAVE_IO_USB
USB_power(1);
#endif
}


Expand Down
22 changes: 22 additions & 0 deletions target/nanos/plugin_script.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*******************************************************************************
* Ledger - Secure firmware
* (c) 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023 Ledger
*
* 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.
********************************************************************************/

/* Reuse the main linker script */
INCLUDE script.ld

/* No global variable allowed in plugins */
ASSERT( (_ebss - _bss) <= 0, ".bss section must be empty for plugins" )
4 changes: 2 additions & 2 deletions target/nanos/script.ld
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*******************************************************************************
* Ledger Blue - Secure firmware
* (c) 2016, 2017, 2018, 2019, 2020 Ledger
* Ledger - Secure firmware
* (c) 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023 Ledger
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
22 changes: 22 additions & 0 deletions target/nanos2/plugin_script.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*******************************************************************************
* Ledger - Secure firmware
* (c) 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023 Ledger
*
* 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.
********************************************************************************/

/* Reuse the main linker script */
INCLUDE script.ld

/* No global variable allowed in plugins */
ASSERT( (_ebss - _bss) <= 0, ".bss section must be empty for plugins" )
6 changes: 4 additions & 2 deletions target/nanos2/script.ld
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*******************************************************************************
* Ledger Blue - Secure firmware
* (c) 2016, 2017, 2018, 2019 Ledger
* Ledger - Secure firmware
* (c) 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023 Ledger
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -94,6 +94,8 @@ SECTIONS

} > DISCARD /*> SRAM AT>FLASH = 0x00 */

ASSERT( (_edata - _data) <= 0, ".data section must be empty" )

.bss :
{
/**
Expand Down
22 changes: 22 additions & 0 deletions target/nanox/plugin_script.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*******************************************************************************
* Ledger - Secure firmware
* (c) 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023 Ledger
*
* 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.
********************************************************************************/

/* Reuse the main linker script */
INCLUDE script.ld

/* No global variable allowed in plugins */
ASSERT( (_ebss - _bss) <= 4, ".bss section must be empty for plugins" )
6 changes: 4 additions & 2 deletions target/nanox/script.ld
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*******************************************************************************
* Ledger Blue - Secure firmware
* (c) 2016, 2017, 2018, 2019 Ledger
* Ledger - Secure firmware
* (c) 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023 Ledger
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -96,6 +96,8 @@ SECTIONS

} > DISCARD /*> SRAM AT>FLASH = 0x00 */

ASSERT( (_edata - _data) <= 0, ".data section must be empty" )

/* The .init_array is initialized with functions with the constructor
* attribute. Discard this section since there's no loader. */
/DISCARD/ : {
Expand Down
Loading

0 comments on commit 11fdad0

Please sign in to comment.