Skip to content
This repository has been archived by the owner on May 31, 2023. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'savannah/master' (cryptopatch_v4)
Browse files Browse the repository at this point in the history
This merge matches exactly the manually applied patches
at tag 'cryptopatch_v4'. This can be verified with:

    git checkout <this commit>
    git diff cryptopatch_v4
  • Loading branch information
John Lane committed Mar 14, 2018
2 parents 5b02039 + 28b0d19 commit 655bab2
Show file tree
Hide file tree
Showing 38 changed files with 1,952 additions and 413 deletions.
6 changes: 3 additions & 3 deletions grub-core/commands/file.c
Expand Up @@ -497,7 +497,7 @@ grub_cmd_file (grub_extcmd_context_t ctxt, int argc, char **args)
case IS_X86_LINUX32:
case IS_X86_LINUX:
{
struct linux_kernel_header lh;
struct linux_i386_kernel_header lh;
if (grub_file_read (file, &lh, sizeof (lh)) != sizeof (lh))
break;
if (lh.boot_flag != grub_cpu_to_le16_compile_time (0xaa55))
Expand All @@ -508,7 +508,7 @@ grub_cmd_file (grub_extcmd_context_t ctxt, int argc, char **args)

/* FIXME: some really old kernels (< 1.3.73) will fail this. */
if (lh.header !=
grub_cpu_to_le32_compile_time (GRUB_LINUX_MAGIC_SIGNATURE)
grub_cpu_to_le32_compile_time (GRUB_LINUX_I386_MAGIC_SIGNATURE)
|| grub_le_to_cpu16 (lh.version) < 0x0200)
break;

Expand All @@ -521,7 +521,7 @@ grub_cmd_file (grub_extcmd_context_t ctxt, int argc, char **args)
/* FIXME: 2.03 is not always good enough (Linux 2.4 can be 2.03 and
still not support 32-bit boot. */
if (lh.header !=
grub_cpu_to_le32_compile_time (GRUB_LINUX_MAGIC_SIGNATURE)
grub_cpu_to_le32_compile_time (GRUB_LINUX_I386_MAGIC_SIGNATURE)
|| grub_le_to_cpu16 (lh.version) < 0x0203)
break;

Expand Down
9 changes: 9 additions & 0 deletions grub-core/commands/ls.c
Expand Up @@ -201,6 +201,15 @@ grub_ls_list_files (char *dirname, int longlist, int all, int human)
if (grub_errno == GRUB_ERR_UNKNOWN_FS)
grub_errno = GRUB_ERR_NONE;

#ifdef GRUB_MACHINE_IEEE1275
/*
* Close device to prevent a double open in grub_normal_print_device_info().
* Otherwise it may lead to hangs on some IEEE 1275 platforms.
*/
grub_device_close (dev);
dev = NULL;
#endif

grub_normal_print_device_info (device_name);
}
else if (fs)
Expand Down
22 changes: 20 additions & 2 deletions grub-core/disk/ahci.c
Expand Up @@ -82,6 +82,20 @@ enum grub_ahci_hba_port_command
GRUB_AHCI_HBA_PORT_CMD_FR = 0x4000,
};

enum grub_ahci_hba_port_int_status
{
GRUB_AHCI_HBA_PORT_IS_IFS = (1UL << 27),
GRUB_AHCI_HBA_PORT_IS_HBDS = (1UL << 28),
GRUB_AHCI_HBA_PORT_IS_HBFS = (1UL << 29),
GRUB_AHCI_HBA_PORT_IS_TFES = (1UL << 30),
};

#define GRUB_AHCI_HBA_PORT_IS_FATAL_MASK ( \
GRUB_AHCI_HBA_PORT_IS_IFS | \
GRUB_AHCI_HBA_PORT_IS_HBDS | \
GRUB_AHCI_HBA_PORT_IS_HBFS | \
GRUB_AHCI_HBA_PORT_IS_TFES)

struct grub_ahci_hba
{
grub_uint32_t cap;
Expand Down Expand Up @@ -1026,15 +1040,19 @@ grub_ahci_readwrite_real (struct grub_ahci_device *dev,

endtime = grub_get_time_ms () + (spinup ? 20000 : 20000);
while ((dev->hba->ports[dev->port].command_issue & 1))
if (grub_get_time_ms () > endtime)
if (grub_get_time_ms () > endtime ||
(dev->hba->ports[dev->port].intstatus & GRUB_AHCI_HBA_PORT_IS_FATAL_MASK))
{
grub_dprintf ("ahci", "AHCI status <%x %x %x %x>\n",
dev->hba->ports[dev->port].command_issue,
dev->hba->ports[dev->port].sata_active,
dev->hba->ports[dev->port].intstatus,
dev->hba->ports[dev->port].task_file_data);
dev->hba->ports[dev->port].command_issue = 0;
err = grub_error (GRUB_ERR_IO, "AHCI transfer timed out");
if (dev->hba->ports[dev->port].intstatus & GRUB_AHCI_HBA_PORT_IS_FATAL_MASK)
err = grub_error (GRUB_ERR_IO, "AHCI transfer error");
else
err = grub_error (GRUB_ERR_IO, "AHCI transfer timed out");
if (!reset)
grub_ahci_reset_port (dev, 1);
break;
Expand Down
1 change: 1 addition & 0 deletions grub-core/efiemu/i386/loadcore64.c
Expand Up @@ -98,6 +98,7 @@ grub_arch_efiemu_relocate_symbols64 (grub_efiemu_segment_t segs,
break;

case R_X86_64_PC32:
case R_X86_64_PLT32:
err = grub_efiemu_write_value (addr,
*addr32 + rel->r_addend
+ sym.off
Expand Down
4 changes: 4 additions & 0 deletions grub-core/genmod.sh.in
Expand Up @@ -58,6 +58,10 @@ if test x@TARGET_APPLE_LINKER@ != x1; then
-K grub_mod_init -K grub_mod_fini \
-K _grub_mod_init -K _grub_mod_fini \
-R .note.gnu.gold-version -R .note.GNU-stack \
-R .gnu.build.attributes \
-R .rel.gnu.build.attributes \
-R .rela.gnu.build.attributes \
-R .eh_frame -R .rela.eh_frame -R .rel.eh_frame \
-R .note -R .comment -R .ARM.exidx $tmpfile || exit 1
fi
if ! test -z "${TARGET_OBJ2ELF}"; then
Expand Down
200 changes: 200 additions & 0 deletions grub-core/kern/ieee1275/ieee1275.c
Expand Up @@ -19,6 +19,7 @@

#include <grub/ieee1275/ieee1275.h>
#include <grub/types.h>
#include <grub/misc.h>

#define IEEE1275_PHANDLE_INVALID ((grub_ieee1275_cell_t) -1)
#define IEEE1275_IHANDLE_INVALID ((grub_ieee1275_cell_t) 0)
Expand Down Expand Up @@ -482,6 +483,91 @@ grub_ieee1275_close (grub_ieee1275_ihandle_t ihandle)
return 0;
}

int
grub_ieee1275_decode_unit4 (grub_ieee1275_ihandle_t ihandle,
void *addr, grub_size_t size,
grub_uint32_t *phy_lo, grub_uint32_t *phy_hi,
grub_uint32_t *lun_lo, grub_uint32_t *lun_hi)
{
struct decode_args
{
struct grub_ieee1275_common_hdr common;
grub_ieee1275_cell_t method;
grub_ieee1275_cell_t ihandle;
grub_ieee1275_cell_t size;
grub_ieee1275_cell_t addr;
grub_ieee1275_cell_t catch_result;
grub_ieee1275_cell_t tgt_h;
grub_ieee1275_cell_t tgt_l;
grub_ieee1275_cell_t lun_h;
grub_ieee1275_cell_t lun_l;
}
args;

INIT_IEEE1275_COMMON (&args.common, "call-method", 4, 5);
args.method = (grub_ieee1275_cell_t) "decode-unit";
args.ihandle = ihandle;
args.size = size;
args.addr = (grub_ieee1275_cell_t) addr;
args.catch_result = 1;

if ((IEEE1275_CALL_ENTRY_FN (&args) == -1) || (args.catch_result))
{
grub_error (GRUB_ERR_OUT_OF_RANGE, "decode-unit failed\n");
return -1;
}

*phy_lo = args.tgt_l;
*phy_hi = args.tgt_h;
*lun_lo = args.lun_l;
*lun_hi = args.lun_h;
return 0;
}

char *
grub_ieee1275_encode_uint4 (grub_ieee1275_ihandle_t ihandle,
grub_uint32_t phy_lo, grub_uint32_t phy_hi,
grub_uint32_t lun_lo, grub_uint32_t lun_hi,
grub_size_t *size)
{
char *addr;
struct encode_args
{
struct grub_ieee1275_common_hdr common;
grub_ieee1275_cell_t method;
grub_ieee1275_cell_t ihandle;
grub_ieee1275_cell_t tgt_h;
grub_ieee1275_cell_t tgt_l;
grub_ieee1275_cell_t lun_h;
grub_ieee1275_cell_t lun_l;
grub_ieee1275_cell_t catch_result;
grub_ieee1275_cell_t size;
grub_ieee1275_cell_t addr;
}
args;

INIT_IEEE1275_COMMON (&args.common, "call-method", 6, 3);
args.method = (grub_ieee1275_cell_t) "encode-unit";
args.ihandle = ihandle;

args.tgt_l = phy_lo;
args.tgt_h = phy_hi;
args.lun_l = lun_lo;
args.lun_h = lun_hi;
args.catch_result = 1;

if ((IEEE1275_CALL_ENTRY_FN (&args) == -1) || (args.catch_result))
{
grub_error (GRUB_ERR_OUT_OF_RANGE, "encode-unit failed\n");
return 0;
}

addr = (void *)args.addr;
*size = args.size;
addr = grub_strdup ((char *)args.addr);
return addr;
}

int
grub_ieee1275_claim (grub_addr_t addr, grub_size_t size, unsigned int align,
grub_addr_t *result)
Expand Down Expand Up @@ -607,3 +693,117 @@ grub_ieee1275_milliseconds (grub_uint32_t *msecs)
*msecs = args.msecs;
return 0;
}

int
grub_ieee1275_set_address (grub_ieee1275_ihandle_t ihandle,
grub_uint32_t target, grub_uint32_t lun)
{
struct set_address
{
struct grub_ieee1275_common_hdr common;
grub_ieee1275_cell_t method;
grub_ieee1275_cell_t ihandle;
grub_ieee1275_cell_t tgt;
grub_ieee1275_cell_t lun;
grub_ieee1275_cell_t catch_result;
}
args;

INIT_IEEE1275_COMMON (&args.common, "call-method", 4, 1);

/*
* IEEE 1275-1994 Standard for Boot (Initialization Configuration)
* Firmware: Core Requirements and Practices
* E.3.2.2 Bus-specific methods for bus nodes
*
* A package implementing the scsi-2 device type shall implement the
* following bus-specific method:
*
* set-address ( unit# target# -- )
* Sets the SCSI target number (0x0..0xf) and unit number (0..7) to which
* subsequent commands apply.
*/
args.method = (grub_ieee1275_cell_t) "set-address";
args.ihandle = ihandle;
args.tgt = target;
args.lun = lun;

if (IEEE1275_CALL_ENTRY_FN (&args) == -1)
return -1;

return args.catch_result;
}

int
grub_ieee1275_no_data_command (grub_ieee1275_ihandle_t ihandle,
const void *cmd_addr, grub_ssize_t *result)
{
struct set_address
{
struct grub_ieee1275_common_hdr common;
grub_ieee1275_cell_t method;
grub_ieee1275_cell_t ihandle;
grub_ieee1275_cell_t cmd_addr;
grub_ieee1275_cell_t error;
grub_ieee1275_cell_t catch_result;
}
args;

INIT_IEEE1275_COMMON (&args.common, "call-method", 3, 2);

/*
* IEEE 1275-1994 Standard for Boot (Initialization Configuration)
* Firmware: Core Requirements and Practices
*
* E.3.2.2 Bus-specific methods for bus nodes
*
* A package implementing the scsi-2 device type shall implement the
* following bus-specific method:
*
* no-data-command ( cmd-addr -- error? )
* Executes a simple SCSI command, automatically retrying under
* certain conditions. cmd-addr is the address of a 6-byte command buffer
* containing an SCSI command that does not have a data transfer phase.
* Executes the command, retrying indefinitely with the same retry criteria
* as retry-command.
*
* error? is nonzero if an error occurred, zero otherwise.
* NOTE no-data-command is a convenience function. It provides
* no capabilities that are not present in retry-command, but for
* those commands that meet its restrictions, it is easier to use.
*/
args.method = (grub_ieee1275_cell_t) "no-data-command";
args.ihandle = ihandle;
args.cmd_addr = (grub_ieee1275_cell_t) cmd_addr;

if (IEEE1275_CALL_ENTRY_FN (&args) == -1)
return -1;

if (result)
*result = args.error;

return args.catch_result;
}

int
grub_ieee1275_get_block_size (grub_ieee1275_ihandle_t ihandle)
{
struct size_args_ieee1275
{
struct grub_ieee1275_common_hdr common;
grub_ieee1275_cell_t method;
grub_ieee1275_cell_t ihandle;
grub_ieee1275_cell_t result;
grub_ieee1275_cell_t size;
} args;

INIT_IEEE1275_COMMON (&args.common, "call-method", 2, 2);
args.method = (grub_ieee1275_cell_t) "block-size";
args.ihandle = ihandle;
args.result = 1;

if ((IEEE1275_CALL_ENTRY_FN (&args) == -1) || (args.result))
return 0;

return args.size;
}
56 changes: 56 additions & 0 deletions grub-core/kern/sparc64/ieee1275/ieee1275.c
Expand Up @@ -89,3 +89,59 @@ grub_ieee1275_alloc_physmem (grub_addr_t *paddr, grub_size_t size,

return args.catch_result;
}

grub_uint64_t
grub_ieee1275_num_blocks (grub_ieee1275_ihandle_t ihandle)
{
struct nblocks_args_ieee1275
{
struct grub_ieee1275_common_hdr common;
grub_ieee1275_cell_t method;
grub_ieee1275_cell_t ihandle;
grub_ieee1275_cell_t catch_result;
grub_ieee1275_cell_t blocks;
}
args;

INIT_IEEE1275_COMMON (&args.common, "call-method", 2, 2);
args.method = (grub_ieee1275_cell_t) "#blocks";
args.ihandle = ihandle;
args.catch_result = 1;

if ((IEEE1275_CALL_ENTRY_FN (&args) == -1) || (args.catch_result != 0))
return -1;

/*
* If the number of blocks exceeds the range of an unsigned number,
* return 0 to alert the caller to try the #blocks64 command.
*/
if (args.blocks >= 0xffffffffULL)
return 0;

return args.blocks;
}

grub_uint64_t
grub_ieee1275_num_blocks64 (grub_ieee1275_ihandle_t ihandle)
{
struct nblocks_args_ieee1275
{
struct grub_ieee1275_common_hdr common;
grub_ieee1275_cell_t method;
grub_ieee1275_cell_t ihandle;
grub_ieee1275_cell_t catch_result;
grub_ieee1275_cell_t hi_blocks;
grub_ieee1275_cell_t lo_blocks;
}
args;

INIT_IEEE1275_COMMON (&args.common, "call-method", 2, 3);
args.method = (grub_ieee1275_cell_t) "#blocks64";
args.ihandle = ihandle;
args.catch_result = 1;

if ((IEEE1275_CALL_ENTRY_FN (&args) == -1) || (args.catch_result != 0))
return -1;

return ((args.hi_blocks << 32) | (args.lo_blocks));
}
1 change: 1 addition & 0 deletions grub-core/kern/x86_64/dl.c
Expand Up @@ -70,6 +70,7 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr,
break;

case R_X86_64_PC32:
case R_X86_64_PLT32:
{
grub_int64_t value;
value = ((grub_int32_t) *addr32) + rel->r_addend + sym->st_value -
Expand Down

0 comments on commit 655bab2

Please sign in to comment.