All of lore.kernel.org
 help / color / mirror / Atom feed
From: AKASHI Takahiro <takahiro.akashi@linaro.org>
To: u-boot@lists.denx.de
Subject: [PATCH v6 03/17] common: update: add a generic interface for FIT image
Date: Mon,  7 Sep 2020 14:34:12 +0900	[thread overview]
Message-ID: <20200907053426.1675646-4-takahiro.akashi@linaro.org> (raw)
In-Reply-To: <20200907053426.1675646-1-takahiro.akashi@linaro.org>

The main purpose of this patch is to separate a generic interface for
updating firmware using DFU drivers from "auto-update" via tftp.

This function will also be used in implementing UEFI capsule update
in a later commit.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
---
 common/Kconfig      | 15 ++++++++++
 common/Makefile     |  3 +-
 common/update.c     | 71 +++++++++++++++++++++++++++++++++++++++++++++
 drivers/dfu/Kconfig |  1 +
 include/image.h     | 12 ++++++++
 5 files changed, 100 insertions(+), 2 deletions(-)

diff --git a/common/Kconfig b/common/Kconfig
index c58f08ba91bf..36998e382bda 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -1050,9 +1050,15 @@ endmenu
 
 menu "Update support"
 
+config UPDATE_COMMON
+	bool
+	default n
+	select DFU_ALT
+
 config UPDATE_TFTP
 	bool "Auto-update using fitImage via TFTP"
 	depends on FIT
+	select UPDATE_COMMON
 	help
 	  This option allows performing update of NOR with data in fitImage
 	  sent via TFTP boot.
@@ -1067,6 +1073,15 @@ config UPDATE_TFTP_MSEC_MAX
 	default 100
 	depends on UPDATE_TFTP
 
+config UPDATE_FIT
+	bool "Firmware update using fitImage"
+	depends on FIT
+	depends on DFU
+	select UPDATE_COMMON
+	help
+	  This option allows performing update of DFU-capable storage with
+	  data in fitImage.
+
 config ANDROID_AB
 	bool "Android A/B updates"
 	default n
diff --git a/common/Makefile b/common/Makefile
index 2e7a090588d9..bcf352d01652 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -53,8 +53,7 @@ obj-$(CONFIG_LCD_ROTATION) += lcd_console_rotation.o
 obj-$(CONFIG_LCD_DT_SIMPLEFB) += lcd_simplefb.o
 obj-$(CONFIG_LYNXKDI) += lynxkdi.o
 obj-$(CONFIG_MENU) += menu.o
-obj-$(CONFIG_UPDATE_TFTP) += update.o
-obj-$(CONFIG_DFU_TFTP) += update.o
+obj-$(CONFIG_UPDATE_COMMON) += update.o
 obj-$(CONFIG_USB_KEYBOARD) += usb_kbd.o
 obj-$(CONFIG_CMDLINE) += cli_readline.o cli_simple.o
 
diff --git a/common/update.c b/common/update.c
index 8dd6ee8b7ddb..808be0880dfd 100644
--- a/common/update.c
+++ b/common/update.c
@@ -29,6 +29,7 @@
 #include <errno.h>
 #include <mtd/cfi_flash.h>
 
+#ifdef CONFIG_DFU_TFTP
 /* env variable holding the location of the update file */
 #define UPDATE_FILE_ENV		"updatefile"
 
@@ -98,6 +99,7 @@ static int update_load(char *filename, ulong msec_max, int cnt_max, ulong addr)
 
 	return rv;
 }
+#endif /* CONFIG_DFU_TFTP */
 
 #ifdef CONFIG_MTD_NOR_FLASH
 static int update_flash_protect(int prot, ulong addr_first, ulong addr_last)
@@ -231,6 +233,7 @@ static int update_fit_getparams(const void *fit, int noffset, ulong *addr,
 	return 0;
 }
 
+#ifdef CONFIG_DFU_TFTP
 int update_tftp(ulong addr, char *interface, char *devstring)
 {
 	char *filename, *env_addr, *fit_image_name;
@@ -337,3 +340,71 @@ next_node:
 
 	return ret;
 }
+#endif /* CONFIG_DFU_UPDATE */
+
+#ifdef CONFIG_UPDATE_FIT
+/**
+ * fit_update - update storage with FIT image
+ * @fit:	Pointer to FIT image
+ *
+ * Update firmware on storage using FIT image as input.
+ * The storage area to be update will be identified by the name
+ * in FIT and matching it to "dfu_alt_info" variable.
+ *
+ * Return:      0 - on success, non-zero - otherwise
+ */
+int fit_update(const void *fit)
+{
+	char *fit_image_name;
+	ulong update_addr, update_fladdr, update_size;
+	int images_noffset, ndepth, noffset;
+	int ret = 0;
+
+	if (!fit)
+		return -EINVAL;
+
+	if (!fit_check_format((void *)fit)) {
+		printf("Bad FIT format of the update file, aborting auto-update\n");
+		return -EINVAL;
+	}
+
+	/* process updates */
+	images_noffset = fdt_path_offset(fit, FIT_IMAGES_PATH);
+
+	ndepth = 0;
+	noffset = fdt_next_node(fit, images_noffset, &ndepth);
+	while (noffset >= 0 && ndepth > 0) {
+		if (ndepth != 1)
+			goto next_node;
+
+		fit_image_name = (char *)fit_get_name(fit, noffset, NULL);
+		printf("Processing update '%s' :", fit_image_name);
+
+		if (!fit_image_verify(fit, noffset)) {
+			printf("Error: invalid update hash, aborting\n");
+			ret = 1;
+			goto next_node;
+		}
+
+		printf("\n");
+		if (update_fit_getparams(fit, noffset, &update_addr,
+					 &update_fladdr, &update_size)) {
+			printf("Error: can't get update parameters, aborting\n");
+			ret = 1;
+			goto next_node;
+		}
+
+		if (fit_image_check_type(fit, noffset, IH_TYPE_FIRMWARE)) {
+			ret = dfu_write_by_name(fit_image_name,
+						(void *)update_addr,
+						update_size, NULL, NULL);
+			if (ret)
+				return ret;
+		}
+next_node:
+		noffset = fdt_next_node(fit, noffset, &ndepth);
+	}
+
+	return ret;
+}
+#endif /* CONFIG_UPDATE_FIT */
diff --git a/drivers/dfu/Kconfig b/drivers/dfu/Kconfig
index 78f901ff348a..ce0c42c7df9c 100644
--- a/drivers/dfu/Kconfig
+++ b/drivers/dfu/Kconfig
@@ -22,6 +22,7 @@ config DFU_TFTP
 	bool "DFU via TFTP"
 	select DFU_ALT
 	select DFU_OVER_TFTP
+	select UPDATE_COMMON
 	help
 	  This option allows performing update of DFU-managed medium with data
 	  sent via TFTP boot.
diff --git a/include/image.h b/include/image.h
index 9a5a87dbf870..35b8b7c3d84f 100644
--- a/include/image.h
+++ b/include/image.h
@@ -1592,4 +1592,16 @@ struct fit_loadable_tbl {
 		.handler = _handler, \
 	}
 
+/**
+ * fit_update - update storage with FIT image
+ * @fit:        Pointer to FIT image
+ *
+ * Update firmware on storage using FIT image as input.
+ * The storage area to be update will be identified by the name
+ * in FIT and matching it to "dfu_alt_info" variable.
+ *
+ * Return:      0 on success, non-zero otherwise
+ */
+int fit_update(const void *fit);
+
 #endif	/* __IMAGE_H__ */
-- 
2.28.0

  parent reply	other threads:[~2020-09-07  5:34 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-07  5:34 [PATCH v6 00/17] efi_loader: add capsule update support AKASHI Takahiro
2020-09-07  5:34 ` [PATCH v6 01/17] dfu: rename dfu_tftp_write() to dfu_write_by_name() AKASHI Takahiro
2020-09-09 12:30   ` Heinrich Schuchardt
2020-09-10  1:54     ` AKASHI Takahiro
2020-09-10  2:26       ` Tom Rini
2020-09-11  0:46         ` AKASHI Takahiro
2020-09-11  2:41           ` Tom Rini
2020-09-18  1:28             ` AKASHI Takahiro
2020-09-18  1:32               ` Tom Rini
2020-09-18  8:08                 ` Lukasz Majewski
2020-09-07  5:34 ` [PATCH v6 02/17] dfu: modify an argument type for an address AKASHI Takahiro
2020-09-07  5:34 ` AKASHI Takahiro [this message]
2020-09-07  5:34 ` [PATCH v6 04/17] dfu: export dfu_list AKASHI Takahiro
2020-09-07  5:34 ` [PATCH v6 05/17] efi_loader: add option to initialise EFI subsystem early AKASHI Takahiro
2020-09-07  5:34 ` [PATCH v6 06/17] efi_loader: add efi_create_indexed_name() AKASHI Takahiro
2020-09-07  5:34 ` [PATCH v6 07/17] efi_loader: define UpdateCapsule api AKASHI Takahiro
2020-09-07  5:34 ` [PATCH v6 08/17] efi_loader: capsule: add capsule_on_disk support AKASHI Takahiro
2020-09-07  5:34 ` [PATCH v6 09/17] efi_loader: capsule: add memory range capsule definitions AKASHI Takahiro
2020-09-07  5:34 ` [PATCH v6 10/17] efi_loader: capsule: support firmware update AKASHI Takahiro
2020-09-07  5:34 ` [PATCH v6 11/17] efi_loader: add firmware management protocol for FIT image AKASHI Takahiro
2020-09-07  5:34 ` [PATCH v6 12/17] dfu: add dfu_write_by_alt() AKASHI Takahiro
2020-09-07  5:34 ` [PATCH v6 13/17] efi_loader: add firmware management protocol for raw image AKASHI Takahiro
2020-09-07  5:34 ` [PATCH v6 14/17] cmd: add "efidebug capsule" command AKASHI Takahiro
2020-09-07  5:34 ` [PATCH v6 15/17] tools: add mkeficapsule command for UEFI capsule update AKASHI Takahiro
2020-09-07  5:34 ` [PATCH v6 16/17] test/py: efi_capsule: test for FIT image capsule AKASHI Takahiro
2020-09-07  5:34 ` [PATCH v6 17/17] test/py: efi_capsule: test for raw " AKASHI Takahiro
2020-09-09 14:48 ` [PATCH v6 00/17] efi_loader: add capsule update support Heinrich Schuchardt
2020-09-09 16:56   ` Tom Rini
2020-09-10  2:52     ` AKASHI Takahiro
2020-09-10  2:58       ` Tom Rini
2020-09-11  0:52         ` AKASHI Takahiro
2020-09-11  1:02           ` Tom Rini
2020-09-11  2:31             ` AKASHI Takahiro
2020-09-11  2:44               ` Tom Rini
2020-09-10  2:43   ` AKASHI Takahiro

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200907053426.1675646-4-takahiro.akashi@linaro.org \
    --to=takahiro.akashi@linaro.org \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.