From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1UPMDg-0004qb-JE for mharc-grub-devel@gnu.org; Mon, 08 Apr 2013 20:15:28 -0400 Received: from eggs.gnu.org ([208.118.235.92]:59815) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UPMDe-0004qP-8K for grub-devel@gnu.org; Mon, 08 Apr 2013 20:15:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UPMDb-00015f-IC for grub-devel@gnu.org; Mon, 08 Apr 2013 20:15:26 -0400 Received: from mail-ea0-x22e.google.com ([2a00:1450:4013:c01::22e]:44778) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UPMDb-00015W-7S for grub-devel@gnu.org; Mon, 08 Apr 2013 20:15:23 -0400 Received: by mail-ea0-f174.google.com with SMTP id m14so2529719eaj.19 for ; Mon, 08 Apr 2013 17:15:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:message-id:date:from:user-agent:mime-version:to:subject :references:in-reply-to:x-enigmail-version:content-type; bh=ZowEJOWbXoiU9qArPZqdwwXvcyt1fKqbD53YbGE1Jl4=; b=QxTkZYZBBFZf1VOirGxFLvLOik4Vbgykvd0Pq8i68vePyVvUeBjPyu+VMuAr+oKGPb eUKDlFuj9jujtPl3155bjldf446KMESaApQLvgFPEB4Z9CJQcm9GVfN0WIGFnwl9VsD8 dQ+Y8lTSyYnzQOZyxMZdEZrO9NFPHorkkqq0kcwUGguNFrbgFMaBj1MiX3ezSmacAyr1 y/gxYzzVSiaDG85WS+jWuX18oFJdNeEQdJxPMnup8x95Xx6F0zkwczmmEXmrQZsX41Av 7tcMZh9Nf45Lz6JK47EopUIZGK1LduCuwLHNauONPt6XyhtoL7vmiWb55K/qmVkS40ZJ SvIw== X-Received: by 10.15.22.76 with SMTP id e52mr54448526eeu.7.1365466522473; Mon, 08 Apr 2013 17:15:22 -0700 (PDT) Received: from debian.x201.phnet (245-188.1-85.cust.bluewin.ch. [85.1.188.245]) by mx.google.com with ESMTPS id b5sm3135912eew.16.2013.04.08.17.15.21 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 08 Apr 2013 17:15:21 -0700 (PDT) Message-ID: <51635D98.7020901@gmail.com> Date: Tue, 09 Apr 2013 02:15:20 +0200 From: =?UTF-8?B?VmxhZGltaXIgJ8+GLWNvZGVyL3BoY29kZXInIFNlcmJpbmVua28=?= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.12) Gecko/20130116 Icedove/10.0.12 MIME-Version: 1.0 To: The development of GNU GRUB Subject: Re: [PATCH 4/7] Support for ARM/U-Boot platforms References: In-Reply-To: X-Enigmail-Version: 1.4.1 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="------------enig1C20D387AE7B9DCF7E57DA4D" X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:4013:c01::22e 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: Tue, 09 Apr 2013 00:15:27 -0000 This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enig1C20D387AE7B9DCF7E57DA4D Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 24.03.2013 18:01, Leif Lindholm wrote: >=20 > 0004-arm-uboot-support.patch >=20 >=20 > =3D=3D=3D modified file 'Makefile.util.def' > --- Makefile.util.def 2013-03-24 13:03:12 +0000 > +++ Makefile.util.def 2013-03-24 13:03:31 +0000 > @@ -467,6 +467,7 @@ > enable =3D mips_loongson; > enable =3D ia64_efi; > enable =3D powerpc_ieee1275; > + enable =3D arm_uboot; > }; > =20 > script =3D { >=20 > =3D=3D=3D modified file 'grub-core/Makefile.am' > --- grub-core/Makefile.am 2013-03-20 16:13:31 +0000 > +++ grub-core/Makefile.am 2013-03-24 13:03:31 +0000 > @@ -211,6 +211,13 @@ > KERNEL_HEADER_FILES +=3D $(top_srcdir)/include/grub/lib/arg.h > endif > =20 > +if COND_arm_uboot > +KERNEL_HEADER_FILES +=3D $(top_srcdir)/include/grub/uboot/uboot.h > +KERNEL_HEADER_FILES +=3D $(top_srcdir)/include/grub/uboot/disk.h > +KERNEL_HEADER_FILES +=3D $(top_srcdir)/include/grub/extcmd.h > +KERNEL_HEADER_FILES +=3D $(top_srcdir)/include/grub/lib/arg.h > +endif > + > if COND_emu > KERNEL_HEADER_FILES +=3D $(top_srcdir)/include/grub/datetime.h > KERNEL_HEADER_FILES +=3D $(top_srcdir)/include/grub/emu/misc.h >=20 > =3D=3D=3D modified file 'grub-core/Makefile.core.def' > --- grub-core/Makefile.core.def 2013-03-24 13:03:12 +0000 > +++ grub-core/Makefile.core.def 2013-03-24 13:03:31 +0000 > @@ -79,6 +79,7 @@ > mips_startup =3D kern/mips/startup.S; > sparc64_ieee1275_startup =3D kern/sparc64/ieee1275/crt0.S; > powerpc_ieee1275_startup =3D kern/powerpc/ieee1275/startup.S; > + arm_uboot_startup =3D kern/arm/uboot/startup.S; > =20 > common =3D kern/command.c; > common =3D kern/corecmd.c; >=20 > =3D=3D=3D added directory 'grub-core/kern/arm/uboot' > =3D=3D=3D added file 'grub-core/kern/arm/uboot/startup.S' > --- grub-core/kern/arm/uboot/startup.S 1970-01-01 00:00:00 +0000 > +++ grub-core/kern/arm/uboot/startup.S 2013-03-24 13:03:31 +0000 > @@ -0,0 +1,176 @@ > +/* > + * 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 > + > +/* > + * GRUB is called from U-Boot as a Linux Kernel type image, which > + * means among other things that it always enters in ARM state. > + * > + * > + * Overview of GRUB image layout: > + * > + * _start: > + * Entry point (1 ARM branch instruction, to "codestart")= > + * grub_total_module_size: > + * Data field: Size of included module blob > + * (when generated by grub-mkimage) > + * codestart: > + * Remainder of statically-linked executable code and dat= a. > + * __bss_start: > + * Start of included module blob. > + * Also where global/static variables are located. > + * _end: > + * End of bss region (but not necessarily module blob). > + * : > + * Any part of the module blob that extends beyond _end. > + * : > + * Loadable modules, post relocation. > + * : =20 > + * : > + */ > +=09 > + .text > + .arm > +FUNCTION(_start) > + b codestart > +=09 > + @ Size of final image integrated module blob - set by grub-mkimage > + . =3D _start + GRUB_KERNEL_MACHINE_TOTAL_MODULE_SIZE > +VARIABLE(grub_total_module_size) > + .long 0 > + > +FUNCTION(codestart) > + @ Store context: Machine ID, atags/dtb, ... > + @ U-Boot API signature is stored on the U-Boot heap > + @ Stack pointer used as start address for signature probing > + mov r12, sp > + ldr sp, =3Dentry_state > + push {r4-r12,lr} @ store U-Boot context (sp in r12) > + > + @ Put kernel parameters aside until we can store them (further down) > + mov r4, r1 @ machine type > + mov r5, r2 @ boot data > + > + @ Modules have been stored as a blob in BSS, > + @ they need to be manually relocated to _end or > + @ (__bss_start + grub_total_module_size), whichever greater. > + bl uboot_get_real_bss_start @ r0 =3D src > + ldr r1, =3DEXT_C(_end) @ dst =3D End of BSS > + ldr r2, grub_total_module_size @ blob size > + add r3, r0, r2 @ blob end > + cmp r1, r3 @ _end < blob end? > + movlt r1, r3 @ dst =3D blob end + blob size > +=09 > +1: ldr r3, [r0], #4 @ r3 =3D *src++=20 > + str r3, [r1], #4 @ *dst++ =3D r3=20 > + subs r2, #4 @ remaining -=3D 4 > + bne 1b @ while remaining !=3D 0 > +=09 > + @ Set up a new stack, beyond the end of copied modules. > + ldr r3, =3DGRUB_KERNEL_MACHINE_STACK_SIZE > + add r3, r1, r3 @ Place stack beyond end of modules > + and sp, r3, #~0x7 @ Ensure 8-byte alignment > + > + @ Since we _are_ the C run-time, we need to manually zero the BSS > + @ region before continuing > + bl uboot_get_real_bss_start @ zero from here This start is wrong. Even if modules start later due to alignment, BSS starts at __bss_start. Additional problem is that both __bss_start and _end may be unaligned unless special care is taken (like putting a dummy uint32_t at the beginning of BSS by putting it at the end of startup.S or using ld options) > + ldr r1, =3DEXT_C(_end) @ to here > + mov r2, #0 > +1: str r2, [r0], #4 > + cmp r0, r1 > + bne 1b > + > + @ Global variables now accessible - store kernel parameters in memory= > + ldr r12, =3DEXT_C(uboot_machine_type) > + str r4, [r12] > + ldr r12, =3DEXT_C(uboot_boot_data) > + str r5, [r12] > +=09 Instead of temporary stashing the values to registers you can just init those values in C code to e.g. 0x55aa55aa so they'll be in .data and so accessible from the very beginning. > + b EXT_C(grub_main) > + > + /* > + * __bss_start does not actually point to the start of the runtime > + * BSS, but rather to the next byte following the preceding data. > + */ Only modules are aligned. BSS itself is still at _bss. > +FUNCTION (uboot_get_real_bss_start) > + ldr r0, =3DEXT_C(__bss_start) @ src > + tst r0, #(GRUB_KERNEL_MACHINE_MOD_ALIGN - 1) > + beq 1f > + mvn r1, #(GRUB_KERNEL_MACHINE_MOD_ALIGN - 1) > + and r0, r0, r1 > + add r0, r0, #(GRUB_KERNEL_MACHINE_MOD_ALIGN) Can be trivially simplified to: mvn r1, #(GRUB_KERNEL_MACHINE_MOD_ALIGN - 1) add r0, r0, r1 and r0, r0, r1 which can be then inlined. Also it's more reliable to save grub_modbase as soon as we computed it in asm part (and use 0x55aa55aa trick to make it accessible early) --------------enig1C20D387AE7B9DCF7E57DA4D 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.12 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iF4EAREKAAYFAlFjXZgACgkQNak7dOguQgkpPAD/V31xaMz4L1b1ZGzBPPiI7Rvl 0oybTcA4mzoLXLpjX5EBAJJ+Kr4im03/Y0v+Yykj36I8GMn1CiSe6wOvVnuZa12M =2d4I -----END PGP SIGNATURE----- --------------enig1C20D387AE7B9DCF7E57DA4D--