mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-14 03:30:02 +00:00
bootloader: use webusb by default
This commit is contained in:
parent
c627fcb836
commit
e865012663
@ -46,7 +46,6 @@ static void usb_init_all(void) {
|
||||
|
||||
static uint8_t rx_buffer[USB_PACKET_SIZE];
|
||||
|
||||
#if USE_WEBUSB
|
||||
static const usb_webusb_info_t webusb_info = {
|
||||
.iface_num = USB_IFACE_NUM,
|
||||
.ep_in = USB_EP_DIR_IN | 0x01,
|
||||
@ -57,46 +56,10 @@ static void usb_init_all(void) {
|
||||
.rx_buffer = rx_buffer,
|
||||
.polling_interval = 1,
|
||||
};
|
||||
#else
|
||||
static const uint8_t hid_report_desc[] = {
|
||||
0x06, 0x00, 0xff, // USAGE_PAGE (Vendor Defined)
|
||||
0x09, 0x01, // USAGE (1)
|
||||
0xa1, 0x01, // COLLECTION (Application)
|
||||
0x09, 0x20, // USAGE (Input Report Data)
|
||||
0x15, 0x00, // LOGICAL_MINIMUM (0)
|
||||
0x26, 0xff, 0x00, // LOGICAL_MAXIMUM (255)
|
||||
0x75, 0x08, // REPORT_SIZE (8)
|
||||
0x95, 0x40, // REPORT_COUNT (64)
|
||||
0x81, 0x02, // INPUT (Data,Var,Abs)
|
||||
0x09, 0x21, // USAGE (Output Report Data)
|
||||
0x15, 0x00, // LOGICAL_MINIMUM (0)
|
||||
0x26, 0xff, 0x00, // LOGICAL_MAXIMUM (255)
|
||||
0x75, 0x08, // REPORT_SIZE (8)
|
||||
0x95, 0x40, // REPORT_COUNT (64)
|
||||
0x91, 0x02, // OUTPUT (Data,Var,Abs)
|
||||
0xc0 // END_COLLECTION
|
||||
};
|
||||
static const usb_hid_info_t hid_info = {
|
||||
.iface_num = USB_IFACE_NUM,
|
||||
.ep_in = USB_EP_DIR_IN | 0x01,
|
||||
.ep_out = USB_EP_DIR_OUT | 0x01,
|
||||
.subclass = 0,
|
||||
.protocol = 0,
|
||||
.max_packet_len = sizeof(rx_buffer),
|
||||
.rx_buffer = rx_buffer,
|
||||
.polling_interval = 1,
|
||||
.report_desc_len = sizeof(hid_report_desc),
|
||||
.report_desc = hid_report_desc,
|
||||
};
|
||||
#endif
|
||||
|
||||
usb_init(&dev_info);
|
||||
|
||||
#if USE_WEBUSB
|
||||
ensure(usb_webusb_add(&webusb_info), NULL);
|
||||
#else
|
||||
ensure(usb_hid_add(&hid_info), NULL);
|
||||
#endif
|
||||
|
||||
usb_start();
|
||||
}
|
||||
@ -108,11 +71,7 @@ static secbool bootloader_usb_loop(const vendor_header * const vhdr, const image
|
||||
uint8_t buf[USB_PACKET_SIZE];
|
||||
|
||||
for (;;) {
|
||||
#if USE_WEBUSB
|
||||
int r = usb_webusb_read_blocking(USB_IFACE_NUM, buf, USB_PACKET_SIZE, USB_TIMEOUT);
|
||||
#else
|
||||
int r = usb_hid_read_blocking(USB_IFACE_NUM, buf, USB_PACKET_SIZE, USB_TIMEOUT);
|
||||
#endif
|
||||
if (r != USB_PACKET_SIZE) {
|
||||
continue;
|
||||
}
|
||||
|
@ -73,11 +73,7 @@ static bool _usb_write(pb_ostream_t *stream, const pb_byte_t *buf, size_t count)
|
||||
memcpy(state->buf + state->packet_pos, buf + written, USB_PACKET_SIZE - state->packet_pos);
|
||||
written += USB_PACKET_SIZE - state->packet_pos;
|
||||
// send packet
|
||||
#if USE_WEBUSB
|
||||
int r = usb_webusb_write_blocking(state->iface_num, state->buf, USB_PACKET_SIZE, USB_TIMEOUT);
|
||||
#else
|
||||
int r = usb_hid_write_blocking(state->iface_num, state->buf, USB_PACKET_SIZE, USB_TIMEOUT);
|
||||
#endif
|
||||
ensure(sectrue * (r == USB_PACKET_SIZE), NULL);
|
||||
// prepare new packet
|
||||
state->packet_index++;
|
||||
@ -98,11 +94,7 @@ static void _usb_write_flush(usb_write_state *state)
|
||||
memset(state->buf + state->packet_pos, 0, USB_PACKET_SIZE - state->packet_pos);
|
||||
}
|
||||
// send packet
|
||||
#if USE_WEBUSB
|
||||
int r = usb_webusb_write_blocking(state->iface_num, state->buf, USB_PACKET_SIZE, USB_TIMEOUT);
|
||||
#else
|
||||
int r = usb_hid_write_blocking(state->iface_num, state->buf, USB_PACKET_SIZE, USB_TIMEOUT);
|
||||
#endif
|
||||
ensure(sectrue * (r == USB_PACKET_SIZE), NULL);
|
||||
}
|
||||
|
||||
@ -182,11 +174,7 @@ static bool _usb_read(pb_istream_t *stream, uint8_t *buf, size_t count)
|
||||
memcpy(buf + read, state->buf + state->packet_pos, USB_PACKET_SIZE - state->packet_pos);
|
||||
read += USB_PACKET_SIZE - state->packet_pos;
|
||||
// read next packet
|
||||
#if USE_WEBUSB
|
||||
int r = usb_webusb_read_blocking(state->iface_num, state->buf, USB_PACKET_SIZE, USB_TIMEOUT);
|
||||
#else
|
||||
int r = usb_hid_read_blocking(state->iface_num, state->buf, USB_PACKET_SIZE, USB_TIMEOUT);
|
||||
#endif
|
||||
ensure(sectrue * (r == USB_PACKET_SIZE), NULL);
|
||||
// prepare next packet
|
||||
state->packet_index++;
|
||||
@ -540,11 +528,7 @@ void process_msg_unknown(uint8_t iface_num, uint32_t msg_size, uint8_t *buf)
|
||||
// consume remaining message
|
||||
int remaining_chunks = (msg_size - (USB_PACKET_SIZE - MSG_HEADER1_LEN)) / (USB_PACKET_SIZE - MSG_HEADER2_LEN);
|
||||
for (int i = 0; i < remaining_chunks; i++) {
|
||||
#if USE_WEBUSB
|
||||
int r = usb_webusb_read_blocking(USB_IFACE_NUM, buf, USB_PACKET_SIZE, USB_TIMEOUT);
|
||||
#else
|
||||
int r = usb_hid_read_blocking(USB_IFACE_NUM, buf, USB_PACKET_SIZE, USB_TIMEOUT);
|
||||
#endif
|
||||
ensure(sectrue * (r == USB_PACKET_SIZE), NULL);
|
||||
}
|
||||
|
||||
|
@ -5,8 +5,6 @@
|
||||
#include "image.h"
|
||||
#include "secbool.h"
|
||||
|
||||
#define USE_WEBUSB 1
|
||||
|
||||
#define USB_TIMEOUT 100
|
||||
#define USB_PACKET_SIZE 64
|
||||
#define USB_IFACE_NUM 0
|
||||
|
Loading…
Reference in New Issue
Block a user