diff --git a/Config.in.app-image b/Config.in.app-image index 0dbda3ab1..312cb3f4e 100644 --- a/Config.in.app-image +++ b/Config.in.app-image @@ -7,14 +7,14 @@ menu "Demo Application Image Storage Setup" config IMG_ADDRESS string "Flash Offset for Demo-App" - depends on DATAFLASH || FLASH || NANDFLASH + depends on DATAFLASH || FLASH || NANDFLASH || (SDCARD && !FATFS) default "0x00008400" if DATAFLASH default "0x00040000" if NANDFLASH default "0x00000000" if SDCARD config IMG_SIZE string "Demo-App Image Size" - depends on DATAFLASH || FLASH || NANDFLASH + depends on DATAFLASH || FLASH || NANDFLASH || (SDCARD && !FATFS) default "0x00010000" if LOAD_64KB default "0x00100000" if LOAD_1MB default "0x00400000" if LOAD_4MB diff --git a/Config.in.kernel b/Config.in.kernel index f10488b4d..67dfb3deb 100644 --- a/Config.in.kernel +++ b/Config.in.kernel @@ -86,7 +86,7 @@ config LINUX_KERNEL_ARG_STRING_FILE endif config IMG_ADDRESS - depends on DATAFLASH || FLASH || NANDFLASH + depends on DATAFLASH || FLASH || NANDFLASH || (SDCARD && !FATFS) string "Flash Offset for Linux Kernel Image" default "0x00200000" if FLASH default "0x00040000" if DATAFLASH @@ -109,11 +109,11 @@ config OF_LIBFDT config OF_OVERRIDE_DTB_NAME string "Override Flattened Device Tree Blob filename" - depends on OF_LIBFDT && SDCARD + depends on OF_LIBFDT && (SDCARD && !FATFS) config OF_OFFSET string "The Offset of Flash Device Tree Blob" - depends on OF_LIBFDT && (DATAFLASH || FLASH || NANDFLASH) + depends on OF_LIBFDT && (DATAFLASH || FLASH || NANDFLASH || (SDCARD && !FATFS)) default "0x00008400" if DATAFLASH default "0x00180000" if NANDFLASH default "0x00100000" if FLASH diff --git a/Config.in.u-boot b/Config.in.u-boot index f65b207e6..0dad71c4f 100644 --- a/Config.in.u-boot +++ b/Config.in.u-boot @@ -7,7 +7,7 @@ menu "U-Boot Image Storage Setup" config IMG_ADDRESS string "Flash Offset for U-Boot" - depends on DATAFLASH || FLASH || NANDFLASH + depends on DATAFLASH || FLASH || NANDFLASH || (SDCARD && !FATFS) default "0x00008000" if FLASH default "0x00008000" if DATAFLASH default "0x00040000" if NANDFLASH @@ -16,7 +16,7 @@ config IMG_ADDRESS config IMG_SIZE string "U-Boot Image Size" - depends on DATAFLASH || FLASH || NANDFLASH + depends on DATAFLASH || FLASH || NANDFLASH || (SDCARD && !FATFS) default "0x000a0000" help at91bootstrap will copy this size of U-Boot image diff --git a/driver/Config.in.nvm b/driver/Config.in.nvm index 5fa474b87..90dc7e49b 100644 --- a/driver/Config.in.nvm +++ b/driver/Config.in.nvm @@ -112,9 +112,12 @@ config SDHC_8BIT_SUPPORT used for another interface. config FATFS - bool + bool "Load image from FAT partition" depends on SDCARD default y if SDCARD + help + Load next stage image from FAT12/16/32 partition. Otherwise from raw + block device, image offset must be a multiple 512 bytes. endmenu diff --git a/driver/common.c b/driver/common.c index 5a7598a9d..306667643 100644 --- a/driver/common.c +++ b/driver/common.c @@ -14,7 +14,7 @@ load_function load_image; #endif -#ifdef CONFIG_SDCARD +#if defined(CONFIG_SDCARD) && defined(CONFIG_FATFS) char filename[FILENAME_BUF_LEN]; #ifdef CONFIG_OF_LIBFDT char of_filename[FILENAME_BUF_LEN]; @@ -42,14 +42,14 @@ load_function get_image_load_func(void) #endif } -#if defined(CONFIG_DATAFLASH) || defined(CONFIG_NANDFLASH) || defined(CONFIG_FLASH) +#if defined(CONFIG_DATAFLASH) || defined(CONFIG_NANDFLASH) || defined(CONFIG_FLASH) || (defined(CONFIG_SDCARD) && !defined(CONFIG_FATFS)) unsigned int get_image_load_offset(unsigned int addr) { #ifdef CONFIG_FLASH return (addr | 0x10000000); #endif -#if defined(CONFIG_NANDFLASH) || defined(CONFIG_DATAFLASH) +#if defined(CONFIG_NANDFLASH) || defined(CONFIG_DATAFLASH) || defined(CONFIG_SDCARD) return addr; #endif } @@ -58,14 +58,14 @@ unsigned int get_image_load_offset(unsigned int addr) void init_load_image(struct image_info *image) { memset(image, 0, sizeof(*image)); -#ifdef CONFIG_SDCARD +#if defined(CONFIG_SDCARD) && defined(CONFIG_FATFS) memset(filename, 0, FILENAME_BUF_LEN); #ifdef CONFIG_OF_LIBFDT memset(of_filename, 0, FILENAME_BUF_LEN); #endif #endif -#if defined(CONFIG_DATAFLASH) || defined(CONFIG_NANDFLASH) || defined(CONFIG_FLASH) +#if defined(CONFIG_DATAFLASH) || defined(CONFIG_NANDFLASH) || defined(CONFIG_FLASH) || (defined(CONFIG_SDCARD) && !defined(CONFIG_FATFS)) #if !defined(CONFIG_LOAD_LINUX) && !defined(CONFIG_LOAD_ANDROID) image->length = IMG_SIZE; @@ -83,7 +83,7 @@ void init_load_image(struct image_info *image) image->of_dest = (unsigned char *)OF_ADDRESS; #endif -#ifdef CONFIG_SDCARD +#if defined(CONFIG_SDCARD) && defined(CONFIG_FATFS) image->filename = filename; strcpy(image->filename, IMAGE_NAME); #ifdef CONFIG_OF_LIBFDT diff --git a/driver/sdcard.c b/driver/sdcard.c index 0fbb19212..ee8a2197b 100644 --- a/driver/sdcard.c +++ b/driver/sdcard.c @@ -9,12 +9,18 @@ #include "string.h" +#ifdef CONFIG_FATFS #include "ff.h" +#else +#include "media.h" +#include "fdt.h" +#endif #include "debug.h" #define CHUNK_SIZE 0x40000 +#ifdef CONFIG_FATFS static int sdcard_loadimage(char *filename, BYTE *dest) { FIL file; @@ -81,7 +87,7 @@ static int sdcard_read_cmd(char *cmdline_file, char *cmdline_args) ret = -1; goto read_fail; } - + ret = 0; read_fail: @@ -92,11 +98,43 @@ static int sdcard_read_cmd(char *cmdline_file, char *cmdline_args) } #endif +#else +#if defined(CONFIG_LOAD_LINUX) || defined(CONFIG_LOAD_ANDROID) +static int update_image_length(unsigned int offset, + unsigned char *dest, + unsigned char flag) +{ + unsigned int length = 512; + int ret; + + dbg_info("SD/MMC: update image length from image\n"); + + memcpy(dest, (const char *)offset, length); + + if (flag == KERNEL_IMAGE) + return kernel_size(dest); +#ifdef CONFIG_OF_LIBFDT + else { + ret = check_dt_blob_valid((void *)dest); + if (!ret) + return of_get_dt_total_size((void *)dest); + } +#endif + return -1; +} +#endif +#endif + int load_sdcard(struct image_info *image) { +#ifdef CONFIG_FATFS FATFS fs; FRESULT fret; +#else + unsigned int start_block; + unsigned int block_count; +#endif int ret; #ifdef CONFIG_AT91_MCI @@ -113,6 +151,7 @@ int load_sdcard(struct image_info *image) at91_sdhc_hw_init(); #endif +#ifdef CONFIG_FATFS /* mount fs */ fret = f_mount(0, &fs); if (fret != FR_OK) { @@ -171,4 +210,54 @@ int load_sdcard(struct image_info *image) } return 0; +#else + ret = sdcard_initialize(); + if (ret) { + return ret; + } + +#if defined(CONFIG_LOAD_LINUX) || defined(CONFIG_LOAD_ANDROID) + int length = update_image_length(image->offset, image->dest, KERNEL_IMAGE); + if (length == -1) + return -1; + + image->length = length; +#endif + + dbg_info("SD/MMC: Copy %x bytes from %x to %x\n", + image->length, image->offset, image->dest); + + start_block = image->offset / 512; + block_count = (image->length + 511) / 512; + + ret = sdcard_block_read(start_block, block_count, image->dest); + ret = ret == block_count ? 0 : -1; + if (ret) { + return ret; + } + +#ifdef CONFIG_OF_LIBFDT + if(image->of_dest) { + length = update_image_length(image->of_offset, + image->of_dest, DT_BLOB); + if (length == -1) + return -1; + + image->of_length = length; + + dbg_info("SD/MMC: dt blob: Copy %x bytes from %x to %x\n", + image->of_length, image->of_offset, image->of_dest); + + start_block = image->of_offset / 512; + block_count = (image->of_length + 511) / 512; + + ret = sdcard_block_read(start_block, block_count, image->of_dest); + ret = ret == block_count ? 0 : -1; + if (ret) { + return ret; + } + } +#endif + return 0; +#endif } diff --git a/include/common.h b/include/common.h index 79eb73755..b32751cab 100644 --- a/include/common.h +++ b/include/common.h @@ -30,11 +30,11 @@ enum { /* structure definition */ struct image_info { -#if defined(CONFIG_DATAFLASH) || defined(CONFIG_NANDFLASH) || defined(CONFIG_FLASH) +#if defined(CONFIG_DATAFLASH) || defined(CONFIG_NANDFLASH) || defined(CONFIG_FLASH) || (defined(CONFIG_SDCARD) && !defined(CONFIG_FATFS)) unsigned int offset; unsigned int length; #endif -#ifdef CONFIG_SDCARD +#if defined(CONFIG_SDCARD) && defined(CONFIG_FATFS) char *filename; #ifdef CONFIG_OVERRIDE_CMDLINE_FROM_EXT_FILE char *cmdline_file; @@ -44,11 +44,11 @@ struct image_info unsigned char *dest; #ifdef CONFIG_OF_LIBFDT -#if defined(CONFIG_DATAFLASH) || defined(CONFIG_NANDFLASH) || defined(CONFIG_FLASH) +#if defined(CONFIG_DATAFLASH) || defined(CONFIG_NANDFLASH) || defined(CONFIG_FLASH) || (defined(CONFIG_SDCARD) && !defined(CONFIG_FATFS)) unsigned int of_offset; unsigned int of_length; #endif -#ifdef CONFIG_SDCARD +#if defined(CONFIG_SDCARD) && defined(CONFIG_FATFS) char *of_filename; #endif unsigned char *of_dest; @@ -61,7 +61,7 @@ typedef int (*load_function)(struct image_info *image); load_function get_image_load_func(void); -#if defined(CONFIG_DATAFLASH) || defined(CONFIG_NANDFLASH) || defined(CONFIG_FLASH) +#if defined(CONFIG_DATAFLASH) || defined(CONFIG_NANDFLASH) || defined(CONFIG_FLASH) || (defined(CONFIG_SDCARD) && !defined(CONFIG_FATFS)) unsigned int get_image_load_offset(unsigned int addr); #endif