Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions scripts/jlink-bootloader.gdb
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
# Connect to jlink gdb server
target extended-remote :2331

# load the firmware into ROM
load
# It seems more reliable to reset the chip before loading the new firmware. It
# is also how they do it in the example in the wiki:
# https://kb.segger.com/J-Link_GDB_Server#Console

# Reset the CPU
monitor reset

# load the firmware into ROM
load

#break Reset_Handler
#break HardFault_Handler
#break NMI_Handler
Expand Down
8 changes: 6 additions & 2 deletions scripts/jlink.gdb
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
# Connect to jlink gdb server
target extended-remote :2331

# load the firmware into ROM
load
# It seems more reliable to reset the chip before loading the new firmware. It
# is also how they do it in the example in the wiki:
# https://kb.segger.com/J-Link_GDB_Server#Console

# Reset the CPU
monitor reset

# load the firmware into ROM
load

# Set VTOR (Vector Table Offset Register) to where the firmware is located
set *(uint32_t*)0xE000ED08=0x10000
# Set stack pointer to initial stack pointer according to exception table.
Expand Down
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ set(DRIVER-SOURCES
${CMAKE_SOURCE_DIR}/src/platform/driver_init.c
${CMAKE_SOURCE_DIR}/src/ui/oled/oled.c
${CMAKE_SOURCE_DIR}/src/ui/oled/oled_writer.c
${CMAKE_SOURCE_DIR}/src/ui/canvas.c
)
set(DRIVER-SOURCES ${DRIVER-SOURCES} PARENT_SCOPE)

Expand Down
25 changes: 13 additions & 12 deletions src/bootloader/bootloader.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <screen.h>
#include <stdint.h>
#include <string.h>
#include <ui/canvas.h>
#include <ui/components/ui_images.h>
#include <ui/fonts/arial_fonts.h>
#include <ui/graphics/graphics.h>
Expand Down Expand Up @@ -328,15 +329,14 @@ static void _render_message(const char* message, int duration)
{
char print[100];
snprintf(print, sizeof(print), "%s", message);
UG_ClearBuffer();
UG_PutString(0, 0, print, false);
UG_SendBuffer();
canvas_commit();
oled_blit();
delay_ms(duration);
}

void bootloader_render_default_screen(void)
{
UG_ClearBuffer();
_load_logo();
#if PLATFORM_BITBOX02PLUS == 1
UG_PutString(0, SCREEN_HEIGHT - 9 * 2 - 5, "See the BitBoxApp", false);
Expand All @@ -354,7 +354,8 @@ void bootloader_render_default_screen(void)
}
UG_PutString(0, SCREEN_HEIGHT - 9, "See the BitBoxApp", false);
#endif
UG_SendBuffer();
canvas_commit();
oled_blit();
}

#if PLATFORM_BITBOX02PLUS
Expand All @@ -368,7 +369,6 @@ void bootloader_render_ble_confirm_screen(bool confirmed)
uint32_t pairing_code_int = (*(uint32_t*)&bootloader_pairing_code_bytes[0]) % 1000000;
char code_str[10] = {0};
snprintf(code_str, sizeof(code_str), "%06u", (unsigned)pairing_code_int);
UG_ClearBuffer();
uint16_t check_width = IMAGE_DEFAULT_CHECKMARK_HEIGHT + IMAGE_DEFAULT_CHECKMARK_HEIGHT / 2 - 1;
if (confirmed) {
UG_PutString(15, 0, "Confirm on app", false);
Expand All @@ -380,13 +380,13 @@ void bootloader_render_ble_confirm_screen(bool confirmed)
UG_FontSelect(&font_monogram_5X9);
UG_PutString(45, SCREEN_HEIGHT / 2 - 9, code_str, false);
UG_FontSelect(&font_font_a_9X9);
UG_SendBuffer();
canvas_commit();
oled_blit();
}
#endif

static void _render_progress(float progress)
{
UG_ClearBuffer();
_load_logo();
if (progress > 0) {
char label[5] = {0};
Expand All @@ -401,7 +401,8 @@ static void _render_progress(float progress)
msg = "INSTALLING";
}
UG_PutString(SCREEN_WIDTH / 2 - 3, SCREEN_HEIGHT - 9 * 2, msg, false);
UG_SendBuffer();
canvas_commit();
oled_blit();
}

static void _render_hash(const char* title, const uint8_t* hash)
Expand Down Expand Up @@ -433,7 +434,6 @@ static void _render_hash(const char* title, const uint8_t* hash)
&hash_hex[48]);

for (uint8_t i = 1; i <= seconds; i++) {
UG_ClearBuffer();
UG_PutString(0, 0, title, false);

snprintf(timer_buf, sizeof(timer_buf), "%ds", seconds - i);
Expand All @@ -449,7 +449,8 @@ static void _render_hash(const char* title, const uint8_t* hash)

UG_FontSelect(f_regular);

UG_SendBuffer();
canvas_commit();
oled_blit();
delay_ms(1000);
}
bootloader_render_default_screen();
Expand Down Expand Up @@ -1013,7 +1014,6 @@ static void _check_init(boot_data_t* data)
#ifdef BOOTLOADER_DEVDEVICE
static bool _devdevice_enter(secbool_u32 firmware_verified)
{
UG_ClearBuffer();
UG_PutString(0, 0, " <Enter bootloader>", false);
UG_PutString(0, SCREEN_HEIGHT / 2 - 11, "DEV DEVICE", false);
UG_PutString(0, SCREEN_HEIGHT / 2 + 2, "NOT FOR VALUE", false);
Expand Down Expand Up @@ -1043,7 +1043,8 @@ static bool _devdevice_enter(secbool_u32 firmware_verified)
UG_DrawLine(xpos + 5, ypos, xpos, ypos + 5, C_WHITE);
UG_DrawLine(xpos - 2, ypos + 3, xpos, ypos + 5, C_WHITE);
}
UG_SendBuffer();
canvas_commit();
oled_blit();
while (true) {
do {
qtouch_process();
Expand Down
7 changes: 4 additions & 3 deletions src/bootloader/startup.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <rust/rust.h>
#include <screen.h>
#include <string.h>
#include <ui/canvas.h>
#include <ui/oled/oled.h>
#include <usb/class/hid/hww/hid_hww.h>
#include <usb/usb_processing.h>
Expand Down Expand Up @@ -83,7 +84,7 @@ int main(void)
bootloader_init();
platform_init();
__stack_chk_guard = rand_sync_read32(&RAND_0);
screen_init(oled_set_pixel, oled_mirror, oled_clear_buffer);
screen_init(oled_set_pixel, oled_mirror);
#if defined(BOOTLOADER_DEVDEVICE) || PLATFORM_BITBOX02PLUS == 1
qtouch_init();
#endif
Expand Down Expand Up @@ -189,7 +190,6 @@ int main(void)

if (qtouch_is_scroller_active(top_slider)) {
bool ok;
UG_ClearBuffer();
if (qtouch_get_scroller_position(top_slider) < 127) {
bootloader_render_default_screen();
ok = false;
Expand Down Expand Up @@ -218,7 +218,8 @@ int main(void)
ringbuffer_put(&uart_write_queue, tmp[i]);
}
bootloader_pairing_request = false;
UG_SendBuffer();
canvas_commit();
oled_blit();
}
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/factorysetup.c
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ int main(void)
system_init();
platform_init();
__stack_chk_guard = common_stack_chk_guard();
screen_init(oled_set_pixel, oled_mirror, oled_clear_buffer);
screen_init(oled_set_pixel, oled_mirror);
screen_splash();
common_main();

Expand Down
2 changes: 1 addition & 1 deletion src/firmware.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ int main(void)
system_init();
platform_init();
__stack_chk_guard = common_stack_chk_guard();
screen_init(oled_set_pixel, oled_mirror, oled_clear_buffer);
screen_init(oled_set_pixel, oled_mirror);
screen_splash();
qtouch_init();
common_main();
Expand Down
7 changes: 5 additions & 2 deletions src/reset.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@
#include "system.h"
#include "uart.h"
#include <screen.h>
#include <ui/canvas.h>

#ifndef TESTING
#include "securechip/securechip.h"
#include <driver_init.h>
#include <hal_delay.h>
#include <ui/components/status.h>
#include <ui/oled/oled.h>
#include <ui/ugui/ugui.h>
#endif

Expand All @@ -41,9 +43,10 @@ static void _show_reset_label(bool status)
{
const char* msg = "Device reset";
component_t* comp = status_create(msg, status, NULL, NULL);
screen_clear();
canvas_clear();
comp->f->render(comp);
UG_SendBuffer();
canvas_commit();
oled_blit();
comp->f->cleanup(comp);
delay_ms(3000);
}
Expand Down
7 changes: 4 additions & 3 deletions src/rust/bitbox02-rust/src/general/screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@

use core::time::Duration;

use bitbox02::{delay, ug_clear_buffer, ug_font_select_9x9, ug_put_string, ug_send_buffer};
use bitbox02::{canvas_clear, canvas_commit, delay, oled_blit, ug_font_select_9x9, ug_put_string};

pub fn print_debug_internal(duration: Duration, msg: &str) {
ug_clear_buffer();
canvas_clear();
ug_font_select_9x9();
ug_put_string(0, 0, msg, false);
ug_send_buffer();
canvas_commit();
oled_blit();
delay(duration);
}

Expand Down
7 changes: 5 additions & 2 deletions src/rust/bitbox02-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ const ALLOWLIST_TYPES: &[&str] = &[
];

const ALLOWLIST_FNS: &[&str] = &[
"UG_ClearBuffer",
"UG_FontSelect",
"UG_PutString",
"UG_SendBuffer",
"bip32_derive_xpub",
"bitbox02_smarteeprom_init",
"bitbox_secp256k1_dleq_prove",
"bitbox_secp256k1_dleq_verify",
"canvas_clear",
"canvas_commit",
"confirm_create",
"confirm_transaction_address_create",
"confirm_transaction_fee_create",
Expand Down Expand Up @@ -114,6 +114,7 @@ const ALLOWLIST_FNS: &[&str] = &[
"memory_get_platform",
"memory_get_securechip_type",
"memory_spi_get_active_ble_firmware_version",
"oled_blit",
"spi_mem_protected_area_write",
"menu_create",
"fake_memory_factoryreset",
Expand Down Expand Up @@ -199,6 +200,7 @@ const BITBOX02_SOURCES: &[&str] = &[
"src/u2f.c",
"src/u2f/u2f_app.c",
"src/u2f/u2f_packet.c",
"src/ui/canvas.c",
"src/ui/components/button.c",
"src/ui/components/confirm_gesture.c",
"src/ui/components/confirm_transaction.c",
Expand Down Expand Up @@ -402,6 +404,7 @@ pub fn main() -> Result<(), &'static str> {
"test/hardware-fakes/src/fake_component.c",
"test/hardware-fakes/src/fake_diskio.c",
"test/hardware-fakes/src/fake_memory.c",
"test/hardware-fakes/src/fake_oled.c",
"test/hardware-fakes/src/fake_qtouch.c",
"test/hardware-fakes/src/fake_screen.c",
"test/hardware-fakes/src/fake_securechip.c",
Expand Down
1 change: 1 addition & 0 deletions src/rust/bitbox02-sys/wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <securechip/securechip.h>
#include <system.h>
#include <time.h>
#include <ui/canvas.h>
#include <ui/components/confirm.h>
#include <ui/components/confirm_transaction.h>
#include <ui/components/empty.h>
Expand Down
12 changes: 8 additions & 4 deletions src/rust/bitbox02/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,16 @@ pub fn ug_put_string(x: i16, y: i16, input: &str, inverted: bool) {
}
}

pub fn ug_clear_buffer() {
unsafe { bitbox02_sys::UG_ClearBuffer() }
pub fn canvas_clear() {
unsafe { bitbox02_sys::canvas_clear() }
}

pub fn ug_send_buffer() {
unsafe { bitbox02_sys::UG_SendBuffer() }
pub fn canvas_commit() {
unsafe { bitbox02_sys::canvas_commit() }
}

pub fn oled_blit() {
unsafe { bitbox02_sys::oled_blit() }
}

pub fn ug_font_select_9x9() {
Expand Down
25 changes: 7 additions & 18 deletions src/screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include <ui/canvas.h>
#include <ui/components/ui_images.h>
#include <ui/fonts/arial_fonts.h>
#include <ui/oled/oled.h>
Expand All @@ -32,7 +33,6 @@
static UG_GUI guioled; // Global GUI structure for OLED screen
static bool screen_upside_down = false;
static void (*_mirror_fn)(bool);
static void (*_clear_fn)(void);

UG_COLOR screen_front_color = C_WHITE;
UG_COLOR screen_back_color = C_BLACK;
Expand All @@ -45,10 +45,11 @@ void screen_print_debug(const char* message, int duration)
{
char print[100];
snprintf(print, sizeof(print), "%s", message);
screen_clear();
canvas_clear();
UG_FontSelect(&font_font_a_9X9);
UG_PutString(0, 0, print, false);
UG_SendBuffer();
canvas_commit();
oled_blit();
#ifndef TESTING
if (duration > 0) delay_ms(duration);
#endif
Expand Down Expand Up @@ -79,16 +80,14 @@ void screen_print_debug_hex(const uint8_t* bytes, size_t len, int duration)
// Careful, this function is used in both the bootloader and the firmware.
void screen_splash(void)
{
screen_clear();

int height = IMAGE_DEFAULT_ARROW_HEIGHT;
int x = 0;
int y = SCREEN_HEIGHT / 2 - height;
image_arrow(x - height + 2, y, height, ARROW_RIGHT);
image_arrow(SCREEN_WIDTH - x - 2, y, height, ARROW_LEFT);

UG_SendBuffer();
screen_clear();
canvas_commit();
oled_blit();
}

void screen_rotate(void)
Expand All @@ -105,18 +104,8 @@ bool screen_is_upside_down(void)
return screen_upside_down;
}

void screen_init(
void (*pixel_fn)(UG_S16, UG_S16, UG_COLOR),
void (*mirror_fn)(bool),
void (*clear_fn)(void))
void screen_init(void (*pixel_fn)(UG_S16, UG_S16, UG_COLOR), void (*mirror_fn)(bool))
{
_mirror_fn = mirror_fn;
_clear_fn = clear_fn;
UG_Init(&guioled, pixel_fn, &font_font_a_11X10, SCREEN_WIDTH, SCREEN_HEIGHT);
}

void screen_clear(void)
{
ASSERT(_clear_fn);
_clear_fn();
}
Loading