Re: [PATCH 1/2] ARM: am33xx: Add barebox_update eMMC option

2015-09-03 Thread Sascha Hauer
On Wed, Sep 02, 2015 at 08:36:56AM +0200, Daniel Schultz wrote:
> With this patch the barebox_update command will be extended by the possibility
> to flash the MLO to eMMC devices.
> 
> The MLO will be flashed to the following addresses:
> 0x2
> 0x4
> 0x6
> 
> The MBR at addr. 0x0 won't be overwritten.
> Therefore it's necessary to remove the MLO in the boot partition.

Couldn't you instead write the MLO to 0x0 but keep the partition table?
It seems the first 512 bytes from the MLO are unused execpt for the
CHSETTINGS header which does not conflict with the partition table.

Sascha

-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |

___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 1/2] ARM: am33xx: Add barebox_update eMMC option

2015-09-02 Thread Daniel Schultz
With this patch the barebox_update command will be extended by the possibility
to flash the MLO to eMMC devices.

The MLO will be flashed to the following addresses:
0x2
0x4
0x6

The MBR at addr. 0x0 won't be overwritten.
Therefore it's necessary to remove the MLO in the boot partition.

Signed-off-by: Daniel Schultz 
---
 arch/arm/configs/am335x_defconfig |  1 +
 arch/arm/mach-omap/Kconfig|  7 
 arch/arm/mach-omap/Makefile   |  1 +
 arch/arm/mach-omap/am33xx_bbu_emmc.c  | 78 +++
 arch/arm/mach-omap/include/mach/bbu.h | 18 
 5 files changed, 105 insertions(+)
 create mode 100644 arch/arm/mach-omap/am33xx_bbu_emmc.c

diff --git a/arch/arm/configs/am335x_defconfig 
b/arch/arm/configs/am335x_defconfig
index 559f56a..c5ab3c9 100644
--- a/arch/arm/configs/am335x_defconfig
+++ b/arch/arm/configs/am335x_defconfig
@@ -1,6 +1,7 @@
 CONFIG_ARCH_OMAP=y
 CONFIG_BAREBOX_UPDATE_AM33XX_SPI_NOR_MLO=y
 CONFIG_BAREBOX_UPDATE_AM33XX_NAND=y
+CONFIG_BAREBOX_UPDATE_AM33XX_EMMC=y
 CONFIG_OMAP_MULTI_BOARDS=y
 CONFIG_MACH_AFI_GF=y
 CONFIG_MACH_BEAGLEBONE=y
diff --git a/arch/arm/mach-omap/Kconfig b/arch/arm/mach-omap/Kconfig
index fb17df0..0df38e1 100644
--- a/arch/arm/mach-omap/Kconfig
+++ b/arch/arm/mach-omap/Kconfig
@@ -105,6 +105,13 @@ config BAREBOX_UPDATE_AM33XX_NAND
  This also includes a handler for updating the regular barebox binary
  in NAND.
 
+config BAREBOX_UPDATE_AM33XX_EMMC
+   prompt "barebox update eMMC handler"
+   bool
+   depends on BAREBOX_UPDATE
+   help
+ Say Y for barebox update eMMC handler.
+
 config ARCH_TEXT_BASE
hex
default 0x80e8 if MACH_OMAP343xSDP
diff --git a/arch/arm/mach-omap/Makefile b/arch/arm/mach-omap/Makefile
index bef1d05..82f1a9e 100644
--- a/arch/arm/mach-omap/Makefile
+++ b/arch/arm/mach-omap/Makefile
@@ -34,3 +34,4 @@ obj-$(CONFIG_OMAP4_USBBOOT) += omap4_rom_usb.o
 obj-$(CONFIG_CMD_BOOT_ORDER) += boot_order.o
 obj-$(CONFIG_BAREBOX_UPDATE_AM33XX_SPI_NOR_MLO) += am33xx_bbu_spi_mlo.o
 obj-$(CONFIG_BAREBOX_UPDATE_AM33XX_NAND) += am33xx_bbu_nand.o
+obj-$(CONFIG_BAREBOX_UPDATE_AM33XX_EMMC) += am33xx_bbu_emmc.o
diff --git a/arch/arm/mach-omap/am33xx_bbu_emmc.c 
b/arch/arm/mach-omap/am33xx_bbu_emmc.c
new file mode 100644
index 000..1c1bebc
--- /dev/null
+++ b/arch/arm/mach-omap/am33xx_bbu_emmc.c
@@ -0,0 +1,78 @@
+/*
+ * Copyright (c) 2015 Phytec Messtechnik GmbH
+ * Author: Daniel Schultz 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+static int emmc_mlo_handler(struct bbu_handler *handler, struct bbu_data *data)
+{
+   int ret = 0;
+   int i = 0;
+   int fd;
+   const void *image = data->image;
+   size_t size = data->len;
+
+   if (file_detect_type(image, size) != filetype_ch_image) {
+   pr_err("%s is not a valid ch-image\n", data->imagefile);
+   return -EINVAL;
+   }
+   ret = bbu_confirm(data);
+   if (ret != 0)
+   return ret;
+
+   fd = open(handler->devicefile, O_WRONLY);
+   if (fd < 0) {
+   pr_err("could not open %s: %s\n", handler->devicefile,
+   errno_str());
+   return fd;
+   }
+
+   for (i = 1; i < 4; i++) {
+   ret = pwrite(fd, image, size, i * 0x2);
+   if (ret < 0) {
+   pr_err("could not write to fd %s: %s\n",
+   handler->devicefile, errno_str());
+   close(fd);
+   return ret;
+   }
+   }
+   close(fd);
+
+   printf("Remove the MLO from the %s boot partition.\nOtherwise the wrong 
MLO may be loaded!\n",
+   handler->devicefile);
+
+   return 0;
+}
+
+int am33xx_bbu_emmc_mlo_register_handler(const char *name, char *devicefile)
+{
+   struct bbu_handler *handler;
+   int ret;
+
+   handler = xzalloc(sizeof(*handler));
+   handler->devicefile = devicefile;
+   handler->name = name;
+   handler->handler = emmc_mlo_handler;
+
+   ret = bbu_register_handler(handler);
+
+   if (ret)
+   free(handler);
+
+   return ret;
+}
diff --git a/arch/arm/mach-omap/include/mach/bbu.h 
b/arch/arm/mach-omap/include/mach/bbu.h
index 36d87e1..4d1b4fa 100644
--- a/arch/arm/mach-omap/include/mach/bbu.h
+++ b/arch/arm/mach-omap/include/mach/bbu.h
@@ -37,4 +37,22 @@ static inline int