summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorAhmad Fatoum <a.fatoum@pengutronix.de>2022-06-02 11:01:27 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2022-06-03 09:17:27 +0200
commit960535d9bf19cb1a26517cf792c708743ec811b7 (patch)
treecb846ef61a2c4a0ae43223acf1220f5c9aafa8b1 /common
parent278a4fd206da4bb6cb8c32c2c18161788c816bbe (diff)
downloadbarebox-960535d9bf19cb1a26517cf792c708743ec811b7.tar.gz
barebox-960535d9bf19cb1a26517cf792c708743ec811b7.tar.xz
bbu: move barebox_update eMMC boot handling into common code
Like with the i.MX, the STM32MP1 BootROM also consults the EXT_CSD_PARTITION_CONFIG register to find out what to boot. The barebox_update code used for atomic update on i.MX is thus useful to the STM32MP as well, so move the boot switching part to a generic location. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20220602090133.3190450-2-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'common')
-rw-r--r--common/bbu.c55
1 files changed, 55 insertions, 0 deletions
diff --git a/common/bbu.c b/common/bbu.c
index cd7bdc40b7..6a47b21a55 100644
--- a/common/bbu.c
+++ b/common/bbu.c
@@ -19,6 +19,7 @@
#include <malloc.h>
#include <linux/stat.h>
#include <image-metadata.h>
+#include <environment.h>
#include <file-list.h>
static LIST_HEAD(bbu_image_handlers);
@@ -304,6 +305,60 @@ struct bbu_std {
enum filetype filetype;
};
+int bbu_mmcboot_handler(struct bbu_handler *handler, struct bbu_data *data,
+ int (*chained_handler)(struct bbu_handler *, struct bbu_data *))
+{
+ struct bbu_data _data = *data;
+ int ret;
+ char *bootpartvar;
+ const char *bootpart;
+ char *devicefile;
+ const char *devname = devpath_to_name(data->devicefile);
+
+ ret = device_detect_by_name(devname);
+ if (ret) {
+ pr_err("Couldn't detect device '%s'\n", devname);
+ return ret;
+ }
+
+ ret = asprintf(&bootpartvar, "%s.boot", devname);
+ if (ret < 0)
+ return ret;
+
+ bootpart = getenv(bootpartvar);
+ if (!bootpart) {
+ ret = -ENOENT;
+ goto free_bootpartvar;
+ }
+
+ if (!strcmp(bootpart, "boot0")) {
+ bootpart = "boot1";
+ } else {
+ bootpart = "boot0";
+ }
+
+ ret = asprintf(&devicefile, "/dev/%s.%s", devname, bootpart);
+ if (ret < 0)
+ goto free_bootpartvar;
+
+ _data.devicefile = devicefile;
+
+ ret = chained_handler(handler, &_data);
+ if (ret < 0)
+ goto free_devicefile;
+
+ /* on success switch boot source */
+ ret = setenv(bootpartvar, bootpart);
+
+free_devicefile:
+ free(devicefile);
+
+free_bootpartvar:
+ free(bootpartvar);
+
+ return ret;
+}
+
static int bbu_std_file_handler(struct bbu_handler *handler,
struct bbu_data *data)
{