Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add writable SPI flash and XMODEM xfer support #370

Open
wants to merge 33 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
a33f660
Cherry-pick flash files from arty-soc branch. Add SPI flash bitbang t…
cr1901 Mar 31, 2017
afb11ef
Add erase free area to bitbang test.
cr1901 Mar 31, 2017
0662522
Flush data cache between reads in bitbang test.
cr1901 Mar 31, 2017
13e75f1
Add non-zero write to spiflash debug.
cr1901 Apr 2, 2017
f435a0d
Fix include guard for flash bitbang interface.
cr1901 Apr 2, 2017
0cfbf85
Add stub xmodem/sfl implementation.
Aug 4, 2017
72a4bce
Add XMODEM implementation for SPI (currently nonfunctional).
Aug 5, 2017
8ca8ed8
Integrate libmodem as submodule (library link compiles).
cr1901 Aug 18, 2017
9d90b0f
Ensure rebuild of libmodem if contents change.
cr1901 Aug 19, 2017
36baad5
Start integrating libmodem into firmware.
cr1901 Aug 19, 2017
beb0f35
XMODEM xfers now succeed with libmodem. Update libmodem submodule.
cr1901 Aug 20, 2017
61c0b00
CRC token required for all xfer modes; BIOS uses it.
cr1901 Aug 20, 2017
f6d4830
Move .bss to main_ram so file buffers fit.
cr1901 Aug 20, 2017
3ccd486
Allow hex values for write commands.
cr1901 Aug 20, 2017
41d6278
write_to_buf needs to move offset into buffer to avoid overwriting data.
cr1901 Aug 20, 2017
d99096e
Do not write len/CRC; assume arbitrary data input.
cr1901 Aug 20, 2017
ed8d203
write_xmodem() at arbitrary flash addresses is functional.
cr1901 Aug 20, 2017
86a116a
Mild refactor of SPI flash write code paths.
cr1901 Aug 20, 2017
220a547
Add CRC32 support to upload (and helper script).
cr1901 Aug 20, 2017
ab9443c
Bump third_party/libmodem up to documentation commits.
cr1901 Aug 24, 2017
7dae4bc
libmodem uses Meson build system now. Integrate libmodem build like l…
cr1901 Sep 6, 2017
01b6d8f
Fix libmodem compilation so that hdmi2usb_dir is set properly, uses o…
cr1901 Sep 8, 2017
0e3b138
Fix libmodem include path, remove scons remnants.
cr1901 Sep 11, 2017
308b27e
Disable PIC option added by meson when compiling libmodem- crashes fi…
cr1901 Sep 27, 2017
955cf6d
Ensure firmware compiles successfully after merge.
cr1901 Oct 7, 2017
bc8dd47
Parameterize meson executable name, which may be available as 'meson'…
cr1901 Dec 13, 2017
02fbd66
Add meson as travis CI dependency to build libmodem.
cr1901 Dec 13, 2017
02296eb
Fix travis CI dependencies.
cr1901 Dec 13, 2017
96428a2
CC needs to be set to a dummy value for meson. Add comment explaining.
cr1901 Dec 14, 2017
2f87f9d
Update libmodem to include hdmi2usb-or1k backend.
cr1901 Dec 14, 2017
3f0c329
Improve conditional compilation for bitbang_test.
cr1901 Dec 14, 2017
6a4935a
Fix bad libmodem update.
cr1901 Dec 14, 2017
95aa9e3
Merge branch 'upstream' into xfer-fw
cr1901 Aug 19, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
[submodule "third_party/flash_proxies"]
path = third_party/flash_proxies
url = https://github.com/jordens/bscan_spi_bitstreams
[submodule "third_party/libmodem"]
path = third_party/libmodem
url = https://github.com/cr1901/libmodem
[submodule "third_party/migen"]
path = third_party/migen
url = https://github.com/m-labs/migen.git
7 changes: 7 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ addons:
- libftdi-dev
- libreadline-dev
- libusb-1.0-0-dev
- python3-pip
- python-yaml
- realpath
- util-linux
Expand All @@ -31,6 +32,12 @@ env:
# cores.
- JOBS=2

before_install:
- wget https://github.com/ninja-build/ninja/releases/download/v1.8.2/ninja-linux.zip -O /tmp/ninja.zip
- unzip -d ninja-1.8.2 /tmp/ninja.zip
- export PATH=$PATH:$PWD/ninja-1.8.2/
- pip3 install --user meson

install:
- export CPUS="$C" && echo "CPUS='$CPUS'"
- export PLATFORMS="$P" && echo "PLATFORMS='$PLATFORMS'"
Expand Down
9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ endif
PYTHON ?= python
export PYTHON

MESON ?= meson
export MESON

SPLIT_REGEX := ^\([^.]*\)\.\?\(.*\)$$

# The platform to run on. It is made up of FPGA_MAIN_BOARD.EXPANSION_BOARD
Expand Down Expand Up @@ -275,7 +278,11 @@ gateware-clean:

# Firmware - the stuff which runs in the soft CPU inside the FPGA.
# --------------------------------------
firmware-cmd: litex-submodules
FIRMWARE_MODULES=libmodem
firmware-submodules: $(addsuffix /.git,$(addprefix third_party/,$(FIRMWARE_MODULES)))
@true

firmware-cmd: litex-submodules firmware-submodules
mkdir -p $(TARGET_BUILD_DIR)
ifneq ($(OS),Windows_NT)
$(MAKE_CMD) --no-compile-gateware \
Expand Down
9 changes: 7 additions & 2 deletions firmware/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ OBJECTS=\
encoder.o \
etherbone.o \
ethernet.o \
flash.o \
fx2.o \
hdmi_in0.o \
hdmi_out0.o \
Expand All @@ -40,6 +41,7 @@ OBJECTS=\
pll.o \
processor.o \
reboot.o \
spiflash.o \
stdio_wrap.o \
telnet.o \
tofe_eeprom.o \
Expand All @@ -52,7 +54,7 @@ OBJECTS=\

CFLAGS += \
-I$(FIRMWARE_DIRECTORY) \
-I$(BUILD_DIRECTORY)/software/firmware
-I$(BUILD_DIRECTORY)/software/firmware \

CFLAGS += \
-Wall \
Expand All @@ -62,6 +64,7 @@ CFLAGS += \


include $(UIP_DIRECTORY)/Makefile.mk
include $(MODEM_DIRECTORY)/Makefile.mk

LDFLAGS += \

Expand All @@ -87,7 +90,9 @@ firmware.elf: $(FIRMWARE_DIRECTORY)/linker.ld $(OBJECTS)
-L../libcompiler_rt \
-lcompiler_rt \
-L../uip \
-luip
-luip \
-L../modem \
-lmodem
chmod -x $@

# pull in dependency info for *existing* .o files
Expand Down
108 changes: 107 additions & 1 deletion firmware/ci.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "config.h"
#include "edid.h"
#include "encoder.h"
#include "flash.h"
#include "fx2.h"
#include "hdmi_in0.h"
#include "hdmi_in1.h"
Expand Down Expand Up @@ -174,6 +175,9 @@ static void help_debug(void)
#endif
wputs(" debug dna - show Board's DNA");
wputs(" debug edid <port> - dump monitor EDID");
#if defined(CSR_SPIFLASH_BASE) && defined(FLASH_BOOT_ADDRESS)
wputs(" debug spiflash - test bitbang write");
#endif
#ifdef CSR_CAS_BASE
wputs(" debug cas leds <value> - change the status LEDs");
wputs(" debug cas switches - read the control switches status");
Expand All @@ -182,6 +186,15 @@ static void help_debug(void)
#endif
}

static void help_write(void)
{
wputs("write commands");
#ifdef CSR_SPIFLASH_BASE
wputs(" write spi xmodem addr len - upload new spi flash firmware (xmodem)");
wputs(" write spi sfl addr len crc - upload new spi flash firmware (flterm)");
#endif
}

static void ci_help(void)
{
wputs("help - this command");
Expand Down Expand Up @@ -224,6 +237,7 @@ static void ci_help(void)
wputs("");
#endif
help_debug();
help_write();
}

static char *readstr(void)
Expand Down Expand Up @@ -1004,6 +1018,82 @@ static void debug_ddr(void)
}
#endif

#undef NEXT_TOKEN_OR_RETURN
#define NEXT_TOKEN_OR_RETURN(s, t, reason) \
if(!(t = get_token(&s))) { \
wprintf("Parse failed - " reason " \r\n"); \
return; \
}

#ifdef CSR_SPIFLASH_BASE
static void write_spi(char* str)
{
char *token;
int rc = 0;
char * endptr;
unsigned long addr;
unsigned long len;
unsigned long crc;
int use_xmodem = 0, use_sfl = 0;
char * proto_str;

token = get_token(&str);

if(strcmp(token, "xmodem") == 0) {
use_xmodem = 1;
proto_str = "xmodem";
}
else if(strcmp(token, "sfl") == 0) {
use_sfl = 1;
proto_str = "sfl";
}
else {
wprintf("Protocol not supported.\r\n");
return;
}

NEXT_TOKEN_OR_RETURN(str, token, "Invalid address.");
addr = strtoul(token, &endptr, 0);
if(*endptr != '\0') {
wprintf("Invalid chars in address.");
return;
}

NEXT_TOKEN_OR_RETURN(str, token, "Invalid length.");
len = strtoul(token, &endptr, 0);
if(*endptr != '\0') {
wprintf("Invalid chars in length.");
return;
}

NEXT_TOKEN_OR_RETURN(str, token, "Invalid CRC.");
crc = strtoul(token, &endptr, 0);
if(*endptr != '\0') {
wprintf("Invalid chars in CRC.");
return;
}

wprintf("Will use %s with addr %lX, len %ld and crc %lX.\r\n", proto_str, addr, len, crc);
if(use_xmodem)
rc = write_xmodem(addr, len, crc);
else if(use_sfl)
rc = write_sfl(addr, len, crc);
else
rc = -3;

if(rc == 0)
wprintf("New firmware written successfully.\r\n");
else if(rc == -1)
wprintf("CRC error transmitting firmware.\r\n");
else if(rc == -2)
wprintf("Flash comparison with in-memory image failed.\r\n");
else
wprintf("Unspecified error: %d\r\n", rc);

return;
}
#endif

void ci_prompt(void)
{
wprintf("H2U %s>", uptime_str());
Expand Down Expand Up @@ -1052,6 +1142,8 @@ void ci_service(void)
#endif
else if(strcmp(token, "debug") == 0)
help_debug();
else if(strcmp(token, "write") == 0)
help_write();
else
ci_help();
wputs("");
Expand Down Expand Up @@ -1302,6 +1394,10 @@ void ci_service(void)
#endif
if(found == 0)
wprintf("no such port\n");
#if defined(CSR_SPIFLASH_BASE) && defined(FLASH_BOOT_ADDRESS)
} else if(strcmp(token, "spiflash") == 0) {
bitbang_test();
#endif
#ifdef CSR_CAS_BASE
} else if(strcmp(token, "cas") == 0) {
token = get_token(&str);
Expand Down Expand Up @@ -1331,7 +1427,17 @@ void ci_service(void)
#endif
} else
help_debug();

} else if(strcmp(token, "write") == 0) {
token = get_token(&str);
if(false) { } // XXX: Replace with "command not supported?" if
// CSR_SPIFLASH_BASE isn't defined?
#ifdef CSR_SPIFLASH_BASE
else if((strcmp(token, "spi") == 0) ) {
write_spi(str);
}
#endif
else
help_write();
} else if(strcmp(token, "version") == 0) {
print_version();
} else {
Expand Down
Loading