mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Krzysztof Halasa <khc@pm.waw.pl>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH 6] ARM: support big/little endian switching in "bootz".
Date: Tue, 21 Dec 2010 08:41:55 +0100	[thread overview]
Message-ID: <20101221074155.GU6017@pengutronix.de> (raw)
In-Reply-To: <m3tyi8carg.fsf@intrepid.localdomain>

Hi Krzysztof,

On Mon, Dec 20, 2010 at 11:58:11PM +0100, Krzysztof Halasa wrote:
> ARM: support big/little endian switching in "bootz".
> Perhaps one should make this conditional? Mostly for big-endian
> Barebox loading little-endian (e.g. armel Debian) Linux.

Making it conditional could require a lot of ifdefs, maybe you could
just do...

> 
> Signed-off-by: Krzysztof Hałasa <khc@pm.waw.pl>
> 
> diff --git a/arch/arm/lib/armlinux.c b/arch/arm/lib/armlinux.c
> index f826da6..4d1c757 100644
> --- a/arch/arm/lib/armlinux.c
> +++ b/arch/arm/lib/armlinux.c
> @@ -41,6 +41,7 @@
>  #include <asm/setup.h>
>  #include <asm/barebox-arm.h>
>  #include <asm/armlinux.h>
> +#include <asm/system.h>
>  
>  static struct tag *params;
>  static int armlinux_architecture = 0;
> @@ -85,9 +86,10 @@ static void setup_memory_tags(void)
>  	}
>  }
>  
> -static void setup_commandline_tag(const char *commandline)
> +static void setup_commandline_tag(const char *commandline, int swap)
>  {
>  	const char *p;
> +	size_t words;
>  
>  	if (!commandline)
>  		return;
> @@ -102,12 +104,18 @@ static void setup_commandline_tag(const char *commandline)
>  	if (*p == '\0')
>  		return;
>  
> +	words = (strlen(p) + 1 /* NUL */ + 3 /* round up */) >> 2;
>  	params->hdr.tag = ATAG_CMDLINE;
> -	params->hdr.size =
> -	    (sizeof (struct tag_header) + strlen(p) + 1 + 4) >> 2;
> +	params->hdr.size = (sizeof(struct tag_header) >> 2) + words;
>  
>  	strcpy(params->u.cmdline.cmdline, p);
>  
> +	if (swap) {
> +		u32 *cmd = (u32 *)params->u.cmdline.cmdline;
> +		while (words--)
> +			cmd[words] = swab32(cmd[words]);
> +	}
> +
>  	params = tag_next(params);
>  }
>  
> @@ -156,13 +164,13 @@ static void setup_end_tag (void)
>  	params->hdr.size = 0;
>  }
>  
> -static void setup_tags(struct image_data *data)
> +static void setup_tags(struct image_data *data, int swap)
>  {
>  	const char *commandline = getenv("bootargs");
>  
>  	setup_start_tag();
>  	setup_memory_tags();
> -	setup_commandline_tag(commandline);
> +	setup_commandline_tag(commandline, swap);
>  
>  	if (data && data->initrd)
>  		setup_initrd_tag (&data->initrd->header);
> @@ -231,7 +239,7 @@ static int do_bootm_linux(struct image_data *data)
>  	debug("## Transferring control to Linux (at address 0x%p) ...\n",
>  	       theKernel);
>  
> -	setup_tags(data);
> +	setup_tags(data, 0);
>  
>  	if (relocate_image(data->os, (void *)image_get_load(os_header)))
>  		return -1;
> @@ -290,18 +298,21 @@ late_initcall(armlinux_register_image_handler);
>  
>  #ifdef CONFIG_CMD_BOOTZ
>  struct zimage_header {
> -	u32	unsused[9];
> +	u32	unused[9];
>  	u32	magic;
>  	u32	start;
>  	u32	end;
>  };
>  
> +#define ZIMAGE_MAGIC 0x016F2818
> +
>  static int do_bootz(struct command *cmdtp, int argc, char *argv[])
>  {
>  	void (*theKernel)(int zero, int arch, void *params);
> -	int fd, ret;
> +	int fd, ret, swap = 0;
>  	struct zimage_header header;
>  	void *zimage;
> +	u32 end;

#ifdef CONFIG_BOOTZ_ENDIANESS_SWAP
	int enable_swap = 1;
#else
	int enable_swap = 0;
#endif

>  
>  	if (argc != 2) {
>  		barebox_cmd_usage(cmdtp);
> @@ -320,27 +331,51 @@ static int do_bootz(struct command *cmdtp, int argc, char *argv[])
>  		goto err_out;
>  	}
>  
> -	if (header.magic != 0x016f2818) {
> +	switch (header.magic) {
> +	case swab32(ZIMAGE_MAGIC):
> +		swap = 1;

		swap = enable_swap;

This should be enough for the compiler to throw away most overhead.

> +		/* fall through */
> +	case ZIMAGE_MAGIC:
> +		break;
> +	default:
>  		printf("invalid magic 0x%08x\n", header.magic);
>  		goto err_out;
>  	}
>  
> -	zimage = xmalloc(header.end);
> +	end = header.end;
> +
> +	if (swap)
> +		end = swab32(end);
> +
> +	zimage = xmalloc(end);
>  	memcpy(zimage, &header, sizeof(header));
>  
> -	ret = read(fd, zimage + sizeof(header), header.end - sizeof(header));
> -	if (ret < header.end - sizeof(header)) {
> +	ret = read(fd, zimage + sizeof(header), end - sizeof(header));
> +	if (ret < end - sizeof(header)) {
>  		printf("could not read %s\n", argv[1]);
>  		goto err_out1;
>  	}
>  
> +	if (swap) {
> +		void *ptr;
> +		for (ptr = zimage; ptr < zimage + end; ptr += 4)
> +			*(u32 *)ptr = swab32(*(u32 *)ptr);
> +	}
> +
>  	theKernel = zimage;
>  
> -	printf("loaded zImage from %s with size %d\n", argv[1], header.end);
> +	printf("loaded zImage from %s with size %d\n", argv[1], end);
>  
> -	setup_tags(NULL);
> +	setup_tags(NULL, swap);
>  
>  	shutdown_barebox();
> +	if (swap) {
> +		u32 reg;
> +		__asm__ __volatile__("mrc p15, 0, %0, c1, c0" : "=r" (reg));
> +		reg ^= CR_B; /* swap big-endian flag */
> +		__asm__ __volatile__("mcr p15, 0, %0, c1, c0" :: "r" (reg));
> +	}
> +
>  	theKernel(0, armlinux_architecture, armlinux_bootparams);
>  
>  	return 0;
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox

-- 
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:[~2010-12-21  7:41 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-12-20 22:30 my IXP4xx-related and other patches Krzysztof Halasa
2010-12-20 22:40 ` [PATCH 1] Delete unused file common/dlmalloc.src Krzysztof Halasa
2010-12-21  9:34   ` Sascha Hauer
2010-12-20 22:42 ` [PATCH 2] Remove unused eth_get_name() prototype Krzysztof Halasa
2010-12-20 22:44 ` [PATCH 3] Flash CFI: removed unused 'size' variable Krzysztof Halasa
2010-12-20 22:45 ` [PATCH 4] Fix help text for "loadb" and "loady" commands Krzysztof Halasa
2010-12-20 22:54 ` [PATCH 5] Fix error handling with malloc, memalign etc. Memalign() can't fail now Krzysztof Halasa
2010-12-21  8:58   ` Sascha Hauer
2010-12-22  0:58   ` Jean-Christophe PLAGNIOL-VILLARD
2010-12-22 19:00     ` Krzysztof Halasa
2010-12-23 11:25       ` Krzysztof Halasa
2010-12-23 10:36     ` Sascha Hauer
2010-12-20 22:58 ` [PATCH 6] ARM: support big/little endian switching in "bootz" Krzysztof Halasa
2010-12-21  7:41   ` Sascha Hauer [this message]
2010-12-22  1:00   ` Jean-Christophe PLAGNIOL-VILLARD
2010-12-22 18:55     ` Krzysztof Halasa
2010-12-23 10:47       ` Sascha Hauer
2010-12-20 23:01 ` [PATCH 7] Fix top-level Makefile to work with GNU make 3.82 Krzysztof Halasa
2010-12-20 23:02 ` [PATCH 8] Cosmetic fixes, including format attributes for printf() and friends Krzysztof Halasa
2010-12-20 23:04 ` [PATCH 9] ARM: support big-endian processors Krzysztof Halasa
2010-12-20 23:06 ` [PATCH 10] ARM: Add support for IXP4xx CPU and for Goramo Multilink router platform Krzysztof Halasa
2010-12-21  7:42   ` Belisko Marek
2010-12-21  9:25     ` Sascha Hauer
2010-12-21  9:30     ` Juergen Beisert
2010-12-21  8:35   ` Sascha Hauer
2010-12-22  0:48     ` Krzysztof Halasa
2010-12-22  0:57   ` Jean-Christophe PLAGNIOL-VILLARD
2010-12-22 12:46     ` Sascha Hauer
2010-12-22 19:36       ` Krzysztof Halasa
2010-12-23  3:26         ` Jean-Christophe PLAGNIOL-VILLARD
2010-12-23 11:42           ` Krzysztof Halasa
2010-12-22 19:13     ` Krzysztof Halasa
2010-12-20 23:08 ` [PATCH 11] Silence few warnings Krzysztof Halasa
2010-12-20 23:10 ` [PATCH 12] Fix NOR CFI flash driver to work on big endian systems Krzysztof Halasa
2010-12-22  1:01   ` Jean-Christophe PLAGNIOL-VILLARD
2010-12-22 12:48     ` Sascha Hauer
2010-12-20 23:14 ` [PATCH 13] Fix usage of __LITTLE_ENDIAN macro Krzysztof Halasa
2010-12-21  9:17 ` my IXP4xx-related and other patches Sascha Hauer
2010-12-22  0:51 ` [PATCH 5a] Fix error handling with malloc, memalign etc. Introduce xmemalign() Krzysztof Halasa
2010-12-22  0:53 ` [PATCH 6a] ARM: support big/little endian switching in "bootz" Krzysztof Halasa
2010-12-22  0:55 ` [PATCH 10a] ARM: Add support for IXP4xx CPU and for Goramo Multilink router platform Krzysztof Halasa

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=20101221074155.GU6017@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=khc@pm.waw.pl \
    /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