5 #include <types/types.h>
6 #include <talloc/talloc.h>
11 static struct platform *platform;
12 static struct config *config;
14 static void dump_config(struct config *config)
18 pb_log("configuration:\n");
20 if (config->autoboot_enabled)
21 pb_log(" autoboot: enabled, %d sec\n",
22 config->autoboot_timeout_sec);
24 pb_log(" autoboot: disabled\n");
26 if (config->network.n_interfaces || config->network.n_dns_servers)
27 pb_log(" network configuration:\n");
29 for (i = 0; i < config->network.n_interfaces; i++) {
30 struct interface_config *ifconf =
31 config->network.interfaces[i];
33 pb_log(" interface %02x:%02x:%02x:%02x:%02x:%02x\n",
34 ifconf->hwaddr[0], ifconf->hwaddr[1],
35 ifconf->hwaddr[2], ifconf->hwaddr[3],
36 ifconf->hwaddr[4], ifconf->hwaddr[5]);
43 if (ifconf->method == CONFIG_METHOD_DHCP) {
46 } else if (ifconf->method == CONFIG_METHOD_STATIC) {
48 pb_log(" ip: %s\n", ifconf->static_config.address);
49 pb_log(" gw: %s\n", ifconf->static_config.gateway);
53 for (i = 0; i < config->network.n_dns_servers; i++)
54 pb_log(" dns server %s\n", config->network.dns_servers[i]);
57 void config_set_defaults(struct config *config)
59 config->autoboot_enabled = true;
60 config->autoboot_timeout_sec = 10;
61 config->network.interfaces = NULL;
62 config->network.n_interfaces = 0;
63 config->network.dns_servers = NULL;
64 config->network.n_dns_servers = 0;
66 config->n_boot_priorities = 2;
67 config->boot_priorities = talloc_array(config, struct boot_priority,
68 config->n_boot_priorities);
69 config->boot_priorities[0].type = DEVICE_TYPE_NETWORK;
70 config->boot_priorities[1].type = DEVICE_TYPE_DISK;
74 int platform_init(void *ctx)
76 extern struct platform *__start_platforms, *__stop_platforms;
79 platform_ctx = talloc_new(ctx);
81 for (p = &__start_platforms; p < &__stop_platforms; p++) {
82 if (!(*p)->probe(*p, platform_ctx))
88 config = talloc(platform_ctx, struct config);
89 config_set_defaults(config);
92 pb_log("Detected platform type: %s\n", platform->name);
93 if (platform->load_config)
94 platform->load_config(platform, config);
96 pb_log("No platform type detected, some platform-specific "
97 "functionality will be disabled\n");
105 const struct platform *platform_get(void)
110 int config_set(struct config *newconfig)
114 if (!platform || !platform->save_config)
117 if (newconfig == config)
120 pb_log("new configuration data received\n");
121 dump_config(newconfig);
123 rc = platform->save_config(platform, newconfig);
126 config = talloc_steal(platform_ctx, newconfig);
128 pb_log("error saving new configuration; changes lost\n");
133 /* A non-exported function to allow the test infrastructure to initialise
134 * (and change) the configuration variables */
136 struct config __attribute__((unused)) *test_config_init(
137 struct parser_test *test);
138 struct config *test_config_init(struct parser_test *test)
140 config = talloc(test, struct config);
141 config_set_defaults(config);
145 const struct config *config_get(void)
150 void config_set_autoboot(bool autoboot_enabled)
152 config->autoboot_enabled = autoboot_enabled;
154 pb_log("set autoboot: %s\n",
155 config->autoboot_enabled ? "enabled" : "disabled");
158 int platform_fini(void)
160 talloc_free(platform_ctx);