summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorAaron Durbin <adurbin@chromium.org>2016-07-11 12:16:08 -0500
committerAaron Durbin <adurbin@chromium.org>2016-07-12 23:38:39 +0200
commitedfcce80b2dc474f0701786e8d44a11d59deeb13 (patch)
tree57dca0a0044be82fbe552fe99a64580e14281e02 /src/lib
parent4934818118bdf36927bc8e15aa4d609ba2348b25 (diff)
downloadcoreboot-edfcce80b2dc474f0701786e8d44a11d59deeb13.tar.xz
lib/selfboot: don't open code linked list operations
The list insertion operations were open coded at each location. Add helper functions which provide the semantics needed by the selfboot code in a single place. Change-Id: Ic757255e01934b499def839131c257bde9d0cc93 Signed-off-by: Aaron Durbin <adurbin@chromium.org> Reviewed-on: https://review.coreboot.org/15601 Tested-by: build bot (Jenkins) Reviewed-by: Furquan Shaikh <furquan@google.com> Reviewed-by: Paul Menzel <paulepanter@users.sourceforge.net> Reviewed-by: Patrick Georgi <pgeorgi@google.com>
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/selfboot.c31
1 files changed, 19 insertions, 12 deletions
diff --git a/src/lib/selfboot.c b/src/lib/selfboot.c
index 75d67251b1..61784152dd 100644
--- a/src/lib/selfboot.c
+++ b/src/lib/selfboot.c
@@ -42,6 +42,22 @@ struct segment {
int compression;
};
+static void segment_insert_before(struct segment *seg, struct segment *new)
+{
+ new->next = seg;
+ new->prev = seg->prev;
+ seg->prev->next = new;
+ seg->prev = new;
+}
+
+static void segment_insert_after(struct segment *seg, struct segment *new)
+{
+ new->next = seg->next;
+ new->prev = seg;
+ seg->next->prev = new;
+ seg->next = new;
+}
+
/* The problem:
* Static executables all want to share the same addresses
* in memory because only a few addresses are reliably present on
@@ -148,10 +164,7 @@ static int relocate_segment(unsigned long buffer, struct segment *seg)
}
/* Order by stream offset */
- new->next = seg;
- new->prev = seg->prev;
- seg->prev->next = new;
- seg->prev = new;
+ segment_insert_before(seg, new);
/* compute the new value of start */
start = seg->s_dstaddr;
@@ -183,10 +196,7 @@ static int relocate_segment(unsigned long buffer, struct segment *seg)
new->s_filesz = 0;
}
/* Order by stream offset */
- new->next = seg->next;
- new->prev = seg;
- seg->next->prev = new;
- seg->next = new;
+ segment_insert_after(seg, new);
printk(BIOS_SPEW, " late: [0x%016lx, 0x%016lx, 0x%016lx)\n",
new->s_dstaddr,
@@ -311,10 +321,7 @@ static int build_self_segment_list(
/* We have found another CODE, DATA or BSS segment */
/* Insert new segment at the end of the list */
- new->next = head;
- new->prev = head->prev;
- head->prev->next = new;
- head->prev = new;
+ segment_insert_before(head, new);
}
return 1;