1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-24 15:28:10 +00:00

bootloader: first UI steps

This commit is contained in:
Pavol Rusnak 2017-10-16 18:03:04 +02:00
parent 0e2a1da99b
commit 2010213338
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
4 changed files with 30 additions and 19 deletions

View File

@ -178,3 +178,6 @@ combine: ## combine boardloader + bootloader + firmware into one combined image
$(BOOTLOADER_START) $(BOOTLOADER_BUILD_DIR)/bootloader.bin \
$(FIRMWARE_START) $(FIRMWARE_BUILD_DIR)/firmware.bin \
> $(FIRMWARE_BUILD_DIR)/combined.bin \
upload: ## upload firmware using trezorctl
trezorctl firmware_update -f $(FIRMWARE_BUILD_DIR)/firmware.bin

View File

@ -66,10 +66,6 @@ static const uint8_t * const BOOTLOADER_KEYS[] = {
#endif
};
void check_and_jump(void)
{
}
int usb_init_all(void) {
static const usb_dev_info_t dev_info = {
.vendor_id = 0x1209,
@ -124,6 +120,8 @@ void bootloader_loop(void)
ensure(0 == usb_init_all(), NULL);
display_clear();
display_text_center(120, 30, "TREZOR Bootloader", -1, FONT_BOLD, COLOR_WHITE, COLOR_BLACK);
display_fade(0, BACKLIGHT_NORMAL, 1000);
uint8_t buf[USB_PACKET_SIZE];
@ -147,10 +145,19 @@ void bootloader_loop(void)
process_msg_Ping(USB_IFACE_NUM, msg_size, buf);
break;
case 6: // FirmwareErase
display_text_center(120, 230, "Updating firmware", -1, FONT_BOLD, COLOR_WHITE, COLOR_BLACK);
process_msg_FirmwareErase(USB_IFACE_NUM, msg_size, buf);
break;
case 7: // FirmwareUpload
process_msg_FirmwareUpload(USB_IFACE_NUM, msg_size, buf);
r = process_msg_FirmwareUpload(USB_IFACE_NUM, msg_size, buf);
if (r < 0) { // error
display_clear();
display_text_center(120, 230, "Error", -1, FONT_BOLD, COLOR_WHITE, COLOR_BLACK);
} else
if (r == 0) { // last chunk received
display_clear();
display_text_center(120, 230, "Done", -1, FONT_BOLD, COLOR_WHITE, COLOR_BLACK);
}
break;
default:
process_msg_unknown(USB_IFACE_NUM, msg_size, buf);
@ -201,7 +208,8 @@ int main(void)
touched |= touch_read();
}
if (touched != 0) {
// start the bootloader if user touched the screen or no firmware installed
if (touched != 0 || !vendor_parse_header((const uint8_t *)FIRMWARE_START, NULL)) {
bootloader_loop();
shutdown();
}

View File

@ -1,5 +1,6 @@
#include <string.h>
#include <pb.h>
#include <pb_decode.h>
#include <pb_encode.h>
#include "messages.pb.h"
@ -7,11 +8,17 @@
#include "common.h"
#include "display.h"
#include "flash.h"
#include "image.h"
#include "usb.h"
#include "version.h"
#include "messages.h"
#define FIRMWARE_CHUNK_SIZE (128 * 1024)
#define MSG_HEADER1_LEN 9
#define MSG_HEADER2_LEN 1
bool msg_parse_header(const uint8_t *buf, uint16_t *msg_id, uint32_t *msg_size)
{
if (buf[0] != '?' || buf[1] != '#' || buf[2] != '#') {
@ -204,8 +211,8 @@ void process_msg_Initialize(uint8_t iface_num, uint32_t msg_size, uint8_t *buf)
MSG_SEND_ASSIGN_VALUE(minor_version, VERSION_MINOR);
MSG_SEND_ASSIGN_VALUE(patch_version, VERSION_PATCH);
MSG_SEND_ASSIGN_VALUE(bootloader_mode, true);
// TODO: properly detect firmware
MSG_SEND_ASSIGN_VALUE(firmware_present, false);
bool firmware_present = vendor_parse_header((const uint8_t *)FIRMWARE_START, NULL);
MSG_SEND_ASSIGN_VALUE(firmware_present, firmware_present);
MSG_SEND(Features);
}
@ -286,14 +293,14 @@ static bool _read_payload(pb_istream_t *stream, const pb_field_t *field, void **
return true;
}
void process_msg_FirmwareUpload(uint8_t iface_num, uint32_t msg_size, uint8_t *buf)
int process_msg_FirmwareUpload(uint8_t iface_num, uint32_t msg_size, uint8_t *buf)
{
if (!flash_unlock()) {
MSG_SEND_INIT(Failure);
MSG_SEND_ASSIGN_VALUE(code, FailureType_Failure_ProcessError);
MSG_SEND_ASSIGN_STRING(message, "Could not unlock flash");
MSG_SEND(Failure);
return;
return -1;
}
MSG_RECV_INIT(FirmwareUpload);
@ -318,10 +325,10 @@ void process_msg_FirmwareUpload(uint8_t iface_num, uint32_t msg_size, uint8_t *b
MSG_SEND_ASSIGN_VALUE(length, chunk_requested);
MSG_SEND(FirmwareRequest);
} else {
display_clear();
MSG_SEND_INIT(Success);
MSG_SEND(Success);
}
return (int)firmware_remaining;
}
void process_msg_unknown(uint8_t iface_num, uint32_t msg_size, uint8_t *buf)

View File

@ -4,22 +4,15 @@
#include <stdint.h>
#include <stdbool.h>
#include <pb.h>
#define MSG_HEADER1_LEN 9
#define MSG_HEADER2_LEN 1
#define USB_PACKET_SIZE 64
#define USB_IFACE_NUM 0
#define FIRMWARE_CHUNK_SIZE (128*1024)
bool msg_parse_header(const uint8_t *buf, uint16_t *msg_id, uint32_t *msg_size);
void process_msg_Initialize(uint8_t iface_num, uint32_t msg_size, uint8_t *buf);
void process_msg_Ping(uint8_t iface_num, uint32_t msg_size, uint8_t *buf);
void process_msg_FirmwareErase(uint8_t iface_num, uint32_t msg_size, uint8_t *buf);
void process_msg_FirmwareUpload(uint8_t iface_num, uint32_t msg_size, uint8_t *buf);
int process_msg_FirmwareUpload(uint8_t iface_num, uint32_t msg_size, uint8_t *buf);
void process_msg_unknown(uint8_t iface_num, uint32_t msg_size, uint8_t *buf);
#endif