Skip to content

Commit

Permalink
Merge pull request #651 from LedgerHQ/xch/nbgl-on-lns
Browse files Browse the repository at this point in the history
API_LEVEL_LNS: Add support for NBGL on LNS
  • Loading branch information
xchapron-ledger authored May 14, 2024
2 parents d1d68f2 + 68c1e17 commit 611ba9b
Show file tree
Hide file tree
Showing 26 changed files with 3,589 additions and 453 deletions.
47 changes: 16 additions & 31 deletions Makefile.defines
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#*******************************************************************************
# Ledger SDK
# (c) 2017 Ledger
# (c) 2024 Ledger
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -15,22 +15,10 @@
# limitations under the License.
#*******************************************************************************

#extract TARGET_NAME/TARGET_ID from the SDK to allow for makefile choices
TARGET := nanos
TARGET_ID:=$(shell cat $(BOLOS_SDK)/include/bolos_target.h | grep TARGET_ID | cut -f3 -d' ')
TARGET_NAME:=$(shell cat $(BOLOS_SDK)/include/bolos_target.h | grep TARGET_ | grep -v TARGET_ID | cut -f2 -d' ')
TARGET_VERSION:=$(shell cat $(BOLOS_SDK)/include/bolos_version.h | grep define | cut -f2 -d'"')
SDK_NAME := "nanos-secure-sdk"
SDK_VERSION := $(shell git -C $(BOLOS_SDK) describe --tags --exact-match --match "v[0-9]*" --dirty)
SDK_HASH := $(shell git -C $(BOLOS_SDK) describe --always --dirty --exclude '*' --abbrev=40)
ifeq ($(SDK_VERSION),)
SDK_VERSION := "None"
endif
ifeq ($(SDK_HASH),)
SDK_HASH := "None"
endif
ifeq ($(__MAKEFILE_DEFINES__),)
__MAKEFILE_DEFINES__ := 1

$(info TARGET_NAME=$(TARGET_NAME) TARGET_ID=$(TARGET_ID) TARGET_VERSION=$(TARGET_VERSION))
include $(BOLOS_SDK)/Makefile.target

# APPNAME exposed to the app as a CFLAG because it might contain spaces
CFLAGS += -DAPPNAME=\"$(APPNAME)\"
Expand All @@ -41,23 +29,12 @@ APP_METADATA_LIST := TARGET TARGET_NAME APPVERSION SDK_NAME SDK_VERSION SDK_HASH
DEFINES += $(foreach item,$(APP_METADATA_LIST), $(item)=\"$($(item))\")
DEFINES += TARGET_VERSION=$(TARGET_VERSION)

BUILD_DIR := build
TARGET_BUILD_DIR := $(BUILD_DIR)/$(TARGET)
BIN_DIR := $(TARGET_BUILD_DIR)/bin
OBJ_DIR := $(TARGET_BUILD_DIR)/obj
DBG_DIR := $(TARGET_BUILD_DIR)/dbg
DEP_DIR := $(TARGET_BUILD_DIR)/dep
GEN_SRC_DIR := $(TARGET_BUILD_DIR)/gen_src

### platform definitions
DEFINES += gcc __IO=volatile

# no assert by default
DEFINES += NDEBUG

# Debug mode disabled by default
DEBUG:=0

# default is not to display make commands
log = $(if $(strip $(VERBOSE)),$1,@$1) # kept for retrocompat
L = $(if $(strip $(VERBOSE)),,@)
Expand Down Expand Up @@ -133,12 +110,18 @@ else
LDFLAGS += -nostartfiles
endif

DISABLE_UI ?= 0
ifeq ($(DISABLE_UI), 0)
# For LNS devices, by default NBGL is not used
USE_NBGL ?= 0

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

ifeq ($(USE_NBGL),0)
DEFINES += HAVE_BAGL
else
DEFINES += HAVE_NBGL
DEFINES += NBGL_USE_CASE
endif # USE_NBGL
endif

ifeq ($(TARGET_NAME),TARGET_NANOX)
Expand Down Expand Up @@ -173,3 +156,5 @@ endif

# define the default makefile target (high in include to avoid glyph.h or what not specific target to be the default one when no target passed on the make command line)
all: default

endif
8 changes: 4 additions & 4 deletions Makefile.rules
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
#*******************************************************************************

# temporary redef, to ensure wider compliance of the SDK with pre-1.6 apps
ifeq ($(DISABLE_UI),0)
ifeq ($(TARGET_NAME),$(filter $(TARGET_NAME),TARGET_NANOS TARGET_NANOX TARGET_NANOS2))
SDK_SOURCE_PATH += lib_bagl lib_ux
endif
ifeq ($(USE_NBGL),0)
SDK_SOURCE_PATH += lib_bagl lib_ux
else
SDK_SOURCE_PATH += lib_nbgl lib_ux_nbgl lib_ux_sync
endif

define uniq =
Expand Down
76 changes: 52 additions & 24 deletions Makefile.standard_app
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
# limitations under the License.
#*******************************************************************************

include $(BOLOS_SDK)/Makefile.target

#####################################################################
# BLUETOOTH #
#####################################################################
ifeq ($(ENABLE_BLUETOOTH), 1)
ifeq ($(TARGET_NAME),$(filter $(TARGET_NAME),TARGET_NANOX TARGET_STAX))
ifeq ($(TARGET_NAME),$(filter $(TARGET_NAME),TARGET_NANOX TARGET_STAX TARGET_FLEX))
HAVE_APPLICATION_FLAG_BOLOS_SETTINGS = 1
DEFINES += HAVE_BLE BLE_COMMAND_TIMEOUT_MS=2000 HAVE_BLE_APDU
DEFINES += BLE_SEGMENT_SIZE=32
Expand All @@ -31,10 +33,9 @@ endif
# NFC #
#####################################################################
ifeq ($(ENABLE_NFC), 1)
ifeq ($(TARGET_NAME),$(filter $(TARGET_NAME), TARGET_STAX))
STANDARD_APP_FLAGS = 0x200 # APPLICATION_FLAG_BOLOS_SETTINGS
ifeq ($(TARGET_NAME),$(filter $(TARGET_NAME), TARGET_STAX TARGET_FLEX))
HAVE_APPLICATION_FLAG_BOLOS_SETTINGS = 1
DEFINES += HAVE_NFC
SDK_SOURCE_PATH += lib_nfc
endif
endif

Expand Down Expand Up @@ -78,6 +79,38 @@ ifneq ($(DISABLE_DEFAULT_IO_SEPROXY_BUFFER_SIZE), 1)
endif
endif

#####################################################################
# NBGL #
#####################################################################
ifeq ($(TARGET_NAME),$(filter $(TARGET_NAME),TARGET_NANOS TARGET_NANOX TARGET_NANOS2))
ifeq ($(ENABLE_NBGL_FOR_NANO_DEVICES), 1)
USE_NBGL = 1
else
USE_NBGL = 0
endif
else
USE_NBGL = 1
endif

ifeq ($(ENABLE_NBGL_QRCODE), 1)
ifeq ($(TARGET_NAME),$(filter $(TARGET_NAME),TARGET_STAX TARGET_FLEX))
DEFINES += NBGL_QRCODE
SDK_SOURCE_PATH += qrcode
endif
endif

ifeq ($(ENABLE_NBGL_KEYBOARD), 1)
ifeq ($(TARGET_NAME),$(filter $(TARGET_NAME),TARGET_STAX TARGET_FLEX))
DEFINES += NBGL_KEYBOARD
endif
endif

ifeq ($(ENABLE_NBGL_KEYPAD), 1)
ifeq ($(TARGET_NAME),$(filter $(TARGET_NAME),TARGET_STAX TARGET_FLEX))
DEFINES += NBGL_KEYPAD
endif
endif

#####################################################################
# STANDARD DEFINES #
#####################################################################
Expand Down Expand Up @@ -111,7 +144,7 @@ ifneq ($(DISABLE_STANDARD_WEBUSB), 1)
endif

ifneq ($(DISABLE_STANDARD_BAGL_UX_FLOW), 1)
ifneq ($(TARGET_NAME), TARGET_STAX)
ifneq ($(USE_NBGL), 1)
DEFINES += HAVE_UX_FLOW
endif
endif
Expand All @@ -124,25 +157,15 @@ ifneq ($(DISABLE_STANDARD_APP_FILES), 1)
SDK_SOURCE_PATH += lib_standard_app
endif

#####################################################################
# NBGL #
#####################################################################
ifeq ($(ENABLE_NBGL_QRCODE), 1)
ifeq ($(TARGET_NAME), TARGET_STAX)
DEFINES += NBGL_QRCODE
SDK_SOURCE_PATH += qrcode
endif
endif

ifeq ($(ENABLE_NBGL_KEYBOARD), 1)
ifeq ($(TARGET_NAME), TARGET_STAX)
DEFINES += NBGL_KEYBOARD
endif
ifneq ($(DISABLE_STANDARD_APP_SYNC_RAPDU), 1)
# On LNS only activate it by default if using NBGL.
# This impact stack usage and shouldn't be activated on all apps silently
ifneq ($(TARGET_NAME),TARGET_NANOS)
DEFINES += STANDARD_APP_SYNC_RAPDU
else
ifeq ($(ENABLE_NBGL_FOR_NANO_DEVICES), 1)
DEFINES += STANDARD_APP_SYNC_RAPDU
endif

ifeq ($(ENABLE_NBGL_KEYPAD), 1)
ifeq ($(TARGET_NAME), TARGET_STAX)
DEFINES += NBGL_KEYPAD
endif
endif

Expand Down Expand Up @@ -200,9 +223,14 @@ endif
ifeq ($(TARGET_NAME), TARGET_NANOS2)
ICONNAME ?= $(ICON_NANOSP)
endif
ifeq ($(TARGET_NAME),TARGET_STAX)
ifeq ($(TARGET_NAME), TARGET_STAX)
ICONNAME ?= $(ICON_STAX)
endif
ifeq ($(TARGET_NAME), TARGET_FLEX)
ICONNAME ?= $(ICON_FLEX)
endif

include $(BOLOS_SDK)/Makefile.defines

include $(BOLOS_SDK)/Makefile.glyphs

Expand Down
52 changes: 52 additions & 0 deletions Makefile.target
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#*******************************************************************************
# Ledger SDK
# (c) 2024 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.
#*******************************************************************************

ifeq ($(__MAKEFILE_TARGET__),)
__MAKEFILE_TARGET__ := 1

#extract TARGET_NAME/TARGET_ID from the SDK to allow for makefile choices
TARGET := nanos
TARGET_ID:=$(shell cat $(BOLOS_SDK)/include/bolos_target.h | grep TARGET_ID | cut -f3 -d' ')
TARGET_NAME:=$(shell cat $(BOLOS_SDK)/include/bolos_target.h | grep TARGET_ | grep -v TARGET_ID | cut -f2 -d' ')
TARGET_VERSION:=$(shell cat $(BOLOS_SDK)/include/bolos_version.h | grep define | cut -f2 -d'"')
SDK_NAME := "nanos-secure-sdk"
SDK_VERSION := $(shell git -C $(BOLOS_SDK) describe --tags --exact-match --match "v[0-9]*" --dirty)
SDK_HASH := $(shell git -C $(BOLOS_SDK) describe --always --dirty --exclude '*' --abbrev=40)
ifeq ($(SDK_VERSION),)
SDK_VERSION := "None"
endif
ifeq ($(SDK_HASH),)
SDK_HASH := "None"
endif

$(info TARGET_NAME=$(TARGET_NAME) TARGET_ID=$(TARGET_ID) TARGET_VERSION=$(TARGET_VERSION))

BUILD_DIR := build
TARGET_BUILD_DIR := $(BUILD_DIR)/$(TARGET)
BIN_DIR := $(TARGET_BUILD_DIR)/bin
OBJ_DIR := $(TARGET_BUILD_DIR)/obj
DBG_DIR := $(TARGET_BUILD_DIR)/dbg
DEP_DIR := $(TARGET_BUILD_DIR)/dep
GEN_SRC_DIR := $(TARGET_BUILD_DIR)/gen_src

# Debug mode disabled by default
DEBUG:=0

# define the default makefile target (high in include to avoid glyph.h or what not specific target to be the default one when no target passed on the make command line)
all: default

endif
8 changes: 4 additions & 4 deletions icon3.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,20 +206,20 @@ def main():
print("};")

if args.glyphcheader:
print("""#ifdef HAVE_BAGL
print("""#if defined(HAVE_BAGL) || defined(HAVE_NBGL)
#include \"bagl.h\"
extern const bagl_icon_details_t C_{0};
#endif // GLYPH_{0}_BPP
#endif // HAVE_BAGL""".format(image_name))
#endif // HAVE_BAGL || HAVE_NBGL""".format(image_name))
elif args.glyphcfile:
color_ref = image_name
if args.factorize:
if color_array_serialized in colors_array:
color_ref = colors_array[color_array_serialized]
print("""#ifdef HAVE_BAGL
print("""#if defined(HAVE_BAGL) || defined(HAVE_NBGL)
#include \"bagl.h\"
const bagl_icon_details_t C_{0} = {{ GLYPH_{0}_WIDTH, GLYPH_{0}_HEIGHT, {1}, C_{2}_colors, C_{0}_bitmap }};
#endif // HAVE_BAGL""".format(image_name, int(math.log(num_colors, 2)), color_ref))
#endif // HAVE_BAGL || HAVE_NBGL""".format(image_name, int(math.log(num_colors, 2)), color_ref))
else:
# Origin 0,0 is left top for blue, instead of left bottom for all image encodings
print("{{ {0:d}, {1:d}, {2:d}, C_{3}_colors, C_{3}_bitmap }},".format(
Expand Down
3 changes: 2 additions & 1 deletion include/os_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ extern unsigned char G_io_apdu_buffer[IO_APDU_BUFFER_SIZE];
#define IO_RETURN_AFTER_TX 0x20
#define IO_ASYNCH_REPLY 0x10 // avoid apdu state reset if tx_len == 0 when we're expected to reply
#define IO_FINISHED 0x08 // inter task communication value
#define IO_FLAGS 0xF8
#define IO_CONTINUE_RX 0x04
#define IO_FLAGS 0xFC
unsigned short io_exchange(unsigned char channel_and_flags, unsigned short tx_len);

typedef enum {
Expand Down
26 changes: 26 additions & 0 deletions include/ux.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

/*****************************************************************************
* (c) 2024 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.
*****************************************************************************/

#pragma once

#ifdef HAVE_BAGL
#include "ux_bagl.h"
#endif

#ifdef HAVE_NBGL
#include "ux_nbgl.h"
#endif
Loading

0 comments on commit 611ba9b

Please sign in to comment.