[U-Boot] [PATCH] NIOS2: Added DE2 board with SD support

ivanchuklist ivanchu ivanchuklist at gmail.com
Mon Dec 22 22:25:16 CET 2008


Hi list,
I wrote about my work with u-boot in the thread "[U-Boot] DE2 board with MMC
interface (PIO based) and FAT support enabled" and i decided to post a
patch. I would like to discuss the changes.
I have changed the Makefile to match the binutils provided by Altera and i
added the DE2 board.
I have also made changes to the files cmd_mem.c to add one more command
"dmmc". Because the SD card is not a memory mapped device in the bus like a
flash memory, we can't deduce the direction of data (i mean when copying
data to sd or from sd) with the function mmc2info(). I tried to solve this
trick by using the command dmmc.
I found problems at link level with cmd_mmc.o and cmd_mem.o because both
files includes mmc.h, then i have two copies of the same functions in both
objects files. I solved this problem by declaring extern the function
mmc_init in cmd_mmc.c.
I think i should post the file include/asm-nios2/arch-nios2/mmc.h and the
board related files but i will wait your response.
In include/asm-nios2/arch-nios2/mmc.h i implemented mmc_get_dev() and
mmc_read_block() to provide access to the FAT table.
The code is working with all the examples distributed by Altera in the DE2
board and it should work with any SD socket interfaced by PIO cores.

diff --git a/Makefile b/Makefile
index 4df4812..6501d08 100644
--- a/Makefile
+++ b/Makefile
@@ -163,7 +163,7 @@ ifeq ($(ARCH),nios)
 CROSS_COMPILE = nios-elf-
 endif
 ifeq ($(ARCH),nios2)
-CROSS_COMPILE = nios2-elf-
+CROSS_COMPILE = nios2-linux-
 endif
 ifeq ($(ARCH),m68k)
 CROSS_COMPILE = m68k-elf-
@@ -3137,6 +3137,9 @@ PK1C20_config : unconfig
 PCI5441_config : unconfig
     @$(MKCONFIG)  PCI5441 nios2 nios2 pci5441 psyent

+DE2_config : unconfig
+    @$(MKCONFIG)  DE2 nios2 nios2 de2 altera
+
 #========================================================================
 ## Microblaze
 #========================================================================
diff --git a/common/cmd_mem.c b/common/cmd_mem.c
index 400cfd7..4585795 100644
--- a/common/cmd_mem.c
+++ b/common/cmd_mem.c
@@ -53,6 +53,7 @@ uint    dp_last_length = 0x40;
 uint    mm_last_addr, mm_last_size;

 static    ulong    base_address = 0;
+static    ulong    mmc_direction = 0;

 /* Memory Display
  *
@@ -355,6 +356,17 @@ int do_mem_cmp (cmd_tbl_t *cmdtp, int flag, int argc,
char *argv[])
     return rcode;
 }

+int do_dmmc( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
+{
+    if (argc > 1)
+        mmc_direction = simple_strtoul(argv[1], NULL, 10);
+    if (mmc_direction)
+        printf("Mem to mmc\n");
+    else
+        printf("Mmc to mem\n");
+    return 0;
+}
+
 int do_mem_cp ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 {
     ulong    addr, dest, count;
@@ -405,7 +417,7 @@ int do_mem_cp ( cmd_tbl_t *cmdtp, int flag, int argc,
char *argv[])
 #endif

 #if defined(CONFIG_CMD_MMC)
-    if (mmc2info(dest)) {
+    if (mmc_direction) {
         int rc;

         puts ("Copy to MMC... ");
@@ -422,9 +434,7 @@ int do_mem_cp ( cmd_tbl_t *cmdtp, int flag, int argc,
char *argv[])
         }
         puts ("done\n");
         return 0;
-    }
-
-    if (mmc2info(addr)) {
+    } else {
         int rc;

         puts ("Copy from MMC... ");
@@ -1221,6 +1231,14 @@ U_BOOT_CMD(
     "[.b, .w, .l] address value [count]\n    - write memory\n"
 );

+#if defined(CONFIG_CMD_MMC)
+U_BOOT_CMD(
+    dmmc,    2,    1,    do_dmmc,
+    "dmmc    - set mmc-memory copy direction\n",
+    "direction\n    - copy mmc<->mem\n"
+);
+#endif
+
 U_BOOT_CMD(
     cp,    4,    1,    do_mem_cp,
     "cp    - memory copy\n",
diff --git a/common/cmd_mmc.c b/common/cmd_mmc.c
index 25c9702..c9a5ac6 100644
--- a/common/cmd_mmc.c
+++ b/common/cmd_mmc.c
@@ -23,7 +23,8 @@

 #include <common.h>
 #include <command.h>
-#include <mmc.h>
+
+extern int mmc_init(int);

 int do_mmc (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 {
@@ -31,6 +32,7 @@ int do_mmc (cmd_tbl_t *cmdtp, int flag, int argc, char
*argv[])
         printf ("No MMC card found\n");
         return 1;
     }
+    printf ("MMC card found\n");
     return 0;
 }


More information about the U-Boot mailing list