Use a table to handle DTB matching.

Signed-off-by: Eric Chung <[email protected]>

---
v7:
- Abandon to load product name from ENV.
v6:
- Rebased onto latest upstream. Cleaned up board_fit_config_name_match()
  to maintain consistentcy with v5.
---
 board/spacemit/k1/spl.c | 50 +++++++++++++++++++++++++++++++------------------
 1 file changed, 32 insertions(+), 18 deletions(-)

diff --git a/board/spacemit/k1/spl.c b/board/spacemit/k1/spl.c
index 613e8c4cf02a..9f200f2fc184 100644
--- a/board/spacemit/k1/spl.c
+++ b/board/spacemit/k1/spl.c
@@ -97,6 +97,15 @@ static void i2c_early_init(void)
        }
 }
 
+static const struct {
+       const char *eeprom_name;
+       const char *fit_name;
+} k1_board_map[] = {
+       { "k1-x_MUSE-Pi-Pro",   "spacemit/k1-musepi-pro"    },
+       { "k1-x_deb1",          "spacemit/k1-bananapi-f3"   },
+       { "k1-x_milkv-jupiter", "spacemit/k1-milkv-jupiter" },
+};
+
 int read_product_name(char *name, int size)
 {
        u8 eeprom_data[TLV_TOTAL_LEN_MAX], *p;
@@ -130,6 +139,27 @@ int read_product_name(char *name, int size)
        return -ENOENT;
 }
 
+static void fixup_product_name(void)
+{
+       char fdt_name[I2C_BUF_SIZE];
+       int i;
+
+       for (i = 0; i < ARRAY_SIZE(k1_board_map); i++) {
+               memset(fdt_name, 0, I2C_BUF_SIZE);
+               if (!strncmp(product_name, k1_board_map[i].eeprom_name,
+                            strlen(k1_board_map[i].eeprom_name))) {
+                       snprintf(fdt_name, I2C_BUF_SIZE, "%s",
+                                k1_board_map[i].fit_name);
+                       break;
+               }
+       }
+       if (fdt_name[0] == '\0') {
+               /* set default board name */
+               sprintf(fdt_name, CONFIG_DEFAULT_DEVICE_TREE);
+       }
+       memcpy(product_name, fdt_name, I2C_BUF_SIZE);
+}
+
 static void clk_early_init(void)
 {
        struct udevice *dev;
@@ -369,6 +399,7 @@ void board_init_f(ulong dummy)
                log_info("Fail to detect board:%d\n", ret);
        else
                log_info("Get board name:%s\n", product_name);
+       fixup_product_name();
        pmic_init();
 
        ddr_early_init();
@@ -432,24 +463,7 @@ void spl_board_init(void)
 
 int board_fit_config_name_match(const char *name)
 {
-       char fdt_name[I2C_BUF_SIZE];
-       int i;
-
-       memset(fdt_name, 0, I2C_BUF_SIZE);
-       if (!strncmp(product_name, "k1-x_", 5)) {
-               snprintf(fdt_name, I2C_BUF_SIZE, "%s-%s", "k1",
-                        &product_name[5]);
-       }
-       if (fdt_name[0] == '\0') {
-               /* set default board name */
-               sprintf(fdt_name, "k1-musepi-pro");
-       }
-       for (i = 0; i < I2C_BUF_SIZE; i++) {
-               if (fdt_name[i] == '\0')
-                       break;
-               fdt_name[i] = tolower(fdt_name[i]);
-       }
-       if (!strcmp(name, fdt_name))
+       if (!strcmp(name, product_name))
                return 0;
        return -ENOENT;
 }

-- 
2.51.0

Reply via email to