summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2018-06-11 22:36:28 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2018-06-11 22:36:28 +0200
commit8985573ad66c9fb011910a352b8c1427ee08ded3 (patch)
tree86eaba30b6363eeaba0d196f4e88d85958dc0e40
parent57c475b48dcf8e41ddaaa77686ea41adb9049dc5 (diff)
parentec4dca17bb6a0029466de80754a20fec13d0e111 (diff)
downloadbarebox-8985573ad66c9fb011910a352b8c1427ee08ded3.tar.gz
barebox-8985573ad66c9fb011910a352b8c1427ee08ded3.tar.xz
Merge branch 'for-next/mvebu'
-rw-r--r--arch/arm/mach-mvebu/common.c29
-rw-r--r--arch/arm/mach-mvebu/dove.c22
-rw-r--r--arch/arm/mach-mvebu/kwbootimage.c11
-rw-r--r--arch/arm/mach-omap/am33xx_bbu_nand.c38
-rw-r--r--common/filetype.c22
-rw-r--r--include/filetype.h1
-rw-r--r--include/libfile.h1
-rw-r--r--lib/libfile.c33
-rw-r--r--scripts/kwboot.c63
9 files changed, 146 insertions, 74 deletions
diff --git a/arch/arm/mach-mvebu/common.c b/arch/arm/mach-mvebu/common.c
index fa971da11e..83aeb41ae2 100644
--- a/arch/arm/mach-mvebu/common.c
+++ b/arch/arm/mach-mvebu/common.c
@@ -37,6 +37,10 @@
#define DOVE_SDRAM_MAP_VALID BIT(0)
#define DOVE_SDRAM_LENGTH_SHIFT 16
#define DOVE_SDRAM_LENGTH_MASK (0x00f << DOVE_SDRAM_LENGTH_SHIFT)
+#define DOVE_SDRAM_REGS_BASE_DECODE 0x10
+
+#define DOVE_CPU_CTRL (MVEBU_REMAP_INT_REG_BASE + 0xd025c)
+#define DOVE_AXI_CTRL (MVEBU_REMAP_INT_REG_BASE + 0xd0224)
#define KIRKWOOD_SDRAM_BASE (IOMEM(MVEBU_REMAP_INT_REG_BASE) + 0x00000)
#define KIRKWOOD_DDR_BASE_CSn(n) (0x1500 + ((n) * 0x8))
@@ -192,8 +196,33 @@ static void mvebu_remap_registers(void)
void __naked __noreturn dove_barebox_entry(void *boarddata)
{
+ uint32_t val;
+ void __iomem *mcbase = mvebu_get_initial_int_reg_base() + 0x800000;
+
mvebu_remap_registers();
+ /*
+ * On dove there is an additional register window that is expected to be
+ * located 0x800000 after the main register window. This contains the
+ * DDR registers.
+ */
+ val = readl(mcbase + DOVE_SDRAM_REGS_BASE_DECODE) & 0x0000ffff;
+ val |= (unsigned long)DOVE_SDRAM_BASE & 0xffff0000;
+ writel(val, mcbase + DOVE_SDRAM_REGS_BASE_DECODE);
+
+ /* tell the axi controller about where to find the DDR controller */
+ val = readl(DOVE_AXI_CTRL) & 0x007fffff;
+ val |= (unsigned long)DOVE_SDRAM_BASE & 0xff800000;
+ writel(val, DOVE_AXI_CTRL);
+
+ /*
+ * The AXI units internal space base starts at the same address as the
+ * DDR controller.
+ */
+ val = readl(DOVE_CPU_CTRL) & 0xfff007ff;
+ val |= ((unsigned long)DOVE_SDRAM_BASE & 0xff800000) >> 12;
+ writel(val, DOVE_CPU_CTRL);
+
barebox_arm_entry(0, dove_memory_find(), boarddata);
}
diff --git a/arch/arm/mach-mvebu/dove.c b/arch/arm/mach-mvebu/dove.c
index 1cdb7e1b82..37fde63f18 100644
--- a/arch/arm/mach-mvebu/dove.c
+++ b/arch/arm/mach-mvebu/dove.c
@@ -22,27 +22,6 @@
#include <linux/mbus.h>
#include <mach/dove-regs.h>
-static inline void dove_remap_mc_regs(void)
-{
- void __iomem *mcboot = IOMEM(DOVE_BOOTUP_MC_REGS);
- uint32_t val;
-
- /* remap ahb slave base */
- val = readl(DOVE_CPU_CTRL) & 0xffff0000;
- val |= (DOVE_REMAP_MC_REGS & 0xffff0000) >> 16;
- writel(val, DOVE_CPU_CTRL);
-
- /* remap axi bridge address */
- val = readl(DOVE_AXI_CTRL) & 0x007fffff;
- val |= DOVE_REMAP_MC_REGS & 0xff800000;
- writel(val, DOVE_AXI_CTRL);
-
- /* remap memory controller base address */
- val = readl(mcboot + SDRAM_REGS_BASE_DECODE) & 0x0000ffff;
- val |= DOVE_REMAP_MC_REGS & 0xffff0000;
- writel(val, mcboot + SDRAM_REGS_BASE_DECODE);
-}
-
static void __noreturn dove_restart_soc(struct restart_handler *rst)
{
/* enable and assert RSTOUTn */
@@ -62,7 +41,6 @@ static int dove_init_soc(void)
barebox_set_model("Marvell Dove");
barebox_set_hostname("dove");
- dove_remap_mc_regs();
mvebu_mbus_init();
return 0;
diff --git a/arch/arm/mach-mvebu/kwbootimage.c b/arch/arm/mach-mvebu/kwbootimage.c
index 8d364ceb7b..e379d732fe 100644
--- a/arch/arm/mach-mvebu/kwbootimage.c
+++ b/arch/arm/mach-mvebu/kwbootimage.c
@@ -10,7 +10,7 @@
#include <asm/unaligned.h>
#include <mach/common.h>
-static int do_bootm_kwbimage_v1(struct image_data *data)
+static int do_bootm_kwbimage_v0_v1(struct image_data *data)
{
int fd, ret;
loff_t offset;
@@ -69,14 +69,21 @@ out_free:
return ret;
}
+static struct image_handler image_handler_kwbimage_v0_handler = {
+ .name = "MVEBU kwbimage v0",
+ .bootm = do_bootm_kwbimage_v0_v1,
+ .filetype = filetype_kwbimage_v0,
+};
+
static struct image_handler image_handler_kwbimage_v1_handler = {
.name = "MVEBU kwbimage v1",
- .bootm = do_bootm_kwbimage_v1,
+ .bootm = do_bootm_kwbimage_v0_v1,
.filetype = filetype_kwbimage_v1,
};
static int mvebu_register_kwbimage_image_handler(void)
{
+ register_image_handler(&image_handler_kwbimage_v0_handler);
register_image_handler(&image_handler_kwbimage_v1_handler);
return 0;
diff --git a/arch/arm/mach-omap/am33xx_bbu_nand.c b/arch/arm/mach-omap/am33xx_bbu_nand.c
index 7785d40f1f..6fc6e7e40f 100644
--- a/arch/arm/mach-omap/am33xx_bbu_nand.c
+++ b/arch/arm/mach-omap/am33xx_bbu_nand.c
@@ -20,6 +20,7 @@
#include <bbu.h>
#include <fs.h>
#include <fcntl.h>
+#include <libfile.h>
#include <filetype.h>
struct nand_bbu_handler {
@@ -28,39 +29,6 @@ struct nand_bbu_handler {
int num_devicefiles;
};
-static int write_image(const char *devfile, const void *image, size_t size)
-{
- int fd = 0;
- int ret = 0;
-
- fd = open(devfile, O_WRONLY);
- if (fd < 0) {
- pr_err("could not open %s: %s\n", devfile,
- errno_str());
- return fd;
- }
-
- ret = erase(fd, ERASE_SIZE_ALL, 0);
- if (ret < 0) {
- pr_err("could not erase %s: %s\n", devfile,
- errno_str());
- close(fd);
- return ret;
- }
-
- ret = write(fd, image, size);
- if (ret < 0) {
- pr_err("could not write to fd %s: %s\n", devfile,
- errno_str());
- close(fd);
- return ret;
- }
-
- close(fd);
-
- return 0;
-}
-
/*
* Upate given nand partitions with an image
*/
@@ -80,12 +48,12 @@ static int nand_slot_update_handler(struct bbu_handler *handler,
/* check if the devicefile has been overwritten */
if (strcmp(data->devicefile, nh->devicefile[0]) != 0) {
- ret = write_image(data->devicefile, image, size);
+ ret = write_file_flash(data->devicefile, image, size);
if (ret != 0)
return ret;
} else {
for (i = 0; i < nh->num_devicefiles; i++) {
- ret = write_image(nh->devicefile[i], image, size);
+ ret = write_file_flash(nh->devicefile[i], image, size);
if (ret != 0)
return ret;
}
diff --git a/common/filetype.c b/common/filetype.c
index 444ec14cc4..bb807df721 100644
--- a/common/filetype.c
+++ b/common/filetype.c
@@ -65,7 +65,8 @@ static const struct filetype_str filetype_str[] = {
[filetype_exe] = { "MS-DOS executable", "exe" },
[filetype_mxs_bootstream] = { "Freescale MXS bootstream", "mxsbs" },
[filetype_socfpga_xload] = { "SoCFPGA prebootloader image", "socfpga-xload" },
- [filetype_kwbimage_v1] = { "MVEBU kwbimage (v1)", "kwb" },
+ [filetype_kwbimage_v0] = { "MVEBU kwbimage (v0)", "kwb0" },
+ [filetype_kwbimage_v1] = { "MVEBU kwbimage (v1)", "kwb1" },
[filetype_android_sparse] = { "Android sparse image", "sparse" },
[filetype_arm64_linux_image] = { "ARM aarch64 Linux image", "aarch64-linux" },
};
@@ -302,10 +303,21 @@ enum filetype file_detect_type(const void *_buf, size_t bufsize)
if ((buf8[0] == 0x5a || buf8[0] == 0x69 || buf8[0] == 0x78 ||
buf8[0] == 0x8b || buf8[0] == 0x9c) &&
buf8[0x1] == 0 && buf8[0x2] == 0 && buf8[0x3] == 0 &&
- buf8[0x8] == 1 && buf8[0x18] == 0 && buf8[0x1b] == 0 &&
- buf8[0x1c] == 0 && buf8[0x1d] == 0 &&
- (buf8[0x1e] == 0 || buf8[0x1e] == 1))
- return filetype_kwbimage_v1;
+ buf8[0x18] == 0 && buf8[0x1b] == 0 && buf8[0x1c] == 0) {
+ unsigned char sum = 0;
+ int i;
+
+ for (i = 0; i <= 0x1e; ++i)
+ sum += buf8[i];
+
+ if (sum == buf8[0x1f] && buf8[0x8] == 0)
+ return filetype_kwbimage_v0;
+
+ if (sum == buf8[0x1f] &&
+ buf8[0x8] == 1 && buf8[0x1d] == 0 &&
+ (buf8[0x1e] == 0 || buf8[0x1e] == 1))
+ return filetype_kwbimage_v1;
+ }
if (is_sparse_image(_buf))
return filetype_android_sparse;
diff --git a/include/filetype.h b/include/filetype.h
index 9986938ddb..d9963a2449 100644
--- a/include/filetype.h
+++ b/include/filetype.h
@@ -38,6 +38,7 @@ enum filetype {
filetype_xz_compressed,
filetype_mxs_bootstream,
filetype_socfpga_xload,
+ filetype_kwbimage_v0,
filetype_kwbimage_v1,
filetype_android_sparse,
filetype_arm64_linux_image,
diff --git a/include/libfile.h b/include/libfile.h
index fd2fadeaa8..2c5eef71f1 100644
--- a/include/libfile.h
+++ b/include/libfile.h
@@ -12,6 +12,7 @@ int read_file_2(const char *filename, size_t *size, void **outbuf,
loff_t max_size);
int write_file(const char *filename, const void *buf, size_t size);
+int write_file_flash(const char *filename, const void *buf, size_t size);
int copy_file(const char *src, const char *dst, int verbose);
diff --git a/lib/libfile.c b/lib/libfile.c
index b7db22d694..d22519b8f4 100644
--- a/lib/libfile.c
+++ b/lib/libfile.c
@@ -251,6 +251,39 @@ int write_file(const char *filename, const void *buf, size_t size)
EXPORT_SYMBOL(write_file);
/**
+ * write_file_flash - write a buffer to a file backed by flash
+ * @filename: The filename to write
+ * @size: The size of the buffer
+ *
+ * Functional this is identical to write_file but calls erase() before writing.
+ *
+ * Return: 0 for success or negative error value
+ */
+int write_file_flash(const char *filename, const void *buf, size_t size)
+{
+ int fd, ret;
+
+ fd = open(filename, O_WRONLY);
+ if (fd < 0)
+ return fd;
+
+ ret = erase(fd, size, 0);
+ if (ret < 0)
+ goto out_close;
+
+ ret = write_full(fd, buf, size);
+
+out_close:
+ close(fd);
+
+ if (ret < 0)
+ return ret;
+
+ return 0;
+}
+EXPORT_SYMBOL(write_file_flash);
+
+/**
* copy_file - Copy a file
* @src: The source filename
* @dst: The destination filename
diff --git a/scripts/kwboot.c b/scripts/kwboot.c
index db177ceb5f..df52144e45 100644
--- a/scripts/kwboot.c
+++ b/scripts/kwboot.c
@@ -602,12 +602,24 @@ out:
return rc;
}
+static unsigned char crc(const unsigned char *img, size_t len)
+{
+ unsigned char ret = 0;
+ size_t i;
+
+ for (i = 0; i < len; ++i)
+ ret += img[i];
+
+ return ret;
+}
+
static int
kwboot_check_image(unsigned char *img, size_t size)
{
size_t i;
size_t header_size, image_size, image_offset;
unsigned char csum = 0;
+ unsigned char imgversion;
if (size < 0x20) {
fprintf(stderr,
@@ -636,7 +648,8 @@ kwboot_check_image(unsigned char *img, size_t size)
return 1;
}
- if (img[0x8] != 1) {
+ imgversion = img[0x8];
+ if (imgversion > 1) {
fprintf(stderr, "Unknown version: 0x%hhx\n", img[0x8]);
return 1;
}
@@ -646,7 +659,15 @@ kwboot_check_image(unsigned char *img, size_t size)
image_offset = img[0xc] | (img[0xd] << 8) |
(img[0xe] << 16) | (img[0xf] << 24);
- header_size = (img[0x9] << 16) | img[0xa] | (img[0xb] << 8);
+ if (imgversion == 0) {
+ /* Image format 0 */
+ header_size =
+ img[0x1e] * 0x200 /* header extensions */ +
+ img[0x1d] * 0x800 /* binary header extensions */;
+ } else {
+ /* Image format 1 */
+ header_size = (img[0x9] << 16) | img[0xa] | (img[0xb] << 8);
+ }
if (header_size > image_offset) {
fprintf(stderr, "Header (%zu) expands over image start (%zu)\n",
@@ -660,16 +681,38 @@ kwboot_check_image(unsigned char *img, size_t size)
return 1;
}
- for (i = 0; i < header_size; ++i)
- csum += img[i];
- csum -= img[0x1f];
+ if (imgversion == 0) {
+ /* check Main Header */
+ csum = crc(img, 0x1f);
+ if (csum != img[0x1f]) {
+ fprintf(stderr,
+ "Main Header checksum mismatch: specified: 0x%02hhx, calculated: 0x%02hhx\n",
+ img[0x1f], csum);
+ return 1;
+ }
+
+ /* check Header Extensions */
+ for (i = 0; i < img[0x1e]; ++i) {
+ csum = crc(img + 0x20 + i * 0x200, 0x1df);
+ if (csum != img[i * 0x200 + 0x1ff]) {
+ fprintf(stderr,
+ "Extension Header #%zu checksum mismatch: specified: 0x%02hhx, calculated: 0x%02hhx\n",
+ i, img[i * 0x200 + 0x1ff], csum);
+ return 1;
+ }
+ }
+ } else {
+ csum = crc(img, header_size);
+ csum -= img[0x1f];
+
+ if (csum != img[0x1f]) {
+ fprintf(stderr,
+ "Checksum mismatch: specified: 0x%02hhx, calculated: 0x%02hhx\n",
+ img[0x1f], csum);
+ return 1;
+ }
- if (csum != img[0x1f]) {
- fprintf(stderr,
- "Checksum mismatch: specified: 0x%02hhx, calculated: 0x%02hhx\n",
- img[0x1f], csum);
- return 1;
}
return 0;