]> git.ozlabs.org Git - yaboot.git/blobdiff - second/cfg.c
use of cfg_set_default_by_mac() function in yaboot.c
[yaboot.git] / second / cfg.c
index 56b058af5ecde651e6ccf265d00a8802e264e94d..fe3f1e1b40d8c78ed4d8d396d42792582ff63904 100644 (file)
@@ -422,6 +422,30 @@ cfg_set_redo:
      return 0;
 }
 
+static int cfg_reset ()
+{
+    CONFIG *walk;
+#if DEBUG
+    prom_printf("Resetting image table\n");
+#endif
+    line_num = 0;
+    images = NULL;
+    curr_table = NULL;
+    curr_table = cf_options;
+    for (walk = curr_table; walk->type != cft_end; walk++) {
+#if DEBUG
+        prom_printf("ItemA %s = %s\n", walk->name, walk->data);
+#endif
+        if (walk->data != NULL)
+            walk->data = NULL;
+#if DEBUG
+        prom_printf("ItemB %s = %s\n\n", walk->name, walk->data);
+#endif
+    }
+
+    return 0;
+}
+
 int cfg_parse (char *cfg_file, char *buff, int len)
 {
      char *item, *value;
@@ -430,6 +454,8 @@ int cfg_parse (char *cfg_file, char *buff, int len)
      currp = buff;
      endp = currp + len;
 
+     cfg_reset();
+
      if (setjmp (env))
          return -1;
      while (1) {
@@ -559,6 +585,43 @@ char *cfg_get_default (void)
      return ret;
 }
 
+/*
+ * cfg_set_default_by_mac ()
+ * return 1 if the default cf_option was changed to label with the MAC addr
+ * return 0 if not changed
+ */
+int cfg_set_default_by_mac (char *mac_addr)
+{
+     CONFIG *walk;
+     struct IMAGES *tmp;
+     char * label = NULL;
+     int haslabel = 0;
+
+     /* check if there is an image label equal to mac_addr */
+     for (tmp = images; tmp; tmp = tmp->next) {
+        label = cfg_get_strg_i (tmp->table, "label");
+        if (!strcmp(label,mac_addr)){
+            haslabel = 1;
+        }
+     }
+
+     if (!haslabel)
+         return 0;
+     else {
+         /*
+          * if there is an image label equal to mac_addr, change the default
+          * cf_options to this image label
+          */
+         for (walk = cf_options; walk->type != cft_end; walk++) {
+             if (!strcasecmp(walk->name,"default")) {
+                 walk->data = mac_addr;
+                 return 1;
+             }
+         }
+         return 0;
+     }
+}
+
 /*
  * Local variables:
  * c-file-style: "k&r"