summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/Makefile4
-rw-r--r--common/board_f.c2
-rw-r--r--common/bootm_os.c5
-rw-r--r--common/main.c6
-rw-r--r--common/spl/spl_fat.c36
-rw-r--r--common/spl/spl_fit.c76
-rw-r--r--common/spl/spl_mmc.c1
-rw-r--r--common/spl/spl_nand.c37
-rw-r--r--common/spl/spl_ymodem.c98
9 files changed, 214 insertions, 51 deletions
diff --git a/common/Makefile b/common/Makefile
index 0562d5c..1557a04 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -26,8 +26,8 @@ obj-y += bootretry.o
endif
# boards
-obj-$(CONFIG_SYS_GENERIC_BOARD) += board_f.o
-obj-$(CONFIG_SYS_GENERIC_BOARD) += board_r.o
+obj-y += board_f.o
+obj-y += board_r.o
obj-$(CONFIG_DISPLAY_BOARDINFO) += board_info.o
obj-$(CONFIG_DISPLAY_BOARDINFO_LATE) += board_info.o
diff --git a/common/board_f.c b/common/board_f.c
index 109025a..d405b5b 100644
--- a/common/board_f.c
+++ b/common/board_f.c
@@ -274,7 +274,7 @@ static int setup_mon_len(void)
gd->mon_len = CONFIG_SYS_MONITOR_LEN;
#elif defined(CONFIG_NDS32)
gd->mon_len = (ulong)(&__bss_end) - (ulong)(&_start);
-#else
+#elif defined(CONFIG_SYS_MONITOR_BASE)
/* TODO: use (ulong)&__bss_end - (ulong)&__text_start; ? */
gd->mon_len = (ulong)&__bss_end - CONFIG_SYS_MONITOR_BASE;
#endif
diff --git a/common/bootm_os.c b/common/bootm_os.c
index cb83f4a..9ec84bd 100644
--- a/common/bootm_os.c
+++ b/common/bootm_os.c
@@ -484,9 +484,8 @@ int boot_selected_os(int argc, char * const argv[], int state,
state == BOOTM_STATE_OS_FAKE_GO) /* We expect to return */
return 0;
bootstage_error(BOOTSTAGE_ID_BOOT_OS_RETURNED);
-#ifdef DEBUG
- puts("\n## Control returned to monitor - resetting...\n");
-#endif
+ debug("\n## Control returned to monitor - resetting...\n");
+
return BOOTM_ERR_RESET;
}
diff --git a/common/main.c b/common/main.c
index 42bbb50..2116a9e 100644
--- a/common/main.c
+++ b/common/main.c
@@ -47,12 +47,6 @@ void main_loop(void)
bootstage_mark_name(BOOTSTAGE_ID_MAIN_LOOP, "main_loop");
-#ifndef CONFIG_SYS_GENERIC_BOARD
- puts("Warning: Your board does not use generic board. Please read\n");
- puts("doc/README.generic-board and take action. Boards not\n");
- puts("upgraded by the late 2014 may break or be removed.\n");
-#endif
-
#ifdef CONFIG_VERSION_VARIABLE
setenv("ver", version_string); /* set version variable */
#endif /* CONFIG_VERSION_VARIABLE */
diff --git a/common/spl/spl_fat.c b/common/spl/spl_fat.c
index 5b0d969..db67618 100644
--- a/common/spl/spl_fat.c
+++ b/common/spl/spl_fat.c
@@ -15,6 +15,7 @@
#include <fat.h>
#include <errno.h>
#include <image.h>
+#include <libfdt.h>
static int fat_registered;
@@ -39,6 +40,20 @@ static int spl_register_fat_device(struct blk_desc *block_dev, int partition)
return err;
}
+static ulong spl_fit_read(struct spl_load_info *load, ulong file_offset,
+ ulong size, void *buf)
+{
+ loff_t actread;
+ int ret;
+ char *filename = (char *)load->filename;
+
+ ret = fat_read_file(filename, buf, file_offset, size, &actread);
+ if (ret)
+ return ret;
+
+ return actread;
+}
+
int spl_load_image_fat(struct blk_desc *block_dev,
int partition,
const char *filename)
@@ -57,11 +72,24 @@ int spl_load_image_fat(struct blk_desc *block_dev,
if (err <= 0)
goto end;
- err = spl_parse_image_header(header);
- if (err)
- goto end;
+ if (IS_ENABLED(CONFIG_SPL_LOAD_FIT) &&
+ image_get_magic(header) == FDT_MAGIC) {
+ struct spl_load_info load;
+
+ debug("Found FIT\n");
+ load.read = spl_fit_read;
+ load.bl_len = 1;
+ load.filename = (void *)filename;
+ load.priv = NULL;
- err = file_fat_read(filename, (u8 *)spl_image.load_addr, 0);
+ return spl_load_simple_fit(&load, 0, header);
+ } else {
+ err = spl_parse_image_header(header);
+ if (err)
+ goto end;
+
+ err = file_fat_read(filename, (u8 *)spl_image.load_addr, 0);
+ }
end:
#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
diff --git a/common/spl/spl_fit.c b/common/spl/spl_fit.c
index 26842ba..a828f72 100644
--- a/common/spl/spl_fit.c
+++ b/common/spl/spl_fit.c
@@ -67,9 +67,7 @@ static int spl_fit_select_fdt(const void *fdt, int images, int *fdt_offsetp)
*fdt_offsetp = fdt_getprop_u32(fdt, fdt_node, "data-offset");
len = fdt_getprop_u32(fdt, fdt_node, "data-size");
-#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
- printf("FIT: Selected '%s'\n", name);
-#endif
+ debug("FIT: Selected '%s'\n", name);
return len;
}
@@ -87,6 +85,42 @@ static int spl_fit_select_fdt(const void *fdt, int images, int *fdt_offsetp)
return -ENOENT;
}
+static int get_aligned_image_offset(struct spl_load_info *info, int offset)
+{
+ /*
+ * If it is a FS read, get the first address before offset which is
+ * aligned to ARCH_DMA_MINALIGN. If it is raw read return the
+ * block number to which offset belongs.
+ */
+ if (info->filename)
+ return offset & ~(ARCH_DMA_MINALIGN - 1);
+
+ return offset / info->bl_len;
+}
+
+static int get_aligned_image_overhead(struct spl_load_info *info, int offset)
+{
+ /*
+ * If it is a FS read, get the difference between the offset and
+ * the first address before offset which is aligned to
+ * ARCH_DMA_MINALIGN. If it is raw read return the offset within the
+ * block.
+ */
+ if (info->filename)
+ return offset & (ARCH_DMA_MINALIGN - 1);
+
+ return offset % info->bl_len;
+}
+
+static int get_aligned_image_size(struct spl_load_info *info, int data_size,
+ int offset)
+{
+ if (info->filename)
+ return data_size + get_aligned_image_overhead(info, offset);
+
+ return (data_size + info->bl_len - 1) / info->bl_len;
+}
+
int spl_load_simple_fit(struct spl_load_info *info, ulong sector, void *fit)
{
int sectors;
@@ -96,7 +130,7 @@ int spl_load_simple_fit(struct spl_load_info *info, ulong sector, void *fit)
void *load_ptr;
int fdt_offset, fdt_len;
int data_offset, data_size;
- int base_offset;
+ int base_offset, align_len = ARCH_DMA_MINALIGN - 1;
int src_sector;
void *dst;
@@ -123,7 +157,8 @@ int spl_load_simple_fit(struct spl_load_info *info, ulong sector, void *fit)
* be before CONFIG_SYS_TEXT_BASE.
*/
fit = (void *)(CONFIG_SYS_TEXT_BASE - size - info->bl_len);
- sectors = (size + info->bl_len - 1) / info->bl_len;
+ fit = (void *)ALIGN((ulong)fit, 8);
+ sectors = get_aligned_image_size(info, size, 0);
count = info->read(info, sector, sectors, fit);
debug("fit read sector %lx, sectors=%d, dst=%p, count=%lu\n",
sector, sectors, fit, count);
@@ -156,19 +191,23 @@ int spl_load_simple_fit(struct spl_load_info *info, ulong sector, void *fit)
* byte will be at 'load'. This may mean we need to load it starting
* before then, since we can only read whole blocks.
*/
- sectors = (data_size + info->bl_len - 1) / info->bl_len;
data_offset += base_offset;
+ sectors = get_aligned_image_size(info, data_size, data_offset);
load_ptr = (void *)load;
debug("U-Boot size %x, data %p\n", data_size, load_ptr);
- dst = load_ptr - (data_offset % info->bl_len);
+ dst = load_ptr;
/* Read the image */
- src_sector = sector + data_offset / info->bl_len;
- debug("image: data_offset=%x, dst=%p, src_sector=%x, sectors=%x\n",
- data_offset, dst, src_sector, sectors);
+ src_sector = sector + get_aligned_image_offset(info, data_offset);
+ debug("Aligned image read: dst=%p, src_sector=%x, sectors=%x\n",
+ dst, src_sector, sectors);
count = info->read(info, src_sector, sectors, dst);
if (count != sectors)
return -EIO;
+ debug("image: dst=%p, data_offset=%x, size=%x\n", dst, data_offset,
+ data_size);
+ memcpy(dst, dst + get_aligned_image_overhead(info, data_offset),
+ data_size);
/* Figure out which device tree the board wants to use */
fdt_len = spl_fit_select_fdt(fit, images, &fdt_offset);
@@ -178,13 +217,15 @@ int spl_load_simple_fit(struct spl_load_info *info, ulong sector, void *fit)
/*
* Read the device tree and place it after the image. There may be
* some extra data before it since we can only read entire blocks.
+ * And also align the destination address to ARCH_DMA_MINALIGN.
*/
- dst = load_ptr + data_size;
+ dst = (void *)((load + data_size + align_len) & ~align_len);
fdt_offset += base_offset;
- count = info->read(info, sector + fdt_offset / info->bl_len, sectors,
- dst);
- debug("fit read %x sectors to %x, dst %p, data_offset %x\n",
- sectors, spl_image.load_addr, dst, fdt_offset);
+ sectors = get_aligned_image_size(info, fdt_len, fdt_offset);
+ src_sector = sector + get_aligned_image_offset(info, fdt_offset);
+ count = info->read(info, src_sector, sectors, dst);
+ debug("Aligned fdt read: dst %p, src_sector = %x, sectors %x\n",
+ dst, src_sector, sectors);
if (count != sectors)
return -EIO;
@@ -193,7 +234,10 @@ int spl_load_simple_fit(struct spl_load_info *info, ulong sector, void *fit)
* After this we will have the U-Boot image and its device tree ready
* for us to start.
*/
- memcpy(dst, dst + fdt_offset % info->bl_len, fdt_len);
+ debug("fdt: dst=%p, data_offset=%x, size=%x\n", dst, fdt_offset,
+ fdt_len);
+ memcpy(load_ptr + data_size,
+ dst + get_aligned_image_overhead(info, fdt_offset), fdt_len);
return 0;
}
diff --git a/common/spl/spl_mmc.c b/common/spl/spl_mmc.c
index 6adfc9b..ef8583a 100644
--- a/common/spl/spl_mmc.c
+++ b/common/spl/spl_mmc.c
@@ -76,6 +76,7 @@ static int mmc_load_image_raw_sector(struct mmc *mmc, unsigned long sector)
debug("Found FIT\n");
load.dev = mmc;
load.priv = NULL;
+ load.filename = NULL;
load.bl_len = mmc->read_bl_len;
load.read = h_spl_load_read;
ret = spl_load_simple_fit(&load, sector, header);
diff --git a/common/spl/spl_nand.c b/common/spl/spl_nand.c
index bbd9546..7cf0d1b 100644
--- a/common/spl/spl_nand.c
+++ b/common/spl/spl_nand.c
@@ -9,6 +9,8 @@
#include <spl.h>
#include <asm/io.h>
#include <nand.h>
+#include <libfdt_env.h>
+#include <fdt.h>
#if defined(CONFIG_SPL_NAND_RAW_ONLY)
int spl_nand_load_image(void)
@@ -24,6 +26,19 @@ int spl_nand_load_image(void)
return 0;
}
#else
+
+static ulong spl_nand_fit_read(struct spl_load_info *load, ulong offs,
+ ulong size, void *dst)
+{
+ int ret;
+
+ ret = nand_spl_load_image(offs, size, dst);
+ if (!ret)
+ return size;
+ else
+ return 0;
+}
+
static int spl_nand_load_element(int offset, struct image_header *header)
{
int err;
@@ -32,12 +47,24 @@ static int spl_nand_load_element(int offset, struct image_header *header)
if (err)
return err;
- err = spl_parse_image_header(header);
- if (err)
- return err;
+ if (IS_ENABLED(CONFIG_SPL_LOAD_FIT) &&
+ image_get_magic(header) == FDT_MAGIC) {
+ struct spl_load_info load;
- return nand_spl_load_image(offset, spl_image.size,
- (void *)(unsigned long)spl_image.load_addr);
+ debug("Found FIT\n");
+ load.dev = NULL;
+ load.priv = NULL;
+ load.filename = NULL;
+ load.bl_len = 1;
+ load.read = spl_nand_fit_read;
+ return spl_load_simple_fit(&load, offset, header);
+ } else {
+ err = spl_parse_image_header(header);
+ if (err)
+ return err;
+ return nand_spl_load_image(offset, spl_image.size,
+ (void *)(ulong)spl_image.load_addr);
+ }
}
int spl_nand_load_image(void)
diff --git a/common/spl/spl_ymodem.c b/common/spl/spl_ymodem.c
index 4f26ea5..5402301 100644
--- a/common/spl/spl_ymodem.c
+++ b/common/spl/spl_ymodem.c
@@ -14,15 +14,60 @@
#include <xyzModem.h>
#include <asm/u-boot.h>
#include <asm/utils.h>
+#include <libfdt.h>
#define BUF_SIZE 1024
+/*
+ * Information required to load image using ymodem.
+ *
+ * @image_read: Now of bytes read from the image.
+ * @buf: pointer to the previous read block.
+ */
+struct ymodem_fit_info {
+ int image_read;
+ char *buf;
+};
+
static int getcymodem(void) {
if (tstc())
return (getc());
return -1;
}
+static ulong ymodem_read_fit(struct spl_load_info *load, ulong offset,
+ ulong size, void *addr)
+{
+ int res, err;
+ struct ymodem_fit_info *info = load->priv;
+ char *buf = info->buf;
+
+ while (info->image_read < offset) {
+ res = xyzModem_stream_read(buf, BUF_SIZE, &err);
+ if (res <= 0)
+ return res;
+ info->image_read += res;
+ }
+
+ if (info->image_read > offset) {
+ res = info->image_read - offset;
+ memcpy(addr, &buf[BUF_SIZE - res], res);
+ addr = addr + res;
+ }
+
+ while (info->image_read < offset + size) {
+ res = xyzModem_stream_read(buf, BUF_SIZE, &err);
+ if (res <= 0)
+ return res;
+
+ memcpy(addr, buf, res);
+ info->image_read += res;
+ addr += res;
+ }
+
+ return size;
+}
+
int spl_ymodem_load_image(void)
{
int size = 0;
@@ -31,30 +76,55 @@ int spl_ymodem_load_image(void)
int ret;
connection_info_t info;
char buf[BUF_SIZE];
- ulong store_addr = ~0;
ulong addr = 0;
info.mode = xyzModem_ymodem;
ret = xyzModem_stream_open(&info, &err);
+ if (ret) {
+ printf("spl: ymodem err - %s\n", xyzModem_error(err));
+ return ret;
+ }
+
+ res = xyzModem_stream_read(buf, BUF_SIZE, &err);
+ if (res <= 0)
+ goto end_stream;
+
+ if (IS_ENABLED(CONFIG_SPL_LOAD_FIT) &&
+ image_get_magic((struct image_header *)buf) == FDT_MAGIC) {
+ struct spl_load_info load;
+ struct ymodem_fit_info info;
+
+ debug("Found FIT\n");
+ load.dev = NULL;
+ load.priv = (void *)&info;
+ load.filename = NULL;
+ load.bl_len = 1;
+ info.buf = buf;
+ info.image_read = BUF_SIZE;
+ load.read = ymodem_read_fit;
+ ret = spl_load_simple_fit(&load, 0, (void *)buf);
+ size = info.image_read;
- if (!ret) {
- while ((res =
- xyzModem_stream_read(buf, BUF_SIZE, &err)) > 0) {
- if (addr == 0) {
- ret = spl_parse_image_header((struct image_header *)buf);
- if (ret)
- return ret;
- }
- store_addr = addr + spl_image.load_addr;
+ while ((res = xyzModem_stream_read(buf, BUF_SIZE, &err)) > 0)
+ size += res;
+ } else {
+ spl_parse_image_header((struct image_header *)buf);
+ ret = spl_parse_image_header((struct image_header *)buf);
+ if (ret)
+ return ret;
+ addr = spl_image.load_addr;
+ memcpy((void *)addr, buf, res);
+ size += res;
+ addr += res;
+
+ while ((res = xyzModem_stream_read(buf, BUF_SIZE, &err)) > 0) {
+ memcpy((void *)addr, buf, res);
size += res;
addr += res;
- memcpy((char *)(store_addr), buf, res);
}
- } else {
- printf("spl: ymodem err - %s\n", xyzModem_error(err));
- return ret;
}
+end_stream:
xyzModem_stream_close(&err);
xyzModem_stream_terminate(false, &getcymodem);