| 1 |
|
| 2 |
|
| 3 |
#include <bootblock_common.h> |
| 4 |
#include <soc/soc.h> |
| 5 |
#include <soc/spi.h> |
| 6 |
#include <soc/uart.h> |
| 7 |
#include <soc/gpio.h> |
| 8 |
#include <spi_flash.h> |
| 9 |
#include <console/console.h> |
| 10 |
#include <fmap.h> |
| 11 |
#include "mainboard.h" |
| 12 |
|
| 13 |
void bootblock_mainboard_early_init(void) |
| 14 |
{ |
| 15 |
|
| 16 |
gpio_output(ELGON_GPIO_UART_SEL, 0); |
| 17 |
|
| 18 |
|
| 19 |
gpio_output(ELGON_GPIO_ERROR_LED, 0); |
| 20 |
|
| 21 |
if (CONFIG(BOOTBLOCK_CONSOLE)) { |
| 22 |
if (!uart_is_enabled(CONFIG_UART_FOR_CONSOLE)) |
| 23 |
uart_setup(CONFIG_UART_FOR_CONSOLE, CONFIG_TTYS0_BAUD); |
| 24 |
} |
| 25 |
} |
| 26 |
|
| 27 |
static void configure_spi_flash(void) |
| 28 |
{ |
| 29 |
|
| 30 |
spi_init_custom(0, |
| 31 |
28000000, |
| 32 |
0, |
| 33 |
0, |
| 34 |
0, |
| 35 |
0, |
| 36 |
1); |
| 37 |
|
| 38 |
|
| 39 |
gpio_output(ELGON_GPIO_SPI_MUX, 1); |
| 40 |
} |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
static void protect_ro_rgn_spi_flash(void) |
| 49 |
{ |
| 50 |
const struct spi_flash *flash = boot_device_spi_flash(); |
| 51 |
const char *fmapname = "WP_RO"; |
| 52 |
struct region ro_rgn; |
| 53 |
|
| 54 |
if (fmap_locate_area(fmapname, &ro_rgn)) { |
| 55 |
printk(BIOS_ERR, "%s: No %s FMAP section.\n", __func__, |
| 56 |
fmapname); |
| 57 |
die("Can't verify flash protections!"); |
| 58 |
} |
| 59 |
|
| 60 |
u8 reg8 = 0; |
| 61 |
spi_flash_status(flash, ®8); |
| 62 |
|
| 63 |
|
| 64 |
if (!(reg8 & 0x80) || |
| 65 |
spi_flash_is_write_protected(flash, &ro_rgn) != 1) { |
| 66 |
printk(BIOS_WARNING, "%s: FMAP section %s is not write-protected\n", |
| 67 |
__func__, fmapname); |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
if (spi_flash_set_write_protected(flash, &ro_rgn, |
| 75 |
SPI_WRITE_PROTECTION_PIN) != 0) |
| 76 |
die("Failed to write-protect WP_RO region!"); |
| 77 |
} |
| 78 |
printk(BIOS_INFO, "%s: FMAP section %s is write-protected\n", |
| 79 |
__func__, fmapname); |
| 80 |
} |
| 81 |
|
| 82 |
void bootblock_mainboard_init(void) |
| 83 |
{ |
| 84 |
configure_spi_flash(); |
| 85 |
protect_ro_rgn_spi_flash(); |
| 86 |
} |