image: android: Add routine to get dtbo params
[oweals/u-boot.git] / common / common_fit.c
index 5f5f3f9a4475af7f0b2e6b9b2be71b09e4afdd35..41305d8aa69315e2fd16f18158a01c43f7a08413 100644 (file)
@@ -1,15 +1,13 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * Copyright (C) 2016 Google, Inc
  * Written by Simon Glass <sjg@chromium.org>
- *
- * SPDX-License-Identifier:     GPL-2.0+
  */
 
 #include <common.h>
 #include <errno.h>
 #include <image.h>
-#include <libfdt.h>
-#include <spl.h>
+#include <linux/libfdt.h>
 
 ulong fdt_getprop_u32(const void *fdt, int node, const char *prop)
 {
@@ -32,6 +30,9 @@ int fit_find_config_node(const void *fdt)
 {
        const char *name;
        int conf, node, len;
+       const char *dflt_conf_name;
+       const char *dflt_conf_desc = NULL;
+       int dflt_conf_node = -ENOENT;
 
        conf = fdt_path_offset(fdt, FIT_CONFS_PATH);
        if (conf < 0) {
@@ -39,6 +40,9 @@ int fit_find_config_node(const void *fdt)
                      conf);
                return -EINVAL;
        }
+
+       dflt_conf_name = fdt_getprop(fdt, conf, "default", &len);
+
        for (node = fdt_first_subnode(fdt, conf);
             node >= 0;
             node = fdt_next_subnode(fdt, node)) {
@@ -50,6 +54,15 @@ int fit_find_config_node(const void *fdt)
 #endif
                        return -EINVAL;
                }
+
+               if (dflt_conf_name) {
+                       const char *node_name = fdt_get_name(fdt, node, NULL);
+                       if (strcmp(dflt_conf_name, node_name) == 0) {
+                               dflt_conf_node = node;
+                               dflt_conf_desc = name;
+                       }
+               }
+
                if (board_fit_config_name_match(name))
                        continue;
 
@@ -58,5 +71,10 @@ int fit_find_config_node(const void *fdt)
                return node;
        }
 
+       if (dflt_conf_node != -ENOENT) {
+               debug("Selecting default config '%s'\n", dflt_conf_desc);
+               return dflt_conf_node;
+       }
+
        return -ENOENT;
 }