booster: get functional build working

This has successfully updated a PVT unit to v1.9.1.

Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
Sean Cross 2019-08-28 11:30:03 +08:00
parent e13755fff0
commit 0a7b193f96
9 changed files with 408 additions and 282 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,33 @@
#ifndef CSR_ACCESSORS_DEFINED
#define CSR_ACCESSORS_DEFINED
#include <stdint.h>
static inline void csr_writeb(uint8_t value, uint32_t addr)
{
*((volatile uint8_t *)addr) = value;
}
static inline uint8_t csr_readb(uint32_t addr)
{
return *(volatile uint8_t *)addr;
}
static inline void csr_writew(uint16_t value, uint32_t addr)
{
*((volatile uint16_t *)addr) = value;
}
static inline uint16_t csr_readw(uint32_t addr)
{
return *(volatile uint16_t *)addr;
}
static inline void csr_writel(uint32_t value, uint32_t addr)
{
*((volatile uint32_t *)addr) = value;
}
static inline uint32_t csr_readl(uint32_t addr)
{
return *(volatile uint32_t *)addr;
}
#endif /* CSR_ACCESSORS_DEFINED */

View File

@ -15,6 +15,7 @@ void usb_connect(void);
void usb_idle(void);
void usb_disconnect(void);
void usb_setup(const struct usb_setup_request *setup, uint32_t size);
void usb_set_address(uint8_t);
void usb_ack_in(void);
void usb_ack_out(void);
@ -25,4 +26,4 @@ void usb_send(const void *data, int total_count);
}
#endif
#endif
#endif

View File

@ -54,7 +54,7 @@ SECTIONS
_edata = ALIGN(16); /* Make sure _edata is >= _gp. */
} > sram
booster_data = ADDR(.data) + SIZEOF(.data);
/* booster_data = ADDR(.data) + SIZEOF(.data); */
booster_src = ADDR(.startup) + SIZEOF(.startup) + SIZEOF(.data);
}

View File

@ -1,4 +1,5 @@
#include <booster.h>
#include <csr_accessors.h>
#include <csr.h>
#include <irq.h>
#include <rgb.h>
@ -13,7 +14,7 @@ extern uint32_t hash_length;
extern uint32_t image_seed;
extern uint32_t spi_id;
extern struct booster_data booster_data;
extern struct booster_data booster_src;
uint32_t read_spi_id;
uint32_t cached_image_length;
uint32_t cached_spi_id;
@ -165,7 +166,7 @@ __attribute__((noreturn)) void fobooster_main(void)
// Ensure the hash matches what's expected.
calculated_hash = XXH32((const void *)0x20040000, hash_length, image_seed);
if (calculated_hash != booster_data.xxhash)
if (calculated_hash != booster_src.xxhash)
{
error(HASH_MISMATCH);
}
@ -182,22 +183,23 @@ __attribute__((noreturn)) void fobooster_main(void)
}
}
// Patch the target image so that it goes to our program if the user
// reboots.
((uint8_t *)cached_image)[9] = 0x04;
// Now that everything is copied to RAM, disable memory-mapped SPI mode.
// This puts the SPI into bit-banged mode, which allows us to write to it.
cached_spi_id = spi_id; // Copy spi_id over first, since it is still on the flash.
cached_image_length = image_length;
// Ensure the cached image matches the image on disk.
int i;
for (i = 0; i < cached_image_length; i++) {
if (((uint8_t *)cached_image)[i] != ((uint8_t *)0x20000000)[i]) {
if (((uint8_t *)cached_image)[i] != ((uint8_t *)0x20040000)[i]) {
error(FINAL_IMAGE_MISMATCH);
}
}
// Patch the target image so that it goes to our program if the user
// reboots.
((uint8_t *)cached_image)[9] = 0x04;
picorvspi_cfg4_write(0);
ftfl_busy_wait();
@ -260,4 +262,4 @@ __attribute__((noreturn)) void fobooster_main(void)
rgb_mode_writing();
finish_flashing();
}
}

View File

@ -1,3 +1,4 @@
#include <csr_accessors.h>
#include <csr.h>
enum led_registers
@ -120,4 +121,4 @@ void rgb_init(void)
rgb_write((12000000 / 2048000) - 1, LEDDBR);
rgb_mode_writing();
}
}

View File

@ -1,4 +1,5 @@
#include <stdint.h>
#include <csr_accessors.h>
#include <csr.h>
#define SP_MOSI_PIN 0
@ -166,4 +167,4 @@ uint32_t spiId(void) {
spiEnd();
return id;
}
}

View File

@ -68,6 +68,7 @@ static const uint8_t usb_string_microsoft[18] = {
static uint8_t reply_buffer[8];
static uint8_t usb_configuration = 0;
__attribute__((section(".ramtext")))
void usb_setup(const struct usb_setup_request *setup, uint32_t size)
{
const uint8_t *data = NULL;
@ -77,6 +78,9 @@ void usb_setup(const struct usb_setup_request *setup, uint32_t size)
switch (setup->wRequestAndType)
{
case 0x0500: // SET_ADDRESS
usb_set_address(setup->wValue);
break;
case 0x0b01: // SET_INTERFACE
break;

View File

@ -1,3 +1,4 @@
#include <csr_accessors.h>
#include <csr.h>
#include <irq.h>
#include <string.h>
@ -21,6 +22,9 @@ static volatile int data_offset;
static volatile int data_to_send;
static int next_packet_is_empty;
static uint8_t new_address;
static int have_new_address;
// Note that our PIDs are only bits 2 and 3 of the token,
// since all other bits are effectively redundant at this point.
enum USB_PID {
@ -40,6 +44,11 @@ enum epfifo_response {
#define USB_EV_ERROR 1
#define USB_EV_PACKET 2
void usb_set_address(uint8_t address) {
new_address = address;
have_new_address = 1;
}
void usb_idle(void) {
usb_ep_0_out_ev_enable_write(0);
usb_ep_0_in_ev_enable_write(0);
@ -58,6 +67,7 @@ void usb_disconnect(void) {
usb_ep_0_in_ev_enable_write(0);
irq_setmask(irq_getmask() & ~(1 << USB_INTERRUPT));
usb_pullup_out_write(0);
usb_address_write(0);
}
void usb_connect(void) {
@ -81,7 +91,7 @@ void usb_connect(void) {
void usb_init(void) {
usb_ep0out_wr_ptr = 0;
usb_ep0out_rd_ptr = 0;
usb_pullup_out_write(0);
usb_disconnect();
}
static void process_tx(void) {
@ -169,15 +179,23 @@ void usb_isr(void) {
}
}
if (obuf_len >= 2)
obuf_len -= 2 /* Strip off CRC16 */;
// if (obuf_len >= 2)
// obuf_len -= 2 /* Strip off CRC16 */;
if (last_tok == USB_PID_SETUP) {
// if (last_tok == USB_PID_SETUP) {
if (obuf_len >= 8) {
// HACK: There's no inter-packet indicator, so sometimes we
// receive an ACK packet at the start of our SETUP packet.
// To work around this, assume that all SETUP packets are 10-
// bytes (8 bytes plus CRC16) and work backwards from the end
// of the buffer.
uint32_t setup_pkt[2];
memcpy(setup_pkt, obuf + obuf_len - 10, 8);
usb_ep_0_in_dtb_write(1);
data_offset = 0;
current_length = 0;
current_data = NULL;
usb_setup((const void *)obuf, obuf_len);
usb_setup((const void *)setup_pkt, 8);
}
usb_ep_0_out_ev_pending_write(ep0o_pending);
@ -188,6 +206,10 @@ void usb_isr(void) {
if (ep0i_pending) {
usb_ep_0_in_respond_write(EPF_NAK);
usb_ep_0_in_ev_pending_write(ep0i_pending);
if (have_new_address) {
have_new_address = 0;
usb_address_write(new_address);
}
}
return;
@ -234,4 +256,4 @@ int usb_recv(void *buffer, unsigned int buffer_len) {
return 0;
}
#endif /* CSR_USB_EP_0_OUT_EV_PENDING_ADDR */
#endif /* CSR_USB_EP_0_OUT_EV_PENDING_ADDR */