Skip to contentSkip to conversation

Fix u-boot compile on darwin host

PATCH New andreas.devel at googlemail.com 5 participants 9 messages Oct 24, 2014 – Oct 30, 2014

lore
Share & tools
lore
#0 lore raw

cover Fix u-boot compile on darwin host

From: Andreas Bie?mann <[email protected]>

This series make u-boot compile on OS X again, tested with Yosemite and Lion.

Andreas Bie?mann (2):
tools/socfpgaimage.c: fix build on darwin
tools/kwbimage.c: fix build on darwin

 tools/kwbimage.c     |  6 ++++--
 tools/socfpgaimage.c | 16 ++++++++--------
 2 files changed, 12 insertions(+), 10 deletions(-)
Signature · 1 line
1.9.3 (Apple Git-50)
#1 lore raw

PATCH 1/2 tools/socfpgaimage.c: fix build on darwin

From: Andreas Bie?mann <[email protected]>

socfpgaimage utilizes htole32 and friends, unfortunately these functions are not available on darwin. Fix it by using the cpu_to_le32 and friends defined in compiler.h as other parts in mkimage do.

This patch fixes the following error:
---8<---
HOSTCC tools/socfpgaimage.o
tools/socfpgaimage.c:77:22: warning: implicit declaration of function 'htole32' is invalid in C99 [-Wimplicit-function-declaration]

        header.validation = htole32(VALIDATION_WORD);
                            ^
tools/socfpgaimage.c:80:22: warning: implicit declaration of function 'htole16' is invalid in C99 [-Wimplicit-function-declaration]
        header.length_u32 = htole16(length_bytes/4);
                            ^
tools/socfpgaimage.c:95:6: warning: implicit declaration of function 'le32toh' is invalid in C99 [-Wimplicit-function-declaration]
        if (le32toh(header.validation) != VALIDATION_WORD)
            ^
tools/socfpgaimage.c:97:6: warning: implicit declaration of function 'le16toh' is invalid in C99 [-Wimplicit-function-declaration]
        if (le16toh(header.checksum) != hdr_checksum(&header))
            ^

4 warnings generated.
...
HOSTLD tools/dumpimage
Undefined symbols for architecture x86_64:
"_htole16", referenced from:
_socfpgaimage_set_header in socfpgaimage.o
"_htole32", referenced from:
_socfpgaimage_set_header in socfpgaimage.o
"_le16toh", referenced from:
_verify_buffer in socfpgaimage.o
"_le32toh", referenced from:
_verify_buffer in socfpgaimage.o
ld: symbol(s) not found for architecture x86_64
--->8---

---

 tools/socfpgaimage.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
tools/socfpgaimage.c +8 -8
index 396d8a5..917873e 100644
@@ -74,12 +74,12 @@ static uint16_t hdr_checksum(struct socfpga_header *header)
 static void build_header(uint8_t *buf, uint8_t version, uint8_t flags,
 			 uint16_t length_bytes)
 {
-	header.validation = htole32(VALIDATION_WORD);
+	header.validation = cpu_to_le32(VALIDATION_WORD);
 	header.version = version;
 	header.flags = flags;
-	header.length_u32 = htole16(length_bytes/4);
+	header.length_u32 = cpu_to_le16(length_bytes/4);
 	header.zero = 0;
-	header.checksum = htole16(hdr_checksum(&header));
+	header.checksum = cpu_to_le16(hdr_checksum(&header));
 
 	memcpy(buf, &header, sizeof(header));
 }
@@ -92,12 +92,12 @@ static int verify_header(const uint8_t *buf)
 {
 	memcpy(&header, buf, sizeof(header));
 
-	if (le32toh(header.validation) != VALIDATION_WORD)
+	if (le32_to_cpu(header.validation) != VALIDATION_WORD)
 		return -1;
-	if (le16toh(header.checksum) != hdr_checksum(&header))
+	if (le16_to_cpu(header.checksum) != hdr_checksum(&header))
 		return -1;
 
-	return le16toh(header.length_u32) * 4;
+	return le16_to_cpu(header.length_u32) * 4;
 }
 
 /* Sign the buffer and return the signed buffer size */
@@ -116,7 +116,7 @@ static int sign_buffer(uint8_t *buf,
 	/* Calculate and apply the CRC */
 	calc_crc = ~pbl_crc32(0, (char *)buf, len);
 
-	*((uint32_t *)(buf + len)) = htole32(calc_crc);
+	*((uint32_t *)(buf + len)) = cpu_to_le32(calc_crc);
 
 	if (!pad_64k)
 		return len + 4;
@@ -150,7 +150,7 @@ static int verify_buffer(const uint8_t *buf)
 
 	calc_crc = ~pbl_crc32(0, (const char *)buf, len);
 
-	buf_crc = le32toh(*((uint32_t *)(buf + len)));
+	buf_crc = le32_to_cpu(*((uint32_t *)(buf + len)));
 
 	if (buf_crc != calc_crc) {
 		fprintf(stderr, "CRC32 does not match (%08x != %08x)\n",
Signature · 1 line
1.9.3 (Apple Git-50)
#2 lore raw

PATCH 1/2 tools/socfpgaimage.c: fix build on darwin

Quoted 40 lines · andreas.devel at googlemail.com

From: Andreas Bie?mann <[email protected]>

socfpgaimage utilizes htole32 and friends, unfortunately these functions are not available on darwin. Fix it by using the cpu_to_le32 and friends defined in compiler.h as other parts in mkimage do.

This patch fixes the following error:
---8<---
HOSTCC tools/socfpgaimage.o
tools/socfpgaimage.c:77:22: warning: implicit declaration of function 'htole32' is invalid in C99 [-Wimplicit-function-declaration]

header.validation = htole32(VALIDATION_WORD);
                            ^
tools/socfpgaimage.c:80:22: warning: implicit declaration of function
'htole16' is invalid in C99 [-Wimplicit-function-declaration]
header.length_u32 = htole16(length_bytes/4);
                            ^
tools/socfpgaimage.c:95:6: warning: implicit declaration of function
'le32toh' is invalid in C99 [-Wimplicit-function-declaration] if
(le32toh(header.validation) != VALIDATION_WORD)
            ^
tools/socfpgaimage.c:97:6: warning: implicit declaration of function
'le16toh' is invalid in C99 [-Wimplicit-function-declaration] if
(le16toh(header.checksum) != hdr_checksum(&header))
            ^

4 warnings generated.
...
HOSTLD tools/dumpimage
Undefined symbols for architecture x86_64:
"_htole16", referenced from:
_socfpgaimage_set_header in socfpgaimage.o
"_htole32", referenced from:
_socfpgaimage_set_header in socfpgaimage.o
"_le16toh", referenced from:
_verify_buffer in socfpgaimage.o
"_le32toh", referenced from:
_verify_buffer in socfpgaimage.o
ld: symbol(s) not found for architecture x86_64
--->8---

Quoted 1 line

Best regards,
Marek Vasut

#3 lore raw

PATCH 1/2 tools/socfpgaimage.c: fix build on darwin

Quoted 41 lines · Marek Vasut
Quoted 40 lines · andreas.devel at googlemail.com

From: Andreas Bie?mann <[email protected]>

socfpgaimage utilizes htole32 and friends, unfortunately these functions are not available on darwin. Fix it by using the cpu_to_le32 and friends defined in compiler.h as other parts in mkimage do.

This patch fixes the following error:
---8<---
HOSTCC tools/socfpgaimage.o
tools/socfpgaimage.c:77:22: warning: implicit declaration of function 'htole32' is invalid in C99 [-Wimplicit-function-declaration]

header.validation = htole32(VALIDATION_WORD);
                            ^
tools/socfpgaimage.c:80:22: warning: implicit declaration of function
'htole16' is invalid in C99 [-Wimplicit-function-declaration]
header.length_u32 = htole16(length_bytes/4);
                            ^
tools/socfpgaimage.c:95:6: warning: implicit declaration of function
'le32toh' is invalid in C99 [-Wimplicit-function-declaration] if
(le32toh(header.validation) != VALIDATION_WORD)
            ^
tools/socfpgaimage.c:97:6: warning: implicit declaration of function
'le16toh' is invalid in C99 [-Wimplicit-function-declaration] if
(le16toh(header.checksum) != hdr_checksum(&header))
            ^

4 warnings generated.
...
HOSTLD tools/dumpimage
Undefined symbols for architecture x86_64:
"_htole16", referenced from:
_socfpgaimage_set_header in socfpgaimage.o
"_htole32", referenced from:
_socfpgaimage_set_header in socfpgaimage.o
"_le16toh", referenced from:
_verify_buffer in socfpgaimage.o
"_le32toh", referenced from:
_verify_buffer in socfpgaimage.o
ld: symbol(s) not found for architecture x86_64
--->8---

Quoted 3 lines
Quoted 1 line

Marek, do you want to take it to your tree? Tom was not cc-ed on the mail, so I'm not sure if you he'll apply it...
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Applied
#4 lore raw

PATCH 1/2 tools/socfpgaimage.c: fix build on darwin

Quoted 2 lines · Pavel Machek
Quoted 1 line · Marek Vasut

On Friday, October 24, 2014 at 11:39:10 PM, andreas.devel at googlemail.com

Quoted 53 lines · wrote:
Quoted 53 lines
Quoted 53 lines

From: Andreas Bie?mann <[email protected]>

socfpgaimage utilizes htole32 and friends, unfortunately these functions are not available on darwin. Fix it by using the cpu_to_le32 and friends defined in compiler.h as other parts in mkimage do.

This patch fixes the following error:
---8<---

HOSTCC tools/socfpgaimage.o

tools/socfpgaimage.c:77:22: warning: implicit declaration of function 'htole32' is invalid in C99 [-Wimplicit-function-declaration] header.validation = htole32(VALIDATION_WORD);

                            ^

tools/socfpgaimage.c:80:22: warning: implicit declaration of function 'htole16' is invalid in C99 [-Wimplicit-function-declaration] header.length_u32 = htole16(length_bytes/4);

                            ^

tools/socfpgaimage.c:95:6: warning: implicit declaration of function 'le32toh' is invalid in C99 [-Wimplicit-function-declaration] if (le32toh(header.validation) != VALIDATION_WORD)

            ^

tools/socfpgaimage.c:97:6: warning: implicit declaration of function 'le16toh' is invalid in C99 [-Wimplicit-function-declaration] if (le16toh(header.checksum) != hdr_checksum(&header))

            ^

4 warnings generated.
...

HOSTLD tools/dumpimage

Undefined symbols for architecture x86_64:
"_htole16", referenced from:
_socfpgaimage_set_header in socfpgaimage.o

"_htole32", referenced from:
_socfpgaimage_set_header in socfpgaimage.o

"_le16toh", referenced from:
_verify_buffer in socfpgaimage.o

"_le32toh", referenced from:
_verify_buffer in socfpgaimage.o

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

ld: symbol(s) not found for architecture x86_64
--->8---

Applied, thanks.

Best regards,
Marek Vasut

#5 lore raw

PATCH 2/2 tools/kwbimage.c: fix build on darwin

In reply to andreas.devel at googlemail.com

From: Andreas Bie?mann <[email protected]>

kwbimage uses get_current_dir_name(3) which is a gnu extension and not available on darwin host. Fix this by converting to portable getcwd(3) function.

This patch fixes the following error:
---8<---
HOSTCC tools/kwbimage.o
tools/kwbimage.c:399:16: warning: implicit declaration of function 'get_current_dir_name' is invalid in C99 [-Wimplicit-function-declaration]

                        char *cwd = get_current_dir_name();
                                    ^
tools/kwbimage.c:399:10: warning: incompatible integer to pointer conversion initializing 'char *' with an expression of type 'int' [-Wint-conversion]
                        char *cwd = get_current_dir_name();
                              ^     ~~~~~~~~~~~~~~~~~~~~~~

2 warnings generated.
...
Undefined symbols for architecture x86_64:
"_get_current_dir_name", referenced from:
_image_headersz_v1 in kwbimage.o
ld: symbol(s) not found for architecture x86_64
--->8---

---

 tools/kwbimage.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
tools/kwbimage.c +4 -2
index ca4fc78..8fd70ef 100644
@@ -12,6 +12,7 @@
  */
 
 #include "imagetool.h"
+#include <limits.h>
 #include <image.h>
 #include <stdint.h>
 #include "kwbimage.h"
@@ -396,13 +397,14 @@ static size_t image_headersz_v1(struct image_tool_params *params,
 
 		ret = stat(binarye->binary.file, &s);
 		if (ret < 0) {
-			char *cwd = get_current_dir_name();
+			char cwd[PATH_MAX];
+			memset(cwd, 0, sizeof(cwd));
+			getcwd(cwd, sizeof(cwd));
 			fprintf(stderr,
 				"Didn't find the file '%s' in '%s' which is mandatory to generate the image\n"
 				"This file generally contains the DDR3 training code, and should be extracted from an existing bootable\n"
 				"image for your board. See 'kwbimage -x' to extract it from an existing image.\n",
 				binarye->binary.file, cwd);
-			free(cwd);
 			return 0;
 		}
 
Signature · 1 line
1.9.3 (Apple Git-50)
#6 lore raw

PATCH 2/2 tools/kwbimage.c: fix build on darwin

Quoted 23 lines · andreas.devel at googlemail.com

From: Andreas Bie?mann <[email protected]>

kwbimage uses get_current_dir_name(3) which is a gnu extension and not available on darwin host. Fix this by converting to portable getcwd(3) function.

This patch fixes the following error:
---8<---
HOSTCC tools/kwbimage.o
tools/kwbimage.c:399:16: warning: implicit declaration of function 'get_current_dir_name' is invalid in C99 [-Wimplicit-function-declaration]

                         char *cwd = get_current_dir_name();
                                     ^
tools/kwbimage.c:399:10: warning: incompatible integer to pointer conversion initializing 'char *' with an expression of type 'int' [-Wint-conversion]
                         char *cwd = get_current_dir_name();
                               ^     ~~~~~~~~~~~~~~~~~~~~~~

2 warnings generated.
...
Undefined symbols for architecture x86_64:
"_get_current_dir_name", referenced from:
_image_headersz_v1 in kwbimage.o
ld: symbol(s) not found for architecture x86_64
--->8---

Quoted 2 lines

Thanks,
Stefan

#7 lore raw

PATCH 2/2 tools/kwbimage.c: fix build on darwin

In reply to andreas.devel at googlemail.com
Quoted 23 lines · On Fri, 24 Oct 2014 23:39:11 +0200 andreas.devel at googlemail.com wrote:

From: Andreas Bie?mann <[email protected]>

kwbimage uses get_current_dir_name(3) which is a gnu extension and not available on darwin host. Fix this by converting to portable getcwd(3) function.

This patch fixes the following error:
---8<---
HOSTCC tools/kwbimage.o
tools/kwbimage.c:399:16: warning: implicit declaration of function 'get_current_dir_name' is invalid in C99 [-Wimplicit-function-declaration]

                        char *cwd = get_current_dir_name();
                                    ^
tools/kwbimage.c:399:10: warning: incompatible integer to pointer conversion initializing 'char *' with an expression of type 'int' [-Wint-conversion]
                        char *cwd = get_current_dir_name();
                              ^     ~~~~~~~~~~~~~~~~~~~~~~

2 warnings generated.
...
Undefined symbols for architecture x86_64:
"_get_current_dir_name", referenced from:
_image_headersz_v1 in kwbimage.o
ld: symbol(s) not found for architecture x86_64
--->8---

Quoted 7 lines

---

 tools/kwbimage.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Applied to u-boot-staging. Thanks!

Anatolij

#8 lore raw

PATCH 2/2 tools/kwbimage.c: fix build on darwin

Quoted 29 lines · On Thu, 30 Oct 2014 23:11:03 +0100 Anatolij Gustschin <[email protected]> wrote:
Quoted 26 lines · On Fri, 24 Oct 2014 23:39:11 +0200 andreas.devel at googlemail.com wrote:

From: Andreas Bie?mann <[email protected]>

kwbimage uses get_current_dir_name(3) which is a gnu extension and not available on darwin host. Fix this by converting to portable getcwd(3) function.

This patch fixes the following error:
---8<---
HOSTCC tools/kwbimage.o
tools/kwbimage.c:399:16: warning: implicit declaration of function 'get_current_dir_name' is invalid in C99 [-Wimplicit-function-declaration]

                        char *cwd = get_current_dir_name();
                                    ^
tools/kwbimage.c:399:10: warning: incompatible integer to pointer conversion initializing 'char *' with an expression of type 'int' [-Wint-conversion]
                        char *cwd = get_current_dir_name();
                              ^     ~~~~~~~~~~~~~~~~~~~~~~

2 warnings generated.
...
Undefined symbols for architecture x86_64:
"_get_current_dir_name", referenced from:
_image_headersz_v1 in kwbimage.o
ld: symbol(s) not found for architecture x86_64
--->8---

Quoted 6 lines
Quoted 4 lines

---

 tools/kwbimage.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Applied to u-boot-staging. Thanks!

Now I see

tools/kwbimage.c:402:4: warning: ignoring return value of ?getcwd?, declared with attribute warn_unused_result [-Wunused-result]

So, additionally applied:

tools/kwbimage.c +8 -2
index 0a388c8..ec52f9e 100644
@@ -398,13 +398,19 @@ static size_t image_headersz_v1(struct image_tool_params *params,
 		ret = stat(binarye->binary.file, &s);
 		if (ret < 0) {
 			char cwd[PATH_MAX];
+			char *dir = cwd;
+
 			memset(cwd, 0, sizeof(cwd));
-			getcwd(cwd, sizeof(cwd));
+			if (!getcwd(cwd, sizeof(cwd))) {
+				dir = "current working directory";
+				perror("getcwd() failed");
+			}
+
 			fprintf(stderr,
 				"Didn't find the file '%s' in '%s' which is mandatory to generate the image\n"
 				"This file generally contains the DDR3 training code, and should be extracted from an existing bootable\n"
 				"image for your board. See 'kwbimage -x' to extract it from an existing image.\n",
-				binarye->binary.file, cwd);
+				binarye->binary.file, dir);
 			return 0;
 		}