From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1Vsfog-0007GX-37 for mharc-grub-devel@gnu.org; Mon, 16 Dec 2013 16:35:06 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46331) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vsfoa-0007EG-57 for grub-devel@gnu.org; Mon, 16 Dec 2013 16:35:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VsfoV-0007bP-HI for grub-devel@gnu.org; Mon, 16 Dec 2013 16:35:00 -0500 Received: from mail-ee0-x22c.google.com ([2a00:1450:4013:c00::22c]:50936) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VsfoV-0007b5-6a for grub-devel@gnu.org; Mon, 16 Dec 2013 16:34:55 -0500 Received: by mail-ee0-f44.google.com with SMTP id b57so2477192eek.31 for ; Mon, 16 Dec 2013 13:34:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type; bh=IojDVSZtlJzRWe3Oqzx9+nSTix9XTAKEYjat7n+BfSA=; b=HUIWbGQgcRBL82FYFA/f+tGnZnDmGTwWalWJwqs/moavykOW8fbRJIbGqlJQ+AN5mF tg7JQhuteEXd7OTUYvH8Dl6jIhYwsrGaeIfoR3LgTE5zuUelV2Lv3LVCbDpK9MGqHR+b +Q5OL26WovnOqxssU7yvBvpDZVFAacS12hkWongY9CDIHCmF/2GmtY+KydGSrt841TD3 XV+fIcGYxXmlaUxRAL1iONbdoeQB9dLNj5Li09r8QaXohWZTf32l3R3YkX3bngxVd9EE 7AepslM1AZdkzHstk/4Qr9Oqt+0HAAHMQjgVU41xdR9SwmOQi7Jg1C1w93Y0nDhfoMlY A+3w== X-Received: by 10.14.101.4 with SMTP id a4mr19176105eeg.28.1387229694333; Mon, 16 Dec 2013 13:34:54 -0800 (PST) Received: from [192.168.1.16] (85-188.196-178.cust.bluewin.ch. [178.196.188.85]) by mx.google.com with ESMTPSA id n1sm46825715eep.20.2013.12.16.13.34.52 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 16 Dec 2013 13:34:53 -0800 (PST) Message-ID: <52AF71FB.1080700@gmail.com> Date: Mon, 16 Dec 2013 22:34:51 +0100 From: =?UTF-8?B?VmxhZGltaXIgJ8+GLWNvZGVyL3BoY29kZXInIFNlcmJpbmVua28=?= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20131103 Icedove/17.0.10 MIME-Version: 1.0 To: grub-devel@gnu.org Subject: Re: [PATCH] add arm64 UEFI Linux loader References: <20131216135551.GV22356@rocoto.smurfnet.nu> <20131216201301.24356028@opensuse.site> <20131216162403.GW22356@rocoto.smurfnet.nu> In-Reply-To: <20131216162403.GW22356@rocoto.smurfnet.nu> X-Enigmail-Version: 1.6 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="sNLcv8snsJgDPFJkXH0pp0EGqgX2jx9Ir" X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:4013:c00::22c 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: Mon, 16 Dec 2013 21:35:04 -0000 This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --sNLcv8snsJgDPFJkXH0pp0EGqgX2jx9Ir Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 16.12.2013 17:24, Leif Lindholm wrote: > On Mon, Dec 16, 2013 at 08:13:01PM +0400, Andrey Borzenkov wrote: >> > =D0=92 Mon, 16 Dec 2013 14:55:51 +0100 >> > Leif Lindholm =D0=BF=D0=B8=D1=88=D0=B5=D1= =82: >> >=20 >>> > > This loader supports booting using the UEFI stub method only. >> >=20 >> > And where is patch? :) > Doh! > Here. >=20 >=20 > 0002-arm64-add-EFI-Linux-loader.patch >=20 >=20 >>>From 03ebc609f33df1ddcdf10668cacf69f1861a5acf Mon Sep 17 00:00:00 2001 > From: Leif Lindholm > Date: Wed, 4 Dec 2013 15:21:16 +0000 > Subject: [PATCH 2/2] arm64: add EFI Linux loader >=20 > Signed-off-by: Leif Lindholm > --- > grub-core/Makefile.core.def | 3 +- > grub-core/loader/arm64/linux.c | 486 ++++++++++++++++++++++++++++++++= ++++++++ > include/grub/arm64/linux.h | 54 +++++ > include/grub/efi/api.h | 4 + > 4 files changed, 546 insertions(+), 1 deletion(-) > create mode 100644 grub-core/loader/arm64/linux.c > create mode 100644 include/grub/arm64/linux.h >=20 > diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def > index 4102e73..ffa4f4b 100644 > --- a/grub-core/Makefile.core.def > +++ b/grub-core/Makefile.core.def > @@ -1667,7 +1667,8 @@ module =3D { > sparc64_ieee1275 =3D loader/sparc64/ieee1275/linux.c; > ia64_efi =3D loader/ia64/efi/linux.c; > arm =3D loader/arm/linux.c; > - arm =3D lib/fdt.c; > + arm64 =3D loader/arm64/linux.c; > + fdt =3D lib/fdt.c; > common =3D loader/linux.c; > common =3D lib/cmdline.c; > enable =3D noemu; > diff --git a/grub-core/loader/arm64/linux.c b/grub-core/loader/arm64/li= nux.c > new file mode 100644 > index 0000000..e94a76a > --- /dev/null > +++ b/grub-core/loader/arm64/linux.c > @@ -0,0 +1,486 @@ > +/* > + * GRUB -- GRand Unified Bootloader > + * 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 . > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +GRUB_MOD_LICENSE ("GPLv3+"); > + > +#define GRUB_EFI_PAGE_SHIFT 12 > +#define BYTES_TO_PAGES(bytes) (((bytes) + 0xfff) >> GRUB_EFI_PAGE_SH= IFT) > + > +static grub_efi_guid_t fdt_guid =3D GRUB_EFI_DEVICE_TREE_GUID; > + > +typedef void (*kernel_stub) (grub_efi_handle_t, grub_efi_system_table_= t *); > +typedef void (*kernel_image) (void *); > + > +static grub_dl_t my_mod; > +static int loaded; > +static void *kernel_mem; > +static grub_uint64_t kernel_size; > +static void *initrd_mem; > +static grub_uint32_t initrd_size; > + > +static grub_uint32_t cmdline_size; > + > +static grub_addr_t initrd_start; > +static grub_addr_t initrd_end; > + > +static void *orig_fdt; > +static void *fdt; > + > +static char *linux_args; > + > +static void > +get_fdt (void) > +{ > + grub_efi_configuration_table_t *tables; > + unsigned int i; > + int fdt_loaded; > + int size; > + > + if (!orig_fdt) > + { > + fdt_loaded =3D 0; > + /* Look for FDT in UEFI config tables. */ > + tables =3D grub_efi_system_table->configuration_table; > + > + for (i =3D 0; i < grub_efi_system_table->num_table_entries; i++)= > + if (grub_memcmp (&tables[i].vendor_guid, &fdt_guid, sizeof (fdt_guid)= ) > + =3D=3D 0) > + { > + orig_fdt =3D tables[i].vendor_table; > + grub_dprintf ("linux", "found registered FDT @ 0x%p\n", orig_fdt)= ; > + break; > + } > + } > + else > + fdt_loaded =3D 1; > + > + size =3D > + orig_fdt ? grub_fdt_get_totalsize (orig_fdt) : GRUB_FDT_EMPTY_TREE= _SZ; > + size +=3D grub_strlen (linux_args) + 0x400; > + > + grub_dprintf ("linux", "allocating %d bytes for fdt\n", size); > + fdt =3D grub_efi_allocate_pages (0, BYTES_TO_PAGES (size)); > + if (!fdt) > + return; > + > + if (orig_fdt) > + { > + grub_memmove (fdt, orig_fdt, size); > + grub_fdt_set_totalsize (fdt, size); > + if (fdt_loaded) > + grub_free (orig_fdt); There is a problem with this: in case of failure orig_fdt isn't available for next try anymore. > + } > + else > + { > + grub_fdt_create_empty_tree (fdt, size); > + } > +} > + > +static grub_err_t > +check_kernel (struct linux_kernel_header *lh) > +{ > + if (lh->magic !=3D GRUB_LINUX_MAGIC) > + return GRUB_ERR_BAD_OS; You need grub_error here > + > + if ((lh->code0 & 0xffff) !=3D 0x5A4D) > + { Need a comment that it's MZ/exe header > + grub_error (GRUB_ERR_BAD_OS, Sounds like NOT_IMPLEMENTED_YET > + N_ > + ("Plain Image kernel not supported - rebuild with CONFIG_UEFI_STUB= enabled.\n")); > + return GRUB_ERR_BAD_OS; You can return grub_error (....); > + dtb =3D grub_file_open (filename); > + if (!dtb) > + { > + grub_error (GRUB_ERR_FILE_NOT_FOUND, N_("failed to open file"));= grub_file_open already does that. > + size =3D grub_file_size (dtb); > + if (size =3D=3D 0) > + goto out; > + You propbably need some error > + tmp_fdt =3D grub_malloc (size); > + if (!tmp_fdt) > + goto out; > + > + if (grub_file_read (dtb, tmp_fdt, size) !=3D size) > + { > + grub_free (tmp_fdt); Where is file closed? > + return NULL; > + } > + > + if (grub_fdt_check_header (tmp_fdt, size) !=3D 0) > + { > + grub_free (tmp_fdt); ditto > + return NULL; > + } > + > +out: > + grub_file_close (dtb); > + return tmp_fdt; > +} > + > +static grub_err_t > +grub_cmd_devicetree (grub_command_t cmd __attribute__ ((unused)), > + int argc, char *argv[]) > +{ > + void *blob; > + > + if (!loaded) > + { > + grub_error (GRUB_ERR_BAD_ARGUMENT, > + N_("you need to load the kernel first")); > + return GRUB_ERR_BAD_OS; > + } > + > + if (argc !=3D 1) > + return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"))= ; > + > + blob =3D load_dtb (argv[0]); > + if (!blob) > + return GRUB_ERR_FILE_NOT_FOUND; > + > + orig_fdt =3D blob; > + > + return GRUB_ERR_NONE; > +} > + > +static grub_err_t > +grub_linux_boot (void) > +{ > + grub_efi_loaded_image_t *image; > + struct linux_kernel_header *lh =3D kernel_mem; > + struct grub_pe32_optional_header *oh; pe32? Not pe64? > + kernel_stub entry; > + grub_err_t retval; > + > + retval =3D finalize_params (); > + if (retval !=3D GRUB_ERR_NONE) > + return retval; > + > + /* > + * Terminate command line of usurped image, to inform > + * stub loader to get command line out of DT. > + */ > + image =3D grub_efi_get_loaded_image (grub_efi_image_handle); > + image->load_options =3D NULL; > + image->load_options_size =3D 0; > + > + oh =3D (void *) ((grub_addr_t) kernel_mem + sizeof ("PE\0") + lh->hd= r_offset > + + sizeof (struct grub_pe32_coff_header)); > + > + entry =3D (void *) ((grub_addr_t) kernel_mem + oh->entry_addr); > + grub_dprintf ("linux", "Entry point: %p\n", (void *) entry); > + entry (grub_efi_image_handle, grub_efi_system_table); > + > + /* When successful, not reached */ > + return GRUB_ERR_NONE; Sounds like return grub_errno; then > +} > + > +static grub_err_t > +grub_linux_unload (void) > +{ > + grub_dl_unref (my_mod); > + loaded =3D 0; > + if (initrd_mem) > + grub_efi_free_pages ((grub_efi_physical_address_t) initrd_mem, > + BYTES_TO_PAGES (initrd_size)); > + if (kernel_mem) > + grub_efi_free_pages ((grub_efi_physical_address_t) kernel_mem, > + BYTES_TO_PAGES (kernel_size)); > + if (fdt) > + grub_efi_free_pages ((grub_efi_physical_address_t) fdt, > + BYTES_TO_PAGES (grub_fdt_get_totalsize (fdt))); is fdt allocate with malloc or allocate_pages? > + if (!loaded) > + { > + grub_error (GRUB_ERR_BAD_ARGUMENT, > + N_("you need to load the kernel first")); > + goto fail; > + } > + > + files =3D grub_zalloc (argc * sizeof (files[0])); > + if (!files) > + goto fail; > + > + for (i =3D 0; i < argc; i++) > + { > + grub_file_filter_disable_compression (); > + files[i] =3D grub_file_open (argv[i]); > + if (!files[i]) > + goto fail; > + nfiles++; > + size +=3D ALIGN_UP (grub_file_size (files[i]), 4); > + } > + Why don't you use methods from loader/linux.c ? > + if (grub_file_read (file, kernel_mem, kernel_size) > + !=3D (grub_int64_t) kernel_size) > + { > + grub_error (GRUB_ERR_FILE_READ_ERROR, N_("Can't read kernel %s")= , > + argv[0]); Please look at similar place in other architectures. --sNLcv8snsJgDPFJkXH0pp0EGqgX2jx9Ir Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.15 (GNU/Linux) Comment: Using GnuPG with Icedove - http://www.enigmail.net/ iF4EAREKAAYFAlKvcfwACgkQmBXlbbo5nOv41AD9H9/gUNlDDBNx0thMwG37Yq/6 tY/9ATcI0aKrq4ob/Y4BAIQr87NB1kFon/xFLJCZCMwdFmnmkqIrZOr/6TJYapL2 =CHJL -----END PGP SIGNATURE----- --sNLcv8snsJgDPFJkXH0pp0EGqgX2jx9Ir--