mirror of
http://cgit.git.savannah.gnu.org/git/grub.git
synced 2026-04-28 14:33:34 +00:00
Compare commits
92 Commits
phcoder/ve
...
arm_corebo
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3bf4907004 | ||
|
|
8af937d133 | ||
|
|
fc4b6e8b19 | ||
|
|
e824ec487b | ||
|
|
456f220e6a | ||
|
|
187f78ec11 | ||
|
|
0558f4cd9b | ||
|
|
80c274084d | ||
|
|
2fee7bb8de | ||
|
|
642ff2676f | ||
|
|
46f08fb93b | ||
|
|
b0300c6048 | ||
|
|
3e6d59d7cb | ||
|
|
9f8f747605 | ||
|
|
102016960d | ||
|
|
07cd46627b | ||
|
|
9e161d1302 | ||
|
|
06c92907c1 | ||
|
|
74cef4ab78 | ||
|
|
f4116c3a42 | ||
|
|
2d56c1b117 | ||
|
|
1f72ca020d | ||
|
|
3d300d7247 | ||
|
|
03104c2d98 | ||
|
|
40562ddf1e | ||
|
|
1ea06af1ae | ||
|
|
df21b9363d | ||
|
|
8efde40d0c | ||
|
|
d624e04af1 | ||
|
|
bbd85a0292 | ||
|
|
4f06545767 | ||
|
|
66d0e16425 | ||
|
|
a98c706755 | ||
|
|
95f663ec1d | ||
|
|
2b2a338ad6 | ||
|
|
6c9512b610 | ||
|
|
f447b3d2bb | ||
|
|
295fe6c548 | ||
|
|
9cd85f276f | ||
|
|
502a7c48e9 | ||
|
|
418b32f8e9 | ||
|
|
98490fc328 | ||
|
|
3625fdc0b9 | ||
|
|
1ec2b7758b | ||
|
|
f51e8d0dda | ||
|
|
ee52ea80d6 | ||
|
|
c55f74a5c5 | ||
|
|
3b1bb7f3eb | ||
|
|
0b71582111 | ||
|
|
dc491ff04a | ||
|
|
192243b13e | ||
|
|
0f3ae7324a | ||
|
|
ab8770a314 | ||
|
|
f2df41cffa | ||
|
|
b0227ce4b9 | ||
|
|
f900bea454 | ||
|
|
dc51ac70ee | ||
|
|
869a0bc476 | ||
|
|
f9ee0c3e5d | ||
|
|
8af26e386c | ||
|
|
78e9b82d2c | ||
|
|
86139504b7 | ||
|
|
35c1d629f9 | ||
|
|
bacb8f911f | ||
|
|
fbda565356 | ||
|
|
598185f806 | ||
|
|
ca2fd6c93f | ||
|
|
a29fb4722c | ||
|
|
7562f4ab53 | ||
|
|
c7d0aa5450 | ||
|
|
ceb68c6648 | ||
|
|
99291427d2 | ||
|
|
6ffee98e1b | ||
|
|
a6649f5b8e | ||
|
|
c3c14cffef | ||
|
|
84939af253 | ||
|
|
ba6d40e8bb | ||
|
|
2c3a054f4f | ||
|
|
b8eda96422 | ||
|
|
ca3962ca7b | ||
|
|
a4f7d77f7d | ||
|
|
5099975ace | ||
|
|
2f98d7648e | ||
|
|
018e382144 | ||
|
|
f5cba79512 | ||
|
|
46569db585 | ||
|
|
575c7a6e3c | ||
|
|
fc489a889d | ||
|
|
bfb517bc3b | ||
|
|
437dba573f | ||
|
|
974ba94330 | ||
|
|
963d21b76c |
@@ -84,7 +84,6 @@ This edition documents version @value{VERSION}.
|
||||
* Video Subsystem::
|
||||
* PFF2 Font File Format::
|
||||
* Graphical Menu Software Design::
|
||||
* Verifiers framework::
|
||||
* Copying This Manual:: Copying This Manual
|
||||
* Index::
|
||||
@end menu
|
||||
@@ -1950,58 +1949,6 @@ the graphics mode that was in use before @code{grub_video_setup()} was called
|
||||
might fix some of the problems.
|
||||
|
||||
|
||||
@node Verifiers framework
|
||||
@chapter Verifiers framework
|
||||
|
||||
To register your own verifier call @samp{grub_verifier_register} with a
|
||||
structure pointing to your functions.
|
||||
|
||||
The interface is inspired by hash interface with @samp{init}/@samp{write}/@samp{fini}.
|
||||
|
||||
There are eesntially 2 ways of using it: hashing and whole-file verification:
|
||||
|
||||
With hashing approach:
|
||||
During @samp{init} you decide whether you want to check given file and init context.
|
||||
In @samp{write} you update you hashing state.
|
||||
In @samp{fini} you check that hash matches the expected value/passes some check/...
|
||||
|
||||
With whole-file verification:
|
||||
During @samp{init} you decide whether you want to check given file and init context.
|
||||
In @samp{write} you verify file and return error if it fails.
|
||||
You don't have @samp{fini}.
|
||||
|
||||
Additional @samp{verify_string} receives various strings like kernel parameters to
|
||||
verify. Returning no error means successful verification and an error stops the current
|
||||
action.
|
||||
|
||||
Detailed description of API:
|
||||
|
||||
Every time a file is opened your @samp{init} function is called with file descriptor
|
||||
and file type. Your function can have following outcomes:
|
||||
|
||||
@itemize
|
||||
|
||||
@item returning no error and setting @samp{*flags} to @samp{GRUB_VERIFY_FLAGS_SKIP_VERIFICATION}.
|
||||
In this case your verifier will not be called anymore and your verifier is considered
|
||||
to have skipped verification
|
||||
|
||||
@item returning error. Then opening of the fail will fail due to failed verification.
|
||||
|
||||
@item returning no error and not setting @samp{*flags} to @samp{GRUB_VERIFY_FLAGS_SKIP_VERIFICATION}
|
||||
In this case verification is done as described in following section
|
||||
|
||||
@end itemize
|
||||
|
||||
In the third case your @samp{write} will be called with chunks of file. If you need the whole file in a single
|
||||
chunk then during @samp{init} set bit @samp{GRUB_VERIFY_FLAGS_SINGLE_CHUNK} in @samp{*flags}.
|
||||
During @samp{init} you may set @samp{*context} if you need additional context. At every iteration you may return
|
||||
an error and the the file will be considered as having failed the verification. If you return no error then
|
||||
verification continues.
|
||||
|
||||
Optionally at the end of the file @samp{fini} if it exists is called with just the context. If you return
|
||||
no error during any of @samp{init}, @samp{write} and @samp{fini} then the file is considered as having
|
||||
succeded verification.
|
||||
|
||||
@node Copying This Manual
|
||||
@appendix Copying This Manual
|
||||
|
||||
|
||||
@@ -164,7 +164,6 @@ kernel = {
|
||||
arm_coreboot = term/arm/pl050.c;
|
||||
arm_coreboot = term/arm/cros.c;
|
||||
arm_coreboot = term/arm/cros_ec.c;
|
||||
arm_coreboot = bus/spi/rk3288_spi.c;
|
||||
arm_coreboot = commands/keylayouts.c;
|
||||
arm_coreboot = kern/arm/coreboot/dma.c;
|
||||
|
||||
@@ -899,11 +898,6 @@ module = {
|
||||
cppflags = '-I$(srcdir)/lib/posix_wrap';
|
||||
};
|
||||
|
||||
module = {
|
||||
name = verify_helper;
|
||||
common = commands/verify_helper.c;
|
||||
};
|
||||
|
||||
module = {
|
||||
name = hdparm;
|
||||
common = commands/hdparm.c;
|
||||
|
||||
@@ -25,22 +25,28 @@ static grub_size_t root_address_cells, root_size_cells;
|
||||
/* Pointer to this symbol signals invalid mapping. */
|
||||
char grub_fdtbus_invalid_mapping[1];
|
||||
|
||||
struct grub_fdtbus_dev
|
||||
{
|
||||
struct grub_fdtbus_dev *next;
|
||||
struct grub_fdtbus_dev *parent;
|
||||
int node;
|
||||
struct grub_fdtbus_driver *driver;
|
||||
};
|
||||
|
||||
struct grub_fdtbus_dev *devs;
|
||||
struct grub_fdtbus_driver *drivers;
|
||||
|
||||
int
|
||||
grub_fdtbus_is_compatible (const char *compat_string,
|
||||
const struct grub_fdtbus_dev *dev)
|
||||
static int
|
||||
is_compatible (struct grub_fdtbus_driver *driver,
|
||||
int node)
|
||||
{
|
||||
grub_size_t compatible_size;
|
||||
const char *compatible = grub_fdt_get_prop (dtb, dev->node, "compatible",
|
||||
const char *compatible = grub_fdt_get_prop (dtb, node, "compatible",
|
||||
&compatible_size);
|
||||
if (!compatible)
|
||||
return 0;
|
||||
const char *compatible_end = compatible + compatible_size;
|
||||
while (compatible < compatible_end)
|
||||
{
|
||||
if (grub_strcmp (compat_string, compatible) == 0)
|
||||
if (grub_strcmp (driver->compatible, compatible) == 0)
|
||||
return 1;
|
||||
compatible += grub_strlen (compatible) + 1;
|
||||
}
|
||||
@@ -67,12 +73,10 @@ fdtbus_scan (struct grub_fdtbus_dev *parent)
|
||||
dev->parent = parent;
|
||||
devs = dev;
|
||||
FOR_LIST_ELEMENTS(driver, drivers)
|
||||
if (!dev->driver && grub_fdtbus_is_compatible (driver->compatible, dev))
|
||||
if (!dev->driver && is_compatible (driver, node))
|
||||
{
|
||||
grub_dprintf ("fdtbus", "Attaching %s\n", driver->compatible);
|
||||
if (driver->attach (dev) == GRUB_ERR_NONE)
|
||||
if (driver->attach(dev) == GRUB_ERR_NONE)
|
||||
{
|
||||
grub_dprintf ("fdtbus", "Attached %s\n", driver->compatible);
|
||||
dev->driver = driver;
|
||||
break;
|
||||
}
|
||||
@@ -86,18 +90,13 @@ void
|
||||
grub_fdtbus_register (struct grub_fdtbus_driver *driver)
|
||||
{
|
||||
struct grub_fdtbus_dev *dev;
|
||||
grub_dprintf ("fdtbus", "Registering %s\n", driver->compatible);
|
||||
grub_list_push (GRUB_AS_LIST_P (&drivers),
|
||||
GRUB_AS_LIST (driver));
|
||||
for (dev = devs; dev; dev = dev->next)
|
||||
if (!dev->driver && grub_fdtbus_is_compatible (driver->compatible, dev))
|
||||
if (!dev->driver && is_compatible (driver, dev->node))
|
||||
{
|
||||
grub_dprintf ("fdtbus", "Attaching %s (%p)\n", driver->compatible, dev);
|
||||
if (driver->attach (dev) == GRUB_ERR_NONE)
|
||||
{
|
||||
grub_dprintf ("fdtbus", "Attached %s\n", driver->compatible);
|
||||
dev->driver = driver;
|
||||
}
|
||||
if (driver->attach(dev) == GRUB_ERR_NONE)
|
||||
dev->driver = driver;
|
||||
grub_print_error ();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,103 +0,0 @@
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
*
|
||||
* Copyright (C) 2012 Google Inc.
|
||||
* Copyright (C) 2016 Free Software Foundation, Inc.
|
||||
*
|
||||
* This is based on depthcharge code.
|
||||
*
|
||||
* GRUB 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, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* GRUB 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 GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <grub/mm.h>
|
||||
#include <grub/time.h>
|
||||
#include <grub/misc.h>
|
||||
#include <grub/fdtbus.h>
|
||||
#include <grub/machine/kernel.h>
|
||||
|
||||
static grub_err_t
|
||||
spi_send (const struct grub_fdtbus_dev *dev, const void *data, grub_size_t sz)
|
||||
{
|
||||
const grub_uint8_t *ptr = data, *end = ptr + sz;
|
||||
volatile grub_uint32_t *spi = grub_fdtbus_map_reg (dev, 0, 0);
|
||||
spi[2] = 0;
|
||||
spi[1] = sz - 1;
|
||||
spi[0] = ((1 << 18) | spi[0]) & ~(1 << 19);
|
||||
spi[2] = 1;
|
||||
while (ptr < end)
|
||||
{
|
||||
while (spi[9] & 2);
|
||||
spi[256] = *ptr++;
|
||||
}
|
||||
while (spi[9] & 1);
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
spi_receive (const struct grub_fdtbus_dev *dev, void *data, grub_size_t sz)
|
||||
{
|
||||
grub_uint8_t *ptr = data, *end = ptr + sz;
|
||||
volatile grub_uint32_t *spi = grub_fdtbus_map_reg (dev, 0, 0);
|
||||
spi[2] = 0;
|
||||
spi[1] = sz - 1;
|
||||
spi[0] = ((1 << 19) | spi[0]) & ~(1 << 18);
|
||||
spi[2] = 1;
|
||||
while (ptr < end)
|
||||
{
|
||||
while (spi[9] & 8);
|
||||
*ptr++ = spi[512];
|
||||
}
|
||||
while (spi[9] & 1);
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
spi_start (const struct grub_fdtbus_dev *dev)
|
||||
{
|
||||
volatile grub_uint32_t *spi = grub_fdtbus_map_reg (dev, 0, 0);
|
||||
spi[3] = 1;
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
static void
|
||||
spi_stop (const struct grub_fdtbus_dev *dev)
|
||||
{
|
||||
volatile grub_uint32_t *spi = grub_fdtbus_map_reg (dev, 0, 0);
|
||||
spi[3] = 0;
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
spi_attach(const struct grub_fdtbus_dev *dev)
|
||||
{
|
||||
if (!grub_fdtbus_is_mapping_valid (grub_fdtbus_map_reg (dev, 0, 0)))
|
||||
return GRUB_ERR_IO;
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
static struct grub_fdtbus_driver spi =
|
||||
{
|
||||
.compatible = "rockchip,rk3288-spi",
|
||||
.attach = spi_attach,
|
||||
.send = spi_send,
|
||||
.receive = spi_receive,
|
||||
.start = spi_start,
|
||||
.stop = spi_stop,
|
||||
};
|
||||
|
||||
void
|
||||
grub_rk3288_spi_init (void)
|
||||
{
|
||||
grub_fdtbus_register (&spi);
|
||||
}
|
||||
@@ -635,7 +635,7 @@ grub_cmd_acpi (struct grub_extcmd_context *ctxt, int argc, char **args)
|
||||
grub_size_t size;
|
||||
char *buf;
|
||||
|
||||
file = grub_file_open (args[i], GRUB_FILE_TYPE_ACPI_TABLE);
|
||||
file = grub_file_open (args[i]);
|
||||
if (! file)
|
||||
{
|
||||
free_tables ();
|
||||
|
||||
@@ -121,8 +121,8 @@ grub_cmd_blocklist (grub_command_t cmd __attribute__ ((unused)),
|
||||
if (argc < 1)
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"));
|
||||
|
||||
file = grub_file_open (args[0], GRUB_FILE_TYPE_PRINT_BLOCKLIST
|
||||
| GRUB_FILE_TYPE_NO_DECOMPRESS);
|
||||
grub_file_filter_disable_compression ();
|
||||
file = grub_file_open (args[0]);
|
||||
if (! file)
|
||||
return grub_errno;
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ grub_cmd_cat (grub_extcmd_context_t ctxt, int argc, char **args)
|
||||
if (argc != 1)
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"));
|
||||
|
||||
file = grub_file_open (args[0], GRUB_FILE_TYPE_CAT);
|
||||
file = grub_file_open (args[0]);
|
||||
if (! file)
|
||||
return grub_errno;
|
||||
|
||||
|
||||
@@ -45,8 +45,8 @@ grub_cmd_cmp (grub_command_t cmd __attribute__ ((unused)),
|
||||
grub_printf_ (N_("Compare file `%s' with `%s':\n"), args[0],
|
||||
args[1]);
|
||||
|
||||
file1 = grub_file_open (args[0], GRUB_FILE_TYPE_CMP);
|
||||
file2 = grub_file_open (args[1], GRUB_FILE_TYPE_CMP);
|
||||
file1 = grub_file_open (args[0]);
|
||||
file2 = grub_file_open (args[1]);
|
||||
if (! file1 || ! file2)
|
||||
goto cleanup;
|
||||
|
||||
|
||||
@@ -169,7 +169,7 @@ grub_cmd_loadbios (grub_command_t cmd __attribute__ ((unused)),
|
||||
|
||||
if (argc > 1)
|
||||
{
|
||||
file = grub_file_open (argv[1], GRUB_FILE_TYPE_VBE_DUMP);
|
||||
file = grub_file_open (argv[1]);
|
||||
if (! file)
|
||||
return grub_errno;
|
||||
|
||||
@@ -183,7 +183,7 @@ grub_cmd_loadbios (grub_command_t cmd __attribute__ ((unused)),
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
file = grub_file_open (argv[0], GRUB_FILE_TYPE_VBE_DUMP);
|
||||
file = grub_file_open (argv[0]);
|
||||
if (! file)
|
||||
return grub_errno;
|
||||
|
||||
|
||||
@@ -163,7 +163,7 @@ grub_cmd_file (grub_extcmd_context_t ctxt, int argc, char **args)
|
||||
if (type == -1)
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT, "no type specified");
|
||||
|
||||
file = grub_file_open (args[0], GRUB_FILE_TYPE_XNU_KERNEL);
|
||||
file = grub_file_open (args[0]);
|
||||
if (!file)
|
||||
return grub_errno;
|
||||
switch (type)
|
||||
@@ -546,8 +546,7 @@ grub_cmd_file (grub_extcmd_context_t ctxt, int argc, char **args)
|
||||
case IS_XNU64:
|
||||
case IS_XNU32:
|
||||
{
|
||||
macho = grub_macho_open (args[0], GRUB_FILE_TYPE_XNU_KERNEL,
|
||||
(type == IS_XNU64));
|
||||
macho = grub_macho_open (args[0], (type == IS_XNU64));
|
||||
if (!macho)
|
||||
break;
|
||||
/* FIXME: more checks? */
|
||||
|
||||
@@ -113,7 +113,7 @@ check_list (const gcry_md_spec_t *hash, const char *hashfilename,
|
||||
if (hash->mdlen > GRUB_CRYPTO_MAX_MDLEN)
|
||||
return grub_error (GRUB_ERR_BUG, "mdlen is too long");
|
||||
|
||||
hashlist = grub_file_open (hashfilename, GRUB_FILE_TYPE_HASHLIST);
|
||||
hashlist = grub_file_open (hashfilename);
|
||||
if (!hashlist)
|
||||
return grub_errno;
|
||||
|
||||
@@ -141,15 +141,17 @@ check_list (const gcry_md_spec_t *hash, const char *hashfilename,
|
||||
filename = grub_xasprintf ("%s/%s", prefix, p);
|
||||
if (!filename)
|
||||
return grub_errno;
|
||||
file = grub_file_open (filename, GRUB_FILE_TYPE_TO_HASH
|
||||
| (!uncompress ? GRUB_FILE_TYPE_NO_DECOMPRESS
|
||||
: 0));
|
||||
if (!uncompress)
|
||||
grub_file_filter_disable_compression ();
|
||||
file = grub_file_open (filename);
|
||||
grub_free (filename);
|
||||
}
|
||||
else
|
||||
file = grub_file_open (p, GRUB_FILE_TYPE_TO_HASH
|
||||
| (!uncompress ? GRUB_FILE_TYPE_NO_DECOMPRESS
|
||||
: 0));
|
||||
{
|
||||
if (!uncompress)
|
||||
grub_file_filter_disable_compression ();
|
||||
file = grub_file_open (p);
|
||||
}
|
||||
if (!file)
|
||||
{
|
||||
grub_file_close (hashlist);
|
||||
@@ -240,9 +242,9 @@ grub_cmd_hashsum (struct grub_extcmd_context *ctxt,
|
||||
grub_file_t file;
|
||||
grub_err_t err;
|
||||
unsigned j;
|
||||
file = grub_file_open (args[i], GRUB_FILE_TYPE_TO_HASH
|
||||
| (!uncompress ? GRUB_FILE_TYPE_NO_DECOMPRESS
|
||||
: 0));
|
||||
if (!uncompress)
|
||||
grub_file_filter_disable_compression ();
|
||||
file = grub_file_open (args[i]);
|
||||
if (!file)
|
||||
{
|
||||
if (!keep)
|
||||
|
||||
@@ -90,7 +90,7 @@ grub_cmd_hexdump (grub_extcmd_context_t ctxt, int argc, char **args)
|
||||
{
|
||||
grub_file_t file;
|
||||
|
||||
file = grub_file_open (args[0], GRUB_FILE_TYPE_HEXCAT);
|
||||
file = grub_file_open (args[0]);
|
||||
if (! file)
|
||||
return 0;
|
||||
|
||||
|
||||
@@ -1,79 +0,0 @@
|
||||
/* nthibr.c - tests whether an MS Windows system partition is hibernated */
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2013 Peter Lustig
|
||||
* Copyright (C) 2013 Free Software Foundation, Inc.
|
||||
*
|
||||
* GRUB 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, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* GRUB 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 GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <grub/types.h>
|
||||
#include <grub/mm.h>
|
||||
#include <grub/file.h>
|
||||
#include <grub/misc.h>
|
||||
#include <grub/dl.h>
|
||||
#include <grub/command.h>
|
||||
#include <grub/err.h>
|
||||
#include <grub/i18n.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
static grub_err_t
|
||||
grub_cmd_nthibr (grub_command_t cmd __attribute__ ((unused)),
|
||||
int argc, char **args)
|
||||
{
|
||||
grub_uint8_t hibr_file_magic[4];
|
||||
grub_file_t hibr_file = 0;
|
||||
|
||||
if (argc != 1)
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("one argument expected"));
|
||||
|
||||
hibr_file = grub_file_open (args[0], GRUB_FILE_TYPE_FILE_ID);
|
||||
if (!hibr_file)
|
||||
return grub_errno;
|
||||
|
||||
/* Try to read magic number of 'hiberfil.sys' */
|
||||
if (grub_file_read (hibr_file, hibr_file_magic,
|
||||
sizeof (hibr_file_magic))
|
||||
!= (grub_ssize_t) sizeof (hibr_file_magic))
|
||||
{
|
||||
if (!grub_errno)
|
||||
grub_error (GRUB_ERR_TEST_FAILURE, "false");
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if (!(grub_memcmp ("hibr", hibr_file_magic, sizeof (hibr_file_magic)) == 0
|
||||
|| grub_memcmp ("HIBR", hibr_file_magic, sizeof (hibr_file_magic)) == 0))
|
||||
grub_error (GRUB_ERR_TEST_FAILURE, "false");
|
||||
|
||||
exit:
|
||||
grub_file_close (hibr_file);
|
||||
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
static grub_command_t cmd;
|
||||
|
||||
GRUB_MOD_INIT (check_nt_hiberfil)
|
||||
{
|
||||
cmd = grub_register_command ("check_nt_hiberfil", grub_cmd_nthibr,
|
||||
N_("FILE"),
|
||||
N_("Test whether a hiberfil.sys is "
|
||||
"in hibernated state."));
|
||||
}
|
||||
|
||||
GRUB_MOD_FINI (check_nt_hiberfil)
|
||||
{
|
||||
grub_unregister_command (cmd);
|
||||
}
|
||||
@@ -93,7 +93,7 @@ grub_cmd_play (grub_command_t cmd __attribute__ ((unused)),
|
||||
grub_uint32_t tempo;
|
||||
grub_file_t file;
|
||||
|
||||
file = grub_file_open (args[0], GRUB_FILE_TYPE_AUDIO);
|
||||
file = grub_file_open (args[0]);
|
||||
|
||||
if (! file)
|
||||
return grub_errno;
|
||||
|
||||
@@ -220,7 +220,7 @@ grub_cmd_keymap (struct grub_command *cmd __attribute__ ((unused)),
|
||||
else
|
||||
filename = argv[0];
|
||||
|
||||
file = grub_file_open (filename, GRUB_FILE_TYPE_KEYBOARD_LAYOUT);
|
||||
file = grub_file_open (filename);
|
||||
if (! file)
|
||||
goto fail;
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ legacy_file (const char *filename)
|
||||
if (!suffix)
|
||||
return grub_errno;
|
||||
|
||||
file = grub_file_open (filename, GRUB_FILE_TYPE_CONFIG);
|
||||
file = grub_file_open (filename);
|
||||
if (! file)
|
||||
{
|
||||
grub_free (suffix);
|
||||
|
||||
@@ -44,8 +44,7 @@ static const struct grub_arg_option options[] =
|
||||
PUBKEY filter (that insists upon properly signed files) as well. PUBKEY
|
||||
filter is restored before the function returns. */
|
||||
static grub_file_t
|
||||
open_envblk_file (char *filename,
|
||||
enum grub_file_type type)
|
||||
open_envblk_file (char *filename, int untrusted)
|
||||
{
|
||||
grub_file_t file;
|
||||
char *buf = 0;
|
||||
@@ -73,7 +72,13 @@ open_envblk_file (char *filename,
|
||||
grub_strcpy (filename + len + 1, GRUB_ENVBLK_DEFCFG);
|
||||
}
|
||||
|
||||
file = grub_file_open (filename, type);
|
||||
/* The filters that are disabled will be re-enabled by the call to
|
||||
grub_file_open() after this particular file is opened. */
|
||||
grub_file_filter_disable_compression ();
|
||||
if (untrusted)
|
||||
grub_file_filter_disable_pubkey ();
|
||||
|
||||
file = grub_file_open (filename);
|
||||
|
||||
grub_free (buf);
|
||||
return file;
|
||||
@@ -166,10 +171,7 @@ grub_cmd_load_env (grub_extcmd_context_t ctxt, int argc, char **args)
|
||||
whitelist.list = args;
|
||||
|
||||
/* state[0] is the -f flag; state[1] is the --skip-sig flag */
|
||||
file = open_envblk_file ((state[0].set) ? state[0].arg : 0,
|
||||
GRUB_FILE_TYPE_LOADENV
|
||||
| (state[1].set
|
||||
? GRUB_FILE_TYPE_SKIP_SIGNATURE : 0));
|
||||
file = open_envblk_file ((state[0].set) ? state[0].arg : 0, state[1].set);
|
||||
if (! file)
|
||||
return grub_errno;
|
||||
|
||||
@@ -204,10 +206,7 @@ grub_cmd_list_env (grub_extcmd_context_t ctxt,
|
||||
grub_file_t file;
|
||||
grub_envblk_t envblk;
|
||||
|
||||
file = open_envblk_file ((state[0].set) ? state[0].arg : 0,
|
||||
GRUB_FILE_TYPE_LOADENV
|
||||
| (state[1].set
|
||||
? GRUB_FILE_TYPE_SKIP_SIGNATURE : 0));
|
||||
file = open_envblk_file ((state[0].set) ? state[0].arg : 0, 0);
|
||||
if (! file)
|
||||
return grub_errno;
|
||||
|
||||
@@ -391,8 +390,7 @@ grub_cmd_save_env (grub_extcmd_context_t ctxt, int argc, char **args)
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT, "no variable is specified");
|
||||
|
||||
file = open_envblk_file ((state[0].set) ? state[0].arg : 0,
|
||||
GRUB_FILE_TYPE_SAVEENV
|
||||
| GRUB_FILE_TYPE_SKIP_SIGNATURE);
|
||||
1 /* allow untrusted */);
|
||||
if (! file)
|
||||
return grub_errno;
|
||||
|
||||
|
||||
@@ -129,8 +129,8 @@ print_files_long (const char *filename, const struct grub_dirhook_info *info,
|
||||
|
||||
/* XXX: For ext2fs symlinks are detected as files while they
|
||||
should be reported as directories. */
|
||||
file = grub_file_open (pathname, GRUB_FILE_TYPE_GET_SIZE
|
||||
| GRUB_FILE_TYPE_NO_DECOMPRESS);
|
||||
grub_file_filter_disable_compression ();
|
||||
file = grub_file_open (pathname);
|
||||
if (! file)
|
||||
{
|
||||
grub_errno = 0;
|
||||
@@ -225,8 +225,8 @@ grub_ls_list_files (char *dirname, int longlist, int all, int human)
|
||||
struct grub_dirhook_info info;
|
||||
grub_errno = 0;
|
||||
|
||||
file = grub_file_open (dirname, GRUB_FILE_TYPE_GET_SIZE
|
||||
| GRUB_FILE_TYPE_NO_DECOMPRESS);
|
||||
grub_file_filter_disable_compression ();
|
||||
file = grub_file_open (dirname);
|
||||
if (! file)
|
||||
goto fail;
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ grub_mini_cmd_cat (struct grub_command *cmd __attribute__ ((unused)),
|
||||
if (argc < 1)
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"));
|
||||
|
||||
file = grub_file_open (argv[0], GRUB_FILE_TYPE_CAT);
|
||||
file = grub_file_open (argv[0]);
|
||||
if (! file)
|
||||
return grub_errno;
|
||||
|
||||
|
||||
@@ -242,8 +242,7 @@ grub_cmd_nativedisk (grub_command_t cmd __attribute__ ((unused)),
|
||||
if (! filename)
|
||||
goto fail;
|
||||
|
||||
file = grub_file_open (filename,
|
||||
GRUB_FILE_TYPE_GRUB_MODULE);
|
||||
file = grub_file_open (filename);
|
||||
grub_free (filename);
|
||||
if (! file)
|
||||
goto fail;
|
||||
|
||||
@@ -193,7 +193,7 @@ grub_cmd_parttool (grub_command_t cmd __attribute__ ((unused)),
|
||||
{
|
||||
grub_file_t file;
|
||||
|
||||
file = grub_file_open (filename, GRUB_FILE_TYPE_GRUB_MODULE_LIST);
|
||||
file = grub_file_open (filename);
|
||||
if (file)
|
||||
{
|
||||
char *buf = 0;
|
||||
|
||||
@@ -81,8 +81,8 @@ iterate_device (const char *name, void *data)
|
||||
if (! buf)
|
||||
return 1;
|
||||
|
||||
file = grub_file_open (buf, GRUB_FILE_TYPE_FS_SEARCH
|
||||
| GRUB_FILE_TYPE_NO_DECOMPRESS);
|
||||
grub_file_filter_disable_compression ();
|
||||
file = grub_file_open (buf);
|
||||
if (file)
|
||||
{
|
||||
found = 1;
|
||||
|
||||
@@ -355,8 +355,8 @@ test_parse (char **args, int *argn, int argc)
|
||||
if (grub_strcmp (args[*argn], "-s") == 0)
|
||||
{
|
||||
grub_file_t file;
|
||||
file = grub_file_open (args[*argn + 1], GRUB_FILE_TYPE_GET_SIZE
|
||||
| GRUB_FILE_TYPE_NO_DECOMPRESS);
|
||||
grub_file_filter_disable_compression ();
|
||||
file = grub_file_open (args[*argn + 1]);
|
||||
update_val (file && (grub_file_size (file) != 0), &ctx);
|
||||
if (file)
|
||||
grub_file_close (file);
|
||||
|
||||
@@ -57,7 +57,7 @@ grub_cmd_testload (struct grub_command *cmd __attribute__ ((unused)),
|
||||
if (argc < 1)
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"));
|
||||
|
||||
file = grub_file_open (argv[0], GRUB_FILE_TYPE_TESTLOAD);
|
||||
file = grub_file_open (argv[0]);
|
||||
if (! file)
|
||||
return grub_errno;
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ grub_cmd_testspeed (grub_extcmd_context_t ctxt, int argc, char **args)
|
||||
if (buffer == NULL)
|
||||
return grub_errno;
|
||||
|
||||
file = grub_file_open (args[0], GRUB_FILE_TYPE_TESTLOAD);
|
||||
file = grub_file_open (args[0]);
|
||||
if (file == NULL)
|
||||
goto quit;
|
||||
|
||||
|
||||
@@ -30,10 +30,16 @@
|
||||
#include <grub/env.h>
|
||||
#include <grub/kernel.h>
|
||||
#include <grub/extcmd.h>
|
||||
#include <grub/verify.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
struct grub_verified
|
||||
{
|
||||
grub_file_t file;
|
||||
void *buf;
|
||||
};
|
||||
typedef struct grub_verified *grub_verified_t;
|
||||
|
||||
enum
|
||||
{
|
||||
OPTION_SKIP_SIG = 0
|
||||
@@ -439,26 +445,22 @@ rsa_pad (gcry_mpi_t *hmpi, grub_uint8_t *hval,
|
||||
return ret;
|
||||
}
|
||||
|
||||
struct grub_pubkey_context
|
||||
{
|
||||
grub_file_t sig;
|
||||
struct signature_v4_header v4;
|
||||
grub_uint8_t v;
|
||||
const gcry_md_spec_t *hash;
|
||||
void *hash_context;
|
||||
};
|
||||
|
||||
static grub_err_t
|
||||
grub_verify_signature_init (struct grub_pubkey_context *ctxt, grub_file_t sig)
|
||||
grub_verify_signature_real (char *buf, grub_size_t size,
|
||||
grub_file_t f, grub_file_t sig,
|
||||
struct grub_public_key *pkey)
|
||||
{
|
||||
grub_size_t len;
|
||||
grub_uint8_t v;
|
||||
grub_uint8_t h;
|
||||
grub_uint8_t t;
|
||||
grub_err_t err;
|
||||
grub_uint8_t type = 0;
|
||||
grub_uint8_t pk;
|
||||
|
||||
grub_memset (ctxt, 0, sizeof (*ctxt));
|
||||
const gcry_md_spec_t *hash;
|
||||
struct signature_v4_header v4;
|
||||
grub_err_t err;
|
||||
grub_size_t i;
|
||||
gcry_mpi_t mpis[10];
|
||||
grub_uint8_t type = 0;
|
||||
|
||||
err = read_packet_header (sig, &type, &len);
|
||||
if (err)
|
||||
@@ -467,18 +469,18 @@ grub_verify_signature_init (struct grub_pubkey_context *ctxt, grub_file_t sig)
|
||||
if (type != 0x2)
|
||||
return grub_error (GRUB_ERR_BAD_SIGNATURE, N_("bad signature"));
|
||||
|
||||
if (grub_file_read (sig, &ctxt->v, sizeof (ctxt->v)) != sizeof (ctxt->v))
|
||||
if (grub_file_read (sig, &v, sizeof (v)) != sizeof (v))
|
||||
return grub_error (GRUB_ERR_BAD_SIGNATURE, N_("bad signature"));
|
||||
|
||||
if (ctxt->v != 4)
|
||||
if (v != 4)
|
||||
return grub_error (GRUB_ERR_BAD_SIGNATURE, N_("bad signature"));
|
||||
|
||||
if (grub_file_read (sig, &ctxt->v4, sizeof (ctxt->v4)) != sizeof (ctxt->v4))
|
||||
if (grub_file_read (sig, &v4, sizeof (v4)) != sizeof (v4))
|
||||
return grub_error (GRUB_ERR_BAD_SIGNATURE, N_("bad signature"));
|
||||
|
||||
h = ctxt->v4.hash;
|
||||
t = ctxt->v4.type;
|
||||
pk = ctxt->v4.pkeyalgo;
|
||||
h = v4.hash;
|
||||
t = v4.type;
|
||||
pk = v4.pkeyalgo;
|
||||
|
||||
if (t != 0)
|
||||
return grub_error (GRUB_ERR_BAD_SIGNATURE, N_("bad signature"));
|
||||
@@ -489,232 +491,183 @@ grub_verify_signature_init (struct grub_pubkey_context *ctxt, grub_file_t sig)
|
||||
if (pk >= ARRAY_SIZE (pkalgos) || pkalgos[pk].name == NULL)
|
||||
return grub_error (GRUB_ERR_BAD_SIGNATURE, N_("bad signature"));
|
||||
|
||||
ctxt->hash = grub_crypto_lookup_md_by_name (hashes[h]);
|
||||
if (!ctxt->hash)
|
||||
hash = grub_crypto_lookup_md_by_name (hashes[h]);
|
||||
if (!hash)
|
||||
return grub_error (GRUB_ERR_BAD_SIGNATURE, "hash `%s' not loaded", hashes[h]);
|
||||
|
||||
grub_dprintf ("crypt", "alive\n");
|
||||
|
||||
ctxt->sig = sig;
|
||||
|
||||
ctxt->hash_context = grub_zalloc (ctxt->hash->contextsize);
|
||||
if (!ctxt->hash_context)
|
||||
return grub_errno;
|
||||
|
||||
ctxt->hash->init (ctxt->hash_context);
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_pubkey_write (void *ctxt_, void *buf, grub_size_t size)
|
||||
{
|
||||
struct grub_pubkey_context *ctxt = ctxt_;
|
||||
ctxt->hash->write (ctxt->hash_context, buf, size);
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_verify_signature_real (struct grub_pubkey_context *ctxt,
|
||||
struct grub_public_key *pkey)
|
||||
{
|
||||
gcry_mpi_t mpis[10];
|
||||
grub_uint8_t pk = ctxt->v4.pkeyalgo;
|
||||
grub_size_t i;
|
||||
grub_uint8_t *readbuf = NULL;
|
||||
unsigned char *hval;
|
||||
grub_ssize_t rem = grub_be_to_cpu16 (ctxt->v4.hashed_sub);
|
||||
grub_uint32_t headlen = grub_cpu_to_be32 (rem + 6);
|
||||
grub_uint8_t s;
|
||||
grub_uint16_t unhashed_sub;
|
||||
grub_ssize_t r;
|
||||
grub_uint8_t hash_start[2];
|
||||
gcry_mpi_t hmpi;
|
||||
grub_uint64_t keyid = 0;
|
||||
struct grub_public_subkey *sk;
|
||||
|
||||
readbuf = grub_malloc (READBUF_SIZE);
|
||||
if (!readbuf)
|
||||
goto fail;
|
||||
|
||||
ctxt->hash->write (ctxt->hash_context, &ctxt->v, sizeof (ctxt->v));
|
||||
ctxt->hash->write (ctxt->hash_context, &ctxt->v4, sizeof (ctxt->v4));
|
||||
while (rem)
|
||||
{
|
||||
r = grub_file_read (ctxt->sig, readbuf,
|
||||
rem < READBUF_SIZE ? rem : READBUF_SIZE);
|
||||
if (r < 0)
|
||||
goto fail;
|
||||
if (r == 0)
|
||||
break;
|
||||
ctxt->hash->write (ctxt->hash_context, readbuf, r);
|
||||
rem -= r;
|
||||
}
|
||||
ctxt->hash->write (ctxt->hash_context, &ctxt->v, sizeof (ctxt->v));
|
||||
s = 0xff;
|
||||
ctxt->hash->write (ctxt->hash_context, &s, sizeof (s));
|
||||
ctxt->hash->write (ctxt->hash_context, &headlen, sizeof (headlen));
|
||||
r = grub_file_read (ctxt->sig, &unhashed_sub, sizeof (unhashed_sub));
|
||||
if (r != sizeof (unhashed_sub))
|
||||
goto fail;
|
||||
{
|
||||
grub_uint8_t *ptr;
|
||||
grub_uint32_t l;
|
||||
rem = grub_be_to_cpu16 (unhashed_sub);
|
||||
if (rem > READBUF_SIZE)
|
||||
void *context = NULL;
|
||||
unsigned char *hval;
|
||||
grub_ssize_t rem = grub_be_to_cpu16 (v4.hashed_sub);
|
||||
grub_uint32_t headlen = grub_cpu_to_be32 (rem + 6);
|
||||
grub_uint8_t s;
|
||||
grub_uint16_t unhashed_sub;
|
||||
grub_ssize_t r;
|
||||
grub_uint8_t hash_start[2];
|
||||
gcry_mpi_t hmpi;
|
||||
grub_uint64_t keyid = 0;
|
||||
struct grub_public_subkey *sk;
|
||||
grub_uint8_t *readbuf = NULL;
|
||||
|
||||
context = grub_zalloc (hash->contextsize);
|
||||
readbuf = grub_zalloc (READBUF_SIZE);
|
||||
if (!context || !readbuf)
|
||||
goto fail;
|
||||
r = grub_file_read (ctxt->sig, readbuf, rem);
|
||||
if (r != rem)
|
||||
goto fail;
|
||||
for (ptr = readbuf; ptr < readbuf + rem; ptr += l)
|
||||
|
||||
hash->init (context);
|
||||
if (buf)
|
||||
hash->write (context, buf, size);
|
||||
else
|
||||
while (1)
|
||||
{
|
||||
r = grub_file_read (f, readbuf, READBUF_SIZE);
|
||||
if (r < 0)
|
||||
goto fail;
|
||||
if (r == 0)
|
||||
break;
|
||||
hash->write (context, readbuf, r);
|
||||
}
|
||||
|
||||
hash->write (context, &v, sizeof (v));
|
||||
hash->write (context, &v4, sizeof (v4));
|
||||
while (rem)
|
||||
{
|
||||
if (*ptr < 192)
|
||||
l = *ptr++;
|
||||
else if (*ptr < 255)
|
||||
{
|
||||
if (ptr + 1 >= readbuf + rem)
|
||||
break;
|
||||
l = (((ptr[0] & ~192) << GRUB_CHAR_BIT) | ptr[1]) + 192;
|
||||
ptr += 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ptr + 5 >= readbuf + rem)
|
||||
break;
|
||||
l = grub_be_to_cpu32 (grub_get_unaligned32 (ptr + 1));
|
||||
ptr += 5;
|
||||
}
|
||||
if (*ptr == 0x10 && l >= 8)
|
||||
keyid = grub_get_unaligned64 (ptr + 1);
|
||||
r = grub_file_read (sig, readbuf,
|
||||
rem < READBUF_SIZE ? rem : READBUF_SIZE);
|
||||
if (r < 0)
|
||||
goto fail;
|
||||
if (r == 0)
|
||||
break;
|
||||
hash->write (context, readbuf, r);
|
||||
rem -= r;
|
||||
}
|
||||
hash->write (context, &v, sizeof (v));
|
||||
s = 0xff;
|
||||
hash->write (context, &s, sizeof (s));
|
||||
hash->write (context, &headlen, sizeof (headlen));
|
||||
r = grub_file_read (sig, &unhashed_sub, sizeof (unhashed_sub));
|
||||
if (r != sizeof (unhashed_sub))
|
||||
goto fail;
|
||||
{
|
||||
grub_uint8_t *ptr;
|
||||
grub_uint32_t l;
|
||||
rem = grub_be_to_cpu16 (unhashed_sub);
|
||||
if (rem > READBUF_SIZE)
|
||||
goto fail;
|
||||
r = grub_file_read (sig, readbuf, rem);
|
||||
if (r != rem)
|
||||
goto fail;
|
||||
for (ptr = readbuf; ptr < readbuf + rem; ptr += l)
|
||||
{
|
||||
if (*ptr < 192)
|
||||
l = *ptr++;
|
||||
else if (*ptr < 255)
|
||||
{
|
||||
if (ptr + 1 >= readbuf + rem)
|
||||
break;
|
||||
l = (((ptr[0] & ~192) << GRUB_CHAR_BIT) | ptr[1]) + 192;
|
||||
ptr += 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ptr + 5 >= readbuf + rem)
|
||||
break;
|
||||
l = grub_be_to_cpu32 (grub_get_unaligned32 (ptr + 1));
|
||||
ptr += 5;
|
||||
}
|
||||
if (*ptr == 0x10 && l >= 8)
|
||||
keyid = grub_get_unaligned64 (ptr + 1);
|
||||
}
|
||||
}
|
||||
|
||||
hash->final (context);
|
||||
|
||||
grub_dprintf ("crypt", "alive\n");
|
||||
|
||||
hval = hash->read (context);
|
||||
|
||||
if (grub_file_read (sig, hash_start, sizeof (hash_start)) != sizeof (hash_start))
|
||||
goto fail;
|
||||
if (grub_memcmp (hval, hash_start, sizeof (hash_start)) != 0)
|
||||
goto fail;
|
||||
|
||||
grub_dprintf ("crypt", "@ %x\n", (int)grub_file_tell (sig));
|
||||
|
||||
for (i = 0; i < pkalgos[pk].nmpisig; i++)
|
||||
{
|
||||
grub_uint16_t l;
|
||||
grub_size_t lb;
|
||||
grub_dprintf ("crypt", "alive\n");
|
||||
if (grub_file_read (sig, &l, sizeof (l)) != sizeof (l))
|
||||
goto fail;
|
||||
grub_dprintf ("crypt", "alive\n");
|
||||
lb = (grub_be_to_cpu16 (l) + 7) / 8;
|
||||
grub_dprintf ("crypt", "l = 0x%04x\n", grub_be_to_cpu16 (l));
|
||||
if (lb > READBUF_SIZE - sizeof (grub_uint16_t))
|
||||
goto fail;
|
||||
grub_dprintf ("crypt", "alive\n");
|
||||
if (grub_file_read (sig, readbuf + sizeof (grub_uint16_t), lb) != (grub_ssize_t) lb)
|
||||
goto fail;
|
||||
grub_dprintf ("crypt", "alive\n");
|
||||
grub_memcpy (readbuf, &l, sizeof (l));
|
||||
grub_dprintf ("crypt", "alive\n");
|
||||
|
||||
if (gcry_mpi_scan (&mpis[i], GCRYMPI_FMT_PGP,
|
||||
readbuf, lb + sizeof (grub_uint16_t), 0))
|
||||
goto fail;
|
||||
grub_dprintf ("crypt", "alive\n");
|
||||
}
|
||||
|
||||
if (pkey)
|
||||
sk = grub_crypto_pk_locate_subkey (keyid, pkey);
|
||||
else
|
||||
sk = grub_crypto_pk_locate_subkey_in_trustdb (keyid);
|
||||
if (!sk)
|
||||
{
|
||||
/* TRANSLATORS: %08x is 32-bit key id. */
|
||||
grub_error (GRUB_ERR_BAD_SIGNATURE, N_("public key %08x not found"),
|
||||
keyid);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (pkalgos[pk].pad (&hmpi, hval, hash, sk))
|
||||
goto fail;
|
||||
if (!*pkalgos[pk].algo)
|
||||
{
|
||||
grub_dl_load (pkalgos[pk].module);
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
if (!*pkalgos[pk].algo)
|
||||
{
|
||||
grub_error (GRUB_ERR_BAD_SIGNATURE, N_("module `%s' isn't loaded"),
|
||||
pkalgos[pk].module);
|
||||
goto fail;
|
||||
}
|
||||
if ((*pkalgos[pk].algo)->verify (0, hmpi, mpis, sk->mpis, 0, 0))
|
||||
goto fail;
|
||||
|
||||
grub_free (context);
|
||||
grub_free (readbuf);
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
|
||||
fail:
|
||||
grub_free (context);
|
||||
grub_free (readbuf);
|
||||
if (!grub_errno)
|
||||
return grub_error (GRUB_ERR_BAD_SIGNATURE, N_("bad signature"));
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
ctxt->hash->final (ctxt->hash_context);
|
||||
|
||||
grub_dprintf ("crypt", "alive\n");
|
||||
|
||||
hval = ctxt->hash->read (ctxt->hash_context);
|
||||
|
||||
if (grub_file_read (ctxt->sig, hash_start, sizeof (hash_start)) != sizeof (hash_start))
|
||||
goto fail;
|
||||
if (grub_memcmp (hval, hash_start, sizeof (hash_start)) != 0)
|
||||
goto fail;
|
||||
|
||||
grub_dprintf ("crypt", "@ %x\n", (int)grub_file_tell (ctxt->sig));
|
||||
|
||||
for (i = 0; i < pkalgos[pk].nmpisig; i++)
|
||||
{
|
||||
grub_uint16_t l;
|
||||
grub_size_t lb;
|
||||
grub_dprintf ("crypt", "alive\n");
|
||||
if (grub_file_read (ctxt->sig, &l, sizeof (l)) != sizeof (l))
|
||||
goto fail;
|
||||
grub_dprintf ("crypt", "alive\n");
|
||||
lb = (grub_be_to_cpu16 (l) + 7) / 8;
|
||||
grub_dprintf ("crypt", "l = 0x%04x\n", grub_be_to_cpu16 (l));
|
||||
if (lb > READBUF_SIZE - sizeof (grub_uint16_t))
|
||||
goto fail;
|
||||
grub_dprintf ("crypt", "alive\n");
|
||||
if (grub_file_read (ctxt->sig, readbuf + sizeof (grub_uint16_t), lb) != (grub_ssize_t) lb)
|
||||
goto fail;
|
||||
grub_dprintf ("crypt", "alive\n");
|
||||
grub_memcpy (readbuf, &l, sizeof (l));
|
||||
grub_dprintf ("crypt", "alive\n");
|
||||
|
||||
if (gcry_mpi_scan (&mpis[i], GCRYMPI_FMT_PGP,
|
||||
readbuf, lb + sizeof (grub_uint16_t), 0))
|
||||
goto fail;
|
||||
grub_dprintf ("crypt", "alive\n");
|
||||
}
|
||||
|
||||
if (pkey)
|
||||
sk = grub_crypto_pk_locate_subkey (keyid, pkey);
|
||||
else
|
||||
sk = grub_crypto_pk_locate_subkey_in_trustdb (keyid);
|
||||
if (!sk)
|
||||
{
|
||||
/* TRANSLATORS: %08x is 32-bit key id. */
|
||||
grub_error (GRUB_ERR_BAD_SIGNATURE, N_("public key %08x not found"),
|
||||
keyid);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (pkalgos[pk].pad (&hmpi, hval, ctxt->hash, sk))
|
||||
goto fail;
|
||||
if (!*pkalgos[pk].algo)
|
||||
{
|
||||
grub_dl_load (pkalgos[pk].module);
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
if (!*pkalgos[pk].algo)
|
||||
{
|
||||
grub_error (GRUB_ERR_BAD_SIGNATURE, N_("module `%s' isn't loaded"),
|
||||
pkalgos[pk].module);
|
||||
goto fail;
|
||||
}
|
||||
if ((*pkalgos[pk].algo)->verify (0, hmpi, mpis, sk->mpis, 0, 0))
|
||||
goto fail;
|
||||
|
||||
grub_free (readbuf);
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
|
||||
fail:
|
||||
grub_free (readbuf);
|
||||
if (!grub_errno)
|
||||
return grub_error (GRUB_ERR_BAD_SIGNATURE, N_("bad signature"));
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
static void
|
||||
grub_pubkey_close_real (struct grub_pubkey_context *ctxt)
|
||||
{
|
||||
if (ctxt->sig)
|
||||
grub_file_close (ctxt->sig);
|
||||
if (ctxt->hash_context)
|
||||
grub_free (ctxt->hash_context);
|
||||
}
|
||||
|
||||
static void
|
||||
grub_pubkey_close (void *ctxt)
|
||||
{
|
||||
grub_pubkey_close_real (ctxt);
|
||||
grub_free (ctxt);
|
||||
}
|
||||
|
||||
grub_err_t
|
||||
grub_verify_signature (grub_file_t f, grub_file_t sig,
|
||||
struct grub_public_key *pkey)
|
||||
{
|
||||
grub_err_t err;
|
||||
struct grub_pubkey_context ctxt;
|
||||
grub_uint8_t *readbuf = NULL;
|
||||
err = grub_verify_signature_init (&ctxt, sig);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
readbuf = grub_zalloc (READBUF_SIZE);
|
||||
if (!readbuf)
|
||||
goto fail;
|
||||
|
||||
while (1)
|
||||
{
|
||||
grub_ssize_t r;
|
||||
r = grub_file_read (f, readbuf, READBUF_SIZE);
|
||||
if (r < 0)
|
||||
goto fail;
|
||||
if (r == 0)
|
||||
break;
|
||||
err = grub_pubkey_write (&ctxt, readbuf, r);
|
||||
if (err)
|
||||
return err;
|
||||
}
|
||||
|
||||
grub_verify_signature_real (&ctxt, pkey);
|
||||
fail:
|
||||
grub_pubkey_close_real (&ctxt);
|
||||
return grub_errno;
|
||||
return grub_verify_signature_real (0, 0, f, sig, pkey);
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
@@ -727,12 +680,10 @@ grub_cmd_trust (grub_extcmd_context_t ctxt,
|
||||
if (argc < 1)
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("one argument expected"));
|
||||
|
||||
pkf = grub_file_open (args[0],
|
||||
GRUB_FILE_TYPE_PUBLIC_KEY_TRUST
|
||||
| GRUB_FILE_TYPE_NO_DECOMPRESS
|
||||
| (ctxt->state[OPTION_SKIP_SIG].set
|
||||
? GRUB_FILE_TYPE_SKIP_SIGNATURE
|
||||
: 0));
|
||||
grub_file_filter_disable_compression ();
|
||||
if (ctxt->state[OPTION_SKIP_SIG].set)
|
||||
grub_file_filter_disable_pubkey ();
|
||||
pkf = grub_file_open (args[0]);
|
||||
if (!pkf)
|
||||
return grub_errno;
|
||||
pk = grub_load_public_key (pkf);
|
||||
@@ -820,12 +771,10 @@ grub_cmd_verify_signature (grub_extcmd_context_t ctxt,
|
||||
if (argc > 2)
|
||||
{
|
||||
grub_file_t pkf;
|
||||
pkf = grub_file_open (args[2],
|
||||
GRUB_FILE_TYPE_PUBLIC_KEY
|
||||
| GRUB_FILE_TYPE_NO_DECOMPRESS
|
||||
| (ctxt->state[OPTION_SKIP_SIG].set
|
||||
? GRUB_FILE_TYPE_SKIP_SIGNATURE
|
||||
: 0));
|
||||
grub_file_filter_disable_compression ();
|
||||
if (ctxt->state[OPTION_SKIP_SIG].set)
|
||||
grub_file_filter_disable_pubkey ();
|
||||
pkf = grub_file_open (args[2]);
|
||||
if (!pkf)
|
||||
return grub_errno;
|
||||
pk = grub_load_public_key (pkf);
|
||||
@@ -837,16 +786,16 @@ grub_cmd_verify_signature (grub_extcmd_context_t ctxt,
|
||||
grub_file_close (pkf);
|
||||
}
|
||||
|
||||
f = grub_file_open (args[0], GRUB_FILE_TYPE_VERIFY_SIGNATURE);
|
||||
grub_file_filter_disable_all ();
|
||||
f = grub_file_open (args[0]);
|
||||
if (!f)
|
||||
{
|
||||
err = grub_errno;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
sig = grub_file_open (args[1],
|
||||
GRUB_FILE_TYPE_SIGNATURE
|
||||
| GRUB_FILE_TYPE_NO_DECOMPRESS);
|
||||
grub_file_filter_disable_all ();
|
||||
sig = grub_file_open (args[1]);
|
||||
if (!sig)
|
||||
{
|
||||
err = grub_errno;
|
||||
@@ -866,52 +815,135 @@ grub_cmd_verify_signature (grub_extcmd_context_t ctxt,
|
||||
|
||||
static int sec = 0;
|
||||
|
||||
static void
|
||||
verified_free (grub_verified_t verified)
|
||||
{
|
||||
if (verified)
|
||||
{
|
||||
grub_free (verified->buf);
|
||||
grub_free (verified);
|
||||
}
|
||||
}
|
||||
|
||||
static grub_ssize_t
|
||||
verified_read (struct grub_file *file, char *buf, grub_size_t len)
|
||||
{
|
||||
grub_verified_t verified = file->data;
|
||||
|
||||
grub_memcpy (buf, (char *) verified->buf + file->offset, len);
|
||||
return len;
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_pubkey_init (grub_file_t io, enum grub_file_type type __attribute__ ((unused)),
|
||||
void **context, enum grub_verify_flags *flags)
|
||||
verified_close (struct grub_file *file)
|
||||
{
|
||||
grub_verified_t verified = file->data;
|
||||
|
||||
grub_file_close (verified->file);
|
||||
verified_free (verified);
|
||||
file->data = 0;
|
||||
|
||||
/* device and name are freed by parent */
|
||||
file->device = 0;
|
||||
file->name = 0;
|
||||
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
struct grub_fs verified_fs =
|
||||
{
|
||||
.name = "verified_read",
|
||||
.read = verified_read,
|
||||
.close = verified_close
|
||||
};
|
||||
|
||||
static grub_file_t
|
||||
grub_pubkey_open (grub_file_t io, const char *filename)
|
||||
{
|
||||
grub_file_t sig;
|
||||
char *fsuf, *ptr;
|
||||
grub_err_t err;
|
||||
grub_file_filter_t curfilt[GRUB_FILE_FILTER_MAX];
|
||||
grub_file_t ret;
|
||||
grub_verified_t verified;
|
||||
|
||||
if (!sec)
|
||||
{
|
||||
*flags = GRUB_VERIFY_FLAGS_SKIP_VERIFICATION;
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
fsuf = grub_malloc (grub_strlen (io->name) + sizeof (".sig"));
|
||||
return io;
|
||||
if (io->device->disk &&
|
||||
(io->device->disk->dev->id == GRUB_DISK_DEVICE_MEMDISK_ID
|
||||
|| io->device->disk->dev->id == GRUB_DISK_DEVICE_PROCFS_ID))
|
||||
return io;
|
||||
fsuf = grub_malloc (grub_strlen (filename) + sizeof (".sig"));
|
||||
if (!fsuf)
|
||||
return grub_errno;
|
||||
ptr = grub_stpcpy (fsuf, io->name);
|
||||
return NULL;
|
||||
ptr = grub_stpcpy (fsuf, filename);
|
||||
grub_memcpy (ptr, ".sig", sizeof (".sig"));
|
||||
|
||||
sig = grub_file_open (fsuf, GRUB_FILE_TYPE_SIGNATURE);
|
||||
grub_memcpy (curfilt, grub_file_filters_enabled,
|
||||
sizeof (curfilt));
|
||||
grub_file_filter_disable_all ();
|
||||
sig = grub_file_open (fsuf);
|
||||
grub_memcpy (grub_file_filters_enabled, curfilt,
|
||||
sizeof (curfilt));
|
||||
grub_free (fsuf);
|
||||
if (!sig)
|
||||
return grub_errno;
|
||||
return NULL;
|
||||
|
||||
|
||||
struct grub_pubkey_context *ctxt = grub_malloc (sizeof (*ctxt));
|
||||
if (!ctxt)
|
||||
ret = grub_malloc (sizeof (*ret));
|
||||
if (!ret)
|
||||
{
|
||||
grub_file_close (sig);
|
||||
return grub_errno;
|
||||
return NULL;
|
||||
}
|
||||
err = grub_verify_signature_init (ctxt, sig);
|
||||
*ret = *io;
|
||||
|
||||
ret->fs = &verified_fs;
|
||||
ret->not_easily_seekable = 0;
|
||||
if (ret->size >> (sizeof (grub_size_t) * GRUB_CHAR_BIT - 1))
|
||||
{
|
||||
grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
|
||||
"big file signature isn't implemented yet");
|
||||
grub_file_close (sig);
|
||||
grub_free (ret);
|
||||
return NULL;
|
||||
}
|
||||
verified = grub_malloc (sizeof (*verified));
|
||||
if (!verified)
|
||||
{
|
||||
grub_file_close (sig);
|
||||
grub_free (ret);
|
||||
return NULL;
|
||||
}
|
||||
verified->buf = grub_malloc (ret->size);
|
||||
if (!verified->buf)
|
||||
{
|
||||
grub_file_close (sig);
|
||||
grub_free (verified);
|
||||
grub_free (ret);
|
||||
return NULL;
|
||||
}
|
||||
if (grub_file_read (io, verified->buf, ret->size) != (grub_ssize_t) ret->size)
|
||||
{
|
||||
if (!grub_errno)
|
||||
grub_error (GRUB_ERR_FILE_READ_ERROR, N_("premature end of file %s"),
|
||||
filename);
|
||||
grub_file_close (sig);
|
||||
verified_free (verified);
|
||||
grub_free (ret);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
err = grub_verify_signature_real (verified->buf, ret->size, 0, sig, NULL);
|
||||
grub_file_close (sig);
|
||||
if (err)
|
||||
{
|
||||
grub_pubkey_close (ctxt);
|
||||
return err;
|
||||
verified_free (verified);
|
||||
grub_free (ret);
|
||||
return NULL;
|
||||
}
|
||||
*context = ctxt;
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_pubkey_fini (void *ctxt)
|
||||
{
|
||||
return grub_verify_signature_real (ctxt, NULL);
|
||||
verified->file = io;
|
||||
ret->data = verified;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static char *
|
||||
@@ -935,16 +967,8 @@ struct grub_fs pseudo_fs =
|
||||
{
|
||||
.name = "pseudo",
|
||||
.read = pseudo_read
|
||||
};
|
||||
};
|
||||
|
||||
struct grub_file_verifier grub_pubkey_verifier =
|
||||
{
|
||||
.name = "pgp",
|
||||
.init = grub_pubkey_init,
|
||||
.fini = grub_pubkey_fini,
|
||||
.write = grub_pubkey_write,
|
||||
.close = grub_pubkey_close,
|
||||
};
|
||||
|
||||
static grub_extcmd_t cmd, cmd_trust;
|
||||
static grub_command_t cmd_distrust, cmd_list;
|
||||
@@ -959,6 +983,8 @@ GRUB_MOD_INIT(verify)
|
||||
sec = 1;
|
||||
else
|
||||
sec = 0;
|
||||
|
||||
grub_file_filter_register (GRUB_FILE_FILTER_PUBKEY, grub_pubkey_open);
|
||||
|
||||
grub_register_variable_hook ("check_signatures", 0, grub_env_write_sec);
|
||||
grub_env_export ("check_signatures");
|
||||
@@ -1004,13 +1030,11 @@ GRUB_MOD_INIT(verify)
|
||||
cmd_distrust = grub_register_command ("distrust", grub_cmd_distrust,
|
||||
N_("PUBKEY_ID"),
|
||||
N_("Remove PUBKEY_ID from trusted keys."));
|
||||
|
||||
grub_verifier_register (&grub_pubkey_verifier);
|
||||
}
|
||||
|
||||
GRUB_MOD_FINI(verify)
|
||||
{
|
||||
grub_verifier_unregister (&grub_pubkey_verifier);
|
||||
grub_file_filter_unregister (GRUB_FILE_FILTER_PUBKEY);
|
||||
grub_unregister_extcmd (cmd);
|
||||
grub_unregister_extcmd (cmd_trust);
|
||||
grub_unregister_command (cmd_list);
|
||||
|
||||
@@ -1,186 +0,0 @@
|
||||
#include <grub/file.h>
|
||||
#include <grub/verify.h>
|
||||
#include <grub/dl.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
struct grub_file_verifier *grub_file_verifiers;
|
||||
|
||||
struct grub_verified
|
||||
{
|
||||
grub_file_t file;
|
||||
void *buf;
|
||||
};
|
||||
typedef struct grub_verified *grub_verified_t;
|
||||
|
||||
static void
|
||||
verified_free (grub_verified_t verified)
|
||||
{
|
||||
if (verified)
|
||||
{
|
||||
grub_free (verified->buf);
|
||||
grub_free (verified);
|
||||
}
|
||||
}
|
||||
|
||||
static grub_ssize_t
|
||||
verified_read (struct grub_file *file, char *buf, grub_size_t len)
|
||||
{
|
||||
grub_verified_t verified = file->data;
|
||||
|
||||
grub_memcpy (buf, (char *) verified->buf + file->offset, len);
|
||||
return len;
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
verified_close (struct grub_file *file)
|
||||
{
|
||||
grub_verified_t verified = file->data;
|
||||
|
||||
grub_file_close (verified->file);
|
||||
verified_free (verified);
|
||||
file->data = 0;
|
||||
|
||||
/* device and name are freed by parent */
|
||||
file->device = 0;
|
||||
file->name = 0;
|
||||
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
struct grub_fs verified_fs =
|
||||
{
|
||||
.name = "verified_read",
|
||||
.read = verified_read,
|
||||
.close = verified_close
|
||||
};
|
||||
|
||||
static grub_file_t
|
||||
grub_verify_helper_open (grub_file_t io, enum grub_file_type type)
|
||||
{
|
||||
grub_verified_t verified = 0;
|
||||
struct grub_file_verifier *ver;
|
||||
void *context;
|
||||
grub_file_t ret = 0;
|
||||
grub_err_t err;
|
||||
|
||||
if ((type & GRUB_FILE_TYPE_MASK) == GRUB_FILE_TYPE_SIGNATURE
|
||||
|| (type & GRUB_FILE_TYPE_MASK) == GRUB_FILE_TYPE_VERIFY_SIGNATURE
|
||||
|| (type & GRUB_FILE_TYPE_SKIP_SIGNATURE))
|
||||
return io;
|
||||
|
||||
if (io->device->disk &&
|
||||
(io->device->disk->dev->id == GRUB_DISK_DEVICE_MEMDISK_ID
|
||||
|| io->device->disk->dev->id == GRUB_DISK_DEVICE_PROCFS_ID))
|
||||
return io;
|
||||
|
||||
FOR_LIST_ELEMENTS(ver, grub_file_verifiers)
|
||||
{
|
||||
enum grub_verify_flags flags = 0;
|
||||
err = ver->init (io, type, &context, &flags);
|
||||
if (err)
|
||||
goto fail_noclose;
|
||||
if (!(flags & GRUB_VERIFY_FLAGS_SKIP_VERIFICATION))
|
||||
break;
|
||||
}
|
||||
if (!ver)
|
||||
/* No verifiers wanted to verify. Just return underlying file. */
|
||||
return io;
|
||||
|
||||
ret = grub_malloc (sizeof (*ret));
|
||||
if (!ret)
|
||||
{
|
||||
goto fail;
|
||||
}
|
||||
*ret = *io;
|
||||
|
||||
ret->fs = &verified_fs;
|
||||
ret->not_easily_seekable = 0;
|
||||
if (ret->size >> (sizeof (grub_size_t) * GRUB_CHAR_BIT - 1))
|
||||
{
|
||||
grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
|
||||
"big file signature isn't implemented yet");
|
||||
goto fail;
|
||||
}
|
||||
verified = grub_malloc (sizeof (*verified));
|
||||
if (!verified)
|
||||
{
|
||||
goto fail;
|
||||
}
|
||||
verified->buf = grub_malloc (ret->size);
|
||||
if (!verified->buf)
|
||||
{
|
||||
goto fail;
|
||||
}
|
||||
if (grub_file_read (io, verified->buf, ret->size) != (grub_ssize_t) ret->size)
|
||||
{
|
||||
if (!grub_errno)
|
||||
grub_error (GRUB_ERR_FILE_READ_ERROR, N_("premature end of file %s"),
|
||||
io->name);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
err = ver->write (context, verified->buf, ret->size);
|
||||
if (err)
|
||||
goto fail;
|
||||
|
||||
err = ver->fini ? ver->fini (context) : GRUB_ERR_NONE;
|
||||
if (err)
|
||||
goto fail;
|
||||
|
||||
ver->close (context);
|
||||
|
||||
FOR_LIST_ELEMENTS_NEXT(ver, grub_file_verifiers)
|
||||
{
|
||||
enum grub_verify_flags flags = 0;
|
||||
err = ver->init (io, type, &context, &flags);
|
||||
if (err)
|
||||
goto fail_noclose;
|
||||
if (flags & GRUB_VERIFY_FLAGS_SKIP_VERIFICATION)
|
||||
continue;
|
||||
err = ver->write (context, verified->buf, ret->size);
|
||||
if (err)
|
||||
goto fail;
|
||||
|
||||
err = ver->fini ? ver->fini (context) : GRUB_ERR_NONE;
|
||||
if (err)
|
||||
goto fail;
|
||||
|
||||
ver->close (context);
|
||||
}
|
||||
|
||||
verified->file = io;
|
||||
ret->data = verified;
|
||||
return ret;
|
||||
|
||||
fail:
|
||||
ver->close (context);
|
||||
fail_noclose:
|
||||
verified_free (verified);
|
||||
grub_free (ret);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
grub_err_t
|
||||
grub_verify_string (char *str, enum grub_verify_string_type type)
|
||||
{
|
||||
struct grub_file_verifier *ver;
|
||||
FOR_LIST_ELEMENTS(ver, grub_file_verifiers)
|
||||
{
|
||||
grub_err_t err;
|
||||
err = ver->verify_string ? ver->verify_string (str, type) : GRUB_ERR_NONE;
|
||||
if (err)
|
||||
return err;
|
||||
}
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
GRUB_MOD_INIT(verify_helper)
|
||||
{
|
||||
grub_file_filter_register (GRUB_FILE_FILTER_VERIFY, grub_verify_helper_open);
|
||||
}
|
||||
|
||||
GRUB_MOD_FINI(verify_helper)
|
||||
{
|
||||
grub_file_filter_unregister (GRUB_FILE_FILTER_VERIFY);
|
||||
}
|
||||
@@ -92,8 +92,7 @@ grub_cmd_loopback (grub_extcmd_context_t ctxt, int argc, char **args)
|
||||
if (argc < 2)
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"));
|
||||
|
||||
file = grub_file_open (args[1], GRUB_FILE_TYPE_LOOPBACK
|
||||
| GRUB_FILE_TYPE_NO_DECOMPRESS);
|
||||
file = grub_file_open (args[1]);
|
||||
if (! file)
|
||||
return grub_errno;
|
||||
|
||||
|
||||
@@ -187,7 +187,7 @@ grub_efiemu_load_file (const char *filename)
|
||||
grub_file_t file;
|
||||
grub_err_t err;
|
||||
|
||||
file = grub_file_open (filename, GRUB_FILE_TYPE_GRUB_MODULE);
|
||||
file = grub_file_open (filename);
|
||||
if (! file)
|
||||
return grub_errno;
|
||||
|
||||
|
||||
@@ -418,7 +418,7 @@ grub_font_load (const char *filename)
|
||||
#endif
|
||||
|
||||
if (filename[0] == '(' || filename[0] == '/' || filename[0] == '+')
|
||||
file = grub_buffile_open (filename, GRUB_FILE_TYPE_FONT, 1024);
|
||||
file = grub_buffile_open (filename, 1024);
|
||||
else
|
||||
{
|
||||
const char *prefix = grub_env_get ("prefix");
|
||||
@@ -438,7 +438,7 @@ grub_font_load (const char *filename)
|
||||
ptr = grub_stpcpy (ptr, filename);
|
||||
ptr = grub_stpcpy (ptr, ".pf2");
|
||||
*ptr = 0;
|
||||
file = grub_buffile_open (fullname, GRUB_FILE_TYPE_FONT, 1024);
|
||||
file = grub_buffile_open (fullname, 1024);
|
||||
grub_free (fullname);
|
||||
}
|
||||
if (!file)
|
||||
|
||||
@@ -425,7 +425,7 @@ grub_cmd_zfs_key (grub_extcmd_context_t ctxt, int argc, char **args)
|
||||
if (argc > 0)
|
||||
{
|
||||
grub_file_t file;
|
||||
file = grub_file_open (args[0], GRUB_FILE_TYPE_ZFS_ENCRYPTION_KEY);
|
||||
file = grub_file_open (args[0]);
|
||||
if (!file)
|
||||
return grub_errno;
|
||||
real_size = grub_file_read (file, buf, 1024);
|
||||
|
||||
@@ -291,7 +291,7 @@ grub_mofile_open (struct grub_gettext_context *ctx,
|
||||
/* Using fd_mo and not another variable because
|
||||
it's needed for grub_gettext_get_info. */
|
||||
|
||||
fd = grub_file_open (filename, GRUB_FILE_TYPE_GETTEXT_CATALOG);
|
||||
fd = grub_file_open (filename);
|
||||
|
||||
if (!fd)
|
||||
return grub_errno;
|
||||
|
||||
@@ -743,7 +743,7 @@ grub_gfxmenu_view_load_theme (grub_gfxmenu_view_t view, const char *theme_path)
|
||||
p.view = view;
|
||||
p.theme_dir = grub_get_dirname (theme_path);
|
||||
|
||||
file = grub_file_open (theme_path, GRUB_FILE_TYPE_THEME);
|
||||
file = grub_file_open (theme_path);
|
||||
if (! file)
|
||||
{
|
||||
grub_free (p.theme_dir);
|
||||
|
||||
@@ -43,8 +43,7 @@ typedef struct grub_bufio *grub_bufio_t;
|
||||
static struct grub_fs grub_bufio_fs;
|
||||
|
||||
grub_file_t
|
||||
grub_bufio_open (grub_file_t io,
|
||||
grub_size_t size)
|
||||
grub_bufio_open (grub_file_t io, int size)
|
||||
{
|
||||
grub_file_t file;
|
||||
grub_bufio_t bufio = 0;
|
||||
@@ -58,7 +57,7 @@ grub_bufio_open (grub_file_t io,
|
||||
else if (size > GRUB_BUFIO_MAX_SIZE)
|
||||
size = GRUB_BUFIO_MAX_SIZE;
|
||||
|
||||
if (size > io->size)
|
||||
if ((size < 0) || ((unsigned) size > io->size))
|
||||
size = ((io->size > GRUB_BUFIO_MAX_SIZE) ? GRUB_BUFIO_MAX_SIZE :
|
||||
io->size);
|
||||
|
||||
@@ -82,12 +81,11 @@ grub_bufio_open (grub_file_t io,
|
||||
}
|
||||
|
||||
grub_file_t
|
||||
grub_buffile_open (const char *name, enum grub_file_type type,
|
||||
grub_size_t size)
|
||||
grub_buffile_open (const char *name, int size)
|
||||
{
|
||||
grub_file_t io, file;
|
||||
|
||||
io = grub_file_open (name, type);
|
||||
io = grub_file_open (name);
|
||||
if (! io)
|
||||
return 0;
|
||||
|
||||
|
||||
@@ -1125,14 +1125,11 @@ initialize_tables (grub_gzio_t gzio)
|
||||
even if IO does not contain data compressed by gzip, return a valid file
|
||||
object. Note that this function won't close IO, even if an error occurs. */
|
||||
static grub_file_t
|
||||
grub_gzio_open (grub_file_t io, enum grub_file_type type)
|
||||
grub_gzio_open (grub_file_t io, const char *name __attribute__ ((unused)))
|
||||
{
|
||||
grub_file_t file;
|
||||
grub_gzio_t gzio = 0;
|
||||
|
||||
if (type & GRUB_FILE_TYPE_NO_DECOMPRESS)
|
||||
return io;
|
||||
|
||||
file = (grub_file_t) grub_zalloc (sizeof (*file));
|
||||
if (! file)
|
||||
return 0;
|
||||
|
||||
@@ -407,14 +407,12 @@ CORRUPTED:
|
||||
}
|
||||
|
||||
static grub_file_t
|
||||
grub_lzopio_open (grub_file_t io, enum grub_file_type type)
|
||||
grub_lzopio_open (grub_file_t io,
|
||||
const char *name __attribute__ ((unused)))
|
||||
{
|
||||
grub_file_t file;
|
||||
grub_lzopio_t lzopio;
|
||||
|
||||
if (type & GRUB_FILE_TYPE_NO_DECOMPRESS)
|
||||
return io;
|
||||
|
||||
file = (grub_file_t) grub_zalloc (sizeof (*file));
|
||||
if (!file)
|
||||
return 0;
|
||||
|
||||
@@ -69,8 +69,7 @@ grub_file_offset_close (grub_file_t file)
|
||||
}
|
||||
|
||||
grub_file_t
|
||||
grub_file_offset_open (grub_file_t parent, enum grub_file_type type,
|
||||
grub_off_t start, grub_off_t size)
|
||||
grub_file_offset_open (grub_file_t parent, grub_off_t start, grub_off_t size)
|
||||
{
|
||||
struct grub_offset_file *off_data;
|
||||
grub_file_t off_file, last_off_file;
|
||||
@@ -96,10 +95,10 @@ grub_file_offset_open (grub_file_t parent, enum grub_file_type type,
|
||||
last_off_file = NULL;
|
||||
for (filter = GRUB_FILE_FILTER_COMPRESSION_FIRST;
|
||||
off_file && filter <= GRUB_FILE_FILTER_COMPRESSION_LAST; filter++)
|
||||
if (grub_file_filters[filter])
|
||||
if (grub_file_filters_enabled[filter])
|
||||
{
|
||||
last_off_file = off_file;
|
||||
off_file = grub_file_filters[filter] (off_file, type);
|
||||
off_file = grub_file_filters_enabled[filter] (off_file, parent->name);
|
||||
}
|
||||
|
||||
if (!off_file)
|
||||
|
||||
@@ -169,14 +169,12 @@ ERROR:
|
||||
}
|
||||
|
||||
static grub_file_t
|
||||
grub_xzio_open (grub_file_t io, enum grub_file_type type)
|
||||
grub_xzio_open (grub_file_t io,
|
||||
const char *name __attribute__ ((unused)))
|
||||
{
|
||||
grub_file_t file;
|
||||
grub_xzio_t xzio;
|
||||
|
||||
if (type & GRUB_FILE_TYPE_NO_DECOMPRESS)
|
||||
return io;
|
||||
|
||||
file = (grub_file_t) grub_zalloc (sizeof (*file));
|
||||
if (!file)
|
||||
return 0;
|
||||
|
||||
@@ -97,12 +97,30 @@ heap_init (grub_uint64_t addr, grub_uint64_t size, grub_memory_type_t type,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const void *dtb;
|
||||
static grub_size_t dtb_size;
|
||||
|
||||
static int
|
||||
iterate_linuxbios_table (grub_linuxbios_table_item_t table_item, void *data __attribute__ ((unused)))
|
||||
{
|
||||
if (table_item->tag != GRUB_LINUXBIOS_MEMBER_DTB)
|
||||
return 0;
|
||||
|
||||
if (grub_fdt_check_header (table_item + 1, table_item->size) >= 0)
|
||||
{
|
||||
dtb = table_item + 1;
|
||||
dtb_size = table_item->size;
|
||||
}
|
||||
else
|
||||
grub_printf ("Invalid DTB supplied by coreboot\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
grub_machine_init (void)
|
||||
{
|
||||
struct grub_module_header *header;
|
||||
void *dtb = 0;
|
||||
grub_size_t dtb_size = 0;
|
||||
|
||||
modend = grub_modules_get_end ();
|
||||
|
||||
@@ -128,12 +146,12 @@ grub_machine_init (void)
|
||||
grub_memmove (dtb_copy, dtb_orig_addr, dtb_size);
|
||||
break;
|
||||
}
|
||||
if (!dtb)
|
||||
grub_linuxbios_table_iterate (iterate_linuxbios_table, 0);
|
||||
if (!dtb)
|
||||
grub_fatal ("No DTB found");
|
||||
grub_fdtbus_init (dtb, dtb_size);
|
||||
|
||||
grub_rk3288_spi_init ();
|
||||
|
||||
grub_machine_timer_init ();
|
||||
grub_cros_init ();
|
||||
grub_pl050_init ();
|
||||
|
||||
@@ -688,7 +688,7 @@ grub_dl_load_file (const char *filename)
|
||||
|
||||
grub_boot_time ("Loading module %s", filename);
|
||||
|
||||
file = grub_file_open (filename, GRUB_FILE_TYPE_GRUB_MODULE);
|
||||
file = grub_file_open (filename);
|
||||
if (! file)
|
||||
return 0;
|
||||
|
||||
|
||||
@@ -136,12 +136,12 @@ fail:
|
||||
}
|
||||
|
||||
grub_elf_t
|
||||
grub_elf_open (const char *name, enum grub_file_type type)
|
||||
grub_elf_open (const char *name)
|
||||
{
|
||||
grub_file_t file;
|
||||
grub_elf_t elf;
|
||||
|
||||
file = grub_file_open (name, type);
|
||||
file = grub_file_open (name);
|
||||
if (! file)
|
||||
return 0;
|
||||
|
||||
|
||||
@@ -28,7 +28,8 @@
|
||||
|
||||
void (*EXPORT_VAR (grub_grubnet_fini)) (void);
|
||||
|
||||
grub_file_filter_t grub_file_filters[GRUB_FILE_FILTER_MAX];
|
||||
grub_file_filter_t grub_file_filters_all[GRUB_FILE_FILTER_MAX];
|
||||
grub_file_filter_t grub_file_filters_enabled[GRUB_FILE_FILTER_MAX];
|
||||
|
||||
/* Get the device part of the filename NAME. It is enclosed by parentheses. */
|
||||
char *
|
||||
@@ -58,7 +59,7 @@ grub_file_get_device_name (const char *name)
|
||||
}
|
||||
|
||||
grub_file_t
|
||||
grub_file_open (const char *name, enum grub_file_type type)
|
||||
grub_file_open (const char *name)
|
||||
{
|
||||
grub_device_t device = 0;
|
||||
grub_file_t file = 0, last_file = 0;
|
||||
@@ -113,20 +114,18 @@ grub_file_open (const char *name, enum grub_file_type type)
|
||||
file->name = grub_strdup (name);
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
|
||||
for (filter = 0; file && filter < ARRAY_SIZE (grub_file_filters);
|
||||
for (filter = 0; file && filter < ARRAY_SIZE (grub_file_filters_enabled);
|
||||
filter++)
|
||||
if (grub_file_filters[filter])
|
||||
if (grub_file_filters_enabled[filter])
|
||||
{
|
||||
last_file = file;
|
||||
file = grub_file_filters[filter] (file, type);
|
||||
if (file && file != last_file)
|
||||
{
|
||||
file->name = grub_strdup (name);
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
}
|
||||
file = grub_file_filters_enabled[filter] (file, name);
|
||||
}
|
||||
if (!file)
|
||||
grub_file_close (last_file);
|
||||
|
||||
grub_memcpy (grub_file_filters_enabled, grub_file_filters_all,
|
||||
sizeof (grub_file_filters_enabled));
|
||||
|
||||
return file;
|
||||
|
||||
@@ -138,6 +137,9 @@ grub_file_open (const char *name, enum grub_file_type type)
|
||||
|
||||
grub_free (file);
|
||||
|
||||
grub_memcpy (grub_file_filters_enabled, grub_file_filters_all,
|
||||
sizeof (grub_file_filters_enabled));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -62,13 +62,12 @@ unsigned int grub_loader_cmdline_size (int argc, char *argv[])
|
||||
return size;
|
||||
}
|
||||
|
||||
grub_err_t
|
||||
grub_create_loader_cmdline (int argc, char *argv[], char *buf,
|
||||
grub_size_t size, enum grub_verify_string_type type)
|
||||
int grub_create_loader_cmdline (int argc, char *argv[], char *buf,
|
||||
grub_size_t size)
|
||||
{
|
||||
int i, space;
|
||||
unsigned int arg_size;
|
||||
char *c, *orig_buf = buf;
|
||||
char *c;
|
||||
|
||||
for (i = 0; i < argc; i++)
|
||||
{
|
||||
@@ -105,5 +104,5 @@ grub_create_loader_cmdline (int argc, char *argv[], char *buf,
|
||||
|
||||
*buf = 0;
|
||||
|
||||
return grub_verify_string (orig_buf, type);
|
||||
return i;
|
||||
}
|
||||
|
||||
@@ -696,7 +696,7 @@ syslinux_parse_real (struct syslinux_menu *menu)
|
||||
char *buf = NULL;
|
||||
grub_err_t err = GRUB_ERR_NONE;
|
||||
|
||||
file = grub_file_open (menu->filename, GRUB_FILE_TYPE_CONFIG);
|
||||
file = grub_file_open (menu->filename);
|
||||
if (!file)
|
||||
return grub_errno;
|
||||
while ((grub_free (buf), buf = grub_file_getline (file)))
|
||||
|
||||
@@ -28,7 +28,6 @@
|
||||
#include <grub/cpu/linux.h>
|
||||
#include <grub/lib/cmdline.h>
|
||||
#include <grub/linux.h>
|
||||
#include <grub/verify.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
@@ -400,11 +399,8 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
|
||||
/* Create kernel command line. */
|
||||
grub_memcpy (linux_args, LINUX_IMAGE, sizeof (LINUX_IMAGE));
|
||||
err = grub_create_loader_cmdline (argc, argv,
|
||||
linux_args + sizeof (LINUX_IMAGE) - 1, size,
|
||||
GRUB_VERIFY_KERNEL_CMDLINE);
|
||||
if (err)
|
||||
goto fail;
|
||||
grub_create_loader_cmdline (argc, argv,
|
||||
linux_args + sizeof (LINUX_IMAGE) - 1, size);
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
|
||||
|
||||
@@ -31,7 +31,6 @@
|
||||
#include <grub/efi/pe32.h>
|
||||
#include <grub/i18n.h>
|
||||
#include <grub/lib/cmdline.h>
|
||||
#include <grub/verify.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
@@ -306,12 +305,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
goto fail;
|
||||
}
|
||||
grub_memcpy (linux_args, LINUX_IMAGE, sizeof (LINUX_IMAGE));
|
||||
err = grub_create_loader_cmdline (argc, argv,
|
||||
linux_args + sizeof (LINUX_IMAGE) - 1,
|
||||
cmdline_size,
|
||||
GRUB_VERIFY_KERNEL_CMDLINE);
|
||||
if (err)
|
||||
goto fail;
|
||||
grub_create_loader_cmdline (argc, argv,
|
||||
linux_args + sizeof (LINUX_IMAGE) - 1,
|
||||
cmdline_size);
|
||||
|
||||
if (grub_errno == GRUB_ERR_NONE)
|
||||
{
|
||||
|
||||
@@ -219,7 +219,7 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)),
|
||||
|
||||
b = grub_efi_system_table->boot_services;
|
||||
|
||||
file = grub_file_open (filename, GRUB_FILE_TYPE_EFI_CHAINLOADED_IMAGE);
|
||||
file = grub_file_open (filename);
|
||||
if (! file)
|
||||
goto fail;
|
||||
|
||||
|
||||
@@ -35,7 +35,6 @@
|
||||
#include <grub/ns8250.h>
|
||||
#include <grub/bsdlabel.h>
|
||||
#include <grub/crypto.h>
|
||||
#include <grub/verify.h>
|
||||
#ifdef GRUB_MACHINE_PCBIOS
|
||||
#include <grub/machine/int.h>
|
||||
#endif
|
||||
@@ -417,8 +416,6 @@ grub_freebsd_add_meta_module (const char *filename, const char *type,
|
||||
grub_addr_t addr, grub_uint32_t size)
|
||||
{
|
||||
const char *name;
|
||||
grub_err_t err;
|
||||
|
||||
name = grub_strrchr (filename, '/');
|
||||
if (name)
|
||||
name++;
|
||||
@@ -472,9 +469,6 @@ grub_freebsd_add_meta_module (const char *filename, const char *type,
|
||||
*(p++) = ' ';
|
||||
}
|
||||
*p = 0;
|
||||
err = grub_verify_string (cmdline, GRUB_VERIFY_MODULE_CMDLINE);
|
||||
if (err)
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1463,7 +1457,7 @@ grub_bsd_load (int argc, char *argv[])
|
||||
goto fail;
|
||||
}
|
||||
|
||||
file = grub_file_open (argv[0], GRUB_FILE_TYPE_BSD_KERNEL);
|
||||
file = grub_file_open (argv[0]);
|
||||
if (!file)
|
||||
goto fail;
|
||||
|
||||
@@ -1540,7 +1534,7 @@ grub_cmd_freebsd (grub_extcmd_context_t ctxt, int argc, char *argv[])
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
file = grub_file_open (argv[0], GRUB_FILE_TYPE_BSD_KERNEL);
|
||||
file = grub_file_open (argv[0]);
|
||||
if (! file)
|
||||
return grub_errno;
|
||||
|
||||
@@ -1699,7 +1693,7 @@ grub_cmd_netbsd (grub_extcmd_context_t ctxt, int argc, char *argv[])
|
||||
{
|
||||
grub_file_t file;
|
||||
|
||||
file = grub_file_open (argv[0], GRUB_FILE_TYPE_BSD_KERNEL);
|
||||
file = grub_file_open (argv[0]);
|
||||
if (! file)
|
||||
return grub_errno;
|
||||
|
||||
@@ -1808,7 +1802,7 @@ grub_cmd_freebsd_loadenv (grub_command_t cmd __attribute__ ((unused)),
|
||||
goto fail;
|
||||
}
|
||||
|
||||
file = grub_file_open (argv[0], GRUB_FILE_TYPE_FREEBSD_ENV);
|
||||
file = grub_file_open (argv[0]);
|
||||
if ((!file) || (!file->size))
|
||||
goto fail;
|
||||
|
||||
@@ -1913,7 +1907,7 @@ grub_cmd_freebsd_module (grub_command_t cmd __attribute__ ((unused)),
|
||||
return 0;
|
||||
}
|
||||
|
||||
file = grub_file_open (argv[0], GRUB_FILE_TYPE_FREEBSD_MODULE);
|
||||
file = grub_file_open (argv[0]);
|
||||
if ((!file) || (!file->size))
|
||||
goto fail;
|
||||
|
||||
@@ -1964,7 +1958,7 @@ grub_netbsd_module_load (char *filename, grub_uint32_t type)
|
||||
void *src;
|
||||
grub_err_t err;
|
||||
|
||||
file = grub_file_open (filename, GRUB_FILE_TYPE_NETBSD_MODULE);
|
||||
file = grub_file_open (filename);
|
||||
if ((!file) || (!file->size))
|
||||
goto fail;
|
||||
|
||||
@@ -2054,7 +2048,7 @@ grub_cmd_freebsd_module_elf (grub_command_t cmd __attribute__ ((unused)),
|
||||
return 0;
|
||||
}
|
||||
|
||||
file = grub_file_open (argv[0], GRUB_FILE_TYPE_FREEBSD_MODULE_ELF);
|
||||
file = grub_file_open (argv[0]);
|
||||
if (!file)
|
||||
return grub_errno;
|
||||
if (!file->size)
|
||||
@@ -2094,7 +2088,7 @@ grub_cmd_openbsd_ramdisk (grub_command_t cmd __attribute__ ((unused)),
|
||||
if (!openbsd_ramdisk.max_size)
|
||||
return grub_error (GRUB_ERR_BAD_OS, "your kOpenBSD doesn't support ramdisk");
|
||||
|
||||
file = grub_file_open (args[0], GRUB_FILE_TYPE_OPENBSD_RAMDISK);
|
||||
file = grub_file_open (args[0]);
|
||||
if (! file)
|
||||
return grub_errno;
|
||||
|
||||
|
||||
@@ -439,7 +439,7 @@ grub_cmd_chain (grub_command_t cmd __attribute__ ((unused)),
|
||||
|
||||
grub_loader_unset ();
|
||||
|
||||
file = grub_file_open (argv[0], GRUB_FILE_TYPE_COREBOOT_CHAINLOADER);
|
||||
file = grub_file_open (argv[0]);
|
||||
if (!file)
|
||||
return grub_errno;
|
||||
|
||||
|
||||
@@ -695,7 +695,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
goto fail;
|
||||
}
|
||||
|
||||
file = grub_file_open (argv[0], GRUB_FILE_TYPE_LINUX_KERNEL);
|
||||
file = grub_file_open (argv[0]);
|
||||
if (! file)
|
||||
goto fail;
|
||||
|
||||
@@ -1012,17 +1012,11 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
if (!linux_cmdline)
|
||||
goto fail;
|
||||
grub_memcpy (linux_cmdline, LINUX_IMAGE, sizeof (LINUX_IMAGE));
|
||||
{
|
||||
grub_err_t err;
|
||||
err = grub_create_loader_cmdline (argc, argv,
|
||||
linux_cmdline
|
||||
+ sizeof (LINUX_IMAGE) - 1,
|
||||
maximal_cmdline_size
|
||||
- (sizeof (LINUX_IMAGE) - 1),
|
||||
GRUB_VERIFY_KERNEL_CMDLINE);
|
||||
if (err)
|
||||
goto fail;
|
||||
}
|
||||
grub_create_loader_cmdline (argc, argv,
|
||||
linux_cmdline
|
||||
+ sizeof (LINUX_IMAGE) - 1,
|
||||
maximal_cmdline_size
|
||||
- (sizeof (LINUX_IMAGE) - 1));
|
||||
|
||||
len = prot_file_size;
|
||||
if (grub_file_read (file, prot_mode_mem, len) != len && !grub_errno)
|
||||
|
||||
@@ -673,8 +673,10 @@ grub_multiboot_init_mbi (int argc, char *argv[])
|
||||
return grub_errno;
|
||||
cmdline_size = len;
|
||||
|
||||
return grub_create_loader_cmdline (argc, argv, cmdline,
|
||||
cmdline_size, GRUB_VERIFY_KERNEL_CMDLINE);
|
||||
grub_create_loader_cmdline (argc, argv, cmdline,
|
||||
cmdline_size);
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
grub_err_t
|
||||
@@ -683,7 +685,6 @@ grub_multiboot_add_module (grub_addr_t start, grub_size_t size,
|
||||
{
|
||||
struct module *newmod;
|
||||
grub_size_t len = 0;
|
||||
grub_err_t err;
|
||||
|
||||
newmod = grub_malloc (sizeof (*newmod));
|
||||
if (!newmod)
|
||||
@@ -703,13 +704,8 @@ grub_multiboot_add_module (grub_addr_t start, grub_size_t size,
|
||||
newmod->cmdline_size = len;
|
||||
total_modcmd += ALIGN_UP (len, 4);
|
||||
|
||||
err = grub_create_loader_cmdline (argc, argv, newmod->cmdline,
|
||||
newmod->cmdline_size, GRUB_VERIFY_MODULE_CMDLINE);
|
||||
if (err)
|
||||
{
|
||||
grub_free (newmod);
|
||||
return grub_errno;
|
||||
}
|
||||
grub_create_loader_cmdline (argc, argv, newmod->cmdline,
|
||||
newmod->cmdline_size);
|
||||
|
||||
if (modules_last)
|
||||
modules_last->next = newmod;
|
||||
|
||||
@@ -156,8 +156,8 @@ grub_chainloader_cmd (const char *filename, grub_chainloader_flags_t flags)
|
||||
|
||||
grub_dl_ref (my_mod);
|
||||
|
||||
file = grub_file_open (filename, GRUB_FILE_TYPE_PCCHAINLOADER
|
||||
| GRUB_FILE_TYPE_NO_DECOMPRESS);
|
||||
grub_file_filter_disable_compression ();
|
||||
file = grub_file_open (filename);
|
||||
if (! file)
|
||||
goto fail;
|
||||
|
||||
|
||||
@@ -110,7 +110,7 @@ grub_cmd_freedos (grub_command_t cmd __attribute__ ((unused)),
|
||||
if (!rel)
|
||||
goto fail;
|
||||
|
||||
file = grub_file_open (argv[0], GRUB_FILE_TYPE_FREEDOS);
|
||||
file = grub_file_open (argv[0]);
|
||||
if (! file)
|
||||
goto fail;
|
||||
|
||||
|
||||
@@ -139,7 +139,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
goto fail;
|
||||
}
|
||||
|
||||
file = grub_file_open (argv[0], GRUB_FILE_TYPE_LINUX_KERNEL);
|
||||
file = grub_file_open (argv[0]);
|
||||
if (! file)
|
||||
goto fail;
|
||||
|
||||
@@ -334,14 +334,11 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
/* Create kernel command line. */
|
||||
grub_memcpy ((char *)grub_linux_real_chunk + GRUB_LINUX_CL_OFFSET,
|
||||
LINUX_IMAGE, sizeof (LINUX_IMAGE));
|
||||
err = grub_create_loader_cmdline (argc, argv,
|
||||
(char *)grub_linux_real_chunk
|
||||
+ GRUB_LINUX_CL_OFFSET + sizeof (LINUX_IMAGE) - 1,
|
||||
maximal_cmdline_size
|
||||
- (sizeof (LINUX_IMAGE) - 1),
|
||||
GRUB_VERIFY_KERNEL_CMDLINE);
|
||||
if (err)
|
||||
goto fail;
|
||||
grub_create_loader_cmdline (argc, argv,
|
||||
(char *)grub_linux_real_chunk
|
||||
+ GRUB_LINUX_CL_OFFSET + sizeof (LINUX_IMAGE) - 1,
|
||||
maximal_cmdline_size
|
||||
- (sizeof (LINUX_IMAGE) - 1));
|
||||
|
||||
if (grub_linux_is_bzimage)
|
||||
grub_linux_prot_target = GRUB_LINUX_BZIMAGE_ADDR;
|
||||
|
||||
@@ -90,7 +90,7 @@ grub_cmd_ntldr (grub_command_t cmd __attribute__ ((unused)),
|
||||
if (!rel)
|
||||
goto fail;
|
||||
|
||||
file = grub_file_open (argv[0], GRUB_FILE_TYPE_NTLDR);
|
||||
file = grub_file_open (argv[0]);
|
||||
if (! file)
|
||||
goto fail;
|
||||
|
||||
|
||||
@@ -33,7 +33,6 @@
|
||||
#include <grub/mm.h>
|
||||
#include <grub/cpu/relocator.h>
|
||||
#include <grub/extcmd.h>
|
||||
#include <grub/verify.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
@@ -414,7 +413,7 @@ grub_cmd_plan9 (grub_extcmd_context_t ctxt, int argc, char *argv[])
|
||||
if (!rel)
|
||||
goto fail;
|
||||
|
||||
fill_ctx.file = grub_file_open (argv[0], GRUB_FILE_TYPE_PLAN9_KERNEL);
|
||||
fill_ctx.file = grub_file_open (argv[0]);
|
||||
if (! fill_ctx.file)
|
||||
goto fail;
|
||||
|
||||
@@ -506,7 +505,6 @@ grub_cmd_plan9 (grub_extcmd_context_t ctxt, int argc, char *argv[])
|
||||
configptr = grub_stpcpy (configptr, "bootfile=");
|
||||
configptr = grub_stpcpy (configptr, bootpath);
|
||||
*configptr++ = '\n';
|
||||
char *cmdline = configptr;
|
||||
{
|
||||
int i;
|
||||
for (i = 1; i < argc; i++)
|
||||
@@ -515,15 +513,6 @@ grub_cmd_plan9 (grub_extcmd_context_t ctxt, int argc, char *argv[])
|
||||
*configptr++ = '\n';
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
grub_err_t err;
|
||||
*configptr = '\0';
|
||||
err = grub_verify_string (cmdline, GRUB_VERIFY_KERNEL_CMDLINE);
|
||||
if (err)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
configptr = grub_stpcpy (configptr, fill_ctx.pmap);
|
||||
|
||||
{
|
||||
|
||||
@@ -99,7 +99,7 @@ grub_cmd_pxechain (grub_command_t cmd __attribute__ ((unused)),
|
||||
if (!rel)
|
||||
goto fail;
|
||||
|
||||
file = grub_file_open (argv[0], GRUB_FILE_TYPE_PXECHAINLOADER);
|
||||
file = grub_file_open (argv[0]);
|
||||
if (! file)
|
||||
goto fail;
|
||||
|
||||
|
||||
@@ -99,7 +99,7 @@ grub_cmd_truecrypt (grub_command_t cmd __attribute__ ((unused)),
|
||||
|
||||
grub_dl_ref (my_mod);
|
||||
|
||||
file = grub_file_open (argv[0], GRUB_FILE_TYPE_TRUECRYPT);
|
||||
file = grub_file_open (argv[0]);
|
||||
if (! file)
|
||||
goto fail;
|
||||
|
||||
|
||||
@@ -40,7 +40,6 @@
|
||||
#include <grub/xen_file.h>
|
||||
#include <grub/linux.h>
|
||||
#include <grub/i386/memory.h>
|
||||
#include <grub/verify.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
@@ -648,11 +647,8 @@ grub_cmd_xen (grub_command_t cmd __attribute__ ((unused)),
|
||||
grub_create_loader_cmdline (argc - 1, argv + 1,
|
||||
(char *) xen_state.next_start.cmd_line,
|
||||
sizeof (xen_state.next_start.cmd_line) - 1);
|
||||
err = grub_verify_string (xen_state.next_start.cmd_line, GRUB_VERIFY_MODULE_CMDLINE);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
file = grub_file_open (argv[0], GRUB_FILE_TYPE_LINUX_KERNEL);
|
||||
file = grub_file_open (argv[0]);
|
||||
if (!file)
|
||||
return grub_errno;
|
||||
|
||||
@@ -897,8 +893,9 @@ grub_cmd_module (grub_command_t cmd __attribute__ ((unused)),
|
||||
|
||||
xen_state.max_addr = ALIGN_UP (xen_state.max_addr, PAGE_SIZE);
|
||||
|
||||
file = grub_file_open (argv[0], GRUB_FILE_TYPE_LINUX_INITRD |
|
||||
(nounzip ? GRUB_FILE_TYPE_NO_DECOMPRESS : 0));
|
||||
if (nounzip)
|
||||
grub_file_filter_disable_compression ();
|
||||
file = grub_file_open (argv[0]);
|
||||
if (!file)
|
||||
return grub_errno;
|
||||
size = grub_file_size (file);
|
||||
@@ -912,9 +909,6 @@ grub_cmd_module (grub_command_t cmd __attribute__ ((unused)),
|
||||
|
||||
grub_create_loader_cmdline (argc - 1, argv + 1,
|
||||
get_virtual_current_address (ch), cmdline_len);
|
||||
err = grub_verify_string (get_virtual_current_address (ch), GRUB_VERIFY_MODULE_CMDLINE);
|
||||
if (err)
|
||||
goto fail;
|
||||
|
||||
xen_state.module_info_page[xen_state.n_modules].cmdline =
|
||||
xen_state.max_addr - xen_state.modules_target_start;
|
||||
|
||||
@@ -78,7 +78,7 @@ grub_xen_file (grub_file_t file)
|
||||
Trim it. */
|
||||
if (grub_memcmp (magic, XZ_MAGIC, sizeof (XZ_MAGIC) - 1) == 0)
|
||||
payload_length -= 4;
|
||||
off_file = grub_file_offset_open (file, GRUB_FILE_TYPE_LINUX_KERNEL, payload_offset,
|
||||
off_file = grub_file_offset_open (file, payload_offset,
|
||||
payload_length);
|
||||
if (!off_file)
|
||||
goto fail;
|
||||
|
||||
@@ -487,7 +487,7 @@ grub_cmd_devprop_load (grub_command_t cmd __attribute__ ((unused)),
|
||||
if (argc != 1)
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"));
|
||||
|
||||
file = grub_file_open (args[0], GRUB_FILE_XNU_DEVPROP);
|
||||
file = grub_file_open (args[0]);
|
||||
if (! file)
|
||||
return grub_errno;
|
||||
size = grub_file_size (file);
|
||||
|
||||
@@ -33,7 +33,6 @@
|
||||
#include <grub/i18n.h>
|
||||
#include <grub/env.h>
|
||||
#include <grub/linux.h>
|
||||
#include <grub/verify.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
@@ -544,12 +543,6 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
p = grub_stpcpy (p, argv[i]);
|
||||
}
|
||||
cmdline[10] = '=';
|
||||
|
||||
*p = '\0';
|
||||
|
||||
err = grub_verify_string (cmdline, GRUB_VERIFY_KERNEL_CMDLINE);
|
||||
if (err)
|
||||
goto fail;
|
||||
|
||||
boot_param->command_line = (grub_uint64_t) cmdline;
|
||||
boot_param->efi_systab = (grub_uint64_t) grub_efi_system_table;
|
||||
|
||||
@@ -173,6 +173,7 @@ grub_initrd_init (int argc, char *argv[],
|
||||
eptr = grub_strchr (ptr, ':');
|
||||
if (eptr)
|
||||
{
|
||||
grub_file_filter_disable_compression ();
|
||||
initrd_ctx->components[i].newc_name = grub_strndup (ptr, eptr - ptr);
|
||||
if (!initrd_ctx->components[i].newc_name)
|
||||
{
|
||||
@@ -197,9 +198,8 @@ grub_initrd_init (int argc, char *argv[],
|
||||
root = 0;
|
||||
newc = 0;
|
||||
}
|
||||
initrd_ctx->components[i].file = grub_file_open (fname,
|
||||
GRUB_FILE_TYPE_LINUX_INITRD
|
||||
| GRUB_FILE_TYPE_NO_DECOMPRESS);
|
||||
grub_file_filter_disable_compression ();
|
||||
initrd_ctx->components[i].file = grub_file_open (fname);
|
||||
if (!initrd_ctx->components[i].file)
|
||||
{
|
||||
grub_initrd_close (initrd_ctx);
|
||||
|
||||
@@ -188,12 +188,12 @@ fail:
|
||||
}
|
||||
|
||||
grub_macho_t
|
||||
grub_macho_open (const char *name, enum grub_file_type type, int is_64bit)
|
||||
grub_macho_open (const char *name, int is_64bit)
|
||||
{
|
||||
grub_file_t file;
|
||||
grub_macho_t macho;
|
||||
|
||||
file = grub_file_open (name, type);
|
||||
file = grub_file_open (name);
|
||||
if (! file)
|
||||
return 0;
|
||||
|
||||
|
||||
@@ -237,7 +237,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
if (argc == 0)
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"));
|
||||
|
||||
elf = grub_elf_open (argv[0], GRUB_FILE_TYPE_LINUX_KERNEL);
|
||||
elf = grub_elf_open (argv[0]);
|
||||
if (! elf)
|
||||
return grub_errno;
|
||||
|
||||
@@ -327,8 +327,6 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
linux_argv++;
|
||||
linux_args += ALIGN_UP (sizeof ("a0"), 4);
|
||||
|
||||
char *params = linux_args;
|
||||
|
||||
#ifdef GRUB_MACHINE_MIPS_LOONGSON
|
||||
{
|
||||
unsigned mtype = grub_arch_machine;
|
||||
@@ -354,12 +352,6 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
linux_args += ALIGN_UP (grub_strlen (argv[i]) + 1, 4);
|
||||
}
|
||||
|
||||
*linux_args = '\0';
|
||||
|
||||
err = grub_verify_string (params, GRUB_VERIFY_KERNEL_CMDLINE);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
/* Reserve space for rd arguments. */
|
||||
rd_addr_arg_off = (grub_uint8_t *) linux_args - (grub_uint8_t *) playground;
|
||||
linux_args += ALIGN_UP (sizeof ("rd_start=0xXXXXXXXXXXXXXXXX"), 4);
|
||||
|
||||
@@ -306,16 +306,14 @@ grub_cmd_multiboot (grub_command_t cmd __attribute__ ((unused)),
|
||||
if (argc == 0)
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"));
|
||||
|
||||
file = grub_file_open (argv[0], GRUB_FILE_TYPE_MULTIBOOT_KERNEL);
|
||||
file = grub_file_open (argv[0]);
|
||||
if (! file)
|
||||
return grub_errno;
|
||||
|
||||
grub_dl_ref (my_mod);
|
||||
|
||||
/* Skip filename. */
|
||||
err = grub_multiboot_init_mbi (argc - 1, argv + 1);
|
||||
if (err)
|
||||
goto fail;
|
||||
grub_multiboot_init_mbi (argc - 1, argv + 1);
|
||||
|
||||
grub_relocator_unload (grub_multiboot_relocator);
|
||||
grub_multiboot_relocator = grub_relocator_new ();
|
||||
@@ -374,8 +372,10 @@ grub_cmd_module (grub_command_t cmd __attribute__ ((unused)),
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT,
|
||||
N_("you need to load the kernel first"));
|
||||
|
||||
file = grub_file_open (argv[0], GRUB_FILE_TYPE_MULTIBOOT_MODULE
|
||||
| (nounzip ? GRUB_FILE_TYPE_NO_DECOMPRESS : 0));
|
||||
if (nounzip)
|
||||
grub_file_filter_disable_compression ();
|
||||
|
||||
file = grub_file_open (argv[0]);
|
||||
if (! file)
|
||||
return grub_errno;
|
||||
|
||||
|
||||
@@ -1074,8 +1074,10 @@ grub_multiboot_init_mbi (int argc, char *argv[])
|
||||
return grub_errno;
|
||||
cmdline_size = len;
|
||||
|
||||
return grub_create_loader_cmdline (argc, argv, cmdline, cmdline_size,
|
||||
GRUB_VERIFY_KERNEL_CMDLINE);
|
||||
grub_create_loader_cmdline (argc, argv, cmdline,
|
||||
cmdline_size);
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
grub_err_t
|
||||
@@ -1084,7 +1086,6 @@ grub_multiboot_add_module (grub_addr_t start, grub_size_t size,
|
||||
{
|
||||
struct module *newmod;
|
||||
grub_size_t len = 0;
|
||||
grub_err_t err;
|
||||
|
||||
newmod = grub_malloc (sizeof (*newmod));
|
||||
if (!newmod)
|
||||
@@ -1103,10 +1104,8 @@ grub_multiboot_add_module (grub_addr_t start, grub_size_t size,
|
||||
newmod->cmdline_size = len;
|
||||
total_modcmd += ALIGN_UP (len, MULTIBOOT_TAG_ALIGN);
|
||||
|
||||
err = grub_create_loader_cmdline (argc, argv, newmod->cmdline,
|
||||
newmod->cmdline_size, GRUB_VERIFY_MODULE_CMDLINE);
|
||||
if (err)
|
||||
return err;
|
||||
grub_create_loader_cmdline (argc, argv, newmod->cmdline,
|
||||
newmod->cmdline_size);
|
||||
|
||||
if (modules_last)
|
||||
modules_last->next = newmod;
|
||||
|
||||
@@ -302,9 +302,8 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
|
||||
/* Create kernel command line. */
|
||||
grub_memcpy (linux_args, LINUX_IMAGE, sizeof (LINUX_IMAGE));
|
||||
if (grub_create_loader_cmdline (argc, argv, linux_args + sizeof (LINUX_IMAGE) - 1,
|
||||
size))
|
||||
goto out;
|
||||
grub_create_loader_cmdline (argc, argv, linux_args + sizeof (LINUX_IMAGE) - 1,
|
||||
size);
|
||||
|
||||
out:
|
||||
|
||||
|
||||
@@ -340,9 +340,8 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
|
||||
/* Create kernel command line. */
|
||||
grub_memcpy (linux_args, LINUX_IMAGE, sizeof (LINUX_IMAGE));
|
||||
if (grub_create_loader_cmdline (argc, argv, linux_args + sizeof (LINUX_IMAGE) - 1,
|
||||
size, GRUB_VERIFY_KERNEL_CMDLINE))
|
||||
goto out;
|
||||
grub_create_loader_cmdline (argc, argv, linux_args + sizeof (LINUX_IMAGE) - 1,
|
||||
size);
|
||||
|
||||
out:
|
||||
if (elf)
|
||||
|
||||
@@ -33,7 +33,6 @@
|
||||
#include <grub/extcmd.h>
|
||||
#include <grub/env.h>
|
||||
#include <grub/i18n.h>
|
||||
#include <grub/verify.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
@@ -352,7 +351,7 @@ grub_cmd_xnu_kernel (grub_command_t cmd __attribute__ ((unused)),
|
||||
|
||||
grub_xnu_unload ();
|
||||
|
||||
macho = grub_macho_open (args[0], GRUB_FILE_TYPE_XNU_KERNEL, 0);
|
||||
macho = grub_macho_open (args[0], 0);
|
||||
if (! macho)
|
||||
return grub_errno;
|
||||
|
||||
@@ -426,10 +425,6 @@ grub_cmd_xnu_kernel (grub_command_t cmd __attribute__ ((unused)),
|
||||
if (ptr != grub_xnu_cmdline)
|
||||
*(ptr - 1) = 0;
|
||||
|
||||
err = grub_verify_string (grub_xnu_cmdline, GRUB_VERIFY_KERNEL_CMDLINE);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
#if defined (__i386) && !defined (GRUB_MACHINE_EFI)
|
||||
err = grub_efiemu_autocore ();
|
||||
if (err)
|
||||
@@ -461,7 +456,7 @@ grub_cmd_xnu_kernel64 (grub_command_t cmd __attribute__ ((unused)),
|
||||
|
||||
grub_xnu_unload ();
|
||||
|
||||
macho = grub_macho_open (args[0], GRUB_FILE_TYPE_XNU_KERNEL, 1);
|
||||
macho = grub_macho_open (args[0], 1);
|
||||
if (! macho)
|
||||
return grub_errno;
|
||||
|
||||
@@ -539,10 +534,6 @@ grub_cmd_xnu_kernel64 (grub_command_t cmd __attribute__ ((unused)),
|
||||
if (ptr != grub_xnu_cmdline)
|
||||
*(ptr - 1) = 0;
|
||||
|
||||
err = grub_verify_string (grub_xnu_cmdline, GRUB_VERIFY_KERNEL_CMDLINE);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
#if defined (__i386) && !defined (GRUB_MACHINE_EFI)
|
||||
err = grub_efiemu_autocore ();
|
||||
if (err)
|
||||
@@ -683,7 +674,7 @@ grub_xnu_load_driver (char *infoplistname, grub_file_t binaryfile,
|
||||
macho = 0;
|
||||
|
||||
if (infoplistname)
|
||||
infoplist = grub_file_open (infoplistname, GRUB_FILE_TYPE_XNU_INFO_PLIST);
|
||||
infoplist = grub_file_open (infoplistname);
|
||||
else
|
||||
infoplist = 0;
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
@@ -780,7 +771,7 @@ grub_cmd_xnu_mkext (grub_command_t cmd __attribute__ ((unused)),
|
||||
if (! grub_xnu_heap_size)
|
||||
return grub_error (GRUB_ERR_BAD_OS, N_("you need to load the kernel first"));
|
||||
|
||||
file = grub_file_open (args[0], GRUB_FILE_TYPE_XNU_MKEXT);
|
||||
file = grub_file_open (args[0]);
|
||||
if (! file)
|
||||
return grub_errno;
|
||||
|
||||
@@ -894,7 +885,7 @@ grub_cmd_xnu_ramdisk (grub_command_t cmd __attribute__ ((unused)),
|
||||
if (! grub_xnu_heap_size)
|
||||
return grub_error (GRUB_ERR_BAD_OS, N_("you need to load the kernel first"));
|
||||
|
||||
file = grub_file_open (args[0], GRUB_FILE_TYPE_XNU_RAMDISK);
|
||||
file = grub_file_open (args[0]);
|
||||
if (! file)
|
||||
return grub_errno;
|
||||
|
||||
@@ -934,7 +925,7 @@ grub_xnu_check_os_bundle_required (char *plistname,
|
||||
if (binname)
|
||||
*binname = 0;
|
||||
|
||||
file = grub_file_open (plistname, GRUB_FILE_TYPE_XNU_INFO_PLIST);
|
||||
file = grub_file_open (plistname);
|
||||
if (! file)
|
||||
return 0;
|
||||
|
||||
@@ -1219,7 +1210,7 @@ grub_xnu_load_kext_from_dir (char *dirname, const char *osbundlerequired,
|
||||
grub_strcpy (binname + grub_strlen (binname), "/");
|
||||
grub_strcpy (binname + grub_strlen (binname), binsuffix);
|
||||
grub_dprintf ("xnu", "%s:%s\n", ctx.plistname, binname);
|
||||
binfile = grub_file_open (binname, GRUB_FILE_TYPE_XNU_KEXT);
|
||||
binfile = grub_file_open (binname);
|
||||
if (! binfile)
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
|
||||
@@ -1262,7 +1253,7 @@ grub_cmd_xnu_kext (grub_command_t cmd __attribute__ ((unused)),
|
||||
/* User explicitly specified plist and binary. */
|
||||
if (grub_strcmp (args[1], "-") != 0)
|
||||
{
|
||||
binfile = grub_file_open (args[1], GRUB_FILE_TYPE_XNU_KEXT);
|
||||
binfile = grub_file_open (args[1]);
|
||||
if (! binfile)
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
@@ -53,8 +53,8 @@ grub_xnu_resume (char *imagename)
|
||||
grub_addr_t target_image;
|
||||
grub_err_t err;
|
||||
|
||||
file = grub_file_open (imagename, GRUB_FILE_TYPE_XNU_HIBERNATE_IMAGE
|
||||
| GRUB_FILE_TYPE_NO_DECOMPRESS);
|
||||
grub_file_filter_disable_compression ();
|
||||
file = grub_file_open (imagename);
|
||||
if (! file)
|
||||
return 0;
|
||||
|
||||
|
||||
@@ -33,6 +33,12 @@ autoload_fs_module (void)
|
||||
{
|
||||
grub_named_list_t p;
|
||||
int ret = 0;
|
||||
grub_file_filter_t grub_file_filters_was[GRUB_FILE_FILTER_MAX];
|
||||
|
||||
grub_memcpy (grub_file_filters_was, grub_file_filters_enabled,
|
||||
sizeof (grub_file_filters_enabled));
|
||||
grub_memcpy (grub_file_filters_enabled, grub_file_filters_all,
|
||||
sizeof (grub_file_filters_enabled));
|
||||
|
||||
while ((p = fs_module_list) != NULL)
|
||||
{
|
||||
@@ -50,6 +56,9 @@ autoload_fs_module (void)
|
||||
grub_free (p);
|
||||
}
|
||||
|
||||
grub_memcpy (grub_file_filters_enabled, grub_file_filters_was,
|
||||
sizeof (grub_file_filters_enabled));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -73,7 +82,7 @@ read_fs_list (const char *prefix)
|
||||
tmp_autoload_hook = grub_fs_autoload_hook;
|
||||
grub_fs_autoload_hook = NULL;
|
||||
|
||||
file = grub_file_open (filename, GRUB_FILE_TYPE_GRUB_MODULE_LIST);
|
||||
file = grub_file_open (filename);
|
||||
if (file)
|
||||
{
|
||||
/* Override previous fs.lst. */
|
||||
|
||||
@@ -94,7 +94,7 @@ read_crypto_list (const char *prefix)
|
||||
return;
|
||||
}
|
||||
|
||||
file = grub_file_open (filename, GRUB_FILE_TYPE_GRUB_MODULE_LIST);
|
||||
file = grub_file_open (filename);
|
||||
grub_free (filename);
|
||||
if (!file)
|
||||
{
|
||||
|
||||
@@ -106,7 +106,7 @@ read_command_list (const char *prefix)
|
||||
{
|
||||
grub_file_t file;
|
||||
|
||||
file = grub_file_open (filename, GRUB_FILE_TYPE_GRUB_MODULE_LIST);
|
||||
file = grub_file_open (filename);
|
||||
if (file)
|
||||
{
|
||||
char *buf = NULL;
|
||||
|
||||
@@ -123,7 +123,7 @@ read_config_file (const char *config)
|
||||
}
|
||||
|
||||
/* Try to open the config file. */
|
||||
rawfile = grub_file_open (config, GRUB_FILE_TYPE_CONFIG);
|
||||
rawfile = grub_file_open (config);
|
||||
if (! rawfile)
|
||||
return 0;
|
||||
|
||||
|
||||
@@ -331,7 +331,7 @@ read_terminal_list (const char *prefix)
|
||||
return;
|
||||
}
|
||||
|
||||
file = grub_file_open (filename, GRUB_FILE_TYPE_GRUB_MODULE_LIST);
|
||||
file = grub_file_open (filename);
|
||||
grub_free (filename);
|
||||
if (!file)
|
||||
{
|
||||
|
||||
@@ -34,8 +34,6 @@ struct grub_ps2_state ps2_state;
|
||||
|
||||
struct grub_cros_ec_keyscan old_scan;
|
||||
|
||||
static const struct grub_fdtbus_dev *cros_ec;
|
||||
|
||||
static grub_uint8_t map_code[GRUB_CROS_EC_KEYSCAN_COLS][GRUB_CROS_EC_KEYSCAN_ROWS];
|
||||
|
||||
static grub_uint8_t e0_translate[16] =
|
||||
@@ -53,8 +51,8 @@ grub_cros_keyboard_getkey (struct grub_term_input *term __attribute__ ((unused))
|
||||
{
|
||||
struct grub_cros_ec_keyscan scan;
|
||||
int i, j;
|
||||
if (grub_cros_ec_scan_keyboard (cros_ec, &scan) < 0)
|
||||
return GRUB_TERM_NO_KEY;
|
||||
if (grub_cros_ec_scan_keyboard(&scan) < 0)
|
||||
return GRUB_TERM_NO_KEY;
|
||||
for (i = 0; i < GRUB_CROS_EC_KEYSCAN_COLS; i++)
|
||||
if (scan.data[i] ^ old_scan.data[i])
|
||||
for (j = 0; j < GRUB_CROS_EC_KEYSCAN_ROWS; j++)
|
||||
@@ -89,14 +87,11 @@ static struct grub_term_input grub_cros_keyboard_term =
|
||||
};
|
||||
|
||||
static grub_err_t
|
||||
cros_attach (const struct grub_fdtbus_dev *dev)
|
||||
cros_attach(const struct grub_fdtbus_dev *dev __attribute__ ((unused)))
|
||||
{
|
||||
grub_size_t keymap_size, i;
|
||||
const grub_uint8_t *keymap = grub_fdtbus_get_prop (dev, "linux,keymap", &keymap_size);
|
||||
|
||||
if (!dev->parent || !grub_cros_ec_validate (dev->parent))
|
||||
return GRUB_ERR_IO;
|
||||
|
||||
if (keymap)
|
||||
{
|
||||
for (i = 0; i + 3 < keymap_size; i += 4)
|
||||
@@ -105,14 +100,13 @@ cros_attach (const struct grub_fdtbus_dev *dev)
|
||||
map_code[keymap[i+1]][keymap[i]] = keymap[i+3];
|
||||
}
|
||||
|
||||
cros_ec = dev->parent;
|
||||
ps2_state.current_set = 1;
|
||||
ps2_state.at_keyboard_status = 0;
|
||||
grub_term_register_input ("cros_keyboard", &grub_cros_keyboard_term);
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
static struct grub_fdtbus_driver cros =
|
||||
struct grub_fdtbus_driver cros =
|
||||
{
|
||||
.compatible = "google,cros-ec-keyb",
|
||||
.attach = cros_attach
|
||||
|
||||
@@ -24,41 +24,110 @@
|
||||
#include <grub/time.h>
|
||||
#include <grub/misc.h>
|
||||
#include <grub/arm/cros_ec.h>
|
||||
#include <grub/fdtbus.h>
|
||||
|
||||
static const grub_uint64_t FRAMING_TIMEOUT_MS = 300;
|
||||
static grub_uint64_t
|
||||
grub_get_time_us (void)
|
||||
{
|
||||
return 1000 * grub_get_time_ms ();
|
||||
}
|
||||
|
||||
static const grub_uint8_t EC_FRAMING_BYTE = 0xec;
|
||||
static void
|
||||
grub_microsleep (grub_uint64_t len)
|
||||
{
|
||||
grub_uint64_t end_time = grub_get_time_us () + len;
|
||||
while (grub_get_time_us () < end_time)
|
||||
grub_cpu_idle ();
|
||||
}
|
||||
|
||||
volatile grub_uint32_t *spi = (volatile grub_uint32_t *) 0xff110000;
|
||||
|
||||
static int
|
||||
spi_send (const void *data, grub_size_t sz)
|
||||
{
|
||||
const grub_uint8_t *ptr = data, *end = ptr + sz;
|
||||
spi[2] = 0;
|
||||
spi[1] = sz - 1;
|
||||
spi[0] = ((1 << 18) | spi[0]) & ~(1 << 19);
|
||||
spi[2] = 1;
|
||||
while (ptr < end)
|
||||
{
|
||||
while (spi[9] & 2);
|
||||
spi[256] = *ptr++;
|
||||
}
|
||||
while (spi[9] & 1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
spi_read (void *data, grub_size_t sz)
|
||||
{
|
||||
grub_uint8_t *ptr = data, *end = ptr + sz;
|
||||
spi[2] = 0;
|
||||
spi[1] = sz - 1;
|
||||
spi[0] = ((1 << 19) | spi[0]) & ~(1 << 18);
|
||||
spi[2] = 1;
|
||||
while (ptr < end)
|
||||
{
|
||||
while (spi[9] & 8);
|
||||
*ptr++ = spi[512];
|
||||
}
|
||||
while (spi[9] & 1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
spi_start (void)
|
||||
{
|
||||
spi[3] = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
spi_stop (void)
|
||||
{
|
||||
spi[3] = 0;
|
||||
}
|
||||
|
||||
#define uint8_t grub_uint8_t
|
||||
#define uint16_t grub_uint16_t
|
||||
#define uint32_t grub_uint32_t
|
||||
#define uint64_t grub_uint64_t
|
||||
#define mdelay grub_millisleep
|
||||
#define memcpy grub_memcpy
|
||||
|
||||
static const uint64_t FramingTimeoutUs = 300 * 1000;
|
||||
|
||||
static const uint8_t EcFramingByte = 0xec;
|
||||
|
||||
#define EC_CMD_MKBP_STATE 0x60
|
||||
#define EC_CMD_VERSION0 0xdc
|
||||
|
||||
static grub_uint64_t last_transfer;
|
||||
static uint64_t last_transfer;
|
||||
|
||||
static void
|
||||
stop_bus (const struct grub_fdtbus_dev *spi)
|
||||
stop_bus (void)
|
||||
{
|
||||
spi->driver->stop (spi);
|
||||
last_transfer = grub_get_time_ms ();
|
||||
spi_stop ();
|
||||
last_transfer = grub_get_time_us ();
|
||||
}
|
||||
|
||||
static int
|
||||
wait_for_frame (const struct grub_fdtbus_dev *spi)
|
||||
wait_for_frame (void)
|
||||
{
|
||||
grub_uint64_t start = grub_get_time_ms ();
|
||||
grub_uint8_t byte;
|
||||
uint64_t start = grub_get_time_us ();
|
||||
uint8_t byte;
|
||||
do
|
||||
{
|
||||
if (spi->driver->receive (spi, &byte, 1))
|
||||
if (spi_read (&byte, 1))
|
||||
return -1;
|
||||
if (byte != EC_FRAMING_BYTE &&
|
||||
grub_get_time_ms () - start > FRAMING_TIMEOUT_MS)
|
||||
if (byte != EcFramingByte &&
|
||||
grub_get_time_us () - start > FramingTimeoutUs)
|
||||
{
|
||||
grub_dprintf ("cros", "Timeout waiting for framing byte.\n");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
while (byte != EC_FRAMING_BYTE);
|
||||
while (byte != EcFramingByte);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -69,11 +138,11 @@ wait_for_frame (const struct grub_fdtbus_dev *spi)
|
||||
* @param size Size of data block in bytes
|
||||
* @return checksum value (0 to 255)
|
||||
*/
|
||||
static grub_uint8_t
|
||||
static uint8_t
|
||||
cros_ec_calc_checksum (const void *data, int size)
|
||||
{
|
||||
grub_uint8_t csum;
|
||||
const grub_uint8_t *bytes = data;
|
||||
uint8_t csum;
|
||||
const uint8_t *bytes = data;
|
||||
int i;
|
||||
|
||||
for (i = csum = 0; i < size; i++)
|
||||
@@ -93,15 +162,14 @@ static grub_uint8_t busbuf[256];
|
||||
#define MSG_BYTES ((int)sizeof (busbuf))
|
||||
|
||||
static int
|
||||
ec_command (const struct grub_fdtbus_dev *dev, int cmd, int cmd_version,
|
||||
ec_command (int cmd, int cmd_version,
|
||||
const void *dout, int dout_len, void *din, int din_len)
|
||||
{
|
||||
const struct grub_fdtbus_dev *spi = dev->parent;
|
||||
grub_uint8_t *bytes;
|
||||
uint8_t *bytes;
|
||||
|
||||
/* Header + data + checksum. */
|
||||
grub_uint32_t out_bytes = CROS_EC_SPI_OUT_HDR_SIZE + dout_len + 1;
|
||||
grub_uint32_t in_bytes = CROS_EC_SPI_IN_HDR_SIZE + din_len + 1;
|
||||
uint32_t out_bytes = CROS_EC_SPI_OUT_HDR_SIZE + dout_len + 1;
|
||||
uint32_t in_bytes = CROS_EC_SPI_IN_HDR_SIZE + din_len + 1;
|
||||
|
||||
/*
|
||||
* Sanity-check I/O sizes given transaction overhead in internal
|
||||
@@ -123,65 +191,62 @@ ec_command (const struct grub_fdtbus_dev *dev, int cmd, int cmd_version,
|
||||
*bytes++ = EC_CMD_VERSION0 + cmd_version;
|
||||
*bytes++ = cmd;
|
||||
*bytes++ = dout_len;
|
||||
grub_memcpy (bytes, dout, dout_len);
|
||||
memcpy (bytes, dout, dout_len);
|
||||
bytes += dout_len;
|
||||
|
||||
*bytes++ = cros_ec_calc_checksum (busbuf,
|
||||
CROS_EC_SPI_OUT_HDR_SIZE + dout_len);
|
||||
|
||||
/* Depthcharge uses 200 us here but GRUB timer resolution is only 1ms,
|
||||
decrease this when we increase timer resolution. */
|
||||
while (grub_get_time_ms () - last_transfer < 1)
|
||||
while (grub_get_time_us () - last_transfer < 200)
|
||||
;
|
||||
|
||||
if (spi->driver->start (spi))
|
||||
if (spi_start ())
|
||||
return -1;
|
||||
|
||||
/* Allow EC to ramp up clock after being awoken. */
|
||||
/* Depthcharge only waits 100 us here but GRUB timer resolution is only 1ms,
|
||||
decrease this when we increase timer resolution. */
|
||||
grub_millisleep (1);
|
||||
/* See chrome-os-partner:32223 for more details. */
|
||||
grub_microsleep (100);
|
||||
|
||||
if (spi->driver->send (spi, busbuf, out_bytes))
|
||||
if (spi_send (busbuf, out_bytes))
|
||||
{
|
||||
stop_bus (spi);
|
||||
stop_bus ();
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Wait until the EC is ready. */
|
||||
if (wait_for_frame (spi))
|
||||
if (wait_for_frame ())
|
||||
{
|
||||
stop_bus (spi);
|
||||
stop_bus ();
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Read the response code and the data length. */
|
||||
bytes = busbuf;
|
||||
if (spi->driver->receive (spi, bytes, 2))
|
||||
if (spi_read (bytes, 2))
|
||||
{
|
||||
stop_bus (spi);
|
||||
stop_bus ();
|
||||
return -1;
|
||||
}
|
||||
grub_uint8_t result = *bytes++;
|
||||
grub_uint8_t length = *bytes++;
|
||||
uint8_t result = *bytes++;
|
||||
uint8_t length = *bytes++;
|
||||
|
||||
/* Make sure there's enough room for the data. */
|
||||
if (CROS_EC_SPI_IN_HDR_SIZE + length + 1 > MSG_BYTES)
|
||||
{
|
||||
grub_dprintf ("cros", "Received length %#02x too large\n", length);
|
||||
stop_bus (spi);
|
||||
stop_bus ();
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Read the data and the checksum, and finish up. */
|
||||
if (spi->driver->receive (spi, bytes, length + 1))
|
||||
if (spi_read (bytes, length + 1))
|
||||
{
|
||||
stop_bus (spi);
|
||||
stop_bus ();
|
||||
return -1;
|
||||
}
|
||||
bytes += length;
|
||||
int expected = *bytes++;
|
||||
stop_bus (spi);
|
||||
stop_bus ();
|
||||
|
||||
/* Check the integrity of the response. */
|
||||
if (result != 0)
|
||||
@@ -205,34 +270,18 @@ ec_command (const struct grub_fdtbus_dev *dev, int cmd, int cmd_version,
|
||||
din_len = length;
|
||||
if (din)
|
||||
{
|
||||
grub_memcpy (din, (grub_uint8_t *) busbuf + CROS_EC_SPI_IN_HDR_SIZE, din_len);
|
||||
memcpy (din, (uint8_t *) busbuf + CROS_EC_SPI_IN_HDR_SIZE, din_len);
|
||||
}
|
||||
|
||||
return din_len;
|
||||
}
|
||||
|
||||
int
|
||||
grub_cros_ec_scan_keyboard (const struct grub_fdtbus_dev *dev, struct grub_cros_ec_keyscan *scan)
|
||||
grub_cros_ec_scan_keyboard (struct grub_cros_ec_keyscan *scan)
|
||||
{
|
||||
if (ec_command (dev, EC_CMD_MKBP_STATE, 0, NULL, 0, scan,
|
||||
if (ec_command (EC_CMD_MKBP_STATE, 0, NULL, 0, scan,
|
||||
sizeof (*scan)) < (int) sizeof (*scan))
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
grub_cros_ec_validate (const struct grub_fdtbus_dev *dev)
|
||||
{
|
||||
if (!grub_fdtbus_is_compatible("google,cros-ec-spi", dev))
|
||||
return 0;
|
||||
if (!dev->parent)
|
||||
return 0;
|
||||
if (!dev->parent->driver)
|
||||
return 0;
|
||||
if (!dev->parent->driver->send
|
||||
|| !dev->parent->driver->receive)
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -40,8 +40,6 @@ grub_keyboard_controller_init (void);
|
||||
static void
|
||||
keyboard_controller_wait_until_ready (void)
|
||||
{
|
||||
/* 50 us would be enough but our current time resolution is 1ms. */
|
||||
grub_millisleep (1);
|
||||
while (! KEYBOARD_COMMAND_ISREADY (grub_inb (KEYBOARD_REG_STATUS)));
|
||||
}
|
||||
|
||||
@@ -52,11 +50,10 @@ wait_ack (void)
|
||||
grub_uint8_t ack;
|
||||
|
||||
endtime = grub_get_time_ms () + 20;
|
||||
do {
|
||||
keyboard_controller_wait_until_ready ();
|
||||
do
|
||||
ack = grub_inb (KEYBOARD_REG_DATA);
|
||||
} while (ack != GRUB_AT_ACK && ack != GRUB_AT_NACK
|
||||
&& grub_get_time_ms () < endtime);
|
||||
while (ack != GRUB_AT_ACK && ack != GRUB_AT_NACK
|
||||
&& grub_get_time_ms () < endtime);
|
||||
return ack;
|
||||
}
|
||||
|
||||
@@ -138,10 +135,12 @@ query_mode (void)
|
||||
if (!e)
|
||||
return 0;
|
||||
|
||||
do {
|
||||
keyboard_controller_wait_until_ready ();
|
||||
keyboard_controller_wait_until_ready ();
|
||||
|
||||
do
|
||||
ret = grub_inb (KEYBOARD_REG_DATA);
|
||||
} while (ret == GRUB_AT_ACK);
|
||||
while (ret == GRUB_AT_ACK);
|
||||
|
||||
/* QEMU translates the set even in no-translate mode. */
|
||||
if (ret == 0x43 || ret == 1)
|
||||
return 1;
|
||||
@@ -170,11 +169,7 @@ set_scancodes (void)
|
||||
#else
|
||||
|
||||
grub_keyboard_controller_write (grub_keyboard_controller_orig
|
||||
& ~KEYBOARD_AT_TRANSLATE
|
||||
& ~KEYBOARD_AT_DISABLE);
|
||||
|
||||
keyboard_controller_wait_until_ready ();
|
||||
grub_outb (KEYBOARD_COMMAND_ENABLE, KEYBOARD_REG_DATA);
|
||||
& ~KEYBOARD_AT_TRANSLATE);
|
||||
|
||||
write_mode (2);
|
||||
ps2_state.current_set = query_mode ();
|
||||
|
||||
@@ -29,14 +29,11 @@
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
#define CURSOR_MASK ((1 << 28) - 1)
|
||||
#define OVERFLOW (1 << 31)
|
||||
|
||||
struct grub_linuxbios_cbmemc
|
||||
{
|
||||
grub_uint32_t size;
|
||||
grub_uint32_t cursor;
|
||||
char body[0];
|
||||
grub_uint32_t pointer;
|
||||
char data[0];
|
||||
};
|
||||
|
||||
static struct grub_linuxbios_cbmemc *cbmemc;
|
||||
@@ -44,20 +41,11 @@ static struct grub_linuxbios_cbmemc *cbmemc;
|
||||
static void
|
||||
put (struct grub_term_output *term __attribute__ ((unused)), const int c)
|
||||
{
|
||||
grub_uint32_t flags, cursor;
|
||||
if (!cbmemc)
|
||||
return;
|
||||
flags = cbmemc->cursor & ~CURSOR_MASK;
|
||||
cursor = cbmemc->cursor & CURSOR_MASK;
|
||||
if (cursor >= cbmemc->size)
|
||||
return;
|
||||
cbmemc->body[cursor++] = c;
|
||||
if (cursor >= cbmemc->size)
|
||||
{
|
||||
cursor = 0;
|
||||
flags |= OVERFLOW;
|
||||
}
|
||||
cbmemc->cursor = flags | cursor;
|
||||
if (cbmemc->pointer < cbmemc->size)
|
||||
cbmemc->data[cbmemc->pointer] = c;
|
||||
cbmemc->pointer++;
|
||||
}
|
||||
|
||||
struct grub_terminfo_output_state grub_cbmemc_terminfo_output =
|
||||
@@ -99,29 +87,21 @@ grub_cmd_cbmemc (struct grub_command *cmd __attribute__ ((unused)),
|
||||
int argc __attribute__ ((unused)),
|
||||
char *argv[] __attribute__ ((unused)))
|
||||
{
|
||||
grub_size_t size, cursor;
|
||||
struct grub_linuxbios_cbmemc *real_cbmemc;
|
||||
grub_size_t len;
|
||||
char *str;
|
||||
struct grub_linuxbios_cbmemc *cbmemc_saved;
|
||||
|
||||
if (!cbmemc)
|
||||
return grub_error (GRUB_ERR_IO, "no CBMEM console found");
|
||||
|
||||
real_cbmemc = cbmemc;
|
||||
len = cbmemc->pointer;
|
||||
if (len > cbmemc->size)
|
||||
len = cbmemc->size;
|
||||
str = cbmemc->data;
|
||||
cbmemc_saved = cbmemc;
|
||||
cbmemc = 0;
|
||||
cursor = real_cbmemc->cursor & CURSOR_MASK;
|
||||
if (!(real_cbmemc->cursor & OVERFLOW) && cursor < real_cbmemc->size)
|
||||
size = cursor;
|
||||
else
|
||||
size = real_cbmemc->size;
|
||||
if (real_cbmemc->cursor & OVERFLOW)
|
||||
{
|
||||
if (cursor > size)
|
||||
cursor = 0;
|
||||
grub_xnputs(real_cbmemc->body + cursor, size - cursor);
|
||||
grub_xnputs(real_cbmemc->body, cursor);
|
||||
}
|
||||
else
|
||||
grub_xnputs(real_cbmemc->body, size);
|
||||
cbmemc = real_cbmemc;
|
||||
grub_xnputs (str, len);
|
||||
cbmemc = cbmemc_saved;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -772,7 +772,7 @@ grub_video_reader_jpeg (struct grub_video_bitmap **bitmap,
|
||||
grub_file_t file;
|
||||
struct grub_jpeg_data *data;
|
||||
|
||||
file = grub_buffile_open (filename, GRUB_FILE_TYPE_PIXMAP, 0);
|
||||
file = grub_buffile_open (filename, 0);
|
||||
if (!file)
|
||||
return grub_errno;
|
||||
|
||||
|
||||
@@ -1086,7 +1086,7 @@ grub_video_reader_png (struct grub_video_bitmap **bitmap,
|
||||
grub_file_t file;
|
||||
struct grub_png_data *data;
|
||||
|
||||
file = grub_buffile_open (filename, GRUB_FILE_TYPE_PIXMAP, 0);
|
||||
file = grub_buffile_open (filename, 0);
|
||||
if (!file)
|
||||
return grub_errno;
|
||||
|
||||
|
||||
@@ -297,7 +297,7 @@ grub_video_reader_tga (struct grub_video_bitmap **bitmap,
|
||||
|
||||
grub_memset (&data, 0, sizeof (data));
|
||||
|
||||
data.file = grub_buffile_open (filename, GRUB_FILE_TYPE_PIXMAP, 0);
|
||||
data.file = grub_buffile_open (filename, 0);
|
||||
if (! data.file)
|
||||
return grub_errno;
|
||||
|
||||
|
||||
@@ -34,8 +34,8 @@ struct grub_fdt_board
|
||||
extern struct grub_fdt_board grub_fdt_boards[];
|
||||
void grub_machine_timer_init (void);
|
||||
void grub_pl050_init (void);
|
||||
void grub_cros_init (void);
|
||||
void grub_rk3288_spi_init (void);
|
||||
void
|
||||
grub_cros_init (void);
|
||||
extern grub_addr_t EXPORT_VAR (start_of_ram);
|
||||
#endif /* ! ASM_FILE */
|
||||
|
||||
|
||||
0
include/grub/arm/coreboot/memory.h
Normal file
0
include/grub/arm/coreboot/memory.h
Normal file
@@ -2,20 +2,15 @@
|
||||
#define GRUB_ARM_CROS_EC_H 1
|
||||
|
||||
#include <grub/types.h>
|
||||
#include <grub/fdtbus.h>
|
||||
|
||||
#define GRUB_CROS_EC_KEYSCAN_COLS 13
|
||||
#define GRUB_CROS_EC_KEYSCAN_ROWS 8
|
||||
|
||||
struct grub_cros_ec_keyscan {
|
||||
grub_uint8_t data[GRUB_CROS_EC_KEYSCAN_COLS];
|
||||
grub_uint8_t data[GRUB_CROS_EC_KEYSCAN_COLS];
|
||||
};
|
||||
|
||||
int
|
||||
grub_cros_ec_scan_keyboard (const struct grub_fdtbus_dev *dev,
|
||||
struct grub_cros_ec_keyscan *scan);
|
||||
|
||||
int
|
||||
grub_cros_ec_validate (const struct grub_fdtbus_dev *dev);
|
||||
grub_cros_ec_scan_keyboard(struct grub_cros_ec_keyscan *scan);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -23,11 +23,9 @@
|
||||
#define KEYBOARD_COMMAND_ISREADY(x) !((x) & 0x02)
|
||||
#define KEYBOARD_COMMAND_READ 0x20
|
||||
#define KEYBOARD_COMMAND_WRITE 0x60
|
||||
#define KEYBOARD_COMMAND_ENABLE 0xf4
|
||||
#define KEYBOARD_COMMAND_REBOOT 0xfe
|
||||
|
||||
#define KEYBOARD_AT_TRANSLATE 0x40
|
||||
#define KEYBOARD_AT_DISABLE 0x10
|
||||
|
||||
#define KEYBOARD_ISMAKE(x) !((x) & 0x80)
|
||||
#define KEYBOARD_ISREADY(x) ((x) & 0x01)
|
||||
|
||||
@@ -22,9 +22,7 @@
|
||||
|
||||
#include <grub/file.h>
|
||||
|
||||
grub_file_t EXPORT_FUNC (grub_bufio_open) (grub_file_t io, grub_size_t size);
|
||||
grub_file_t EXPORT_FUNC (grub_buffile_open) (const char *name,
|
||||
enum grub_file_type type,
|
||||
grub_size_t size);
|
||||
grub_file_t EXPORT_FUNC (grub_bufio_open) (grub_file_t io, int size);
|
||||
grub_file_t EXPORT_FUNC (grub_buffile_open) (const char *name, int size);
|
||||
|
||||
#endif /* ! GRUB_BUFIO_H */
|
||||
|
||||
@@ -71,7 +71,8 @@ enum
|
||||
GRUB_LINUXBIOS_MEMBER_LINK = 0x11,
|
||||
GRUB_LINUXBIOS_MEMBER_FRAMEBUFFER = 0x12,
|
||||
GRUB_LINUXBIOS_MEMBER_TIMESTAMPS = 0x16,
|
||||
GRUB_LINUXBIOS_MEMBER_CBMEMC = 0x17
|
||||
GRUB_LINUXBIOS_MEMBER_CBMEMC = 0x17,
|
||||
GRUB_LINUXBIOS_MEMBER_DTB = 0x33,
|
||||
};
|
||||
|
||||
struct grub_linuxbios_table_framebuffer {
|
||||
|
||||
@@ -42,7 +42,7 @@ typedef int (*grub_elf32_phdr_iterate_hook_t)
|
||||
typedef int (*grub_elf64_phdr_iterate_hook_t)
|
||||
(grub_elf_t elf, Elf64_Phdr *phdr, void *arg);
|
||||
|
||||
grub_elf_t grub_elf_open (const char *, enum grub_file_type type);
|
||||
grub_elf_t grub_elf_open (const char *);
|
||||
grub_elf_t grub_elf_file (grub_file_t file, const char *filename);
|
||||
grub_err_t grub_elf_close (grub_elf_t);
|
||||
|
||||
|
||||
@@ -22,13 +22,7 @@
|
||||
#include <grub/fdt.h>
|
||||
#include <grub/err.h>
|
||||
|
||||
struct grub_fdtbus_dev
|
||||
{
|
||||
struct grub_fdtbus_dev *next;
|
||||
struct grub_fdtbus_dev *parent;
|
||||
int node;
|
||||
struct grub_fdtbus_driver *driver;
|
||||
};
|
||||
struct grub_fdtbus_dev;
|
||||
|
||||
struct grub_fdtbus_driver
|
||||
{
|
||||
@@ -39,12 +33,6 @@ struct grub_fdtbus_driver
|
||||
|
||||
grub_err_t (*attach) (const struct grub_fdtbus_dev *dev);
|
||||
void (*detach) (const struct grub_fdtbus_dev *dev);
|
||||
|
||||
/* Message bus operations. */
|
||||
grub_err_t (*send) (const struct grub_fdtbus_dev *dev, const void *data, grub_size_t sz);
|
||||
grub_err_t (*receive) (const struct grub_fdtbus_dev *dev, void *data, grub_size_t sz);
|
||||
grub_err_t (*start) (const struct grub_fdtbus_dev *dev);
|
||||
void (*stop) (const struct grub_fdtbus_dev *dev);
|
||||
};
|
||||
|
||||
extern char EXPORT_VAR(grub_fdtbus_invalid_mapping)[1];
|
||||
@@ -75,10 +63,6 @@ EXPORT_FUNC(grub_fdtbus_register) (struct grub_fdtbus_driver *driver);
|
||||
void
|
||||
EXPORT_FUNC(grub_fdtbus_unregister) (struct grub_fdtbus_driver *driver);
|
||||
|
||||
int
|
||||
EXPORT_FUNC(grub_fdtbus_is_compatible) (const char *compat_string,
|
||||
const struct grub_fdtbus_dev *dev);
|
||||
|
||||
/* Must be called before any register(). */
|
||||
/* dtb is assumed to be unfreeable and must remain
|
||||
valid for lifetime of GRUB.
|
||||
|
||||
@@ -25,108 +25,6 @@
|
||||
#include <grub/fs.h>
|
||||
#include <grub/disk.h>
|
||||
|
||||
enum grub_file_type
|
||||
{
|
||||
/* GRUB module to be loaded. */
|
||||
GRUB_FILE_TYPE_GRUB_MODULE,
|
||||
/* Loopback file to be represented as disk. */
|
||||
GRUB_FILE_TYPE_LOOPBACK,
|
||||
/* Linux kernel to be loaded. */
|
||||
GRUB_FILE_TYPE_LINUX_KERNEL,
|
||||
/* Linux initrd. */
|
||||
GRUB_FILE_TYPE_LINUX_INITRD,
|
||||
|
||||
/* Multiboot kernel. */
|
||||
GRUB_FILE_TYPE_MULTIBOOT_KERNEL,
|
||||
/* Multiboot module. */
|
||||
GRUB_FILE_TYPE_MULTIBOOT_MODULE,
|
||||
|
||||
GRUB_FILE_TYPE_BSD_KERNEL,
|
||||
GRUB_FILE_TYPE_FREEBSD_ENV,
|
||||
GRUB_FILE_TYPE_FREEBSD_MODULE,
|
||||
GRUB_FILE_TYPE_FREEBSD_MODULE_ELF,
|
||||
GRUB_FILE_TYPE_NETBSD_MODULE,
|
||||
GRUB_FILE_TYPE_OPENBSD_RAMDISK,
|
||||
|
||||
GRUB_FILE_TYPE_XNU_INFO_PLIST,
|
||||
GRUB_FILE_TYPE_XNU_MKEXT,
|
||||
GRUB_FILE_TYPE_XNU_KEXT,
|
||||
GRUB_FILE_TYPE_XNU_KERNEL,
|
||||
GRUB_FILE_TYPE_XNU_RAMDISK,
|
||||
GRUB_FILE_TYPE_XNU_HIBERNATE_IMAGE,
|
||||
GRUB_FILE_XNU_DEVPROP,
|
||||
|
||||
GRUB_FILE_TYPE_PLAN9_KERNEL,
|
||||
|
||||
GRUB_FILE_TYPE_NTLDR,
|
||||
GRUB_FILE_TYPE_TRUECRYPT,
|
||||
GRUB_FILE_TYPE_FREEDOS,
|
||||
GRUB_FILE_TYPE_PXECHAINLOADER,
|
||||
GRUB_FILE_TYPE_PCCHAINLOADER,
|
||||
|
||||
GRUB_FILE_TYPE_COREBOOT_CHAINLOADER,
|
||||
|
||||
GRUB_FILE_TYPE_EFI_CHAINLOADED_IMAGE,
|
||||
|
||||
/* File holding signature. */
|
||||
GRUB_FILE_TYPE_SIGNATURE,
|
||||
/* File holding public key to verify signature once. */
|
||||
GRUB_FILE_TYPE_PUBLIC_KEY,
|
||||
/* File holding public key to add to trused keys. */
|
||||
GRUB_FILE_TYPE_PUBLIC_KEY_TRUST,
|
||||
/* File of which we intend to print a blocklist to the user. */
|
||||
GRUB_FILE_TYPE_PRINT_BLOCKLIST,
|
||||
/* File we intend to use for test loading or testing speed. */
|
||||
GRUB_FILE_TYPE_TESTLOAD,
|
||||
/* File we open only to get its size. E.g. in ls output. */
|
||||
GRUB_FILE_TYPE_GET_SIZE,
|
||||
/* Font file. */
|
||||
GRUB_FILE_TYPE_FONT,
|
||||
/* File holding encryption key for encrypted ZFS. */
|
||||
GRUB_FILE_TYPE_ZFS_ENCRYPTION_KEY,
|
||||
/* File we open n grub-fstest. */
|
||||
GRUB_FILE_TYPE_FSTEST,
|
||||
/* File we open n grub-mount. */
|
||||
GRUB_FILE_TYPE_MOUNT,
|
||||
/* File which we attempt to identify the type of. */
|
||||
GRUB_FILE_TYPE_FILE_ID,
|
||||
/* File holding ACPI table. */
|
||||
GRUB_FILE_TYPE_ACPI_TABLE,
|
||||
/* File we intend show to user. */
|
||||
GRUB_FILE_TYPE_CAT,
|
||||
GRUB_FILE_TYPE_HEXCAT,
|
||||
/* One of pair of files we intend to compare. */
|
||||
GRUB_FILE_TYPE_CMP,
|
||||
/* List of hashes for hashsum. */
|
||||
GRUB_FILE_TYPE_HASHLIST,
|
||||
/* File hashed by hashsum. */
|
||||
GRUB_FILE_TYPE_TO_HASH,
|
||||
/* Keyboard layout. */
|
||||
GRUB_FILE_TYPE_KEYBOARD_LAYOUT,
|
||||
/* Picture file. */
|
||||
GRUB_FILE_TYPE_PIXMAP,
|
||||
/* *.lst shipped by GRUB. */
|
||||
GRUB_FILE_TYPE_GRUB_MODULE_LIST,
|
||||
/* config file. */
|
||||
GRUB_FILE_TYPE_CONFIG,
|
||||
GRUB_FILE_TYPE_THEME,
|
||||
GRUB_FILE_TYPE_GETTEXT_CATALOG,
|
||||
GRUB_FILE_TYPE_FS_SEARCH,
|
||||
GRUB_FILE_TYPE_AUDIO,
|
||||
GRUB_FILE_TYPE_VBE_DUMP,
|
||||
|
||||
GRUB_FILE_TYPE_LOADENV,
|
||||
GRUB_FILE_TYPE_SAVEENV,
|
||||
|
||||
GRUB_FILE_TYPE_VERIFY_SIGNATURE,
|
||||
|
||||
GRUB_FILE_TYPE_MASK = 0xffff,
|
||||
|
||||
/* --skip-sig is specified. */
|
||||
GRUB_FILE_TYPE_SKIP_SIGNATURE = 0x10000,
|
||||
GRUB_FILE_TYPE_NO_DECOMPRESS = 0x20000,
|
||||
};
|
||||
|
||||
/* File description. */
|
||||
struct grub_file
|
||||
{
|
||||
@@ -170,7 +68,7 @@ extern grub_disk_read_hook_t EXPORT_VAR(grub_file_progress_hook);
|
||||
/* Filters with lower ID are executed first. */
|
||||
typedef enum grub_file_filter_id
|
||||
{
|
||||
GRUB_FILE_FILTER_VERIFY,
|
||||
GRUB_FILE_FILTER_PUBKEY,
|
||||
GRUB_FILE_FILTER_GZIO,
|
||||
GRUB_FILE_FILTER_XZIO,
|
||||
GRUB_FILE_FILTER_LZOPIO,
|
||||
@@ -179,26 +77,61 @@ typedef enum grub_file_filter_id
|
||||
GRUB_FILE_FILTER_COMPRESSION_LAST = GRUB_FILE_FILTER_LZOPIO,
|
||||
} grub_file_filter_id_t;
|
||||
|
||||
typedef grub_file_t (*grub_file_filter_t) (grub_file_t in, enum grub_file_type type);
|
||||
typedef grub_file_t (*grub_file_filter_t) (grub_file_t in, const char *filename);
|
||||
|
||||
extern grub_file_filter_t EXPORT_VAR(grub_file_filters)[GRUB_FILE_FILTER_MAX];
|
||||
extern grub_file_filter_t EXPORT_VAR(grub_file_filters_all)[GRUB_FILE_FILTER_MAX];
|
||||
extern grub_file_filter_t EXPORT_VAR(grub_file_filters_enabled)[GRUB_FILE_FILTER_MAX];
|
||||
|
||||
static inline void
|
||||
grub_file_filter_register (grub_file_filter_id_t id, grub_file_filter_t filter)
|
||||
{
|
||||
grub_file_filters[id] = filter;
|
||||
grub_file_filters_all[id] = filter;
|
||||
grub_file_filters_enabled[id] = filter;
|
||||
}
|
||||
|
||||
static inline void
|
||||
grub_file_filter_unregister (grub_file_filter_id_t id)
|
||||
{
|
||||
grub_file_filters[id] = 0;
|
||||
grub_file_filters_all[id] = 0;
|
||||
grub_file_filters_enabled[id] = 0;
|
||||
}
|
||||
|
||||
static inline void
|
||||
grub_file_filter_disable (grub_file_filter_id_t id)
|
||||
{
|
||||
grub_file_filters_enabled[id] = 0;
|
||||
}
|
||||
|
||||
static inline void
|
||||
grub_file_filter_disable_compression (void)
|
||||
{
|
||||
grub_file_filter_id_t id;
|
||||
|
||||
for (id = GRUB_FILE_FILTER_COMPRESSION_FIRST;
|
||||
id <= GRUB_FILE_FILTER_COMPRESSION_LAST; id++)
|
||||
grub_file_filters_enabled[id] = 0;
|
||||
}
|
||||
|
||||
static inline void
|
||||
grub_file_filter_disable_all (void)
|
||||
{
|
||||
grub_file_filter_id_t id;
|
||||
|
||||
for (id = 0;
|
||||
id < GRUB_FILE_FILTER_MAX; id++)
|
||||
grub_file_filters_enabled[id] = 0;
|
||||
}
|
||||
|
||||
static inline void
|
||||
grub_file_filter_disable_pubkey (void)
|
||||
{
|
||||
grub_file_filters_enabled[GRUB_FILE_FILTER_PUBKEY] = 0;
|
||||
}
|
||||
|
||||
/* Get a device name from NAME. */
|
||||
char *EXPORT_FUNC(grub_file_get_device_name) (const char *name);
|
||||
|
||||
grub_file_t EXPORT_FUNC(grub_file_open) (const char *name, enum grub_file_type type);
|
||||
grub_file_t EXPORT_FUNC(grub_file_open) (const char *name);
|
||||
grub_ssize_t EXPORT_FUNC(grub_file_read) (grub_file_t file, void *buf,
|
||||
grub_size_t len);
|
||||
grub_off_t EXPORT_FUNC(grub_file_seek) (grub_file_t file, grub_off_t offset);
|
||||
@@ -226,8 +159,8 @@ grub_file_seekable (const grub_file_t file)
|
||||
}
|
||||
|
||||
grub_file_t
|
||||
grub_file_offset_open (grub_file_t parent, enum grub_file_type type,
|
||||
grub_off_t start, grub_off_t size);
|
||||
grub_file_offset_open (grub_file_t parent, grub_off_t start,
|
||||
grub_off_t size);
|
||||
void
|
||||
grub_file_offset_close (grub_file_t file);
|
||||
|
||||
|
||||
@@ -21,12 +21,11 @@
|
||||
#define GRUB_CMDLINE_HEADER 1
|
||||
|
||||
#include <grub/types.h>
|
||||
#include <grub/verify.h>
|
||||
|
||||
#define LINUX_IMAGE "BOOT_IMAGE="
|
||||
|
||||
unsigned int grub_loader_cmdline_size (int argc, char *argv[]);
|
||||
grub_err_t grub_create_loader_cmdline (int argc, char *argv[], char *buf,
|
||||
grub_size_t size, enum grub_verify_string_type type);
|
||||
int grub_create_loader_cmdline (int argc, char *argv[], char *buf,
|
||||
grub_size_t size);
|
||||
|
||||
#endif /* ! GRUB_CMDLINE_HEADER */
|
||||
|
||||
@@ -35,7 +35,6 @@ void EXPORT_FUNC(grub_list_push) (grub_list_t *head, grub_list_t item);
|
||||
void EXPORT_FUNC(grub_list_remove) (grub_list_t item);
|
||||
|
||||
#define FOR_LIST_ELEMENTS(var, list) for ((var) = (list); (var); (var) = (var)->next)
|
||||
#define FOR_LIST_ELEMENTS_NEXT(var, list) for ((var) = (var)->next; (var); (var) = (var)->next)
|
||||
#define FOR_LIST_ELEMENTS_SAFE(var, nxt, list) for ((var) = (list), (nxt) = ((var) ? (var)->next : 0); (var); (var) = (nxt), ((nxt) = (var) ? (var)->next : 0))
|
||||
|
||||
static inline void *
|
||||
|
||||
@@ -49,8 +49,7 @@ struct grub_macho_file
|
||||
};
|
||||
typedef struct grub_macho_file *grub_macho_t;
|
||||
|
||||
grub_macho_t grub_macho_open (const char *, enum grub_file_type type,
|
||||
int is_64bit);
|
||||
grub_macho_t grub_macho_open (const char *, int is_64bit);
|
||||
grub_macho_t grub_macho_file (grub_file_t file, const char *filename,
|
||||
int is_64bit);
|
||||
grub_err_t grub_macho_close (grub_macho_t);
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
#include <grub/file.h>
|
||||
#include <grub/list.h>
|
||||
|
||||
enum grub_verify_flags
|
||||
{
|
||||
GRUB_VERIFY_FLAGS_SKIP_VERIFICATION = 1,
|
||||
GRUB_VERIFY_FLAGS_SINGLE_CHUNK = 2,
|
||||
};
|
||||
|
||||
enum grub_verify_string_type
|
||||
{
|
||||
GRUB_VERIFY_KERNEL_CMDLINE,
|
||||
GRUB_VERIFY_MODULE_CMDLINE,
|
||||
};
|
||||
|
||||
struct grub_file_verifier
|
||||
{
|
||||
struct grub_file_verifier *next;
|
||||
struct grub_file_verifier **prev;
|
||||
|
||||
const char *name;
|
||||
|
||||
/* Check if file needs to be verified and set up context. */
|
||||
/* init/read/fini is structured in the same way as hash interface. */
|
||||
grub_err_t (*init) (grub_file_t io, enum grub_file_type type,
|
||||
void **context, enum grub_verify_flags *verify_flags);
|
||||
/* Right now we pass the whole file in one call but it
|
||||
will change in the future. If you insist on single buffer we can
|
||||
you need to set GRUB_VERIFY_FLAGS_SINGLE_CHUNK in verify_flags.
|
||||
*/
|
||||
grub_err_t (*write) (void *context, void *buf, grub_size_t sz);
|
||||
grub_err_t (*fini) (void *context);
|
||||
void (*close) (void *context);
|
||||
|
||||
grub_err_t (*verify_string) (char *str, enum grub_verify_string_type type);
|
||||
};
|
||||
|
||||
extern struct grub_file_verifier *grub_file_verifiers;
|
||||
|
||||
static inline void
|
||||
grub_verifier_register (struct grub_file_verifier *ver)
|
||||
{
|
||||
grub_list_push (GRUB_AS_LIST_P (&grub_file_verifiers), GRUB_AS_LIST (ver));
|
||||
}
|
||||
|
||||
static inline void
|
||||
grub_verifier_unregister (struct grub_file_verifier *ver)
|
||||
{
|
||||
grub_list_remove (GRUB_AS_LIST (ver));
|
||||
}
|
||||
|
||||
grub_err_t
|
||||
grub_verify_string (char *str, enum grub_verify_string_type type);
|
||||
@@ -120,9 +120,9 @@ read_file (char *pathname, int (*hook) (grub_off_t ofs, char *buf, int len, void
|
||||
return;
|
||||
}
|
||||
|
||||
file = grub_file_open (pathname, ((uncompress == 0)
|
||||
? GRUB_FILE_TYPE_NO_DECOMPRESS : 0)
|
||||
| GRUB_FILE_TYPE_FSTEST);
|
||||
if (uncompress == 0)
|
||||
grub_file_filter_disable_compression ();
|
||||
file = grub_file_open (pathname);
|
||||
if (!file)
|
||||
{
|
||||
grub_util_error (_("cannot open `%s': %s"), pathname,
|
||||
|
||||
@@ -214,6 +214,14 @@ SUFFIX (grub_mkimage_generate_elf) (const struct grub_install_image_target_desc
|
||||
string_size += sizeof (".xen");
|
||||
footer_size += XEN_NOTE_SIZE;
|
||||
}
|
||||
if (image_target->id == IMAGE_COREBOOT && image_target->elf_target == EM_ARM
|
||||
&& image_target->link_addr == 0)
|
||||
{
|
||||
phnum++;
|
||||
shnum++;
|
||||
string_size += sizeof (".coreboot_flags");
|
||||
footer_size += COREBOOT_NOTE_SIZE;
|
||||
}
|
||||
header_size = ALIGN_UP (sizeof (*ehdr) + phnum * sizeof (*phdr)
|
||||
+ shnum * sizeof (*shdr) + string_size, layout->align);
|
||||
|
||||
@@ -309,6 +317,40 @@ SUFFIX (grub_mkimage_generate_elf) (const struct grub_install_image_target_desc
|
||||
phdr->p_align = grub_host_to_target32 (image_target->link_align);
|
||||
}
|
||||
|
||||
if (image_target->id == IMAGE_COREBOOT && image_target->elf_target == EM_ARM
|
||||
&& image_target->link_addr == 0)
|
||||
{
|
||||
char *note_start = (elf_img + program_size + header_size);
|
||||
Elf_Nhdr *note_ptr;
|
||||
char *ptr = (char *) note_start;
|
||||
|
||||
grub_util_info ("adding coreboot NOTE segment");
|
||||
|
||||
note_ptr = (Elf_Nhdr *) ptr;
|
||||
note_ptr->n_namesz = grub_host_to_target32 (sizeof (GRUB_COREBOOT_NOTE_NAME));
|
||||
note_ptr->n_descsz = grub_host_to_target32 (8);
|
||||
note_ptr->n_type = grub_host_to_target32 (0);
|
||||
ptr += sizeof (Elf_Nhdr);
|
||||
memcpy (ptr, GRUB_COREBOOT_NOTE_NAME, sizeof (GRUB_COREBOOT_NOTE_NAME));
|
||||
ptr += ALIGN_UP (sizeof (GRUB_COREBOOT_NOTE_NAME), 4);
|
||||
((grub_uint32_t *) ptr)[0] = grub_host_to_target32 (is_relocatable (image_target));
|
||||
((grub_uint32_t *) ptr)[1] = 0;
|
||||
((grub_uint32_t *) ptr)[2] = grub_host_to_target32 (layout->align);
|
||||
ptr += 12;
|
||||
|
||||
assert (COREBOOT_NOTE_SIZE == (ptr - note_start));
|
||||
|
||||
phdr++;
|
||||
phdr->p_type = grub_host_to_target32 (PT_NOTE);
|
||||
phdr->p_flags = grub_host_to_target32 (PF_R);
|
||||
phdr->p_align = grub_host_to_target32 (image_target->voidp_sizeof);
|
||||
phdr->p_vaddr = 0;
|
||||
phdr->p_paddr = 0;
|
||||
phdr->p_filesz = grub_host_to_target32 (COREBOOT_NOTE_SIZE);
|
||||
phdr->p_memsz = 0;
|
||||
phdr->p_offset = grub_host_to_target32 (header_size + program_size);
|
||||
}
|
||||
|
||||
if (image_target->id == IMAGE_XEN)
|
||||
{
|
||||
char *note_start = (elf_img + program_size + header_size);
|
||||
@@ -489,6 +531,26 @@ SUFFIX (grub_mkimage_generate_elf) (const struct grub_install_image_target_desc
|
||||
shdr->sh_entsize = grub_host_to_target32 (0);
|
||||
shdr++;
|
||||
}
|
||||
if (image_target->id == IMAGE_COREBOOT && image_target->elf_target == EM_ARM
|
||||
&& image_target->link_addr == 0)
|
||||
{
|
||||
memcpy (ptr, ".coreboot_flags", sizeof (".coreboot_flags"));
|
||||
shdr->sh_name = grub_host_to_target32 (ptr - str_start);
|
||||
ptr += sizeof (".coreboot_flags");
|
||||
shdr->sh_type = grub_host_to_target32 (SHT_PROGBITS);
|
||||
shdr->sh_addr = grub_host_to_target_addr (target_addr + layout->kernel_size);
|
||||
shdr->sh_offset = grub_host_to_target_addr (program_size + header_size
|
||||
+ sizeof (Elf_Nhdr)
|
||||
+ ALIGN_UP (sizeof (GRUB_COREBOOT_NOTE_NAME), 4));
|
||||
shdr->sh_size = grub_host_to_target32 (COREBOOT_NOTE_SIZE
|
||||
- sizeof (Elf_Nhdr)
|
||||
- ALIGN_UP (sizeof (GRUB_COREBOOT_NOTE_NAME), 4));
|
||||
shdr->sh_link = grub_host_to_target32 (0);
|
||||
shdr->sh_info = grub_host_to_target32 (0);
|
||||
shdr->sh_addralign = grub_host_to_target32 (image_target->voidp_sizeof);
|
||||
shdr->sh_entsize = grub_host_to_target32 (0);
|
||||
shdr++;
|
||||
}
|
||||
}
|
||||
|
||||
free (*core_img);
|
||||
|
||||
@@ -208,7 +208,7 @@ fuse_getattr (const char *path, struct stat *st)
|
||||
if (!ctx.file_info.dir)
|
||||
{
|
||||
grub_file_t file;
|
||||
file = grub_file_open (path, GRUB_FILE_TYPE_GET_SIZE);
|
||||
file = grub_file_open (path);
|
||||
if (! file && grub_errno == GRUB_ERR_BAD_FILE_TYPE)
|
||||
{
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
@@ -244,7 +244,7 @@ static int
|
||||
fuse_open (const char *path, struct fuse_file_info *fi __attribute__ ((unused)))
|
||||
{
|
||||
grub_file_t file;
|
||||
file = grub_file_open (path, GRUB_FILE_TYPE_MOUNT);
|
||||
file = grub_file_open (path);
|
||||
if (! file)
|
||||
return translate_error ();
|
||||
files[first_fd++] = file;
|
||||
@@ -308,7 +308,7 @@ fuse_readdir_call_fill (const char *filename,
|
||||
grub_file_t file;
|
||||
char *tmp;
|
||||
tmp = xasprintf ("%s/%s", ctx->path, filename);
|
||||
file = grub_file_open (tmp, GRUB_FILE_TYPE_GET_SIZE);
|
||||
file = grub_file_open (tmp);
|
||||
free (tmp);
|
||||
/* Symlink to directory. */
|
||||
if (! file && grub_errno == GRUB_ERR_BAD_FILE_TYPE)
|
||||
|
||||
@@ -533,6 +533,24 @@ static const struct grub_install_image_target_desc image_targets[] =
|
||||
.mod_align = GRUB_KERNEL_ARM_UBOOT_MOD_ALIGN,
|
||||
.link_align = 4
|
||||
},
|
||||
{
|
||||
.dirname = "arm-coreboot",
|
||||
.names = { "arm-coreboot", NULL },
|
||||
.voidp_sizeof = 4,
|
||||
.bigendian = 0,
|
||||
.id = IMAGE_COREBOOT,
|
||||
.flags = PLATFORM_FLAGS_NONE,
|
||||
.total_module_size = GRUB_KERNEL_ARM_COREBOOT_TOTAL_MODULE_SIZE,
|
||||
.decompressor_compressed_size = TARGET_NO_FIELD,
|
||||
.decompressor_uncompressed_size = TARGET_NO_FIELD,
|
||||
.decompressor_uncompressed_addr = TARGET_NO_FIELD,
|
||||
.section_align = GRUB_KERNEL_ARM_COREBOOT_MOD_ALIGN,
|
||||
.vaddr_offset = 0,
|
||||
.elf_target = EM_ARM,
|
||||
.mod_gap = GRUB_KERNEL_ARM_COREBOOT_MOD_GAP,
|
||||
.mod_align = GRUB_KERNEL_ARM_COREBOOT_MOD_ALIGN,
|
||||
.link_align = 4,
|
||||
},
|
||||
/* For coreboot versions that don't support self-relocating images. */
|
||||
{
|
||||
.dirname = "arm-coreboot-vexpress",
|
||||
|
||||
Reference in New Issue
Block a user