From 7e89dd517b01692b2857ae72f738a86a03bbd0ec Mon Sep 17 00:00:00 2001 From: Radek Zajic Date: Sun, 2 Sep 2018 23:07:49 +0200 Subject: [PATCH 1/4] Update romheaders and dependencies to support UEFI headers --- romheaders/Makefile | 2 +- romheaders/romheaders.c | 54 +++++++++- shared/eficodes.c | 215 ++++++++++++++++++++++++++++++++++++++++ shared/pcihdr.h | 13 +++ 4 files changed, 282 insertions(+), 2 deletions(-) create mode 100644 shared/eficodes.c diff --git a/romheaders/Makefile b/romheaders/Makefile index cdb3d51..e287ea5 100644 --- a/romheaders/Makefile +++ b/romheaders/Makefile @@ -30,7 +30,7 @@ STRIP = strip CFLAGS = -O2 -Wall -Wextra INCLUDES = -I../shared -SOURCES = romheaders.c ../shared/classcodes.c +SOURCES = romheaders.c ../shared/classcodes.c ../shared/eficodes.c .SUFFIXES: .c diff --git a/romheaders/romheaders.c b/romheaders/romheaders.c index ebabdcd..a1fb683 100644 --- a/romheaders/romheaders.c +++ b/romheaders/romheaders.c @@ -47,10 +47,15 @@ char *rom=NULL; size_t romlen=0; -/* Prototypes for functions exported from devsupp/pci/classcodes.c */ +/* Prototypes for functions exported from: + * - devsupp/pci/classcodes.c + * - devsupp/pci/eficodes.c + */ char *pci_device_class_name(u32 code); char *pci_code_type_name(unsigned char code); +char *efi_subsystem_name(u16 code); +char *efi_machine_type_name(u16 code); /* Functions local to this file: bool dump_rom_header(rom_header_t *data); @@ -119,6 +124,7 @@ static bool dump_pci_data(pci_data_t *data) static void dump_platform_extensions(u8 type, rom_header_t *data) { u32 entry; + efirom_header_t *efidata; switch (type) { case 0x00: @@ -162,6 +168,52 @@ static void dump_platform_extensions(u8 type, rom_header_t *data) printf(" Pointer to FCode program: 0x%04x\n\n", data->reserved[1]<<8|data->reserved[0]); break; + case 0x03: +/* +typedef struct { + be_u16(signature); + le_u16(initialization_size); + le_u32(efi_signature); + le_u16(efi_subsystem); + le_u16(efi_machine_type); + le_u16(compression_type); + u8 reserved[0x8]; + le_u16(efi_image_header_offset); + le_u16(data_ptr); + le_u16(padd); +} efirom_header_t; +*/ + efidata = (efirom_header_t *) data; + + if (LITTLE_ENDIAN_WORD_FETCH(efidata->efi_signature) != 0x0ef1) { + printf("EFI signature is missing.\n"); + printf(" This is not a valid EFI option rom.\n"); + break; + } + + printf("Platform specific data for EFI compliant option rom:\n"); + + printf(" Initialization size: %d\n", + LITTLE_ENDIAN_WORD_FETCH(efidata->initialization_size)*512); + printf(" EFI signature: 0x%04x\n", + LITTLE_ENDIAN_LONG_FETCH(efidata->efi_signature)); + printf(" EFI subsystem: %d (%s)\n", + LITTLE_ENDIAN_WORD_FETCH(efidata->efi_subsystem), + efi_subsystem_name(LITTLE_ENDIAN_WORD_FETCH(efidata->efi_subsystem)) + ); + printf(" EFI machine type: 0x%04x (%s)\n", + LITTLE_ENDIAN_WORD_FETCH(efidata->efi_machine_type), + efi_machine_type_name(LITTLE_ENDIAN_WORD_FETCH(efidata->efi_machine_type)) + ); + printf(" EFI image %s compressed\n", + (LITTLE_ENDIAN_WORD_FETCH(efidata->compression_type) ? "is" : "is not")); + printf(" EFI image header offset: 0x%x\n", + LITTLE_ENDIAN_WORD_FETCH(efidata->efi_image_header_offset)); + break; + case 0xff: + printf("This looks to be an iPXE ROM (full length). If there is\n"); + printf(" also a code type 0x00 ROM, that one is an iPXE MROM (stub).\n"); + break; default: printf("Parsing of platform specific data not available for this image\n\n"); } diff --git a/shared/eficodes.c b/shared/eficodes.c new file mode 100644 index 0000000..3b55e84 --- /dev/null +++ b/shared/eficodes.c @@ -0,0 +1,215 @@ +/* + * OpenBIOS - free your system! + * ( FCode tokenizer ) + * + * This program is part of a free implementation of the IEEE 1275-1994 + * Standard for Boot (Initialization Configuration) Firmware. + * + * Copyright (C) 2001-2005 Stefan Reinauer + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA, 02110-1301 USA + * + */ + +/* ************************************************************************** + * + * Functions to correlate PCI Device Class-Codes and PCI Code Types + * with their printable names. + * + * (C) Copyright 2005 IBM Corporation. All Rights Reserved. + * Module Author: David L. Paktor dlpaktor@us.ibm.com + * + **************************************************************************** */ + +#include +#include "types.h" + +/* ************************************************************************** + * + * Functions Eported: + * pci_device_class_name + * Convert a numeric PCI Class Code to the Device Class Name + * + * pci_code_type_name + * Convert a numeric PCI Code Type to a printable Name + * + **************************************************************************** */ + +const char *efi_machine_type_name(u16 code); +const char *efi_subsystem_name(u16 code); + + +typedef struct { + const u32 classcode; + const char *classname; +} num_to_name_table ; + + +/* ************************************************************************** + * + * Function name: convert_num_to_name + * Synopsis: Find the Name, in the given table, for the given Number. + * Support function for Exported Functions. + * + * Inputs: + * Parameters: + * u32 num Number to look up + * num_to_name_table *table Pointer to Table to scan + * int max Maximum Index of Table + * char *not_found String to return if Number not in Table + * + * Outputs: + * Returned Value: Pointer to string giving the Name + * + * Error Detection: + * Unrecognized Number + * Return "not_found" string + * + * Process Explanation: + * Scan the Table for a match. + * + * Still to be done / Misc remarks: + * Had been considering a more sophisticated binary search, + * but the database is too small to merit the extra code. + * Stayed with the KISS principle... + * + * + **************************************************************************** */ + +static const char *convert_num_to_name(u32 num, + num_to_name_table *table, + int max, + const char *not_found) +{ + int indx; + const char *retval; + + retval = not_found; + + for (indx = 0; indx < max ; indx++) + { + if ( num == table[indx].classcode ) + { + retval = table[indx].classname ; + break ; + } + } + return ( retval ); +} + + +/* ************************************************************************** + * + * + * Structures: + * efi_machine_type_name_table Constant Data Table that correlates + * Machine Types with their Names. + * + * efi_subsystem_name_table Constant Data Table that correlates + * Subsytem Codes with their Names. + * + **************************************************************************** */ + + +static const num_to_name_table efi_machine_type_name_table[] = { + { 0x01c2 , "ARMTHUMB_MIXED (ARM32/Thumb)" }, + { 0x014c , "IA32 (x86)" }, + { 0x0200 , "IA64 (Itanium)" }, + { 0x8664 , "AMD64 (x86-64)" }, + { 0xAA64 , "ARM64 (AArch64)" }, + { 0x0EBC , "EFI byte code" } +}; + + +static const num_to_name_table efi_subsystem_name_table[] = { + { 10 , "EFI Application" }, + { 11 , "EFI Boot Service Driver" }, + { 12 , "EFI Runtime Driver." }, + +}; + +/* ************************************************************************** + * + * Function name: efi_machine_type_name + * Synopsis: Return the machine type name for the given machine code + * + * Inputs: + * Parameters: + * u32 code Numeric EFI machine type code + * + * Outputs: + * Returned Value: Pointer to string giving the machine type + * + * Error Detection: + * Unrecognized machine type + * String returned is "unknown as of EFI specs 2.7" + * + * Process Explanation: + * Scan the efi_machine_type_name for a match. + * + * + **************************************************************************** */ + +const char *efi_machine_type_name(u16 code) +{ + const int pdc_max_indx = + sizeof(efi_machine_type_name_table)/sizeof(num_to_name_table) ; + const char *result ; + + result = convert_num_to_name( + code, + (num_to_name_table *)efi_machine_type_name_table, + pdc_max_indx, + "unknown as of EFI specs 2.7"); + + return ( result ); +} + + +/* ************************************************************************** + * + * Function name: efi_subsystem_name + * Synopsis: Return a printable Name for the given EFI subsystem name + * + * Inputs: + * Parameters: + * u16 code Numeric EFI subsystem code + * + * Outputs: + * Returned Value: Pointer to string giving printable Name + * + * Error Detection: + * Unrecognized EFI subsystem code + * String returned is "unknown as of EFI specs 2.7" + * + * Process Explanation: + * Scan the efi_subsystem_name for a match. + * + * + **************************************************************************** */ + +const char *efi_subsystem_name(u16 code) +{ + const int pct_max_indx = + sizeof(efi_subsystem_name_table)/sizeof(num_to_name_table) ; + const char *result ; + + result = convert_num_to_name( + (u32)code, + (num_to_name_table *)efi_subsystem_name_table, + pct_max_indx, + "unknown as of EFI specs 2.7"); + return ( result ); +} + diff --git a/shared/pcihdr.h b/shared/pcihdr.h index 824652c..24fe487 100644 --- a/shared/pcihdr.h +++ b/shared/pcihdr.h @@ -149,6 +149,19 @@ typedef struct { le_u16(padd); } rom_header_t; +typedef struct { + be_u16(signature); + le_u16(initialization_size); + le_u32(efi_signature); + le_u16(efi_subsystem); + le_u16(efi_machine_type); + le_u16(compression_type); + u8 reserved[0x8]; + le_u16(efi_image_header_offset); + le_u16(data_ptr); + le_u16(padd); +} efirom_header_t; + typedef struct { be_u32 (signature); From bf811ab214a625d5ba15434a24ea59ebb8c9bdd7 Mon Sep 17 00:00:00 2001 From: Radek Zajic Date: Sun, 2 Sep 2018 23:09:04 +0200 Subject: [PATCH 2/4] romheaders: clean-up --- romheaders/romheaders.c | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/romheaders/romheaders.c b/romheaders/romheaders.c index a1fb683..7378634 100644 --- a/romheaders/romheaders.c +++ b/romheaders/romheaders.c @@ -169,20 +169,6 @@ static void dump_platform_extensions(u8 type, rom_header_t *data) data->reserved[1]<<8|data->reserved[0]); break; case 0x03: -/* -typedef struct { - be_u16(signature); - le_u16(initialization_size); - le_u32(efi_signature); - le_u16(efi_subsystem); - le_u16(efi_machine_type); - le_u16(compression_type); - u8 reserved[0x8]; - le_u16(efi_image_header_offset); - le_u16(data_ptr); - le_u16(padd); -} efirom_header_t; -*/ efidata = (efirom_header_t *) data; if (LITTLE_ENDIAN_WORD_FETCH(efidata->efi_signature) != 0x0ef1) { From e39adec37d8956c6db634cae9e424704b2eb1445 Mon Sep 17 00:00:00 2001 From: Radek Zajic Date: Sun, 2 Sep 2018 23:10:37 +0200 Subject: [PATCH 3/4] romheaders: update path to shared files --- romheaders/romheaders.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/romheaders/romheaders.c b/romheaders/romheaders.c index 7378634..6e10b99 100644 --- a/romheaders/romheaders.c +++ b/romheaders/romheaders.c @@ -48,8 +48,8 @@ size_t romlen=0; /* Prototypes for functions exported from: - * - devsupp/pci/classcodes.c - * - devsupp/pci/eficodes.c + * - shared/classcodes.c + * - shared/eficodes.c */ char *pci_device_class_name(u32 code); From 287adc79692153740934868d506220b9cf9d5d98 Mon Sep 17 00:00:00 2001 From: Radek Zajic Date: Sun, 2 Sep 2018 23:14:38 +0200 Subject: [PATCH 4/4] eficodes: update copyright and comments --- shared/eficodes.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/shared/eficodes.c b/shared/eficodes.c index 3b55e84..65e92de 100644 --- a/shared/eficodes.c +++ b/shared/eficodes.c @@ -24,9 +24,13 @@ /* ************************************************************************** * - * Functions to correlate PCI Device Class-Codes and PCI Code Types + * Functions to correlate EFI subsystem type and machine name * with their printable names. * + * (C) Copyright 2018. All Rights Reserved. + * Module Author: Radek Zajic radek@zajic.v.pytli.cz + * + * Based on the classcodes.c file * (C) Copyright 2005 IBM Corporation. All Rights Reserved. * Module Author: David L. Paktor dlpaktor@us.ibm.com * @@ -38,11 +42,11 @@ /* ************************************************************************** * * Functions Eported: - * pci_device_class_name - * Convert a numeric PCI Class Code to the Device Class Name + * efi_subsystem_name + * Convert a numeric EFI subsystem type to a printable Name * - * pci_code_type_name - * Convert a numeric PCI Code Type to a printable Name + * efi_machine_type_name + * Convert a numeric EFI machine type to a printable Name * **************************************************************************** */