MCPcopy Create free account
hub / github.com/coreboot/coreboot / flashconsole_init

Function flashconsole_init

src/drivers/spi/flashconsole.c:19–68  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

17static size_t line_offset;
18
19void flashconsole_init(void)
20{
21 uint8_t buffer[READ_BUFFER_SIZE];
22 size_t size;
23 size_t initial_offset = 0;
24 size_t len = READ_BUFFER_SIZE;
25 size_t i;
26
27 if (fmap_locate_area_as_rdev_rw("CONSOLE", &rdev)) {
28 printk(BIOS_INFO, "Can't find 'CONSOLE' area in FMAP\n");
29 return;
30 }
31 size = region_device_sz(&rdev);
32
33 /*
34 * We need to check the region until we find a 0xff indicating
35 * the end of a previous log write.
36 * We can't erase the region because one stage would erase the
37 * data from the previous stage. Also, it looks like doing an
38 * erase could completely freeze the SPI controller and then
39 * we can't write anything anymore (apparently might happen if
40 * the sector is already erased, so we would need to read
41 * anyways to check if it's all 0xff).
42 */
43 for (i = 0; i < len && initial_offset < size;) {
44 // Fill the buffer on first iteration
45 if (i == 0) {
46 len = MIN(READ_BUFFER_SIZE, size - offset);
47 if (rdev_readat(&rdev, buffer, initial_offset, len) != len)
48 return;
49 }
50 if (buffer[i] == 0xff) {
51 initial_offset += i;
52 break;
53 }
54 // If we're done, repeat the process for the next sector
55 if (++i == READ_BUFFER_SIZE) {
56 initial_offset += len;
57 i = 0;
58 }
59 }
60 // Make sure there is still space left on the console
61 if (initial_offset >= size) {
62 printk(BIOS_INFO, "No space left on 'console' region in SPI flash\n");
63 return;
64 }
65
66 offset = initial_offset;
67 rdev_ptr = &rdev;
68}
69
70void flashconsole_tx_byte(unsigned char c)
71{

Callers 1

__flashconsole_initFunction · 0.85

Calls 4

region_device_szFunction · 0.85
rdev_readatFunction · 0.85
printkFunction · 0.50

Tested by

no test coverage detected