ebiederm | c779889 | 2009-04-01 11:03:32 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2003 Eric W. Biederman <ebiederm@xmission.com> |
| 5 | * Copyright (C) 2009 Ron Minnich <rminnich@gmail.com> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; version 2 of the License. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA, 02110-1301 USA |
| 19 | */ |
| 20 | |
Stefan Reinauer | 1377491 | 2011-10-14 15:19:21 -0700 | [diff] [blame] | 21 | #include <arch/byteorder.h> |
Ronald G. Minnich | ae63126 | 2009-04-01 10:48:39 +0000 | [diff] [blame] | 22 | #include <console/console.h> |
Stefan Reinauer | de3206a | 2010-02-22 06:09:43 +0000 | [diff] [blame] | 23 | #include <fallback.h> |
Ronald G. Minnich | ae63126 | 2009-04-01 10:48:39 +0000 | [diff] [blame] | 24 | #include <boot/elf.h> |
| 25 | #include <boot/elf_boot.h> |
| 26 | #include <boot/coreboot_tables.h> |
Ronald G. Minnich | ae63126 | 2009-04-01 10:48:39 +0000 | [diff] [blame] | 27 | #include <stdint.h> |
| 28 | #include <stdlib.h> |
| 29 | #include <string.h> |
Peter Stuge | 483b7bb | 2009-04-14 07:40:01 +0000 | [diff] [blame] | 30 | #include <cbfs.h> |
Myles Watson | 5817078 | 2009-10-28 16:13:28 +0000 | [diff] [blame] | 31 | #include <lib.h> |
Duncan Laurie | cde7801 | 2011-10-19 15:32:39 -0700 | [diff] [blame] | 32 | #if CONFIG_COLLECT_TIMESTAMPS |
| 33 | #include <timestamp.h> |
| 34 | #endif |
Stefan Reinauer | d37ab45 | 2012-12-18 16:23:28 -0800 | [diff] [blame^] | 35 | #include <coverage.h> |
Ronald G. Minnich | ae63126 | 2009-04-01 10:48:39 +0000 | [diff] [blame] | 36 | |
Stefan Reinauer | 1943629 | 2011-11-07 12:43:03 -0800 | [diff] [blame] | 37 | /* Maximum physical address we can use for the coreboot bounce buffer. */ |
Ronald G. Minnich | ae63126 | 2009-04-01 10:48:39 +0000 | [diff] [blame] | 38 | #ifndef MAX_ADDR |
| 39 | #define MAX_ADDR -1UL |
| 40 | #endif |
| 41 | |
Stefan Reinauer | 1943629 | 2011-11-07 12:43:03 -0800 | [diff] [blame] | 42 | /* from coreboot_ram.ld: */ |
Ronald G. Minnich | ae63126 | 2009-04-01 10:48:39 +0000 | [diff] [blame] | 43 | extern unsigned char _ram_seg; |
| 44 | extern unsigned char _eram_seg; |
| 45 | |
Stefan Reinauer | 1943629 | 2011-11-07 12:43:03 -0800 | [diff] [blame] | 46 | static const unsigned long lb_start = (unsigned long)&_ram_seg; |
| 47 | static const unsigned long lb_end = (unsigned long)&_eram_seg; |
| 48 | |
Ronald G. Minnich | ae63126 | 2009-04-01 10:48:39 +0000 | [diff] [blame] | 49 | struct segment { |
| 50 | struct segment *next; |
| 51 | struct segment *prev; |
Ronald G. Minnich | ae63126 | 2009-04-01 10:48:39 +0000 | [diff] [blame] | 52 | unsigned long s_dstaddr; |
| 53 | unsigned long s_srcaddr; |
| 54 | unsigned long s_memsz; |
| 55 | unsigned long s_filesz; |
Patrick Georgi | 369bc78 | 2009-04-25 07:32:24 +0000 | [diff] [blame] | 56 | int compression; |
Ronald G. Minnich | ae63126 | 2009-04-01 10:48:39 +0000 | [diff] [blame] | 57 | }; |
| 58 | |
Zheng Bao | e6ad7fa | 2009-11-05 10:02:59 +0000 | [diff] [blame] | 59 | /* The problem: |
Ronald G. Minnich | ae63126 | 2009-04-01 10:48:39 +0000 | [diff] [blame] | 60 | * Static executables all want to share the same addresses |
| 61 | * in memory because only a few addresses are reliably present on |
| 62 | * a machine, and implementing general relocation is hard. |
| 63 | * |
| 64 | * The solution: |
Stefan Reinauer | f64893a | 2009-07-23 22:03:14 +0000 | [diff] [blame] | 65 | * - Allocate a buffer the size of the coreboot image plus additional |
| 66 | * required space. |
| 67 | * - Anything that would overwrite coreboot copy into the lower part of |
Zheng Bao | e6ad7fa | 2009-11-05 10:02:59 +0000 | [diff] [blame] | 68 | * the buffer. |
Stefan Reinauer | f64893a | 2009-07-23 22:03:14 +0000 | [diff] [blame] | 69 | * - After loading an ELF image copy coreboot to the top of the buffer. |
Ronald G. Minnich | ae63126 | 2009-04-01 10:48:39 +0000 | [diff] [blame] | 70 | * - Then jump to the loaded image. |
Zheng Bao | e6ad7fa | 2009-11-05 10:02:59 +0000 | [diff] [blame] | 71 | * |
Ronald G. Minnich | ae63126 | 2009-04-01 10:48:39 +0000 | [diff] [blame] | 72 | * Benefits: |
| 73 | * - Nearly arbitrary standalone executables can be loaded. |
| 74 | * - Coreboot is preserved, so it can be returned to. |
| 75 | * - The implementation is still relatively simple, |
Zheng Bao | ba49fb7 | 2009-11-01 09:18:23 +0000 | [diff] [blame] | 76 | * and much simpler than the general case implemented in kexec. |
Ronald G. Minnich | ae63126 | 2009-04-01 10:48:39 +0000 | [diff] [blame] | 77 | */ |
| 78 | |
Patrick Georgi | 5eceb32 | 2009-05-13 16:27:25 +0000 | [diff] [blame] | 79 | static unsigned long bounce_size, bounce_buffer; |
| 80 | |
Myles Watson | 9202798 | 2009-09-23 20:32:21 +0000 | [diff] [blame] | 81 | static void get_bounce_buffer(struct lb_memory *mem, unsigned long req_size) |
Ronald G. Minnich | ae63126 | 2009-04-01 10:48:39 +0000 | [diff] [blame] | 82 | { |
| 83 | unsigned long lb_size; |
| 84 | unsigned long mem_entries; |
| 85 | unsigned long buffer; |
| 86 | int i; |
Stefan Reinauer | 1943629 | 2011-11-07 12:43:03 -0800 | [diff] [blame] | 87 | lb_size = lb_end - lb_start; |
| 88 | /* Plus coreboot size so I have somewhere |
| 89 | * to place a copy to return to. |
| 90 | */ |
Myles Watson | 9202798 | 2009-09-23 20:32:21 +0000 | [diff] [blame] | 91 | lb_size = req_size + lb_size; |
Stefan Reinauer | 1943629 | 2011-11-07 12:43:03 -0800 | [diff] [blame] | 92 | mem_entries = (mem->size - sizeof(*mem)) / sizeof(mem->map[0]); |
Ronald G. Minnich | ae63126 | 2009-04-01 10:48:39 +0000 | [diff] [blame] | 93 | buffer = 0; |
| 94 | for(i = 0; i < mem_entries; i++) { |
| 95 | unsigned long mstart, mend; |
| 96 | unsigned long msize; |
| 97 | unsigned long tbuffer; |
| 98 | if (mem->map[i].type != LB_MEM_RAM) |
| 99 | continue; |
| 100 | if (unpack_lb64(mem->map[i].start) > MAX_ADDR) |
| 101 | continue; |
| 102 | if (unpack_lb64(mem->map[i].size) < lb_size) |
| 103 | continue; |
| 104 | mstart = unpack_lb64(mem->map[i].start); |
| 105 | msize = MAX_ADDR - mstart +1; |
| 106 | if (msize > unpack_lb64(mem->map[i].size)) |
| 107 | msize = unpack_lb64(mem->map[i].size); |
| 108 | mend = mstart + msize; |
| 109 | tbuffer = mend - lb_size; |
Zheng Bao | e6ad7fa | 2009-11-05 10:02:59 +0000 | [diff] [blame] | 110 | if (tbuffer < buffer) |
Ronald G. Minnich | ae63126 | 2009-04-01 10:48:39 +0000 | [diff] [blame] | 111 | continue; |
| 112 | buffer = tbuffer; |
| 113 | } |
Patrick Georgi | 5eceb32 | 2009-05-13 16:27:25 +0000 | [diff] [blame] | 114 | bounce_buffer = buffer; |
Myles Watson | 9202798 | 2009-09-23 20:32:21 +0000 | [diff] [blame] | 115 | bounce_size = req_size; |
Ronald G. Minnich | ae63126 | 2009-04-01 10:48:39 +0000 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | static int valid_area(struct lb_memory *mem, unsigned long buffer, |
| 119 | unsigned long start, unsigned long len) |
| 120 | { |
| 121 | /* Check through all of the memory segments and ensure |
| 122 | * the segment that was passed in is completely contained |
| 123 | * in RAM. |
| 124 | */ |
| 125 | int i; |
| 126 | unsigned long end = start + len; |
Stefan Reinauer | 1943629 | 2011-11-07 12:43:03 -0800 | [diff] [blame] | 127 | unsigned long mem_entries = (mem->size - sizeof(*mem)) / |
| 128 | sizeof(mem->map[0]); |
Ronald G. Minnich | ae63126 | 2009-04-01 10:48:39 +0000 | [diff] [blame] | 129 | |
| 130 | /* See if I conflict with the bounce buffer */ |
| 131 | if (end >= buffer) { |
| 132 | return 0; |
| 133 | } |
| 134 | |
| 135 | /* Walk through the table of valid memory ranges and see if I |
| 136 | * have a match. |
| 137 | */ |
| 138 | for(i = 0; i < mem_entries; i++) { |
| 139 | uint64_t mstart, mend; |
| 140 | uint32_t mtype; |
| 141 | mtype = mem->map[i].type; |
| 142 | mstart = unpack_lb64(mem->map[i].start); |
| 143 | mend = mstart + unpack_lb64(mem->map[i].size); |
Stefan Reinauer | c6b8b7d | 2011-11-07 12:56:12 -0800 | [diff] [blame] | 144 | if ((mtype == LB_MEM_RAM) && (start >= mstart) && (end < mend)) { |
Ronald G. Minnich | ae63126 | 2009-04-01 10:48:39 +0000 | [diff] [blame] | 145 | break; |
| 146 | } |
Stefan Reinauer | c6b8b7d | 2011-11-07 12:56:12 -0800 | [diff] [blame] | 147 | if ((mtype == LB_MEM_TABLE) && (start >= mstart) && (end < mend)) { |
Stefan Reinauer | d6b4f1c | 2010-09-23 18:29:40 +0000 | [diff] [blame] | 148 | printk(BIOS_ERR, "Payload is overwriting coreboot tables.\n"); |
Ronald G. Minnich | ae63126 | 2009-04-01 10:48:39 +0000 | [diff] [blame] | 149 | break; |
| 150 | } |
| 151 | } |
| 152 | if (i == mem_entries) { |
Stefan Reinauer | 9ec8ed8 | 2011-10-18 15:11:04 -0700 | [diff] [blame] | 153 | if (start < (1024*1024) && end <=(1024*1024)) { |
| 154 | printk(BIOS_DEBUG, "Payload (probably SeaBIOS) loaded" |
| 155 | " into a reserved area in the lower 1MB\n"); |
| 156 | return 1; |
| 157 | } |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 158 | printk(BIOS_ERR, "No matching ram area found for range:\n"); |
| 159 | printk(BIOS_ERR, " [0x%016lx, 0x%016lx)\n", start, end); |
| 160 | printk(BIOS_ERR, "Ram areas\n"); |
Ronald G. Minnich | ae63126 | 2009-04-01 10:48:39 +0000 | [diff] [blame] | 161 | for(i = 0; i < mem_entries; i++) { |
| 162 | uint64_t mstart, mend; |
| 163 | uint32_t mtype; |
| 164 | mtype = mem->map[i].type; |
| 165 | mstart = unpack_lb64(mem->map[i].start); |
| 166 | mend = mstart + unpack_lb64(mem->map[i].size); |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 167 | printk(BIOS_ERR, " [0x%016lx, 0x%016lx) %s\n", |
Zheng Bao | e6ad7fa | 2009-11-05 10:02:59 +0000 | [diff] [blame] | 168 | (unsigned long)mstart, |
| 169 | (unsigned long)mend, |
Ronald G. Minnich | ae63126 | 2009-04-01 10:48:39 +0000 | [diff] [blame] | 170 | (mtype == LB_MEM_RAM)?"RAM":"Reserved"); |
Zheng Bao | e6ad7fa | 2009-11-05 10:02:59 +0000 | [diff] [blame] | 171 | |
Ronald G. Minnich | ae63126 | 2009-04-01 10:48:39 +0000 | [diff] [blame] | 172 | } |
| 173 | return 0; |
| 174 | } |
| 175 | return 1; |
| 176 | } |
| 177 | |
Patrick Georgi | 5eceb32 | 2009-05-13 16:27:25 +0000 | [diff] [blame] | 178 | |
| 179 | static int overlaps_coreboot(struct segment *seg) |
| 180 | { |
| 181 | unsigned long start, end; |
| 182 | start = seg->s_dstaddr; |
| 183 | end = start + seg->s_memsz; |
| 184 | return !((end <= lb_start) || (start >= lb_end)); |
| 185 | } |
| 186 | |
Zheng Bao | e6ad7fa | 2009-11-05 10:02:59 +0000 | [diff] [blame] | 187 | static int relocate_segment(unsigned long buffer, struct segment *seg) |
Ronald G. Minnich | ae63126 | 2009-04-01 10:48:39 +0000 | [diff] [blame] | 188 | { |
| 189 | /* Modify all segments that want to load onto coreboot |
| 190 | * to load onto the bounce buffer instead. |
| 191 | */ |
Zheng Bao | e6ad7fa | 2009-11-05 10:02:59 +0000 | [diff] [blame] | 192 | /* ret: 1 : A new segment is inserted before the seg. |
Stefan Reinauer | 1943629 | 2011-11-07 12:43:03 -0800 | [diff] [blame] | 193 | * 0 : A new segment is inserted after the seg, or no new one. |
| 194 | */ |
Zheng Bao | e6ad7fa | 2009-11-05 10:02:59 +0000 | [diff] [blame] | 195 | unsigned long start, middle, end, ret = 0; |
Ronald G. Minnich | ae63126 | 2009-04-01 10:48:39 +0000 | [diff] [blame] | 196 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 197 | printk(BIOS_SPEW, "lb: [0x%016lx, 0x%016lx)\n", |
Ronald G. Minnich | ae63126 | 2009-04-01 10:48:39 +0000 | [diff] [blame] | 198 | lb_start, lb_end); |
| 199 | |
Patrick Georgi | 5eceb32 | 2009-05-13 16:27:25 +0000 | [diff] [blame] | 200 | /* I don't conflict with coreboot so get out of here */ |
| 201 | if (!overlaps_coreboot(seg)) |
Zheng Bao | e6ad7fa | 2009-11-05 10:02:59 +0000 | [diff] [blame] | 202 | return 0; |
Patrick Georgi | 5eceb32 | 2009-05-13 16:27:25 +0000 | [diff] [blame] | 203 | |
Ronald G. Minnich | ae63126 | 2009-04-01 10:48:39 +0000 | [diff] [blame] | 204 | start = seg->s_dstaddr; |
| 205 | middle = start + seg->s_filesz; |
| 206 | end = start + seg->s_memsz; |
Ronald G. Minnich | ae63126 | 2009-04-01 10:48:39 +0000 | [diff] [blame] | 207 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 208 | printk(BIOS_SPEW, "segment: [0x%016lx, 0x%016lx, 0x%016lx)\n", |
Ronald G. Minnich | ae63126 | 2009-04-01 10:48:39 +0000 | [diff] [blame] | 209 | start, middle, end); |
| 210 | |
Patrick Georgi | 369bc78 | 2009-04-25 07:32:24 +0000 | [diff] [blame] | 211 | if (seg->compression == CBFS_COMPRESS_NONE) { |
| 212 | /* Slice off a piece at the beginning |
| 213 | * that doesn't conflict with coreboot. |
| 214 | */ |
| 215 | if (start < lb_start) { |
| 216 | struct segment *new; |
| 217 | unsigned long len = lb_start - start; |
| 218 | new = malloc(sizeof(*new)); |
| 219 | *new = *seg; |
| 220 | new->s_memsz = len; |
| 221 | seg->s_memsz -= len; |
| 222 | seg->s_dstaddr += len; |
| 223 | seg->s_srcaddr += len; |
| 224 | if (seg->s_filesz > len) { |
| 225 | new->s_filesz = len; |
| 226 | seg->s_filesz -= len; |
| 227 | } else { |
| 228 | seg->s_filesz = 0; |
| 229 | } |
| 230 | |
| 231 | /* Order by stream offset */ |
| 232 | new->next = seg; |
| 233 | new->prev = seg->prev; |
| 234 | seg->prev->next = new; |
| 235 | seg->prev = new; |
Patrick Georgi | 369bc78 | 2009-04-25 07:32:24 +0000 | [diff] [blame] | 236 | |
| 237 | /* compute the new value of start */ |
| 238 | start = seg->s_dstaddr; |
Zheng Bao | e6ad7fa | 2009-11-05 10:02:59 +0000 | [diff] [blame] | 239 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 240 | printk(BIOS_SPEW, " early: [0x%016lx, 0x%016lx, 0x%016lx)\n", |
Zheng Bao | e6ad7fa | 2009-11-05 10:02:59 +0000 | [diff] [blame] | 241 | new->s_dstaddr, |
Patrick Georgi | 369bc78 | 2009-04-25 07:32:24 +0000 | [diff] [blame] | 242 | new->s_dstaddr + new->s_filesz, |
| 243 | new->s_dstaddr + new->s_memsz); |
Zheng Bao | e6ad7fa | 2009-11-05 10:02:59 +0000 | [diff] [blame] | 244 | |
| 245 | ret = 1; |
Stefan Reinauer | f64893a | 2009-07-23 22:03:14 +0000 | [diff] [blame] | 246 | } |
Zheng Bao | e6ad7fa | 2009-11-05 10:02:59 +0000 | [diff] [blame] | 247 | |
| 248 | /* Slice off a piece at the end |
| 249 | * that doesn't conflict with coreboot |
Patrick Georgi | 369bc78 | 2009-04-25 07:32:24 +0000 | [diff] [blame] | 250 | */ |
| 251 | if (end > lb_end) { |
| 252 | unsigned long len = lb_end - start; |
| 253 | struct segment *new; |
| 254 | new = malloc(sizeof(*new)); |
| 255 | *new = *seg; |
| 256 | seg->s_memsz = len; |
| 257 | new->s_memsz -= len; |
| 258 | new->s_dstaddr += len; |
| 259 | new->s_srcaddr += len; |
| 260 | if (seg->s_filesz > len) { |
| 261 | seg->s_filesz = len; |
| 262 | new->s_filesz -= len; |
| 263 | } else { |
| 264 | new->s_filesz = 0; |
| 265 | } |
| 266 | /* Order by stream offset */ |
| 267 | new->next = seg->next; |
| 268 | new->prev = seg; |
| 269 | seg->next->prev = new; |
| 270 | seg->next = new; |
Patrick Georgi | 369bc78 | 2009-04-25 07:32:24 +0000 | [diff] [blame] | 271 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 272 | printk(BIOS_SPEW, " late: [0x%016lx, 0x%016lx, 0x%016lx)\n", |
Zheng Bao | e6ad7fa | 2009-11-05 10:02:59 +0000 | [diff] [blame] | 273 | new->s_dstaddr, |
Patrick Georgi | 369bc78 | 2009-04-25 07:32:24 +0000 | [diff] [blame] | 274 | new->s_dstaddr + new->s_filesz, |
| 275 | new->s_dstaddr + new->s_memsz); |
Ronald G. Minnich | ae63126 | 2009-04-01 10:48:39 +0000 | [diff] [blame] | 276 | } |
Ronald G. Minnich | ae63126 | 2009-04-01 10:48:39 +0000 | [diff] [blame] | 277 | } |
Stefan Reinauer | f64893a | 2009-07-23 22:03:14 +0000 | [diff] [blame] | 278 | |
Ronald G. Minnich | ae63126 | 2009-04-01 10:48:39 +0000 | [diff] [blame] | 279 | /* Now retarget this segment onto the bounce buffer */ |
Zheng Bao | e6ad7fa | 2009-11-05 10:02:59 +0000 | [diff] [blame] | 280 | /* sort of explanation: the buffer is a 1:1 mapping to coreboot. |
Ronald G. Minnich | ae63126 | 2009-04-01 10:48:39 +0000 | [diff] [blame] | 281 | * so you will make the dstaddr be this buffer, and it will get copied |
| 282 | * later to where coreboot lives. |
| 283 | */ |
| 284 | seg->s_dstaddr = buffer + (seg->s_dstaddr - lb_start); |
| 285 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 286 | printk(BIOS_SPEW, " bounce: [0x%016lx, 0x%016lx, 0x%016lx)\n", |
Zheng Bao | e6ad7fa | 2009-11-05 10:02:59 +0000 | [diff] [blame] | 287 | seg->s_dstaddr, |
| 288 | seg->s_dstaddr + seg->s_filesz, |
Ronald G. Minnich | ae63126 | 2009-04-01 10:48:39 +0000 | [diff] [blame] | 289 | seg->s_dstaddr + seg->s_memsz); |
Zheng Bao | e6ad7fa | 2009-11-05 10:02:59 +0000 | [diff] [blame] | 290 | |
| 291 | return ret; |
Ronald G. Minnich | ae63126 | 2009-04-01 10:48:39 +0000 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | |
| 295 | static int build_self_segment_list( |
Zheng Bao | e6ad7fa | 2009-11-05 10:02:59 +0000 | [diff] [blame] | 296 | struct segment *head, |
Patrick Georgi | 5eceb32 | 2009-05-13 16:27:25 +0000 | [diff] [blame] | 297 | struct lb_memory *mem, |
Peter Stuge | 483b7bb | 2009-04-14 07:40:01 +0000 | [diff] [blame] | 298 | struct cbfs_payload *payload, u32 *entry) |
Ronald G. Minnich | ae63126 | 2009-04-01 10:48:39 +0000 | [diff] [blame] | 299 | { |
| 300 | struct segment *new; |
| 301 | struct segment *ptr; |
Peter Stuge | 483b7bb | 2009-04-14 07:40:01 +0000 | [diff] [blame] | 302 | struct cbfs_payload_segment *segment, *first_segment; |
Ronald G. Minnich | ae63126 | 2009-04-01 10:48:39 +0000 | [diff] [blame] | 303 | memset(head, 0, sizeof(*head)); |
Ronald G. Minnich | ae63126 | 2009-04-01 10:48:39 +0000 | [diff] [blame] | 304 | head->next = head->prev = head; |
| 305 | first_segment = segment = &payload->segments; |
| 306 | |
| 307 | while(1) { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 308 | printk(BIOS_DEBUG, "Loading segment from rom address 0x%p\n", segment); |
Ronald G. Minnich | ae63126 | 2009-04-01 10:48:39 +0000 | [diff] [blame] | 309 | switch(segment->type) { |
Ronald G. Minnich | ae63126 | 2009-04-01 10:48:39 +0000 | [diff] [blame] | 310 | case PAYLOAD_SEGMENT_PARAMS: |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 311 | printk(BIOS_DEBUG, " parameter section (skipped)\n"); |
Ronald G. Minnich | ae63126 | 2009-04-01 10:48:39 +0000 | [diff] [blame] | 312 | segment++; |
| 313 | continue; |
Stefan Reinauer | f64893a | 2009-07-23 22:03:14 +0000 | [diff] [blame] | 314 | |
Ronald G. Minnich | ae63126 | 2009-04-01 10:48:39 +0000 | [diff] [blame] | 315 | case PAYLOAD_SEGMENT_CODE: |
| 316 | case PAYLOAD_SEGMENT_DATA: |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 317 | printk(BIOS_DEBUG, " %s (compression=%x)\n", |
Stefan Reinauer | f64893a | 2009-07-23 22:03:14 +0000 | [diff] [blame] | 318 | segment->type == PAYLOAD_SEGMENT_CODE ? "code" : "data", |
| 319 | ntohl(segment->compression)); |
| 320 | new = malloc(sizeof(*new)); |
Stefan Reinauer | 02e75b2 | 2011-10-17 09:51:15 -0700 | [diff] [blame] | 321 | new->s_dstaddr = ntohll(segment->load_addr); |
Stefan Reinauer | f64893a | 2009-07-23 22:03:14 +0000 | [diff] [blame] | 322 | new->s_memsz = ntohl(segment->mem_len); |
| 323 | new->compression = ntohl(segment->compression); |
Ronald G. Minnich | ae63126 | 2009-04-01 10:48:39 +0000 | [diff] [blame] | 324 | |
Stefan Reinauer | 02e75b2 | 2011-10-17 09:51:15 -0700 | [diff] [blame] | 325 | new->s_srcaddr = (u32) ((unsigned char *)first_segment) |
| 326 | + ntohl(segment->offset); |
Stefan Reinauer | f64893a | 2009-07-23 22:03:14 +0000 | [diff] [blame] | 327 | new->s_filesz = ntohl(segment->len); |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 328 | printk(BIOS_DEBUG, " New segment dstaddr 0x%lx memsize 0x%lx srcaddr 0x%lx filesize 0x%lx\n", |
Stefan Reinauer | f64893a | 2009-07-23 22:03:14 +0000 | [diff] [blame] | 329 | new->s_dstaddr, new->s_memsz, new->s_srcaddr, new->s_filesz); |
| 330 | /* Clean up the values */ |
| 331 | if (new->s_filesz > new->s_memsz) { |
| 332 | new->s_filesz = new->s_memsz; |
| 333 | } |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 334 | printk(BIOS_DEBUG, " (cleaned up) New segment addr 0x%lx size 0x%lx offset 0x%lx filesize 0x%lx\n", |
Stefan Reinauer | f64893a | 2009-07-23 22:03:14 +0000 | [diff] [blame] | 335 | new->s_dstaddr, new->s_memsz, new->s_srcaddr, new->s_filesz); |
| 336 | break; |
| 337 | |
Ronald G. Minnich | ae63126 | 2009-04-01 10:48:39 +0000 | [diff] [blame] | 338 | case PAYLOAD_SEGMENT_BSS: |
Stefan Reinauer | 02e75b2 | 2011-10-17 09:51:15 -0700 | [diff] [blame] | 339 | printk(BIOS_DEBUG, " BSS 0x%p (%d byte)\n", (void *) |
| 340 | (intptr_t)ntohll(segment->load_addr), |
| 341 | ntohl(segment->mem_len)); |
Ronald G. Minnich | ae63126 | 2009-04-01 10:48:39 +0000 | [diff] [blame] | 342 | new = malloc(sizeof(*new)); |
| 343 | new->s_filesz = 0; |
Stefan Reinauer | 02e75b2 | 2011-10-17 09:51:15 -0700 | [diff] [blame] | 344 | new->s_dstaddr = ntohll(segment->load_addr); |
Ronald G. Minnich | ae63126 | 2009-04-01 10:48:39 +0000 | [diff] [blame] | 345 | new->s_memsz = ntohl(segment->mem_len); |
Ronald G. Minnich | ae63126 | 2009-04-01 10:48:39 +0000 | [diff] [blame] | 346 | break; |
| 347 | |
| 348 | case PAYLOAD_SEGMENT_ENTRY: |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 349 | printk(BIOS_DEBUG, " Entry Point 0x%p\n", (void *) ntohl((u32) segment->load_addr)); |
Stefan Reinauer | 02e75b2 | 2011-10-17 09:51:15 -0700 | [diff] [blame] | 350 | *entry = ntohll(segment->load_addr); |
Stefan Reinauer | f64893a | 2009-07-23 22:03:14 +0000 | [diff] [blame] | 351 | /* Per definition, a payload always has the entry point |
| 352 | * as last segment. Thus, we use the occurence of the |
| 353 | * entry point as break condition for the loop. |
| 354 | * Can we actually just look at the number of section? |
| 355 | */ |
Ronald G. Minnich | ae63126 | 2009-04-01 10:48:39 +0000 | [diff] [blame] | 356 | return 1; |
Stefan Reinauer | f64893a | 2009-07-23 22:03:14 +0000 | [diff] [blame] | 357 | |
| 358 | default: |
| 359 | /* We found something that we don't know about. Throw |
| 360 | * hands into the sky and run away! |
| 361 | */ |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 362 | printk(BIOS_EMERG, "Bad segment type %x\n", segment->type); |
Stefan Reinauer | f64893a | 2009-07-23 22:03:14 +0000 | [diff] [blame] | 363 | return -1; |
Ronald G. Minnich | ae63126 | 2009-04-01 10:48:39 +0000 | [diff] [blame] | 364 | } |
Stefan Reinauer | f64893a | 2009-07-23 22:03:14 +0000 | [diff] [blame] | 365 | |
Stefan Reinauer | c44de49 | 2012-01-11 14:07:39 -0800 | [diff] [blame] | 366 | /* We have found another CODE, DATA or BSS segment */ |
Ronald G. Minnich | ae63126 | 2009-04-01 10:48:39 +0000 | [diff] [blame] | 367 | segment++; |
Stefan Reinauer | f64893a | 2009-07-23 22:03:14 +0000 | [diff] [blame] | 368 | |
Stefan Reinauer | c44de49 | 2012-01-11 14:07:39 -0800 | [diff] [blame] | 369 | /* Find place where to insert our segment */ |
Ronald G. Minnich | ae63126 | 2009-04-01 10:48:39 +0000 | [diff] [blame] | 370 | for(ptr = head->next; ptr != head; ptr = ptr->next) { |
Stefan Reinauer | 02e75b2 | 2011-10-17 09:51:15 -0700 | [diff] [blame] | 371 | if (new->s_srcaddr < ntohll(segment->load_addr)) |
Ronald G. Minnich | ae63126 | 2009-04-01 10:48:39 +0000 | [diff] [blame] | 372 | break; |
| 373 | } |
Stefan Reinauer | f64893a | 2009-07-23 22:03:14 +0000 | [diff] [blame] | 374 | |
Ronald G. Minnich | ae63126 | 2009-04-01 10:48:39 +0000 | [diff] [blame] | 375 | /* Order by stream offset */ |
| 376 | new->next = ptr; |
| 377 | new->prev = ptr->prev; |
| 378 | ptr->prev->next = new; |
| 379 | ptr->prev = new; |
Ronald G. Minnich | ae63126 | 2009-04-01 10:48:39 +0000 | [diff] [blame] | 380 | } |
Stefan Reinauer | f64893a | 2009-07-23 22:03:14 +0000 | [diff] [blame] | 381 | |
Ronald G. Minnich | ae63126 | 2009-04-01 10:48:39 +0000 | [diff] [blame] | 382 | return 1; |
Ronald G. Minnich | ae63126 | 2009-04-01 10:48:39 +0000 | [diff] [blame] | 383 | } |
| 384 | |
| 385 | static int load_self_segments( |
Patrick Georgi | 5eceb32 | 2009-05-13 16:27:25 +0000 | [diff] [blame] | 386 | struct segment *head, |
| 387 | struct lb_memory *mem, |
| 388 | struct cbfs_payload *payload) |
Ronald G. Minnich | ae63126 | 2009-04-01 10:48:39 +0000 | [diff] [blame] | 389 | { |
Ronald G. Minnich | ae63126 | 2009-04-01 10:48:39 +0000 | [diff] [blame] | 390 | struct segment *ptr; |
Zheng Bao | e6ad7fa | 2009-11-05 10:02:59 +0000 | [diff] [blame] | 391 | |
Patrick Georgi | 26dd71c | 2009-09-30 21:36:38 +0000 | [diff] [blame] | 392 | unsigned long bounce_high = lb_end; |
Patrick Georgi | 5eceb32 | 2009-05-13 16:27:25 +0000 | [diff] [blame] | 393 | for(ptr = head->next; ptr != head; ptr = ptr->next) { |
Stefan Reinauer | c44de49 | 2012-01-11 14:07:39 -0800 | [diff] [blame] | 394 | if (!overlaps_coreboot(ptr)) |
| 395 | continue; |
Patrick Georgi | 26dd71c | 2009-09-30 21:36:38 +0000 | [diff] [blame] | 396 | if (ptr->s_dstaddr + ptr->s_memsz > bounce_high) |
| 397 | bounce_high = ptr->s_dstaddr + ptr->s_memsz; |
Patrick Georgi | 5eceb32 | 2009-05-13 16:27:25 +0000 | [diff] [blame] | 398 | } |
Patrick Georgi | 26dd71c | 2009-09-30 21:36:38 +0000 | [diff] [blame] | 399 | get_bounce_buffer(mem, bounce_high - lb_start); |
Patrick Georgi | 5eceb32 | 2009-05-13 16:27:25 +0000 | [diff] [blame] | 400 | if (!bounce_buffer) { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 401 | printk(BIOS_ERR, "Could not find a bounce buffer...\n"); |
Patrick Georgi | 5eceb32 | 2009-05-13 16:27:25 +0000 | [diff] [blame] | 402 | return 0; |
| 403 | } |
| 404 | for(ptr = head->next; ptr != head; ptr = ptr->next) { |
| 405 | /* Verify the memory addresses in the segment are valid */ |
| 406 | if (!valid_area(mem, bounce_buffer, ptr->s_dstaddr, ptr->s_memsz)) |
| 407 | return 0; |
| 408 | } |
Ronald G. Minnich | ae63126 | 2009-04-01 10:48:39 +0000 | [diff] [blame] | 409 | for(ptr = head->next; ptr != head; ptr = ptr->next) { |
Stefan Reinauer | f64893a | 2009-07-23 22:03:14 +0000 | [diff] [blame] | 410 | unsigned char *dest, *src; |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 411 | printk(BIOS_DEBUG, "Loading Segment: addr: 0x%016lx memsz: 0x%016lx filesz: 0x%016lx\n", |
Ronald G. Minnich | ae63126 | 2009-04-01 10:48:39 +0000 | [diff] [blame] | 412 | ptr->s_dstaddr, ptr->s_memsz, ptr->s_filesz); |
Zheng Bao | e6ad7fa | 2009-11-05 10:02:59 +0000 | [diff] [blame] | 413 | |
Patrick Georgi | 5eceb32 | 2009-05-13 16:27:25 +0000 | [diff] [blame] | 414 | /* Modify the segment to load onto the bounce_buffer if necessary. |
| 415 | */ |
Zheng Bao | e6ad7fa | 2009-11-05 10:02:59 +0000 | [diff] [blame] | 416 | if (relocate_segment(bounce_buffer, ptr)) { |
| 417 | ptr = (ptr->prev)->prev; |
| 418 | continue; |
| 419 | } |
Patrick Georgi | 5eceb32 | 2009-05-13 16:27:25 +0000 | [diff] [blame] | 420 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 421 | printk(BIOS_DEBUG, "Post relocation: addr: 0x%016lx memsz: 0x%016lx filesz: 0x%016lx\n", |
Patrick Georgi | 5eceb32 | 2009-05-13 16:27:25 +0000 | [diff] [blame] | 422 | ptr->s_dstaddr, ptr->s_memsz, ptr->s_filesz); |
| 423 | |
Ronald G. Minnich | ae63126 | 2009-04-01 10:48:39 +0000 | [diff] [blame] | 424 | /* Compute the boundaries of the segment */ |
| 425 | dest = (unsigned char *)(ptr->s_dstaddr); |
Myles Watson | fa12b67 | 2009-04-30 22:45:41 +0000 | [diff] [blame] | 426 | src = (unsigned char *)(ptr->s_srcaddr); |
Zheng Bao | e6ad7fa | 2009-11-05 10:02:59 +0000 | [diff] [blame] | 427 | |
Ronald G. Minnich | ae63126 | 2009-04-01 10:48:39 +0000 | [diff] [blame] | 428 | /* Copy data from the initial buffer */ |
| 429 | if (ptr->s_filesz) { |
Ronald G. Minnich | 671cedc | 2009-05-14 21:26:28 +0000 | [diff] [blame] | 430 | unsigned char *middle, *end; |
Ronald G. Minnich | ae63126 | 2009-04-01 10:48:39 +0000 | [diff] [blame] | 431 | size_t len; |
| 432 | len = ptr->s_filesz; |
Patrick Georgi | 369bc78 | 2009-04-25 07:32:24 +0000 | [diff] [blame] | 433 | switch(ptr->compression) { |
Patrick Georgi | 369bc78 | 2009-04-25 07:32:24 +0000 | [diff] [blame] | 434 | case CBFS_COMPRESS_LZMA: { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 435 | printk(BIOS_DEBUG, "using LZMA\n"); |
Patrick Georgi | 369bc78 | 2009-04-25 07:32:24 +0000 | [diff] [blame] | 436 | len = ulzma(src, dest); |
Myles Watson | 94de72b | 2010-06-01 15:19:25 +0000 | [diff] [blame] | 437 | if (!len) /* Decompression Error. */ |
| 438 | return 0; |
Patrick Georgi | 369bc78 | 2009-04-25 07:32:24 +0000 | [diff] [blame] | 439 | break; |
| 440 | } |
Stefan Reinauer | 3e4fb9d | 2011-04-21 21:26:58 +0000 | [diff] [blame] | 441 | #if CONFIG_COMPRESSED_PAYLOAD_NRV2B |
Patrick Georgi | 369bc78 | 2009-04-25 07:32:24 +0000 | [diff] [blame] | 442 | case CBFS_COMPRESS_NRV2B: { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 443 | printk(BIOS_DEBUG, "using NRV2B\n"); |
Patrick Georgi | 369bc78 | 2009-04-25 07:32:24 +0000 | [diff] [blame] | 444 | unsigned long unrv2b(u8 *src, u8 *dst, unsigned long *ilen_p); |
| 445 | unsigned long tmp; |
| 446 | len = unrv2b(src, dest, &tmp); |
| 447 | break; |
| 448 | } |
| 449 | #endif |
| 450 | case CBFS_COMPRESS_NONE: { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 451 | printk(BIOS_DEBUG, "it's not compressed!\n"); |
Patrick Georgi | 369bc78 | 2009-04-25 07:32:24 +0000 | [diff] [blame] | 452 | memcpy(dest, src, len); |
| 453 | break; |
| 454 | } |
| 455 | default: |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 456 | printk(BIOS_INFO, "CBFS: Unknown compression type %d\n", ptr->compression); |
Patrick Georgi | 369bc78 | 2009-04-25 07:32:24 +0000 | [diff] [blame] | 457 | return -1; |
| 458 | } |
| 459 | end = dest + ptr->s_memsz; |
| 460 | middle = dest + len; |
Myles Watson | 94de72b | 2010-06-01 15:19:25 +0000 | [diff] [blame] | 461 | printk(BIOS_SPEW, "[ 0x%08lx, %08lx, 0x%08lx) <- %08lx\n", |
Patrick Georgi | 369bc78 | 2009-04-25 07:32:24 +0000 | [diff] [blame] | 462 | (unsigned long)dest, |
| 463 | (unsigned long)middle, |
| 464 | (unsigned long)end, |
| 465 | (unsigned long)src); |
Ronald G. Minnich | 671cedc | 2009-05-14 21:26:28 +0000 | [diff] [blame] | 466 | |
| 467 | /* Zero the extra bytes between middle & end */ |
| 468 | if (middle < end) { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 469 | printk(BIOS_DEBUG, "Clearing Segment: addr: 0x%016lx memsz: 0x%016lx\n", |
Ronald G. Minnich | 671cedc | 2009-05-14 21:26:28 +0000 | [diff] [blame] | 470 | (unsigned long)middle, (unsigned long)(end - middle)); |
Zheng Bao | e6ad7fa | 2009-11-05 10:02:59 +0000 | [diff] [blame] | 471 | |
Ronald G. Minnich | 671cedc | 2009-05-14 21:26:28 +0000 | [diff] [blame] | 472 | /* Zero the extra bytes */ |
| 473 | memset(middle, 0, end - middle); |
| 474 | } |
Patrick Georgi | 26dd71c | 2009-09-30 21:36:38 +0000 | [diff] [blame] | 475 | /* Copy the data that's outside the area that shadows coreboot_ram */ |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 476 | printk(BIOS_DEBUG, "dest %p, end %p, bouncebuffer %lx\n", dest, end, bounce_buffer); |
Patrick Georgi | 26dd71c | 2009-09-30 21:36:38 +0000 | [diff] [blame] | 477 | if ((unsigned long)end > bounce_buffer) { |
| 478 | if ((unsigned long)dest < bounce_buffer) { |
Myles Watson | 7943fe6 | 2009-10-30 02:08:07 +0000 | [diff] [blame] | 479 | unsigned char *from = dest; |
| 480 | unsigned char *to = (unsigned char*)(lb_start-(bounce_buffer-(unsigned long)dest)); |
Patrick Georgi | 26dd71c | 2009-09-30 21:36:38 +0000 | [diff] [blame] | 481 | unsigned long amount = bounce_buffer-(unsigned long)dest; |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 482 | printk(BIOS_DEBUG, "move prefix around: from %p, to %p, amount: %lx\n", from, to, amount); |
Patrick Georgi | 26dd71c | 2009-09-30 21:36:38 +0000 | [diff] [blame] | 483 | memcpy(to, from, amount); |
| 484 | } |
| 485 | if ((unsigned long)end > bounce_buffer + (lb_end - lb_start)) { |
| 486 | unsigned long from = bounce_buffer + (lb_end - lb_start); |
| 487 | unsigned long to = lb_end; |
Myles Watson | 7943fe6 | 2009-10-30 02:08:07 +0000 | [diff] [blame] | 488 | unsigned long amount = (unsigned long)end - from; |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 489 | printk(BIOS_DEBUG, "move suffix around: from %lx, to %lx, amount: %lx\n", from, to, amount); |
Myles Watson | 7943fe6 | 2009-10-30 02:08:07 +0000 | [diff] [blame] | 490 | memcpy((char*)to, (char*)from, amount); |
Patrick Georgi | 26dd71c | 2009-09-30 21:36:38 +0000 | [diff] [blame] | 491 | } |
| 492 | } |
Ronald G. Minnich | ae63126 | 2009-04-01 10:48:39 +0000 | [diff] [blame] | 493 | } |
| 494 | } |
| 495 | return 1; |
Ronald G. Minnich | ae63126 | 2009-04-01 10:48:39 +0000 | [diff] [blame] | 496 | } |
| 497 | |
Ronald G. Minnich | 9764d4c | 2012-06-12 16:29:32 -0700 | [diff] [blame] | 498 | int selfboot(struct lb_memory *mem, struct cbfs_payload *payload) |
Ronald G. Minnich | ae63126 | 2009-04-01 10:48:39 +0000 | [diff] [blame] | 499 | { |
Myles Watson | fa12b67 | 2009-04-30 22:45:41 +0000 | [diff] [blame] | 500 | u32 entry=0; |
Ronald G. Minnich | ae63126 | 2009-04-01 10:48:39 +0000 | [diff] [blame] | 501 | struct segment head; |
Ronald G. Minnich | ae63126 | 2009-04-01 10:48:39 +0000 | [diff] [blame] | 502 | |
| 503 | /* Preprocess the self segments */ |
Patrick Georgi | 5eceb32 | 2009-05-13 16:27:25 +0000 | [diff] [blame] | 504 | if (!build_self_segment_list(&head, mem, payload, &entry)) |
Ronald G. Minnich | ae63126 | 2009-04-01 10:48:39 +0000 | [diff] [blame] | 505 | goto out; |
| 506 | |
| 507 | /* Load the segments */ |
Patrick Georgi | 5eceb32 | 2009-05-13 16:27:25 +0000 | [diff] [blame] | 508 | if (!load_self_segments(&head, mem, payload)) |
Ronald G. Minnich | ae63126 | 2009-04-01 10:48:39 +0000 | [diff] [blame] | 509 | goto out; |
| 510 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 511 | printk(BIOS_SPEW, "Loaded segments\n"); |
Ronald G. Minnich | ae63126 | 2009-04-01 10:48:39 +0000 | [diff] [blame] | 512 | |
| 513 | /* Reset to booting from this image as late as possible */ |
| 514 | boot_successful(); |
| 515 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 516 | printk(BIOS_DEBUG, "Jumping to boot code at %x\n", entry); |
Alexandru Gagniuc | 5005bb06 | 2011-04-11 20:17:22 +0000 | [diff] [blame] | 517 | post_code(POST_ENTER_ELF_BOOT); |
Ronald G. Minnich | ae63126 | 2009-04-01 10:48:39 +0000 | [diff] [blame] | 518 | |
Duncan Laurie | cde7801 | 2011-10-19 15:32:39 -0700 | [diff] [blame] | 519 | #if CONFIG_COLLECT_TIMESTAMPS |
| 520 | timestamp_add_now(TS_SELFBOOT_JUMP); |
| 521 | #endif |
Stefan Reinauer | d37ab45 | 2012-12-18 16:23:28 -0800 | [diff] [blame^] | 522 | #if CONFIG_COVERAGE |
| 523 | coverage_exit(); |
| 524 | #endif |
Duncan Laurie | cde7801 | 2011-10-19 15:32:39 -0700 | [diff] [blame] | 525 | |
Stefan Reinauer | 75dbc38 | 2012-10-15 15:19:43 -0700 | [diff] [blame] | 526 | /* Before we go off to run the payload, see if |
| 527 | * we stayed within our bounds. |
| 528 | */ |
| 529 | checkstack(_estack, 0); |
| 530 | |
Ronald G. Minnich | ae63126 | 2009-04-01 10:48:39 +0000 | [diff] [blame] | 531 | /* Jump to kernel */ |
Patrick Georgi | 5eceb32 | 2009-05-13 16:27:25 +0000 | [diff] [blame] | 532 | jmp_to_elf_entry((void*)entry, bounce_buffer, bounce_size); |
Ronald G. Minnich | ae63126 | 2009-04-01 10:48:39 +0000 | [diff] [blame] | 533 | return 1; |
| 534 | |
Patrick Georgi | c5fc7db | 2012-03-07 15:55:47 +0100 | [diff] [blame] | 535 | out: |
Ronald G. Minnich | ae63126 | 2009-04-01 10:48:39 +0000 | [diff] [blame] | 536 | return 0; |
| 537 | } |
| 538 | |
Stefan Reinauer | 1943629 | 2011-11-07 12:43:03 -0800 | [diff] [blame] | 539 | void *cbfs_load_payload(struct lb_memory *lb_mem, const char *name) |
| 540 | { |
| 541 | struct cbfs_payload *payload; |
| 542 | |
| 543 | payload = (struct cbfs_payload *)cbfs_find_file(name, CBFS_TYPE_PAYLOAD); |
Stefan Reinauer | 1943629 | 2011-11-07 12:43:03 -0800 | [diff] [blame] | 544 | |
Ronald G. Minnich | 9764d4c | 2012-06-12 16:29:32 -0700 | [diff] [blame] | 545 | return payload; |
Stefan Reinauer | 1943629 | 2011-11-07 12:43:03 -0800 | [diff] [blame] | 546 | } |
| 547 | |