summaryrefslogtreecommitdiffstats
path: root/arch
diff options
context:
space:
mode:
Diffstat (limited to 'arch')
-rw-r--r--arch/efi/Kconfig51
-rw-r--r--arch/efi/Makefile43
-rw-r--r--arch/efi/efi/Makefile2
-rw-r--r--arch/efi/efi/clocksource.c58
-rw-r--r--arch/efi/efi/efi-block-io.c174
-rw-r--r--arch/efi/efi/efi-device.c352
-rw-r--r--arch/efi/efi/efi-image.c293
-rw-r--r--arch/efi/efi/efi.c388
-rw-r--r--arch/efi/efi/env-efi/network/eth0-discover5
-rw-r--r--arch/efi/include/asm/barebox.h1
-rw-r--r--arch/efi/include/asm/bitops.h22
-rw-r--r--arch/efi/include/asm/bitsperlong.h10
-rw-r--r--arch/efi/include/asm/byteorder.h8
-rw-r--r--arch/efi/include/asm/common.h4
-rw-r--r--arch/efi/include/asm/dma.h13
-rw-r--r--arch/efi/include/asm/elf.h60
-rw-r--r--arch/efi/include/asm/io.h55
-rw-r--r--arch/efi/include/asm/posix_types.h1
-rw-r--r--arch/efi/include/asm/sections.h1
-rw-r--r--arch/efi/include/asm/string.h1
-rw-r--r--arch/efi/include/asm/swab.h6
-rw-r--r--arch/efi/include/asm/types.h65
-rw-r--r--arch/efi/include/asm/unaligned.h19
-rw-r--r--arch/efi/include/mach/debug_ll.h20
-rw-r--r--arch/efi/include/mach/efi-device.h45
-rw-r--r--arch/efi/include/mach/efi.h28
-rw-r--r--arch/efi/lib/asm-offsets.c12
-rw-r--r--arch/x86/Kconfig53
-rw-r--r--arch/x86/Makefile75
-rw-r--r--arch/x86/bios/Makefile3
-rw-r--r--arch/x86/bios/bios_disk.S (renamed from arch/x86/lib/bios_disk.S)0
-rw-r--r--arch/x86/bios/memory16.S (renamed from arch/x86/lib/memory16.S)0
-rw-r--r--arch/x86/bios/traveler.S (renamed from arch/x86/lib/traveler.S)0
-rw-r--r--arch/x86/configs/efi_defconfig (renamed from arch/efi/configs/efi_defconfig)2
-rw-r--r--arch/x86/configs/generic_defconfig1
-rw-r--r--arch/x86/include/asm/elf.h74
-rw-r--r--arch/x86/include/asm/io.h71
-rw-r--r--arch/x86/include/asm/types.h51
-rw-r--r--arch/x86/include/asm/unaligned.h5
-rw-r--r--arch/x86/lib/Makefile5
-rw-r--r--arch/x86/lib/asm-offsets.c7
-rw-r--r--arch/x86/mach-efi/.gitignore (renamed from arch/efi/lib/.gitignore)0
-rw-r--r--arch/x86/mach-efi/Makefile (renamed from arch/efi/lib/Makefile)1
-rw-r--r--arch/x86/mach-efi/clocksource.c11
-rw-r--r--arch/x86/mach-efi/crt0-efi-ia32.S (renamed from arch/efi/lib/crt0-efi-ia32.S)0
-rw-r--r--arch/x86/mach-efi/crt0-efi-x86_64.S (renamed from arch/efi/lib/crt0-efi-x86_64.S)0
-rw-r--r--arch/x86/mach-efi/elf_ia32_efi.lds.S (renamed from arch/efi/lib/elf_ia32_efi.lds.S)0
-rw-r--r--arch/x86/mach-efi/elf_x86_64_efi.lds.S (renamed from arch/efi/lib/elf_x86_64_efi.lds.S)0
-rw-r--r--arch/x86/mach-efi/include/mach/barebox.lds.h1
-rw-r--r--arch/x86/mach-efi/include/mach/debug_ll.h1
-rw-r--r--arch/x86/mach-efi/reloc_ia32.c (renamed from arch/efi/lib/reloc_ia32.c)0
-rw-r--r--arch/x86/mach-efi/reloc_x86_64.c (renamed from arch/efi/lib/reloc_x86_64.c)0
52 files changed, 267 insertions, 1831 deletions
diff --git a/arch/efi/Kconfig b/arch/efi/Kconfig
deleted file mode 100644
index d8d0592e51..0000000000
--- a/arch/efi/Kconfig
+++ /dev/null
@@ -1,51 +0,0 @@
-config ARCH_EFI
- bool
- default y
- select HAS_DEBUG_LL
- select HAS_KALLSYMS
- select EFI_GUID
- select EFI_DEVICEPATH
- select PRINTF_UUID
- select GENERIC_FIND_NEXT_BIT
-
-config ARCH_TEXT_BASE
- hex
- default 0x0
-
-menu "EFI specific settings"
-
-config 64BIT
- def_bool y
- help
- Say yes to build a 64-bit binary - formerly known as x86_64
- Say no to build a 32-bit binary - formerly known as i386.
-
- 32-bit support currently does not compile and is not tested
- due to the lack of hardware.
-
-config X86_32
- def_bool y
- depends on !64BIT
-
-config X86_64
- def_bool y
- depends on 64BIT
-
-config ARCH_EFI_REGISTER_COM1
- bool "Register first serial port"
- help
- Say yes here to register the first serial port on ioport 0x3f8.
- This is useful to control barebox over a serial port if the board
- has one. Enabling this option may not work on boards which do not
- have a serial port. Also enable DRIVER_SERIAL_NS16550 to enable
- the NS16550 driver.
-
-endmenu
-
-source common/Kconfig
-source commands/Kconfig
-source net/Kconfig
-source drivers/Kconfig
-source fs/Kconfig
-source lib/Kconfig
-source crypto/Kconfig
diff --git a/arch/efi/Makefile b/arch/efi/Makefile
deleted file mode 100644
index 32a1c152b7..0000000000
--- a/arch/efi/Makefile
+++ /dev/null
@@ -1,43 +0,0 @@
-KBUILD_DEFCONFIG := efi_defconfig
-
-CFLAGS += -fpic -fshort-wchar -mno-sse -mno-mmx
-
-ifeq ($(CONFIG_X86_32),y)
- UTS_MACHINE := i386
- biarch := $(call cc-option,-m32)
- AFLAGS += $(biarch)
- CFLAGS += $(biarch)
- TARGET = efi-app-ia32
-else
- UTS_MACHINE := x86_64
- AFLAGS += -m64
- CFLAGS += -m64 -mno-red-zone
- TARGET = efi-app-x86_64
-endif
-
-lds-$(CONFIG_X86_32) := arch/efi/lib/elf_ia32_efi.lds
-lds-$(CONFIG_X86_64) := arch/efi/lib/elf_x86_64_efi.lds
-
-cmd_barebox__ ?= $(LD) $(LDFLAGS) $(LDFLAGS_barebox) -o $@ \
- -T $(lds-y) \
- -shared -Bsymbolic -nostdlib -znocombreloc \
- --start-group $(barebox-common) \
- --end-group \
- $(filter-out $(barebox-lds) $(barebox-common) FORCE ,$^)
-
-quiet_cmd_efi_image = EFI-IMG $@
- cmd_efi_image = $(OBJCOPY) -j .text -j .sdata -j .data -j .dynamic \
- -j .dynsym -j .rel -j .rela -j .reloc -j __barebox_initcalls \
- -j __barebox_exitcalls -j __barebox_cmd -j .barebox_magicvar \
- -j .bbenv.* --target=$(TARGET) $< $@
-
-KBUILD_BINARY := barebox
-
-LDFLAGS := -m elf_$(UTS_MACHINE) --no-undefined
-
-barebox.efi: $(KBUILD_BINARY) FORCE
- $(call if_changed,efi_image)
-
-KBUILD_IMAGE := barebox.efi
-
-common-y += arch/efi/efi/ arch/efi/lib/
diff --git a/arch/efi/efi/Makefile b/arch/efi/efi/Makefile
deleted file mode 100644
index a856e5907c..0000000000
--- a/arch/efi/efi/Makefile
+++ /dev/null
@@ -1,2 +0,0 @@
-obj-y += efi.o clocksource.o efi-block-io.o efi-device.o efi-image.o
-bbenv-y += env-efi
diff --git a/arch/efi/efi/clocksource.c b/arch/efi/efi/clocksource.c
deleted file mode 100644
index c92c35b112..0000000000
--- a/arch/efi/efi/clocksource.c
+++ /dev/null
@@ -1,58 +0,0 @@
-#include <common.h>
-#include <efi.h>
-#include <mach/efi.h>
-#include <clock.h>
-
-#ifdef __x86_64__
-uint64_t ticks_read(void)
-{
- uint64_t a, d;
-
- __asm__ volatile ("rdtsc" : "=a" (a), "=d" (d));
-
- return (d << 32) | a;
-}
-#else
-uint64_t ticks_read(void)
-{
- uint64_t val;
-
- __asm__ volatile ("rdtsc" : "=A" (val));
-
- return val;
-}
-#endif
-
-static uint64_t freq;
-
-/* count TSC ticks during a millisecond delay */
-static uint64_t ticks_freq(void)
-{
- uint64_t ticks_start, ticks_end;
-
- ticks_start = ticks_read();
- BS->stall(1000);
- ticks_end = ticks_read();
-
- return (ticks_end - ticks_start) * 1000;
-}
-
-static uint64_t efi_clocksource_read(void)
-{
- return 1000 * 1000 * ticks_read() / freq;
-}
-
-static struct clocksource cs = {
- .read = efi_clocksource_read,
- .mask = CLOCKSOURCE_MASK(64),
- .shift = 0,
-};
-
-int efi_clocksource_init(void)
-{
- cs.mult = clocksource_hz2mult(1000 * 1000, cs.shift);
-
- freq = ticks_freq();
-
- return init_clock(&cs);
-}
diff --git a/arch/efi/efi/efi-block-io.c b/arch/efi/efi/efi-block-io.c
deleted file mode 100644
index e02d3b49cc..0000000000
--- a/arch/efi/efi/efi-block-io.c
+++ /dev/null
@@ -1,174 +0,0 @@
-#include <common.h>
-#include <driver.h>
-#include <init.h>
-#include <malloc.h>
-#include <fs.h>
-#include <string.h>
-#include <command.h>
-#include <errno.h>
-#include <linux/stat.h>
-#include <xfuncs.h>
-#include <fcntl.h>
-#include <efi.h>
-#include <block.h>
-#include <disks.h>
-#include <mach/efi.h>
-#include <mach/efi-device.h>
-
-#define EFI_BLOCK_IO_PROTOCOL_REVISION2 0x00020001
-#define EFI_BLOCK_IO_PROTOCOL_REVISION3 ((2<<16) | (31))
-
-struct efi_block_io_media{
- u32 media_id;
- bool removable_media;
- bool media_present;
- bool logical_partition;
- bool read_only;
- bool write_caching;
- u32 block_size;
- u32 io_align;
- u64 last_block;
- u64 lowest_aligned_lba; /* added in Revision 2 */
- u32 logical_blocks_per_physical_block; /* added in Revision 2 */
- u32 optimal_transfer_length_granularity; /* added in Revision 3 */
-};
-
-struct efi_block_io_protocol {
- u64 revision;
- struct efi_block_io_media *media;
- efi_status_t(EFIAPI *reset)(struct efi_block_io_protocol *this,
- bool ExtendedVerification);
- efi_status_t(EFIAPI *read)(struct efi_block_io_protocol *this, u32 media_id,
- u64 lba, unsigned long buffer_size, void *buf);
- efi_status_t(EFIAPI *write)(struct efi_block_io_protocol *this, u32 media_id,
- u64 lba, unsigned long buffer_size, void *buf);
- efi_status_t(EFIAPI *flush)(struct efi_block_io_protocol *this);
-};
-
-struct efi_bio_priv {
- struct efi_block_io_protocol *protocol;
- struct device_d *dev;
- struct block_device blk;
- u32 media_id;
-};
-
-static int efi_bio_read(struct block_device *blk, void *buffer, int block,
- int num_blocks)
-{
- struct efi_bio_priv *priv = container_of(blk, struct efi_bio_priv, blk);
- efi_status_t efiret;
-
- efiret = priv->protocol->read(priv->protocol, priv->media_id,
- block, num_blocks * 512, buffer);
-
- if (EFI_ERROR(efiret))
- return -efi_errno(efiret);
-
- return 0;
-}
-
-static int efi_bio_write(struct block_device *blk,
- const void *buffer, int block, int num_blocks)
-{
- struct efi_bio_priv *priv = container_of(blk, struct efi_bio_priv, blk);
- efi_status_t efiret;
-
- efiret = priv->protocol->write(priv->protocol, priv->media_id,
- block, num_blocks * 512, (void *)buffer);
- if (EFI_ERROR(efiret))
- return -efi_errno(efiret);
-
- return 0;
-}
-
-static int efi_bio_flush(struct block_device *blk)
-{
- struct efi_bio_priv *priv = container_of(blk, struct efi_bio_priv, blk);
- efi_status_t efiret;
-
- efiret = priv->protocol->flush(priv->protocol);
- if (EFI_ERROR(efiret))
- return -efi_errno(efiret);
-
- return 0;
-}
-
-static struct block_device_ops efi_bio_ops = {
- .read = efi_bio_read,
- .write = efi_bio_write,
- .flush = efi_bio_flush,
-};
-
-static void efi_bio_print_info(struct efi_bio_priv *priv)
-{
- struct efi_block_io_media *media = priv->protocol->media;
- u64 revision = priv->protocol->revision;
-
- dev_dbg(priv->dev, "revision: 0x%016llx\n", revision);
- dev_dbg(priv->dev, "media_id: 0x%08x\n", media->media_id);
- dev_dbg(priv->dev, "removable_media: %d\n", media->removable_media);
- dev_dbg(priv->dev, "media_present: %d\n", media->media_present);
- dev_dbg(priv->dev, "logical_partition: %d\n", media->logical_partition);
- dev_dbg(priv->dev, "read_only: %d\n", media->read_only);
- dev_dbg(priv->dev, "write_caching: %d\n", media->write_caching);
- dev_dbg(priv->dev, "block_size: 0x%08x\n", media->block_size);
- dev_dbg(priv->dev, "io_align: 0x%08x\n", media->io_align);
- dev_dbg(priv->dev, "last_block: 0x%016llx\n", media->last_block);
-
- if (revision < EFI_BLOCK_IO_PROTOCOL_REVISION2)
- return;
-
- dev_dbg(priv->dev, "u64 lowest_aligned_lba: 0x%08llx\n",
- media->lowest_aligned_lba);
- dev_dbg(priv->dev, "logical_blocks_per_physical_block: 0x%08x\n",
- media->logical_blocks_per_physical_block);
-
- if (revision < EFI_BLOCK_IO_PROTOCOL_REVISION3)
- return;
-
- dev_dbg(priv->dev, "optimal_transfer_length_granularity: 0x%08x\n",
- media->optimal_transfer_length_granularity);
-}
-
-int efi_bio_probe(struct efi_device *efidev)
-{
- int ret;
- struct efi_bio_priv *priv;
- struct efi_block_io_media *media;
-
- priv = xzalloc(sizeof(*priv));
-
- BS->handle_protocol(efidev->handle, &efi_block_io_protocol_guid,
- (void **)&priv->protocol);
- if (!priv->protocol)
- return -ENODEV;
-
- media = priv->protocol->media;
- efi_bio_print_info(priv);
- priv->dev = &efidev->dev;
-
- priv->blk.cdev.name = xasprintf("disk%d", cdev_find_free_index("disk"));
- priv->blk.blockbits = ffs(media->block_size) - 1;
- priv->blk.num_blocks = media->last_block + 1;
- priv->blk.ops = &efi_bio_ops;
- priv->blk.dev = &efidev->dev;
-
- priv->media_id = media->media_id;
-
- ret = blockdevice_register(&priv->blk);
- if (ret)
- return ret;
-
- parse_partition_table(&priv->blk);
-
- return 0;
-}
-
-static struct efi_driver efi_fs_driver = {
- .driver = {
- .name = "efi-block-io",
- },
- .probe = efi_bio_probe,
- .guid = EFI_BLOCK_IO_PROTOCOL_GUID,
-};
-device_efi_driver(efi_fs_driver);
diff --git a/arch/efi/efi/efi-device.c b/arch/efi/efi/efi-device.c
deleted file mode 100644
index 678a28399d..0000000000
--- a/arch/efi/efi/efi-device.c
+++ /dev/null
@@ -1,352 +0,0 @@
-/*
- * efi-device.c - barebox EFI payload support
- *
- * Copyright (c) 2014 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
- *
- * See file CREDITS for list of people who contributed to this
- * project.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- */
-
-#include <command.h>
-#include <common.h>
-#include <driver.h>
-#include <malloc.h>
-#include <memory.h>
-#include <string.h>
-#include <linux/sizes.h>
-#include <wchar.h>
-#include <init.h>
-#include <efi.h>
-#include <mach/efi.h>
-#include <mach/efi-device.h>
-#include <linux/err.h>
-
-int efi_locate_handle(enum efi_locate_search_type search_type,
- efi_guid_t *protocol,
- void *search_key,
- unsigned long *no_handles,
- efi_handle_t **buffer)
-{
- efi_status_t efiret;
- unsigned long buffer_size = 0;
- efi_handle_t *buf;
-
- efiret = BS->locate_handle(search_type, protocol, search_key, &buffer_size,
- NULL);
- if (EFI_ERROR(efiret) && efiret != EFI_BUFFER_TOO_SMALL)
- return -efi_errno(efiret);
-
- buf = malloc(buffer_size);
- if (!buf)
- return -ENOMEM;
-
- efiret = BS->locate_handle(search_type, protocol, search_key, &buffer_size,
- buf);
- if (EFI_ERROR(efiret)) {
- free(buf);
- return -efi_errno(efiret);
- }
-
- *no_handles = buffer_size / sizeof(efi_handle_t);
- *buffer = buf;
-
- return 0;
-}
-
-static struct efi_device *efi_find_device(efi_handle_t *handle)
-{
- struct device_d *dev;
- struct efi_device *efidev;
-
- bus_for_each_device(&efi_bus, dev) {
- efidev = container_of(dev, struct efi_device, dev);
-
- if (efidev->handle == handle)
- return efidev;
- }
-
- return NULL;
-}
-
-static void efi_devinfo(struct device_d *dev)
-{
- struct efi_device *efidev = to_efi_device(dev);
- int i;
-
- printf("Protocols:\n");
-
- for (i = 0; i < efidev->num_guids; i++)
- printf(" %d: %pUl: %s\n", i, &efidev->guids[i],
- efi_guid_string(&efidev->guids[i]));
-}
-
-static efi_handle_t *efi_find_parent(efi_handle_t *handle)
-{
- unsigned long handle_count = 0;
- efi_handle_t *handles = NULL, *parent;
- unsigned long num_guids;
- efi_guid_t **guids;
- int ret, i, j, k;
- efi_status_t efiret;
- struct efi_open_protocol_information_entry *entry_buffer;
- unsigned long entry_count;
-
- ret = efi_locate_handle(all_handles, NULL, NULL, &handle_count, &handles);
- if (ret)
- return NULL;
-
- /*
- * Normally one would expect a function/pointer to retrieve the parent.
- * With EFI we have to:
- * - get all handles
- * - for each handle get the registered protocols
- * - for each protocol get the users
- * - the user which matches the input handle is the parent
- */
- for (i = 0; i < handle_count; i++) {
- efiret = BS->open_protocol(handles[i], &efi_device_path_protocol_guid,
- NULL, NULL, NULL, EFI_OPEN_PROTOCOL_TEST_PROTOCOL);
- if (EFI_ERROR(efiret))
- continue;
-
- BS->protocols_per_handle(handles[i], &guids, &num_guids);
- for (j = 0; j < num_guids; j++) {
- efiret = BS->open_protocol_information(handles[i], guids[j],
- &entry_buffer, &entry_count);
- for (k = 0; k < entry_count; k++) {
- if (entry_buffer[k].controller_handle == NULL)
- continue;
- if (entry_buffer[k].controller_handle == handles[i])
- continue;
- if (entry_buffer[k].controller_handle == handle) {
- parent = handles[i];
- goto out;
- }
- }
- }
- }
-
- parent = NULL;
-
- free(handles);
-out:
- return parent;
-}
-
-static struct efi_device *efi_add_device(efi_handle_t *handle, efi_guid_t **guids,
- int num_guids)
-{
- struct efi_device *efidev;
- int i;
- efi_guid_t *guidarr;
- efi_status_t efiret;
- void *devpath;
-
- efidev = efi_find_device(handle);
- if (efidev)
- return ERR_PTR(-EEXIST);
-
- efiret = BS->open_protocol(handle, &efi_device_path_protocol_guid,
- NULL, NULL, NULL, EFI_OPEN_PROTOCOL_TEST_PROTOCOL);
- if (EFI_ERROR(efiret))
- return ERR_PTR(-EINVAL);
-
- guidarr = malloc(sizeof(efi_guid_t) * num_guids);
-
- for (i = 0; i < num_guids; i++)
- memcpy(&guidarr[i], guids[i], sizeof(efi_guid_t));
-
- efiret = BS->open_protocol(handle, &efi_device_path_protocol_guid,
- &devpath, NULL, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL);
- if (EFI_ERROR(efiret)) {
- free(guidarr);
- return ERR_PTR(-EINVAL);
- }
-
- efidev = xzalloc(sizeof(*efidev));
-
- efidev->guids = guidarr;
- efidev->num_guids = num_guids;
- efidev->handle = handle;
- efidev->dev.bus = &efi_bus;
- efidev->dev.id = DEVICE_ID_SINGLE;
- efidev->dev.info = efi_devinfo;
- efidev->devpath = devpath;
-
- BS->handle_protocol(handle, &guidarr[0], &efidev->protocol);
-
- sprintf(efidev->dev.name, "handle-%p", handle);
-
- efidev->parent_handle = efi_find_parent(efidev->handle);
-
- return efidev;
-}
-
-
-static int efi_register_device(struct efi_device *efidev)
-{
- char *dev_path_str;
- struct efi_device *parent;
- int ret;
-
- if (efi_find_device(efidev->handle))
- return -EEXIST;
-
- if (efidev->parent_handle) {
- parent = efi_find_device(efidev->parent_handle);
- if (!parent)
- return -EINVAL;
-
- efidev->dev.parent = &parent->dev;
- }
-
- ret = register_device(&efidev->dev);
- if (ret)
- return ret;
-
- dev_path_str = device_path_to_str(efidev->devpath);
- if (dev_path_str) {
- dev_add_param_fixed(&efidev->dev, "devpath", dev_path_str);
- free(dev_path_str);
- }
-
- debug("registered efi device %s\n", dev_name(&efidev->dev));
-
- return 0;
-}
-
-/**
- * efi_register_devices - iterate over all EFI handles and register
- * the devices found
- *
- * in barebox we treat all EFI handles which support the device_path
- * protocol as devices. This function iterates over all handles and
- * registers the corresponding devices. efi_register_devices is safe
- * to call multiple times. Already registered devices will be ignored.
- *
- */
-void efi_register_devices(void)
-{
- unsigned long handle_count = 0;
- efi_handle_t *handles = NULL;
- unsigned long num_guids;
- efi_guid_t **guids;
- int ret, i;
- struct efi_device **efidevs;
- int registered;
-
- ret = efi_locate_handle(all_handles, NULL, NULL, &handle_count, &handles);
- if (ret)
- return;
-
- efidevs = xzalloc(handle_count * sizeof(struct efi_device *));
-
- for (i = 0; i < handle_count; i++) {
- BS->protocols_per_handle(handles[i], &guids, &num_guids);
-
- efidevs[i] = efi_add_device(handles[i], guids, num_guids);
- }
-
- /*
- * We have a list of devices we want to register, but can only
- * register a device when all parents are registered already.
- * Do this by continiously iterating over the list until no
- * further devices are registered.
- */
- do {
- registered = 0;
-
- for (i = 0; i < handle_count; i++) {
- if (IS_ERR(efidevs[i]))
- continue;
-
- ret = efi_register_device(efidevs[i]);
- if (!ret) {
- efidevs[i] = ERR_PTR(-EEXIST);
- registered = 1;
- }
- }
- } while (registered);
-
- free(efidevs);
- free(handles);
-}
-
-int efi_connect_all(void)
-{
- efi_status_t efiret;
- unsigned long handle_count;
- efi_handle_t *handle_buffer;
- int i;
-
- efiret = BS->locate_handle_buffer(all_handles, NULL, NULL, &handle_count,
- &handle_buffer);
- if (EFI_ERROR(efiret))
- return -efi_errno(efiret);
-
- for (i = 0; i < handle_count; i++)
- efiret = BS->connect_controller(handle_buffer[i], NULL, NULL, true);
-
- if (handle_buffer)
- BS->free_pool(handle_buffer);
-
- return 0;
-}
-
-static int efi_bus_match(struct device_d *dev, struct driver_d *drv)
-{
- struct efi_driver *efidrv = to_efi_driver(drv);
- struct efi_device *efidev = to_efi_device(dev);
- int i;
-
- for (i = 0; i < efidev->num_guids; i++) {
- if (!memcmp(&efidrv->guid, &efidev->guids[i], sizeof(efi_guid_t)))
- return 0;
- }
-
- return 1;
-}
-
-static int efi_bus_probe(struct device_d *dev)
-{
- struct efi_driver *efidrv = to_efi_driver(dev->driver);
- struct efi_device *efidev = to_efi_device(dev);
-
- return efidrv->probe(efidev);
-}
-
-static void efi_bus_remove(struct device_d *dev)
-{
- struct efi_driver *efidrv = to_efi_driver(dev->driver);
- struct efi_device *efidev = to_efi_device(dev);
-
- if (efidrv->remove)
- efidrv->remove(efidev);
-}
-
-struct bus_type efi_bus = {
- .name = "efi",
- .match = efi_bus_match,
- .probe = efi_bus_probe,
- .remove = efi_bus_remove,
-};
-
-static int efi_init_devices(void)
-{
- bus_register(&efi_bus);
-
- efi_register_devices();
-
- return 0;
-}
-core_initcall(efi_init_devices);
diff --git a/arch/efi/efi/efi-image.c b/arch/efi/efi/efi-image.c
deleted file mode 100644
index 27f3c1b39c..0000000000
--- a/arch/efi/efi/efi-image.c
+++ /dev/null
@@ -1,293 +0,0 @@
-/*
- * efi-image.c - barebox EFI payload support
- *
- * Copyright (c) 2014 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
- *
- * See file CREDITS for list of people who contributed to this
- * project.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- */
-
-#include <clock.h>
-#include <common.h>
-#include <linux/sizes.h>
-#include <memory.h>
-#include <command.h>
-#include <magicvar.h>
-#include <init.h>
-#include <driver.h>
-#include <io.h>
-#include <efi.h>
-#include <malloc.h>
-#include <string.h>
-#include <linux/err.h>
-#include <boot.h>
-#include <bootm.h>
-#include <fs.h>
-#include <libfile.h>
-#include <binfmt.h>
-#include <wchar.h>
-#include <mach/efi.h>
-#include <mach/efi-device.h>
-
-struct linux_kernel_header {
- /* first sector of the image */
- uint8_t code1[0x0020];
- uint16_t cl_magic; /**< Magic number 0xA33F */
- uint16_t cl_offset; /**< The offset of command line */
- uint8_t code2[0x01F1 - 0x0020 - 2 - 2];
- uint8_t setup_sects; /**< The size of the setup in sectors */
- uint16_t root_flags; /**< If the root is mounted readonly */
- uint16_t syssize; /**< obsolete */
- uint16_t swap_dev; /**< obsolete */
- uint16_t ram_size; /**< obsolete */
- uint16_t vid_mode; /**< Video mode control */
- uint16_t root_dev; /**< Default root device number */
- uint16_t boot_flag; /**< 0xAA55 magic number */
-
- /* second sector of the image */
- uint16_t jump; /**< Jump instruction (this is code!) */
- uint32_t header; /**< Magic signature "HdrS" */
- uint16_t version; /**< Boot protocol version supported */
- uint32_t realmode_swtch; /**< Boot loader hook */
- uint16_t start_sys; /**< The load-low segment (obsolete) */
- uint16_t kernel_version; /**< Points to kernel version string */
- uint8_t type_of_loader; /**< Boot loader identifier */
- uint8_t loadflags; /**< Boot protocol option flags */
- uint16_t setup_move_size; /**< Move to high memory size */
- uint32_t code32_start; /**< Boot loader hook */
- uint32_t ramdisk_image; /**< initrd load address */
- uint32_t ramdisk_size; /**< initrd size */
- uint32_t bootsect_kludge; /**< obsolete */
- uint16_t heap_end_ptr; /**< Free memory after setup end */
- uint8_t ext_loader_ver; /**< boot loader's extension of the version number */
- uint8_t ext_loader_type; /**< boot loader's extension of its type */
- uint32_t cmd_line_ptr; /**< Points to the kernel command line */
- uint32_t initrd_addr_max; /**< Highest address for initrd */
- uint32_t kernel_alignment; /**< Alignment unit required by the kernel */
- uint8_t relocatable_kernel; /** */
- uint8_t min_alignment; /** */
- uint16_t xloadflags; /** */
- uint32_t cmdline_size; /** */
- uint32_t hardware_subarch; /** */
- uint64_t hardware_subarch_data; /** */
- uint32_t payload_offset; /** */
- uint32_t payload_length; /** */
- uint64_t setup_data; /** */
- uint64_t pref_address; /** */
- uint32_t init_size; /** */
- uint32_t handover_offset; /** */
-} __attribute__ ((packed));
-
-int efi_load_image(const char *file, efi_loaded_image_t **loaded_image,
- efi_handle_t *h)
-{
- void *exe;
- size_t size;
- efi_handle_t handle;
- efi_status_t efiret = EFI_SUCCESS;
-
- exe = read_file(file, &size);
- if (!exe)
- return -EINVAL;
-
- efiret = BS->load_image(false, efi_parent_image, efi_device_path, exe, size,
- &handle);
- if (EFI_ERROR(efiret)) {
- pr_err("failed to LoadImage: %s\n", efi_strerror(efiret));
- goto out;
- };
-
- efiret = BS->open_protocol(handle, &efi_loaded_image_protocol_guid,
- (void **)loaded_image,
- efi_parent_image, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL);
- if (EFI_ERROR(efiret)) {
- pr_err("failed to OpenProtocol: %s\n", efi_strerror(efiret));
- BS->unload_image(handle);
- goto out;
- }
-
- *h = handle;
-out:
- memset(exe, 0, size);
- free(exe);
- return -efi_errno(efiret);
-}
-
-static int efi_execute_image(const char *file)
-{
- efi_handle_t handle;
- efi_loaded_image_t *loaded_image;
- efi_status_t efiret;
- struct linux_kernel_header *image_header;
- const char *options;
- bool is_driver;
- int ret;
-
- ret = efi_load_image(file, &loaded_image, &handle);
- if (ret)
- return ret;
-
- is_driver = (loaded_image->image_code_type == EFI_BOOT_SERVICES_CODE) ||
- (loaded_image->image_code_type == EFI_RUNTIME_SERVICES_CODE);
-
- image_header = (struct linux_kernel_header *)loaded_image->image_base;
- if (image_header->boot_flag == 0xAA55 &&
- image_header->header == 0x53726448) {
- pr_debug("Linux kernel detected. Adding bootargs.");
- options = linux_bootargs_get();
- pr_err("add linux options '%s'\n", options);
- loaded_image->load_options = xstrdup_char_to_wchar(options);
- loaded_image->load_options_size =
- (strlen(options) + 1) * sizeof(wchar_t);
- shutdown_barebox();
- }
-
- efiret = BS->start_image(handle, NULL, NULL);
- if (EFI_ERROR(efiret))
- pr_err("failed to StartImage: %s\n", efi_strerror(efiret));
-
- if (!is_driver)
- BS->unload_image(handle);
-
- efi_connect_all();
- efi_register_devices();
-
- return -efi_errno(efiret);
-}
-
-#ifdef __x86_64__
-typedef void(*handover_fn)(void *image, efi_system_table_t *table,
- struct linux_kernel_header *header);
-
-static inline void linux_efi_handover(efi_handle_t handle,
- struct linux_kernel_header *header)
-{
- handover_fn handover;
-
- asm volatile ("cli");
- handover = (handover_fn)((long)header->code32_start + 512 +
- header->handover_offset);
- handover(handle, efi_sys_table, header);
-}
-#else
-typedef void(*handover_fn)(VOID *image, EFI_SYSTEM_TABLE *table,
- struct SetupHeader *setup) __attribute__((regparm(0)));
-
-static inline void linux_efi_handover(efi_handle_t handle,
- struct linux_kernel_header *header)
-{
- handover_fn handover;
-
- handover = (handover_fn)((long)header->code32_start +
- header->handover_offset);
- handover(handle, efi_sys_table, header);
-}
-#endif
-
-static int do_bootm_efi(struct image_data *data)
-{
- void *tmp;
- void *initrd = NULL;
- size_t size;
- efi_handle_t handle;
- int ret;
- const char *options;
- efi_loaded_image_t *loaded_image;
- struct linux_kernel_header *image_header, *boot_header;
-
- ret = efi_load_image(data->os_file, &loaded_image, &handle);
- if (ret)
- return ret;
-
- image_header = (struct linux_kernel_header *)loaded_image->image_base;
-
- if (image_header->boot_flag != 0xAA55 ||
- image_header->header != 0x53726448 ||
- image_header->version < 0x20b ||
- !image_header->relocatable_kernel) {
- pr_err("Not a valid kernel image!\n");
- BS->unload_image(handle);
- return -EINVAL;
- }
-
- boot_header = xmalloc(0x4000);
- memset(boot_header, 0, 0x4000);
- memcpy(boot_header, image_header, sizeof(*image_header));
-
- boot_header->type_of_loader = 0xff;
-
- if (data->initrd_file) {
- tmp = read_file(data->initrd_file, &size);
- initrd = xmemalign(PAGE_SIZE, PAGE_ALIGN(size));
- memcpy(initrd, tmp, size);
- memset(initrd + size, 0, PAGE_ALIGN(size) - size);
- free(tmp);
- boot_header->ramdisk_image = (uint64_t)initrd;
- boot_header->ramdisk_size = PAGE_ALIGN(size);
- }
-
- options = linux_bootargs_get();
- boot_header->cmd_line_ptr = (uint64_t)options;
- boot_header->cmdline_size = strlen(options);
-
- boot_header->code32_start = (uint64_t)loaded_image->image_base +
- (image_header->setup_sects+1) * 512;
-
- if (bootm_verbose(data)) {
- printf("\nStarting kernel at 0x%p", loaded_image->image_base);
- if (data->initrd_file)
- printf(", initrd at 0x%08x",
- boot_header->ramdisk_image);
- printf("...\n");
- }
-
- if (data->dryrun) {
- BS->unload_image(handle);
- free(boot_header);
- free(initrd);
- return 0;
- }
-
- efi_set_variable_usec("LoaderTimeExecUSec", &efi_systemd_vendor_guid,
- get_time_ns()/1000);
-
- shutdown_barebox();
- linux_efi_handover(handle, boot_header);
-
- return 0;
-}
-
-static struct image_handler efi_handle_tr = {
- .name = "EFI Application",
- .bootm = do_bootm_efi,
- .filetype = filetype_exe,
-};
-
-static int efi_execute(struct binfmt_hook *b, char *file, int argc, char **argv)
-{
- return efi_execute_image(file);
-}
-
-static struct binfmt_hook binfmt_efi_hook = {
- .type = filetype_exe,
- .hook = efi_execute,
-};
-
-static int efi_register_image_handler(void)
-{
- register_image_handler(&efi_handle_tr);
- binfmt_register(&binfmt_efi_hook);
-
- return 0;
-}
-late_initcall(efi_register_image_handler);
diff --git a/arch/efi/efi/efi.c b/arch/efi/efi/efi.c
deleted file mode 100644
index 36ac016a91..0000000000
--- a/arch/efi/efi/efi.c
+++ /dev/null
@@ -1,388 +0,0 @@
-/*
- * efi.c - barebox EFI payload support
- *
- * Copyright (c) 2014 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
- *
- * See file CREDITS for list of people who contributed to this
- * project.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- */
-
-#include <common.h>
-#include <linux/sizes.h>
-#include <memory.h>
-#include <clock.h>
-#include <command.h>
-#include <magicvar.h>
-#include <init.h>
-#include <restart.h>
-#include <driver.h>
-#include <platform_data/serial-ns16550.h>
-#include <io.h>
-#include <efi.h>
-#include <malloc.h>
-#include <string.h>
-#include <linux/err.h>
-#include <boot.h>
-#include <fs.h>
-#include <binfmt.h>
-#include <wchar.h>
-#include <envfs.h>
-#include <efi.h>
-#include <mach/efi.h>
-#include <mach/efi-device.h>
-
-efi_runtime_services_t *RT;
-efi_boot_services_t *BS;
-efi_system_table_t *efi_sys_table;
-efi_handle_t efi_parent_image;
-struct efi_device_path *efi_device_path;
-efi_loaded_image_t *efi_loaded_image;
-
-void *efi_get_variable(char *name, efi_guid_t *vendor, int *var_size)
-{
- efi_status_t efiret;
- void *buf;
- unsigned long size = 0;
- s16 *name16 = xstrdup_char_to_wchar(name);
-
- efiret = RT->get_variable(name16, vendor, NULL, &size, NULL);
-
- if (EFI_ERROR(efiret) && efiret != EFI_BUFFER_TOO_SMALL) {
- buf = ERR_PTR(-efi_errno(efiret));
- goto out;
- }
-
- buf = malloc(size);
- if (!buf) {
- buf = ERR_PTR(-ENOMEM);
- goto out;
- }
-
- efiret = RT->get_variable(name16, vendor, NULL, &size, buf);
- if (EFI_ERROR(efiret)) {
- free(buf);
- buf = ERR_PTR(-efi_errno(efiret));
- goto out;
- }
-
- if (var_size)
- *var_size = size;
-
-out:
- free(name16);
-
- return buf;
-}
-
-int efi_set_variable(char *name, efi_guid_t *vendor, uint32_t attributes,
- void *buf, unsigned long size)
-{
- efi_status_t efiret = EFI_SUCCESS;
- s16 *name16 = xstrdup_char_to_wchar(name);
-
- efiret = RT->set_variable(name16, vendor, attributes, size, buf);
-
- free(name16);
-
- return -efi_errno(efiret);
-}
-
-int efi_set_variable_usec(char *name, efi_guid_t *vendor, uint64_t usec)
-{
- char buf[20];
- wchar_t buf16[40];
-
- snprintf(buf, sizeof(buf), "%lld", usec);
- strcpy_char_to_wchar(buf16, buf);
-
- return efi_set_variable(name, vendor,
- EFI_VARIABLE_BOOTSERVICE_ACCESS |
- EFI_VARIABLE_RUNTIME_ACCESS, buf16,
- (strlen(buf)+1) * sizeof(wchar_t));
-}
-
-struct efi_boot {
- u32 attributes;
- u16 file_path_len;
- char *description;
- struct efi_device_path *path;
- void *binary;
-};
-
-struct efi_boot *efi_get_boot(int num)
-{
- struct efi_boot *boot = xzalloc(sizeof(*boot));
- void *buf, *ptr;
- int size;
- char *name;
-
- name = xasprintf("Boot%04X", num);
-
- buf = efi_get_global_var(name, &size);
-
- free(name);
-
- if (IS_ERR(buf)) {
- free(boot);
- return NULL;
- }
-
- ptr = buf;
-
- boot->attributes = *(u32 *)ptr;
-
- ptr += sizeof(u32);
-
- boot->file_path_len = *(u16 *)ptr;
-
- ptr += sizeof(u16);
-
- boot->description = xstrdup_wchar_to_char(ptr);
-
- ptr += (strlen(boot->description) + 1) * 2;
-
- printf("description: %s\n", boot->description);
-
- boot->path = memdup(ptr, boot->file_path_len);
-
- printf("path: %s\n", device_path_to_str(boot->path));
-
- return boot;
-}
-
-static int misc_init(void)
-{
- efi_get_boot(1);
- efi_get_boot(2);
- efi_get_boot(3);
-
- return 0;
-}
-late_initcall(misc_init);
-
-const char *efi_strerror(efi_status_t err)
-{
- const char *str;
-
- switch (err) {
- case EFI_SUCCESS: str = "Success"; break;
- case EFI_LOAD_ERROR: str = "Load Error"; break;
- case EFI_INVALID_PARAMETER: str = "Invalid Parameter"; break;
- case EFI_UNSUPPORTED: str = "Unsupported"; break;
- case EFI_BAD_BUFFER_SIZE: str = "Bad Buffer Size"; break;
- case EFI_BUFFER_TOO_SMALL: str = "Buffer Too Small"; break;
- case EFI_NOT_READY: str = "Not Ready"; break;
- case EFI_DEVICE_ERROR: str = "Device Error"; break;
- case EFI_WRITE_PROTECTED: str = "Write Protected"; break;
- case EFI_OUT_OF_RESOURCES: str = "Out of Resources"; break;
- case EFI_VOLUME_CORRUPTED: str = "Volume Corrupt"; break;
- case EFI_VOLUME_FULL: str = "Volume Full"; break;
- case EFI_NO_MEDIA: str = "No Media"; break;
- case EFI_MEDIA_CHANGED: str = "Media changed"; break;
- case EFI_NOT_FOUND: str = "Not Found"; break;
- case EFI_ACCESS_DENIED: str = "Access Denied"; break;
- case EFI_NO_RESPONSE: str = "No Response"; break;
- case EFI_NO_MAPPING: str = "No mapping"; break;
- case EFI_TIMEOUT: str = "Time out"; break;
- case EFI_NOT_STARTED: str = "Not started"; break;
- case EFI_ALREADY_STARTED: str = "Already started"; break;
- case EFI_ABORTED: str = "Aborted"; break;
- case EFI_ICMP_ERROR: str = "ICMP Error"; break;
- case EFI_TFTP_ERROR: str = "TFTP Error"; break;
- case EFI_PROTOCOL_ERROR: str = "Protocol Error"; break;
- case EFI_INCOMPATIBLE_VERSION: str = "Incompatible Version"; break;
- case EFI_SECURITY_VIOLATION: str = "Security Violation"; break;
- case EFI_CRC_ERROR: str = "CRC Error"; break;
- case EFI_END_OF_MEDIA: str = "End of Media"; break;
- case EFI_END_OF_FILE: str = "End of File"; break;
- case EFI_INVALID_LANGUAGE: str = "Invalid Language"; break;
- case EFI_COMPROMISED_DATA: str = "Compromised Data"; break;
- default: str = "unknown error";
- }
-
- return str;
-}
-
-int efi_errno(efi_status_t err)
-{
- int ret;
-
- switch (err) {
- case EFI_SUCCESS: ret = 0; break;
- case EFI_LOAD_ERROR: ret = EIO; break;
- case EFI_INVALID_PARAMETER: ret = EINVAL; break;
- case EFI_UNSUPPORTED: ret = ENOTSUPP; break;
- case EFI_BAD_BUFFER_SIZE: ret = EINVAL; break;
- case EFI_BUFFER_TOO_SMALL: ret = EINVAL; break;
- case EFI_NOT_READY: ret = EAGAIN; break;
- case EFI_DEVICE_ERROR: ret = EIO; break;
- case EFI_WRITE_PROTECTED: ret = EROFS; break;
- case EFI_OUT_OF_RESOURCES: ret = ENOMEM; break;
- case EFI_VOLUME_CORRUPTED: ret = EIO; break;
- case EFI_VOLUME_FULL: ret = ENOSPC; break;
- case EFI_NO_MEDIA: ret = ENOMEDIUM; break;
- case EFI_MEDIA_CHANGED: ret = ENOMEDIUM; break;
- case EFI_NOT_FOUND: ret = ENODEV; break;
- case EFI_ACCESS_DENIED: ret = EACCES; break;
- case EFI_NO_RESPONSE: ret = ETIMEDOUT; break;
- case EFI_NO_MAPPING: ret = EINVAL; break;
- case EFI_TIMEOUT: ret = ETIMEDOUT; break;
- case EFI_NOT_STARTED: ret = EINVAL; break;
- case EFI_ALREADY_STARTED: ret = EINVAL; break;
- case EFI_ABORTED: ret = EINTR; break;
- case EFI_ICMP_ERROR: ret = EINVAL; break;
- case EFI_TFTP_ERROR: ret = EINVAL; break;
- case EFI_PROTOCOL_ERROR: ret = EPROTO; break;
- case EFI_INCOMPATIBLE_VERSION: ret = EINVAL; break;
- case EFI_SECURITY_VIOLATION: ret = EINVAL; break;
- case EFI_CRC_ERROR: ret = EINVAL; break;
- case EFI_END_OF_MEDIA: ret = EINVAL; break;
- case EFI_END_OF_FILE: ret = EINVAL; break;
- case EFI_INVALID_LANGUAGE: ret = EINVAL; break;
- case EFI_COMPROMISED_DATA: ret = EINVAL; break;
- default: ret = EINVAL;
- }
-
- return ret;
-}
-
-static struct NS16550_plat ns16550_plat = {
- .clock = 115200 * 16,
-};
-
-static int efi_console_init(void)
-{
- barebox_set_model("barebox EFI payload");
-
- add_generic_device("efi-stdio", DEVICE_ID_SINGLE, NULL, 0 , 0, 0, NULL);
-
- if (IS_ENABLED(CONFIG_ARCH_EFI_REGISTER_COM1))
- add_ns16550_device(0, 0x3f8, 0x10, IORESOURCE_IO | IORESOURCE_MEM_8BIT,
- &ns16550_plat);
-
- return 0;
-}
-console_initcall(efi_console_init);
-
-static void __noreturn efi_restart_system(struct restart_handler *rst)
-{
- RT->reset_system(EFI_RESET_WARM, EFI_SUCCESS, 0, NULL);
-
- hang();
-}
-
-static int restart_register_feature(void)
-{
- restart_handler_register_fn(efi_restart_system);
-
- return 0;
-}
-coredevice_initcall(restart_register_feature);
-
-extern char image_base[];
-extern initcall_t __barebox_initcalls_start[], __barebox_early_initcalls_end[],
- __barebox_initcalls_end[];
-
-static int efi_init(void)
-{
- char *env;
-
- defaultenv_append_directory(env_efi);
-
- env = xasprintf("/efivars/barebox-env-%pUl", &efi_barebox_vendor_guid);
- default_environment_path_set(env);
-
- return 0;
-}
-device_initcall(efi_init);
-
-/**
- * efi-main - Entry point for EFI images
- */
-efi_status_t efi_main(efi_handle_t image, efi_system_table_t *sys_table)
-{
- efi_physical_addr_t mem;
- size_t memsize;
- efi_status_t efiret;
- char *uuid;
-
-#ifdef DEBUG
- sys_table->con_out->output_string(sys_table->con_out, L"barebox\n");
-#endif
-
- BS = sys_table->boottime;
-
- efi_parent_image = image;
- efi_sys_table = sys_table;
- RT = sys_table->runtime;
-
- efiret = BS->open_protocol(efi_parent_image, &efi_loaded_image_protocol_guid,
- (void **)&efi_loaded_image,
- efi_parent_image, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL);
- if (!EFI_ERROR(efiret))
- BS->handle_protocol(efi_loaded_image->device_handle,
- &efi_device_path_protocol_guid, (void **)&efi_device_path);
-
- mem = 0x3fffffff;
- for (memsize = SZ_256M; memsize >= SZ_8M; memsize /= 2) {
- efiret = BS->allocate_pages(EFI_ALLOCATE_MAX_ADDRESS,
- EFI_LOADER_DATA,
- memsize/PAGE_SIZE, &mem);
- if (!EFI_ERROR(efiret))
- break;
- if (efiret != EFI_OUT_OF_RESOURCES)
- panic("failed to allocate malloc pool: %s\n",
- efi_strerror(efiret));
- }
- if (EFI_ERROR(efiret))
- panic("failed to allocate malloc pool: %s\n",
- efi_strerror(efiret));
- mem_malloc_init((void *)mem, (void *)mem + memsize);
-
- efi_clocksource_init();
- efi_set_variable_usec("LoaderTimeInitUSec", &efi_systemd_vendor_guid,
- get_time_ns()/1000);
-
- uuid = device_path_to_partuuid(device_path_from_handle(
- efi_loaded_image->device_handle));
- if (uuid) {
- wchar_t *uuid16 = xstrdup_char_to_wchar(uuid);
- efi_set_variable("LoaderDevicePartUUID",
- &efi_systemd_vendor_guid,
- EFI_VARIABLE_BOOTSERVICE_ACCESS |
- EFI_VARIABLE_RUNTIME_ACCESS,
- uuid16, (strlen(uuid)+1) * sizeof(wchar_t));
- free(uuid);
- free(uuid16);
- }
-
- start_barebox();
-
- return EFI_SUCCESS;
-}
-
-static int do_efiexit(int argc, char *argv[])
-{
- return BS->exit(efi_parent_image, EFI_SUCCESS, 0, NULL);
-}
-
-BAREBOX_CMD_HELP_START(efiexit)
-BAREBOX_CMD_HELP_TEXT("Leave barebox and return to the calling EFI process\n")
-BAREBOX_CMD_HELP_END
-
-BAREBOX_CMD_START(efiexit)
- .cmd = do_efiexit,
- BAREBOX_CMD_DESC("Usage: efiexit")
- BAREBOX_CMD_GROUP(CMD_GRP_MISC)
- BAREBOX_CMD_HELP(cmd_efiexit_help)
-BAREBOX_CMD_END
diff --git a/arch/efi/efi/env-efi/network/eth0-discover b/arch/efi/efi/env-efi/network/eth0-discover
deleted file mode 100644
index 62c31a553c..0000000000
--- a/arch/efi/efi/env-efi/network/eth0-discover
+++ /dev/null
@@ -1,5 +0,0 @@
-#!/bin/sh
-
-for i in /boot/network-drivers/*; do
- $i;
-done
diff --git a/arch/efi/include/asm/barebox.h b/arch/efi/include/asm/barebox.h
deleted file mode 100644
index 2997587d82..0000000000
--- a/arch/efi/include/asm/barebox.h
+++ /dev/null
@@ -1 +0,0 @@
-/* dummy */
diff --git a/arch/efi/include/asm/bitops.h b/arch/efi/include/asm/bitops.h
deleted file mode 100644
index 447023da63..0000000000
--- a/arch/efi/include/asm/bitops.h
+++ /dev/null
@@ -1,22 +0,0 @@
-#ifndef _SANDBOX_BITOPS_H
-#define _SANDBOX_BITOPS_H
-
-/* nothing but the defaults.. */
-#include <asm-generic/bitops/__ffs.h>
-#include <asm-generic/bitops/__fls.h>
-#include <asm-generic/bitops/ffs.h>
-#include <asm-generic/bitops/fls.h>
-#include <asm-generic/bitops/ffz.h>
-#include <asm-generic/bitops/find.h>
-#include <asm-generic/bitops/fls64.h>
-#include <asm-generic/bitops/hweight.h>
-#include <asm-generic/bitops/ops.h>
-
-#define set_bit(x, y) __set_bit(x, y)
-#define clear_bit(x, y) __clear_bit(x, y)
-#define change_bit(x, y) __change_bit(x, y)
-#define test_and_set_bit(x, y) __test_and_set_bit(x, y)
-#define test_and_clear_bit(x, y) __test_and_clear_bit(x, y)
-#define test_and_change_bit(x, y) __test_and_change_bit(x, y)
-
-#endif
diff --git a/arch/efi/include/asm/bitsperlong.h b/arch/efi/include/asm/bitsperlong.h
deleted file mode 100644
index 00c1fc2625..0000000000
--- a/arch/efi/include/asm/bitsperlong.h
+++ /dev/null
@@ -1,10 +0,0 @@
-#ifndef __ASM_BITSPERLONG_H
-#define __ASM_BITSPERLONG_H
-
-#ifdef __x86_64__
-#define BITS_PER_LONG 64
-#else
-#define BITS_PER_LONG 32
-#endif
-
-#endif /* __ASM_BITSPERLONG_H */
diff --git a/arch/efi/include/asm/byteorder.h b/arch/efi/include/asm/byteorder.h
deleted file mode 100644
index 37316f2371..0000000000
--- a/arch/efi/include/asm/byteorder.h
+++ /dev/null
@@ -1,8 +0,0 @@
-#ifndef _I386_BYTEORDER_H
-#define _I386_BYTEORDER_H
-
-#include <asm/types.h>
-
-#include <linux/byteorder/little_endian.h>
-
-#endif /* _I386_BYTEORDER_H */
diff --git a/arch/efi/include/asm/common.h b/arch/efi/include/asm/common.h
deleted file mode 100644
index b0e6b7fb18..0000000000
--- a/arch/efi/include/asm/common.h
+++ /dev/null
@@ -1,4 +0,0 @@
-#ifndef ASM_COMMON_H
-#define ASM_COMMON_H
-
-#endif /* ASM_COMMON_H */
diff --git a/arch/efi/include/asm/dma.h b/arch/efi/include/asm/dma.h
deleted file mode 100644
index 459536779e..0000000000
--- a/arch/efi/include/asm/dma.h
+++ /dev/null
@@ -1,13 +0,0 @@
-/*
- * Copyright (C) 2012 by Marc Kleine-Budde <mkl@pengutronix.de>
- *
- * This file is released under the GPLv2
- *
- */
-
-#ifndef __ASM_DMA_H
-#define __ASM_DMA_H
-
-/* empty*/
-
-#endif /* __ASM_DMA_H */
diff --git a/arch/efi/include/asm/elf.h b/arch/efi/include/asm/elf.h
deleted file mode 100644
index ddde035188..0000000000
--- a/arch/efi/include/asm/elf.h
+++ /dev/null
@@ -1,60 +0,0 @@
-#ifndef __ASM_SANDBOX_ELF_H__
-#define __ASM_SANDBOX_ELF_H__
-
-#ifdef __i386__
-
-typedef struct user_fxsr_struct elf_fpxregset_t;
-
-#define R_386_NONE 0
-#define R_386_32 1
-#define R_386_PC32 2
-#define R_386_GOT32 3
-#define R_386_PLT32 4
-#define R_386_COPY 5
-#define R_386_GLOB_DAT 6
-#define R_386_JMP_SLOT 7
-#define R_386_RELATIVE 8
-#define R_386_GOTOFF 9
-#define R_386_GOTPC 10
-#define R_386_NUM 11
-
-/*
- * These are used to set parameters in the core dumps.
- */
-#define ELF_CLASS ELFCLASS32
-#define ELF_DATA ELFDATA2LSB
-#define ELF_ARCH EM_386
-
-#else
-
-/* x86-64 relocation types */
-#define R_X86_64_NONE 0 /* No reloc */
-#define R_X86_64_64 1 /* Direct 64 bit */
-#define R_X86_64_PC32 2 /* PC relative 32 bit signed */
-#define R_X86_64_GOT32 3 /* 32 bit GOT entry */
-#define R_X86_64_PLT32 4 /* 32 bit PLT address */
-#define R_X86_64_COPY 5 /* Copy symbol at runtime */
-#define R_X86_64_GLOB_DAT 6 /* Create GOT entry */
-#define R_X86_64_JUMP_SLOT 7 /* Create PLT entry */
-#define R_X86_64_RELATIVE 8 /* Adjust by program base */
-#define R_X86_64_GOTPCREL 9 /* 32 bit signed pc relative
- offset to GOT */
-#define R_X86_64_32 10 /* Direct 32 bit zero extended */
-#define R_X86_64_32S 11 /* Direct 32 bit sign extended */
-#define R_X86_64_16 12 /* Direct 16 bit zero extended */
-#define R_X86_64_PC16 13 /* 16 bit sign extended pc relative */
-#define R_X86_64_8 14 /* Direct 8 bit sign extended */
-#define R_X86_64_PC8 15 /* 8 bit sign extended pc relative */
-
-#define R_X86_64_NUM 16
-
-/*
- * These are used to set parameters in the core dumps.
- */
-#define ELF_CLASS ELFCLASS64
-#define ELF_DATA ELFDATA2LSB
-#define ELF_ARCH EM_X86_64
-
-#endif
-
-#endif /* __ASM_SANDBOX_ELF_H__ */
diff --git a/arch/efi/include/asm/io.h b/arch/efi/include/asm/io.h
deleted file mode 100644
index ac8a9c1b35..0000000000
--- a/arch/efi/include/asm/io.h
+++ /dev/null
@@ -1,55 +0,0 @@
-#ifndef __ASM_SANDBOX_IO_H
-#define __ASM_SANDBOX_IO_H
-
-#define build_mmio_read(name, size, type, reg, barrier) \
- static inline type name(const volatile void *addr) \
- { type ret; asm volatile("mov" size " %1,%0":reg (ret) \
- :"m" (*(volatile type*)addr) barrier); return ret; }
-
-build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
-build_mmio_read(readw, "w", unsigned short, "=r", :"memory")
-build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
-
-#define build_mmio_write(name, size, type, reg, barrier) \
- static inline void name(type val, volatile void *addr) \
- { asm volatile("mov" size " %0,%1": :reg (val), \
- "m" (*(volatile type*)addr) barrier); }
-
-build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
-build_mmio_write(writew, "w", unsigned short, "r", :"memory")
-build_mmio_write(writel, "l", unsigned int, "r", :"memory")
-
-#define BUILDIO(bwl, bw, type) \
-static inline void out##bwl(unsigned type value, int port) \
-{ \
- asm volatile("out" #bwl " %" #bw "0, %w1" \
- : : "a"(value), "Nd"(port)); \
-} \
- \
-static inline unsigned type in##bwl(int port) \
-{ \
- unsigned type value; \
- asm volatile("in" #bwl " %w1, %" #bw "0" \
- : "=a"(value) : "Nd"(port)); \
- return value; \
-} \
- \
-static inline void outs##bwl(int port, const void *addr, unsigned long count) \
-{ \
- asm volatile("rep; outs" #bwl \
- : "+S"(addr), "+c"(count) : "d"(port)); \
-} \
- \
-static inline void ins##bwl(int port, void *addr, unsigned long count) \
-{ \
- asm volatile("rep; ins" #bwl \
- : "+D"(addr), "+c"(count) : "d"(port)); \
-}
-
-BUILDIO(b, b, char)
-BUILDIO(w, w, short)
-BUILDIO(l, , int)
-
-#define IO_SPACE_LIMIT 0xffff
-
-#endif /* __ASM_SANDBOX_IO_H */
diff --git a/arch/efi/include/asm/posix_types.h b/arch/efi/include/asm/posix_types.h
deleted file mode 100644
index 22cae6230c..0000000000
--- a/arch/efi/include/asm/posix_types.h
+++ /dev/null
@@ -1 +0,0 @@
-#include <asm-generic/posix_types.h>
diff --git a/arch/efi/include/asm/sections.h b/arch/efi/include/asm/sections.h
deleted file mode 100644
index 2b8c516038..0000000000
--- a/arch/efi/include/asm/sections.h
+++ /dev/null
@@ -1 +0,0 @@
-#include <asm-generic/sections.h>
diff --git a/arch/efi/include/asm/string.h b/arch/efi/include/asm/string.h
deleted file mode 100644
index 2997587d82..0000000000
--- a/arch/efi/include/asm/string.h
+++ /dev/null
@@ -1 +0,0 @@
-/* dummy */
diff --git a/arch/efi/include/asm/swab.h b/arch/efi/include/asm/swab.h
deleted file mode 100644
index 60a90120b6..0000000000
--- a/arch/efi/include/asm/swab.h
+++ /dev/null
@@ -1,6 +0,0 @@
-#ifndef _ASM_SWAB_H
-#define _ASM_SWAB_H
-
-/* nothing. use generic functions */
-
-#endif /* _ASM_SWAB_H */
diff --git a/arch/efi/include/asm/types.h b/arch/efi/include/asm/types.h
deleted file mode 100644
index 3caac398d8..0000000000
--- a/arch/efi/include/asm/types.h
+++ /dev/null
@@ -1,65 +0,0 @@
-#ifndef __ASM_I386_TYPES_H
-#define __ASM_I386_TYPES_H
-
-#ifndef __ASSEMBLY__
-
-#ifdef __x86_64__
-/*
- * This is used in dlmalloc. On X86_64 we need it to be
- * 64 bit
- */
-#define INTERNAL_SIZE_T unsigned long
-
-/*
- * This is a Kconfig variable in the Kernel, but we want to detect
- * this during compile time, so we set it here.
- */
-#define CONFIG_PHYS_ADDR_T_64BIT
-
-#endif
-
-typedef unsigned short umode_t;
-
-/*
- * __xx is ok: it doesn't pollute the POSIX namespace. Use these in the
- * header files exported to user space
- */
-
-typedef __signed__ char __s8;
-typedef unsigned char __u8;
-
-typedef __signed__ short __s16;
-typedef unsigned short __u16;
-
-typedef __signed__ int __s32;
-typedef unsigned int __u32;
-
-#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
-typedef __signed__ long long __s64;
-typedef unsigned long long __u64;
-#endif
-
-/*
- * These aren't exported outside the kernel to avoid name space clashes
- */
-#ifdef __KERNEL__
-
-typedef signed char s8;
-typedef unsigned char u8;
-
-typedef signed short s16;
-typedef unsigned short u16;
-
-typedef signed int s32;
-typedef unsigned int u32;
-
-typedef signed long long s64;
-typedef unsigned long long u64;
-
-#include <asm/bitsperlong.h>
-
-#endif /* __KERNEL__ */
-
-#endif
-
-#endif
diff --git a/arch/efi/include/asm/unaligned.h b/arch/efi/include/asm/unaligned.h
deleted file mode 100644
index d02da6e60d..0000000000
--- a/arch/efi/include/asm/unaligned.h
+++ /dev/null
@@ -1,19 +0,0 @@
-#ifndef _ASM_SANDBOX_UNALIGNED_H
-#define _ASM_SANDBOX_UNALIGNED_H
-
-/*
- * The architecture sandbox is compiled on can do unaligned accesses itself.
- */
-
-#include <linux/unaligned/access_ok.h>
-#include <linux/unaligned/generic.h>
-
-#if __BYTE_ORDER == __LITTLE_ENDIAN
-#define get_unaligned __get_unaligned_le
-#define put_unaligned __put_unaligned_le
-#else
-#define get_unaligned __get_unaligned_be
-#define put_unaligned __put_unaligned_be
-#endif
-
-#endif /* _ASM_SANDBOX_UNALIGNED_H */
diff --git a/arch/efi/include/mach/debug_ll.h b/arch/efi/include/mach/debug_ll.h
deleted file mode 100644
index 0fb2cb8c2a..0000000000
--- a/arch/efi/include/mach/debug_ll.h
+++ /dev/null
@@ -1,20 +0,0 @@
-#ifndef __MACH_DEBUG_LL_H__
-#define __MACH_DEBUG_LL_H__
-
-#define EFI_DEBUG 0
-#define EFI_DEBUG_CLEAR_MEMORY 0
-
-#include <efi.h>
-#include <mach/efi.h>
-
-static inline void PUTC_LL(char c)
-{
- uint16_t str[2] = {};
- struct efi_simple_text_output_protocol *con_out = efi_sys_table->con_out;
-
- str[0] = c;
-
- con_out->output_string(con_out, str);
-}
-
-#endif
diff --git a/arch/efi/include/mach/efi-device.h b/arch/efi/include/mach/efi-device.h
deleted file mode 100644
index fe074a44bb..0000000000
--- a/arch/efi/include/mach/efi-device.h
+++ /dev/null
@@ -1,45 +0,0 @@
-#ifndef __MACH_EFI_DEVICE_H
-#define __MACH_EFI_DEVICE_H
-
-struct efi_device {
- struct device_d dev;
- efi_guid_t *guids;
- int num_guids;
- efi_handle_t handle;
- efi_handle_t parent_handle;
- void *protocol;
- struct efi_device_path *devpath;
-};
-
-struct efi_driver {
- struct driver_d driver;
- int (*probe)(struct efi_device *efidev);
- void (*remove)(struct efi_device *efidev);
- efi_guid_t guid;
-};
-
-extern struct bus_type efi_bus;
-
-static inline struct efi_device *to_efi_device(struct device_d *dev)
-{
- return container_of(dev, struct efi_device, dev);
-}
-
-static inline struct efi_driver *to_efi_driver(struct driver_d *drv)
-{
- return container_of(drv, struct efi_driver, driver);
-}
-
-#define device_efi_driver(drv) \
- register_driver_macro(device, efi, drv)
-
-static inline int efi_driver_register(struct efi_driver *efidrv)
-{
- efidrv->driver.bus = &efi_bus;
- return register_driver(&efidrv->driver);
-}
-
-int efi_connect_all(void);
-void efi_register_devices(void);
-
-#endif /* __MACH_EFI_DEVICE_H */
diff --git a/arch/efi/include/mach/efi.h b/arch/efi/include/mach/efi.h
deleted file mode 100644
index 2b25cf1868..0000000000
--- a/arch/efi/include/mach/efi.h
+++ /dev/null
@@ -1,28 +0,0 @@
-#ifndef __MACH_EFI_H
-#define __MACH_EFI_H
-
-#include <efi.h>
-
-const char *efi_strerror(efi_status_t err);
-
-extern efi_system_table_t *efi_sys_table;
-extern efi_handle_t efi_parent_image;
-extern struct efi_device_path *efi_device_path;
-extern efi_loaded_image_t *efi_loaded_image;
-
-int efi_errno(efi_status_t err);
-
-int efi_clocksource_init(void);
-
-void *efi_get_variable(char *name, efi_guid_t *vendor, int *var_size);
-
-static inline void *efi_get_global_var(char *name, int *var_size)
-{
- return efi_get_variable(name, &efi_global_variable_guid, var_size);
-}
-
-int efi_set_variable(char *name, efi_guid_t *vendor, uint32_t attributes,
- void *buf, unsigned long size);
-int efi_set_variable_usec(char *name, efi_guid_t *vendor, uint64_t usec);
-
-#endif /* __MACH_EFI_H */
diff --git a/arch/efi/lib/asm-offsets.c b/arch/efi/lib/asm-offsets.c
deleted file mode 100644
index 22f382b71e..0000000000
--- a/arch/efi/lib/asm-offsets.c
+++ /dev/null
@@ -1,12 +0,0 @@
-/*
- * Generate definitions needed by assembly language modules.
- * This code generates raw asm output which is post-processed to extract
- * and format the required data.
- */
-
-#include <linux/kbuild.h>
-
-int main(void)
-{
- return 0;
-}
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 346640dcda..52ccf4894f 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -1,9 +1,16 @@
#
#
#
+config X86
+ bool
+ select HAS_KALLSYMS
+ select GENERIC_FIND_NEXT_BIT
+ default y
+
config ARCH_TEXT_BASE
hex
default 0x00007c00 if MACH_X86_GENERIC
+ default 0x0 if MACH_EFI_GENERIC
config BOARD_LINKER_SCRIPT
bool
@@ -14,17 +21,33 @@ config GENERIC_LINKER_SCRIPT
default y
depends on !BOARD_LINKER_SCRIPT
-config X86
+menu "ARCH specific settings"
+
+config 64BIT
+ def_bool y if X86_EFI
+ help
+ Say yes to build a 64-bit binary - formerly known as x86_64
+ Say no to build a 32-bit binary - formerly known as i386.
+
+ 32-bit support currently does not compile and is not tested
+ due to the lack of hardware.
+
+config X86_32
+ def_bool y
+ depends on !64BIT
+
+config X86_64
+ def_bool y
+ depends on 64BIT
+
+endmenu
+
+config X86_BOOTLOADER
bool
- select HAS_KALLSYMS
+ select X86_32
select HAS_MODULES
select HAVE_CONFIGURABLE_MEMORY_LAYOUT
select HAVE_CONFIGURABLE_TEXT_BASE
- select GENERIC_FIND_NEXT_BIT
- default y
-
-config X86_BOOTLOADER
- bool
choice
prompt "Select your board"
@@ -32,14 +55,30 @@ choice
config MACH_X86_GENERIC
bool "Generic x86"
select X86_BOOTLOADER
+ depends on !X86_EFI
help
Say Y here if you want barebox to be your BIOS based bootloader
+config MACH_EFI_GENERIC
+ bool "Generic EFI"
+ depends on X86_EFI
+ select HAS_DEBUG_LL
+ help
+ Say Y here if you want barebox to be your EFI based bootloader
+
endchoice
choice
prompt "Bring up type"
+ config X86_EFI
+ bool "EFI"
+ select EFI_BOOTUP
+ select EFI_GUID
+ select EFI_DEVICEPATH
+ select PRINTF_UUID
+ select CLOCKSOURCE_EFI_X86
+
config X86_BIOS_BRINGUP
bool "16 bit BIOS"
help
diff --git a/arch/x86/Makefile b/arch/x86/Makefile
index da17d70bdc..0751e63649 100644
--- a/arch/x86/Makefile
+++ b/arch/x86/Makefile
@@ -1,20 +1,47 @@
KBUILD_DEFCONFIG := generic_defconfig
-CPPFLAGS += -D__X86__ -fno-strict-aliasing
+CPPFLAGS += -D__X86__
-board-y := x86_generic
-machine-y := i386
+board-$(CONFIG_MACH_X86_GENERIC) := x86_generic
TEXT_BASE = $(CONFIG_TEXT_BASE)
-CPPFLAGS += -march=i386 -m32 -DTEXT_BASE=$(TEXT_BASE) \
+ifeq ($(CONFIG_X86_EFI),y)
+machine-y := efi
+CFLAGS += -fpic -fshort-wchar -mno-sse -mno-mmx
+ifeq ($(CONFIG_X86_32),y)
+ TARGET = efi-app-ia32
+else
+ TARGET = efi-app-x86_64
+endif
+else
+CPPFLAGS += -fno-strict-aliasing
+CPPFLAGS += -march=i386 -DTEXT_BASE=$(TEXT_BASE) \
-fno-unwind-tables -fno-asynchronous-unwind-tables
-LDFLAGS += -m elf_i386
+
+machine-y := i386
+endif
+
+ifeq ($(CONFIG_X86_32),y)
+ UTS_MACHINE := i386
+ biarch := $(call cc-option,-m32)
+ AFLAGS += $(biarch)
+ CFLAGS += $(biarch)
+ CPPFLAGS += $(biarch)
+else
+ UTS_MACHINE := x86_64
+ AFLAGS += -m64
+ CFLAGS += -m64 -mno-red-zone
+ CPPFLAGS += -m64
+endif
+
ifndef CONFIG_MODULES
# Add cleanup flags
+ifneq ($(CONFIG_X86_EFI),y)
CPPFLAGS += -fdata-sections -ffunction-sections
-LDFLAGS_uboot += -static --gc-sections
+LDFLAGS_barebox += -static --gc-sections
+endif
endif
machdirs := $(patsubst %,arch/x86/mach-%/,$(machine-y))
@@ -39,12 +66,46 @@ endif
common-y += $(BOARD) $(MACH)
common-y += arch/x86/lib/
-common-y += arch/x86/boot/
+common-$(CONFIG_X86_BIOS_BRINGUP) += arch/x86/bios/
# arch/x86/cpu/
+ifeq ($(CONFIG_X86_EFI),y)
+lds-$(CONFIG_X86_32) := arch/x86/mach-efi/elf_ia32_efi.lds
+lds-$(CONFIG_X86_64) := arch/x86/mach-efi/elf_x86_64_efi.lds
+
+cmd_barebox__ ?= $(LD) $(LDFLAGS) $(LDFLAGS_barebox) -o $@ \
+ -T $(lds-y) \
+ -shared -Bsymbolic -nostdlib -znocombreloc \
+ --start-group $(barebox-common) \
+ --end-group \
+ $(filter-out $(barebox-lds) $(barebox-common) FORCE ,$^)
+
+quiet_cmd_efi_image = EFI-IMG $@
+ cmd_efi_image = $(OBJCOPY) -j .text -j .sdata -j .data -j .dynamic \
+ -j .dynsym -j .rel -j .rela -j .reloc -j __barebox_initcalls \
+ -j __barebox_exitcalls -j __barebox_cmd -j .barebox_magicvar \
+ -j .bbenv.* -j .bblogo.* --target=$(TARGET) $< $@
+
+KBUILD_BINARY := barebox
+
+LDFLAGS := --no-undefined
+
+barebox.efi: $(KBUILD_BINARY) FORCE
+ $(call if_changed,efi_image)
+
+KBUILD_IMAGE := barebox.efi
+
+else
+common-y += arch/x86/boot/
+
lds-$(CONFIG_GENERIC_LINKER_SCRIPT) := arch/x86/lib/barebox.lds
lds-$(CONFIG_BOARD_LINKER_SCRIPT) := $(BOARD)/barebox.lds
+endif
+
+LDFLAGS += -m elf_$(UTS_MACHINE)
+
+CLEAN_FILES += $(lds-y)
CLEAN_FILES += arch/x86/lib/barebox.lds barebox.map barebox.S
diff --git a/arch/x86/bios/Makefile b/arch/x86/bios/Makefile
new file mode 100644
index 0000000000..414ee42a4a
--- /dev/null
+++ b/arch/x86/bios/Makefile
@@ -0,0 +1,3 @@
+obj-y += memory16.o
+obj-y += traveler.o
+obj-y += bios_disk.o
diff --git a/arch/x86/lib/bios_disk.S b/arch/x86/bios/bios_disk.S
index cce33e67af..cce33e67af 100644
--- a/arch/x86/lib/bios_disk.S
+++ b/arch/x86/bios/bios_disk.S
diff --git a/arch/x86/lib/memory16.S b/arch/x86/bios/memory16.S
index 76ee72b56c..76ee72b56c 100644
--- a/arch/x86/lib/memory16.S
+++ b/arch/x86/bios/memory16.S
diff --git a/arch/x86/lib/traveler.S b/arch/x86/bios/traveler.S
index 113b19802e..113b19802e 100644
--- a/arch/x86/lib/traveler.S
+++ b/arch/x86/bios/traveler.S
diff --git a/arch/efi/configs/efi_defconfig b/arch/x86/configs/efi_defconfig
index f24148d3bc..0d9a44a4d2 100644
--- a/arch/efi/configs/efi_defconfig
+++ b/arch/x86/configs/efi_defconfig
@@ -1,7 +1,6 @@
CONFIG_MMU=y
CONFIG_MALLOC_SIZE=0x0
CONFIG_MALLOC_TLSF=y
-CONFIG_PROMPT="barebox> "
CONFIG_HUSH_FANCY_PROMPT=y
CONFIG_CMDLINE_EDITING=y
CONFIG_AUTO_COMPLETE=y
@@ -21,6 +20,7 @@ CONFIG_DEBUG_LL=y
CONFIG_LONGHELP=y
CONFIG_CMD_IOMEM=y
CONFIG_CMD_MEMINFO=y
+# CONFIG_CMD_LINUX16 is not set
CONFIG_CMD_GO=y
CONFIG_CMD_LOADB=y
CONFIG_CMD_RESET=y
diff --git a/arch/x86/configs/generic_defconfig b/arch/x86/configs/generic_defconfig
index 5ff7f531eb..3b94e02a7e 100644
--- a/arch/x86/configs/generic_defconfig
+++ b/arch/x86/configs/generic_defconfig
@@ -1,3 +1,4 @@
+CONFIG_X86_BIOS_BRINGUP=y
CONFIG_X86_HDBOOT=y
CONFIG_STACK_SIZE=0x7000
CONFIG_EXPERIMENTAL=y
diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
index 94a40c6243..ddde035188 100644
--- a/arch/x86/include/asm/elf.h
+++ b/arch/x86/include/asm/elf.h
@@ -1,26 +1,60 @@
+#ifndef __ASM_SANDBOX_ELF_H__
+#define __ASM_SANDBOX_ELF_H__
+
+#ifdef __i386__
+
+typedef struct user_fxsr_struct elf_fpxregset_t;
+
+#define R_386_NONE 0
+#define R_386_32 1
+#define R_386_PC32 2
+#define R_386_GOT32 3
+#define R_386_PLT32 4
+#define R_386_COPY 5
+#define R_386_GLOB_DAT 6
+#define R_386_JMP_SLOT 7
+#define R_386_RELATIVE 8
+#define R_386_GOTOFF 9
+#define R_386_GOTPC 10
+#define R_386_NUM 11
+
/*
- * 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.
- *
- *
+ * These are used to set parameters in the core dumps.
*/
+#define ELF_CLASS ELFCLASS32
+#define ELF_DATA ELFDATA2LSB
+#define ELF_ARCH EM_386
-/**
- * @file
- * @brief x86 specific elf information
- *
- */
+#else
-#ifndef _ASM_X86_ELF_H
-#define _ASM_X86_ELF_H
+/* x86-64 relocation types */
+#define R_X86_64_NONE 0 /* No reloc */
+#define R_X86_64_64 1 /* Direct 64 bit */
+#define R_X86_64_PC32 2 /* PC relative 32 bit signed */
+#define R_X86_64_GOT32 3 /* 32 bit GOT entry */
+#define R_X86_64_PLT32 4 /* 32 bit PLT address */
+#define R_X86_64_COPY 5 /* Copy symbol at runtime */
+#define R_X86_64_GLOB_DAT 6 /* Create GOT entry */
+#define R_X86_64_JUMP_SLOT 7 /* Create PLT entry */
+#define R_X86_64_RELATIVE 8 /* Adjust by program base */
+#define R_X86_64_GOTPCREL 9 /* 32 bit signed pc relative
+ offset to GOT */
+#define R_X86_64_32 10 /* Direct 32 bit zero extended */
+#define R_X86_64_32S 11 /* Direct 32 bit sign extended */
+#define R_X86_64_16 12 /* Direct 16 bit zero extended */
+#define R_X86_64_PC16 13 /* 16 bit sign extended pc relative */
+#define R_X86_64_8 14 /* Direct 8 bit sign extended */
+#define R_X86_64_PC8 15 /* 8 bit sign extended pc relative */
+
+#define R_X86_64_NUM 16
+
+/*
+ * These are used to set parameters in the core dumps.
+ */
+#define ELF_CLASS ELFCLASS64
+#define ELF_DATA ELFDATA2LSB
+#define ELF_ARCH EM_X86_64
-#define ELF_CLASS ELFCLASS32
+#endif
-#endif /* _ASM_X86_ELF_H */
+#endif /* __ASM_SANDBOX_ELF_H__ */
diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
index f020510569..df4bc99ec8 100644
--- a/arch/x86/include/asm/io.h
+++ b/arch/x86/include/asm/io.h
@@ -12,44 +12,6 @@
#include <asm/byteorder.h>
-#define IO_SPACE_LIMIT 0xffff
-
-static inline void outb(unsigned char value, int port)
-{
- asm volatile("outb %b0, %w1" : : "a"(value), "Nd"(port));
-}
-
-static inline void outw(unsigned short value, int port)
-{
- asm volatile("outw %w0, %w1" : : "a"(value), "Nd"(port));
-}
-
-static inline void outl(unsigned long value, int port)
-{
- asm volatile("outl %0, %w1" : : "a"(value), "Nd"(port));
-}
-
-static inline unsigned char inb(int port)
-{
- unsigned char value;
- asm volatile("inb %w1, %b0" : "=a"(value) : "Nd"(port));
- return value;
-}
-
-static inline unsigned short inw(int port)
-{
- unsigned short value;
- asm volatile("inw %w1, %w0" : "=a"(value) : "Nd"(port));
- return value;
-}
-
-static inline unsigned long inl(int port)
-{
- unsigned long value;
- asm volatile("inl %w1, %0" : "=a"(value) : "Nd"(port));
- return value;
-}
-
#define build_mmio_read(name, size, type, reg, barrier) \
static inline type name(const volatile void *addr) \
{ type ret; asm volatile("mov" size " %1,%0":reg (ret) \
@@ -68,6 +30,39 @@ build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
build_mmio_write(writew, "w", unsigned short, "r", :"memory")
build_mmio_write(writel, "l", unsigned int, "r", :"memory")
+#define BUILDIO(bwl, bw, type) \
+static inline void out##bwl(unsigned type value, int port) \
+{ \
+ asm volatile("out" #bwl " %" #bw "0, %w1" \
+ : : "a"(value), "Nd"(port)); \
+} \
+ \
+static inline unsigned type in##bwl(int port) \
+{ \
+ unsigned type value; \
+ asm volatile("in" #bwl " %w1, %" #bw "0" \
+ : "=a"(value) : "Nd"(port)); \
+ return value; \
+} \
+ \
+static inline void outs##bwl(int port, const void *addr, unsigned long count) \
+{ \
+ asm volatile("rep; outs" #bwl \
+ : "+S"(addr), "+c"(count) : "d"(port)); \
+} \
+ \
+static inline void ins##bwl(int port, void *addr, unsigned long count) \
+{ \
+ asm volatile("rep; ins" #bwl \
+ : "+D"(addr), "+c"(count) : "d"(port)); \
+}
+
+BUILDIO(b, b, char)
+BUILDIO(w, w, short)
+BUILDIO(l, , int)
+
+#define IO_SPACE_LIMIT 0xffff
+
/* do a tiny io delay */
static inline void io_delay(void)
{
diff --git a/arch/x86/include/asm/types.h b/arch/x86/include/asm/types.h
index 7349ba03c2..3caac398d8 100644
--- a/arch/x86/include/asm/types.h
+++ b/arch/x86/include/asm/types.h
@@ -1,21 +1,29 @@
+#ifndef __ASM_I386_TYPES_H
+#define __ASM_I386_TYPES_H
+
+#ifndef __ASSEMBLY__
+
+#ifdef __x86_64__
+/*
+ * This is used in dlmalloc. On X86_64 we need it to be
+ * 64 bit
+ */
+#define INTERNAL_SIZE_T unsigned long
+
/*
- * 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.
- *
- *
+ * This is a Kconfig variable in the Kernel, but we want to detect
+ * this during compile time, so we set it here.
*/
+#define CONFIG_PHYS_ADDR_T_64BIT
-#ifndef __ASM_X86_TYPES_H
-#define __ASM_X86_TYPES_H
+#endif
-#ifndef __ASSEMBLY__
+typedef unsigned short umode_t;
+
+/*
+ * __xx is ok: it doesn't pollute the POSIX namespace. Use these in the
+ * header files exported to user space
+ */
typedef __signed__ char __s8;
typedef unsigned char __u8;
@@ -26,8 +34,15 @@ typedef unsigned short __u16;
typedef __signed__ int __s32;
typedef unsigned int __u32;
+#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
typedef __signed__ long long __s64;
typedef unsigned long long __u64;
+#endif
+
+/*
+ * These aren't exported outside the kernel to avoid name space clashes
+ */
+#ifdef __KERNEL__
typedef signed char s8;
typedef unsigned char u8;
@@ -41,10 +56,10 @@ typedef unsigned int u32;
typedef signed long long s64;
typedef unsigned long long u64;
-typedef unsigned short umode_t;
+#include <asm/bitsperlong.h>
-#include <asm-generic/bitsperlong.h>
+#endif /* __KERNEL__ */
-#endif /* __ASSEMBLY__ */
+#endif
-#endif /* __ASM_X86_TYPES_H */
+#endif
diff --git a/arch/x86/include/asm/unaligned.h b/arch/x86/include/asm/unaligned.h
index a7bd416b47..7e38706c5d 100644
--- a/arch/x86/include/asm/unaligned.h
+++ b/arch/x86/include/asm/unaligned.h
@@ -8,7 +8,12 @@
#include <linux/unaligned/access_ok.h>
#include <linux/unaligned/generic.h>
+#if __BYTE_ORDER == __LITTLE_ENDIAN
#define get_unaligned __get_unaligned_le
#define put_unaligned __put_unaligned_le
+#else
+#define get_unaligned __get_unaligned_be
+#define put_unaligned __put_unaligned_be
+#endif
#endif /* _ASM_X86_UNALIGNED_H */
diff --git a/arch/x86/lib/Makefile b/arch/x86/lib/Makefile
index b67629f115..05e43f0f2b 100644
--- a/arch/x86/lib/Makefile
+++ b/arch/x86/lib/Makefile
@@ -1,9 +1,8 @@
extra-$(CONFIG_GENERIC_LINKER_SCRIPT) += barebox.lds
+ifneq ($(CONFIG_X86_EFI),y)
obj-y += memory.o
obj-y += gdt.o
+endif
# needed, when running via a 16 bit BIOS
-obj-$(CONFIG_X86_BIOS_BRINGUP) += memory16.o
-obj-$(CONFIG_X86_BIOS_BRINGUP) += traveler.o
-obj-$(CONFIG_X86_BIOS_BRINGUP) += bios_disk.o
obj-$(CONFIG_CMD_LINUX16) += linux_start.o
diff --git a/arch/x86/lib/asm-offsets.c b/arch/x86/lib/asm-offsets.c
index b1be3e5390..0f9c47eaa9 100644
--- a/arch/x86/lib/asm-offsets.c
+++ b/arch/x86/lib/asm-offsets.c
@@ -6,6 +6,13 @@
#include <linux/kbuild.h>
+#ifdef CONFIG_EFI_BOOTUP
+int main(void)
+{
+ return 0;
+}
+#else
void common(void)
{
}
+#endif
diff --git a/arch/efi/lib/.gitignore b/arch/x86/mach-efi/.gitignore
index 847e317701..847e317701 100644
--- a/arch/efi/lib/.gitignore
+++ b/arch/x86/mach-efi/.gitignore
diff --git a/arch/efi/lib/Makefile b/arch/x86/mach-efi/Makefile
index c8a97bae07..f633e7c7ed 100644
--- a/arch/efi/lib/Makefile
+++ b/arch/x86/mach-efi/Makefile
@@ -1,4 +1,5 @@
obj-$(CONFIG_X86_64) += reloc_x86_64.o crt0-efi-x86_64.o
obj-$(CONFIG_X86_32) += reloc_ia32.o crt0-efi-ia32.o
+obj-y += clocksource.o
extra-$(CONFIG_X86_32) += elf_ia32_efi.lds
extra-$(CONFIG_X86_64) += elf_x86_64_efi.lds
diff --git a/arch/x86/mach-efi/clocksource.c b/arch/x86/mach-efi/clocksource.c
new file mode 100644
index 0000000000..2023fa19ac
--- /dev/null
+++ b/arch/x86/mach-efi/clocksource.c
@@ -0,0 +1,11 @@
+#include <common.h>
+#include <init.h>
+#include <driver.h>
+
+static int efi_x86_pure_init(void)
+{
+ struct device_d *dev = device_alloc("efi-cs-x86", DEVICE_ID_SINGLE);
+
+ return platform_device_register(dev);
+}
+core_initcall(efi_x86_pure_init);
diff --git a/arch/efi/lib/crt0-efi-ia32.S b/arch/x86/mach-efi/crt0-efi-ia32.S
index 6f0f2e872e..6f0f2e872e 100644
--- a/arch/efi/lib/crt0-efi-ia32.S
+++ b/arch/x86/mach-efi/crt0-efi-ia32.S
diff --git a/arch/efi/lib/crt0-efi-x86_64.S b/arch/x86/mach-efi/crt0-efi-x86_64.S
index aa03106e9c..aa03106e9c 100644
--- a/arch/efi/lib/crt0-efi-x86_64.S
+++ b/arch/x86/mach-efi/crt0-efi-x86_64.S
diff --git a/arch/efi/lib/elf_ia32_efi.lds.S b/arch/x86/mach-efi/elf_ia32_efi.lds.S
index 69f43f5547..69f43f5547 100644
--- a/arch/efi/lib/elf_ia32_efi.lds.S
+++ b/arch/x86/mach-efi/elf_ia32_efi.lds.S
diff --git a/arch/efi/lib/elf_x86_64_efi.lds.S b/arch/x86/mach-efi/elf_x86_64_efi.lds.S
index 93d34d17ab..93d34d17ab 100644
--- a/arch/efi/lib/elf_x86_64_efi.lds.S
+++ b/arch/x86/mach-efi/elf_x86_64_efi.lds.S
diff --git a/arch/x86/mach-efi/include/mach/barebox.lds.h b/arch/x86/mach-efi/include/mach/barebox.lds.h
new file mode 100644
index 0000000000..40a8c178f1
--- /dev/null
+++ b/arch/x86/mach-efi/include/mach/barebox.lds.h
@@ -0,0 +1 @@
+/* empty */
diff --git a/arch/x86/mach-efi/include/mach/debug_ll.h b/arch/x86/mach-efi/include/mach/debug_ll.h
new file mode 100644
index 0000000000..e144d86e00
--- /dev/null
+++ b/arch/x86/mach-efi/include/mach/debug_ll.h
@@ -0,0 +1 @@
+#include <efi/debug_ll.h>
diff --git a/arch/efi/lib/reloc_ia32.c b/arch/x86/mach-efi/reloc_ia32.c
index 46929631ec..46929631ec 100644
--- a/arch/efi/lib/reloc_ia32.c
+++ b/arch/x86/mach-efi/reloc_ia32.c
diff --git a/arch/efi/lib/reloc_x86_64.c b/arch/x86/mach-efi/reloc_x86_64.c
index 1db72f5dbc..1db72f5dbc 100644
--- a/arch/efi/lib/reloc_x86_64.c
+++ b/arch/x86/mach-efi/reloc_x86_64.c