summaryrefslogtreecommitdiffstats
path: root/arch/arm/mach-omap/xload.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/arm/mach-omap/xload.c')
-rw-r--r--arch/arm/mach-omap/xload.c117
1 files changed, 51 insertions, 66 deletions
diff --git a/arch/arm/mach-omap/xload.c b/arch/arm/mach-omap/xload.c
index 47aa8275b9..e632b53788 100644
--- a/arch/arm/mach-omap/xload.c
+++ b/arch/arm/mach-omap/xload.c
@@ -1,6 +1,7 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
#include <common.h>
#include <bootsource.h>
-#include <partition.h>
#include <nand.h>
#include <init.h>
#include <driver.h>
@@ -12,12 +13,13 @@
#include <malloc.h>
#include <filetype.h>
#include <xymodem.h>
-#include <mach/generic.h>
-#include <mach/am33xx-generic.h>
-#include <mach/omap3-generic.h>
+#include <mach/omap/generic.h>
+#include <mach/omap/am33xx-generic.h>
+#include <mach/omap/omap3-generic.h>
#include <net.h>
#include <environment.h>
#include <dhcp.h>
+#include <mtd/mtd-peb.h>
struct omap_barebox_part *barebox_part;
@@ -30,29 +32,6 @@ static struct omap_barebox_part default_part = {
.nor_size = SZ_1M,
};
-static void *read_image_head(const char *name)
-{
- void *header = xmalloc(ARM_HEAD_SIZE);
- struct cdev *cdev;
- int ret;
-
- cdev = cdev_open(name, O_RDONLY);
- if (!cdev) {
- printf("failed to open %s\n", name);
- return NULL;
- }
-
- ret = cdev_read(cdev, header, ARM_HEAD_SIZE, 0, 0);
- cdev_close(cdev);
-
- if (ret != ARM_HEAD_SIZE) {
- printf("failed to read from %s\n", name);
- return NULL;
- }
-
- return header;
-}
-
static unsigned int get_image_size(void *head)
{
unsigned int ret = 0;
@@ -65,57 +44,67 @@ static unsigned int get_image_size(void *head)
return ret;
}
-static void *read_mtd_barebox(const char *partition)
+static void *read_mtd_barebox(const char *part, unsigned int start, unsigned int size)
{
int ret;
- int size;
- void *to, *header;
+ void *to;
struct cdev *cdev;
+ struct mtd_info *mtd;
+ unsigned int ps, pe;
- header = read_image_head(partition);
- if (header == NULL)
- return NULL;
-
- size = get_image_size(header);
- if (!size) {
- printf("failed to get image size\n");
+ if (!IS_ENABLED(CONFIG_MTD)) {
+ printf("Cannot load from nand/nor: MTD support is disabled\n");
return NULL;
}
- to = xmalloc(size);
-
- cdev = cdev_open(partition, O_RDONLY);
+ cdev = cdev_open_by_name(part, O_RDONLY);
if (!cdev) {
printf("failed to open partition\n");
return NULL;
}
- ret = cdev_read(cdev, to, size, 0, 0);
- if (ret != size) {
- printf("failed to read from partition\n");
+ mtd = cdev->mtd;
+ if (!mtd)
+ return NULL;
+
+ if (mtd_mod_by_eb(start, mtd) != 0) {
+ printf("Start must be eraseblock aligned\n");
return NULL;
}
+ to = xmalloc(size);
+
+ ps = mtd_div_by_eb(start, mtd);
+ pe = mtd_div_by_eb(start + size, mtd);
+ ret = mtd_peb_read_file(mtd, ps, pe, to, size);
+ if (ret) {
+ printf("Can't read image from %s: %d\n", part, ret);
+ goto err;
+ }
+
+ size = get_image_size(to);
+ if (!size) {
+ printf("failed to get image size\n");
+ goto err;
+ }
+
return to;
+
+err:
+ free(to);
+ return NULL;
}
static void *omap_xload_boot_nand(struct omap_barebox_part *part)
{
void *to;
- devfs_add_partition("nand0", part->nand_offset, part->nand_size,
- DEVFS_PARTITION_FIXED, "x");
- dev_add_bb_dev("x", "bbx");
-
- to = read_mtd_barebox("bbx");
+ to = read_mtd_barebox("nand0", part->nand_offset, part->nand_size);
if (to == NULL && part->nand_bkup_size != 0) {
printf("trying to load image from backup partition.\n");
- devfs_add_partition("nand0", part->nand_bkup_offset,
- part->nand_bkup_size,
- DEVFS_PARTITION_FIXED, "x_bkup");
- dev_add_bb_dev("x_bkup", "bbx_bkup");
- to = read_mtd_barebox("bbx_bkup");
+ to = read_mtd_barebox("nand0", part->nand_bkup_offset,
+ part->nand_bkup_size);
}
return to;
@@ -125,7 +114,6 @@ static void *omap_xload_boot_mmc(void)
{
int ret;
void *buf;
- int len;
const char *diskdev;
char *partname;
@@ -147,9 +135,9 @@ static void *omap_xload_boot_mmc(void)
free(partname);
- buf = read_file("/barebox.bin", &len);
+ buf = read_file("/barebox.bin", NULL);
if (!buf)
- buf = read_file("/boot/barebox.bin", &len);
+ buf = read_file("/boot/barebox.bin", NULL);
if (!buf) {
printf("could not read barebox.bin from sd card\n");
return NULL;
@@ -160,16 +148,12 @@ static void *omap_xload_boot_mmc(void)
static void *omap_xload_boot_spi(struct omap_barebox_part *part)
{
- devfs_add_partition("m25p0", part->nor_offset, part->nor_size,
- DEVFS_PARTITION_FIXED, "x");
-
- return read_mtd_barebox("x");
+ return read_mtd_barebox("m25p0", part->nor_offset, part->nor_size);
}
static void *omap4_xload_boot_usb(void){
int ret;
void *buf;
- int len;
ret = mount("omap4_usbboot", "omap4_usbbootfs", "/", NULL);
if (ret) {
@@ -177,7 +161,7 @@ static void *omap4_xload_boot_usb(void){
return NULL;
}
- buf = read_file("/barebox.bin", &len);
+ buf = read_file("/barebox.bin", NULL);
if (!buf)
printf("could not read barebox.bin from omap4_usbbootfs\n");
@@ -188,7 +172,6 @@ static void *omap_serial_boot(void){
struct console_device *cdev;
int ret;
void *buf;
- int len;
int fd;
/* need temporary place to store file */
@@ -216,7 +199,7 @@ static void *omap_serial_boot(void){
return NULL;
}
- buf = read_file("/barebox.bin", &len);
+ buf = read_file("/barebox.bin", NULL);
if (!buf)
printf("could not read barebox.bin from serial\n");
@@ -229,7 +212,6 @@ static void *am33xx_net_boot(void)
{
void *buf = NULL;
int err;
- int len;
struct dhcp_req_param dhcp_param;
const char *bootfile;
IPaddr_t ip;
@@ -289,7 +271,7 @@ static void *am33xx_net_boot(void)
file = basprintf("%s/%s", TFTP_MOUNT, bootfile);
- buf = read_file(file, &len);
+ buf = read_file(file, NULL);
if (!buf)
printf("could not read %s.\n", bootfile);
@@ -373,6 +355,9 @@ int omap_set_barebox_part(struct omap_barebox_part *part)
static int omap_set_xload(void)
{
+ if (!cpu_is_omap())
+ return 0;
+
barebox_main = omap_xload;
return 0;