Commit a9aff3ea authored by H. Peter Anvin's avatar H. Peter Anvin

Merge branch x86/build into x86/efi and fix up arch/x86/boot/tools/build.c

Reason for merge:
       The updates to the EFI boot stub generation conflicted with the
       changes to properly use the get/put_unaligned_le*() macros to
       generate images.

       This merge commit completes the conversion in
       arch/x86/boot/tools/build.c including the places in the code
       which had been changed on the x86/efi branch.

Resolved Conflicts:
	arch/x86/boot/tools/build.c
Signed-off-by: default avatarH. Peter Anvin <hpa@linux.intel.com>
parents e47bb0bd a51f4047
...@@ -37,8 +37,9 @@ setup-y += video-bios.o ...@@ -37,8 +37,9 @@ setup-y += video-bios.o
targets += $(setup-y) targets += $(setup-y)
hostprogs-y := mkcpustr tools/build hostprogs-y := mkcpustr tools/build
HOST_EXTRACFLAGS += $(LINUXINCLUDE) HOSTCFLAGS_mkcpustr.o := -I$(srctree)/arch/$(SRCARCH)/include
HOST_EXTRACFLAGS += -I$(objtree)/include -I$(srctree)/tools/include \
-include $(srctree)/include/linux/kconfig.h
$(obj)/cpu.o: $(obj)/cpustr.h $(obj)/cpu.o: $(obj)/cpustr.h
quiet_cmd_cpustr = CPUSTR $@ quiet_cmd_cpustr = CPUSTR $@
......
...@@ -22,6 +22,7 @@ LDFLAGS := -m elf_$(UTS_MACHINE) ...@@ -22,6 +22,7 @@ LDFLAGS := -m elf_$(UTS_MACHINE)
LDFLAGS_vmlinux := -T LDFLAGS_vmlinux := -T
hostprogs-y := mkpiggy hostprogs-y := mkpiggy
HOST_EXTRACFLAGS += -I$(srctree)/tools/include
VMLINUX_OBJS = $(obj)/vmlinux.lds $(obj)/head_$(BITS).o $(obj)/misc.o \ VMLINUX_OBJS = $(obj)/vmlinux.lds $(obj)/head_$(BITS).o $(obj)/misc.o \
$(obj)/string.o $(obj)/cmdline.o $(obj)/early_serial_console.o \ $(obj)/string.o $(obj)/cmdline.o $(obj)/early_serial_console.o \
......
...@@ -29,14 +29,7 @@ ...@@ -29,14 +29,7 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <inttypes.h> #include <inttypes.h>
#include <tools/le_byteshift.h>
static uint32_t getle32(const void *p)
{
const uint8_t *cp = p;
return (uint32_t)cp[0] + ((uint32_t)cp[1] << 8) +
((uint32_t)cp[2] << 16) + ((uint32_t)cp[3] << 24);
}
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
...@@ -69,7 +62,7 @@ int main(int argc, char *argv[]) ...@@ -69,7 +62,7 @@ int main(int argc, char *argv[])
} }
ilen = ftell(f); ilen = ftell(f);
olen = getle32(&olen); olen = get_unaligned_le32(&olen);
fclose(f); fclose(f);
/* /*
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#define USE_BSD #define USE_BSD
#include <endian.h> #include <endian.h>
#include <regex.h> #include <regex.h>
#include <tools/le_byteshift.h>
static void die(char *fmt, ...); static void die(char *fmt, ...);
...@@ -605,10 +606,7 @@ static void emit_relocs(int as_text) ...@@ -605,10 +606,7 @@ static void emit_relocs(int as_text)
fwrite("\0\0\0\0", 4, 1, stdout); fwrite("\0\0\0\0", 4, 1, stdout);
/* Now print each relocation */ /* Now print each relocation */
for (i = 0; i < reloc_count; i++) { for (i = 0; i < reloc_count; i++) {
buf[0] = (relocs[i] >> 0) & 0xff; put_unaligned_le32(relocs[i], buf);
buf[1] = (relocs[i] >> 8) & 0xff;
buf[2] = (relocs[i] >> 16) & 0xff;
buf[3] = (relocs[i] >> 24) & 0xff;
fwrite(buf, 4, 1, stdout); fwrite(buf, 4, 1, stdout);
} }
} }
......
...@@ -29,18 +29,18 @@ ...@@ -29,18 +29,18 @@
#include <stdarg.h> #include <stdarg.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/sysmacros.h>
#include <unistd.h> #include <unistd.h>
#include <fcntl.h> #include <fcntl.h>
#include <sys/mman.h> #include <sys/mman.h>
#include <asm/boot.h> #include <tools/le_byteshift.h>
typedef unsigned char u8; typedef unsigned char u8;
typedef unsigned short u16; typedef unsigned short u16;
typedef unsigned long u32; typedef unsigned int u32;
#define DEFAULT_MAJOR_ROOT 0 #define DEFAULT_MAJOR_ROOT 0
#define DEFAULT_MINOR_ROOT 0 #define DEFAULT_MINOR_ROOT 0
#define DEFAULT_ROOT_DEV (DEFAULT_MAJOR_ROOT << 8 | DEFAULT_MINOR_ROOT)
/* Minimal number of setup sectors */ /* Minimal number of setup sectors */
#define SETUP_SECT_MIN 5 #define SETUP_SECT_MIN 5
...@@ -159,7 +159,7 @@ int main(int argc, char ** argv) ...@@ -159,7 +159,7 @@ int main(int argc, char ** argv)
die("read-error on `setup'"); die("read-error on `setup'");
if (c < 1024) if (c < 1024)
die("The setup must be at least 1024 bytes"); die("The setup must be at least 1024 bytes");
if (buf[510] != 0x55 || buf[511] != 0xaa) if (get_unaligned_le16(&buf[510]) != 0xAA55)
die("Boot block hasn't got boot flag (0xAA55)"); die("Boot block hasn't got boot flag (0xAA55)");
fclose(file); fclose(file);
...@@ -171,8 +171,7 @@ int main(int argc, char ** argv) ...@@ -171,8 +171,7 @@ int main(int argc, char ** argv)
memset(buf+c, 0, i-c); memset(buf+c, 0, i-c);
/* Set the default root device */ /* Set the default root device */
buf[508] = DEFAULT_MINOR_ROOT; put_unaligned_le16(DEFAULT_ROOT_DEV, &buf[508]);
buf[509] = DEFAULT_MAJOR_ROOT;
fprintf(stderr, "Setup is %d bytes (padded to %d bytes).\n", c, i); fprintf(stderr, "Setup is %d bytes (padded to %d bytes).\n", c, i);
...@@ -192,18 +191,15 @@ int main(int argc, char ** argv) ...@@ -192,18 +191,15 @@ int main(int argc, char ** argv)
/* Patch the setup code with the appropriate size parameters */ /* Patch the setup code with the appropriate size parameters */
buf[0x1f1] = setup_sectors-1; buf[0x1f1] = setup_sectors-1;
buf[0x1f4] = sys_size; put_unaligned_le32(sys_size, &buf[0x1f4]);
buf[0x1f5] = sys_size >> 8;
buf[0x1f6] = sys_size >> 16;
buf[0x1f7] = sys_size >> 24;
#ifdef CONFIG_EFI_STUB #ifdef CONFIG_EFI_STUB
file_sz = sz + i + ((sys_size * 16) - sz); file_sz = sz + i + ((sys_size * 16) - sz);
pe_header = *(unsigned int *)&buf[0x3c]; pe_header = get_unaligned_le32(&buf[0x3c]);
/* Size of image */ /* Size of image */
*(unsigned int *)&buf[pe_header + 0x50] = file_sz; put_unaligned_le32(file_sz, &buf[pe_header + 0x50]);
/* /*
* Subtract the size of the first section (512 bytes) which * Subtract the size of the first section (512 bytes) which
...@@ -213,42 +209,42 @@ int main(int argc, char ** argv) ...@@ -213,42 +209,42 @@ int main(int argc, char ** argv)
file_sz -= 512; file_sz -= 512;
/* Size of code */ /* Size of code */
*(unsigned int *)&buf[pe_header + 0x1c] = file_sz; put_unaligned_le32(file_sz, &buf[pe_header + 0x1c]);
#ifdef CONFIG_X86_32 #ifdef CONFIG_X86_32
/* Address of entry point */ /* Address of entry point */
*(unsigned int *)&buf[pe_header + 0x28] = i; put_unaligned_le32(i, &buf[pe_header + 0x28]);
/* .text size */ /* .text size */
*(unsigned int *)&buf[pe_header + 0xb0] = file_sz; put_unaligned_le32(file_sz, &buf[pe_header + 0xb0]);
/* .text vma */ /* .text vma */
*(unsigned int *)&buf[pe_header + 0xb4] = 0x200; put_unaligned_le32(0x200, &buf[pe_header + 0xb4]);
/* .text size of initialised data */ /* .text size of initialised data */
*(unsigned int *)&buf[pe_header + 0xb8] = file_sz; put_unaligned_le32(file_sz, &buf[pe_header + 0xb8]);
/* .text file offset */ /* .text file offset */
*(unsigned int *)&buf[pe_header + 0xbc] = 0x200; put_unaligned_le32(0x200, &buf[pe_header + 0xbc]);
#else #else
/* /*
* Address of entry point. startup_32 is at the beginning and * Address of entry point. startup_32 is at the beginning and
* the 64-bit entry point (startup_64) is always 512 bytes * the 64-bit entry point (startup_64) is always 512 bytes
* after. * after.
*/ */
*(unsigned int *)&buf[pe_header + 0x28] = i + 512; put_unaligned_le32(i + 512, &buf[pe_header + 0x28]);
/* .text size */ /* .text size */
*(unsigned int *)&buf[pe_header + 0xc0] = file_sz; put_unaligned_le32(file_sz, &buf[pe_header + 0xc0]);
/* .text vma */ /* .text vma */
*(unsigned int *)&buf[pe_header + 0xc4] = 0x200; put_unaligned_le32(0x200, &buf[pe_header + 0xc4]);
/* .text size of initialised data */ /* .text size of initialised data */
*(unsigned int *)&buf[pe_header + 0xc8] = file_sz; put_unaligned_le32(file_sz, &buf[pe_header + 0xc8]);
/* .text file offset */ /* .text file offset */
*(unsigned int *)&buf[pe_header + 0xcc] = 0x200; put_unaligned_le32(0x200, &buf[pe_header + 0xcc]);
#endif /* CONFIG_X86_32 */ #endif /* CONFIG_X86_32 */
#endif /* CONFIG_EFI_STUB */ #endif /* CONFIG_EFI_STUB */
...@@ -269,8 +265,9 @@ int main(int argc, char ** argv) ...@@ -269,8 +265,9 @@ int main(int argc, char ** argv)
} }
/* Write the CRC */ /* Write the CRC */
fprintf(stderr, "CRC %lx\n", crc); fprintf(stderr, "CRC %x\n", crc);
if (fwrite(&crc, 1, 4, stdout) != 4) put_unaligned_le32(crc, buf);
if (fwrite(buf, 1, 4, stdout) != 4)
die("Writing CRC failed"); die("Writing CRC failed");
close(fd); close(fd);
......
#ifndef _TOOLS_BE_BYTESHIFT_H
#define _TOOLS_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 /* _TOOLS_BE_BYTESHIFT_H */
#ifndef _TOOLS_LE_BYTESHIFT_H
#define _TOOLS_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 /* _TOOLS_LE_BYTESHIFT_H */
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
CC = $(CROSS_COMPILE)gcc CC = $(CROSS_COMPILE)gcc
PTHREAD_LIBS = -lpthread PTHREAD_LIBS = -lpthread
WARNINGS = -Wall -Wextra WARNINGS = -Wall -Wextra
CFLAGS = $(WARNINGS) -g $(PTHREAD_LIBS) CFLAGS = $(WARNINGS) -g $(PTHREAD_LIBS) -I../include
all: testusb ffs-test all: testusb ffs-test
%: %.c %: %.c
......
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/types.h> #include <sys/types.h>
#include <unistd.h> #include <unistd.h>
#include <tools/le_byteshift.h>
#include "../../include/linux/usb/functionfs.h" #include "../../include/linux/usb/functionfs.h"
...@@ -47,34 +48,6 @@ ...@@ -47,34 +48,6 @@
#define le32_to_cpu(x) le32toh(x) #define le32_to_cpu(x) le32toh(x)
#define le16_to_cpu(x) le16toh(x) #define le16_to_cpu(x) le16toh(x)
static inline __u16 get_unaligned_le16(const void *_ptr)
{
const __u8 *ptr = _ptr;
return ptr[0] | (ptr[1] << 8);
}
static inline __u32 get_unaligned_le32(const void *_ptr)
{
const __u8 *ptr = _ptr;
return ptr[0] | (ptr[1] << 8) | (ptr[2] << 16) | (ptr[3] << 24);
}
static inline void put_unaligned_le16(__u16 val, void *_ptr)
{
__u8 *ptr = _ptr;
*ptr++ = val;
*ptr++ = val >> 8;
}
static inline void put_unaligned_le32(__u32 val, void *_ptr)
{
__u8 *ptr = _ptr;
*ptr++ = val;
*ptr++ = val >> 8;
*ptr++ = val >> 16;
*ptr++ = val >> 24;
}
/******************** Messages and Errors ***********************************/ /******************** Messages and Errors ***********************************/
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment