mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Andrey Smirnov <andrew.smirnov@gmail.com>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH 3/8] arm/cpu/start.c: Distil some common code in __start().
Date: Mon, 12 Oct 2015 11:44:44 +0200	[thread overview]
Message-ID: <20151012094444.GR7858@pengutronix.de> (raw)
In-Reply-To: <1444589021-12727-3-git-send-email-andrew.smirnov@gmail.com>

On Sun, Oct 11, 2015 at 11:43:36AM -0700, Andrey Smirnov wrote:
> Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
> ---
>  arch/arm/cpu/start.c | 49 +++++++++++++++++++++++++++++++++++--------------
>  1 file changed, 35 insertions(+), 14 deletions(-)
> 
> diff --git a/arch/arm/cpu/start.c b/arch/arm/cpu/start.c
> index 8e5097b..7ffde7c 100644
> --- a/arch/arm/cpu/start.c
> +++ b/arch/arm/cpu/start.c
> @@ -53,6 +53,18 @@ void *barebox_arm_boot_dtb(void)
>  	return barebox_boot_dtb;
>  }
>  
> +static uint32_t get_any_boarddata_magic(const void *boarddata)
> +{
> +	if (get_unaligned_be32(boarddata) == FDT_MAGIC)
> +		return FDT_MAGIC;
> +
> +	if (((struct barebox_arm_boarddata *)boarddata)->magic ==
> +	    BAREBOX_ARM_BOARDDATA_MAGIC)
> +		return BAREBOX_ARM_BOARDDATA_MAGIC;
> +
> +	return 0;
> +}
> +
>  static noinline __noreturn void __start(unsigned long membase,
>  		unsigned long memsize, void *boarddata)
>  {
> @@ -89,21 +101,30 @@ static noinline __noreturn void __start(unsigned long membase,
>  	}
>  
>  	if (boarddata) {
> -		if (get_unaligned_be32(boarddata) == FDT_MAGIC) {
> -			uint32_t totalsize = get_unaligned_be32(boarddata + 4);
> +		uint32_t totalsize;
> +		void **var = NULL;
> +		const char *name;
> +
> +		switch (get_any_boarddata_magic(boarddata)) {
> +		case FDT_MAGIC:
> +			totalsize = get_unaligned_be32(boarddata + 4);
> +			var = &barebox_boot_dtb;
> +			name = "DTB";
> +			break;
> +		case BAREBOX_ARM_BOARDDATA_MAGIC:
> +			totalsize = sizeof(struct barebox_arm_boarddata);
> +			var = &barebox_boarddata;
> +			name = "machine type";
> +			break;
> +		default:
> +			break;
> +		}
> +
> +		if (var) {
>  			endmem -= ALIGN(totalsize, 64);
> -			barebox_boot_dtb = (void *)endmem;
> -			pr_debug("found DTB in boarddata, copying to 0x%p\n",
> -					barebox_boot_dtb);
> -			memcpy(barebox_boot_dtb, boarddata, totalsize);
> -		} else if (((struct barebox_arm_boarddata *)boarddata)->magic ==
> -				BAREBOX_ARM_BOARDDATA_MAGIC) {
> -			endmem -= ALIGN(sizeof(struct barebox_arm_boarddata), 64);
> -			barebox_boarddata = (void *)endmem;
> -			pr_debug("found machine type in boarddata, copying to 0x%p\n",
> -					barebox_boarddata);
> -			memcpy(barebox_boarddata, boarddata,
> -					sizeof(struct barebox_arm_boarddata));
> +			pr_debug("found %s in boarddata, copying to 0x%lu\n",
> +				 name, endmem);
> +			*var = memcpy((void *)endmem, boarddata, totalsize);

I do not see a real improvement in this patch. The previously duplicated
code which is now shared is limited to the pr_debug message and the call
to memcpy. This is done at the cost of making the code slightly more
complicated due to the additional void **var indirection. Dropped this
patch for now. Maybe some additional cleanup or feature may make this
patch more useful, in that case I'll take it then later.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  reply	other threads:[~2015-10-12  9:45 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-11 18:43 [PATCH 1/8] memtest.c: Print iterations count if -i is 0 Andrey Smirnov
2015-10-11 18:43 ` [PATCH 2/8] arm: Disable unaligned accesses Andrey Smirnov
2015-10-11 18:43 ` [PATCH 3/8] arm/cpu/start.c: Distil some common code in __start() Andrey Smirnov
2015-10-12  9:44   ` Sascha Hauer [this message]
2015-10-11 18:43 ` [PATCH 4/8] arm/cpu: Avoid multiple definitions of barebox_arm_entry Andrey Smirnov
2015-10-12  9:37   ` Sascha Hauer
2015-10-11 18:43 ` [PATCH 5/8] freescale-mx6-sabresd: Add CONFIG_DEBUG_LL support Andrey Smirnov
2015-10-11 18:43 ` [PATCH 6/8] common/command.c: Replace magic number with appropriate constant Andrey Smirnov
2015-10-11 18:43 ` [PATCH 7/8] common/parser.c: Do not conflate error reporting disciplines Andrey Smirnov
2015-10-11 18:43 ` [PATCH 8/8] common/parser.c: Do not treat zero return code as error Andrey Smirnov
2015-10-12  9:46 ` [PATCH 1/8] memtest.c: Print iterations count if -i is 0 Sascha Hauer

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=20151012094444.GR7858@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=andrew.smirnov@gmail.com \
    --cc=barebox@lists.infradead.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