Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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

+169 -65
+3 -2
arch/x86/boot/Makefile
··· 37 37 targets += $(setup-y) 38 38 hostprogs-y := mkcpustr tools/build 39 39 40 - HOST_EXTRACFLAGS += $(LINUXINCLUDE) 41 - 40 + HOSTCFLAGS_mkcpustr.o := -I$(srctree)/arch/$(SRCARCH)/include 41 + HOST_EXTRACFLAGS += -I$(objtree)/include -I$(srctree)/tools/include \ 42 + -include $(srctree)/include/linux/kconfig.h 42 43 $(obj)/cpu.o: $(obj)/cpustr.h 43 44 44 45 quiet_cmd_cpustr = CPUSTR $@
+1
arch/x86/boot/compressed/Makefile
··· 22 22 LDFLAGS_vmlinux := -T 23 23 24 24 hostprogs-y := mkpiggy 25 + HOST_EXTRACFLAGS += -I$(srctree)/tools/include 25 26 26 27 VMLINUX_OBJS = $(obj)/vmlinux.lds $(obj)/head_$(BITS).o $(obj)/misc.o \ 27 28 $(obj)/string.o $(obj)/cmdline.o $(obj)/early_serial_console.o \
+2 -9
arch/x86/boot/compressed/mkpiggy.c
··· 29 29 #include <stdio.h> 30 30 #include <string.h> 31 31 #include <inttypes.h> 32 - 33 - static 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 - } 32 + #include <tools/le_byteshift.h> 40 33 41 34 int main(int argc, char *argv[]) 42 35 { ··· 62 69 } 63 70 64 71 ilen = ftell(f); 65 - olen = getle32(&olen); 72 + olen = get_unaligned_le32(&olen); 66 73 fclose(f); 67 74 68 75 /*
+2 -4
arch/x86/boot/compressed/relocs.c
··· 10 10 #define USE_BSD 11 11 #include <endian.h> 12 12 #include <regex.h> 13 + #include <tools/le_byteshift.h> 13 14 14 15 static void die(char *fmt, ...); 15 16 ··· 606 605 fwrite("\0\0\0\0", 4, 1, stdout); 607 606 /* Now print each relocation */ 608 607 for (i = 0; i < reloc_count; i++) { 609 - buf[0] = (relocs[i] >> 0) & 0xff; 610 - buf[1] = (relocs[i] >> 8) & 0xff; 611 - buf[2] = (relocs[i] >> 16) & 0xff; 612 - buf[3] = (relocs[i] >> 24) & 0xff; 608 + put_unaligned_le32(relocs[i], buf); 613 609 fwrite(buf, 4, 1, stdout); 614 610 } 615 611 }
+19 -21
arch/x86/boot/tools/build.c
··· 29 29 #include <stdarg.h> 30 30 #include <sys/types.h> 31 31 #include <sys/stat.h> 32 - #include <sys/sysmacros.h> 33 32 #include <unistd.h> 34 33 #include <fcntl.h> 35 34 #include <sys/mman.h> 36 - #include <asm/boot.h> 35 + #include <tools/le_byteshift.h> 37 36 38 37 typedef unsigned char u8; 39 38 typedef unsigned short u16; 40 - typedef unsigned long u32; 39 + typedef unsigned int u32; 41 40 42 41 #define DEFAULT_MAJOR_ROOT 0 43 42 #define DEFAULT_MINOR_ROOT 0 43 + #define DEFAULT_ROOT_DEV (DEFAULT_MAJOR_ROOT << 8 | DEFAULT_MINOR_ROOT) 44 44 45 45 /* Minimal number of setup sectors */ 46 46 #define SETUP_SECT_MIN 5 ··· 159 159 die("read-error on `setup'"); 160 160 if (c < 1024) 161 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 163 die("Boot block hasn't got boot flag (0xAA55)"); 164 164 fclose(file); 165 165 ··· 171 171 memset(buf+c, 0, i-c); 172 172 173 173 /* Set the default root device */ 174 - buf[508] = DEFAULT_MINOR_ROOT; 175 - buf[509] = DEFAULT_MAJOR_ROOT; 174 + put_unaligned_le16(DEFAULT_ROOT_DEV, &buf[508]); 176 175 177 176 fprintf(stderr, "Setup is %d bytes (padded to %d bytes).\n", c, i); 178 177 ··· 191 192 192 193 /* Patch the setup code with the appropriate size parameters */ 193 194 buf[0x1f1] = setup_sectors-1; 194 - buf[0x1f4] = sys_size; 195 - buf[0x1f5] = sys_size >> 8; 196 - buf[0x1f6] = sys_size >> 16; 197 - buf[0x1f7] = sys_size >> 24; 195 + put_unaligned_le32(sys_size, &buf[0x1f4]); 198 196 199 197 #ifdef CONFIG_EFI_STUB 200 198 file_sz = sz + i + ((sys_size * 16) - sz); 201 199 202 - pe_header = *(unsigned int *)&buf[0x3c]; 200 + pe_header = get_unaligned_le32(&buf[0x3c]); 203 201 204 202 /* Size of code */ 205 - *(unsigned int *)&buf[pe_header + 0x1c] = file_sz; 203 + put_unaligned_le32(file_sz, &buf[pe_header + 0x1c]); 206 204 207 205 /* Size of image */ 208 - *(unsigned int *)&buf[pe_header + 0x50] = file_sz; 206 + put_unaligned_le32(file_sz, &buf[pe_header + 0x50]); 209 207 210 208 #ifdef CONFIG_X86_32 211 209 /* Address of entry point */ 212 - *(unsigned int *)&buf[pe_header + 0x28] = i; 210 + put_unaligned_le32(i, &buf[pe_header + 0x28]); 213 211 214 212 /* .text size */ 215 - *(unsigned int *)&buf[pe_header + 0xb0] = file_sz; 213 + put_unaligned_le32(file_sz, &buf[pe_header + 0xb0]); 216 214 217 215 /* .text size of initialised data */ 218 - *(unsigned int *)&buf[pe_header + 0xb8] = file_sz; 216 + put_unaligned_le32(file_sz, &buf[pe_header + 0xb8]); 219 217 #else 220 218 /* 221 219 * Address of entry point. startup_32 is at the beginning and 222 220 * the 64-bit entry point (startup_64) is always 512 bytes 223 221 * after. 224 222 */ 225 - *(unsigned int *)&buf[pe_header + 0x28] = i + 512; 223 + put_unaligned_le32(i + 512, &buf[pe_header + 0x28]); 226 224 227 225 /* .text size */ 228 - *(unsigned int *)&buf[pe_header + 0xc0] = file_sz; 226 + put_unaligned_le32(file_sz, &buf[pe_header + 0xc0]); 229 227 230 228 /* .text size of initialised data */ 231 - *(unsigned int *)&buf[pe_header + 0xc8] = file_sz; 229 + put_unaligned_le32(file_sz, &buf[pe_header + 0xc8]); 230 + 232 231 #endif /* CONFIG_X86_32 */ 233 232 #endif /* CONFIG_EFI_STUB */ 234 233 ··· 247 250 } 248 251 249 252 /* Write the CRC */ 250 - fprintf(stderr, "CRC %lx\n", crc); 251 - if (fwrite(&crc, 1, 4, stdout) != 4) 253 + fprintf(stderr, "CRC %x\n", crc); 254 + put_unaligned_le32(crc, buf); 255 + if (fwrite(buf, 1, 4, stdout) != 4) 252 256 die("Writing CRC failed"); 253 257 254 258 close(fd);
+70
tools/include/tools/be_byteshift.h
··· 1 + #ifndef _TOOLS_BE_BYTESHIFT_H 2 + #define _TOOLS_BE_BYTESHIFT_H 3 + 4 + #include <linux/types.h> 5 + 6 + static inline __u16 __get_unaligned_be16(const __u8 *p) 7 + { 8 + return p[0] << 8 | p[1]; 9 + } 10 + 11 + static inline __u32 __get_unaligned_be32(const __u8 *p) 12 + { 13 + return p[0] << 24 | p[1] << 16 | p[2] << 8 | p[3]; 14 + } 15 + 16 + static 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 + 22 + static inline void __put_unaligned_be16(__u16 val, __u8 *p) 23 + { 24 + *p++ = val >> 8; 25 + *p++ = val; 26 + } 27 + 28 + static 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 + 34 + static 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 + 40 + static inline __u16 get_unaligned_be16(const void *p) 41 + { 42 + return __get_unaligned_be16((const __u8 *)p); 43 + } 44 + 45 + static inline __u32 get_unaligned_be32(const void *p) 46 + { 47 + return __get_unaligned_be32((const __u8 *)p); 48 + } 49 + 50 + static inline __u64 get_unaligned_be64(const void *p) 51 + { 52 + return __get_unaligned_be64((const __u8 *)p); 53 + } 54 + 55 + static inline void put_unaligned_be16(__u16 val, void *p) 56 + { 57 + __put_unaligned_be16(val, p); 58 + } 59 + 60 + static inline void put_unaligned_be32(__u32 val, void *p) 61 + { 62 + __put_unaligned_be32(val, p); 63 + } 64 + 65 + static inline void put_unaligned_be64(__u64 val, void *p) 66 + { 67 + __put_unaligned_be64(val, p); 68 + } 69 + 70 + #endif /* _TOOLS_BE_BYTESHIFT_H */
+70
tools/include/tools/le_byteshift.h
··· 1 + #ifndef _TOOLS_LE_BYTESHIFT_H 2 + #define _TOOLS_LE_BYTESHIFT_H 3 + 4 + #include <linux/types.h> 5 + 6 + static inline __u16 __get_unaligned_le16(const __u8 *p) 7 + { 8 + return p[0] | p[1] << 8; 9 + } 10 + 11 + static inline __u32 __get_unaligned_le32(const __u8 *p) 12 + { 13 + return p[0] | p[1] << 8 | p[2] << 16 | p[3] << 24; 14 + } 15 + 16 + static 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 + 22 + static inline void __put_unaligned_le16(__u16 val, __u8 *p) 23 + { 24 + *p++ = val; 25 + *p++ = val >> 8; 26 + } 27 + 28 + static 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 + 34 + static 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 + 40 + static inline __u16 get_unaligned_le16(const void *p) 41 + { 42 + return __get_unaligned_le16((const __u8 *)p); 43 + } 44 + 45 + static inline __u32 get_unaligned_le32(const void *p) 46 + { 47 + return __get_unaligned_le32((const __u8 *)p); 48 + } 49 + 50 + static inline __u64 get_unaligned_le64(const void *p) 51 + { 52 + return __get_unaligned_le64((const __u8 *)p); 53 + } 54 + 55 + static inline void put_unaligned_le16(__u16 val, void *p) 56 + { 57 + __put_unaligned_le16(val, p); 58 + } 59 + 60 + static inline void put_unaligned_le32(__u32 val, void *p) 61 + { 62 + __put_unaligned_le32(val, p); 63 + } 64 + 65 + static inline void put_unaligned_le64(__u64 val, void *p) 66 + { 67 + __put_unaligned_le64(val, p); 68 + } 69 + 70 + #endif /* _TOOLS_LE_BYTESHIFT_H */
+1 -1
tools/usb/Makefile
··· 3 3 CC = $(CROSS_COMPILE)gcc 4 4 PTHREAD_LIBS = -lpthread 5 5 WARNINGS = -Wall -Wextra 6 - CFLAGS = $(WARNINGS) -g $(PTHREAD_LIBS) 6 + CFLAGS = $(WARNINGS) -g $(PTHREAD_LIBS) -I../include 7 7 8 8 all: testusb ffs-test 9 9 %: %.c
+1 -28
tools/usb/ffs-test.c
··· 36 36 #include <sys/stat.h> 37 37 #include <sys/types.h> 38 38 #include <unistd.h> 39 + #include <tools/le_byteshift.h> 39 40 40 41 #include "../../include/linux/usb/functionfs.h" 41 42 ··· 47 46 #define cpu_to_le32(x) htole32(x) 48 47 #define le32_to_cpu(x) le32toh(x) 49 48 #define le16_to_cpu(x) le16toh(x) 50 - 51 - static inline __u16 get_unaligned_le16(const void *_ptr) 52 - { 53 - const __u8 *ptr = _ptr; 54 - return ptr[0] | (ptr[1] << 8); 55 - } 56 - 57 - static inline __u32 get_unaligned_le32(const void *_ptr) 58 - { 59 - const __u8 *ptr = _ptr; 60 - return ptr[0] | (ptr[1] << 8) | (ptr[2] << 16) | (ptr[3] << 24); 61 - } 62 - 63 - static inline void put_unaligned_le16(__u16 val, void *_ptr) 64 - { 65 - __u8 *ptr = _ptr; 66 - *ptr++ = val; 67 - *ptr++ = val >> 8; 68 - } 69 - 70 - static inline void put_unaligned_le32(__u32 val, void *_ptr) 71 - { 72 - __u8 *ptr = _ptr; 73 - *ptr++ = val; 74 - *ptr++ = val >> 8; 75 - *ptr++ = val >> 16; 76 - *ptr++ = val >> 24; 77 - } 78 49 79 50 80 51 /******************** Messages and Errors ***********************************/