3 #include <types/types.h>
4 #include <talloc/talloc.h>
10 static struct config *config;
11 static struct config_storage *storage;
14 static void config_set_defaults(struct config *config)
16 config->autoboot_enabled = true;
17 config->autoboot_timeout_sec = 10;
18 config->network.interfaces = NULL;
19 config->network.n_interfaces = 0;
20 config->network.dns_servers = NULL;
21 config->network.n_dns_servers = 0;
23 config->n_boot_priorities = 2;
24 config->boot_priorities = talloc_array(config, struct boot_priority,
25 config->n_boot_priorities);
26 config->boot_priorities[0].type = DEVICE_TYPE_NETWORK;
27 config->boot_priorities[1].type = DEVICE_TYPE_DISK;
31 static void dump_config(struct config *config)
35 pb_log("configuration:\n");
37 if (config->autoboot_enabled)
38 pb_log(" autoboot: enabled, %d sec\n",
39 config->autoboot_timeout_sec);
41 pb_log(" autoboot: disabled\n");
43 if (config->network.n_interfaces || config->network.n_dns_servers)
44 pb_log(" network configuration:\n");
46 for (i = 0; i < config->network.n_interfaces; i++) {
47 struct interface_config *ifconf =
48 config->network.interfaces[i];
50 pb_log(" interface %02x:%02x:%02x:%02x:%02x:%02x\n",
51 ifconf->hwaddr[0], ifconf->hwaddr[1],
52 ifconf->hwaddr[2], ifconf->hwaddr[3],
53 ifconf->hwaddr[4], ifconf->hwaddr[5]);
60 if (ifconf->method == CONFIG_METHOD_DHCP) {
63 } else if (ifconf->method == CONFIG_METHOD_STATIC) {
65 pb_log(" ip: %s\n", ifconf->static_config.address);
66 pb_log(" gw: %s\n", ifconf->static_config.gateway);
70 for (i = 0; i < config->network.n_dns_servers; i++)
71 pb_log(" dns server %s\n", config->network.dns_servers[i]);
74 int config_init(void *ctx)
76 config = talloc(ctx, struct config);
77 config_set_defaults(config);
79 storage = create_powerpc_nvram_storage(config);
81 storage->load(storage, config);
88 /* A non-exported function to allow the test infrastructure to initialise
89 * (and change) the configuration variables */
91 struct config __attribute__((unused)) *test_config_init(
92 struct parser_test *test);
93 struct config *test_config_init(struct parser_test *test)
95 config = talloc(test, struct config);
96 config_set_defaults(config);
100 const struct config *config_get(void)
105 void config_set_autoboot(bool autoboot_enabled)
107 config->autoboot_enabled = autoboot_enabled;
109 pb_log("set autoboot: %s\n",
110 config->autoboot_enabled ? "enabled" : "disabled");
113 int config_fini(void)