From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1aUXVc-0007wu-2S for mharc-grub-devel@gnu.org; Sat, 13 Feb 2016 05:33:00 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49093) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aUXVZ-0007w8-HM for grub-devel@gnu.org; Sat, 13 Feb 2016 05:32:58 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aUXVW-0004sH-9k for grub-devel@gnu.org; Sat, 13 Feb 2016 05:32:57 -0500 Received: from mail-lf0-x243.google.com ([2a00:1450:4010:c07::243]:33917) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aUXVV-0004sD-SS for grub-devel@gnu.org; Sat, 13 Feb 2016 05:32:54 -0500 Received: by mail-lf0-x243.google.com with SMTP id 78so5258287lfy.1 for ; Sat, 13 Feb 2016 02:32:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-type; bh=Z9hD8r2y8NwLaCVfxxqSMeCCJ3UYVIqIGuWchtDGmr8=; b=z1iMEFbytA+UWKul4xFDq7eXaikejHmBGU9Om/8/Lja0J0cXeODPZ7EVpF3nCs/boQ AQwl3UfR3dAid8P220ey5uadnnQNeicg3VdQ0C4UAR26RgJ5qi1emaVsbhC8zjH0yY// rDn6OfER4DEuUwcXoG1etQsla3Az7hoCWt7Hd4dck10YvZIcA0vvEocB+aKOykNyiOvR dB9IVImYtsteP8LoiA+0NB/7G72DQPJWHoXZBAHIbek8pPQyVfzHSAcE/hdtf/DLuASt 2b0Ps54MIpA85Trtm5BG0o2SIwRqwrCQtrOhZOvFv8gkkxBXjn7j/x7fGOC7owlhYQCn CA/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-type; bh=Z9hD8r2y8NwLaCVfxxqSMeCCJ3UYVIqIGuWchtDGmr8=; b=fkVuKmGGrPk7zWZpWBKYJd5pT0BpwwJsTeG641s0k3UMlfPqmJOz96AX5ubtWA8Da/ xwvSIUBMpqgkvARK6Jk3t5ANnQJg5cZQA5yV+u6H96C9GN1+vadaximyxOnFNH4kNz+/ WsJHYd52Nj1bu/cr9qEdQ+N3zwsmnQi0MtLUmyZ2fvm45bDgtTWRlRspbpCgvE0zkk6G R3Ut9YtuY2/Q8s3DGVW0a9ZB5kRADGrOTc1XUHF6Oin9On66JBCtRkgKpdk2GhJebYWv wL+OnybZNyRPZlL9LNAY0WoK7eSRLnA59CxQ5vjkvqsA4d15M5BSK2Ixbyx1M5usflTR 2Hjw== X-Gm-Message-State: AG10YOR40g/s4oBeevPBNUChVEWE8A/e2Uq6UpJ5tpfOZQvziJJKj6F4VWYXHC22CB0IMw== X-Received: by 10.25.26.205 with SMTP id a196mr2733969lfa.125.1455359572792; Sat, 13 Feb 2016 02:32:52 -0800 (PST) Received: from [192.168.1.41] (ppp109-252-76-159.pppoe.spdop.ru. [109.252.76.159]) by smtp.gmail.com with ESMTPSA id ze8sm2389310lbb.45.2016.02.13.02.32.51 for (version=TLSv1/SSLv3 cipher=OTHER); Sat, 13 Feb 2016 02:32:51 -0800 (PST) Subject: Re: [PATCH v3 2/3] i386: Add support for loading from android bootimg To: grub-devel@gnu.org References: <1454964459-28213-1-git-send-email-shea@shealevy.com> <1454964459-28213-3-git-send-email-shea@shealevy.com> <56BE1B60.5060900@gmail.com> <7384a36941a77cced1fde7e3d084280a@shealevy.com> <2b7ecf3a0dda2687029878e0e745bd73@shealevy.com> <56BE4BB7.6040203@gmail.com> From: Andrei Borzenkov X-Enigmail-Draft-Status: N1110 Message-ID: <56BF0652.1050502@gmail.com> Date: Sat, 13 Feb 2016 13:32:50 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.5.1 MIME-Version: 1.0 In-Reply-To: <56BE4BB7.6040203@gmail.com> Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="AEXR32hlw6dEBwoiHcroWQvwG3DAF4tdt" X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:4010:c07::243 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 13 Feb 2016 10:32:58 -0000 This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --AEXR32hlw6dEBwoiHcroWQvwG3DAF4tdt Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 13.02.2016 00:16, Vladimir '=CF=86-coder/phcoder' Serbinenko =D0=BF=D0=B8= =D1=88=D0=B5=D1=82: > On 12.02.2016 20:34, Shea Levy wrote: >> > OK. Do you have any thoughts on how best to extract the "load the ke= rnel >> > and set the command line to a specific string" functionality out of = the >> > linux command, then? >> >=20 > 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 >=20 >=20 > diff --git a/grub-core/loader/i386/linux.c b/grub-core/loader/i386/linu= x.c > index fddcc46..d3870ae 100644 > --- a/grub-core/loader/i386/linux.c > +++ b/grub-core/loader/i386/linux.c > @@ -35,6 +35,7 @@ > #include > #include > #include > +#include > =20 > GRUB_MOD_LICENSE ("GPLv3+"); > =20 > @@ -673,11 +674,11 @@ grub_linux_unload (void) > return GRUB_ERR_NONE; > } > =20 > + > 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 filesi= ze, > + const char *extra_cmdline, int argc, char *argv[]) > { > - grub_file_t file =3D 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)), > =20 > grub_dl_ref (my_mod); > =20 > - if (argc =3D=3D 0) > - { > - grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected")); > - goto fail; > - } > - > - file =3D grub_file_open (argv[0]); > - if (! file) > - goto fail; > + grub_file_seek (file, fileoffset); > =20 > if (grub_file_read (file, &lh, sizeof (lh)) !=3D sizeof (lh)) > { > @@ -757,7 +750,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((= unused)), > setup_sects =3D GRUB_LINUX_DEFAULT_SETUP_SECTS; > =20 > real_size =3D setup_sects << GRUB_DISK_SECTOR_BITS; > - prot_file_size =3D grub_file_size (file) - real_size - GRUB_DISK_SEC= TOR_SIZE; > + prot_file_size =3D filesize - real_size - GRUB_DISK_SECTOR_SIZE; > =20 > if (grub_le_to_cpu16 (lh.version) >=3D 0x205 > && lh.kernel_alignment !=3D 0 > @@ -871,7 +864,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((= unused)), > =20 > /* The other parameters are filled when booting. */ > =20 > - grub_file_seek (file, real_size + GRUB_DISK_SECTOR_SIZE); > + grub_file_seek (file, fileoffset + real_size + GRUB_DISK_SECTOR_SIZE= ); > =20 > grub_dprintf ("linux", "bzImage, setup=3D0x%x, size=3D0x%x\n", > (unsigned) real_size, (unsigned) prot_size); > @@ -1008,12 +1001,32 @@ grub_cmd_linux (grub_command_t cmd __attribute_= _ ((unused)), > linux_cmdline =3D 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 =3D linux_cmdline; > + char *cmdline_ptr_end =3D linux_cmdline + maximal_cmdline_size; > + /* Construct BOOT_IMAGE=3D/boot/... */ > + cmdline_ptr =3D 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. =2E.. > 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; > } > =20 > +static inline char * > +grub_stpncpy (char *dest, const char *src, int c) "Official" prototype has size_t here. --AEXR32hlw6dEBwoiHcroWQvwG3DAF4tdt Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.22 (GNU/Linux) iEYEARECAAYFAla/BlMACgkQR6LMutpd94xOzgCfdI8ZFIPg4mChx7/qwQG6eLXr YbAAnjRlGOiAfZQgL913h3P8tC2z7G97 =C3hq -----END PGP SIGNATURE----- --AEXR32hlw6dEBwoiHcroWQvwG3DAF4tdt--