Showing with 193 additions and 74 deletions.
  1. +9 −1 CHANGELOG.md
  2. +48 −48 README.md
  3. +1 −1 include/flash_access.h
  4. +134 −23 sortbootorder.c
  5. +1 −1 utils/flash_access.c
10 changes: 9 additions & 1 deletion CHANGELOG.md
Expand Up @@ -7,6 +7,13 @@ Releases 4.5.x and 4.6.x are based on mainline support submitted in
[this gerrit ref](https://review.coreboot.org/#/c/14138/).

## [Unreleased]
## [v4.6.21] - 2021-05-27
### Added
- support for bootorder in FMAP region for persistent settings

## Changed
- The description of UART C/D toggles now shows the current state: GPIO or UART

## [v4.6.20] - 2020-08-27
### Fixed
- minor build fix for mainline coreboot
Expand Down Expand Up @@ -200,7 +207,8 @@ initial commit based on [coreboot_140908](http://pcengines.ch/tmp/coreboot_14090
### Fixed
- used proper way to access extended SPI registers

[Unreleased]: https://github.com/pcengines/sortbootorder/compare/v4.6.20...master
[Unreleased]: https://github.com/pcengines/sortbootorder/compare/v4.6.21...master
[v4.6.21]: https://github.com/pcengines/sortbootorder/compare/v4.6.20...v4.6.21
[v4.6.20]: https://github.com/pcengines/sortbootorder/compare/v4.6.19...v4.6.20
[v4.6.19]: https://github.com/pcengines/sortbootorder/compare/v4.6.18...v4.6.19
[v4.6.18]: https://github.com/pcengines/sortbootorder/compare/v4.6.17...v4.6.18
Expand Down
96 changes: 48 additions & 48 deletions README.md
Expand Up @@ -44,8 +44,8 @@ saves boot order in flash.
u USB boot - Currently Enabled
t Serial console - Currently Enabled
k Redirect console output to COM2 - Currently Disabled
o UART C - Currently Enabled
p UART D - Currently Enabled
o UART C - Currently Enabled - Toggle UART C / GPIO
p UART D - Currently Enabled - Toggle UART D / GPIO
m Force mPCIe2 slot CLK (GPP3 PCIe) - Currently Disabled
h EHCI0 controller - Currently Disabled
l Core Performance Boost - Currently Enabled
Expand All @@ -72,10 +72,10 @@ key.
* `t Serial console` - enables/disables output to the serial console
Useful for legacy software, which is not using native serial port output, but
uses standard PC text console instead (eg. FreeDOS).
* `o UART C` - enables/disables UART C on GPIO header. Disabled UART means
enabled GPIO.
* `p UART D` - enables/disables UART D on GPIO header. Disabled UART means
enabled GPIO.
* `o UART C` - enables/disables UART C on GPIO header. Disabled UART C means
enabled GPIO[0..7].
* `p UART D` - enables/disables UART D on GPIO header. Disabled UART D means
enabled GPIO[10..17].
* `m Force mPCIe2 slot CLK (GPP3 PCIe)` - enabling this option forces GPP3 PCIe
clock (which is attached to mPCIe2 slot) to be always on. This helps in some
cases, one example could be
Expand Down Expand Up @@ -257,27 +257,27 @@ in the main menu. Option description:
```
> p
1) Protected range 000000h – 000000h (currently enabled)
2) Protected range 7E0000h – 7FFFFFh
3) Protected range 7C0000h – 7FFFFFh
4) Protected range 780000h – 7FFFFFh
5) Protected range 700000h – 7FFFFFh
6) Protected range 600000h – 7FFFFFh
7) Protected range 400000h – 7FFFFFh
8) Protected range 000000h – 01FFFFh
9) Protected range 000000h – 03FFFFh
10) Protected range 000000h – 07FFFFh
11) Protected range 000000h – 0FFFFFh
12) Protected range 000000h – 1FFFFFh
13) Protected range 000000h – 3FFFFFh
14) Protected range 000000h – 7FFFFFh
15) Protected range 7FF000h – 7FFFFFh
16) Protected range 7FE000h – 7FFFFFh
17) Protected range 7FC000h – 7FFFFFh
18) Protected range 7F8000h – 7FFFFFh
19) Protected range 000000h – 000FFFh
20) Protected range 000000h – 001FFFh
21) Protected range 000000h – 003FFFh
22) Protected range 000000h – 007FFFh
2) Protected range 7E0000h – 7FFFFFh
3) Protected range 7C0000h – 7FFFFFh
4) Protected range 780000h – 7FFFFFh
5) Protected range 700000h – 7FFFFFh
6) Protected range 600000h – 7FFFFFh
7) Protected range 400000h – 7FFFFFh
8) Protected range 000000h – 01FFFFh
9) Protected range 000000h – 03FFFFh
10) Protected range 000000h – 07FFFFh
11) Protected range 000000h – 0FFFFFh
12) Protected range 000000h – 1FFFFFh
13) Protected range 000000h – 3FFFFFh
14) Protected range 000000h – 7FFFFFh
15) Protected range 7FF000h – 7FFFFFh
16) Protected range 7FE000h – 7FFFFFh
17) Protected range 7FC000h – 7FFFFFh
18) Protected range 7F8000h – 7FFFFFh
19) Protected range 000000h – 000FFFh
20) Protected range 000000h – 001FFFh
21) Protected range 000000h – 003FFFh
22) Protected range 000000h – 007FFFh
...
> s
Expand All @@ -293,28 +293,28 @@ SRP0=0 , SRP1=0, WP=?
> b 5
Setting block protection success!
> p
1) Protected range 000000h – 000000h
2) Protected range 7E0000h – 7FFFFFh
3) Protected range 7C0000h – 7FFFFFh
4) Protected range 780000h – 7FFFFFh
1) Protected range 000000h – 000000h
2) Protected range 7E0000h – 7FFFFFh
3) Protected range 7C0000h – 7FFFFFh
4) Protected range 780000h – 7FFFFFh
5) Protected range 700000h – 7FFFFFh (currently enabled)
6) Protected range 600000h – 7FFFFFh
7) Protected range 400000h – 7FFFFFh
8) Protected range 000000h – 01FFFFh
9) Protected range 000000h – 03FFFFh
10) Protected range 000000h – 07FFFFh
11) Protected range 000000h – 0FFFFFh
12) Protected range 000000h – 1FFFFFh
13) Protected range 000000h – 3FFFFFh
14) Protected range 000000h – 7FFFFFh
15) Protected range 7FF000h – 7FFFFFh
16) Protected range 7FE000h – 7FFFFFh
17) Protected range 7FC000h – 7FFFFFh
18) Protected range 7F8000h – 7FFFFFh
19) Protected range 000000h – 000FFFh
20) Protected range 000000h – 001FFFh
21) Protected range 000000h – 003FFFh
22) Protected range 000000h – 007FFFh
6) Protected range 600000h – 7FFFFFh
7) Protected range 400000h – 7FFFFFh
8) Protected range 000000h – 01FFFFh
9) Protected range 000000h – 03FFFFh
10) Protected range 000000h – 07FFFFh
11) Protected range 000000h – 0FFFFFh
12) Protected range 000000h – 1FFFFFh
13) Protected range 000000h – 3FFFFFh
14) Protected range 000000h – 7FFFFFh
15) Protected range 7FF000h – 7FFFFFh
16) Protected range 7FE000h – 7FFFFFh
17) Protected range 7FC000h – 7FFFFFh
18) Protected range 7F8000h – 7FFFFFh
19) Protected range 000000h – 000FFFh
20) Protected range 000000h – 001FFFh
21) Protected range 000000h – 003FFFh
22) Protected range 000000h – 007FFFh
...
Expand Down
2 changes: 1 addition & 1 deletion include/flash_access.h
Expand Up @@ -37,6 +37,6 @@ int lock_sec(u8 reg);
int send_flash_cmd(u8 cmd, void *response, size_t len);
int send_flash_cmd_write(u8 command, size_t cmd_len, const void *data,
size_t data_len);
void save_flash(int flash_address, char buffer[MAX_DEVICES][MAX_LENGTH], u8 max_lines, u8 spi_wp_toggle);
void save_flash(u32 flash_address, char buffer[MAX_DEVICES][MAX_LENGTH], u8 max_lines, u8 spi_wp_toggle);

#endif
157 changes: 134 additions & 23 deletions sortbootorder.c
Expand Up @@ -63,6 +63,12 @@ static void copy_list_line(char *src, char *dest);
static int fetch_file_from_cbfs(char *filename,
char destination[MAX_DEVICES][MAX_LENGTH],
u8 *line_count);
#ifndef COREBOOT_LEGACY
static int fetch_bootorder(char destination[MAX_DEVICES][MAX_LENGTH],
u8 *line_count);
static int fetch_bootorder_from_cbfs(char destination[MAX_DEVICES][MAX_LENGTH],
u8 *line_count);
#endif
static int get_line_number(u8 line_start, u8 line_end, char key);
static void int_ids(char buffer[MAX_DEVICES][MAX_LENGTH], u8 line_cnt,
u8 lineDef_cnt );
Expand All @@ -76,7 +82,7 @@ static void update_tags(char bootlist[MAX_DEVICES][MAX_LENGTH], u8 *max_lines);
static void refresh_tag_values(u8 max_lines);

/*** local variables ***/
static int flash_address;
static void *flash_address;

static u8 ipxe_toggle;
static u8 usb_toggle;
Expand Down Expand Up @@ -107,6 +113,7 @@ static u8 uartd_toggle;

static char bootlist_def[MAX_DEVICES][MAX_LENGTH];
static char bootlist_map[MAX_DEVICES][MAX_LENGTH];
static char bootorder_data[4096];
static char id[MAX_DEVICES] = {0};

static u8 device_toggle[MAX_DEVICES];
Expand All @@ -130,11 +137,6 @@ int main(void) {
u8 line_start = 0;
u8 line_number = 0;
char *token;
char *bootorder_data;
size_t cbfs_length;
#ifndef COREBOOT_LEGACY
struct cbfs_handle *bootorder_handle;
#endif

lib_get_sysinfo();

Expand Down Expand Up @@ -166,23 +168,22 @@ int main(void) {
}

// Find out where the bootorder file is in rom
#ifndef COREBOOT_LEGACY
bootorder_handle = cbfs_get_handle( CBFS_DEFAULT_MEDIA, BOOTORDER_FILE );
flash_address = bootorder_handle->media_offset + bootorder_handle->content_offset;
if ((u32)flash_address & 0xfff)
printf("Warning: The bootorder file is not 4k aligned!\n");
#else
#ifdef COREBOOT_LEGACY
char *tmp = cbfs_get_file_content( CBFS_DEFAULT_MEDIA, BOOTORDER_FILE, CBFS_TYPE_RAW, NULL );
flash_address = (int)tmp;
flash_address = (void *)tmp;
if ((u32)tmp & 0xfff)
printf("Warning: The bootorder file is not 4k aligned!\n");
#endif

fetch_file_from_cbfs( BOOTORDER_FILE, bootlist, &max_lines );
memcpy(bootorder_data, flash_address, 4096);
#else

bootorder_data = (char *) cbfs_get_file_content( CBFS_DEFAULT_MEDIA, BOOTORDER_FILE, CBFS_TYPE_RAW, &cbfs_length );
if (fetch_bootorder(bootlist, &max_lines )) {
printf("Can't read bootorder!\n");
RESET();
}
#endif

// Get required files from CBFS
fetch_file_from_cbfs( BOOTORDER_FILE, bootlist, &max_lines );
fetch_file_from_cbfs( BOOTORDER_DEF, bootlist_def, &bootlist_def_ln );
fetch_file_from_cbfs( BOOTORDER_MAP, bootlist_map, &bootlist_map_ln );

Expand Down Expand Up @@ -346,11 +347,12 @@ int main(void) {
case 's':
case 'S':
update_tags(bootlist, &max_lines);
save_flash(flash_address, bootlist, max_lines, spi_wp_toggle);
save_flash((u32)flash_address, bootlist,
max_lines, spi_wp_toggle);
// fall through to exit ...
case 'x':
case 'X':
printf("\nExiting ...");
printf("\nExiting ...\n");
RESET();
break;
default:
Expand Down Expand Up @@ -457,10 +459,16 @@ static void show_boot_device_list(char buffer[MAX_DEVICES][MAX_LENGTH],
if (com2_available)
printf(" k Redirect console output to COM2 - Currently %s\n",
(com2_toggle) ? "Enabled" : "Disabled");
printf(" o UART C - Currently %s\n",
(uartc_toggle) ? "Enabled" : "Disabled");
printf(" p UART D - Currently %s\n",
(uartd_toggle) ? "Enabled" : "Disabled");
if (uartc_toggle) {
printf(" o UART C - Currently Enabled - Toggle UART C / GPIO\n");
} else {
printf(" o GPIO[0..7] - Currently Enabled - Toggle UART C / GPIO\n");
}
if (uartd_toggle) {
printf(" p UART D - Currently Enabled - Toggle UART D / GPIO\n");
} else {
printf(" p GPIO[10..17] - Currently Enabled - Toggle UART D / GPIO\n");
}
#ifndef TARGET_APU1
printf(" m Force mPCIe2 slot CLK (GPP3 PCIe) - Currently %s\n",
(mpcie2_clk_toggle) ? "Enabled" : "Disabled");
Expand Down Expand Up @@ -488,6 +496,109 @@ static void show_boot_device_list(char buffer[MAX_DEVICES][MAX_LENGTH],
printf(" s Save configuration and exit\n");
}

#ifndef COREBOOT_LEGACY
static int fetch_bootorder_from_cbfs(char destination[MAX_DEVICES][MAX_LENGTH],
u8 *line_count)
{
char *cbfs_dat;
struct cbfs_handle *bootorder_handle;
size_t cbfs_length;

bootorder_handle = cbfs_get_handle(CBFS_DEFAULT_MEDIA, BOOTORDER_FILE);

flash_address = (void *)(bootorder_handle->media_offset +
bootorder_handle->content_offset);

if ((u32)flash_address & 0xfff)
printf("Warning: The bootorder file is not 4k aligned!\n");

cbfs_dat = cbfs_get_file_content(CBFS_DEFAULT_MEDIA, BOOTORDER_FILE,
CBFS_TYPE_RAW, &cbfs_length);

if (!cbfs_dat) {
printf("Error: file [%s] not found!\n", BOOTORDER_FILE);
return -1;
}

if (cbfs_dat[0] == 0xFF || cbfs_dat[0] == 0x00) {
printf("Error: bootorder is empty!\n");
return -1;
}
memcpy(bootorder_data, cbfs_dat, cbfs_length);

if (fetch_file_from_cbfs(BOOTORDER_FILE, destination, line_count))
return -1;

return 0;
}

static int fetch_bootorder(char destination[MAX_DEVICES][MAX_LENGTH],
u8 *line_count)
{
char tmp;
int offset = 0, char_cnt = 0;
u32 bootorder_offset, bootorder_size;
struct cbfs_media default_media;
struct cbfs_media *media = &default_media;

u32 rom_begin = (0xFFFFFFFF - lib_sysinfo.spi_flash.size) + 1;

int rc = fmap_region_by_name(lib_sysinfo.fmap_offset, "BOOTORDER",
&bootorder_offset, &bootorder_size);
if (rc == -1) {
return fetch_bootorder_from_cbfs(destination, line_count);
} else {
flash_address = (void *)(rom_begin + bootorder_offset);

if (init_default_cbfs_media(media))
return -1;

media->open(media);
if (!media->read(media, bootorder_data, bootorder_offset,
bootorder_size))
return -1;
media->close(media);
}

if ((u32)flash_address & 0xfff)
printf("Warning: The bootorder file is not 4k aligned!\n");

if (bootorder_data[0] == 0xFF || bootorder_data[0] == 0x00)
return fetch_bootorder_from_cbfs(destination, line_count);

//count up the lines and display
*line_count = 0;
while (1) {
tmp = *(bootorder_data + offset++);
destination[*line_count][char_cnt] = tmp;
if (tmp == NEWLINE) {
(*line_count)++;
char_cnt = 0;
}
else if ((tmp == 0xFF) || (tmp == NUL) ||
(offset > bootorder_size))
break;
else
char_cnt++;

if (*line_count > MAX_DEVICES) {
printf("aborting due to excessive line_count\n");
break;
}
if (char_cnt > MAX_LENGTH) {
printf("aborting due to excessive char count\n");
break;
}
if (offset > (MAX_LENGTH*MAX_DEVICES)) {
printf("aborting due to excessive cbfs ptr length\n");
break;
}
}

return 0;
}
#endif

/*******************************************************************************/
static void int_ids(char buffer[MAX_DEVICES][MAX_LENGTH], u8 line_cnt,
u8 lineDef_cnt )
Expand Down
2 changes: 1 addition & 1 deletion utils/flash_access.c
Expand Up @@ -93,7 +93,7 @@ inline int send_flash_cmd_write(u8 command, size_t cmd_len, const void *data,
}

/*******************************************************************************/
void save_flash(int flash_address, char buffer[MAX_DEVICES][MAX_LENGTH],
void save_flash(u32 flash_address, char buffer[MAX_DEVICES][MAX_LENGTH],
u8 max_lines, u8 spi_wp_toggle) {
int i = 0;
int k = 0;
Expand Down