diff --git a/arch/arm/mach-imx/include/mach/xload.h b/arch/arm/mach-imx/include/mach/xload.h index 3898d66..4e38ac7 100644 --- a/arch/arm/mach-imx/include/mach/xload.h +++ b/arch/arm/mach-imx/include/mach/xload.h @@ -4,7 +4,6 @@ int imx53_nand_start_image(void); int imx6_spi_load_image(int instance, unsigned int flash_offset, void *buf, int len); int imx6_spi_start_image(int instance); -int imx6_esdhc_load_image(int instance, void *buf, int len); int imx6_esdhc_start_image(int instance); int imx_image_size(void); diff --git a/arch/arm/mach-imx/xload-esdhc.c b/arch/arm/mach-imx/xload-esdhc.c index bd58bdc..4580f53 100644 --- a/arch/arm/mach-imx/xload-esdhc.c +++ b/arch/arm/mach-imx/xload-esdhc.c @@ -216,10 +216,58 @@ return 0; } -int imx6_esdhc_load_image(int instance, void *buf, int len) +static int esdhc_start_image(struct esdhc *esdhc) +{ + void *buf = (void *)0x10000000; + u32 *ivt = buf + SZ_1K; + int ret, len; + void __noreturn (*bb)(void); + unsigned int ofs; + + len = imx_image_size(); + len = ALIGN(len, SECTOR_SIZE); + + ret = esdhc_read_blocks(esdhc, buf, 3 * SECTOR_SIZE); + if (ret) + return ret; + if (*(u32 *)(ivt) != 0x402000d1) { + pr_debug("IVT header not found on SD card. Found 0x%08x instead of 0x402000d1\n", + *ivt); + return -EINVAL; + } + + pr_debug("Check ok, loading image\n"); + + ret = esdhc_read_blocks(esdhc, buf, len); + if (ret) { + pr_err("Loading image failed with %d\n", ret); + return ret; + } + + pr_debug("Image loaded successfully\n"); + + ofs = *(ivt + 1) - *(ivt + 8); + + bb = buf + ofs; + + bb(); +} + +/** + * imx6_esdhc_start_image - Load and start an image from USDHC controller + * @instance: The USDHC controller instance (0..4) + * + * This uses esdhc_start_image() to load an image from SD/MMC. It is + * assumed that the image is the currently running barebox image (This + * information is used to calculate the length of the image). The + * image is started afterwards. + * + * Return: If successful, this function does not return. A negative error + * code is returned when this function fails. + */ +int imx6_esdhc_start_image(int instance) { struct esdhc esdhc; - int ret; switch (instance) { case 0: @@ -240,58 +288,5 @@ esdhc.is_mx6 = 1; - ret = esdhc_read_blocks(&esdhc, buf, len); - if (ret) - return ret; - - return 0; -} - -/** - * imx6_esdhc_start_image - Load and start an image from USDHC controller - * @instance: The USDHC controller instance (0..4) - * - * This uses imx6_esdhc_load_image() to load an image from SD/MMC. - * It is assumed that the image is the currently running barebox image - * (This information is used to calculate the length of the image). The - * image is started afterwards. - * - * Return: If successful, this function does not return. A negative error - * code is returned when this function fails. - */ -int imx6_esdhc_start_image(int instance) -{ - void *buf = (void *)0x10000000; - u32 *ivt = buf + SZ_1K; - int ret, len; - void __noreturn (*bb)(void); - unsigned int ofs; - - len = imx_image_size(); - len = ALIGN(len, SECTOR_SIZE); - - ret = imx6_esdhc_load_image(instance, buf, 3 * SECTOR_SIZE); - if (ret) - return ret; - if (*(u32 *)(ivt) != 0x402000d1) { - pr_debug("IVT header not found on SD card. Found 0x%08x instead of 0x402000d1\n", - *ivt); - return -EINVAL; - } - - pr_debug("Check ok, loading image\n"); - - ret = imx6_esdhc_load_image(instance, buf, len); - if (ret) { - pr_err("Loading image failed with %d\n", ret); - return ret; - } - - pr_debug("Image loaded successfully\n"); - - ofs = *(ivt + 1) - *(ivt + 8); - - bb = buf + ofs; - - bb(); + return esdhc_start_image(&esdhc); }