Skip to content

Commit

Permalink
Adding dual booting fx2 firmware.
Browse files Browse the repository at this point in the history
 * HDMI2USB now boots into HDMI2USB mode!
 * Base boots into usbjtag mode.
  • Loading branch information
mithro committed Jan 8, 2016
1 parent e2fa72d commit e7fbe0d
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 26 deletions.
8 changes: 7 additions & 1 deletion Makefile.lm32
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@ help-lm32:
gateware-lm32: firmware-lm32
@true

firmware-lm32: third_party/misoc/.git
ifeq ($(TARGET),hdmi2usb)
EXTRA_DEPS = embed-fx2
else
EXTRA_DEPS =
endif

firmware-lm32: third_party/misoc/.git $(EXTRA_DEPS)
cd $(MSCDIR) && $(CMD) build-headers
$(MAKE) -C firmware/lm32 all

Expand Down
15 changes: 13 additions & 2 deletions firmware/lm32/ci.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ static void help_debug(void)
puts("debug tofe_eeprom - dump TOFE Board Info EEPROM");
#endif
#ifdef CSR_FX2_RESET_OUT_ADDR
puts("debug fx2_reboot - reboot the FX2 USB IC");
puts("debug fx2_reboot firmware - reboot the FX2 USB IC into firmware");
#endif
}

Expand Down Expand Up @@ -624,7 +624,18 @@ void ci_service(void)
#endif
#ifdef CSR_FX2_RESET_OUT_ADDR
else if(strcmp(token, "fx2_reboot") == 0) {
fx2_reboot();
token = get_token(&str);
if(strcmp(token, "") || strcmp(token, "usbjtag") == 0) {
fx2_reboot(FX2FW_USBJTAG);
}
#ifdef ENCODER_BASE
else if (strcmp(token, "hdmi2usb") == 0) {
fx2_reboot(FX2FW_HDMI2USB);
}
#endif
else {
printf("Unknown firmware\n");
}
}
#endif
else if(strcmp(token, "edid") == 0) {
Expand Down
62 changes: 50 additions & 12 deletions firmware/lm32/fx2.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,67 @@
#define FX2_HACK_SHIFT_REG_EMPTY 2
#define FX2_HACK_STATUS_READY 0

#define FX2_FIRMWARE fx2_mbfw_usbjtag
#include "fx2_fw_usbjtag.c"
#ifdef ENCODER_BASE
#include "fx2_fw_hdmi2usb.c"
#endif

static void fx2_wait(void) {
unsigned int i;
for(i=0;i<1000;i++) __asm__("nop");
}

enum fx2_fw_version fx2_fw_active;


static size_t next_read_addr;
static size_t end_addr;

inline uint8_t fx2_fw_get_value(size_t addr) {
uint8_t r = 0xff;
if (addr < sizeof(FX2_FIRMWARE)) {
r = FX2_FIRMWARE.bytes[addr];
if (addr < end_addr) {
switch(fx2_fw_active) {
case FX2FW_USBJTAG:
r = fx2_mbfw_usbjtag.bytes[addr];
break;
#ifdef ENCODER_BASE
case FX2FW_HDMI2USB:
r = fx2_mbfw_hdmi2usb.bytes[addr];
break;

#endif
}
} else {
printf("fx2: Read from invalid address %02X\n", addr);
printf("fx2: Read from invalid address for USB-JTAG firmware %02X\n", addr);
}
return r;
}

#define FX2_REPORT_PERIOD (1 << 22)
#define FX2_WAIT_PERIOD FX2_REPORT_PERIOD*10

static size_t next_read_addr;
static void fx2_init(void)
static void fx2_load_init(void)
{
next_read_addr = 0;
switch(fx2_fw_active) {
case FX2FW_USBJTAG:
end_addr = FX2_MBFW_USBJTAG_END;
break;
#ifdef ENCODER_BASE
case FX2FW_HDMI2USB:
end_addr = FX2_MBFW_HDMI2USB_END;
break;
#endif
}

fx2_hack_slave_addr_write(FX2_HACK_SLAVE_ADDRESS);
fx2_hack_shift_reg_write(fx2_fw_get_value(0));
fx2_hack_status_write(FX2_HACK_STATUS_READY);
}

static void fx2_load(void)
{
fx2_init();
fx2_load_init();
printf("fx2: Waiting for FX2 to load firmware.\n");

uint64_t i = 0;
Expand All @@ -54,7 +82,7 @@ static void fx2_load(void)
break;
}
} else if ((i % FX2_REPORT_PERIOD) == 0) {
printf("fx2: Waiting at %02X (end: %02X)\n", next_read_addr, FX2_FIRMWARE_END);
printf("fx2: Waiting at %02X (end: %02X)\n", next_read_addr, end_addr);
}
}
if (i > 0) {
Expand All @@ -69,16 +97,16 @@ bool fx2_service(bool verbose)
unsigned char status = fx2_hack_status_read();
if(status == FX2_HACK_SHIFT_REG_EMPTY) { // there's been a master READ
if (verbose) {
printf("fx2: read %02X (end: %02X)\n", next_read_addr, FX2_FIRMWARE_END);
printf("fx2: read %02X (end: %02X)\n", next_read_addr, end_addr);
}
if (next_read_addr < FX2_FIRMWARE_END) {
if (next_read_addr < end_addr) {
// Load next value into the system
fx2_hack_shift_reg_write(fx2_fw_get_value(next_read_addr+1));
fx2_hack_status_write(FX2_HACK_STATUS_READY);
next_read_addr++;
} else {
printf("fx2: Finished loading firmware.\n");
fx2_init();
fx2_load_init();
}
return true;
} else if (status != 0) {
Expand All @@ -87,8 +115,9 @@ bool fx2_service(bool verbose)
return false;
}

void fx2_reboot(void)
void fx2_reboot(enum fx2_fw_version fw)
{
fx2_fw_active = fw;
printf("fx2: Turning off.\n");
fx2_reset_out_write(0);
fx2_wait();
Expand All @@ -97,4 +126,13 @@ void fx2_reboot(void)
fx2_load();
}

void fx2_init(void)
{
#ifdef ENCODER_BASE
fx2_reboot(FX2FW_HDMI2USB);
#else
fx2_reboot(FX2FW_USBJTAG);
#endif
}

#endif
10 changes: 9 additions & 1 deletion firmware/lm32/fx2.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@

#include <stdbool.h>

enum fx2_fw_version {
FX2FW_USBJTAG,
#ifdef ENCODER_BASE
FX2FW_HDMI2USB,
#endif
};

void fx2_init(void);
bool fx2_service(bool verbose);
void fx2_reboot(void);
void fx2_reboot(enum fx2_fw_version fw);

#endif
2 changes: 1 addition & 1 deletion firmware/lm32/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ int main(void)

// Reboot the FX2 chip into HDMI2USB mode
#ifdef CSR_FX2_RESET_OUT_ADDR
fx2_reboot();
fx2_init();
#endif

ci_prompt();
Expand Down
2 changes: 1 addition & 1 deletion targets/opsis_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class BaseSoC(SDRAMSoC):
mem_map.update(SDRAMSoC.mem_map)

def __init__(self, platform,
firmware_ram_size=0xa000,
firmware_ram_size=0x10000,
firmware_filename=None,
**kwargs):
clk_freq = 50*1000000
Expand Down
16 changes: 8 additions & 8 deletions targets/opsis_hdmi2usb.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@

class VideomixerSoC(BaseSoC):
csr_map = {
"hdmi_out0": 20,
"hdmi_out1": 21,
"hdmi_in0": 22,
"hdmi_in0_edid_mem": 23,
"hdmi_in1": 24,
"hdmi_in1_edid_mem": 25,
"hdmi_out0": 21,

This comment has been minimized.

Copy link
@mithro

mithro Jan 20, 2016

Author Owner

Logged an issue about this -> timvideos#171

"hdmi_out1": 22,
"hdmi_in0": 23,
"hdmi_in0_edid_mem": 24,
"hdmi_in1": 25,
"hdmi_in1_edid_mem": 26,
}
csr_map.update(BaseSoC.csr_map)

Expand Down Expand Up @@ -57,8 +57,8 @@ def __init__(self, platform, **kwargs):

class HDMI2USBSoC(VideomixerSoC):
csr_map = {
"encoder_reader": 26,
"encoder": 27
"encoder_reader": 27,
"encoder": 28,
}
csr_map.update(VideomixerSoC.csr_map)
mem_map = {
Expand Down

0 comments on commit e7fbe0d

Please sign in to comment.