- QEMU build warning fix when CONFIG_DISTRO_DEFAULTS=n
- Small fixes on x86 reST docs
- Allow CBFS to be used in SPL
- Remove x86 specific GD flags
This commit is contained in:
Tom Rini 2019-08-19 09:21:46 -04:00
commit 0ed2e2d825
13 changed files with 210 additions and 106 deletions

View File

@ -73,9 +73,6 @@ static void board_final_cleanup(void)
int last_stage_init(void) int last_stage_init(void)
{ {
if (gd->flags & GD_FLG_COLD_BOOT)
timestamp_add_to_bootstage();
/* start usb so that usb keyboard can be used as input device */ /* start usb so that usb keyboard can be used as input device */
if (CONFIG_IS_ENABLED(USB_KEYBOARD)) if (CONFIG_IS_ENABLED(USB_KEYBOARD))
usb_init(); usb_init();

View File

@ -40,9 +40,6 @@ _x86boot_start:
movl %eax, %cr0 movl %eax, %cr0
wbinvd wbinvd
/* Tell 32-bit code it is being entered from an in-RAM copy */
movl $GD_FLG_WARM_BOOT, %ebx
/* /*
* Zero the BIST (Built-In Self Test) value since we don't have it. * Zero the BIST (Built-In Self Test) value since we don't have it.
* It must be 0 or the previous loader would have reported an error. * It must be 0 or the previous loader would have reported an error.
@ -55,11 +52,7 @@ _x86boot_start:
.align 4 .align 4
.long 0x12345678 .long 0x12345678
_start: _start:
/* /* This is the 32-bit cold-reset entry point, coming from start16 */
* This is the 32-bit cold-reset entry point, coming from start16.
* Set %ebx to GD_FLG_COLD_BOOT to indicate this.
*/
movl $GD_FLG_COLD_BOOT, %ebx
/* Save BIST */ /* Save BIST */
movl %eax, %ebp movl %eax, %ebp

View File

@ -23,9 +23,6 @@ start16:
/* Save BIST */ /* Save BIST */
movl %eax, %ecx movl %eax, %ecx
/* Set the Cold Boot / Hard Reset flag */
movl $GD_FLG_COLD_BOOT, %ebx
xorl %eax, %eax xorl %eax, %eax
movl %eax, %cr3 /* Invalidate TLB */ movl %eax, %cr3 /* Invalidate TLB */

View File

@ -137,10 +137,4 @@ static inline __attribute__((no_instrument_function)) gd_t *get_fs_gd_ptr(void)
#endif #endif
/*
* Our private Global Data Flags
*/
#define GD_FLG_COLD_BOOT 0x10000 /* Cold Boot */
#define GD_FLG_WARM_BOOT 0x20000 /* Warm Boot */
#endif /* __ASM_GBL_DATA_H */ #endif /* __ASM_GBL_DATA_H */

View File

@ -29,7 +29,7 @@ static int do_cbfs_init(cmd_tbl_t *cmdtp, int flag, int argc,
} }
} }
file_cbfs_init(end_of_rom); file_cbfs_init(end_of_rom);
if (file_cbfs_result != CBFS_SUCCESS) { if (cbfs_get_result() != CBFS_SUCCESS) {
printf("%s.\n", file_cbfs_error()); printf("%s.\n", file_cbfs_error());
return 1; return 1;
} }
@ -67,7 +67,7 @@ static int do_cbfs_fsload(cmd_tbl_t *cmdtp, int flag, int argc,
file = file_cbfs_find(argv[2]); file = file_cbfs_find(argv[2]);
if (!file) { if (!file) {
if (file_cbfs_result == CBFS_FILE_NOT_FOUND) if (cbfs_get_result() == CBFS_FILE_NOT_FOUND)
printf("%s: %s\n", file_cbfs_error(), argv[2]); printf("%s: %s\n", file_cbfs_error(), argv[2]);
else else
printf("%s.\n", file_cbfs_error()); printf("%s.\n", file_cbfs_error());

View File

@ -709,7 +709,8 @@ to load a 'u-boot-payload.efi', see below test logs on QEMU.
No controllers found No controllers found
Hit any key to stop autoboot: 0 Hit any key to stop autoboot: 0
See README.u-boot_on_efi and README.uefi for details of EFI support in U-Boot. See :doc:`../uefi/u-boot_on_efi` and :doc:`../uefi/uefi` for details of
EFI support in U-Boot.
TODO List TODO List
--------- ---------

View File

@ -87,7 +87,7 @@ The PayloadId can be any 4 Bytes value.
$ qemu-system-x86_64 -machine q35 -nographic -serial mon:stdio -pflash Outputs/qemu/SlimBootloader.bin $ qemu-system-x86_64 -machine q35 -nographic -serial mon:stdio -pflash Outputs/qemu/SlimBootloader.bin
Build Instruction for Slim Bootloader for LeafHill (APL) target Build Instruction for Slim Bootloader for LeafHill (APL) target
-------------------------------------------------------------- ---------------------------------------------------------------
LeafHill is using PCI UART2 device as a serial port. LeafHill is using PCI UART2 device as a serial port.
For MEM32 serial port, CONFIG_SYS_NS16550_MEM32 needs to be enabled in U-Boot. For MEM32 serial port, CONFIG_SYS_NS16550_MEM32 needs to be enabled in U-Boot.

View File

@ -8,6 +8,7 @@ ifdef CONFIG_SPL_BUILD
obj-$(CONFIG_FS_LOADER) += fs.o obj-$(CONFIG_FS_LOADER) += fs.o
obj-$(CONFIG_SPL_FS_FAT) += fat/ obj-$(CONFIG_SPL_FS_FAT) += fat/
obj-$(CONFIG_SPL_FS_EXT4) += ext4/ obj-$(CONFIG_SPL_FS_EXT4) += ext4/
obj-$(CONFIG_SPL_FS_CBFS) += cbfs/
else else
obj-y += fs.o obj-y += fs.o

View File

@ -6,3 +6,15 @@ config FS_CBFS
on systems that use coreboot as the first boot-loader and then load on systems that use coreboot as the first boot-loader and then load
U-Boot to actually boot the Operating System. You can also enable U-Boot to actually boot the Operating System. You can also enable
CMD_CBFS to get command-line access. CMD_CBFS to get command-line access.
config SPL_FS_CBFS
bool "Enable CBFS (Coreboot Filesystem) in SPL"
help
Define this to enable support for reading from a Coreboot
filesystem. This is a ROM-based filesystem used for accessing files
on systems that use coreboot as the first boot-loader and then load
U-Boot to actually boot the Operating System.
Note that most functions in the CBFS API do not work with SPL. Only
those which accept a cbfs_priv * can be used, since BSS is not
available.

View File

@ -8,11 +8,21 @@
#include <malloc.h> #include <malloc.h>
#include <asm/byteorder.h> #include <asm/byteorder.h>
enum cbfs_result file_cbfs_result; static const u32 good_magic = 0x4f524243;
static const u8 good_file_magic[] = "LARCHIVE";
struct cbfs_priv {
int initialized;
struct cbfs_header header;
struct cbfs_cachenode *file_cache;
enum cbfs_result result;
};
static struct cbfs_priv cbfs_s;
const char *file_cbfs_error(void) const char *file_cbfs_error(void)
{ {
switch (file_cbfs_result) { switch (cbfs_s.result) {
case CBFS_SUCCESS: case CBFS_SUCCESS:
return "Success"; return "Success";
case CBFS_NOT_INITIALIZED: case CBFS_NOT_INITIALIZED:
@ -28,14 +38,10 @@ const char *file_cbfs_error(void)
} }
} }
enum cbfs_result cbfs_get_result(void)
static const u32 good_magic = 0x4f524243; {
static const u8 good_file_magic[] = "LARCHIVE"; return cbfs_s.result;
}
static int initialized;
static struct cbfs_header cbfs_header;
static struct cbfs_cachenode *file_cache;
/* Do endian conversion on the CBFS header structure. */ /* Do endian conversion on the CBFS header structure. */
static void swap_header(struct cbfs_header *dest, struct cbfs_header *src) static void swap_header(struct cbfs_header *dest, struct cbfs_header *src)
@ -67,48 +73,49 @@ static void swap_file_header(struct cbfs_fileheader *dest,
* @param start The location in memory to start from. * @param start The location in memory to start from.
* @param size The size of the memory region to search. * @param size The size of the memory region to search.
* @param align The alignment boundaries to check on. * @param align The alignment boundaries to check on.
* @param newNode A pointer to the file structure to load. * @param new_node A pointer to the file structure to load.
* @param used A pointer to the count of of bytes scanned through, * @param used A pointer to the count of of bytes scanned through,
* including the file if one is found. * including the file if one is found.
* *
* @return 1 if a file is found, 0 if one isn't. * @return 1 if a file is found, 0 if one isn't.
*/ */
static int file_cbfs_next_file(u8 *start, u32 size, u32 align, static int file_cbfs_next_file(struct cbfs_priv *priv, u8 *start, u32 size,
struct cbfs_cachenode *newNode, u32 *used) u32 align, struct cbfs_cachenode *new_node,
u32 *used)
{ {
struct cbfs_fileheader header; struct cbfs_fileheader header;
*used = 0; *used = 0;
while (size >= align) { while (size >= align) {
const struct cbfs_fileheader *fileHeader = const struct cbfs_fileheader *file_header =
(const struct cbfs_fileheader *)start; (const struct cbfs_fileheader *)start;
u32 name_len; u32 name_len;
u32 step; u32 step;
/* Check if there's a file here. */ /* Check if there's a file here. */
if (memcmp(good_file_magic, &(fileHeader->magic), if (memcmp(good_file_magic, &file_header->magic,
sizeof(fileHeader->magic))) { sizeof(file_header->magic))) {
*used += align; *used += align;
size -= align; size -= align;
start += align; start += align;
continue; continue;
} }
swap_file_header(&header, fileHeader); swap_file_header(&header, file_header);
if (header.offset < sizeof(struct cbfs_fileheader)) { if (header.offset < sizeof(struct cbfs_fileheader)) {
file_cbfs_result = CBFS_BAD_FILE; priv->result = CBFS_BAD_FILE;
return -1; return -1;
} }
newNode->next = NULL; new_node->next = NULL;
newNode->type = header.type; new_node->type = header.type;
newNode->data = start + header.offset; new_node->data = start + header.offset;
newNode->data_length = header.len; new_node->data_length = header.len;
name_len = header.offset - sizeof(struct cbfs_fileheader); name_len = header.offset - sizeof(struct cbfs_fileheader);
newNode->name = (char *)fileHeader + new_node->name = (char *)file_header +
sizeof(struct cbfs_fileheader); sizeof(struct cbfs_fileheader);
newNode->name_length = name_len; new_node->name_length = name_len;
newNode->attributes_offset = header.attributes_offset; new_node->attributes_offset = header.attributes_offset;
step = header.len; step = header.len;
if (step % align) if (step % align)
@ -121,44 +128,45 @@ static int file_cbfs_next_file(u8 *start, u32 size, u32 align,
} }
/* Look through a CBFS instance and copy file metadata into regular memory. */ /* Look through a CBFS instance and copy file metadata into regular memory. */
static void file_cbfs_fill_cache(u8 *start, u32 size, u32 align) static void file_cbfs_fill_cache(struct cbfs_priv *priv, u8 *start, u32 size,
u32 align)
{ {
struct cbfs_cachenode *cache_node; struct cbfs_cachenode *cache_node;
struct cbfs_cachenode *newNode; struct cbfs_cachenode *new_node;
struct cbfs_cachenode **cache_tail = &file_cache; struct cbfs_cachenode **cache_tail = &priv->file_cache;
/* Clear out old information. */ /* Clear out old information. */
cache_node = file_cache; cache_node = priv->file_cache;
while (cache_node) { while (cache_node) {
struct cbfs_cachenode *oldNode = cache_node; struct cbfs_cachenode *old_node = cache_node;
cache_node = cache_node->next; cache_node = cache_node->next;
free(oldNode); free(old_node);
} }
file_cache = NULL; priv->file_cache = NULL;
while (size >= align) { while (size >= align) {
int result; int result;
u32 used; u32 used;
newNode = (struct cbfs_cachenode *) new_node = (struct cbfs_cachenode *)
malloc(sizeof(struct cbfs_cachenode)); malloc(sizeof(struct cbfs_cachenode));
result = file_cbfs_next_file(start, size, align, result = file_cbfs_next_file(priv, start, size, align, new_node,
newNode, &used); &used);
if (result < 0) { if (result < 0) {
free(newNode); free(new_node);
return; return;
} else if (result == 0) { } else if (result == 0) {
free(newNode); free(new_node);
break; break;
} }
*cache_tail = newNode; *cache_tail = new_node;
cache_tail = &newNode->next; cache_tail = &new_node->next;
size -= used; size -= used;
start += used; start += used;
} }
file_cbfs_result = CBFS_SUCCESS; priv->result = CBFS_SUCCESS;
} }
/* Get the CBFS header out of the ROM and do endian conversion. */ /* Get the CBFS header out of the ROM and do endian conversion. */
@ -173,69 +181,128 @@ static int file_cbfs_load_header(uintptr_t end_of_rom,
if (header->magic != good_magic || header->offset > if (header->magic != good_magic || header->offset >
header->rom_size - header->boot_block_size) { header->rom_size - header->boot_block_size) {
file_cbfs_result = CBFS_BAD_HEADER; cbfs_s.result = CBFS_BAD_HEADER;
return 1; return 1;
} }
return 0; return 0;
} }
void file_cbfs_init(uintptr_t end_of_rom) static int cbfs_load_header_ptr(struct cbfs_priv *priv, ulong base,
struct cbfs_header *header)
{
struct cbfs_header *header_in_rom;
header_in_rom = (struct cbfs_header *)base;
swap_header(header, header_in_rom);
if (header->magic != good_magic || header->offset >
header->rom_size - header->boot_block_size) {
priv->result = CBFS_BAD_HEADER;
return -EFAULT;
}
return 0;
}
static void cbfs_init(struct cbfs_priv *priv, uintptr_t end_of_rom)
{ {
u8 *start_of_rom; u8 *start_of_rom;
initialized = 0;
if (file_cbfs_load_header(end_of_rom, &cbfs_header)) priv->initialized = 0;
if (file_cbfs_load_header(end_of_rom, &priv->header))
return; return;
start_of_rom = (u8 *)(end_of_rom + 1 - cbfs_header.rom_size); start_of_rom = (u8 *)(end_of_rom + 1 - priv->header.rom_size);
file_cbfs_fill_cache(start_of_rom, cbfs_header.rom_size, file_cbfs_fill_cache(priv, start_of_rom, priv->header.rom_size,
cbfs_header.align); priv->header.align);
if (file_cbfs_result == CBFS_SUCCESS) if (priv->result == CBFS_SUCCESS)
initialized = 1; priv->initialized = 1;
}
void file_cbfs_init(uintptr_t end_of_rom)
{
cbfs_init(&cbfs_s, end_of_rom);
}
int cbfs_init_mem(ulong base, ulong size, struct cbfs_priv **privp)
{
struct cbfs_priv priv_s, *priv = &priv_s;
int ret;
/*
* Use a local variable to start with until we know that the CBFS is
* valid. Assume that a master header appears at the start, at offset
* 0x38.
*/
ret = cbfs_load_header_ptr(priv, base + 0x38, &priv->header);
if (ret)
return ret;
file_cbfs_fill_cache(priv, (u8 *)base, priv->header.rom_size,
priv->header.align);
if (priv->result != CBFS_SUCCESS)
return -EINVAL;
priv->initialized = 1;
priv = malloc(sizeof(priv_s));
if (!priv)
return -ENOMEM;
memcpy(priv, &priv_s, sizeof(priv_s));
*privp = priv;
return 0;
} }
const struct cbfs_header *file_cbfs_get_header(void) const struct cbfs_header *file_cbfs_get_header(void)
{ {
if (initialized) { struct cbfs_priv *priv = &cbfs_s;
file_cbfs_result = CBFS_SUCCESS;
return &cbfs_header; if (priv->initialized) {
priv->result = CBFS_SUCCESS;
return &priv->header;
} else { } else {
file_cbfs_result = CBFS_NOT_INITIALIZED; priv->result = CBFS_NOT_INITIALIZED;
return NULL; return NULL;
} }
} }
const struct cbfs_cachenode *file_cbfs_get_first(void) const struct cbfs_cachenode *file_cbfs_get_first(void)
{ {
if (!initialized) { struct cbfs_priv *priv = &cbfs_s;
file_cbfs_result = CBFS_NOT_INITIALIZED;
if (!priv->initialized) {
priv->result = CBFS_NOT_INITIALIZED;
return NULL; return NULL;
} else { } else {
file_cbfs_result = CBFS_SUCCESS; priv->result = CBFS_SUCCESS;
return file_cache; return priv->file_cache;
} }
} }
void file_cbfs_get_next(const struct cbfs_cachenode **file) void file_cbfs_get_next(const struct cbfs_cachenode **file)
{ {
if (!initialized) { struct cbfs_priv *priv = &cbfs_s;
file_cbfs_result = CBFS_NOT_INITIALIZED;
file = NULL; if (!priv->initialized) {
priv->result = CBFS_NOT_INITIALIZED;
*file = NULL;
return; return;
} }
if (*file) if (*file)
*file = (*file)->next; *file = (*file)->next;
file_cbfs_result = CBFS_SUCCESS; priv->result = CBFS_SUCCESS;
} }
const struct cbfs_cachenode *file_cbfs_find(const char *name) const struct cbfs_cachenode *cbfs_find_file(struct cbfs_priv *priv,
const char *name)
{ {
struct cbfs_cachenode *cache_node = file_cache; struct cbfs_cachenode *cache_node = priv->file_cache;
if (!initialized) { if (!priv->initialized) {
file_cbfs_result = CBFS_NOT_INITIALIZED; priv->result = CBFS_NOT_INITIALIZED;
return NULL; return NULL;
} }
@ -245,33 +312,40 @@ const struct cbfs_cachenode *file_cbfs_find(const char *name)
cache_node = cache_node->next; cache_node = cache_node->next;
} }
if (!cache_node) if (!cache_node)
file_cbfs_result = CBFS_FILE_NOT_FOUND; priv->result = CBFS_FILE_NOT_FOUND;
else else
file_cbfs_result = CBFS_SUCCESS; priv->result = CBFS_SUCCESS;
return cache_node; return cache_node;
} }
const struct cbfs_cachenode *file_cbfs_find(const char *name)
{
return cbfs_find_file(&cbfs_s, name);
}
const struct cbfs_cachenode *file_cbfs_find_uncached(uintptr_t end_of_rom, const struct cbfs_cachenode *file_cbfs_find_uncached(uintptr_t end_of_rom,
const char *name) const char *name)
{ {
struct cbfs_priv *priv = &cbfs_s;
u8 *start; u8 *start;
u32 size; u32 size;
u32 align; u32 align;
static struct cbfs_cachenode node; static struct cbfs_cachenode node;
if (file_cbfs_load_header(end_of_rom, &cbfs_header)) if (file_cbfs_load_header(end_of_rom, &priv->header))
return NULL; return NULL;
start = (u8 *)(end_of_rom + 1 - cbfs_header.rom_size); start = (u8 *)(end_of_rom + 1 - priv->header.rom_size);
size = cbfs_header.rom_size; size = priv->header.rom_size;
align = cbfs_header.align; align = priv->header.align;
while (size >= align) { while (size >= align) {
int result; int result;
u32 used; u32 used;
result = file_cbfs_next_file(start, size, align, &node, &used); result = file_cbfs_next_file(priv, start, size, align, &node,
&used);
if (result < 0) if (result < 0)
return NULL; return NULL;
@ -284,25 +358,28 @@ const struct cbfs_cachenode *file_cbfs_find_uncached(uintptr_t end_of_rom,
size -= used; size -= used;
start += used; start += used;
} }
file_cbfs_result = CBFS_FILE_NOT_FOUND; cbfs_s.result = CBFS_FILE_NOT_FOUND;
return NULL; return NULL;
} }
const char *file_cbfs_name(const struct cbfs_cachenode *file) const char *file_cbfs_name(const struct cbfs_cachenode *file)
{ {
file_cbfs_result = CBFS_SUCCESS; cbfs_s.result = CBFS_SUCCESS;
return file->name; return file->name;
} }
u32 file_cbfs_size(const struct cbfs_cachenode *file) u32 file_cbfs_size(const struct cbfs_cachenode *file)
{ {
file_cbfs_result = CBFS_SUCCESS; cbfs_s.result = CBFS_SUCCESS;
return file->data_length; return file->data_length;
} }
u32 file_cbfs_type(const struct cbfs_cachenode *file) u32 file_cbfs_type(const struct cbfs_cachenode *file)
{ {
file_cbfs_result = CBFS_SUCCESS; cbfs_s.result = CBFS_SUCCESS;
return file->type; return file->type;
} }
@ -316,7 +393,7 @@ long file_cbfs_read(const struct cbfs_cachenode *file, void *buffer,
size = maxsize; size = maxsize;
memcpy(buffer, file->data, size); memcpy(buffer, file->data, size);
cbfs_s.result = CBFS_SUCCESS;
file_cbfs_result = CBFS_SUCCESS;
return size; return size;
} }

View File

@ -150,7 +150,7 @@ typedef struct global_data {
#endif #endif
/* /*
* Global Data Flags - the top 16 bits are reserved for arch-specific flags * Global Data Flags
*/ */
#define GD_FLG_RELOC 0x00001 /* Code was relocated to RAM */ #define GD_FLG_RELOC 0x00001 /* Code was relocated to RAM */
#define GD_FLG_DEVINIT 0x00002 /* Devices have been initialized */ #define GD_FLG_DEVINIT 0x00002 /* Devices have been initialized */

View File

@ -90,6 +90,13 @@ extern enum cbfs_result file_cbfs_result;
*/ */
const char *file_cbfs_error(void); const char *file_cbfs_error(void);
/**
* cbfs_get_result() - Get the result of the last CBFS operation
*
*@return last result
*/
enum cbfs_result cbfs_get_result(void);
/** /**
* file_cbfs_init() - Initialize the CBFS driver and load metadata into RAM. * file_cbfs_init() - Initialize the CBFS driver and load metadata into RAM.
* *
@ -128,6 +135,28 @@ void file_cbfs_get_next(const struct cbfs_cachenode **file);
*/ */
const struct cbfs_cachenode *file_cbfs_find(const char *name); const struct cbfs_cachenode *file_cbfs_find(const char *name);
struct cbfs_priv *priv;
/**
* cbfs_find_file() - Find a file in a given CBFS
*
* @cbfs: CBFS to look in (use cbfs_init_mem() to set it up)
* @name: Filename to look for
* @return pointer to CBFS node if found, else NULL
*/
const struct cbfs_cachenode *cbfs_find_file(struct cbfs_priv *cbfs,
const char *name);
/**
* cbfs_init_mem() - Set up a new CBFS
*
* @base: Base address of CBFS
* @size: Size of CBFS in bytes
* @cbfsp: Returns a pointer to CBFS on success
* @return 0 if OK, -ve on error
*/
int cbfs_init_mem(ulong base, ulong size, struct cbfs_priv **privp);
/***************************************************************************/ /***************************************************************************/
/* All of the functions below can be used without first initializing CBFS. */ /* All of the functions below can be used without first initializing CBFS. */

View File

@ -105,11 +105,14 @@
#define CONFIG_OTHBOOTARGS "othbootargs=acpi=off\0" #define CONFIG_OTHBOOTARGS "othbootargs=acpi=off\0"
#endif #endif
#ifndef CONFIG_DISTRO_DEFAULTS #if defined(CONFIG_DISTRO_DEFAULTS)
#define BOOTENV #define DISTRO_BOOTENV BOOTENV
#else
#define DISTRO_BOOTENV
#endif #endif
#define CONFIG_EXTRA_ENV_SETTINGS \ #define CONFIG_EXTRA_ENV_SETTINGS \
DISTRO_BOOTENV \
CONFIG_STD_DEVICES_SETTINGS \ CONFIG_STD_DEVICES_SETTINGS \
"pciconfighost=1\0" \ "pciconfighost=1\0" \
"netdev=eth0\0" \ "netdev=eth0\0" \
@ -118,8 +121,8 @@
"scriptaddr=0x7000000\0" \ "scriptaddr=0x7000000\0" \
"kernel_addr_r=0x1000000\0" \ "kernel_addr_r=0x1000000\0" \
"ramdisk_addr_r=0x4000000\0" \ "ramdisk_addr_r=0x4000000\0" \
"ramdiskfile=initramfs.gz\0" \ "ramdiskfile=initramfs.gz\0"
BOOTENV
#define CONFIG_RAMBOOTCOMMAND \ #define CONFIG_RAMBOOTCOMMAND \
"setenv bootargs root=/dev/ram rw " \ "setenv bootargs root=/dev/ram rw " \