1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-25 17:09:44 +00:00

vendor/libopencm3: update to latest snapshot

This commit is contained in:
Pavol Rusnak 2019-04-01 17:02:32 +02:00
parent 622966383c
commit fc73e54d44
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
14 changed files with 116 additions and 96 deletions

View File

@ -213,9 +213,9 @@ static const char *usb_strings[] = {
"01234567",
};
static int hid_control_request(usbd_device *dev, struct usb_setup_data *req,
uint8_t **buf, uint16_t *len,
usbd_control_complete_callback *complete) {
static enum usbd_request_return_codes hid_control_request(
usbd_device *dev, struct usb_setup_data *req, uint8_t **buf, uint16_t *len,
usbd_control_complete_callback *complete) {
(void)complete;
(void)dev;

View File

@ -259,9 +259,9 @@ static const struct usb_config_descriptor config = {
.interface = ifaces,
};
static int hid_control_request(usbd_device *dev, struct usb_setup_data *req,
uint8_t **buf, uint16_t *len,
usbd_control_complete_callback *complete) {
static enum usbd_request_return_codes hid_control_request(
usbd_device *dev, struct usb_setup_data *req, uint8_t **buf, uint16_t *len,
usbd_control_complete_callback *complete) {
(void)complete;
(void)dev;

View File

@ -14,7 +14,7 @@ SECTIONS
} >ram
}
INCLUDE libopencm3_stm32f2.ld
INCLUDE cortex-m-generic.ld
_ram_start = ORIGIN(ram);
_ram_end = ORIGIN(ram) + LENGTH(ram);

View File

@ -6,4 +6,4 @@ MEMORY
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 128K
}
INCLUDE libopencm3_stm32f2.ld
INCLUDE cortex-m-generic.ld

View File

@ -14,7 +14,7 @@ SECTIONS
} >ram
}
INCLUDE libopencm3_stm32f2.ld
INCLUDE cortex-m-generic.ld
_ram_start = ORIGIN(ram);
_ram_end = ORIGIN(ram) + LENGTH(ram);

View File

@ -18,7 +18,7 @@ SECTIONS
} >rom AT>rom
}
INCLUDE libopencm3_stm32f2.ld
INCLUDE cortex-m-generic.ld
_codelen = SIZEOF(.text) + SIZEOF(.data) + SIZEOF(.ARM.exidx);

View File

@ -15,7 +15,7 @@ SECTIONS
} >ram
}
INCLUDE libopencm3_stm32f2.ld
INCLUDE cortex-m-generic.ld
_ram_start = ORIGIN(ram);
_ram_end = ORIGIN(ram) + LENGTH(ram);

View File

@ -53,7 +53,7 @@ static uint16_t build_bos_descriptor(const struct usb_bos_descriptor *bos,
static const struct usb_bos_descriptor *usb21_bos;
static int usb21_standard_get_descriptor(
static enum usbd_request_return_codes usb21_standard_get_descriptor(
usbd_device *usbd_dev, struct usb_setup_data *req, uint8_t **buf,
uint16_t *len, usbd_control_complete_callback *complete) {
(void)complete;

View File

@ -46,7 +46,7 @@ LGPL License Terms @ref lgpl_license
struct _usbd_device {
const struct usb_device_descriptor *desc;
const struct usb_config_descriptor *config;
const char **strings;
const char * const *strings;
int num_strings;
uint8_t *ctrl_buf; /**< Internal buffer used for control transfers */
@ -122,16 +122,16 @@ void _usbd_control_in(usbd_device *usbd_dev, uint8_t ea);
void _usbd_control_out(usbd_device *usbd_dev, uint8_t ea);
void _usbd_control_setup(usbd_device *usbd_dev, uint8_t ea);
int _usbd_standard_request_device(usbd_device *usbd_dev,
enum usbd_request_return_codes _usbd_standard_request_device(usbd_device *usbd_dev,
struct usb_setup_data *req, uint8_t **buf,
uint16_t *len);
int _usbd_standard_request_interface(usbd_device *usbd_dev,
enum usbd_request_return_codes _usbd_standard_request_interface(usbd_device *usbd_dev,
struct usb_setup_data *req, uint8_t **buf,
uint16_t *len);
int _usbd_standard_request_endpoint(usbd_device *usbd_dev,
enum usbd_request_return_codes _usbd_standard_request_endpoint(usbd_device *usbd_dev,
struct usb_setup_data *req, uint8_t **buf,
uint16_t *len);
int _usbd_standard_request(usbd_device *usbd_dev, struct usb_setup_data *req,
enum usbd_request_return_codes _usbd_standard_request(usbd_device *usbd_dev, struct usb_setup_data *req,
uint8_t **buf, uint16_t *len);
void _usbd_reset(usbd_device *usbd_dev);

View File

@ -48,6 +48,9 @@ int usbd_register_set_config_callback(usbd_device *usbd_dev,
for (i = 0; i < MAX_USER_SET_CONFIG_CALLBACK; i++) {
if (usbd_dev->user_callback_set_config[i]) {
if (usbd_dev->user_callback_set_config[i] == callback) {
return 0;
}
continue;
}
@ -131,8 +134,9 @@ static uint16_t build_config_descriptor(usbd_device *usbd_dev,
}
}
/* Fill in wTotalLength. */
*(uint16_t *)(tmpbuf + 2) = totallen;
/* Fill in wTotalLength.
* Note that tmpbuf is sometimes not halfword-aligned */
memcpy((tmpbuf + 2), &totallen, sizeof(uint16_t));
return total;
}
@ -147,9 +151,10 @@ static int usb_descriptor_index(uint16_t wValue)
return wValue & 0xFF;
}
static int usb_standard_get_descriptor(usbd_device *usbd_dev,
struct usb_setup_data *req,
uint8_t **buf, uint16_t *len)
static enum usbd_request_return_codes
usb_standard_get_descriptor(usbd_device *usbd_dev,
struct usb_setup_data *req,
uint8_t **buf, uint16_t *len)
{
wait_random();
@ -221,9 +226,10 @@ static int usb_standard_get_descriptor(usbd_device *usbd_dev,
return USBD_REQ_NOTSUPP;
}
static int usb_standard_set_address(usbd_device *usbd_dev,
struct usb_setup_data *req, uint8_t **buf,
uint16_t *len)
static enum usbd_request_return_codes
usb_standard_set_address(usbd_device *usbd_dev,
struct usb_setup_data *req, uint8_t **buf,
uint16_t *len)
{
(void)req;
(void)buf;
@ -231,7 +237,7 @@ static int usb_standard_set_address(usbd_device *usbd_dev,
/* The actual address is only latched at the STATUS IN stage. */
if ((req->bmRequestType != 0) || (req->wValue >= 128)) {
return 0;
return USBD_REQ_NOTSUPP;
}
usbd_dev->current_address = req->wValue;
@ -244,12 +250,13 @@ static int usb_standard_set_address(usbd_device *usbd_dev,
usbd_dev->driver->set_address(usbd_dev, req->wValue);
}
return 1;
return USBD_REQ_HANDLED;
}
static int usb_standard_set_configuration(usbd_device *usbd_dev,
struct usb_setup_data *req,
uint8_t **buf, uint16_t *len)
static enum usbd_request_return_codes
usb_standard_set_configuration(usbd_device *usbd_dev,
struct usb_setup_data *req,
uint8_t **buf, uint16_t *len)
{
unsigned i;
int found_index = -1;
@ -305,12 +312,13 @@ static int usb_standard_set_configuration(usbd_device *usbd_dev,
}
}
return 1;
return USBD_REQ_HANDLED;
}
static int usb_standard_get_configuration(usbd_device *usbd_dev,
struct usb_setup_data *req,
uint8_t **buf, uint16_t *len)
static enum usbd_request_return_codes
usb_standard_get_configuration(usbd_device *usbd_dev,
struct usb_setup_data *req,
uint8_t **buf, uint16_t *len)
{
(void)req;
@ -325,12 +333,13 @@ static int usb_standard_get_configuration(usbd_device *usbd_dev,
(*buf)[0] = 0;
}
return 1;
return USBD_REQ_HANDLED;
}
static int usb_standard_set_interface(usbd_device *usbd_dev,
struct usb_setup_data *req,
uint8_t **buf, uint16_t *len)
static enum usbd_request_return_codes
usb_standard_set_interface(usbd_device *usbd_dev,
struct usb_setup_data *req,
uint8_t **buf, uint16_t *len)
{
const struct usb_config_descriptor *cfx =
&usbd_dev->config[usbd_dev->current_config - 1];
@ -365,9 +374,10 @@ static int usb_standard_set_interface(usbd_device *usbd_dev,
return USBD_REQ_HANDLED;
}
static int usb_standard_get_interface(usbd_device *usbd_dev,
struct usb_setup_data *req,
uint8_t **buf, uint16_t *len)
static enum usbd_request_return_codes
usb_standard_get_interface(usbd_device *usbd_dev,
struct usb_setup_data *req,
uint8_t **buf, uint16_t *len)
{
uint8_t *cur_altsetting;
const struct usb_config_descriptor *cfx =
@ -384,9 +394,10 @@ static int usb_standard_get_interface(usbd_device *usbd_dev,
return USBD_REQ_HANDLED;
}
static int usb_standard_device_get_status(usbd_device *usbd_dev,
struct usb_setup_data *req,
uint8_t **buf, uint16_t *len)
static enum usbd_request_return_codes
usb_standard_device_get_status(usbd_device *usbd_dev,
struct usb_setup_data *req,
uint8_t **buf, uint16_t *len)
{
(void)usbd_dev;
(void)req;
@ -399,12 +410,13 @@ static int usb_standard_device_get_status(usbd_device *usbd_dev,
(*buf)[0] = 0;
(*buf)[1] = 0;
return 1;
return USBD_REQ_HANDLED;
}
static int usb_standard_interface_get_status(usbd_device *usbd_dev,
struct usb_setup_data *req,
uint8_t **buf, uint16_t *len)
static enum usbd_request_return_codes
usb_standard_interface_get_status(usbd_device *usbd_dev,
struct usb_setup_data *req,
uint8_t **buf, uint16_t *len)
{
(void)usbd_dev;
(void)req;
@ -416,12 +428,13 @@ static int usb_standard_interface_get_status(usbd_device *usbd_dev,
(*buf)[0] = 0;
(*buf)[1] = 0;
return 1;
return USBD_REQ_HANDLED;
}
static int usb_standard_endpoint_get_status(usbd_device *usbd_dev,
struct usb_setup_data *req,
uint8_t **buf, uint16_t *len)
static enum usbd_request_return_codes
usb_standard_endpoint_get_status(usbd_device *usbd_dev,
struct usb_setup_data *req,
uint8_t **buf, uint16_t *len)
{
(void)req;
@ -431,42 +444,46 @@ static int usb_standard_endpoint_get_status(usbd_device *usbd_dev,
(*buf)[0] = usbd_ep_stall_get(usbd_dev, req->wIndex) ? 1 : 0;
(*buf)[1] = 0;
return 1;
return USBD_REQ_HANDLED;
}
static int usb_standard_endpoint_stall(usbd_device *usbd_dev,
struct usb_setup_data *req,
uint8_t **buf, uint16_t *len)
static enum usbd_request_return_codes
usb_standard_endpoint_stall(usbd_device *usbd_dev,
struct usb_setup_data *req,
uint8_t **buf, uint16_t *len)
{
(void)buf;
(void)len;
usbd_ep_stall_set(usbd_dev, req->wIndex, 1);
return 1;
return USBD_REQ_HANDLED;
}
static int usb_standard_endpoint_unstall(usbd_device *usbd_dev,
struct usb_setup_data *req,
uint8_t **buf, uint16_t *len)
static enum usbd_request_return_codes
usb_standard_endpoint_unstall(usbd_device *usbd_dev,
struct usb_setup_data *req,
uint8_t **buf, uint16_t *len)
{
(void)buf;
(void)len;
usbd_ep_stall_set(usbd_dev, req->wIndex, 0);
return 1;
return USBD_REQ_HANDLED;
}
/* Do not appear to belong to the API, so are omitted from docs */
/**@}*/
int _usbd_standard_request_device(usbd_device *usbd_dev,
struct usb_setup_data *req, uint8_t **buf,
uint16_t *len)
enum usbd_request_return_codes
_usbd_standard_request_device(usbd_device *usbd_dev,
struct usb_setup_data *req, uint8_t **buf,
uint16_t *len)
{
int (*command)(usbd_device *usbd_dev, struct usb_setup_data *req,
uint8_t **buf, uint16_t *len) = NULL;
enum usbd_request_return_codes (*command)(usbd_device *usbd_dev,
struct usb_setup_data *req,
uint8_t **buf, uint16_t *len) = NULL;
switch (req->bRequest) {
case USB_REQ_CLEAR_FEATURE:
@ -509,18 +526,20 @@ int _usbd_standard_request_device(usbd_device *usbd_dev,
}
if (!command) {
return 0;
return USBD_REQ_NOTSUPP;
}
return command(usbd_dev, req, buf, len);
}
int _usbd_standard_request_interface(usbd_device *usbd_dev,
struct usb_setup_data *req, uint8_t **buf,
uint16_t *len)
enum usbd_request_return_codes
_usbd_standard_request_interface(usbd_device *usbd_dev,
struct usb_setup_data *req, uint8_t **buf,
uint16_t *len)
{
int (*command)(usbd_device *usbd_dev, struct usb_setup_data *req,
uint8_t **buf, uint16_t *len) = NULL;
enum usbd_request_return_codes (*command)(usbd_device *usbd_dev,
struct usb_setup_data *req,
uint8_t **buf, uint16_t *len) = NULL;
switch (req->bRequest) {
case USB_REQ_CLEAR_FEATURE:
@ -539,18 +558,20 @@ int _usbd_standard_request_interface(usbd_device *usbd_dev,
}
if (!command) {
return 0;
return USBD_REQ_NOTSUPP;
}
return command(usbd_dev, req, buf, len);
}
int _usbd_standard_request_endpoint(usbd_device *usbd_dev,
struct usb_setup_data *req, uint8_t **buf,
uint16_t *len)
enum usbd_request_return_codes
_usbd_standard_request_endpoint(usbd_device *usbd_dev,
struct usb_setup_data *req, uint8_t **buf,
uint16_t *len)
{
int (*command) (usbd_device *usbd_dev, struct usb_setup_data *req,
uint8_t **buf, uint16_t *len) = NULL;
enum usbd_request_return_codes (*command) (usbd_device *usbd_dev,
struct usb_setup_data *req,
uint8_t **buf, uint16_t *len) = NULL;
switch (req->bRequest) {
case USB_REQ_CLEAR_FEATURE:
@ -576,18 +597,19 @@ int _usbd_standard_request_endpoint(usbd_device *usbd_dev,
}
if (!command) {
return 0;
return USBD_REQ_NOTSUPP;
}
return command(usbd_dev, req, buf, len);
}
int _usbd_standard_request(usbd_device *usbd_dev, struct usb_setup_data *req,
uint8_t **buf, uint16_t *len)
enum usbd_request_return_codes
_usbd_standard_request(usbd_device *usbd_dev, struct usb_setup_data *req,
uint8_t **buf, uint16_t *len)
{
/* FIXME: Have class/vendor requests as well. */
if ((req->bmRequestType & USB_REQ_TYPE_TYPE) != USB_REQ_TYPE_STANDARD) {
return 0;
return USBD_REQ_NOTSUPP;
}
switch (req->bmRequestType & USB_REQ_TYPE_RECIPIENT) {
@ -599,7 +621,7 @@ int _usbd_standard_request(usbd_device *usbd_dev, struct usb_setup_data *req,
case USB_REQ_TYPE_ENDPOINT:
return _usbd_standard_request_endpoint(usbd_dev, req, buf, len);
default:
return 0;
return USBD_REQ_NOTSUPP;
}
}

11
util.h
View File

@ -69,7 +69,6 @@ extern void __attribute__((noreturn)) shutdown(void);
#if !EMULATOR
// defined in memory.ld
extern uint8_t _ram_start[], _ram_end[];
extern uint8_t _stack[];
// defined in startup.s
extern void memset_reg(void *start, void *stop, uint32_t val);
@ -78,11 +77,11 @@ extern void memset_reg(void *start, void *stop, uint32_t val);
#define FW_UNTRUSTED 0x00000000
static inline void __attribute__((noreturn))
jump_to_firmware(const vector_table_t *vector_table, int trust) {
if (FW_SIGNED == trust) { // trusted signed firmware
SCB_VTOR = (uint32_t)vector_table; // * relocate vector table
jump_to_firmware(const vector_table_t *ivt, int trust) {
if (FW_SIGNED == trust) { // trusted signed firmware
SCB_VTOR = (uint32_t)ivt; // * relocate vector table
// Set stack pointer
__asm__ volatile("msr msp, %0" ::"r"(vector_table->initial_sp_value));
__asm__ volatile("msr msp, %0" ::"r"(ivt->initial_sp_value));
} else { // untrusted firmware
timer_init();
mpu_config_firmware(); // * configure MPU for the firmware
@ -90,7 +89,7 @@ jump_to_firmware(const vector_table_t *vector_table, int trust) {
}
// Jump to address
vector_table->reset();
ivt->reset();
// Prevent compiler from generating stack protector code (which causes CPU
// fault because the stack is moved)

2
vendor/libopencm3 vendored

@ -1 +1 @@
Subproject commit b0e050d10d12c42be031c34822117cfd3c5a0ea7
Subproject commit 0fd4f74ee301af5de4e9b036f391bf17c5a52f02

View File

@ -45,7 +45,7 @@ const struct webusb_platform_descriptor
static const char* webusb_https_url;
static int webusb_control_vendor_request(
static enum usbd_request_return_codes webusb_control_vendor_request(
usbd_device* usbd_dev, struct usb_setup_data* req, uint8_t** buf,
uint16_t* len, usbd_control_complete_callback* complete) {
(void)complete;

View File

@ -73,10 +73,9 @@ static const struct winusb_extended_properties_descriptor guid = {
},
}};
static int winusb_descriptor_request(usbd_device *usbd_dev,
struct usb_setup_data *req, uint8_t **buf,
uint16_t *len,
usbd_control_complete_callback *complete) {
static enum usbd_request_return_codes winusb_descriptor_request(
usbd_device *usbd_dev, struct usb_setup_data *req, uint8_t **buf,
uint16_t *len, usbd_control_complete_callback *complete) {
(void)complete;
(void)usbd_dev;
@ -97,7 +96,7 @@ static int winusb_descriptor_request(usbd_device *usbd_dev,
return USBD_REQ_NEXT_CALLBACK;
}
static int winusb_control_vendor_request(
static enum usbd_request_return_codes winusb_control_vendor_request(
usbd_device *usbd_dev, struct usb_setup_data *req, uint8_t **buf,
uint16_t *len, usbd_control_complete_callback *complete) {
(void)complete;