board: amlogic: add set_dfu_alt_info in odroid-n2.c
authorJaehoon Chung <jh80.chung@samsung.com>
Tue, 27 Oct 2020 08:13:22 +0000 (17:13 +0900)
committerJaehoon Chung <jh80.chung@samsung.com>
Tue, 17 Oct 2023 04:19:24 +0000 (13:19 +0900)
Add set_dfu_alt_info in odroid-n2.c.

Change-Id: Ic705a38a221af7dfcdb5a67321739c84a79f61df
Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
board/amlogic/odroid-n2/odroid-n2.c

index 2135457..d661b96 100644 (file)
@@ -138,3 +138,75 @@ int misc_init_r(void)
        odroid_detect_variant();
        return 0;
 }
+
+#ifdef CONFIG_SET_DFU_ALT_INFO
+#include <mmc.h>
+#include <config.h>
+#include <memalign.h>
+static char *get_dfu_alt_system(char *interface, char *devstr)
+{
+       return env_get("dfu_alt_system");
+}
+
+static char *get_dfu_alt_boot(char *interface, char *devstr)
+{
+       struct mmc *mmc;
+       char *alt_boot;
+       int dev_num;
+
+       dev_num = simple_strtoul(devstr, NULL, 10);
+
+       mmc = find_mmc_device(dev_num);
+       if (!mmc)
+               return NULL;
+
+       if (mmc_init(mmc))
+               return NULL;
+
+       if (!strncmp(devstr, "0", 1))
+               alt_boot = CONFIG_DFU_ALT_SYSTEM_2;
+       else
+               alt_boot = CONFIG_DFU_ALT_SYSTEM;
+
+       return alt_boot;
+}
+
+void set_dfu_alt_info(char *interface, char *devstr)
+{
+       size_t buf_size = CONFIG_SET_DFU_ALT_BUF_LEN;
+       ALLOC_CACHE_ALIGN_BUFFER(char, buf, buf_size);
+       char *alt_info = "Settings not found!";
+       char *status = "error!\n";
+       char *alt_setting;
+       char *alt_sep;
+       int offset = 0;
+
+       puts("DFU alt info setting: ");
+
+       alt_setting = get_dfu_alt_boot(interface, devstr);
+       if (alt_setting) {
+               env_set("dfu_alt_boot", alt_setting);
+               offset = snprintf(buf, buf_size, "%s", alt_setting);
+       }
+
+       alt_setting = get_dfu_alt_system(interface, devstr);
+       if (alt_setting) {
+               if (offset)
+                       alt_sep = ";";
+               else
+                       alt_sep = "";
+
+               offset += snprintf(buf + offset, buf_size - offset,
+                                   "%s%s", alt_sep, alt_setting);
+       }
+
+       if (offset) {
+               alt_info = buf;
+               status = "done\n";
+       }
+
+       env_set("dfu_alt_info", alt_info);
+
+       puts(status);
+}
+#endif