From: Andrei Borzenkov <arvidjaar@gmail.com>
To: grub-devel@gnu.org
Subject: Re: [PATCH v3 2/3] i386: Add support for loading from android bootimg
Date: Sat, 13 Feb 2016 13:32:50 +0300 [thread overview]
Message-ID: <56BF0652.1050502@gmail.com> (raw)
In-Reply-To: <56BE4BB7.6040203@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 3983 bytes --]
13.02.2016 00:16, Vladimir 'φ-coder/phcoder' Serbinenko пишет:
> On 12.02.2016 20:34, Shea Levy wrote:
>> > OK. Do you have any thoughts on how best to extract the "load the kernel
>> > and set the command line to a specific string" functionality out of the
>> > linux command, then?
>> >
> At first I wanted to write a short skeleton patch to show what I meant
> but once skeleton is done, there is little actual code involved. Please
> try attached patch
Yes, exactly what I meant. Nitpicks below.
> android.diff
>
>
> diff --git a/grub-core/loader/i386/linux.c b/grub-core/loader/i386/linux.c
> index fddcc46..d3870ae 100644
> --- a/grub-core/loader/i386/linux.c
> +++ b/grub-core/loader/i386/linux.c
> @@ -35,6 +35,7 @@
> #include <grub/i18n.h>
> #include <grub/lib/cmdline.h>
> #include <grub/linux.h>
> +#include <grub/android.h>
>
> GRUB_MOD_LICENSE ("GPLv3+");
>
> @@ -673,11 +674,11 @@ grub_linux_unload (void)
> return GRUB_ERR_NONE;
> }
>
> +
> static grub_err_t
> -grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
> - int argc, char *argv[])
> +linux_load (grub_file_t file, grub_off_t fileoffset, grub_off_t filesize,
> + const char *extra_cmdline, int argc, char *argv[])
> {
> - grub_file_t file = 0;
> struct linux_kernel_header lh;
> grub_uint8_t setup_sects;
> grub_size_t real_size, prot_size, prot_file_size;
> @@ -689,15 +690,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
>
> grub_dl_ref (my_mod);
>
> - if (argc == 0)
> - {
> - grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"));
> - goto fail;
> - }
> -
> - file = grub_file_open (argv[0]);
> - if (! file)
> - goto fail;
> + grub_file_seek (file, fileoffset);
>
> if (grub_file_read (file, &lh, sizeof (lh)) != sizeof (lh))
> {
> @@ -757,7 +750,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
> setup_sects = GRUB_LINUX_DEFAULT_SETUP_SECTS;
>
> real_size = setup_sects << GRUB_DISK_SECTOR_BITS;
> - prot_file_size = grub_file_size (file) - real_size - GRUB_DISK_SECTOR_SIZE;
> + prot_file_size = filesize - real_size - GRUB_DISK_SECTOR_SIZE;
>
> if (grub_le_to_cpu16 (lh.version) >= 0x205
> && lh.kernel_alignment != 0
> @@ -871,7 +864,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
>
> /* The other parameters are filled when booting. */
>
> - grub_file_seek (file, real_size + GRUB_DISK_SECTOR_SIZE);
> + grub_file_seek (file, fileoffset + real_size + GRUB_DISK_SECTOR_SIZE);
>
> grub_dprintf ("linux", "bzImage, setup=0x%x, size=0x%x\n",
> (unsigned) real_size, (unsigned) prot_size);
> @@ -1008,12 +1001,32 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
> linux_cmdline = grub_zalloc (maximal_cmdline_size + 1);
> if (!linux_cmdline)
> goto fail;
> - grub_memcpy (linux_cmdline, LINUX_IMAGE, sizeof (LINUX_IMAGE));
> - grub_create_loader_cmdline (argc, argv,
> - linux_cmdline
> - + sizeof (LINUX_IMAGE) - 1,
> - maximal_cmdline_size
> - - (sizeof (LINUX_IMAGE) - 1));
> + char *cmdline_ptr = linux_cmdline;
> + char *cmdline_ptr_end = linux_cmdline + maximal_cmdline_size;
> + /* Construct BOOT_IMAGE=/boot/... */
> + cmdline_ptr = grub_stpcpy (cmdline_ptr, LINUX_IMAGE);
> + grub_create_loader_cmdline (1, argv, cmdline_ptr,
What if argc is zero? We checked this before, but check is removed. This
became library function now, it should check input for sanity.
...
> diff --git a/include/grub/misc.h b/include/grub/misc.h
> index 2a9f87c..ef9c9b6 100644
> --- a/include/grub/misc.h
> +++ b/include/grub/misc.h
> @@ -64,6 +64,17 @@ grub_stpcpy (char *dest, const char *src)
> return d - 1;
> }
>
> +static inline char *
> +grub_stpncpy (char *dest, const char *src, int c)
"Official" prototype has size_t here.
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]
next prev parent reply other threads:[~2016-02-13 10:33 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-08 20:47 [PATCH v3 0/3] Android bootimg support Shea Levy
2016-02-08 20:47 ` [PATCH v3 1/3] Add helper functions to interact with android bootimg disks Shea Levy
2016-02-12 17:42 ` Vladimir 'φ-coder/phcoder' Serbinenko
2016-02-12 17:53 ` Vladimir 'φ-coder/phcoder' Serbinenko
2016-02-08 20:47 ` [PATCH v3 2/3] i386: Add support for loading from android bootimg Shea Levy
2016-02-12 17:50 ` Vladimir 'φ-coder/phcoder' Serbinenko
2016-02-12 19:19 ` Shea Levy
2016-02-12 19:22 ` Vladimir 'phcoder' Serbinenko
2016-02-12 19:34 ` Shea Levy
2016-02-12 21:16 ` Vladimir 'φ-coder/phcoder' Serbinenko
2016-02-13 10:32 ` Andrei Borzenkov [this message]
2016-02-14 13:21 ` Shea Levy
2016-02-14 13:26 ` Vladimir 'phcoder' Serbinenko
2016-02-14 17:20 ` Andrei Borzenkov
2016-02-14 20:58 ` Seth Goldberg
2016-02-15 3:41 ` Andrei Borzenkov
2016-02-15 4:13 ` Seth Goldberg
2016-02-15 10:55 ` Vladimir 'phcoder' Serbinenko
2016-02-08 20:47 ` [PATCH v3 3/3] Add support for loading initrd " Shea Levy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=56BF0652.1050502@gmail.com \
--to=arvidjaar@gmail.com \
--cc=grub-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).