From: Kay Sievers Date: Tue, 19 Feb 2013 19:41:13 +0000 (+0100) Subject: setup: at "install", always move our boot entry to first slot in the order X-Git-Tag: 23~6 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=baf788f757ecd552c713c6e1d43008b0100d4d64;p=platform%2Fupstream%2Fgummiboot.git setup: at "install", always move our boot entry to first slot in the order --- 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;