software: create liblitespi and mode litespi code to it (with some parts commented...
authorFlorent Kermarrec <florent@enjoy-digital.fr>
Wed, 20 May 2020 07:32:45 +0000 (09:32 +0200)
committerFlorent Kermarrec <florent@enjoy-digital.fr>
Wed, 20 May 2020 07:32:45 +0000 (09:32 +0200)
litex/soc/integration/builder.py
litex/soc/software/bios/Makefile
litex/soc/software/bios/main.c
litex/soc/software/bios/spi.c [deleted file]
litex/soc/software/bios/spi.h [deleted file]
litex/soc/software/liblitespi/Makefile [new file with mode: 0644]
litex/soc/software/liblitespi/spiflash.c [new file with mode: 0644]
litex/soc/software/liblitespi/spiflash.h [new file with mode: 0644]

index 469f21108eadfa1c47c1bb0be29eacf626d47588..2c3044d27923dd25284ff26120281051939da2bf 100644 (file)
@@ -27,6 +27,7 @@ soc_software_packages = [
     "libbase",
     "liblitedram",
     "libliteeth",
+    "liblitespi",
     "liblitesdcard",
     "bios"
 ]
index a04a17b30c94b87656c96a6e35cfdb95670f4d0a..9782d0e31795120372f8c2253488a9853f1bcf18 100755 (executable)
@@ -62,6 +62,7 @@ bios.elf: $(BIOS_DIRECTORY)/linker.ld $(OBJECTS)
        ../libbase/libbase-nofloat.a \
        ../liblitedram/liblitedram.a \
        ../libliteeth/libliteeth.a \
+       ../liblitespi/liblitespi.a \
        ../liblitesdcard/liblitesdcard.a
        $(LD) $(LDFLAGS) -T $(BIOS_DIRECTORY)/linker.ld -N -o $@ \
                ../libbase/crt0-ctr.o \
@@ -70,9 +71,10 @@ bios.elf: $(BIOS_DIRECTORY)/linker.ld $(OBJECTS)
                -L../libbase \
                -L../liblitedram \
                -L../libliteeth \
+               -L../liblitespi \
                -L../liblitesdcard \
                $(BP_LIBS) \
-               -lcompiler_rt -llitedram -lliteeth -llitesdcard -lbase-nofloat \
+               -lcompiler_rt -llitedram -lliteeth -llitespi -llitesdcard -lbase-nofloat \
                $(BP_FLAGS)
 
 ifneq ($(OS),Windows_NT)
index e6765a59ccc3a86efe145fac39285670e2313432..9d1dc85bedef6025c9597d49d265c5364cfa6e25 100644 (file)
@@ -44,7 +44,7 @@
 
 #include "sdram.h"
 #include "sdcard.h"
-#include "spi.h"
+//#include "spi.h"
 #include "boot.h"
 #include "readline.h"
 #include "helpers.h"
@@ -135,9 +135,9 @@ int main(int i, char **c)
                printf("Memory initialization failed\n");
        printf("\n");
 #endif
-#ifdef CSR_SPI_BASE
-       spi_autoconfig();
-#endif
+//#ifdef CSR_SPI_BASE
+//     spi_autoconfig();
+//#endif
 
        if(sdr_ok) {
                printf("--============== \e[1mBoot\e[0m ==================--\n");
diff --git a/litex/soc/software/bios/spi.c b/litex/soc/software/bios/spi.c
deleted file mode 100644 (file)
index 23b677c..0000000
+++ /dev/null
@@ -1,83 +0,0 @@
-// This file is Copyright (c) 2020 Antmicro <www.antmicro.com>
-// License: BSD
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <crc.h>
-
-#include <generated/csr.h>
-#include <generated/mem.h>
-#include <hw/flags.h>
-#include <system.h>
-
-#include "spi.h"
-
-#define DEBUG  0
-#define USER_DEFINED_DUMMY_BITS        0
-
-static spi_mode spi_get_mode(void)
-{
-       return (spi_mode)spi_cfg_read();
-}
-
-static void spi_set_mode(spi_mode mode)
-{
-       spi_cfg_write((unsigned char)mode);
-}
-
-int spi_frequency_test(void)
-{
-       unsigned int lowest_div = spi_clk_divisor_read();
-       unsigned int crc = crc32((unsigned char *)SPIXIP_BASE, SPI_FLASH_BLOCK_SIZE);
-       unsigned int crc_test = crc;
-
-#if DEBUG
-       printf("Testing against CRC32: %08x\n\r", crc);
-#endif
-
-       if(spi_get_mode() != SPI_MODE_MMAP) {
-               spi_set_mode(SPI_MODE_MMAP);
-       }
-
-       /* Check if block is erased (filled with 0xFF) */
-       if(crc == CRC32_ERASED_FLASH) {
-               printf("Block of size %d, started on address 0x%x is erased. Cannot proceed with SPI frequency test.\n\r", SPI_FLASH_BLOCK_SIZE, SPIXIP_BASE);
-               return -1;
-       }
-
-       for(int i = lowest_div; (crc == crc_test) && (i >= 0); i--) {
-               lowest_div = i;
-               spi_clk_divisor_write((uint32_t)i);
-               crc_test = crc32((unsigned char *)SPIXIP_BASE, SPI_FLASH_BLOCK_SIZE);
-#if DEBUG
-               printf("[DIV: %d] %08x\n\r", i, crc_test);
-#endif
-       }
-       lowest_div++;
-       printf("Maximum available frequency: %d Hz\n\r", (spi_sys_clk_freq_read()/(2*(1 + lowest_div))));
-
-       return lowest_div;
-}
-
-void spi_dummy_bits_setup(unsigned int dummy_bits)
-{
-       spi_dummy_bits_write((uint32_t)dummy_bits);
-#if DEBUG
-       printf("Dummy bits set to: %d\n\r", spi_dummy_bits_read());
-#endif
-}
-
-void spi_autoconfig(void)
-{
-       int ret = spi_frequency_test();
-       if(ret < 0) {
-               return;
-       } else {
-               spi_clk_divisor_write((uint32_t)ret);
-       }
-#if (USER_DEFINED_DUMMY_BITS > 0)
-       spi_dummy_bits_setup(USER_DEFINED_DUMMY_BITS);
-#endif
-}
-
diff --git a/litex/soc/software/bios/spi.h b/litex/soc/software/bios/spi.h
deleted file mode 100644 (file)
index 961aef0..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-#ifndef __SPI_H
-#define __SPI_H
-
-#include <generated/csr.h>
-
-#define SPI_FLASH_BLOCK_SIZE   256
-#define CRC32_ERASED_FLASH     0xFEA8A821
-
-typedef enum {
-       SPI_MODE_MMAP = 0,
-       SPI_MODE_MASTER = 1,
-} spi_mode;
-
-int spi_frequency_test(void);
-void spi_dummy_bits_setup(unsigned int dummy_bits);
-void spi_autoconfig(void);
-
-#endif /* __SPI_H */
diff --git a/litex/soc/software/liblitespi/Makefile b/litex/soc/software/liblitespi/Makefile
new file mode 100644 (file)
index 0000000..74f0b13
--- /dev/null
@@ -0,0 +1,23 @@
+include ../include/generated/variables.mak
+include $(SOC_DIRECTORY)/software/common.mak
+
+OBJECTS=spiflash.o
+
+all: liblitespi.a
+
+liblitespi.a: $(OBJECTS)
+       $(AR) crs liblitespi.a $(OBJECTS)
+
+# pull in dependency info for *existing* .o files
+-include $(OBJECTS:.o=.d)
+
+%.o: $(LIBLITESPI_DIRECTORY)/%.c
+       $(compile)
+
+%.o: %.S
+       $(assemble)
+
+.PHONY: all clean
+
+clean:
+       $(RM) $(OBJECTS) liblitespi.a .*~ *~
diff --git a/litex/soc/software/liblitespi/spiflash.c b/litex/soc/software/liblitespi/spiflash.c
new file mode 100644 (file)
index 0000000..702c969
--- /dev/null
@@ -0,0 +1,86 @@
+// This file is Copyright (c) 2020 Antmicro <www.antmicro.com>
+// License: BSD
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <crc.h>
+
+#include <generated/csr.h>
+#include <generated/mem.h>
+#include <system.h>
+
+#include "spiflash.h"
+
+#ifdef SPIXIP_BASE
+
+#define DEBUG  0
+#define USER_DEFINED_DUMMY_BITS        0
+
+static spi_mode spi_get_mode(void)
+{
+       return (spi_mode)spi_cfg_read();
+}
+
+static void spi_set_mode(spi_mode mode)
+{
+       spi_cfg_write((unsigned char)mode);
+}
+
+int spi_frequency_test(void)
+{
+       unsigned int lowest_div = spi_clk_divisor_read();
+       unsigned int crc = crc32((unsigned char *)SPIXIP_BASE, SPI_FLASH_BLOCK_SIZE);
+       unsigned int crc_test = crc;
+
+#if DEBUG
+       printf("Testing against CRC32: %08x\n\r", crc);
+#endif
+
+       if(spi_get_mode() != SPI_MODE_MMAP) {
+               spi_set_mode(SPI_MODE_MMAP);
+       }
+
+       /* Check if block is erased (filled with 0xFF) */
+       if(crc == CRC32_ERASED_FLASH) {
+               printf("Block of size %d, started on address 0x%x is erased. Cannot proceed with SPI frequency test.\n\r", SPI_FLASH_BLOCK_SIZE, SPIXIP_BASE);
+               return -1;
+       }
+
+       for(int i = lowest_div; (crc == crc_test) && (i >= 0); i--) {
+               lowest_div = i;
+               spi_clk_divisor_write((uint32_t)i);
+               crc_test = crc32((unsigned char *)SPIXIP_BASE, SPI_FLASH_BLOCK_SIZE);
+#if DEBUG
+               printf("[DIV: %d] %08x\n\r", i, crc_test);
+#endif
+       }
+       lowest_div++;
+       printf("Maximum available frequency: %d Hz\n\r", (spi_sys_clk_freq_read()/(2*(1 + lowest_div))));
+
+       return lowest_div;
+}
+
+#endif
+
+void spi_dummy_bits_setup(unsigned int dummy_bits)
+{
+       spi_dummy_bits_write((uint32_t)dummy_bits);
+#if DEBUG
+       printf("Dummy bits set to: %d\n\r", spi_dummy_bits_read());
+#endif
+}
+
+void spi_autoconfig(void)
+{
+       int ret = spi_frequency_test();
+       if(ret < 0) {
+               return;
+       } else {
+               spi_clk_divisor_write((uint32_t)ret);
+       }
+#if (USER_DEFINED_DUMMY_BITS > 0)
+       spi_dummy_bits_setup(USER_DEFINED_DUMMY_BITS);
+#endif
+}
+
diff --git a/litex/soc/software/liblitespi/spiflash.h b/litex/soc/software/liblitespi/spiflash.h
new file mode 100644 (file)
index 0000000..b9d210c
--- /dev/null
@@ -0,0 +1,18 @@
+#ifndef __LITESPI_FLASH_H
+#define __LITESPI_FLASH_H
+
+#include <generated/csr.h>
+
+#define SPI_FLASH_BLOCK_SIZE   256
+#define CRC32_ERASED_FLASH     0xFEA8A821
+
+typedef enum {
+       SPI_MODE_MMAP = 0,
+       SPI_MODE_MASTER = 1,
+} spi_mode;
+
+int spi_frequency_test(void);
+void spi_dummy_bits_setup(unsigned int dummy_bits);
+void spi_autoconfig(void);
+
+#endif /* __LITESPI_FLASH_H */