From: Andreas Reichel <[email protected]>

On creation of a new environment automatically set in_progress,
but do not set ustate to INSTALLED as that will be done in the
end when finalizing the update process.

Signed-off-by: Andreas Reichel <[email protected]>
---
 env/env_api.c                 |  4 ++--
 env/env_api_fat.c             |  2 +-
 tools/tests/test_ebgenv_api.c | 15 ++++++++++++---
 3 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/env/env_api.c b/env/env_api.c
index 81b871a..c23b25c 100644
--- a/env/env_api.c
+++ b/env/env_api.c
@@ -75,10 +75,10 @@ int ebg_env_create_new(ebgenv_t *e)
                }
                BG_ENVDATA *new_data = ((BGENV *)e->bgenv)->data;
                uint32_t new_rev = new_data->revision;
-               uint8_t new_ustate = new_data->ustate;
+               uint8_t new_in_progress = new_data->in_progress;
                memcpy(new_data, latest_env->data, sizeof(BG_ENVDATA));
                new_data->revision = new_rev;
-               new_data->ustate = new_ustate;
+               new_data->in_progress = new_in_progress;
                bgenv_close(latest_env);
        } else {
                e->bgenv = latest_env;
diff --git a/env/env_api_fat.c b/env/env_api_fat.c
index 471084a..1790d43 100644
--- a/env/env_api_fat.c
+++ b/env/env_api_fat.c
@@ -420,7 +420,7 @@ BGENV *bgenv_create_new(void)
        memset(env_new->data, 0, sizeof(BG_ENVDATA));
        /* update revision field and testing mode */
        env_new->data->revision = new_rev;
-       env_new->data->ustate = 1;
+       env_new->data->in_progress = 1;
        /* set default watchdog timeout */
        env_new->data->watchdog_timeout_sec = 30;
 
diff --git a/tools/tests/test_ebgenv_api.c b/tools/tests/test_ebgenv_api.c
index 4820bac..f9ab55c 100644
--- a/tools/tests/test_ebgenv_api.c
+++ b/tools/tests/test_ebgenv_api.c
@@ -128,12 +128,11 @@ START_TEST(ebgenv_api_ebg_env_create_new)
 
        ck_assert(((BGENV *)e.bgenv)->data == &envdata[0]);
 
-
-       ck_assert_int_eq(((BGENV *)e.bgenv)->data->in_progress, 0);
+       ck_assert_int_eq(((BGENV *)e.bgenv)->data->in_progress, 1);
        ck_assert_int_eq(
                ((BGENV *)e.bgenv)->data->revision, ENV_NUM_CONFIG_PARTS+1);
 
-       ck_assert_int_eq(((BGENV *)e.bgenv)->data->ustate, USTATE_INSTALLED);
+       ck_assert_int_eq(((BGENV *)e.bgenv)->data->ustate, USTATE_OK);
        ck_assert_int_eq(((BGENV *)e.bgenv)->data->watchdog_timeout_sec, 44);
        (void)str16to8(buffer, ((BGENV *)e.bgenv)->data->kernelfile);
        ck_assert_int_eq(
@@ -141,6 +140,16 @@ START_TEST(ebgenv_api_ebg_env_create_new)
        (void)str16to8(buffer, ((BGENV *)e.bgenv)->data->kernelparams);
        ck_assert_int_eq(
                strncmp(buffer, kernelparams, strlen(kernelparams) + 1), 0);
+
+       /* Test that a new creation of environment does keep the current
+        * values if an update is already in progress
+        */
+       ret = ebg_env_create_new(&e);
+
+       ck_assert(((BGENV *)e.bgenv)->data == &envdata[0]);
+       ck_assert_int_eq(((BGENV *)e.bgenv)->data->ustate, USTATE_OK);
+       ck_assert_int_eq(
+               ((BGENV *)e.bgenv)->data->revision, ENV_NUM_CONFIG_PARTS+1);
 }
 END_TEST
 
-- 
2.15.0

-- 
You received this message because you are subscribed to the Google Groups "EFI 
Boot Guard" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/efibootguard-dev/20171122115942.960-5-andreas.reichel.ext%40siemens.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to