Skip to content

Commit

Permalink
Finish finding the SKL module
Browse files Browse the repository at this point in the history
Signed-off-by: Ross Philipson <[email protected]>
  • Loading branch information
rossphilipson committed Aug 20, 2021
1 parent 50533bb commit b52a164
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 47 deletions.
46 changes: 6 additions & 40 deletions trenchboot/skboot/common/loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -864,13 +864,8 @@ get_loader_ctx_end(loader_ctx *lctx)
* launch.
*/
bool
find_skl_module(loader_ctx *lctx, void **base, uint32_t *size)
find_skl_module(loader_ctx *lctx)
{
if ( base != NULL )
*base = NULL;
if ( size != NULL )
*size = 0;

if ( 0 == get_module_count(lctx)) {
printk(SKBOOT_ERR"no module info\n");
return false;
Expand All @@ -887,13 +882,11 @@ find_skl_module(loader_ctx *lctx, void **base, uint32_t *size)
"checking if module %s is an SKL module...\n",
(const char *)&(m->string));

void *base2 = (void *)m->mod_start;
uint32_t size2 = m->mod_end - (unsigned long)(base2);
if ( is_skl_module(base2, size2) ){
if ( base != NULL )
*base = base2;
if ( size != NULL )
*size = size2;
void *base = (void *)m->mod_start;
uint32_t size = m->mod_end - (unsigned long)(base);
if ( is_skl_module(base, size) ){
g_skl_module = (sl_header_t *)base;
g_skl_size = size;
printk(SKBOOT_DETA"SKL module found\n");
return true;
}
Expand Down Expand Up @@ -1003,33 +996,6 @@ void print_loader_ctx(loader_ctx *lctx)
}
}

uint8_t
*get_loader_rsdp(loader_ctx *lctx, uint32_t *length)
{
struct mb2_tag *start;
struct mb2_tag_new_acpi *new_acpi;

if (LOADER_CTX_BAD(lctx))
return NULL;
if (lctx->type != MB2_ONLY)
return NULL;
if (length == NULL)
return NULL;

start = (struct mb2_tag *) (lctx->addr + 8);
new_acpi = (struct mb2_tag_new_acpi *)
find_mb2_tag_type(start, MB2_TAG_TYPE_ACPI_NEW);
if (new_acpi == NULL){
/* we'll try the old type--the tag structs are the same */
new_acpi = (struct mb2_tag_new_acpi *)
find_mb2_tag_type(start, MB2_TAG_TYPE_ACPI_OLD);
if (new_acpi == NULL)
return NULL;
}
*length = new_acpi->size - 8;
return new_acpi->rsdp;
}

bool
get_loader_efi_ptr(loader_ctx *lctx, uint32_t *address, uint64_t *long_address)
{
Expand Down
3 changes: 3 additions & 0 deletions trenchboot/skboot/common/skboot.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@
__data loader_ctx g_loader_ctx = { NULL, 0 };
__data loader_ctx *g_ldr_ctx = &g_loader_ctx;

__data sl_header_t *g_skl_module = NULL;
__data uint32_t g_skl_size = 0;

static uint32_t g_default_error_action = SK_SHUTDOWN_HALT;
static unsigned int g_cpuid_ext_feat_info;
static bool is_powercycle_required = true;
Expand Down
10 changes: 8 additions & 2 deletions trenchboot/skboot/common/skl.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,26 @@ lz_info_t lz_info = {

bool is_skl_module(const void *skl_base, uint32_t skl_size)
{
sl_header_t *header = (sl_header_t*)skl_base;
sl_header_t *header = (sl_header_t *)skl_base;
lz_info_t *info;

if (skl_size < (16*PAGE_SIZE)) {
printk(SKBOOT_INFO"Possible SKL module too small\n");
return false;
}

info = (lz_info_t*)(header + header->skl_info_offset);
info = (lz_info_t *)(header + header->skl_info_offset);
if (info->version != SKL_VERSION) {
printk(SKBOOT_INFO"Possible SKL module incorrect version\n");
return false;
}

if (tb_memcmp(info->uuid, lz_info.uuid, 16)) {
printk(SKBOOT_INFO"Possible SKL module incorrect UUID\n");
return false;
}

/* Otherwise it looks like the SKL module */

return true;
}
4 changes: 2 additions & 2 deletions trenchboot/skboot/include/linux.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ typedef struct __attribute__ ((packed)) {
uint8_t relocatable_kernel; /* Whether kernel is relocatable
or not */
uint8_t min_alignment; /* Boot Protocol: 2.10+ */
uint16_t xloadflags; /* Boot Protocol: 2.12+ */
uint16_t xloadflags; /* Boot Protocol: 2.12+ */
uint32_t cmdline_size; /* Maximum size of the kernel
command line */
uint32_t hardware_subarch; /* Hardware subarchitecture */
Expand Down Expand Up @@ -158,7 +158,7 @@ typedef struct __attribute__ ((packed)) {
u16 lfb_depth; /* 0x16 */
u32 lfb_base; /* 0x18 */
u32 lfb_size; /* 0x1c */

u16 cl_magic; /* 0x20 */
u16 cl_offset; /* 0x22 */

Expand Down
3 changes: 1 addition & 2 deletions trenchboot/skboot/include/loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,8 @@ extern char *get_module_cmd(loader_ctx *lctx, module_t *mod);
extern char *get_cmdline(loader_ctx *lctx);
extern void determine_loader_type(void *addr, uint32_t magic);
extern unsigned long get_loader_ctx_end(loader_ctx *lctx);
extern bool find_skl_module(loader_ctx *lctx, void **base, uint32_t *size);
extern bool find_skl_module(loader_ctx *lctx);
extern void replace_e820_map(loader_ctx *lctx);
extern uint8_t *get_loader_rsdp(loader_ctx *lctx, uint32_t *length);
extern bool is_loader_launch_efi(loader_ctx *lctx);
extern bool get_loader_efi_ptr(loader_ctx *lctx, uint32_t *address,
uint64_t *long_address);
Expand Down
5 changes: 4 additions & 1 deletion trenchboot/skboot/include/skl.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ typedef struct __packed {
typedef struct __packed {
skl_tag_hdr_t hdr;
uint32_t zero_page;
} skl_tag_boot_linux_t {
} skl_tag_boot_linux_t;

typedef struct __packed {
skl_tag_hdr_t hdr;
Expand All @@ -85,6 +85,9 @@ typedef struct __packed {
setup_indirect_t indirect;
} skl_tag_setup_indirect_t;

extern sl_header_t *g_skl_module;
extern uint32_t g_skl_size;

extern bool is_skl_module(const void *skl_base, uint32_t skl_size);

#endif /* _SKL_H */

0 comments on commit b52a164

Please sign in to comment.