Make read-only guarantee user-settable
[petitboot] / discover / platform-powerpc.c
index bbffb604c8481d914b64b29a4be06935b45a4fc7..fc96305ad70bc56d71d5e002a5b03617a84a57a6 100644 (file)
@@ -39,7 +39,8 @@ struct platform_powerpc {
                                struct platform_powerpc *platform,
                                uint8_t *bootdev, bool *persistent);
        int             (*clear_ipmi_bootdev)(
-                               struct platform_powerpc *platform);
+                               struct platform_powerpc *platform,
+                               bool persistent);
        int             (*set_os_boot_sensor)(
                                struct platform_powerpc *platform);
 };
@@ -52,6 +53,7 @@ static const char *known_params[] = {
        "petitboot,bootdevs",
        "petitboot,language",
        "petitboot,debug?",
+       "petitboot,write?",
        NULL,
 };
 
@@ -547,6 +549,10 @@ static void populate_config(struct platform_powerpc *platform,
                val = get_param(platform, "petitboot,debug?");
                config->debug = val && !strcmp(val, "true");
        }
+
+       val = get_param(platform, "petitboot,write?");
+       if (val)
+               config->allow_writes = !strcmp(val, "true");
 }
 
 static char *iface_config_str(void *ctx, struct interface_config *config)
@@ -663,7 +669,7 @@ static void update_bootdev_config(struct platform_powerpc *platform,
                                                opt->uuid, delim);
                                break;
                        }
-                       tmp = val = talloc_asprintf_append(val, boot_str);
+                       tmp = val = talloc_asprintf_append(val, "%s", boot_str);
        }
 
        update_string_config(platform, "petitboot,bootdevs", val);
@@ -691,6 +697,14 @@ static int update_config(struct platform_powerpc *platform,
                val = tmp = talloc_asprintf(platform, "%d",
                                config->autoboot_timeout_sec);
 
+       if (config->ipmi_bootdev == IPMI_BOOTDEV_INVALID &&
+           platform->clear_ipmi_bootdev) {
+               platform->clear_ipmi_bootdev(platform,
+                               config->ipmi_bootdev_persistent);
+               config->ipmi_bootdev = IPMI_BOOTDEV_NONE;
+               config->ipmi_bootdev_persistent = false;
+       }
+
        update_string_config(platform, "petitboot,timeout", val);
        if (tmp)
                talloc_free(tmp);
@@ -698,6 +712,12 @@ static int update_config(struct platform_powerpc *platform,
        val = config->lang ?: "";
        update_string_config(platform, "petitboot,language", val);
 
+       if (config->allow_writes == defaults->allow_writes)
+               val = "";
+       else
+               val = config->allow_writes ? "true" : "false";
+       update_string_config(platform, "petitboot,write?", val);
+
        update_network_config(platform, config);
 
        update_bootdev_config(platform, config);
@@ -716,6 +736,7 @@ static void set_ipmi_bootdev(struct config *config, enum ipmi_bootdev bootdev,
        case IPMI_BOOTDEV_DISK:
        case IPMI_BOOTDEV_NETWORK:
        case IPMI_BOOTDEV_CDROM:
+       default:
                break;
        case IPMI_BOOTDEV_SETUP:
                config->autoboot_enabled = false;
@@ -805,10 +826,16 @@ static int write_bootdev_sysparam(const char *name, uint8_t val)
 }
 
 static int clear_ipmi_bootdev_sysparams(
-               struct platform_powerpc *platform __attribute__((unused)))
+               struct platform_powerpc *platform __attribute__((unused)),
+               bool persistent)
 {
-       /* invalidate next-boot-device setting */
-       write_bootdev_sysparam("next-boot-device", 0xff);
+       if (persistent) {
+               /* invalidate default-boot-device setting */
+               write_bootdev_sysparam("default-boot-device", 0xff);
+       } else {
+               /* invalidate next-boot-device setting */
+               write_bootdev_sysparam("next-boot-device", 0xff);
+       }
        return 0;
 }
 
@@ -835,7 +862,8 @@ static int get_ipmi_bootdev_sysparams(
        return 0;
 }
 
-static int clear_ipmi_bootdev_ipmi(struct platform_powerpc *platform)
+static int clear_ipmi_bootdev_ipmi(struct platform_powerpc *platform,
+                                  bool persistent __attribute__((unused)))
 {
        uint16_t resp_len;
        uint8_t resp[1];
@@ -1000,7 +1028,7 @@ static void pre_boot(struct platform *p, const struct config *config)
        struct platform_powerpc *platform = to_platform_powerpc(p);
 
        if (!config->ipmi_bootdev_persistent && platform->clear_ipmi_bootdev)
-               platform->clear_ipmi_bootdev(platform);
+               platform->clear_ipmi_bootdev(platform, false);
 
        if (platform->set_os_boot_sensor)
                platform->set_os_boot_sensor(platform);