aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds2012-03-22 11:40:53 -0500
committerLinus Torvalds2012-03-22 11:40:53 -0500
commit02c502566ef505d0469fa27567f48766c1f5f7af (patch)
treedd29678eb5f15ddfe537418eb83ad2c54074c37b
parentf06fc0c0de0b4f01dbad8ec5552e78192c7abbb8 (diff)
parenta51f4047758d2bcd099ea113b833ed380f4024ba (diff)
downloadkernel-omap-02c502566ef505d0469fa27567f48766c1f5f7af.tar.gz
kernel-omap-02c502566ef505d0469fa27567f48766c1f5f7af.tar.xz
kernel-omap-02c502566ef505d0469fa27567f48766c1f5f7af.zip
Merge branch 'x86-build-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull x86/build changes from Ingo Molnar. * 'x86-build-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: x86, build: Fix portability issues when cross-building x86, tools: Remove unneeded header files from tools/build.c USB: ffs-test: Don't duplicate {get,put}_unaligned*() functions x86, efi: Fix endian issues and unaligned accesses x86, boot: Restrict CFLAGS for hostprogs x86, mkpiggy: Don't open code put_unaligned_le32() x86, relocs: Don't open code put_unaligned_le32() tools/include: Add byteshift headers for endian access
-rw-r--r--arch/x86/boot/Makefile5
-rw-r--r--arch/x86/boot/compressed/Makefile1
-rw-r--r--arch/x86/boot/compressed/mkpiggy.c11
-rw-r--r--arch/x86/boot/compressed/relocs.c6
-rw-r--r--arch/x86/boot/tools/build.c40
-rw-r--r--tools/include/tools/be_byteshift.h70
-rw-r--r--tools/include/tools/le_byteshift.h70
-rw-r--r--tools/usb/Makefile2
-rw-r--r--tools/usb/ffs-test.c29
9 files changed, 169 insertions, 65 deletions
diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
index 95365a82b6a0..3e02148bb774 100644
--- a/arch/x86/boot/Makefile
+++ b/arch/x86/boot/Makefile
@@ -37,8 +37,9 @@ setup-y += video-bios.o
37targets += $(setup-y) 37targets += $(setup-y)
38hostprogs-y := mkcpustr tools/build 38hostprogs-y := mkcpustr tools/build
39 39
40HOST_EXTRACFLAGS += $(LINUXINCLUDE) 40HOSTCFLAGS_mkcpustr.o := -I$(srctree)/arch/$(SRCARCH)/include
41 41HOST_EXTRACFLAGS += -I$(objtree)/include -I$(srctree)/tools/include \
42 -include $(srctree)/include/linux/kconfig.h
42$(obj)/cpu.o: $(obj)/cpustr.h 43$(obj)/cpu.o: $(obj)/cpustr.h
43 44
44quiet_cmd_cpustr = CPUSTR $@ 45quiet_cmd_cpustr = CPUSTR $@
diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
index b123b9a8f5b3..fd55a2ff3ad8 100644
--- a/arch/x86/boot/compressed/Makefile
+++ b/arch/x86/boot/compressed/Makefile
@@ -22,6 +22,7 @@ LDFLAGS := -m elf_$(UTS_MACHINE)
22LDFLAGS_vmlinux := -T 22LDFLAGS_vmlinux := -T
23 23
24hostprogs-y := mkpiggy 24hostprogs-y := mkpiggy
25HOST_EXTRACFLAGS += -I$(srctree)/tools/include
25 26
26VMLINUX_OBJS = $(obj)/vmlinux.lds $(obj)/head_$(BITS).o $(obj)/misc.o \ 27VMLINUX_OBJS = $(obj)/vmlinux.lds $(obj)/head_$(BITS).o $(obj)/misc.o \
27 $(obj)/string.o $(obj)/cmdline.o $(obj)/early_serial_console.o \ 28 $(obj)/string.o $(obj)/cmdline.o $(obj)/early_serial_console.o \
diff --git a/arch/x86/boot/compressed/mkpiggy.c b/arch/x86/boot/compressed/mkpiggy.c
index 46a823882437..958a641483dd 100644
--- a/arch/x86/boot/compressed/mkpiggy.c
+++ b/arch/x86/boot/compressed/mkpiggy.c
@@ -29,14 +29,7 @@
29#include <stdio.h> 29#include <stdio.h>
30#include <string.h> 30#include <string.h>
31#include <inttypes.h> 31#include <inttypes.h>
32 32#include <tools/le_byteshift.h>
33static uint32_t getle32(const void *p)
34{
35 const uint8_t *cp = p;
36
37 return (uint32_t)cp[0] + ((uint32_t)cp[1] << 8) +
38 ((uint32_t)cp[2] << 16) + ((uint32_t)cp[3] << 24);
39}
40 33
41int main(int argc, char *argv[]) 34int main(int argc, char *argv[])
42{ 35{
@@ -69,7 +62,7 @@ int main(int argc, char *argv[])
69 } 62 }
70 63
71 ilen = ftell(f); 64 ilen = ftell(f);
72 olen = getle32(&olen); 65 olen = get_unaligned_le32(&olen);
73 fclose(f); 66 fclose(f);
74 67
75 /* 68 /*
diff --git a/arch/x86/boot/compressed/relocs.c b/arch/x86/boot/compressed/relocs.c
index 89bbf4e4d05d..d3c0b0277666 100644
--- a/arch/x86/boot/compressed/relocs.c
+++ b/arch/x86/boot/compressed/relocs.c
@@ -10,6 +10,7 @@
10#define USE_BSD 10#define USE_BSD
11#include <endian.h> 11#include <endian.h>
12#include <regex.h> 12#include <regex.h>
13#include <tools/le_byteshift.h>
13 14
14static void die(char *fmt, ...); 15static void die(char *fmt, ...);
15 16
@@ -605,10 +606,7 @@ static void emit_relocs(int as_text)
605 fwrite("\0\0\0\0", 4, 1, stdout); 606 fwrite("\0\0\0\0", 4, 1, stdout);
606 /* Now print each relocation */ 607 /* Now print each relocation */
607 for (i = 0; i < reloc_count; i++) { 608 for (i = 0; i < reloc_count; i++) {
608 buf[0] = (relocs[i] >> 0) & 0xff; 609 put_unaligned_le32(relocs[i], buf);
609 buf[1] = (relocs[i] >> 8) & 0xff;
610 buf[2] = (relocs[i] >> 16) & 0xff;
611 buf[3] = (relocs[i] >> 24) & 0xff;
612 fwrite(buf, 4, 1, stdout); 610 fwrite(buf, 4, 1, stdout);
613 } 611 }
614 } 612 }
diff --git a/arch/x86/boot/tools/build.c b/arch/x86/boot/tools/build.c
index 4e9bd6bcafa6..ed549767a231 100644
--- a/arch/x86/boot/tools/build.c
+++ b/arch/x86/boot/tools/build.c
@@ -29,18 +29,18 @@
29#include <stdarg.h> 29#include <stdarg.h>
30#include <sys/types.h> 30#include <sys/types.h>
31#include <sys/stat.h> 31#include <sys/stat.h>
32#include <sys/sysmacros.h>
33#include <unistd.h> 32#include <unistd.h>
34#include <fcntl.h> 33#include <fcntl.h>
35#include <sys/mman.h> 34#include <sys/mman.h>
36#include <asm/boot.h> 35#include <tools/le_byteshift.h>
37 36
38typedef unsigned char u8; 37typedef unsigned char u8;
39typedef unsigned short u16; 38typedef unsigned short u16;
40typedef unsigned long u32; 39typedef unsigned int u32;
41 40
42#define DEFAULT_MAJOR_ROOT 0 41#define DEFAULT_MAJOR_ROOT 0
43#define DEFAULT_MINOR_ROOT 0 42#define DEFAULT_MINOR_ROOT 0
43#define DEFAULT_ROOT_DEV (DEFAULT_MAJOR_ROOT << 8 | DEFAULT_MINOR_ROOT)
44 44
45/* Minimal number of setup sectors */ 45/* Minimal number of setup sectors */
46#define SETUP_SECT_MIN 5 46#define SETUP_SECT_MIN 5
@@ -159,7 +159,7 @@ int main(int argc, char ** argv)
159 die("read-error on `setup'"); 159 die("read-error on `setup'");
160 if (c < 1024) 160 if (c < 1024)
161 die("The setup must be at least 1024 bytes"); 161 die("The setup must be at least 1024 bytes");
162 if (buf[510] != 0x55 || buf[511] != 0xaa) 162 if (get_unaligned_le16(&buf[510]) != 0xAA55)
163 die("Boot block hasn't got boot flag (0xAA55)"); 163 die("Boot block hasn't got boot flag (0xAA55)");
164 fclose(file); 164 fclose(file);
165 165
@@ -171,8 +171,7 @@ int main(int argc, char ** argv)
171 memset(buf+c, 0, i-c); 171 memset(buf+c, 0, i-c);
172 172
173 /* Set the default root device */ 173 /* Set the default root device */
174 buf[508] = DEFAULT_MINOR_ROOT; 174 put_unaligned_le16(DEFAULT_ROOT_DEV, &buf[508]);
175 buf[509] = DEFAULT_MAJOR_ROOT;
176 175
177 fprintf(stderr, "Setup is %d bytes (padded to %d bytes).\n", c, i); 176 fprintf(stderr, "Setup is %d bytes (padded to %d bytes).\n", c, i);
178 177
@@ -192,44 +191,42 @@ int main(int argc, char ** argv)
192 191
193 /* Patch the setup code with the appropriate size parameters */ 192 /* Patch the setup code with the appropriate size parameters */
194 buf[0x1f1] = setup_sectors-1; 193 buf[0x1f1] = setup_sectors-1;
195 buf[0x1f4] = sys_size; 194 put_unaligned_le32(sys_size, &buf[0x1f4]);
196 buf[0x1f5] = sys_size >> 8;
197 buf[0x1f6] = sys_size >> 16;
198 buf[0x1f7] = sys_size >> 24;
199 195
200#ifdef CONFIG_EFI_STUB 196#ifdef CONFIG_EFI_STUB
201 file_sz = sz + i + ((sys_size * 16) - sz); 197 file_sz = sz + i + ((sys_size * 16) - sz);
202 198
203 pe_header = *(unsigned int *)&buf[0x3c]; 199 pe_header = get_unaligned_le32(&buf[0x3c]);
204 200
205 /* Size of code */ 201 /* Size of code */
206 *(unsigned int *)&buf[pe_header + 0x1c] = file_sz; 202 put_unaligned_le32(file_sz, &buf[pe_header + 0x1c]);
207 203
208 /* Size of image */ 204 /* Size of image */
209 *(unsigned int *)&buf[pe_header + 0x50] = file_sz; 205 put_unaligned_le32(file_sz, &buf[pe_header + 0x50]);
210 206
211#ifdef CONFIG_X86_32 207#ifdef CONFIG_X86_32
212 /* Address of entry point */ 208 /* Address of entry point */
213 *(unsigned int *)&buf[pe_header + 0x28] = i; 209 put_unaligned_le32(i, &buf[pe_header + 0x28]);
214 210
215 /* .text size */ 211 /* .text size */
216 *(unsigned int *)&buf[pe_header + 0xb0] = file_sz; 212 put_unaligned_le32(file_sz, &buf[pe_header + 0xb0]);
217 213
218 /* .text size of initialised data */ 214 /* .text size of initialised data */
219 *(unsigned int *)&buf[pe_header + 0xb8] = file_sz; 215 put_unaligned_le32(file_sz, &buf[pe_header + 0xb8]);
220#else 216#else
221 /* 217 /*
222 * Address of entry point. startup_32 is at the beginning and 218 * Address of entry point. startup_32 is at the beginning and
223 * the 64-bit entry point (startup_64) is always 512 bytes 219 * the 64-bit entry point (startup_64) is always 512 bytes
224 * after. 220 * after.
225 */ 221 */
226 *(unsigned int *)&buf[pe_header + 0x28] = i + 512; 222 put_unaligned_le32(i + 512, &buf[pe_header + 0x28]);
227 223
228 /* .text size */ 224 /* .text size */
229 *(unsigned int *)&buf[pe_header + 0xc0] = file_sz; 225 put_unaligned_le32(file_sz, &buf[pe_header + 0xc0]);
230 226
231 /* .text size of initialised data */ 227 /* .text size of initialised data */
232 *(unsigned int *)&buf[pe_header + 0xc8] = file_sz; 228 put_unaligned_le32(file_sz, &buf[pe_header + 0xc8]);
229
233#endif /* CONFIG_X86_32 */ 230#endif /* CONFIG_X86_32 */
234#endif /* CONFIG_EFI_STUB */ 231#endif /* CONFIG_EFI_STUB */
235 232
@@ -250,8 +247,9 @@ int main(int argc, char ** argv)
250 } 247 }
251 248
252 /* Write the CRC */ 249 /* Write the CRC */
253 fprintf(stderr, "CRC %lx\n", crc); 250 fprintf(stderr, "CRC %x\n", crc);
254 if (fwrite(&crc, 1, 4, stdout) != 4) 251 put_unaligned_le32(crc, buf);
252 if (fwrite(buf, 1, 4, stdout) != 4)
255 die("Writing CRC failed"); 253 die("Writing CRC failed");
256 254
257 close(fd); 255 close(fd);
diff --git a/tools/include/tools/be_byteshift.h b/tools/include/tools/be_byteshift.h
new file mode 100644
index 000000000000..f4912e2668ba
--- /dev/null
+++ b/tools/include/tools/be_byteshift.h
@@ -0,0 +1,70 @@
1#ifndef _TOOLS_BE_BYTESHIFT_H
2#define _TOOLS_BE_BYTESHIFT_H
3
4#include <linux/types.h>
5
6static inline __u16 __get_unaligned_be16(const __u8 *p)
7{
8 return p[0] << 8 | p[1];
9}
10
11static inline __u32 __get_unaligned_be32(const __u8 *p)
12{
13 return p[0] << 24 | p[1] << 16 | p[2] << 8 | p[3];
14}
15
16static inline __u64 __get_unaligned_be64(const __u8 *p)
17{
18 return (__u64)__get_unaligned_be32(p) << 32 |
19 __get_unaligned_be32(p + 4);
20}
21
22static inline void __put_unaligned_be16(__u16 val, __u8 *p)
23{
24 *p++ = val >> 8;
25 *p++ = val;
26}
27
28static inline void __put_unaligned_be32(__u32 val, __u8 *p)
29{
30 __put_unaligned_be16(val >> 16, p);
31 __put_unaligned_be16(val, p + 2);
32}
33
34static inline void __put_unaligned_be64(__u64 val, __u8 *p)
35{
36 __put_unaligned_be32(val >> 32, p);
37 __put_unaligned_be32(val, p + 4);
38}
39
40static inline __u16 get_unaligned_be16(const void *p)
41{
42 return __get_unaligned_be16((const __u8 *)p);
43}
44
45static inline __u32 get_unaligned_be32(const void *p)
46{
47 return __get_unaligned_be32((const __u8 *)p);
48}
49
50static inline __u64 get_unaligned_be64(const void *p)
51{
52 return __get_unaligned_be64((const __u8 *)p);
53}
54
55static inline void put_unaligned_be16(__u16 val, void *p)
56{
57 __put_unaligned_be16(val, p);
58}
59
60static inline void put_unaligned_be32(__u32 val, void *p)
61{
62 __put_unaligned_be32(val, p);
63}
64
65static inline void put_unaligned_be64(__u64 val, void *p)
66{
67 __put_unaligned_be64(val, p);
68}
69
70#endif /* _TOOLS_BE_BYTESHIFT_H */
diff --git a/tools/include/tools/le_byteshift.h b/tools/include/tools/le_byteshift.h
new file mode 100644
index 000000000000..c99d45a68bda
--- /dev/null
+++ b/tools/include/tools/le_byteshift.h
@@ -0,0 +1,70 @@
1#ifndef _TOOLS_LE_BYTESHIFT_H
2#define _TOOLS_LE_BYTESHIFT_H
3
4#include <linux/types.h>
5
6static inline __u16 __get_unaligned_le16(const __u8 *p)
7{
8 return p[0] | p[1] << 8;
9}
10
11static inline __u32 __get_unaligned_le32(const __u8 *p)
12{
13 return p[0] | p[1] << 8 | p[2] << 16 | p[3] << 24;
14}
15
16static inline __u64 __get_unaligned_le64(const __u8 *p)
17{
18 return (__u64)__get_unaligned_le32(p + 4) << 32 |
19 __get_unaligned_le32(p);
20}
21
22static inline void __put_unaligned_le16(__u16 val, __u8 *p)
23{
24 *p++ = val;
25 *p++ = val >> 8;
26}
27
28static inline void __put_unaligned_le32(__u32 val, __u8 *p)
29{
30 __put_unaligned_le16(val >> 16, p + 2);
31 __put_unaligned_le16(val, p);
32}
33
34static inline void __put_unaligned_le64(__u64 val, __u8 *p)
35{
36 __put_unaligned_le32(val >> 32, p + 4);
37 __put_unaligned_le32(val, p);
38}
39
40static inline __u16 get_unaligned_le16(const void *p)
41{
42 return __get_unaligned_le16((const __u8 *)p);
43}
44
45static inline __u32 get_unaligned_le32(const void *p)
46{
47 return __get_unaligned_le32((const __u8 *)p);
48}
49
50static inline __u64 get_unaligned_le64(const void *p)
51{
52 return __get_unaligned_le64((const __u8 *)p);
53}
54
55static inline void put_unaligned_le16(__u16 val, void *p)
56{
57 __put_unaligned_le16(val, p);
58}
59
60static inline void put_unaligned_le32(__u32 val, void *p)
61{
62 __put_unaligned_le32(val, p);
63}
64
65static inline void put_unaligned_le64(__u64 val, void *p)
66{
67 __put_unaligned_le64(val, p);
68}
69
70#endif /* _TOOLS_LE_BYTESHIFT_H */
diff --git a/tools/usb/Makefile b/tools/usb/Makefile
index 8b704af14349..396d6c44e9d7 100644
--- a/tools/usb/Makefile
+++ b/tools/usb/Makefile
@@ -3,7 +3,7 @@
3CC = $(CROSS_COMPILE)gcc 3CC = $(CROSS_COMPILE)gcc
4PTHREAD_LIBS = -lpthread 4PTHREAD_LIBS = -lpthread
5WARNINGS = -Wall -Wextra 5WARNINGS = -Wall -Wextra
6CFLAGS = $(WARNINGS) -g $(PTHREAD_LIBS) 6CFLAGS = $(WARNINGS) -g $(PTHREAD_LIBS) -I../include
7 7
8all: testusb ffs-test 8all: testusb ffs-test
9%: %.c 9%: %.c
diff --git a/tools/usb/ffs-test.c b/tools/usb/ffs-test.c
index 53452c35d5e1..4b107b5e623f 100644
--- a/tools/usb/ffs-test.c
+++ b/tools/usb/ffs-test.c
@@ -36,6 +36,7 @@
36#include <sys/stat.h> 36#include <sys/stat.h>
37#include <sys/types.h> 37#include <sys/types.h>
38#include <unistd.h> 38#include <unistd.h>
39#include <tools/le_byteshift.h>
39 40
40#include "../../include/linux/usb/functionfs.h" 41#include "../../include/linux/usb/functionfs.h"
41 42
@@ -47,34 +48,6 @@
47#define le32_to_cpu(x) le32toh(x) 48#define le32_to_cpu(x) le32toh(x)
48#define le16_to_cpu(x) le16toh(x) 49#define le16_to_cpu(x) le16toh(x)
49 50
50static inline __u16 get_unaligned_le16(const void *_ptr)
51{
52 const __u8 *ptr = _ptr;
53 return ptr[0] | (ptr[1] << 8);
54}
55
56static inline __u32 get_unaligned_le32(const void *_ptr)
57{
58 const __u8 *ptr = _ptr;
59 return ptr[0] | (ptr[1] << 8) | (ptr[2] << 16) | (ptr[3] << 24);
60}
61
62static inline void put_unaligned_le16(__u16 val, void *_ptr)
63{
64 __u8 *ptr = _ptr;
65 *ptr++ = val;
66 *ptr++ = val >> 8;
67}
68
69static inline void put_unaligned_le32(__u32 val, void *_ptr)
70{
71 __u8 *ptr = _ptr;
72 *ptr++ = val;
73 *ptr++ = val >> 8;
74 *ptr++ = val >> 16;
75 *ptr++ = val >> 24;
76}
77
78 51
79/******************** Messages and Errors ***********************************/ 52/******************** Messages and Errors ***********************************/
80 53