From: Andreas Reichel <[email protected]>

User expects old values to be taken over when none are
specified i.e. in swupdate's sw-description. Thus behavior
of API is changed so that ebg_env_create_new takes the old
values except ustate and revision and copies them.

Signed-off-by: Andreas Reichel <[email protected]>
---
 env/env_api.c          | 8 ++++++++
 tools/tests/test_api.c | 3 +--
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/env/env_api.c b/env/env_api.c
index b3377fc..70e6241 100644
--- a/env/env_api.c
+++ b/env/env_api.c
@@ -66,7 +66,15 @@ int ebg_env_create_new(ebgenv_t *e)
        }
 
        if (!e->ebg_new_env_created) {
+               BGENV *latest_env = bgenv_open_latest();
                e->bgenv = (void *)bgenv_create_new();
+               BG_ENVDATA *new_data = ((BGENV *)e->bgenv)->data;
+               uint32_t new_rev = new_data->revision;
+               uint8_t new_ustate = new_data->ustate;
+               memcpy(new_data, latest_env->data, sizeof(BG_ENVDATA));
+               new_data->revision = new_rev;
+               new_data->ustate = new_ustate;
+               bgenv_close(latest_env);
        }
 
        e->ebg_new_env_created = e->bgenv != NULL;
diff --git a/tools/tests/test_api.c b/tools/tests/test_api.c
index 37247ff..fc5267d 100644
--- a/tools/tests/test_api.c
+++ b/tools/tests/test_api.c
@@ -149,11 +149,10 @@ static void test_api_update(void **state)
 {
        will_return(bgenv_open_latest, &env);
        will_return(bgenv_open_oldest, &envupdate);
+       will_return(bgenv_open_latest, &env);
        assert_int_equal(ebg_env_create_new(&e), 0);
 
        assert_int_equal(envupdate.data->revision, test_env_revision + 1);
-       assert_int_equal(envupdate.data->watchdog_timeout_sec,
-                        DEFAULT_WATCHDOG_TIMEOUT_SEC);
        assert_int_equal(envupdate.data->ustate, 1);
 
        assert_int_equal(ebg_env_set(&e, "ustate", "2"), 0);
-- 
2.14.1

-- 
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/20171005120001.18279-2-andreas.reichel.ext%40siemens.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to