[U-Boot] [PATCH] Building of FIT images does not work.

The type is not set for generation of the FIT images, resulting in no images being created without printing or returning an error
Signed-off-by: Remy Bohmer linux@bohmer.net --- tools/mkimage.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/tools/mkimage.c b/tools/mkimage.c index ab6ea32..8a20594 100644 --- a/tools/mkimage.c +++ b/tools/mkimage.c @@ -229,6 +229,7 @@ main (int argc, char **argv) case 'f': if (--argc <= 0) usage (); + params.type = IH_TYPE_FLATDT; params.datafile = *++argv; params.fflag = 1; goto NXTARG;

mkimage does not build due to missing strtok_r() and getline() implementation
Signed-off-by: Remy Bohmer linux@bohmer.net --- tools/mingw_support.c | 157 +++++++++++++++++++++++++++++++++++++++++++++++++ tools/mingw_support.h | 2 + 2 files changed, 159 insertions(+), 0 deletions(-)
diff --git a/tools/mingw_support.c b/tools/mingw_support.c index 67cd6e1..6379710 100644 --- a/tools/mingw_support.c +++ b/tools/mingw_support.c @@ -24,7 +24,9 @@ #include "mingw_support.h" #include <stdio.h> #include <stdint.h> +#include <string.h> #include <errno.h> +#include <assert.h> #include <io.h>
int fsync(int fd) @@ -77,3 +79,158 @@ int munmap(void *addr, size_t len)
return 0; } + +/* Reentrant string tokenizer. Generic version. + Copyright (C) 1991,1996-1999,2001,2004,2007 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + This program 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 2, or (at your option) + any later version. + + This program 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 this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* Parse S into tokens separated by characters in DELIM. + If S is NULL, the saved pointer in SAVE_PTR is used as + the next starting point. For example: + char s[] = "-abc-=-def"; + char *sp; + x = strtok_r(s, "-", &sp); // x = "abc", sp = "=-def" + x = strtok_r(NULL, "-=", &sp); // x = "def", sp = NULL + x = strtok_r(NULL, "=", &sp); // x = NULL + // s = "abc\0-def\0" +*/ +char *strtok_r(char *s, const char *delim, char **save_ptr) +{ + char *token; + + if (s == NULL) + s = *save_ptr; + + /* Scan leading delimiters. */ + s += strspn(s, delim); + if (*s == '\0') { + *save_ptr = s; + return NULL; + } + + /* Find the end of the token. */ + token = s; + s = strpbrk (token, delim); + if (s == NULL) { + /* This token finishes the string. */ + *save_ptr = memchr(token, '\0', strlen(token)); + } else { + /* Terminate the token and make *SAVE_PTR point past it. */ + *s = '\0'; + *save_ptr = s + 1; + } + return token; +} + +/* getline.c -- Replacement for GNU C library function getline + +Copyright (C) 1993, 1996, 2001, 2002 Free Software Foundation, Inc. + +This program 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 2 of the +License, or (at your option) any later version. + +This program 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 this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + +/* Written by Jan Brittenson, bson@gnu.ai.mit.edu. */ + +/* Always add at least this many bytes when extending the buffer. */ +#define MIN_CHUNK 64 + +/* Read up to (and including) a TERMINATOR from STREAM into *LINEPTR + + OFFSET (and null-terminate it). *LINEPTR is a pointer returned from + malloc (or NULL), pointing to *N characters of space. It is realloc'd + as necessary. Return the number of characters read (not including the + null terminator), or -1 on error or EOF. + NOTE: There is another getstr() function declared in <curses.h>. */ +static int getstr(char **lineptr, size_t *n, FILE *stream, + char terminator, size_t offset) +{ + int nchars_avail; /* Allocated but unused chars in *LINEPTR. */ + char *read_pos; /* Where we're reading into *LINEPTR. */ + int ret; + + if (!lineptr || !n || !stream) + return -1; + + if (!*lineptr) { + *n = MIN_CHUNK; + *lineptr = malloc(*n); + if (!*lineptr) + return -1; + } + + nchars_avail = *n - offset; + read_pos = *lineptr + offset; + + for (;;) { + register int c = getc(stream); + + /* We always want at least one char left in the buffer, since we + always (unless we get an error while reading the first char) + NUL-terminate the line buffer. */ + + assert(*n - nchars_avail == read_pos - *lineptr); + if (nchars_avail < 2) { + if (*n > MIN_CHUNK) + *n *= 2; + else + *n += MIN_CHUNK; + + nchars_avail = *n + *lineptr - read_pos; + *lineptr = realloc(*lineptr, *n); + if (!*lineptr) + return -1; + read_pos = *n - nchars_avail + *lineptr; + assert(*n - nchars_avail == read_pos - *lineptr); + } + + if (c == EOF || ferror (stream)) { + /* Return partial line, if any. */ + if (read_pos == *lineptr) + return -1; + else + break; + } + + *read_pos++ = c; + nchars_avail--; + + if (c == terminator) + /* Return the line. */ + break; + } + + /* Done - NUL terminate and return the number of chars read. */ + *read_pos = '\0'; + + ret = read_pos - (*lineptr + offset); + return ret; +} + +int getline (char **lineptr, size_t *n, FILE *stream) +{ + return getstr(lineptr, n, stream, '\n', 0); +} diff --git a/tools/mingw_support.h b/tools/mingw_support.h index 9e45e64..2793674 100644 --- a/tools/mingw_support.h +++ b/tools/mingw_support.h @@ -44,5 +44,7 @@ typedef ULONG ulong; int fsync(int fd); void *mmap(void *, size_t, int, int, int, int); int munmap(void *, size_t); +char *strtok_r(char *s, const char *delim, char **save_ptr); +int getline(char **lineptr, size_t *n, FILE *stream);
#endif /* __MINGW_SUPPORT_H_ */

The only missing chipselect line support is CS2, and I need it on CS2...
Signed-off-by: Remy Bohmer linux@bohmer.net --- drivers/spi/atmel_dataflash_spi.c | 18 ++++++++++++++++-- 1 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/drivers/spi/atmel_dataflash_spi.c b/drivers/spi/atmel_dataflash_spi.c index 614965c..3a648e6 100644 --- a/drivers/spi/atmel_dataflash_spi.c +++ b/drivers/spi/atmel_dataflash_spi.c @@ -30,7 +30,8 @@ #include <dataflash.h>
#define AT91_SPI_PCS0_DATAFLASH_CARD 0xE /* Chip Select 0: NPCS0%1110 */ -#define AT91_SPI_PCS1_DATAFLASH_CARD 0xD /* Chip Select 0: NPCS0%1101 */ +#define AT91_SPI_PCS1_DATAFLASH_CARD 0xD /* Chip Select 1: NPCS1%1101 */ +#define AT91_SPI_PCS2_DATAFLASH_CARD 0xB /* Chip Select 2: NPCS2%1011 */ #define AT91_SPI_PCS3_DATAFLASH_CARD 0x7 /* Chip Select 3: NPCS3%0111 */
void AT91F_SpiInit(void) @@ -57,7 +58,14 @@ void AT91F_SpiInit(void) ((get_mck_clk_rate() / AT91_SPI_CLK) << 8), AT91_BASE_SPI + AT91_SPI_CSR(1)); #endif - +#ifdef CONFIG_SYS_DATAFLASH_LOGIC_ADDR_CS2 + /* Configure CS2 */ + writel(AT91_SPI_NCPHA | + (AT91_SPI_DLYBS & DATAFLASH_TCSS) | + (AT91_SPI_DLYBCT & DATAFLASH_TCHS) | + ((get_mck_clk_rate() / AT91_SPI_CLK) << 8), + AT91_BASE_SPI + AT91_SPI_CSR(2)); +#endif #ifdef CONFIG_SYS_DATAFLASH_LOGIC_ADDR_CS3 /* Configure CS3 */ writel(AT91_SPI_NCPHA | @@ -99,6 +107,12 @@ void AT91F_SpiEnable(int cs) writel(mode | ((AT91_SPI_PCS1_DATAFLASH_CARD<<16) & AT91_SPI_PCS), AT91_BASE_SPI + AT91_SPI_MR); break; + case 2: /* Configure SPI CS2 for Serial DataFlash AT45DBxx */ + mode = readl(AT91_BASE_SPI + AT91_SPI_MR); + mode &= 0xFFF0FFFF; + writel(mode | ((AT91_SPI_PCS2_DATAFLASH_CARD<<16) & AT91_SPI_PCS), + AT91_BASE_SPI + AT91_SPI_MR); + break; case 3: mode = readl(AT91_BASE_SPI + AT91_SPI_MR); mode &= 0xFFF0FFFF;

The current generic code for handling unaligned access assumes that the processor can properly handle unaligned accesses itself. This is at least not the case for ARM, which results in runtime errors.
Rewrite it such that it works for ARM as well.
Signed-off-by: Remy Bohmer linux@bohmer.net --- include/linux/unaligned/access_ok.h | 48 ++++++++++++++++++++++++---------- 1 files changed, 34 insertions(+), 14 deletions(-)
diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h index 5f46eee..172124f 100644 --- a/include/linux/unaligned/access_ok.h +++ b/include/linux/unaligned/access_ok.h @@ -1,66 +1,86 @@ #ifndef _LINUX_UNALIGNED_ACCESS_OK_H #define _LINUX_UNALIGNED_ACCESS_OK_H
-#include <asm/byteorder.h> - static inline u16 get_unaligned_le16(const void *p) { - return le16_to_cpup((__le16 *)p); + const u8 *__p = p; + return __p[0] | __p[1] << 8; }
static inline u32 get_unaligned_le32(const void *p) { - return le32_to_cpup((__le32 *)p); + const u8 *__p = p; + return __p[0] | __p[1] << 8 | __p[2] << 16 | __p[3] << 24; }
static inline u64 get_unaligned_le64(const void *p) { - return le64_to_cpup((__le64 *)p); + const u8 *__p = p; + return (unsigned long long) + get_unaligned_le32((__p + 4)) << 32 | + get_unaligned_le32(__p); }
static inline u16 get_unaligned_be16(const void *p) { - return be16_to_cpup((__be16 *)p); + const u8 *__p = p; + return __p[0] << 8 | __p[1]; }
static inline u32 get_unaligned_be32(const void *p) { - return be32_to_cpup((__be32 *)p); + const u8 *__p = p; + return __p[0] << 24 | __p[1] << 16 | __p[2] << 8 | __p[3]; }
static inline u64 get_unaligned_be64(const void *p) { - return be64_to_cpup((__be64 *)p); + const u8 *__p = p; + return (unsigned long long) + get_unaligned_be32(__p) << 32 | + get_unaligned_be32((__p + 4)); }
static inline void put_unaligned_le16(u16 val, void *p) { - *((__le16 *)p) = cpu_to_le16(val); + u8 *__p = p; + *__p++ = val; + *__p++ = val >> 8; }
static inline void put_unaligned_le32(u32 val, void *p) { - *((__le32 *)p) = cpu_to_le32(val); + u8 *__p = p; + put_unaligned_le16(val >> 16, __p + 2); + put_unaligned_le16(val, __p); }
static inline void put_unaligned_le64(u64 val, void *p) { - *((__le64 *)p) = cpu_to_le64(val); + u8 *__p = p; + put_unaligned_le32(val >> 32, __p + 4); + put_unaligned_le32(val, __p); }
static inline void put_unaligned_be16(u16 val, void *p) { - *((__be16 *)p) = cpu_to_be16(val); + u8 *__p = p; + *__p++ = val >> 8; + *__p++ = val; }
static inline void put_unaligned_be32(u32 val, void *p) { - *((__be32 *)p) = cpu_to_be32(val); + u8 *__p = p; + put_unaligned_be16(val >> 16, __p); + put_unaligned_be16(val, __p + 2); }
static inline void put_unaligned_be64(u64 val, void *p) { - *((__be64 *)p) = cpu_to_be64(val); + u8 *__p = p; + put_unaligned_be32(val >> 32, __p); + put_unaligned_be32(val, __p + 4); }
#endif /* _LINUX_UNALIGNED_ACCESS_OK_H */

'netretry = once' does the same as 'netretry = yes', because it is not stored when it was tried once.
Signed-off-by: Remy Bohmer linux@bohmer.net --- net/net.c | 34 +++++++++++++++++++++++++--------- 1 files changed, 25 insertions(+), 9 deletions(-)
diff --git a/net/net.c b/net/net.c index cab4b2d..fd13cd9 100644 --- a/net/net.c +++ b/net/net.c @@ -197,6 +197,8 @@ volatile uchar *NetTxPacket = 0; /* THE transmit packet */
static int net_check_prereq (proto_t protocol);
+static int NetTryCount; + /**********************************************************************/
IPaddr_t NetArpWaitPacketIP; @@ -320,6 +322,7 @@ NetLoop(proto_t protocol) NetArpWaitReplyIP = 0; NetArpWaitTxPacket = NULL; NetTxPacket = NULL; + NetTryCount = 1;
if (!NetTxPacket) { int i; @@ -558,17 +561,30 @@ startAgainHandler(uchar * pkt, unsigned dest, unsigned src, unsigned len) void NetStartAgain (void) { char *nretry; - int noretry = 0, once = 0; + int retry_forever = 0; + unsigned long retrycnt = 0; + + nretry = getenv("netretry"); + if (nretry) { + if (!strcmp(nretry, "yes")) + retry_forever = 1; + else if (!strcmp(nretry, "no")) + retrycnt = 0; + else if (!strcmp(nretry, "once")) + retrycnt = 1; + else + retrycnt = simple_strtoul(nretry, NULL, 0); + } else + retry_forever = 1;
- if ((nretry = getenv ("netretry")) != NULL) { - noretry = (strcmp (nretry, "no") == 0); - once = (strcmp (nretry, "once") == 0); - } - if (noretry) { - eth_halt (); + if ((!retry_forever) && (NetTryCount >= retrycnt)) { + eth_halt(); NetState = NETLOOP_FAIL; return; } + + NetTryCount++; + #ifndef CONFIG_NET_MULTI NetSetTimeout (10000UL, startAgainTimeout); NetSetHandler (startAgainHandler); @@ -580,7 +596,7 @@ void NetStartAgain (void) eth_init (gd->bd); if (NetRestartWrap) { NetRestartWrap = 0; - if (NetDevExists && !once) { + if (NetDevExists) { NetSetTimeout (10000UL, startAgainTimeout); NetSetHandler (startAgainHandler); } else {

Signed-off-by: Remy Bohmer linux@bohmer.net --- net/tftp.c | 32 +++++++++++++++++++++++++++++--- 1 files changed, 29 insertions(+), 3 deletions(-)
diff --git a/net/tftp.c b/net/tftp.c index cc60a3b..d254f49 100644 --- a/net/tftp.c +++ b/net/tftp.c @@ -47,6 +47,16 @@ static int TftpTimeoutCountMax = TIMEOUT_COUNT; ulong TftpRRQTimeoutMSecs = TIMEOUT; int TftpRRQTimeoutCountMax = TIMEOUT_COUNT;
+enum { + TFTP_ERR_UNDEFINED = 0, + TFTP_ERR_FILE_NOT_FOUND = 1, + TFTP_ERR_ACCESS_DENIED = 2, + TFTP_ERR_DISK_FULL = 3, + TFTP_ERR_UNEXPECTED_OPCODE = 4, + TFT_ERR_UNKNOWN_TRANSFER_ID = 5, + TFTP_ERR_FILE_ALREADY_EXISTS = 6, +}; + static IPaddr_t TftpServerIP; static int TftpServerPort; /* The UDP port at their end */ static int TftpOurPort; /* The UDP port at our end */ @@ -472,11 +482,27 @@ TftpHandler (uchar * pkt, unsigned dest, unsigned src, unsigned len) case TFTP_ERROR: printf ("\nTFTP error: '%s' (%d)\n", pkt + 2, ntohs(*(ushort *)pkt)); - puts ("Starting again\n\n"); + + switch (ntohs(*(ushort *)pkt)) { + case TFTP_ERR_FILE_NOT_FOUND: + case TFTP_ERR_ACCESS_DENIED: + puts("Not retrying...\n"); + eth_halt(); + NetState = NETLOOP_FAIL; + break; + case TFTP_ERR_UNDEFINED: + case TFTP_ERR_DISK_FULL: + case TFTP_ERR_UNEXPECTED_OPCODE: + case TFT_ERR_UNKNOWN_TRANSFER_ID: + case TFTP_ERR_FILE_ALREADY_EXISTS: + default: + puts("Starting again\n\n"); #ifdef CONFIG_MCAST_TFTP - mcast_cleanup(); + mcast_cleanup(); #endif - NetStartAgain (); + NetStartAgain(); + break; + } break; } }

Signed-off-by: Remy Bohmer linux@bohmer.net --- common/cmd_bootm.c | 2 +- common/image.c | 2 ++ 2 files changed, 3 insertions(+), 1 deletions(-)
diff --git a/common/cmd_bootm.c b/common/cmd_bootm.c index 8f83598..32fd9bb 100644 --- a/common/cmd_bootm.c +++ b/common/cmd_bootm.c @@ -524,7 +524,7 @@ int do_bootm_subcommand (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) } break; #endif -#ifdef CONFIG_OF_LIBFDT +#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_SYS_BOOTMAPSZ) case BOOTM_STATE_FDT: { ulong bootmap_base = getenv_bootm_low(); diff --git a/common/image.c b/common/image.c index 6eaf41e..41b584d 100644 --- a/common/image.c +++ b/common/image.c @@ -1506,9 +1506,11 @@ int boot_get_fdt (int flag, int argc, char *argv[], bootm_headers_t *images, fdt_blob = (char *)data; }
+#if defined(CONFIG_PPC) images->fit_hdr_fdt = fit_hdr; images->fit_uname_fdt = fit_uname_fdt; images->fit_noffset_fdt = fdt_noffset; +#endif break; } else #endif

Dear Remy Bohmer,
please pay a little more attention to the commit subjects (here: s/beng/being/, please); also, make sure the subject is short enough for a commit message title line.
In message 1256764421-27799-7-git-send-email-linux@bohmer.net you wrote:
Signed-off-by: Remy Bohmer linux@bohmer.net
common/cmd_bootm.c | 2 +- common/image.c | 2 ++ 2 files changed, 3 insertions(+), 1 deletions(-)
diff --git a/common/cmd_bootm.c b/common/cmd_bootm.c index 8f83598..32fd9bb 100644 --- a/common/cmd_bootm.c +++ b/common/cmd_bootm.c @@ -524,7 +524,7 @@ int do_bootm_subcommand (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) } break; #endif -#ifdef CONFIG_OF_LIBFDT +#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_SYS_BOOTMAPSZ) case BOOTM_STATE_FDT: { ulong bootmap_base = getenv_bootm_low(); diff --git a/common/image.c b/common/image.c index 6eaf41e..41b584d 100644 --- a/common/image.c +++ b/common/image.c @@ -1506,9 +1506,11 @@ int boot_get_fdt (int flag, int argc, char *argv[], bootm_headers_t *images, fdt_blob = (char *)data; }
+#if defined(CONFIG_PPC) images->fit_hdr_fdt = fit_hdr; images->fit_uname_fdt = fit_uname_fdt; images->fit_noffset_fdt = fdt_noffset; +#endif
NAK. This code is in no way dependent on the Power architecture, so CONFIG_PPC is definitly the wrong thing to check for.
Best regards,
Wolfgang Denk

Hi Wolfgang,
2009/10/29 Wolfgang Denk wd@denx.de:
Dear Remy Bohmer,
please pay a little more attention to the commit subjects (here: s/beng/being/, please); also, make sure the subject is short enough for a commit message title line.
OK.
+#if defined(CONFIG_PPC) images->fit_hdr_fdt = fit_hdr; images->fit_uname_fdt = fit_uname_fdt; images->fit_noffset_fdt = fdt_noffset; +#endif
NAK. This code is in no way dependent on the Power architecture, so CONFIG_PPC is definitly the wrong thing to check for.
Well, in include/image.h, line 223 this is listed: ------------------------------------------------------------------------------- #if defined(CONFIG_PPC) void *fit_hdr_fdt; /* FDT blob FIT image header */ const char *fit_uname_fdt; /* FDT blob subimage node unit name */ int fit_noffset_fdt;/* FDT blob subimage node offset */ #endif -------------------------------------------------------------------------------
So, you are saying the bug is in the header as well? (I just made the code compliant to the ifdef in the header ;-) )
Kind regards,
Remy

Dear Remy,
In message 3efb10970910290435y67cd1c37q6152e58de02678a1@mail.gmail.com you wrote:
NAK. This code is in no way dependent on the Power architecture, so CONFIG_PPC is definitly the wrong thing to check for.
Well, in include/image.h, line 223 this is listed:
...
So, you are saying the bug is in the header as well? (I just made the code compliant to the ifdef in the header ;-) )
If you could clean up that part, too, it wouldbe welcome.
Best regards,
Wolfgang Denk

Remy Bohmer wrote:
Signed-off-by: Remy Bohmer linux@bohmer.net
net/tftp.c | 32 +++++++++++++++++++++++++++++--- 1 files changed, 29 insertions(+), 3 deletions(-)
diff --git a/net/tftp.c b/net/tftp.c index cc60a3b..d254f49 100644 --- a/net/tftp.c +++ b/net/tftp.c @@ -47,6 +47,16 @@ static int TftpTimeoutCountMax = TIMEOUT_COUNT; ulong TftpRRQTimeoutMSecs = TIMEOUT; int TftpRRQTimeoutCountMax = TIMEOUT_COUNT;
+enum {
- TFTP_ERR_UNDEFINED = 0,
- TFTP_ERR_FILE_NOT_FOUND = 1,
- TFTP_ERR_ACCESS_DENIED = 2,
- TFTP_ERR_DISK_FULL = 3,
- TFTP_ERR_UNEXPECTED_OPCODE = 4,
- TFT_ERR_UNKNOWN_TRANSFER_ID = 5,
Applied to net/next after fixing typo in last enum
regards, Ben

Hi Remy,
Remy Bohmer wrote:
'netretry = once' does the same as 'netretry = yes', because it is not stored when it was tried once.
Signed-off-by: Remy Bohmer linux@bohmer.net
net/net.c | 34 +++++++++++++++++++++++++--------- 1 files changed, 25 insertions(+), 9 deletions(-)
Applied to net/next.
thanks, Ben

Dear Ben Warren,
In message 4AF9080E.3050507@gmail.com you wrote:
Hi Remy,
Remy Bohmer wrote:
'netretry = once' does the same as 'netretry = yes', because it is not stored when it was tried once.
Signed-off-by: Remy Bohmer linux@bohmer.net
net/net.c | 34 +++++++++++++++++++++++++--------- 1 files changed, 25 insertions(+), 9 deletions(-)
Applied to net/next.
I think this is a bug fix and should go into this release (with a fix of the typo (s/netry/netretry/) in the Subject, of course).
Can you please do that? Thanks.
Best regards,
Wolfgang Denk

Hi Remy,
On Wednesday 28 October 2009 22:13:38 Remy Bohmer wrote:
The current generic code for handling unaligned access assumes that the processor can properly handle unaligned accesses itself. This is at least not the case for ARM, which results in runtime errors.
Rewrite it such that it works for ARM as well.
I introduced this header some time ago for UBIFS support (for PowerPC). As you may have noticed, it's a copy from the Linux version. And I would like to keep it this way if possible. Looking at the Linux ARM version, the basic difference seems to be the header "include/asm-arm/unaligned.h" which includes this file. The Linux version of "unaligned.h" does *not* include "access_ok.h" at all. It includes "le_byteshift.h" and "be_byteshift.h" instead. And I would really like to keep this in sync with Linux if possible.
So why not do it this way (totally untested):
From 3e9aa23a66041f05b94f94b1326941331248a487 Mon Sep 17 00:00:00 2001 From: Stefan Roese sr@denx.de Date: Thu, 29 Oct 2009 05:57:53 +0100 Subject: [PATCH] arm: Use Linux version for unaligned access code
Signed-off-by: Stefan Roese sr@denx.de --- include/asm-arm/unaligned.h | 3 +- include/linux/unaligned/be_byteshift.h | 70 ++++++++++++++++++++++++++++++++ include/linux/unaligned/le_byteshift.h | 70 ++++++++++++++++++++++++++++++++ 3 files changed, 142 insertions(+), 1 deletions(-) create mode 100644 include/linux/unaligned/be_byteshift.h create mode 100644 include/linux/unaligned/le_byteshift.h
diff --git a/include/asm-arm/unaligned.h b/include/asm-arm/unaligned.h index d644df7..44593a8 100644 --- a/include/asm-arm/unaligned.h +++ b/include/asm-arm/unaligned.h @@ -1,7 +1,8 @@ #ifndef _ASM_ARM_UNALIGNED_H #define _ASM_ARM_UNALIGNED_H
-#include <linux/unaligned/access_ok.h> +#include <linux/unaligned/le_byteshift.h> +#include <linux/unaligned/be_byteshift.h> #include <linux/unaligned/generic.h>
/* diff --git a/include/linux/unaligned/be_byteshift.h b/include/linux/unaligned/be_byteshift.h new file mode 100644 index 0000000..9356b24 --- /dev/null +++ b/include/linux/unaligned/be_byteshift.h @@ -0,0 +1,70 @@ +#ifndef _LINUX_UNALIGNED_BE_BYTESHIFT_H +#define _LINUX_UNALIGNED_BE_BYTESHIFT_H + +#include <linux/types.h> + +static inline u16 __get_unaligned_be16(const u8 *p) +{ + return p[0] << 8 | p[1]; +} + +static inline u32 __get_unaligned_be32(const u8 *p) +{ + return p[0] << 24 | p[1] << 16 | p[2] << 8 | p[3]; +} + +static inline u64 __get_unaligned_be64(const u8 *p) +{ + return (u64)__get_unaligned_be32(p) << 32 | + __get_unaligned_be32(p + 4); +} + +static inline void __put_unaligned_be16(u16 val, u8 *p) +{ + *p++ = val >> 8; + *p++ = val; +} + +static inline void __put_unaligned_be32(u32 val, u8 *p) +{ + __put_unaligned_be16(val >> 16, p); + __put_unaligned_be16(val, p + 2); +} + +static inline void __put_unaligned_be64(u64 val, u8 *p) +{ + __put_unaligned_be32(val >> 32, p); + __put_unaligned_be32(val, p + 4); +} + +static inline u16 get_unaligned_be16(const void *p) +{ + return __get_unaligned_be16((const u8 *)p); +} + +static inline u32 get_unaligned_be32(const void *p) +{ + return __get_unaligned_be32((const u8 *)p); +} + +static inline u64 get_unaligned_be64(const void *p) +{ + return __get_unaligned_be64((const u8 *)p); +} + +static inline void put_unaligned_be16(u16 val, void *p) +{ + __put_unaligned_be16(val, p); +} + +static inline void put_unaligned_be32(u32 val, void *p) +{ + __put_unaligned_be32(val, p); +} + +static inline void put_unaligned_be64(u64 val, void *p) +{ + __put_unaligned_be64(val, p); +} + +#endif /* _LINUX_UNALIGNED_BE_BYTESHIFT_H */ diff --git a/include/linux/unaligned/le_byteshift.h b/include/linux/unaligned/le_byteshift.h new file mode 100644 index 0000000..be376fb --- /dev/null +++ b/include/linux/unaligned/le_byteshift.h @@ -0,0 +1,70 @@ +#ifndef _LINUX_UNALIGNED_LE_BYTESHIFT_H +#define _LINUX_UNALIGNED_LE_BYTESHIFT_H + +#include <linux/types.h> + +static inline u16 __get_unaligned_le16(const u8 *p) +{ + return p[0] | p[1] << 8; +} + +static inline u32 __get_unaligned_le32(const u8 *p) +{ + return p[0] | p[1] << 8 | p[2] << 16 | p[3] << 24; +} + +static inline u64 __get_unaligned_le64(const u8 *p) +{ + return (u64)__get_unaligned_le32(p + 4) << 32 | + __get_unaligned_le32(p); +} + +static inline void __put_unaligned_le16(u16 val, u8 *p) +{ + *p++ = val; + *p++ = val >> 8; +} + +static inline void __put_unaligned_le32(u32 val, u8 *p) +{ + __put_unaligned_le16(val >> 16, p + 2); + __put_unaligned_le16(val, p); +} + +static inline void __put_unaligned_le64(u64 val, u8 *p) +{ + __put_unaligned_le32(val >> 32, p + 4); + __put_unaligned_le32(val, p); +} + +static inline u16 get_unaligned_le16(const void *p) +{ + return __get_unaligned_le16((const u8 *)p); +} + +static inline u32 get_unaligned_le32(const void *p) +{ + return __get_unaligned_le32((const u8 *)p); +} + +static inline u64 get_unaligned_le64(const void *p) +{ + return __get_unaligned_le64((const u8 *)p); +} + +static inline void put_unaligned_le16(u16 val, void *p) +{ + __put_unaligned_le16(val, p); +} + +static inline void put_unaligned_le32(u32 val, void *p) +{ + __put_unaligned_le32(val, p); +} + +static inline void put_unaligned_le64(u64 val, void *p) +{ + __put_unaligned_le64(val, p); +} + +#endif /* _LINUX_UNALIGNED_LE_BYTESHIFT_H */

Hi,
2009/10/29 Stefan Roese sr@denx.de:
Hi Remy,
On Wednesday 28 October 2009 22:13:38 Remy Bohmer wrote:
The current generic code for handling unaligned access assumes that the processor can properly handle unaligned accesses itself. This is at least not the case for ARM, which results in runtime errors.
Rewrite it such that it works for ARM as well.
I introduced this header some time ago for UBIFS support (for PowerPC). As you may have noticed, it's a copy from the Linux version. And I
Yep, I noticed that.
would like to keep it this way if possible.
I understand that, but still the code in there is not _generic_, it might work on Linux since the data-abort trapcode is handling this exception that occurs on unaligned accesses...
Looking at the Linux ARM version, the basic difference seems to be the header "include/asm-arm/unaligned.h" which includes this file. The Linux version of "unaligned.h" does *not* include "access_ok.h" at all. It includes "le_byteshift.h" and "be_byteshift.h" instead. And I would really like to keep this in sync with Linux if possible.
So why not do it this way (totally untested): From 3e9aa23a66041f05b94f94b1326941331248a487 Mon Sep 17 00:00:00 2001 From: Stefan Roese sr@denx.de Date: Thu, 29 Oct 2009 05:57:53 +0100 Subject: [PATCH] arm: Use Linux version for unaligned access code
Signed-off-by: Stefan Roese sr@denx.de
include/asm-arm/unaligned.h | 3 +- include/linux/unaligned/be_byteshift.h | 70 ++++++++++++++++++++++++++++++++ include/linux/unaligned/le_byteshift.h | 70 ++++++++++++++++++++++++++++++++ 3 files changed, 142 insertions(+), 1 deletions(-) create mode 100644 include/linux/unaligned/be_byteshift.h create mode 100644 include/linux/unaligned/le_byteshift.h
Indeed, this looks cleaner for ARM and it works as well... (hmm, looks more like the old code I was using which I removed from my USB-CDC-tree since the unaligned.h code was added to mainline...)
Please give it a try and feel free to submit this patch with a better commit text if it works for you.
Cheers, Stefan
I will clean it up and repost that patch. This patch can be ignored.
Kind Regards,
Remy

Remy Bohmer wrote:
Hi,
2009/10/29 Stefan Roese sr@denx.de:
Hi Remy,
On Wednesday 28 October 2009 22:13:38 Remy Bohmer wrote:
The current generic code for handling unaligned access assumes that the processor can properly handle unaligned accesses itself. This is at least not the case for ARM, which results in runtime errors.
Rewrite it such that it works for ARM as well.
I introduced this header some time ago for UBIFS support (for PowerPC). As you may have noticed, it's a copy from the Linux version. And I
Yep, I noticed that.
would like to keep it this way if possible.
I understand that, but still the code in there is not _generic_, it might work on Linux since the data-abort trapcode is handling this exception that occurs on unaligned accesses...
Looking at the Linux ARM version, the basic difference seems to be the header "include/asm-arm/unaligned.h" which includes this file. The Linux version of "unaligned.h" does *not* include "access_ok.h" at all. It includes "le_byteshift.h" and "be_byteshift.h" instead. And I would really like to keep this in sync with Linux if possible.
So why not do it this way (totally untested):
I see the patch has been reposted. Has it been tested ?
Tom

Hi Tom,
Looking at the Linux ARM version, the basic difference seems to be the header "include/asm-arm/unaligned.h" which includes this file. The Linux version of "unaligned.h" does *not* include "access_ok.h" at all. It includes "le_byteshift.h" and "be_byteshift.h" instead. And I would really like to keep this in sync with Linux if possible.
So why not do it this way (totally untested):
I see the patch has been reposted. Has it been tested ?
Yes, I have tested it, that is why I reposted it according to the suggestion of Stefan... :-)
Remy

Remy Bohmer wrote:
Hi Tom,
Looking at the Linux ARM version, the basic difference seems to be the header "include/asm-arm/unaligned.h" which includes this file. The Linux version of "unaligned.h" does *not* include "access_ok.h" at all. It includes "le_byteshift.h" and "be_byteshift.h" instead. And I would really like to keep this in sync with Linux if possible. So why not do it this way (totally untested):
I see the patch has been reposted. Has it been tested ?
Yes, I have tested it, that is why I reposted it according to the suggestion of Stefan... :-)
Remy
No MAKEALL arm regressions. pushed to arm/next.
Thanks, Tom

On Thursday 29 October 2009 16:34:43 Remy Bohmer wrote:
No MAKEALL arm regressions. pushed to arm/next.
Did you notice this is a bug fix? Shouldn't it go in this release?
Yes, I would recommend to push this into this release as well.
Cheers, Stefan
-- DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-0 Fax: (+49)-8142-66989-80 Email: office@denx.de

Stefan Roese wrote:
On Thursday 29 October 2009 16:34:43 Remy Bohmer wrote:
No MAKEALL arm regressions. pushed to arm/next.
Did you notice this is a bug fix? Shouldn't it go in this release?
Yes, I would recommend to push this into this release as well.
This is fine with me. Tom
Cheers, Stefan
-- DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-0 Fax: (+49)-8142-66989-80 Email: office@denx.de

Dear Remy Bohmer,
In message 1256764421-27799-4-git-send-email-linux@bohmer.net you wrote:
The current generic code for handling unaligned access assumes that the processor can properly handle unaligned accesses itself. This is at least not the case for ARM, which results in runtime errors.
Rewrite it such that it works for ARM as well.
Signed-off-by: Remy Bohmer linux@bohmer.net
include/linux/unaligned/access_ok.h | 48 ++++++++++++++++++++++++---------- 1 files changed, 34 insertions(+), 14 deletions(-)
Applied, thanks.
Best regards,
Wolfgang Denk

Hi Wolfgang,
On Monday 23 November 2009 23:46:38 Wolfgang Denk wrote:
Dear Remy Bohmer,
In message 1256764421-27799-4-git-send-email-linux@bohmer.net you wrote:
The current generic code for handling unaligned access assumes that the processor can properly handle unaligned accesses itself. This is at least not the case for ARM, which results in runtime errors.
Rewrite it such that it works for ARM as well.
Signed-off-by: Remy Bohmer linux@bohmer.net
include/linux/unaligned/access_ok.h | 48 ++++++++++++++++++++++++---------- 1 files changed, 34 insertions(+), 14 deletions(-)
Applied, thanks.
This shouldn't have been applied. Remy did send a different version of this patch (according to my suggestion), which is already included:
commit 25793f76bf9a7be59c9415ef0f78d034e8d53dae Author: Remy Bohmer linux@bohmer.net Date: Thu Oct 29 12:29:37 2009 +0100
ARM: Use Linux version for unaligned access code
The asm-arm/unaligned.h includes linux/unaligned/access_ok.h This file is unsafe to be used on ARM, since it does an unaligned memory accesses which fails on ARM.
Lookin at Linux the basic difference seems to be the header "include/asm-arm/unaligned.h". The Linux version of "unaligned.h" does *not* include "access_ok.h" at all. It includes "le_byteshift.h" and "be_byteshift.h" instead.
Signed-off-by: Remy Bohmer linux@bohmer.net Signed-off-by: Stefan Roese sr@denx.de
Remy, please correct me if I'm wrong here.
Cheers, Stefan
-- DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-0 Fax: (+49)-8142-66989-80 Email: office@denx.de

Hi Stefan,
2009/11/24 Stefan Roese sr@denx.de:
Hi Wolfgang,
On Monday 23 November 2009 23:46:38 Wolfgang Denk wrote:
Dear Remy Bohmer,
In message 1256764421-27799-4-git-send-email-linux@bohmer.net you wrote:
The current generic code for handling unaligned access assumes that the processor can properly handle unaligned accesses itself. This is at least not the case for ARM, which results in runtime errors.
Rewrite it such that it works for ARM as well.
Signed-off-by: Remy Bohmer linux@bohmer.net
include/linux/unaligned/access_ok.h | 48 ++++++++++++++++++++++++---------- 1 files changed, 34 insertions(+), 14 deletions(-)
Applied, thanks.
This shouldn't have been applied. Remy did send a different version of this patch (according to my suggestion), which is already included:
commit 25793f76bf9a7be59c9415ef0f78d034e8d53dae Author: Remy Bohmer linux@bohmer.net Date: Thu Oct 29 12:29:37 2009 +0100
ARM: Use Linux version for unaligned access code
The asm-arm/unaligned.h includes linux/unaligned/access_ok.h This file is unsafe to be used on ARM, since it does an unaligned memory accesses which fails on ARM.
Lookin at Linux the basic difference seems to be the header "include/asm-arm/unaligned.h". The Linux version of "unaligned.h" does *not* include "access_ok.h" at all. It includes "le_byteshift.h" and "be_byteshift.h" instead.
Signed-off-by: Remy Bohmer linux@bohmer.net Signed-off-by: Stefan Roese sr@denx.de
Remy, please correct me if I'm wrong here.
You are right. This patch should not have been applied. The other patch was better.
Kind regards,
Remy

Dear Stefan Roese,
In message 200911240505.25360.sr@denx.de you wrote:
This shouldn't have been applied. Remy did send a different version of this patch (according to my suggestion), which is already included:
Argh... Thanks for pointing out. Fortunately no damage was done as I did not push this from my working repo upstream yet while I was still running some tests. I killed it there.
Thanks again.
Best regards,
Wolfgang Denk

Dear Remy Bohmer,
In message 1256764421-27799-3-git-send-email-linux@bohmer.net you wrote:
The only missing chipselect line support is CS2, and I need it on CS2...
Signed-off-by: Remy Bohmer linux@bohmer.net
drivers/spi/atmel_dataflash_spi.c | 18 ++++++++++++++++-- 1 files changed, 16 insertions(+), 2 deletions(-)
Applied, thanks.
Tom, I hope this is OK with you - seems harmless enough.
Best regards,
Wolfgang Denk

Dear Remy Bohmer,
In message 1256764421-27799-2-git-send-email-linux@bohmer.net you wrote:
mkimage does not build due to missing strtok_r() and getline() implementation
Signed-off-by: Remy Bohmer linux@bohmer.net
tools/mingw_support.c | 157 +++++++++++++++++++++++++++++++++++++++++++++++++ tools/mingw_support.h | 2 + 2 files changed, 159 insertions(+), 0 deletions(-)
Applied, thanks.
Best regards,
Wolfgang Denk

Dear Remy Bohmer,
In message 1256764421-27799-1-git-send-email-linux@bohmer.net you wrote:
The type is not set for generation of the FIT images, resulting in no images being created without printing or returning an error
Signed-off-by: Remy Bohmer linux@bohmer.net
tools/mkimage.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
Applied, thanks.
Best regards,
Wolfgang Denk
participants (5)
-
Ben Warren
-
Remy Bohmer
-
Stefan Roese
-
Tom
-
Wolfgang Denk