summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKay Sievers <kay@vrfy.org>2013-02-19 20:41:13 +0100
committerKay Sievers <kay@vrfy.org>2013-02-19 20:41:13 +0100
commitbaf788f757ecd552c713c6e1d43008b0100d4d64 (patch)
tree13515de8b167daef89fa21b8fe886fa03db0213a
parent859b17d80b72597a22030552b3dbc49df7c7295f (diff)
setup: at "install", always move our boot entry to first slot in the order
-rw-r--r--src/setup/setup.c22
1 files changed, 19 insertions, 3 deletions
diff --git a/src/setup/setup.c b/src/setup/setup.c
index 1ddd195..bb83202 100644
--- a/src/setup/setup.c
+++ b/src/setup/setup.c
@@ -892,15 +892,31 @@ static int insert_into_order(uint16_t slot, bool first) {
n_order = efi_get_boot_order(&order);
if (n_order <= 0) {
+ /* no entry, add us */
err = efi_set_boot_order(&slot, 1);
goto finish;
}
+ /* are we the first and only one? */
+ if (n_order == 1 && order[0] == slot)
+ goto finish;
+
/* are we already in the boot order? */
- for (i = 0; i < n_order; i++)
- if (order[i] == slot)
+ for (i = 0; i < n_order; i++) {
+ if (order[i] != slot)
+ continue;
+
+ /* we do not require to be the first one, all is fine */
+ if (!first)
goto finish;
+ /* move us to the first slot */
+ memmove(&order[1], order, i * sizeof(uint16_t));
+ order[0] = slot;
+ efi_set_boot_order(order, n_order);
+ goto finish;
+ }
+
/* extend array */
new_order = realloc(order, (n_order+1) * sizeof(uint16_t));
if (!new_order) {
@@ -909,7 +925,7 @@ static int insert_into_order(uint16_t slot, bool first) {
}
order = new_order;
- /* add to the top or end of the list */
+ /* add us to the top or end of the list */
if (first) {
memmove(&order[1], order, n_order * sizeof(uint16_t));
order[0] = slot;