coreboot/src/drivers/spi/flashconsole.c
Patrick Georgi 6b5bc77c9b treewide: Remove "this file is part of" lines
Stefan thinks they don't add value.

Command used:
sed -i -e '/file is part of /d' $(git grep "file is part of " |egrep ":( */\*.*\*/\$|#|;#|-- | *\* )" | cut -d: -f1 |grep -v crossgcc |grep -v gcov | grep -v /elf.h |grep -v nvramtool)

The exceptions are for:
 - crossgcc (patch file)
 - gcov (imported from gcc)
 - elf.h (imported from GNU's libc)
 - nvramtool (more complicated header)

The removed lines are:
-       fmt.Fprintln(f, "/* This file is part of the coreboot project. */")
-# This file is part of a set of unofficial pre-commit hooks available
-/* This file is part of coreboot */
-# This file is part of msrtool.
-/* This file is part of msrtool. */
- * This file is part of ncurses, designed to be appended after curses.h.in
-/* This file is part of pgtblgen. */
- * This file is part of the coreboot project.
- /* This file is part of the coreboot project. */
-#  This file is part of the coreboot project.
-# This file is part of the coreboot project.
-## This file is part of the coreboot project.
--- This file is part of the coreboot project.
-/* This file is part of the coreboot project */
-/* This file is part of the coreboot project. */
-;## This file is part of the coreboot project.
-# This file is part of the coreboot project. It originated in the
- * This file is part of the coreinfo project.
-## This file is part of the coreinfo project.
- * This file is part of the depthcharge project.
-/* This file is part of the depthcharge project. */
-/* This file is part of the ectool project. */
- * This file is part of the GNU C Library.
- * This file is part of the libpayload project.
-## This file is part of the libpayload project.
-/* This file is part of the Linux kernel. */
-## This file is part of the superiotool project.
-/* This file is part of the superiotool project */
-/* This file is part of uio_usbdebug */

Change-Id: I82d872b3b337388c93d5f5bf704e9ee9e53ab3a9
Signed-off-by: Patrick Georgi <pgeorgi@google.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/41194
Reviewed-by: HAOUAS Elyes <ehaouas@noos.fr>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
2020-05-11 17:11:40 +00:00

117 lines
2.7 KiB
C

/* SPDX-License-Identifier: GPL-2.0-only */
#include <commonlib/helpers.h>
#include <commonlib/region.h>
#include <boot_device.h>
#include <fmap.h>
#include <console/console.h>
#include <console/flash.h>
#include <types.h>
#define LINE_BUFFER_SIZE 128
#define READ_BUFFER_SIZE 0x100
static const struct region_device *rdev_ptr;
static struct region_device rdev;
static uint8_t line_buffer[LINE_BUFFER_SIZE];
static size_t offset;
static size_t line_offset;
void flashconsole_init(void)
{
uint8_t buffer[READ_BUFFER_SIZE];
size_t size;
size_t initial_offset = 0;
size_t len = READ_BUFFER_SIZE;
size_t i;
if (fmap_locate_area_as_rdev_rw("CONSOLE", &rdev)) {
printk(BIOS_INFO, "Can't find 'CONSOLE' area in FMAP\n");
return;
}
size = region_device_sz(&rdev);
/*
* We need to check the region until we find a 0xff indicating
* the end of a previous log write.
* We can't erase the region because one stage would erase the
* data from the previous stage. Also, it looks like doing an
* erase could completely freeze the SPI controller and then
* we can't write anything anymore (apparently might happen if
* the sector is already erased, so we would need to read
* anyways to check if it's all 0xff).
*/
for (i = 0; i < len && initial_offset < size;) {
// Fill the buffer on first iteration
if (i == 0) {
len = MIN(READ_BUFFER_SIZE, size - offset);
if (rdev_readat(&rdev, buffer, initial_offset, len) != len)
return;
}
if (buffer[i] == 0xff) {
initial_offset += i;
break;
}
// If we're done, repeat the process for the next sector
if (++i == READ_BUFFER_SIZE) {
initial_offset += len;
i = 0;
}
}
// Make sure there is still space left on the console
if (initial_offset >= size) {
printk(BIOS_INFO, "No space left on 'console' region in SPI flash\n");
return;
}
offset = initial_offset;
rdev_ptr = &rdev;
}
void flashconsole_tx_byte(unsigned char c)
{
if (!rdev_ptr)
return;
size_t region_size = region_device_sz(rdev_ptr);
line_buffer[line_offset++] = c;
if (line_offset >= LINE_BUFFER_SIZE ||
offset + line_offset >= region_size || c == '\n') {
flashconsole_tx_flush();
}
}
void flashconsole_tx_flush(void)
{
size_t len = line_offset;
size_t region_size;
static int busy;
/* Prevent any recursive loops in case the spi flash driver
* calls printk (in case of transaction timeout or
* any other error while writing) */
if (busy)
return;
if (!rdev_ptr)
return;
busy = 1;
region_size = region_device_sz(rdev_ptr);
if (offset + len >= region_size)
len = region_size - offset;
if (rdev_writeat(&rdev, line_buffer, offset, len) != len)
return;
// If the region is full, stop future write attempts
if (offset + len >= region_size)
return;
offset += len;
line_offset = 0;
busy = 0;
}