Stefan Reinauer | 5380d51 | 2007-05-24 09:08:36 +0000 | [diff] [blame] | 1 | /* |
Uwe Hermann | d110764 | 2007-08-29 17:52:32 +0000 | [diff] [blame] | 2 | * This file is part of the flashrom project. |
Stefan Reinauer | 5380d51 | 2007-05-24 09:08:36 +0000 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2002 Steven James <pyro@linuxlabs.com> |
| 5 | * Copyright (C) 2002 Linux Networx |
| 6 | * (Written by Eric Biederman <ebiederman@lnxi.com> for Linux Networx) |
Stefan Reinauer | 2d853bb | 2009-03-17 14:39:25 +0000 | [diff] [blame] | 7 | * Copyright (C) 2006-2009 coresystems GmbH |
Stefan Reinauer | 5380d51 | 2007-05-24 09:08:36 +0000 | [diff] [blame] | 8 | * (Written by Stefan Reinauer <stepan@coresystems.de> for coresystems GmbH) |
Carl-Daniel Hailfinger | baaffe0 | 2010-02-02 11:09:03 +0000 | [diff] [blame] | 9 | * Copyright (C) 2010 Carl-Daniel Hailfinger |
Stefan Reinauer | 5380d51 | 2007-05-24 09:08:36 +0000 | [diff] [blame] | 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU General Public License as published by |
| 13 | * the Free Software Foundation; version 2 of the License. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
Stefan Reinauer | 5380d51 | 2007-05-24 09:08:36 +0000 | [diff] [blame] | 19 | */ |
| 20 | |
Carl-Daniel Hailfinger | 831e8f4 | 2010-05-30 22:24:40 +0000 | [diff] [blame] | 21 | #include <unistd.h> |
| 22 | #include <stdio.h> |
Stefan Tauner | 37e8686 | 2012-08-11 16:07:08 +0000 | [diff] [blame] | 23 | #include <ctype.h> |
Carl-Daniel Hailfinger | 1c6d2ff | 2012-08-27 00:44:42 +0000 | [diff] [blame] | 24 | #include <strings.h> |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 25 | #include <string.h> |
Adam Kaufman | 064b1f2 | 2007-02-06 19:47:50 +0000 | [diff] [blame] | 26 | #include "flash.h" |
Carl-Daniel Hailfinger | 5b997c3 | 2010-07-27 22:41:39 +0000 | [diff] [blame] | 27 | #include "programmer.h" |
Stefan Reinauer | 2fbe624 | 2008-01-18 16:17:44 +0000 | [diff] [blame] | 28 | #include "coreboot_tables.h" |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 29 | |
Stefan Tauner | b4e06bd | 2012-08-20 00:24:22 +0000 | [diff] [blame] | 30 | static char *cb_vendor = NULL, *cb_model = NULL; |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 31 | |
Stefan Tauner | b4e06bd | 2012-08-20 00:24:22 +0000 | [diff] [blame] | 32 | /* Tries to find coreboot IDs in the supplied image and compares them to the current IDs. |
| 33 | * Returns... |
Elyes HAOUAS | ac01baa | 2018-05-28 16:52:21 +0200 | [diff] [blame] | 34 | * -1 if IDs in the image do not match the IDs embedded in the current firmware, |
| 35 | * 0 if the IDs could not be found in the image or if they match correctly. |
Carl-Daniel Hailfinger | 2d927fb | 2012-01-04 00:48:27 +0000 | [diff] [blame] | 36 | */ |
Nico Huber | 519be66 | 2018-12-23 20:03:35 +0100 | [diff] [blame] | 37 | int cb_check_image(const uint8_t *image, unsigned int size) |
Carl-Daniel Hailfinger | 66ef4e5 | 2009-12-13 22:28:00 +0000 | [diff] [blame] | 38 | { |
Nico Huber | 441d2a4 | 2016-05-02 11:39:35 +0200 | [diff] [blame] | 39 | const unsigned int *walk; |
Stefan Tauner | 37e8686 | 2012-08-11 16:07:08 +0000 | [diff] [blame] | 40 | unsigned int mb_part_offset, mb_vendor_offset; |
Nico Huber | 441d2a4 | 2016-05-02 11:39:35 +0200 | [diff] [blame] | 41 | const char *mb_part, *mb_vendor; |
Stefan Tauner | 37e8686 | 2012-08-11 16:07:08 +0000 | [diff] [blame] | 42 | |
Nico Huber | 441d2a4 | 2016-05-02 11:39:35 +0200 | [diff] [blame] | 43 | walk = (const unsigned int *)(image + size - 0x10); |
Stefan Tauner | 37e8686 | 2012-08-11 16:07:08 +0000 | [diff] [blame] | 44 | walk--; |
| 45 | |
| 46 | if ((*walk) == 0 || ((*walk) & 0x3ff) != 0) { |
Stefan Tauner | b4e06bd | 2012-08-20 00:24:22 +0000 | [diff] [blame] | 47 | /* Some NVIDIA chipsets store chipset soft straps (IIRC Hypertransport init info etc.) in |
| 48 | * flash at exactly the location where coreboot image size, coreboot vendor name pointer and |
| 49 | * coreboot board name pointer are usually stored. In this case coreboot uses an alternate |
| 50 | * location for the coreboot image data. */ |
Nico Huber | 441d2a4 | 2016-05-02 11:39:35 +0200 | [diff] [blame] | 51 | walk = (const unsigned int *)(image + size - 0x80); |
Stefan Tauner | 37e8686 | 2012-08-11 16:07:08 +0000 | [diff] [blame] | 52 | walk--; |
| 53 | } |
| 54 | |
| 55 | /* |
| 56 | * Check if coreboot last image size is 0 or not a multiple of 1k or |
| 57 | * bigger than the chip or if the pointers to vendor ID or mainboard ID |
| 58 | * are outside the image of if the start of ID strings are nonsensical |
| 59 | * (nonprintable and not \0). |
| 60 | */ |
| 61 | mb_part_offset = *(walk - 1); |
| 62 | mb_vendor_offset = *(walk - 2); |
| 63 | if ((*walk) == 0 || ((*walk) & 0x3ff) != 0 || (*walk) > size || |
| 64 | mb_part_offset > size || mb_vendor_offset > size) { |
Stefan Tauner | b4e06bd | 2012-08-20 00:24:22 +0000 | [diff] [blame] | 65 | msg_pdbg("Flash image seems to be a legacy BIOS. Disabling coreboot-related checks.\n"); |
Stefan Tauner | 37e8686 | 2012-08-11 16:07:08 +0000 | [diff] [blame] | 66 | return 0; |
| 67 | } |
| 68 | |
Nico Huber | 441d2a4 | 2016-05-02 11:39:35 +0200 | [diff] [blame] | 69 | mb_part = (const char *)(image + size - mb_part_offset); |
| 70 | mb_vendor = (const char *)(image + size - mb_vendor_offset); |
Stefan Tauner | 37e8686 | 2012-08-11 16:07:08 +0000 | [diff] [blame] | 71 | if (!isprint((unsigned char)*mb_part) || |
| 72 | !isprint((unsigned char)*mb_vendor)) { |
Stefan Tauner | b4e06bd | 2012-08-20 00:24:22 +0000 | [diff] [blame] | 73 | msg_pdbg("Flash image seems to have garbage in the ID location. " |
| 74 | "Disabling coreboot-related checks.\n"); |
Stefan Tauner | 37e8686 | 2012-08-11 16:07:08 +0000 | [diff] [blame] | 75 | return 0; |
| 76 | } |
| 77 | |
| 78 | msg_pdbg("coreboot last image size (not ROM size) is %d bytes.\n", *walk); |
| 79 | |
Paul Menzel | 592d99c | 2014-11-01 23:12:33 +0000 | [diff] [blame] | 80 | msg_pdbg("Manufacturer: %s\n", mb_vendor); |
| 81 | msg_pdbg("Mainboard ID: %s\n", mb_part); |
Stefan Tauner | 37e8686 | 2012-08-11 16:07:08 +0000 | [diff] [blame] | 82 | |
| 83 | /* If these are not set, the coreboot table was not found. */ |
Stefan Tauner | b4e06bd | 2012-08-20 00:24:22 +0000 | [diff] [blame] | 84 | if (!cb_vendor || !cb_model) |
Stefan Tauner | 37e8686 | 2012-08-11 16:07:08 +0000 | [diff] [blame] | 85 | return 0; |
Stefan Tauner | 37e8686 | 2012-08-11 16:07:08 +0000 | [diff] [blame] | 86 | |
| 87 | /* These comparisons are case insensitive to make things a little less user^Werror prone. */ |
Paul Menzel | 592d99c | 2014-11-01 23:12:33 +0000 | [diff] [blame] | 88 | if (!strcasecmp(mb_vendor, cb_vendor) && !strcasecmp(mb_part, cb_model)) { |
Stefan Tauner | b4e06bd | 2012-08-20 00:24:22 +0000 | [diff] [blame] | 89 | msg_pdbg2("This coreboot image matches this mainboard.\n"); |
Stefan Tauner | 37e8686 | 2012-08-11 16:07:08 +0000 | [diff] [blame] | 90 | } else { |
Stefan Tauner | c6fa32d | 2013-01-04 22:54:07 +0000 | [diff] [blame] | 91 | msg_perr("This coreboot image (%s:%s) does not appear to\n" |
| 92 | "be correct for the detected mainboard (%s:%s).\n", |
Paul Menzel | 592d99c | 2014-11-01 23:12:33 +0000 | [diff] [blame] | 93 | mb_vendor, mb_part, cb_vendor, cb_model); |
Stefan Tauner | b4e06bd | 2012-08-20 00:24:22 +0000 | [diff] [blame] | 94 | return -1; |
Stefan Tauner | 37e8686 | 2012-08-11 16:07:08 +0000 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | return 0; |
| 98 | } |
| 99 | |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 100 | static unsigned long compute_checksum(void *addr, unsigned long length) |
| 101 | { |
| 102 | uint8_t *ptr; |
| 103 | volatile union { |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 104 | uint8_t byte[2]; |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 105 | uint16_t word; |
Michael Karcher | e7f3209 | 2010-01-12 15:36:24 +0000 | [diff] [blame] | 106 | } chksum; |
Uwe Hermann | ac30934 | 2007-10-10 17:42:20 +0000 | [diff] [blame] | 107 | unsigned long sum; |
| 108 | unsigned long i; |
Uwe Hermann | ffec5f3 | 2007-08-23 16:08:21 +0000 | [diff] [blame] | 109 | |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 110 | /* In the most straight forward way possible, |
| 111 | * compute an ip style checksum. |
| 112 | */ |
| 113 | sum = 0; |
| 114 | ptr = addr; |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 115 | for (i = 0; i < length; i++) { |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 116 | unsigned long value; |
| 117 | value = ptr[i]; |
Uwe Hermann | ac30934 | 2007-10-10 17:42:20 +0000 | [diff] [blame] | 118 | if (i & 1) { |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 119 | value <<= 8; |
Uwe Hermann | ac30934 | 2007-10-10 17:42:20 +0000 | [diff] [blame] | 120 | } |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 121 | /* Add the new value */ |
| 122 | sum += value; |
| 123 | /* Wrap around the carry */ |
Uwe Hermann | ac30934 | 2007-10-10 17:42:20 +0000 | [diff] [blame] | 124 | if (sum > 0xFFFF) { |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 125 | sum = (sum + (sum >> 16)) & 0xFFFF; |
Uwe Hermann | ac30934 | 2007-10-10 17:42:20 +0000 | [diff] [blame] | 126 | } |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 127 | } |
Michael Karcher | e7f3209 | 2010-01-12 15:36:24 +0000 | [diff] [blame] | 128 | chksum.byte[0] = sum & 0xff; |
| 129 | chksum.byte[1] = (sum >> 8) & 0xff; |
Uwe Hermann | ffec5f3 | 2007-08-23 16:08:21 +0000 | [diff] [blame] | 130 | |
Michael Karcher | e7f3209 | 2010-01-12 15:36:24 +0000 | [diff] [blame] | 131 | return (~chksum.word) & 0xFFFF; |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | #define for_each_lbrec(head, rec) \ |
| 135 | for(rec = (struct lb_record *)(((char *)head) + sizeof(*head)); \ |
| 136 | (((char *)rec) < (((char *)head) + sizeof(*head) + head->table_bytes)) && \ |
| 137 | (rec->size >= 1) && \ |
| 138 | ((((char *)rec) + rec->size) <= (((char *)head) + sizeof(*head) + head->table_bytes)); \ |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 139 | rec = (struct lb_record *)(((char *)rec) + rec->size)) |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 140 | |
Nico Huber | 519be66 | 2018-12-23 20:03:35 +0100 | [diff] [blame] | 141 | static unsigned int count_lb_records(struct lb_header *head) |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 142 | { |
| 143 | struct lb_record *rec; |
Nico Huber | 519be66 | 2018-12-23 20:03:35 +0100 | [diff] [blame] | 144 | unsigned int count; |
Uwe Hermann | ffec5f3 | 2007-08-23 16:08:21 +0000 | [diff] [blame] | 145 | |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 146 | count = 0; |
| 147 | for_each_lbrec(head, rec) { |
| 148 | count++; |
| 149 | } |
Uwe Hermann | ffec5f3 | 2007-08-23 16:08:21 +0000 | [diff] [blame] | 150 | |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 151 | return count; |
| 152 | } |
| 153 | |
Edward O'Callaghan | 4a55e68 | 2019-11-26 23:28:05 +1100 | [diff] [blame^] | 154 | static int lb_header_valid(struct lb_header *head, unsigned long addr) |
| 155 | { |
| 156 | if (memcmp(head->signature, "LBIO", 4) != 0) |
| 157 | return 0; |
| 158 | msg_pdbg("Found candidate at: %08lx-%08lx\n", |
| 159 | addr, addr + sizeof(*head) + head->table_bytes); |
| 160 | if (head->header_bytes != sizeof(*head)) { |
| 161 | msg_perr("Header bytes of %d are incorrect.\n", |
| 162 | head->header_bytes); |
| 163 | return 0; |
| 164 | } |
| 165 | if (compute_checksum((uint8_t *) head, sizeof(*head)) != 0) { |
| 166 | msg_perr("Bad header checksum.\n"); |
| 167 | return 0; |
| 168 | } |
| 169 | |
| 170 | return 1; |
| 171 | } |
| 172 | |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 173 | static struct lb_header *find_lb_table(void *base, unsigned long start, |
| 174 | unsigned long end) |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 175 | { |
| 176 | unsigned long addr; |
Uwe Hermann | ffec5f3 | 2007-08-23 16:08:21 +0000 | [diff] [blame] | 177 | |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 178 | /* For now be stupid.... */ |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 179 | for (addr = start; addr < end; addr += 16) { |
| 180 | struct lb_header *head = |
| 181 | (struct lb_header *)(((char *)base) + addr); |
| 182 | struct lb_record *recs = |
| 183 | (struct lb_record *)(((char *)base) + addr + sizeof(*head)); |
Edward O'Callaghan | 4a55e68 | 2019-11-26 23:28:05 +1100 | [diff] [blame^] | 184 | if (!lb_header_valid(head, addr)) |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 185 | continue; |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 186 | if (count_lb_records(head) != head->table_entries) { |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 187 | msg_perr("Bad record count: %d.\n", |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 188 | head->table_entries); |
| 189 | continue; |
| 190 | } |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 191 | if (compute_checksum(recs, head->table_bytes) |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 192 | != head->table_checksum) { |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 193 | msg_perr("Bad table checksum: %04x.\n", |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 194 | head->table_checksum); |
| 195 | continue; |
| 196 | } |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 197 | msg_pdbg("Found coreboot table at 0x%08lx.\n", addr); |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 198 | return head; |
| 199 | |
| 200 | }; |
Uwe Hermann | ffec5f3 | 2007-08-23 16:08:21 +0000 | [diff] [blame] | 201 | |
Peter Huewe | 73f8ec8 | 2011-01-24 19:15:51 +0000 | [diff] [blame] | 202 | return NULL; |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | static void find_mainboard(struct lb_record *ptr, unsigned long addr) |
| 206 | { |
| 207 | struct lb_mainboard *rec; |
| 208 | int max_size; |
| 209 | char vendor[256], part[256]; |
Uwe Hermann | ffec5f3 | 2007-08-23 16:08:21 +0000 | [diff] [blame] | 210 | |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 211 | rec = (struct lb_mainboard *)ptr; |
| 212 | max_size = rec->size - sizeof(*rec); |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 213 | msg_pdbg("Vendor ID: %.*s, part ID: %.*s\n", |
Stefan Tauner | b4e06bd | 2012-08-20 00:24:22 +0000 | [diff] [blame] | 214 | max_size - rec->vendor_idx, |
| 215 | rec->strings + rec->vendor_idx, |
| 216 | max_size - rec->part_number_idx, |
| 217 | rec->strings + rec->part_number_idx); |
| 218 | snprintf(vendor, 255, "%.*s", max_size - rec->vendor_idx, rec->strings + rec->vendor_idx); |
| 219 | snprintf(part, 255, "%.*s", max_size - rec->part_number_idx, rec->strings + rec->part_number_idx); |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 220 | |
Stefan Tauner | b4e06bd | 2012-08-20 00:24:22 +0000 | [diff] [blame] | 221 | cb_vendor = strdup(vendor); |
| 222 | cb_model = strdup(part); |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | static struct lb_record *next_record(struct lb_record *rec) |
| 226 | { |
| 227 | return (struct lb_record *)(((char *)rec) + rec->size); |
| 228 | } |
| 229 | |
Stefan Tauner | b4e06bd | 2012-08-20 00:24:22 +0000 | [diff] [blame] | 230 | static void search_lb_records(struct lb_record *rec, struct lb_record *last, unsigned long addr) |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 231 | { |
| 232 | struct lb_record *next; |
| 233 | int count; |
| 234 | count = 0; |
| 235 | |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 236 | for (next = next_record(rec); (rec < last) && (next <= last); |
| 237 | rec = next, addr += rec->size) { |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 238 | next = next_record(rec); |
| 239 | count++; |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 240 | if (rec->tag == LB_TAG_MAINBOARD) { |
| 241 | find_mainboard(rec, addr); |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 242 | break; |
| 243 | } |
| 244 | } |
| 245 | } |
| 246 | |
Stefan Reinauer | 2d853bb | 2009-03-17 14:39:25 +0000 | [diff] [blame] | 247 | #define BYTES_TO_MAP (1024*1024) |
Stefan Tauner | b4e06bd | 2012-08-20 00:24:22 +0000 | [diff] [blame] | 248 | /* returns 0 if the table was parsed successfully and cb_vendor/cb_model have been set. */ |
| 249 | int cb_parse_table(const char **vendor, const char **model) |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 250 | { |
Stefan Reinauer | 2d853bb | 2009-03-17 14:39:25 +0000 | [diff] [blame] | 251 | uint8_t *table_area; |
Stefan Reinauer | f79edb9 | 2009-01-26 01:23:31 +0000 | [diff] [blame] | 252 | unsigned long addr, start; |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 253 | struct lb_header *lb_table; |
| 254 | struct lb_record *rec, *last; |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 255 | |
Carl-Daniel Hailfinger | 60d9bd2 | 2012-08-09 23:34:41 +0000 | [diff] [blame] | 256 | #if defined(__MACH__) && defined(__APPLE__) |
Carl-Daniel Hailfinger | f992c19 | 2010-10-06 23:16:10 +0000 | [diff] [blame] | 257 | /* This is a hack. DirectHW fails to map physical address 0x00000000. |
Stefan Reinauer | f79edb9 | 2009-01-26 01:23:31 +0000 | [diff] [blame] | 258 | * Why? |
| 259 | */ |
| 260 | start = 0x400; |
| 261 | #else |
| 262 | start = 0x0; |
| 263 | #endif |
Carl-Daniel Hailfinger | 43eac03 | 2014-03-05 00:16:16 +0000 | [diff] [blame] | 264 | table_area = physmap_ro_unaligned("low megabyte", start, BYTES_TO_MAP - start); |
Patrick Georgi | ed7a964 | 2010-09-25 22:53:44 +0000 | [diff] [blame] | 265 | if (ERROR_PTR == table_area) { |
Carl-Daniel Hailfinger | baaffe0 | 2010-02-02 11:09:03 +0000 | [diff] [blame] | 266 | msg_perr("Failed getting access to coreboot low tables.\n"); |
| 267 | return -1; |
| 268 | } |
Stefan Reinauer | f79edb9 | 2009-01-26 01:23:31 +0000 | [diff] [blame] | 269 | |
Stefan Reinauer | 2d853bb | 2009-03-17 14:39:25 +0000 | [diff] [blame] | 270 | lb_table = find_lb_table(table_area, 0x00000, 0x1000); |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 271 | if (!lb_table) |
Carl-Daniel Hailfinger | baaffe0 | 2010-02-02 11:09:03 +0000 | [diff] [blame] | 272 | lb_table = find_lb_table(table_area, 0xf0000 - start, BYTES_TO_MAP - start); |
Stefan Reinauer | 2d853bb | 2009-03-17 14:39:25 +0000 | [diff] [blame] | 273 | if (lb_table) { |
| 274 | struct lb_forward *forward = (struct lb_forward *) |
| 275 | (((char *)lb_table) + lb_table->header_bytes); |
| 276 | if (forward->tag == LB_TAG_FORWARD) { |
| 277 | start = forward->forward; |
Uwe Hermann | 7b2969b | 2009-04-15 10:52:49 +0000 | [diff] [blame] | 278 | start &= ~(getpagesize() - 1); |
Carl-Daniel Hailfinger | 43eac03 | 2014-03-05 00:16:16 +0000 | [diff] [blame] | 279 | physunmap_unaligned(table_area, BYTES_TO_MAP); |
| 280 | // FIXME: table_area is never unmapped below, nor is it unmapped above in the no-forward case |
| 281 | table_area = physmap_ro_unaligned("high tables", start, BYTES_TO_MAP); |
Patrick Georgi | ed7a964 | 2010-09-25 22:53:44 +0000 | [diff] [blame] | 282 | if (ERROR_PTR == table_area) { |
Stefan Tauner | b4e06bd | 2012-08-20 00:24:22 +0000 | [diff] [blame] | 283 | msg_perr("Failed getting access to coreboot high tables.\n"); |
Carl-Daniel Hailfinger | baaffe0 | 2010-02-02 11:09:03 +0000 | [diff] [blame] | 284 | return -1; |
| 285 | } |
Stefan Reinauer | 2d853bb | 2009-03-17 14:39:25 +0000 | [diff] [blame] | 286 | lb_table = find_lb_table(table_area, 0x00000, 0x1000); |
| 287 | } |
| 288 | } |
| 289 | |
Peter Stuge | 2dc3aaa | 2009-01-26 00:15:56 +0000 | [diff] [blame] | 290 | if (!lb_table) { |
Stefan Reinauer | 12a04eb | 2011-04-01 18:05:20 +0000 | [diff] [blame] | 291 | msg_pdbg("No coreboot table found.\n"); |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 292 | return -1; |
| 293 | } |
Uwe Hermann | ffec5f3 | 2007-08-23 16:08:21 +0000 | [diff] [blame] | 294 | |
Stefan Reinauer | 2d853bb | 2009-03-17 14:39:25 +0000 | [diff] [blame] | 295 | addr = ((char *)lb_table) - ((char *)table_area) + start; |
Elyes HAOUAS | 124ef38 | 2018-03-27 12:15:09 +0200 | [diff] [blame] | 296 | msg_pinfo("coreboot table found at 0x%lx.\n", |
Stefan Reinauer | 2d853bb | 2009-03-17 14:39:25 +0000 | [diff] [blame] | 297 | (unsigned long)lb_table - (unsigned long)table_area + start); |
Peter Stuge | 2dc3aaa | 2009-01-26 00:15:56 +0000 | [diff] [blame] | 298 | rec = (struct lb_record *)(((char *)lb_table) + lb_table->header_bytes); |
| 299 | last = (struct lb_record *)(((char *)rec) + lb_table->table_bytes); |
Sean Nelson | 316a29f | 2010-05-07 20:09:04 +0000 | [diff] [blame] | 300 | msg_pdbg("coreboot header(%d) checksum: %04x table(%d) checksum: %04x entries: %d\n", |
Peter Stuge | 2dc3aaa | 2009-01-26 00:15:56 +0000 | [diff] [blame] | 301 | lb_table->header_bytes, lb_table->header_checksum, |
| 302 | lb_table->table_bytes, lb_table->table_checksum, |
| 303 | lb_table->table_entries); |
| 304 | search_lb_records(rec, last, addr + lb_table->header_bytes); |
Stefan Tauner | b4e06bd | 2012-08-20 00:24:22 +0000 | [diff] [blame] | 305 | *vendor = cb_vendor; |
| 306 | *model = cb_model; |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 307 | return 0; |
| 308 | } |