Flash filesystem
authorlekernel <sebastien.bourdeauducq@lekernel.net>
Fri, 25 Jun 2010 18:37:35 +0000 (20:37 +0200)
committerlekernel <sebastien.bourdeauducq@lekernel.net>
Fri, 25 Jun 2010 18:37:35 +0000 (20:37 +0200)
16 files changed:
README
boards/milkymist-one/flash/Makefile
boards/milkymist-one/flash/flash.cmd [deleted file]
boards/milkymist-one/flash/flash_bios.cmd [new file with mode: 0644]
boards/milkymist-one/flash/flash_bitstream.cmd [new file with mode: 0644]
boards/milkymist-one/flash/flash_splash.cmd [new file with mode: 0644]
boards/milkymist-one/flash/flash_userfs.cmd [new file with mode: 0644]
software/bios/Makefile
software/demo/Makefile
software/demo/shell.c
software/include/base/blockdev.h [new file with mode: 0644]
software/include/base/fatfs.h
software/include/hw/flash.h
software/libbase/Makefile
software/libbase/blockdev.c [new file with mode: 0644]
software/libbase/fatfs.c

diff --git a/README b/README
index a9a29ea..943f532 100644 (file)
--- a/README
+++ b/README
@@ -26,10 +26,9 @@ You will need:
  - LatticeMico32 toolchain for building the SoC software,
  - SRecord,
  - xxd,
-For the host-side tools:
+ - mtools,
  - native Clang/LLVM toolchain,
  - libGD,
-For the demonstration firmware:
  - RE2C,
  - Lemon parser generator,
  - Scilab.
index d5b8216..99c3eba 100644 (file)
@@ -1,29 +1,55 @@
-all: bitstream.mcs bios.mcs splash.mcs
+MMDIR=../../..
+
+all: bitstream.mcs bios.mcs splash.mcs userfs.mcs
 
 bitstream.mcs:
-       make -C ../synthesis -f Makefile.xst
+       $(MAKE) -C ../synthesis -f Makefile.xst
        promgen -w -p mcs -o bitstream.mcs -s 32768 -u 0x00000000 ../synthesis/build/system.bit -bpi_dc parallel -data_width 16
 
 bios.mcs:
-       make -C ../../../software/bios
-       srec_cat -Output bios.mcs -Intel ../../../software/bios/bios.bin -Binary -offset 0x00180000
+       $(MAKE) -C $(MMDIR)/software/bios
+       srec_cat -Output bios.mcs -Intel $(MMDIR)/software/bios/bios.bin -Binary -offset 0x00180000
 
 splash.mcs: splash.raw
        srec_cat -Output splash.mcs -Intel splash.raw -Binary -offset 0x001C0000
 
+userfs.mcs: userfs.bin
+       srec_cat -Output userfs.mcs -Intel userfs.bin -Binary -offset 0x00260000
+
 splash.raw: splash.png
        $(MMDIR)/tools/makeraw splash.png
 
+userfs.bin:
+       $(MAKE) -C $(MMDIR)/software/demo
+       srec_cat -Output userfs.bin -Binary /dev/null -Binary -fill 0xFF 0x000000 0x300000
+       /sbin/mkdosfs -F 16 -s 1 userfs.bin
+       mcopy -i userfs.bin $(MMDIR)/patches/* $(MMDIR)/software/demo/boot.bin ::
+
 # Run the Xilinx crapware in a separate directory that we can simply rm -rf
 # to get rid of the garbage it puts all over the filesystem.
-flash: all
+flash_bitstream: bitstream.mcs
+       mkdir -p impact_sucks
+       cd impact_sucks && impact -batch ../flash_bitstream.cmd
+
+flash_bios: bios.mcs
        mkdir -p impact_sucks
-       cd impact_sucks && impact -batch ../flash.cmd
+       cd impact_sucks && impact -batch ../flash_bios.cmd
+
+flash_splash: splash.mcs
+       mkdir -p impact_sucks
+       cd impact_sucks && impact -batch ../flash_splash.cmd
+
+flash_userfs: userfs.mcs
+       mkdir -p impact_sucks
+       cd impact_sucks && impact -batch ../flash_userfs.cmd
+
+flash_all: flash_bitstream flash_bios flash_splash flash_userfs
 
 clean:
        rm -rf impact_sucks
        rm -f bitstream.mcs bitstream.prm bitstream.cfi
        rm -f bios.mcs
        rm -f splash.raw splash.mcs
+       rm -f userfs.bin userfs.mcs
 
-.PHONY: flash clean
+.PHONY: flash_bitstream flash_bios flash_splash flash_userfs flash_all clean
diff --git a/boards/milkymist-one/flash/flash.cmd b/boards/milkymist-one/flash/flash.cmd
deleted file mode 100644 (file)
index 011a576..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-setMode -bscan
-setCable -p auto
-identify -inferir
-identifyMPM
-attachflash -position 1 -bpi "28F256J3F"
-assignfiletoattachedflash -position 1 -file "../bitstream.mcs"
-program -p 1 -dataWidth 16 -rs1 NONE -rs0 NONE -bpionly -e
-assignfiletoattachedflash -position 1 -file "../bios.mcs"
-program -p 1 -dataWidth 16 -rs1 NONE -rs0 NONE -bpionly -e
-assignfiletoattachedflash -position 1 -file "../splash.mcs"
-program -p 1 -dataWidth 16 -rs1 NONE -rs0 NONE -bpionly -e
-quit
diff --git a/boards/milkymist-one/flash/flash_bios.cmd b/boards/milkymist-one/flash/flash_bios.cmd
new file mode 100644 (file)
index 0000000..f49aba0
--- /dev/null
@@ -0,0 +1,8 @@
+setMode -bscan
+setCable -p auto
+identify -inferir
+identifyMPM
+attachflash -position 1 -bpi "28F256J3F"
+assignfiletoattachedflash -position 1 -file "../bios.mcs"
+program -p 1 -dataWidth 16 -rs1 NONE -rs0 NONE -bpionly -e
+quit
diff --git a/boards/milkymist-one/flash/flash_bitstream.cmd b/boards/milkymist-one/flash/flash_bitstream.cmd
new file mode 100644 (file)
index 0000000..0b7d023
--- /dev/null
@@ -0,0 +1,8 @@
+setMode -bscan
+setCable -p auto
+identify -inferir
+identifyMPM
+attachflash -position 1 -bpi "28F256J3F"
+assignfiletoattachedflash -position 1 -file "../bitstream.mcs"
+program -p 1 -dataWidth 16 -rs1 NONE -rs0 NONE -bpionly -e
+quit
diff --git a/boards/milkymist-one/flash/flash_splash.cmd b/boards/milkymist-one/flash/flash_splash.cmd
new file mode 100644 (file)
index 0000000..cb41b78
--- /dev/null
@@ -0,0 +1,8 @@
+setMode -bscan
+setCable -p auto
+identify -inferir
+identifyMPM
+attachflash -position 1 -bpi "28F256J3F"
+assignfiletoattachedflash -position 1 -file "../splash.mcs"
+program -p 1 -dataWidth 16 -rs1 NONE -rs0 NONE -bpionly -e
+quit
diff --git a/boards/milkymist-one/flash/flash_userfs.cmd b/boards/milkymist-one/flash/flash_userfs.cmd
new file mode 100644 (file)
index 0000000..026d2eb
--- /dev/null
@@ -0,0 +1,8 @@
+setMode -bscan
+setCable -p auto
+identify -inferir
+identifyMPM
+attachflash -position 1 -bpi "28F256J3F"
+assignfiletoattachedflash -position 1 -file "../userfs.mcs"
+program -p 1 -dataWidth 16 -rs1 NONE -rs0 NONE -bpionly -e
+quit
index 0ba6fb8..9623b40 100644 (file)
@@ -52,7 +52,8 @@ main.o: ../../software/include/hw/common.h ../../software/include/hw/fmlbrg.h
 main.o: ../../software/include/hw/sysctl.h
 main.o: ../../software/include/hw/capabilities.h
 main.o: ../../software/include/hw/gpio.h ../../software/include/hw/uart.h
-main.o: ../../software/include/hw/hpdmc.h boot.h splash.h
+main.o: ../../software/include/hw/hpdmc.h ../../software/include/hw/flash.h
+main.o: boot.h splash.h
 splash.o: ../../software/include/base/stdio.h
 splash.o: ../../software/include/base/stdlib.h
 splash.o: ../../software/include/hw/vga.h ../../software/include/hw/common.h
index 03ca7bf..185c9c6 100644 (file)
@@ -112,6 +112,7 @@ shell.o: ../../software/include/base/stdlib.h
 shell.o: ../../software/include/base/string.h
 shell.o: ../../software/include/base/console.h
 shell.o: ../../software/include/base/uart.h
+shell.o: ../../software/include/base/blockdev.h
 shell.o: ../../software/include/base/fatfs.h
 shell.o: ../../software/include/base/system.h
 shell.o: ../../software/include/base/math.h ../../software/include/base/irq.h
index 1283d60..d5b7a66 100644 (file)
@@ -20,6 +20,7 @@
 #include <string.h>
 #include <console.h>
 #include <uart.h>
+#include <blockdev.h>
 #include <fatfs.h>
 #include <system.h>
 #include <math.h>
@@ -154,19 +155,27 @@ static int lscb(const char *filename, const char *longname, void *param)
 
 static void ls()
 {
-       fatfs_init();
+       if(!fatfs_init(BLOCKDEV_FLASH, 0)) return;
        fatfs_list_files(lscb, NULL);
        fatfs_done();
 }
 
 static void render(const char *filename)
 {
+       char buffer[8192];
+       int size;
+
        if(*filename == 0) {
                printf("render <filename>\n");
                return;
        }
 
-       /* TODO */
+       if(!fatfs_init(BLOCKDEV_FLASH, 0)) return;
+       if(!fatfs_load(filename, buffer, sizeof(buffer), &size)) return;
+       fatfs_done();
+       buffer[size] = 0;
+
+       renderer_start(buffer);
 }
 
 static void spam()
@@ -257,7 +266,7 @@ static void loadpic(const char *filename)
                return;
        }
 
-       if(!fatfs_init()) return;
+       if(!fatfs_init(BLOCKDEV_FLASH, 0)) return;
        if(!fatfs_load(filename, (void *)vga_backbuffer, vga_hres*vga_vres*2, &size)) return;
        fatfs_done();
 
diff --git a/software/include/base/blockdev.h b/software/include/base/blockdev.h
new file mode 100644 (file)
index 0000000..448b3c4
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * Milkymist VJ SoC (Software)
+ * Copyright (C) 2007, 2008, 2009, 2010 Sebastien Bourdeauducq
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __BLOCKDEV_H
+#define __BLOCKDEV_H
+
+enum {
+       BLOCKDEV_FLASH,
+       BLOCKDEV_MEMORY_CARD
+};
+
+int bd_init(int devnr);
+int bd_readblock(int block, void *buffer);
+void bd_done();
+
+#endif /* __BLOCKDEV_H */
index f8b71ba..4563b1c 100644 (file)
@@ -1,16 +1,16 @@
 /*
  * Milkymist VJ SoC (Software)
  * Copyright (C) 2007, 2008, 2009, 2010 Sebastien Bourdeauducq
- * 
+ *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation, version 3 of the License.
- * 
+ *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
@@ -20,7 +20,7 @@
 
 typedef int (*fatfs_dir_callback)(const char *, const char *, void *);
 
-int fatfs_init();
+int fatfs_init(int devnr, int has_part_table);
 int fatfs_list_files(fatfs_dir_callback cb, void *param);
 int fatfs_load(const char *filename, char *buffer, int size, int *realsize);
 void fatfs_done();
index 305fbb9..e62661e 100644 (file)
@@ -21,5 +21,6 @@
 #define FLASH_OFFSET_BITSTREAM (0x00000000)
 #define FLASH_OFFSET_BIOS      (0x00180000)
 #define FLASH_OFFSET_SPLASH    (0x001C0000)
+#define FLASH_OFFSET_USERFS    (0x00260000)
 
 #endif /* __HW_FLASH_H */
index 5f52852..8f18f15 100644 (file)
@@ -1,7 +1,7 @@
 MMDIR=../..
 include $(MMDIR)/software/include.mak
 
-OBJECTS_ALL=divsi3.o libc.o crc16.o crc32.o console.o fatfs.o system.o board.o irq.o
+OBJECTS_ALL=divsi3.o libc.o crc16.o crc32.o console.o blockdev.o fatfs.o system.o board.o irq.o
 OBJECTS=$(OBJECTS_ALL) softfloat.o softfloat-glue.o vsnprintf.o atof.o malloc.o uart-async.o
 OBJECTS_LIGHT=$(OBJECTS_ALL) vsnprintf-nofloat.o uart.o
 
@@ -27,6 +27,10 @@ clean:
 
 atof.o: ../../software/include/base/stdlib.h
 atof.o: ../../software/include/base/ctype.h
+blockdev.o: ../../software/include/hw/flash.h
+blockdev.o: ../../software/include/base/string.h
+blockdev.o: ../../software/include/base/stdlib.h
+blockdev.o: ../../software/include/base/blockdev.h
 board.o: ../../software/include/hw/sysctl.h
 board.o: ../../software/include/hw/common.h
 board.o: ../../software/include/base/stdlib.h
@@ -44,6 +48,7 @@ fatfs.o: ../../software/include/base/string.h
 fatfs.o: ../../software/include/base/ctype.h
 fatfs.o: ../../software/include/base/endian.h
 fatfs.o: ../../software/include/base/console.h
+fatfs.o: ../../software/include/base/blockdev.h
 fatfs.o: ../../software/include/base/fatfs.h
 libc.o: ../../software/include/base/ctype.h
 libc.o: ../../software/include/base/stdio.h
diff --git a/software/libbase/blockdev.c b/software/libbase/blockdev.c
new file mode 100644 (file)
index 0000000..40132df
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Milkymist VJ SoC (Software)
+ * Copyright (C) 2007, 2008, 2009, 2010 Sebastien Bourdeauducq
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <hw/flash.h>
+#include <string.h>
+
+#include <blockdev.h>
+
+int bd_init(int devnr)
+{
+       /* Only flash is supported for now */
+       if(devnr != BLOCKDEV_FLASH) return 0;
+       return 1;
+}
+
+int bd_readblock(int block, void *buffer)
+{
+       memcpy(buffer, (char *)(FLASH_OFFSET_USERFS + block*512), 512);
+       return 1;
+}
+
+void bd_done()
+{
+}
index c01b70c..7b3ed1f 100644 (file)
@@ -21,6 +21,8 @@
 #include <ctype.h>
 #include <endian.h>
 #include <console.h>
+#include <blockdev.h>
+
 #include <fatfs.h>
 
 //#define DEBUG
@@ -119,41 +121,44 @@ static struct directory_entry fatfs_dir_sector_cache[BLOCK_SIZE/sizeof(struct di
 
 static int fatfs_data_start_sector;
 
-int fatfs_init()
+int fatfs_init(int devnr, int has_part_table)
 {
        struct firstsector s0;
        struct fat16_firstsector s;
        int i;
 
-       if(/* !cf_init() */ 1) {
+       if(!bd_init(devnr)) {
                printf("E: Unable to initialize memory card driver\n");
                return 0;
        }
-       
-       /* Read sector 0, with partition table */
-       if(/* !cf_readblock(0, (void *)&s0) */ 1) {
-               printf("E: Unable to read block 0\n");
-               return 0;
-       }
 
-       fatfs_partition_start_sector = -1;
-       for(i=0;i<4;i++)
-               if((s0.partitions[i].type == PARTITION_TYPE_FAT16)
-                ||(s0.partitions[i].type == PARTITION_TYPE_FAT32)) {
+       if(has_part_table) {
+               /* Read sector 0, with partition table */
+               if(!bd_readblock(0, (void *)&s0)) {
+                       printf("E: Unable to read block 0\n");
+                       return 0;
+               }
+
+               fatfs_partition_start_sector = -1;
+               for(i=0;i<4;i++)
+                       if((s0.partitions[i].type == PARTITION_TYPE_FAT16)
+                       ||(s0.partitions[i].type == PARTITION_TYPE_FAT32)) {
 #ifdef DEBUG
-                       printf("I: Using partition #%d: start sector %08x, end sector %08x\n", i,
-                               le32toh(s0.partitions[i].start_sector), le32toh(s0.partitions[i].end_sector));
+                               printf("I: Using partition #%d: start sector %08x, end sector %08x\n", i,
+                                       le32toh(s0.partitions[i].start_sector), le32toh(s0.partitions[i].end_sector));
 #endif
-                       fatfs_partition_start_sector = le32toh(s0.partitions[i].start_sector);
-                       break;
+                               fatfs_partition_start_sector = le32toh(s0.partitions[i].start_sector);
+                               break;
+                       }
+               if(fatfs_partition_start_sector == -1) {
+                       printf("E: No FAT partition was found\n");
+                       return 0;
                }
-       if(fatfs_partition_start_sector == -1) {
-               printf("E: No FAT partition was found\n");
-               return 0;
-       }
+       } else
+               fatfs_partition_start_sector = 0;
        
        /* Read first FAT16 sector */
-       if(/* !cf_readblock(fatfs_partition_start_sector, (void *)&s) */ 1) {
+       if(!bd_readblock(fatfs_partition_start_sector, (void *)&s)) {
                printf("E: Unable to read first FAT sector\n");
                return 0;
        }
@@ -207,12 +212,14 @@ static int fatfs_read_fat(int offset)
 {
        int wanted_sector;
        
-       if((offset < 0) || (offset >= fatfs_fat_entries))
+       if((offset < 0) || (offset >= fatfs_fat_entries)) {
+               printf("E: Incorrect offset %d in fatfs_read_fat\n", offset);
                return -1;
+       }
                
        wanted_sector = fatfs_fat_sector + (offset*2)/BLOCK_SIZE;
        if(wanted_sector != fatfs_fat_cached_sector) {
-               if(/* !cf_readblock(wanted_sector, (void *)&fatfs_fat_sector_cache) */ 1) {
+               if(!bd_readblock(wanted_sector, (void *)&fatfs_fat_sector_cache)) {
                        printf("E: Memory card failed (FAT), sector %d\n", wanted_sector);
                        return -1;
                }
@@ -232,7 +239,7 @@ static const struct directory_entry *fatfs_read_root_directory(int offset)
        wanted_sector = fatfs_root_table_sector + (offset*sizeof(struct directory_entry))/BLOCK_SIZE;
 
        if(wanted_sector != fatfs_dir_cached_sector) {
-               if(/* !cf_readblock(wanted_sector, (void *)&fatfs_dir_sector_cache) */ 1) {
+               if(!bd_readblock(wanted_sector, (void *)&fatfs_dir_sector_cache)) {
                        printf("E: Memory card failed (Rootdir), sector %d\n", wanted_sector);
                        return NULL;
                }
@@ -386,7 +393,7 @@ static int fatfs_load_cluster(int clustern, char *buffer, int maxsectors)
        else
                toread = fatfs_sectors_per_cluster;
        for(i=0;i<toread;i++)
-               if(/* !cf_readblock(startsector+i, (unsigned char *)buffer+i*CF_BLOCK_SIZE) */ 1) {
+               if(!bd_readblock(startsector+i, (unsigned char *)buffer+i*BLOCK_SIZE)) {
                        printf("E: Memory card failed (Cluster), sector %d\n", startsector+i);
                        return 0;
                }
@@ -429,5 +436,5 @@ int fatfs_load(const char *filename, char *buffer, int size, int *realsize)
 
 void fatfs_done()
 {
-       /* cf_done(); */
+       bd_done();
 }