All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Daney <ddaney@caviumnetworks.com>
To: Aurelien Jarno <aurelien@aurel32.net>, <linux-mips@linux-mips.org>
Cc: David Daney <david.daney@cavium.com>
Subject: Re: [PATCH] MIPS: Octeon: byteswap initramfs in little endian mode
Date: Thu, 5 May 2016 14:40:08 -0700	[thread overview]
Message-ID: <572BBDB8.8000300@caviumnetworks.com> (raw)
In-Reply-To: <1462484017-29988-1-git-send-email-aurelien@aurel32.net>

On 05/05/2016 02:33 PM, Aurelien Jarno wrote:
> The initramfs if loaded in memory by U-Boot running in big endian mode.
> When the kernel is running in little endian mode, we need to byteswap it
> as it is accessed byte by byte.

Ouch!

Really it should be fixed in the bootloader, but that probably won't happen.

I wonder, is there a magic number that the initrd has?  If so, we could 
probe for a byteswapped initrd and not do the byte reversal unconditionally.

The logic seems correct, we need to byte swap each 8-byte aligned 8-byte 
word in the image.

>
> Cc: David Daney <david.daney@cavium.com>
> Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
> ---
>   arch/mips/kernel/setup.c | 10 ++++++++++
>   1 file changed, 10 insertions(+)
>
> Note: It might not be the best place to byteswap the initramfs not the
> best way to do it. At least it shows the problem and what shoudl be done.
> Suggestions to improve the patch are welcome.
>
> diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c
> index 4f60734..e7d015e 100644
> --- a/arch/mips/kernel/setup.c
> +++ b/arch/mips/kernel/setup.c
> @@ -263,6 +263,16 @@ static void __init finalize_initrd(void)
>   		goto disable;
>   	}
>
> +#if defined(CONFIG_CPU_CAVIUM_OCTEON) && defined(CONFIG_CPU_LITTLE_ENDIAN)
> +	{
> +		unsigned long i;
> +		pr_info("Cavium Octeon kernel in little endian mode "
> +			"detected, byteswapping ramdisk\n");
> +		for (i = initrd_start; i < ALIGN(initrd_end, 8); i += 8)
> +			*((unsigned long *)i) = swab64(*((unsigned long *)i));
> +	}
> +#endif
> +
>   	reserve_bootmem(__pa(initrd_start), size, BOOTMEM_DEFAULT);
>   	initrd_below_start_ok = 1;
>
>

WARNING: multiple messages have this Message-ID (diff)
From: David Daney <ddaney@caviumnetworks.com>
To: Aurelien Jarno <aurelien@aurel32.net>, linux-mips@linux-mips.org
Cc: David Daney <david.daney@cavium.com>
Subject: Re: [PATCH] MIPS: Octeon: byteswap initramfs in little endian mode
Date: Thu, 5 May 2016 14:40:08 -0700	[thread overview]
Message-ID: <572BBDB8.8000300@caviumnetworks.com> (raw)
Message-ID: <20160505214008.tbu1ntHddx4RK_TYkxA6iHaF5ark6vurCq-zoRLcl64@z> (raw)
In-Reply-To: <1462484017-29988-1-git-send-email-aurelien@aurel32.net>

On 05/05/2016 02:33 PM, Aurelien Jarno wrote:
> The initramfs if loaded in memory by U-Boot running in big endian mode.
> When the kernel is running in little endian mode, we need to byteswap it
> as it is accessed byte by byte.

Ouch!

Really it should be fixed in the bootloader, but that probably won't happen.

I wonder, is there a magic number that the initrd has?  If so, we could 
probe for a byteswapped initrd and not do the byte reversal unconditionally.

The logic seems correct, we need to byte swap each 8-byte aligned 8-byte 
word in the image.

>
> Cc: David Daney <david.daney@cavium.com>
> Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
> ---
>   arch/mips/kernel/setup.c | 10 ++++++++++
>   1 file changed, 10 insertions(+)
>
> Note: It might not be the best place to byteswap the initramfs not the
> best way to do it. At least it shows the problem and what shoudl be done.
> Suggestions to improve the patch are welcome.
>
> diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c
> index 4f60734..e7d015e 100644
> --- a/arch/mips/kernel/setup.c
> +++ b/arch/mips/kernel/setup.c
> @@ -263,6 +263,16 @@ static void __init finalize_initrd(void)
>   		goto disable;
>   	}
>
> +#if defined(CONFIG_CPU_CAVIUM_OCTEON) && defined(CONFIG_CPU_LITTLE_ENDIAN)
> +	{
> +		unsigned long i;
> +		pr_info("Cavium Octeon kernel in little endian mode "
> +			"detected, byteswapping ramdisk\n");
> +		for (i = initrd_start; i < ALIGN(initrd_end, 8); i += 8)
> +			*((unsigned long *)i) = swab64(*((unsigned long *)i));
> +	}
> +#endif
> +
>   	reserve_bootmem(__pa(initrd_start), size, BOOTMEM_DEFAULT);
>   	initrd_below_start_ok = 1;
>
>

  reply	other threads:[~2016-05-05 21:42 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-05 21:33 [PATCH] MIPS: Octeon: byteswap initramfs in little endian mode Aurelien Jarno
2016-05-05 21:40 ` David Daney [this message]
2016-05-05 21:40   ` David Daney
2016-05-05 22:16   ` Aurelien Jarno
2016-05-05 22:53     ` David Daney
2016-05-05 22:53       ` David Daney
2016-05-11 15:44       ` Aurelien Jarno

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=572BBDB8.8000300@caviumnetworks.com \
    --to=ddaney@caviumnetworks.com \
    --cc=aurelien@aurel32.net \
    --cc=david.daney@cavium.com \
    --cc=linux-mips@linux-mips.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.