Re: [PATCH 059/112] efi: payload: init: restrict barebox mem to first 1G only on x86

2024-01-05 Thread Michael Olbrich
On Fri, Jan 05, 2024 at 11:41:09AM +0100, Ahmad Fatoum wrote:
> On 05.01.24 10:31, Michael Olbrich wrote:
> > On Fri, Jan 05, 2024 at 10:14:33AM +0100, Ahmad Fatoum wrote:
> >> On 04.01.24 19:10, Michael Olbrich wrote:
> >>> On Thu, Jan 04, 2024 at 12:17:12PM +0100, Ahmad Fatoum wrote:
> >>>> On 03.01.24 19:58, Michael Olbrich wrote:
> >>>>> On Wed, Jan 03, 2024 at 07:12:19PM +0100, Ahmad Fatoum wrote:
> >>>>>> When run as EFI payload, barebox will not have full access to DRAM and 
> >>>>>> will
> >>>>>> have to ask the EFI firmware for memory. It does so once at the 
> >>>>>> beginning
> >>>>>> and since commit 356aaef5a37d ("efi: improve malloc pool allocation"),
> >>>>>> the buffer was always placed beneath the 1G boundary.
> >>>>>>
> >>>>>> Aforementioned commit didn't elaborate why a maximum of 1G in 
> >>>>>> particular
> >>>>>> was chosen. Anyways, non-PC architectures have different memory maps, 
> >>>>>> so
> >>>>>> a 1G limit doesn't make sense there. Therefore restrict the limit to
> >>>>>> ARCH_X86. On non-x86, we allow the memory pages to be located anywhere.
> >>>>>
> >>>>> The 1G is somewhat arbitrary but if you don't restrict the memory to 
> >>>>> 32bit,
> >>>>> then loading the kernel may fail: The addresses in "struct
> >>>>> linux_kernel_header" are only 32bit. So if you impose no restrictions at
> >>>>> all, then this memory cannot be used for the kernel and initrd.
> >>>>
> >>>> The limit for x86 remains at 1G. It's only for other architectures, that 
> >>>> we
> >>>> remove the limit. I suspect that other architectures won't have this kind
> >>>> of problems though , because they would boot the kernel image via EFI 
> >>>> load
> >>>> and start image boot services, where the EFI firmware takes care to 
> >>>> layout
> >>>> the boot artifacts.
> >>>>
> >>>> Once we have that in place, we could even use it on x86 instead of
> >>>> using struct linux_kernel_header, but I haven't investigated this yet.
> >>>
> >>> How do you load the initrd via EFI? As far as I know, that only works as a
> >>> filename in the EFI boot partition.
> >>
> >> This seems to be relaxed in newer kernels, see
> >> https://lore.kernel.org/linux-efi/20200207202637.ga3464...@rani.riverdale.lan/T/
> > 
> > It's not quite clear to me how that works, but from what I can tell,
> > requires support from the firmware and barebox needs to use it. So that
> > does not help here.
> > You need to either disable the legacy handler to avoid arbitrary failures
> > or explicitly allocate the initrd memory from efi with the restriction to
> > <4G.
> 
> The legacy handler wouldn't apply to other architectures:
> 
>   - The Kernel images for ARM64 and RISC-V have different more-specific 
> filetypes
> than filetype_exe

Ah, now I get it. I forgot that that code is x86 specific. So how do you
boot Linux from EFI anyways on other architectures?
I don't see any filetypes for EFI binaries for other architectures. I'm not
sure how that works but would expect to find some code that hands over
efi_sys_table? Or what am I missing?
And if you boot a non-EFI binary shouldn't you call RS->exit_boot_services()
before actually starting the kernel?

And we should move setting LoaderTimeExecUSec into some kind of barebox
shutdown handler to ensure that it is set even if other bootm handlers are
used. But that's all unrelated to this patch.

Regards,
Michael

>   - The Linux kernel header check will probabaly fail for every format that's 
> not
> x86
> 
> Cheers,
> Ahmad 
> 
> > 
> > Michael
> > 
> >>> That was the reason for implementing
> >>> the "legacy" boot mode. And what about the device-tree?
> >>
> >> There is an EFI config table for FDT (DEVICE_TREE_GUID in Linux code). 
> >> barebox
> >> as EFI loader can use it to provide its own DT. I have to check what's the 
> >> cleanest
> >> way for barebox as EFI payload to provide a different DT, but I hope there 
> >> is a way
> >> without barebox as EFI payload having to manipulate the device tree itself.
> >>
> >> Cheers,
> >> Ahmad
> >>
> >&g

Re: [PATCH 059/112] efi: payload: init: restrict barebox mem to first 1G only on x86

2024-01-05 Thread Michael Olbrich
Hi,

On Fri, Jan 05, 2024 at 10:14:33AM +0100, Ahmad Fatoum wrote:
> On 04.01.24 19:10, Michael Olbrich wrote:
> > On Thu, Jan 04, 2024 at 12:17:12PM +0100, Ahmad Fatoum wrote:
> >> On 03.01.24 19:58, Michael Olbrich wrote:
> >>> On Wed, Jan 03, 2024 at 07:12:19PM +0100, Ahmad Fatoum wrote:
> >>>> When run as EFI payload, barebox will not have full access to DRAM and 
> >>>> will
> >>>> have to ask the EFI firmware for memory. It does so once at the beginning
> >>>> and since commit 356aaef5a37d ("efi: improve malloc pool allocation"),
> >>>> the buffer was always placed beneath the 1G boundary.
> >>>>
> >>>> Aforementioned commit didn't elaborate why a maximum of 1G in particular
> >>>> was chosen. Anyways, non-PC architectures have different memory maps, so
> >>>> a 1G limit doesn't make sense there. Therefore restrict the limit to
> >>>> ARCH_X86. On non-x86, we allow the memory pages to be located anywhere.
> >>>
> >>> The 1G is somewhat arbitrary but if you don't restrict the memory to 
> >>> 32bit,
> >>> then loading the kernel may fail: The addresses in "struct
> >>> linux_kernel_header" are only 32bit. So if you impose no restrictions at
> >>> all, then this memory cannot be used for the kernel and initrd.
> >>
> >> The limit for x86 remains at 1G. It's only for other architectures, that we
> >> remove the limit. I suspect that other architectures won't have this kind
> >> of problems though , because they would boot the kernel image via EFI load
> >> and start image boot services, where the EFI firmware takes care to layout
> >> the boot artifacts.
> >>
> >> Once we have that in place, we could even use it on x86 instead of
> >> using struct linux_kernel_header, but I haven't investigated this yet.
> > 
> > How do you load the initrd via EFI? As far as I know, that only works as a
> > filename in the EFI boot partition.
> 
> This seems to be relaxed in newer kernels, see
> https://lore.kernel.org/linux-efi/20200207202637.ga3464...@rani.riverdale.lan/T/

It's not quite clear to me how that works, but from what I can tell,
requires support from the firmware and barebox needs to use it. So that
does not help here.
You need to either disable the legacy handler to avoid arbitrary failures
or explicitly allocate the initrd memory from efi with the restriction to
<4G.

Michael

> > That was the reason for implementing
> > the "legacy" boot mode. And what about the device-tree?
> 
> There is an EFI config table for FDT (DEVICE_TREE_GUID in Linux code). barebox
> as EFI loader can use it to provide its own DT. I have to check what's the 
> cleanest
> way for barebox as EFI payload to provide a different DT, but I hope there is 
> a way
> without barebox as EFI payload having to manipulate the device tree itself.
> 
> Cheers,
> Ahmad
> 
> > 
> > Michael
> > 
> >>>> This can break PCI drivers on systems that so far assumed barebox memory
> >>>> is located in the first 4G, but that's ok. That code will need to be
> >>>> fixed eventually anyway.
> >>>>
> >>>> Cc: Michael Olbrich 
> >>>> Signed-off-by: Ahmad Fatoum 
> >>>> ---
> >>>>  efi/payload/init.c | 2 +-
> >>>>  1 file changed, 1 insertion(+), 1 deletion(-)
> >>>>
> >>>> diff --git a/efi/payload/init.c b/efi/payload/init.c
> >>>> index 4b612e61afb3..0c2f38e9c86a 100644
> >>>> --- a/efi/payload/init.c
> >>>> +++ b/efi/payload/init.c
> >>>> @@ -292,7 +292,7 @@ void efi_main(efi_handle_t image, struct 
> >>>> efi_system_table *sys_table)
> >>>>  BS->handle_protocol(efi_loaded_image->device_handle,
> >>>>  _device_path_protocol_guid, (void 
> >>>> **)_device_path);
> >>>>  
> >>>> -mem = 0x3fff;
> >>>> +mem = IS_ENABLED(CONFIG_X86) ? 0x3fff : ~0ULL;
> >>>>  for (memsize = SZ_256M; memsize >= SZ_8M; memsize /= 2) {
> >>>>  efiret  = BS->allocate_pages(EFI_ALLOCATE_MAX_ADDRESS,
> >>>>   EFI_LOADER_DATA,
> >>>> -- 
> >>>> 2.39.2
> >>>>
> >>>>
> >>>
> >>
> >> -- 
> >> Pengutronix e.K.   | |
> >> Steuerwalder Str. 21   | http://www.pengutronix.de/  |
> >> 31137 Hildesheim, Germany  | Phone: +49-5121-206917-0|
> >> Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |
> >>
> >>
> > 
> 
> -- 
> Pengutronix e.K.   | |
> Steuerwalder Str. 21   | http://www.pengutronix.de/  |
> 31137 Hildesheim, Germany  | Phone: +49-5121-206917-0|
> Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |
> 
> 

-- 
Pengutronix e.K.   | |
Steuerwalder Str. 21   | http://www.pengutronix.de/  |
31137 Hildesheim, Germany  | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |



Re: [PATCH 059/112] efi: payload: init: restrict barebox mem to first 1G only on x86

2024-01-04 Thread Michael Olbrich
On Thu, Jan 04, 2024 at 12:17:12PM +0100, Ahmad Fatoum wrote:
> On 03.01.24 19:58, Michael Olbrich wrote:
> > On Wed, Jan 03, 2024 at 07:12:19PM +0100, Ahmad Fatoum wrote:
> >> When run as EFI payload, barebox will not have full access to DRAM and will
> >> have to ask the EFI firmware for memory. It does so once at the beginning
> >> and since commit 356aaef5a37d ("efi: improve malloc pool allocation"),
> >> the buffer was always placed beneath the 1G boundary.
> >>
> >> Aforementioned commit didn't elaborate why a maximum of 1G in particular
> >> was chosen. Anyways, non-PC architectures have different memory maps, so
> >> a 1G limit doesn't make sense there. Therefore restrict the limit to
> >> ARCH_X86. On non-x86, we allow the memory pages to be located anywhere.
> > 
> > The 1G is somewhat arbitrary but if you don't restrict the memory to 32bit,
> > then loading the kernel may fail: The addresses in "struct
> > linux_kernel_header" are only 32bit. So if you impose no restrictions at
> > all, then this memory cannot be used for the kernel and initrd.
> 
> The limit for x86 remains at 1G. It's only for other architectures, that we
> remove the limit. I suspect that other architectures won't have this kind
> of problems though , because they would boot the kernel image via EFI load
> and start image boot services, where the EFI firmware takes care to layout
> the boot artifacts.
> 
> Once we have that in place, we could even use it on x86 instead of
> using struct linux_kernel_header, but I haven't investigated this yet.

How do you load the initrd via EFI? As far as I know, that only works as a
filename in the EFI boot partition. That was the reason for implementing
the "legacy" boot mode. And what about the device-tree?

Michael

> >> This can break PCI drivers on systems that so far assumed barebox memory
> >> is located in the first 4G, but that's ok. That code will need to be
> >> fixed eventually anyway.
> >>
> >> Cc: Michael Olbrich 
> >> Signed-off-by: Ahmad Fatoum 
> >> ---
> >>  efi/payload/init.c | 2 +-
> >>  1 file changed, 1 insertion(+), 1 deletion(-)
> >>
> >> diff --git a/efi/payload/init.c b/efi/payload/init.c
> >> index 4b612e61afb3..0c2f38e9c86a 100644
> >> --- a/efi/payload/init.c
> >> +++ b/efi/payload/init.c
> >> @@ -292,7 +292,7 @@ void efi_main(efi_handle_t image, struct 
> >> efi_system_table *sys_table)
> >>BS->handle_protocol(efi_loaded_image->device_handle,
> >>_device_path_protocol_guid, (void 
> >> **)_device_path);
> >>  
> >> -  mem = 0x3fff;
> >> +  mem = IS_ENABLED(CONFIG_X86) ? 0x3fff : ~0ULL;
> >>for (memsize = SZ_256M; memsize >= SZ_8M; memsize /= 2) {
> >>efiret  = BS->allocate_pages(EFI_ALLOCATE_MAX_ADDRESS,
> >> EFI_LOADER_DATA,
> >> -- 
> >> 2.39.2
> >>
> >>
> > 
> 
> -- 
> Pengutronix e.K.   | |
> Steuerwalder Str. 21   | http://www.pengutronix.de/  |
> 31137 Hildesheim, Germany  | Phone: +49-5121-206917-0|
> Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |
> 
> 

-- 
Pengutronix e.K.   | |
Steuerwalder Str. 21   | http://www.pengutronix.de/  |
31137 Hildesheim, Germany  | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |



Re: [PATCH 059/112] efi: payload: init: restrict barebox mem to first 1G only on x86

2024-01-03 Thread Michael Olbrich
On Wed, Jan 03, 2024 at 07:12:19PM +0100, Ahmad Fatoum wrote:
> When run as EFI payload, barebox will not have full access to DRAM and will
> have to ask the EFI firmware for memory. It does so once at the beginning
> and since commit 356aaef5a37d ("efi: improve malloc pool allocation"),
> the buffer was always placed beneath the 1G boundary.
> 
> Aforementioned commit didn't elaborate why a maximum of 1G in particular
> was chosen. Anyways, non-PC architectures have different memory maps, so
> a 1G limit doesn't make sense there. Therefore restrict the limit to
> ARCH_X86. On non-x86, we allow the memory pages to be located anywhere.

The 1G is somewhat arbitrary but if you don't restrict the memory to 32bit,
then loading the kernel may fail: The addresses in "struct
linux_kernel_header" are only 32bit. So if you impose no restrictions at
all, then this memory cannot be used for the kernel and initrd.

Regards,
Michael

> This can break PCI drivers on systems that so far assumed barebox memory
> is located in the first 4G, but that's ok. That code will need to be
> fixed eventually anyway.
> 
> Cc: Michael Olbrich 
> Signed-off-by: Ahmad Fatoum 
> ---
>  efi/payload/init.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/efi/payload/init.c b/efi/payload/init.c
> index 4b612e61afb3..0c2f38e9c86a 100644
> --- a/efi/payload/init.c
> +++ b/efi/payload/init.c
> @@ -292,7 +292,7 @@ void efi_main(efi_handle_t image, struct efi_system_table 
> *sys_table)
>   BS->handle_protocol(efi_loaded_image->device_handle,
>   _device_path_protocol_guid, (void 
> **)_device_path);
>  
> - mem = 0x3fff;
> + mem = IS_ENABLED(CONFIG_X86) ? 0x3fff : ~0ULL;
>   for (memsize = SZ_256M; memsize >= SZ_8M; memsize /= 2) {
>   efiret  = BS->allocate_pages(EFI_ALLOCATE_MAX_ADDRESS,
>EFI_LOADER_DATA,
> -- 
> 2.39.2
> 
> 

-- 
Pengutronix e.K.   | |
Steuerwalder Str. 21   | http://www.pengutronix.de/  |
31137 Hildesheim, Germany  | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |



[PATCH 2/2] efi: fill more EFI runtime variables defined by systemd

2023-12-06 Thread Michael Olbrich
bootctl will use those variables if available, and produce somethink
like this:

System:
  Firmware: UEFI 2.70 (American Megatrends 5.13)
 Firmware Arch: x64
   Secure Boot: disabled (setup)
  TPM2 Support: firmware only, driver unavailable
  Boot into FW: supported

Current Boot Loader:
  Product: barebox-2023.11.0-dirty
 Features: ✗ Boot counting
   ✗ Menu timeout control
   ✗ One-shot menu timeout control
   ✗ Default entry control
   ✗ One-shot entry control
   ✗ Support for XBOOTLDR partition
   ✗ Support for passing random seed to OS
   ✗ Load drop-in drivers
   ✗ Support Type #1 sort-key field
   ✗ Support @saved pseudo-entry
   ✓ Support Type #1 devicetree field
   ✗ Enroll SecureBoot keys
   ✗ Retain SHIM protocols
   ✗ Boot loader sets ESP information
[...]

Signed-off-by: Michael Olbrich 
---
 common/efi/payload/init.c | 34 ++
 1 file changed, 34 insertions(+)

diff --git a/common/efi/payload/init.c b/common/efi/payload/init.c
index 19be7ff07fb6..cfacdffa6761 100644
--- a/common/efi/payload/init.c
+++ b/common/efi/payload/init.c
@@ -36,6 +36,7 @@
 #include 
 #include 
 #include 
+#include 
 
 efi_runtime_services_t *RT;
 efi_boot_services_t *BS;
@@ -322,13 +323,46 @@ static int efi_core_init(void)
 }
 core_initcall(efi_core_init);
 
+/* Features of the loader, i.e. systemd-boot, barebox (imported from systemd) 
*/
+#define EFI_LOADER_FEATURE_CONFIG_TIMEOUT  (1LL << 0)
+#define EFI_LOADER_FEATURE_CONFIG_TIMEOUT_ONE_SHOT (1LL << 1)
+#define EFI_LOADER_FEATURE_ENTRY_DEFAULT   (1LL << 2)
+#define EFI_LOADER_FEATURE_ENTRY_ONESHOT   (1LL << 3)
+#define EFI_LOADER_FEATURE_BOOT_COUNTING   (1LL << 4)
+#define EFI_LOADER_FEATURE_XBOOTLDR(1LL << 5)
+#define EFI_LOADER_FEATURE_RANDOM_SEED (1LL << 6)
+#define EFI_LOADER_FEATURE_LOAD_DRIVER (1LL << 7)
+#define EFI_LOADER_FEATURE_SORT_KEY(1LL << 8)
+#define EFI_LOADER_FEATURE_SAVED_ENTRY (1LL << 9)
+#define EFI_LOADER_FEATURE_DEVICETREE  (1LL << 10)
+#define EFI_LOADER_FEATURE_SECUREBOOT_ENROLL   (1LL << 11)
+#define EFI_LOADER_FEATURE_RETAIN_SHIM (1LL << 12)
+
+
 static int efi_postcore_init(void)
 {
char *uuid;
+   static const uint64_t loader_features =
+   EFI_LOADER_FEATURE_DEVICETREE;
 
efi_set_variable_usec("LoaderTimeInitUSec", _systemd_vendor_guid,
  get_time_ns()/1000);
 
+   efi_set_variable_printf("LoaderInfo", _systemd_vendor_guid,
+   "barebox-" UTS_RELEASE);
+
+   efi_set_variable_printf("LoaderFirmwareInfo", _systemd_vendor_guid,
+   "%ls %u.%02u", efi_sys_table->fw_vendor,
+   efi_sys_table->fw_revision >> 16,
+   efi_sys_table->fw_revision & 0x);
+
+   efi_set_variable_printf("LoaderFirmwareType", _systemd_vendor_guid,
+   "UEFI %u.%02u", efi_sys_table->hdr.revision >> 
16,
+   efi_sys_table->hdr.revision & 0x);
+
+   efi_set_variable_uint64_le("LoaderFeatures", _systemd_vendor_guid,
+  loader_features);
+
uuid = device_path_to_partuuid(device_path_from_handle(
   efi_loaded_image->device_handle));
if (uuid) {
-- 
2.39.2




[PATCH 1/2] efi: add more helper functions to write EFI variables

2023-12-06 Thread Michael Olbrich
Signed-off-by: Michael Olbrich 
---
 common/efi/payload/init.c | 38 ++
 1 file changed, 38 insertions(+)

diff --git a/common/efi/payload/init.c b/common/efi/payload/init.c
index b990b54b2678..19be7ff07fb6 100644
--- a/common/efi/payload/init.c
+++ b/common/efi/payload/init.c
@@ -107,6 +107,44 @@ int efi_set_variable_usec(char *name, efi_guid_t *vendor, 
uint64_t usec)
(strlen(buf)+1) * sizeof(wchar_t));
 }
 
+static int efi_set_variable_printf(char *name, efi_guid_t *vendor, const char 
*fmt, ...)
+{
+   va_list args;
+   char *buf;
+   wchar_t *buf16;
+
+   va_start(args, fmt);
+   buf = xvasprintf(fmt, args);
+   va_end(args);
+   buf16 = xstrdup_char_to_wchar(buf);
+
+   return efi_set_variable(name, vendor,
+   EFI_VARIABLE_BOOTSERVICE_ACCESS |
+   EFI_VARIABLE_RUNTIME_ACCESS, buf16,
+   (strlen(buf)+1) * sizeof(wchar_t));
+   free(buf);
+   free(buf16);
+}
+
+static int efi_set_variable_uint64_le(char *name, efi_guid_t *vendor, uint64_t 
value)
+{
+   uint8_t buf[8];
+
+   buf[0] = (uint8_t)(value >> 0U & 0xFF);
+   buf[1] = (uint8_t)(value >> 8U & 0xFF);
+   buf[2] = (uint8_t)(value >> 16U & 0xFF);
+   buf[3] = (uint8_t)(value >> 24U & 0xFF);
+   buf[4] = (uint8_t)(value >> 32U & 0xFF);
+   buf[5] = (uint8_t)(value >> 40U & 0xFF);
+   buf[6] = (uint8_t)(value >> 48U & 0xFF);
+   buf[7] = (uint8_t)(value >> 56U & 0xFF);
+
+   return efi_set_variable(name, vendor,
+   EFI_VARIABLE_BOOTSERVICE_ACCESS |
+   EFI_VARIABLE_RUNTIME_ACCESS, buf,
+   sizeof(buf));
+}
+
 struct efi_boot {
u32 attributes;
u16 file_path_len;
-- 
2.39.2




[PATCH] x86: efi: add IMD data to the EFI binary

2023-11-03 Thread Michael Olbrich
It it currently missing so the imd command and the bareboximd tool do
not work.

Add the .barebox_imd section to the linker script and copy it to the EFI
binary.

Signed-off-by: Michael Olbrich 
---
 arch/x86/Makefile  | 2 +-
 arch/x86/mach-efi/elf_x86_64_efi.lds.S | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/arch/x86/Makefile b/arch/x86/Makefile
index a0ce8c17f181..019c1adb7781 100644
--- a/arch/x86/Makefile
+++ b/arch/x86/Makefile
@@ -60,7 +60,7 @@ KBUILD_LDFLAGS := --no-undefined
 
 OBJCOPYFLAGS_barebox.efi = \
-j .text -j .sdata -j .data -j .dynamic -j .dynsym -j .rel -j .rela \
-   -j .reloc -j .bbenv.* -j .bblogo.* --target=$(TARGET)
+   -j .reloc -j .bbenv.* -j .bblogo.* -j .barebox_imd --target=$(TARGET)
 
 barebox.efi: $(KBUILD_BINARY) FORCE
$(call if_changed,objcopy)
diff --git a/arch/x86/mach-efi/elf_x86_64_efi.lds.S 
b/arch/x86/mach-efi/elf_x86_64_efi.lds.S
index ab4a9e815c00..52a0d3db2d6c 100644
--- a/arch/x86/mach-efi/elf_x86_64_efi.lds.S
+++ b/arch/x86/mach-efi/elf_x86_64_efi.lds.S
@@ -56,6 +56,8 @@ SECTIONS
}
_edata = .;
 
+   .barebox_imd : { BAREBOX_IMD }
+
. = ALIGN(4096);
.dynamic : { *(.dynamic) }
. = ALIGN(4096);
-- 
2.39.2




[PATCH] net: ifup: pass hostname and linuxdevname to linux with DHCP

2023-04-26 Thread Michael Olbrich
Barebox always uses the hostname in the DHCP request. To configure
kernel networking, use the long ip= syntax for DHCP and set the hostname
as well. This way, Barebox and Linux use the same hostname in the DHCP
request.
Also set the device if linuxdevname is configured. This is already done
for static configurations. Do the same for DHCP.

Signed-off-by: Michael Olbrich 
---
 net/ifup.c | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/net/ifup.c b/net/ifup.c
index 1870f7401714..18ab1363c748 100644
--- a/net/ifup.c
+++ b/net/ifup.c
@@ -159,8 +159,8 @@ out:
 
 static void set_linux_bootarg(struct eth_device *edev)
 {
+   char *bootarg;
if (edev->global_mode == ETH_MODE_STATIC) {
-   char *bootarg;
IPaddr_t serverip;
IPaddr_t gateway;
 
@@ -176,7 +176,11 @@ static void set_linux_bootarg(struct eth_device *edev)
dev_set_param(>dev, "linux.bootargs", bootarg);
free(bootarg);
} else if (edev->global_mode == ETH_MODE_DHCP) {
-   dev_set_param(>dev, "linux.bootargs", "ip=dhcp");
+   bootarg = basprintf("ip=%s:%s:dhcp",
+   barebox_get_hostname(),
+   edev->linuxdevname ? edev->linuxdevname : "");
+   dev_set_param(>dev, "linux.bootargs", bootarg);
+   free(bootarg);
}
 }
 
-- 
2.39.2




Re: [PATCH 2/3] commands: implement devlookup to find device behind device file

2022-06-30 Thread Michael Olbrich
On Thu, Jun 30, 2022 at 02:40:34PM +0200, Ahmad Fatoum wrote:
> For OF-enabled platforms with aliases, device file naming is pretty much
> solved: If there is mmc2 = , then we have a mmc2 device and
> a /dev/mmc2 device file. For other platforms like x86, EFI-provided
> devices are harder to get ahold of. Add a command to make this
> straight-forward to do in scripts. The main use of this is probably to
> access parameters like nt_signature or guid:
> 
>   devloop /dev/disk0 guid

   devlookup /dev/disk0 guid

Right?

Michael

> 
> This would print to console, but we have no output capture yet, so add
> an optional -v VARIABLE parameter as well to allow easy use from
> scripts.
> 
> Signed-off-by: Ahmad Fatoum 
> ---
>  commands/Kconfig | 13 
>  commands/Makefile|  1 +
>  commands/devlookup.c | 73 
>  3 files changed, 87 insertions(+)
>  create mode 100644 commands/devlookup.c
> 
> diff --git a/commands/Kconfig b/commands/Kconfig
> index fb4dcefed8bf..5bab78fd1ce7 100644
> --- a/commands/Kconfig
> +++ b/commands/Kconfig
> @@ -75,6 +75,19 @@ config CMD_DEVINFO
> If called with a device path being the argument, devinfo shows more
> default information about this device and its parameters.
>  
> +config CMD_DEVLOOKUP
> + tristate
> + prompt "devlookup"
> + help
> +   Look up device behind device file and its parameters
> +
> +   devlookup [-v VAR] /dev/DEVICE [parameter]
> +
> +  Detects the device behind a device file and outputs it,
> +  unless a second argument is given. In that case the device
> +  parameter with that name is looked up. Specifying -v VARIABLE
> +  will write output to VARIABLE instead of printing it.
> +
>  config CMD_DEVUNBIND
>   tristate
>   prompt "devunbind"
> diff --git a/commands/Makefile b/commands/Makefile
> index 6c3a7a1dabcd..b43da1a80173 100644
> --- a/commands/Makefile
> +++ b/commands/Makefile
> @@ -110,6 +110,7 @@ obj-$(CONFIG_CMD_DETECT)  += detect.o
>  obj-$(CONFIG_CMD_BOOT)   += boot.o
>  obj-$(CONFIG_CMD_DEVINFO)+= devinfo.o
>  obj-$(CONFIG_CMD_DEVUNBIND)  += devunbind.o
> +obj-$(CONFIG_CMD_DEVLOOKUP)  += devlookup.o
>  obj-$(CONFIG_CMD_DRVINFO)+= drvinfo.o
>  obj-$(CONFIG_CMD_READF)  += readf.o
>  obj-$(CONFIG_CMD_MENUTREE)   += menutree.o
> diff --git a/commands/devlookup.c b/commands/devlookup.c
> new file mode 100644
> index ..9599df7b10bc
> --- /dev/null
> +++ b/commands/devlookup.c
> @@ -0,0 +1,73 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +static int report(const char *variable, const char *val)
> +{
> + if (variable)
> + return setenv(variable, val);
> +
> + if (!val)
> + return -errno;
> +
> + printf("%s\n", val);
> + return 0;
> +}
> +
> +static int do_devlookup(int argc, char *argv[])
> +{
> + const char *variable = NULL, *devicefile, *paramname;
> + struct cdev *cdev;
> + int opt;
> +
> + while ((opt = getopt(argc, argv, "v:")) > 0) {
> + switch(opt) {
> + case 'v':
> + variable = optarg;
> + break;
> + }
> + }
> +
> + if (argc - optind == 0 || argc - optind > 2)
> + return COMMAND_ERROR_USAGE;
> +
> + devicefile = argv[optind];
> + paramname  = argv[optind+1];
> +
> + if (!strstarts(devicefile, "/dev/"))
> + return COMMAND_ERROR_USAGE;
> +
> + devicefile += sizeof "/dev/" - 1;
> +
> + cdev = cdev_by_name(devicefile);
> + if (!cdev)
> + return -ENOENT;
> +
> + if (paramname)
> + return report(variable, dev_get_param(cdev->dev, paramname));
> +
> + return report(variable, dev_name(cdev->dev));
> +}
> +
> +BAREBOX_CMD_HELP_START(devlookup)
> +BAREBOX_CMD_HELP_TEXT("Detects the device behind a device file and outputs 
> it,")
> +BAREBOX_CMD_HELP_TEXT("unless a second argument is given. In that case the 
> device")
> +BAREBOX_CMD_HELP_TEXT("parameter with that name is looked up. Specifying -v 
> VARIABLE")
> +BAREBOX_CMD_HELP_TEXT("will write output to VARIABLE instead of printing it")
> +BAREBOX_CMD_HELP_END
> +
> +BAREBOX_CMD_START(devlookup)
> + .cmd= do_devlookup,
> + BAREBOX_CMD_DESC("look up device behind device file and its parameters")
> + BAREBOX_CMD_OPTS("[-v VAR] /dev/DEVICE [parameter]")
> + BAREBOX_CMD_GROUP(CMD_GRP_SCRIPT)
> + BAREBOX_CMD_HELP(cmd_devlookup_help)
> +BAREBOX_CMD_END
> +
> -- 
> 2.30.2
> 
> 
> 

-- 
Pengutronix e.K.   | |
Steuerwalder Str. 21   | http://www.pengutronix.de/  |
31137 Hildesheim, Germany  | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |

Re: [PATCH v3 2/2] fastboot: bail if update handler couldn't be found for bbu-partition

2022-06-10 Thread Michael Olbrich
On Thu, Jun 09, 2022 at 04:12:39PM +0200, Ahmad Fatoum wrote:
> On 09.06.22 16:10, Sascha Hauer wrote:
> > On Thu, Jun 09, 2022 at 03:09:36PM +0200, Ahmad Fatoum wrote:
> >> Fastboot would fall back to a raw copy even for bbu- partitions if
> >> no barebox_update handler was found. Prevent this by bailing out
> >> with an error code.
> >>
> >> Signed-off-by: Ahmad Fatoum 
> >> ---
> >> v2 -> v3:
> >>   - bail out instead of only printing message and falling back
> >> to raw copy (Sascha)
> >> v1 -> v2:
> >>   - print message in case barebox_update handler is not found
> >> ---
> >>  common/fastboot.c | 9 +++--
> >>  1 file changed, 7 insertions(+), 2 deletions(-)
> >>
> >> diff --git a/common/fastboot.c b/common/fastboot.c
> >> index 330a06f5a32f..a5cf04b39ecd 100644
> >> --- a/common/fastboot.c
> >> +++ b/common/fastboot.c
> >> @@ -683,8 +683,13 @@ static void cb_flash(struct fastboot *fb, const char 
> >> *cmd)
> >>};
> >>  
> >>handler = bbu_find_handler_by_device(data.devicefile);
> >> -  if (!handler)
> >> -  goto copy;
> >> +  if (!handler) {
> >> +  fastboot_tx_print(fb, FASTBOOT_MSG_FAIL,
> >> +"No barebox update handler registered 
> >> for %s",
> >> +data.devicefile);
> >> +  ret = -ENOENT;
> >> +  goto out;
> >> +  }
> > 
> > I didn't verify that, but I believe a full raw bootable disk image
> > generated for i.MX will be detected as barebox image. With this patch we
> > wouldn't be able to flash that anymore.
> 
> Can we just apply v2 and see how often we see the message?

Or maybe the 'is a barebox image' detection is not strict enough? We know
the image size, right? Is there a way to determine the size of the actual
barebox image? If the two differ then it's not a barebox image after all.

Michael

-- 
Pengutronix e.K.   | |
Steuerwalder Str. 21   | http://www.pengutronix.de/  |
31137 Hildesheim, Germany  | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |

___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH 8/8] misc: Add storage-by-uuid driver

2022-02-08 Thread Michael Olbrich
On Mon, Feb 07, 2022 at 10:49:53AM +0100, Sascha Hauer wrote:
> This adds a driver which matches to a "barebox,storage-by-uuid"
> compatible node. The driver looks for a storage device matching the
> given UUID and when found registers a new cdev for the device.
> 
> This driver solved a very specific problem. On EFI the storage devices
> are not connected to any device tree node. barebox-state however expects
> a node to use as its backend. The obvious solution would be to create
> a partition with a specific partuuid and use that for state, in our
> special usecase though the storage device is partitioned with a MBR
> which doesn't have any space left to create a new partition. As this
> driver parses the of partition binding we can use that to create
> a partition in an unallocated are of the disk which is then used for
> state.
> 
> This driver has the problem that it depends on storage devices which
> are not described in the device tree. This means it cannot work with
> deep probe. This is not a problem on EFI though. It's a special purpose
> driver, it's not recommended for general use.
> 
> Signed-off-by: Sascha Hauer 
> ---
>  drivers/misc/Kconfig   |  23 
>  drivers/misc/Makefile  |   1 +
>  drivers/misc/storage-by-uuid.c | 199 +
>  3 files changed, 223 insertions(+)
>  create mode 100644 drivers/misc/storage-by-uuid.c
> 
> diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
> index 5ab0506cd9..78c9c193d8 100644
> --- a/drivers/misc/Kconfig
> +++ b/drivers/misc/Kconfig
> @@ -47,4 +47,27 @@ config STARFIVE_PWRSEQ
> be accessed over /dev/mem or used from kernels which still depend
> on bootloader for initialization.
>  
> +config STORAGE_BY_UUID
> + bool "storage by UUID"
> + depends on OFDEVICE
> + help
> +   This adds a driver which matches to a "barebox,storage-by-uuid"
> +   compatible node. The driver looks for a storage device matching the
> +   given UUID and when found registers a new cdev for the device.
> +
> +   This driver solved a very specific problem. On EFI the storage devices
> +   are not connected to any device tree node. barebox-state however 
> expects
> +   a node to use as its backend. The obvious solution would be to create
> +   a partition with a specific partuuid and use that for state, in our
> +   special usecase though the storage device is partitioned with a MBR
> +   which doesn't have any space left to create a new partition. As this
> +   driver parses the of partition binding we can use that to create
> +   a partition in an unallocated are of the disk which is then used for
> +   state.
> +
> +   This driver has the problem that it depends on storage devices which
> +   are not described in the device tree. This means it cannot work with
> +   deep probe. This is not a problem on EFI though. It's a special 
> purpose
> +   driver, it's not recommended for general use.
> +
>  endmenu
> diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
> index 6326e784fc..986f7b1b38 100644
> --- a/drivers/misc/Makefile
> +++ b/drivers/misc/Makefile
> @@ -9,3 +9,4 @@ obj-$(CONFIG_STATE_DRV)   += state.o
>  obj-$(CONFIG_DEV_MEM)+= mem.o
>  obj-$(CONFIG_UBOOTVAR)   += ubootvar.o
>  obj-$(CONFIG_STARFIVE_PWRSEQ)+= starfive-pwrseq.o
> +obj-$(CONFIG_STORAGE_BY_UUID)+= storage-by-uuid.o
> diff --git a/drivers/misc/storage-by-uuid.c b/drivers/misc/storage-by-uuid.c
> new file mode 100644
> index 00..c9dd6e9793
> --- /dev/null
> +++ b/drivers/misc/storage-by-uuid.c
> @@ -0,0 +1,199 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +static LIST_HEAD(sbu_list);
> +
> +struct sbu {
> + char *uuid;
> + struct device_d *dev;
> + struct cdev *rcdev;
> + struct cdev cdev;
> + struct list_head list;
> +};
> +
> +void storage_by_uuid_check_exist(struct cdev *cdev);
> +
> +static ssize_t sbu_read(struct cdev *cdev, void *buf, size_t count, loff_t 
> offset, ulong flags)
> +{
> + struct sbu *sbu = cdev->priv;
> +
> + return cdev_read(sbu->rcdev, buf, count, offset, flags);
> +}
> +
> +static ssize_t sbu_write(struct cdev *cdev, const void *buf, size_t count, 
> loff_t offset, ulong flags)
> +{
> + struct sbu *sbu = cdev->priv;
> +
> + return cdev_write(sbu->rcdev, buf, count, offset, flags);
> +}
> +
> +static int sbu_ioctl(struct cdev *cdev, int request, void *buf)
> +{
> + struct sbu *sbu = cdev->priv;
> +
> + return cdev_ioctl(sbu->rcdev, request, buf);
> +}
> +
> +static int sbu_open(struct cdev *cdev, unsigned long flags)
> +{
> + struct sbu *sbu = cdev->priv;
> +
> + return cdev_open(sbu->rcdev, flags);
> +}
> +
> +static int sbu_close(struct cdev *cdev)
> +{
> + struct sbu *sbu = cdev->priv;
> +
> + 

[PATCH] efi: probe devices from the device-tree

2022-02-07 Thread Michael Olbrich
The state device-tree may contain devices. For example block devices with a
'barebox,storage-by-uuid' compatible. Probing is necessary to ensure that
those devices are available.

Call barebox_register_of() instead of of_set_root_node(). It probes the
devices after setting the root node.

Signed-off-by: Michael Olbrich 
---

I've tested the series and with this aditional patch it works on EFI, so

Tested-by: Michael Olbrich 

Michael

 common/efi/payload/init.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/common/efi/payload/init.c b/common/efi/payload/init.c
index 6db6b2389540..1541683186fb 100644
--- a/common/efi/payload/init.c
+++ b/common/efi/payload/init.c
@@ -349,7 +349,9 @@ static int efi_late_init(void)
if (IS_ERR(root))
return PTR_ERR(root);
 
-   of_set_root_node(root);
+   ret = barebox_register_of(root);
+   if (ret)
+   pr_warn("Failed to register device-tree: %pe\n", 
ERR_PTR(ret));
 
np = of_find_node_by_alias(root, "state");
 
-- 
2.30.2


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH 3/3] state: support backend-diskuuid / backend-offset

2022-01-26 Thread Michael Olbrich
On Wed, Jan 26, 2022 at 11:15:24AM +0100, Sascha Hauer wrote:
> On Wed, Jan 26, 2022 at 10:35:13AM +0100, Michael Olbrich wrote:
> > On Wed, Jan 26, 2022 at 08:57:27AM +0100, Sascha Hauer wrote:
> > > On Mon, Jan 24, 2022 at 11:04:58AM +0100, Michael Olbrich wrote:
> > > > On some platforms (e.g. EFI on x86_64) the state backend can only be
> > > > selected by a partiton UUID. On existing devices with a DOS partition
> > > > table, there may be no spare partition available for state.
> > > > 
> > > > This makes it possible to select the disk via UUID. The exact position 
> > > > is
> > > > defined by an explicitly specified offset.
> > > > 
> > > > Signed-off-by: Michael Olbrich 
> > > > ---
> > > > 
> > > > I wasn't sure where to add the helper function. Is include/fs.h ok or
> > > > should I put it somewhere else?
> > > > 
> > > > I'll implement the same helper for dt-utils, so we can avoid additional
> > > > #ifdef here.
> > > > 
> > > >  common/state/state.c | 55 +---
> > > >  include/fs.h | 12 ++
> > > >  2 files changed, 49 insertions(+), 18 deletions(-)
> > > > 
> > > > diff --git a/common/state/state.c b/common/state/state.c
> > > > index 8c34ae83e52b..2a8b12d20c5a 100644
> > > > --- a/common/state/state.c
> > > > +++ b/common/state/state.c
> > > > @@ -592,6 +592,7 @@ struct state *state_new_from_node(struct 
> > > > device_node *node, bool readonly)
> > > > const char *backend_type;
> > > > const char *storage_type = NULL;
> > > > const char *alias;
> > > > +   const char *diskuuid;
> > > > uint32_t stridesize;
> > > > struct device_node *partition_node;
> > > > off_t offset = 0;
> > > > @@ -607,30 +608,48 @@ struct state *state_new_from_node(struct 
> > > > device_node *node, bool readonly)
> > > > if (IS_ERR(state))
> > > > return state;
> > > >  
> > > > -   partition_node = of_parse_phandle(node, "backend", 0);
> > > > -   if (!partition_node) {
> > > > -   dev_err(>dev, "Cannot resolve \"backend\" 
> > > > phandle\n");
> > > > -   ret = -EINVAL;
> > > > -   goto out_release_state;
> > > > -   }
> > > > +   ret = of_property_read_string(node, "backend-diskuuid", 
> > > > );
> > > 
> > > This needs some documentation in
> > > Documentation/devicetree/bindings/barebox/barebox,state.rst.
> > 
> > I can do that.
> > 
> > > > +   if (ret == 0) {
> > > > +   u64 off;
> > > > +
> > > > +   ret = devpath_from_diskuuid(diskuuid, 
> > > > >backend_path);
> > > > +   if (ret) {
> > > > +   dev_err(>dev, "state failed find backend 
> > > > device for diskuuid='%s'\n",
> > > > +   diskuuid);
> > > > +   goto out_release_state;
> > > > +   }
> > > > +   ret = of_property_read_u64(node, "backend-offset", 
> > > > );
> > > 
> > > I stumbled upon this because you have to use a 64bit type here instead
> > > of using 'offset' directly. I think 'offset' should be 64bit instead so
> > > that larger offsets can be used.
> > 
> > It's not that simple. 'offset' used as a 'off_t' and 'ssize_t' all over the
> > place in the state framework. On 32bit architecture both are defined as
> > 'long' or 'int'. Both are 32 bit types so changing 'offset' to a 64bit type
> > here doesn't really help.
> 
> Of course not, we would have to replace all variables which are used as
> offset into a device to 64bit types. That's a separate topic which
> doesn't have to be solved as part of this series.

So what should I do here?
- use 'u64' for 'offset' and remove the separate variable
- use 'loff_t' for 'offset'
- keep it as it is
- something else?

> > > > +   }
> > > > +   offset = off;
> > > 
> > > What about the size of the state partition? This is not set anywhere in
> > > this case so it's still zero. It should be specifi

Re: [PATCH 3/3] state: support backend-diskuuid / backend-offset

2022-01-26 Thread Michael Olbrich
On Wed, Jan 26, 2022 at 08:57:27AM +0100, Sascha Hauer wrote:
> On Mon, Jan 24, 2022 at 11:04:58AM +0100, Michael Olbrich wrote:
> > On some platforms (e.g. EFI on x86_64) the state backend can only be
> > selected by a partiton UUID. On existing devices with a DOS partition
> > table, there may be no spare partition available for state.
> > 
> > This makes it possible to select the disk via UUID. The exact position is
> > defined by an explicitly specified offset.
> > 
> > Signed-off-by: Michael Olbrich 
> > ---
> > 
> > I wasn't sure where to add the helper function. Is include/fs.h ok or
> > should I put it somewhere else?
> > 
> > I'll implement the same helper for dt-utils, so we can avoid additional
> > #ifdef here.
> > 
> >  common/state/state.c | 55 +---
> >  include/fs.h | 12 ++
> >  2 files changed, 49 insertions(+), 18 deletions(-)
> > 
> > diff --git a/common/state/state.c b/common/state/state.c
> > index 8c34ae83e52b..2a8b12d20c5a 100644
> > --- a/common/state/state.c
> > +++ b/common/state/state.c
> > @@ -592,6 +592,7 @@ struct state *state_new_from_node(struct device_node 
> > *node, bool readonly)
> > const char *backend_type;
> > const char *storage_type = NULL;
> > const char *alias;
> > +   const char *diskuuid;
> > uint32_t stridesize;
> > struct device_node *partition_node;
> > off_t offset = 0;
> > @@ -607,30 +608,48 @@ struct state *state_new_from_node(struct device_node 
> > *node, bool readonly)
> > if (IS_ERR(state))
> > return state;
> >  
> > -   partition_node = of_parse_phandle(node, "backend", 0);
> > -   if (!partition_node) {
> > -   dev_err(>dev, "Cannot resolve \"backend\" phandle\n");
> > -   ret = -EINVAL;
> > -   goto out_release_state;
> > -   }
> > +   ret = of_property_read_string(node, "backend-diskuuid", );
> 
> This needs some documentation in
> Documentation/devicetree/bindings/barebox/barebox,state.rst.

I can do that.

> > +   if (ret == 0) {
> > +   u64 off;
> > +
> > +   ret = devpath_from_diskuuid(diskuuid, >backend_path);
> > +   if (ret) {
> > +   dev_err(>dev, "state failed find backend device 
> > for diskuuid='%s'\n",
> > +   diskuuid);
> > +   goto out_release_state;
> > +   }
> > +   ret = of_property_read_u64(node, "backend-offset", );
> 
> I stumbled upon this because you have to use a 64bit type here instead
> of using 'offset' directly. I think 'offset' should be 64bit instead so
> that larger offsets can be used.

It's not that simple. 'offset' used as a 'off_t' and 'ssize_t' all over the
place in the state framework. On 32bit architecture both are defined as
'long' or 'int'. Both are 32 bit types so changing 'offset' to a 64bit type
here doesn't really help.
On 64bit architectures 'off_t' and 'ssize_t' are both 'long' which is a
64bit type. We still need to cast from unsigned to signed, but I don't
think that's really a problem here.

So it works for large offsets on 64bit architectures as it is, and it can
be extended to work in 32bit architectures without changing the binding.
But doing that requires larger code changes. And I have no way to test
those.

> > +   if (ret) {
> > +   dev_err(>dev, "'backend-offset' property 
> > undefined\n");
> > +   goto out_release_state;
> > +   }
> > +   offset = off;
> 
> What about the size of the state partition? This is not set anywhere in
> this case so it's still zero. It should be specified the in device tree
> as well. At the same time I'm a bit nervous that it apparently still
> works with size zero.

The code explicitly checks if the size is specified and skips any range
checks if it's not. From what I can tell, it has been like that from the
beginning.

If that's not ok, then I could add a 'backend-size' property, or do you
have something else in mind?

Regards,
Michael

-- 
Pengutronix e.K.   | |
Steuerwalder Str. 21   | http://www.pengutronix.de/  |
31137 Hildesheim, Germany  | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |

___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 2/3] cdev: add diskuuid support

2022-01-24 Thread Michael Olbrich
This allows identifying disks by UUID. For disks with GPT the disk GUID is
used. For DOS partition tables the NT signature ist used, similar to how
the partuuid is generated.

Signed-off-by: Michael Olbrich 
---
 common/partitions/dos.c |  3 +++
 common/partitions/efi.c |  2 ++
 fs/devfs-core.c | 14 ++
 include/driver.h|  1 +
 4 files changed, 20 insertions(+)

diff --git a/common/partitions/dos.c b/common/partitions/dos.c
index 6c76aac37172..258b10a9ed3c 100644
--- a/common/partitions/dos.c
+++ b/common/partitions/dos.c
@@ -182,6 +182,9 @@ static void dos_partition(void *buf, struct block_device 
*blk,
struct disk_signature_priv *dsp;
uint32_t signature = get_unaligned_le32(buf + 0x1b8);
 
+   if (signature)
+   sprintf(blk->cdev.uuid, "%08x", signature);
+
table = (struct partition_entry *)[446];
 
for (i = 0; i < 4; i++) {
diff --git a/common/partitions/efi.c b/common/partitions/efi.c
index 6d811bfb3b01..0787b93f120b 100644
--- a/common/partitions/efi.c
+++ b/common/partitions/efi.c
@@ -445,6 +445,8 @@ static void efi_partition(void *buf, struct block_device 
*blk,
return;
}
 
+   snprintf(blk->cdev.uuid, sizeof(blk->cdev.uuid), "%pUl", 
>disk_guid);
+
nb_part = le32_to_cpu(gpt->num_partition_entries);
 
if (nb_part > MAX_PARTITION) {
diff --git a/fs/devfs-core.c b/fs/devfs-core.c
index 82e4811b384a..2475ab959a10 100644
--- a/fs/devfs-core.c
+++ b/fs/devfs-core.c
@@ -107,6 +107,20 @@ struct cdev *cdev_by_partuuid(const char *partuuid)
return NULL;
 }
 
+struct cdev *cdev_by_diskuuid(const char *diskuuid)
+{
+   struct cdev *cdev;
+
+   if (!diskuuid)
+   return NULL;
+
+   list_for_each_entry(cdev, _list, list) {
+   if (!cdev->master && !strcasecmp(cdev->uuid, diskuuid))
+   return cdev;
+   }
+   return NULL;
+}
+
 /**
  * device_find_partition - find a partition belonging to a physical device
  *
diff --git a/include/driver.h b/include/driver.h
index 409ed7e02afd..e38a15f51f00 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -484,6 +484,7 @@ struct cdev *lcdev_by_name(const char *filename);
 struct cdev *cdev_readlink(struct cdev *cdev);
 struct cdev *cdev_by_device_node(struct device_node *node);
 struct cdev *cdev_by_partuuid(const char *partuuid);
+struct cdev *cdev_by_diskuuid(const char *partuuid);
 struct cdev *cdev_open(const char *name, unsigned long flags);
 struct cdev *cdev_create_loop(const char *path, ulong flags, loff_t offset);
 void cdev_remove_loop(struct cdev *cdev);
-- 
2.30.2


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 3/3] state: support backend-diskuuid / backend-offset

2022-01-24 Thread Michael Olbrich
On some platforms (e.g. EFI on x86_64) the state backend can only be
selected by a partiton UUID. On existing devices with a DOS partition
table, there may be no spare partition available for state.

This makes it possible to select the disk via UUID. The exact position is
defined by an explicitly specified offset.

Signed-off-by: Michael Olbrich 
---

I wasn't sure where to add the helper function. Is include/fs.h ok or
should I put it somewhere else?

I'll implement the same helper for dt-utils, so we can avoid additional
#ifdef here.

 common/state/state.c | 55 +---
 include/fs.h | 12 ++
 2 files changed, 49 insertions(+), 18 deletions(-)

diff --git a/common/state/state.c b/common/state/state.c
index 8c34ae83e52b..2a8b12d20c5a 100644
--- a/common/state/state.c
+++ b/common/state/state.c
@@ -592,6 +592,7 @@ struct state *state_new_from_node(struct device_node *node, 
bool readonly)
const char *backend_type;
const char *storage_type = NULL;
const char *alias;
+   const char *diskuuid;
uint32_t stridesize;
struct device_node *partition_node;
off_t offset = 0;
@@ -607,30 +608,48 @@ struct state *state_new_from_node(struct device_node 
*node, bool readonly)
if (IS_ERR(state))
return state;
 
-   partition_node = of_parse_phandle(node, "backend", 0);
-   if (!partition_node) {
-   dev_err(>dev, "Cannot resolve \"backend\" phandle\n");
-   ret = -EINVAL;
-   goto out_release_state;
-   }
+   ret = of_property_read_string(node, "backend-diskuuid", );
+   if (ret == 0) {
+   u64 off;
+
+   ret = devpath_from_diskuuid(diskuuid, >backend_path);
+   if (ret) {
+   dev_err(>dev, "state failed find backend device 
for diskuuid='%s'\n",
+   diskuuid);
+   goto out_release_state;
+   }
+   ret = of_property_read_u64(node, "backend-offset", );
+   if (ret) {
+   dev_err(>dev, "'backend-offset' property 
undefined\n");
+   goto out_release_state;
+   }
+   offset = off;
+   } else {
+   partition_node = of_parse_phandle(node, "backend", 0);
+   if (!partition_node) {
+   dev_err(>dev, "Cannot resolve \"backend\" 
phandle\n");
+   ret = -EINVAL;
+   goto out_release_state;
+   }
 
 #ifdef __BAREBOX__
-   ret = of_partition_ensure_probed(partition_node);
-   if (ret)
-   goto out_release_state;
+   ret = of_partition_ensure_probed(partition_node);
+   if (ret)
+   goto out_release_state;
 
-   ret = of_find_path_by_node(partition_node, >backend_path, 0);
+   ret = of_find_path_by_node(partition_node, 
>backend_path, 0);
 #else
-   ret = of_get_devicepath(partition_node, >backend_path, , 
);
+   ret = of_get_devicepath(partition_node, >backend_path, 
, );
 #endif
-   if (ret) {
-   if (ret != -EPROBE_DEFER)
-   dev_err(>dev, "state failed to parse path to 
backend: %s\n",
-  strerror(-ret));
-   goto out_release_state;
-   }
+   if (ret) {
+   if (ret != -EPROBE_DEFER)
+   dev_err(>dev, "state failed to parse 
path to backend: %s\n",
+  strerror(-ret));
+   goto out_release_state;
+   }
 
-   state->backend_reproducible_name = 
of_get_reproducible_name(partition_node);
+   state->backend_reproducible_name = 
of_get_reproducible_name(partition_node);
+   }
 
ret = of_property_read_string(node, "backend-type", _type);
if (ret) {
diff --git a/include/fs.h b/include/fs.h
index cd5eb571e08e..1a2f9c7f8e16 100644
--- a/include/fs.h
+++ b/include/fs.h
@@ -177,4 +177,16 @@ static inline const char *devpath_to_name(const char 
*devpath)
return devpath;
 }
 
+static inline int devpath_from_diskuuid(const char *diskuuid, char **devpath)
+{
+   struct cdev *cdev;
+
+   cdev = cdev_by_diskuuid(diskuuid);
+   if (!cdev)
+   return -EINVAL;
+
+   *devpath = xasprintf("/dev/%s", cdev->name);
+   return 0;
+}
+
 #endif /* __FS_H */
-- 
2.30.2


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 0/3] state: find backend with UUID but without a partition

2022-01-24 Thread Michael Olbrich
Hi,

When adding state with a barebox update on existing devices, then it's not
always possible to add a partition for it. But currently that's the only
way to specify the state backend on x86_64/EFI devices.

This adds support backend-diskuuid / backend-offset. This way the backend
is defined by a UUID that selects a disk and an offset within that disk.

Michael

Michael Olbrich (3):
  cdev: rename partuuid to uuid
  cdev: add diskuuid support
  state: support backend-diskuuid / backend-offset

 common/bootm.c |  6 ++---
 common/partitions.c|  2 +-
 common/partitions/dos.c|  3 +++
 common/partitions/efi.c|  2 ++
 common/partitions/parser.h |  2 +-
 common/state/state.c   | 55 +-
 fs/devfs-core.c| 16 ++-
 fs/fs.c|  4 +--
 include/driver.h   |  5 ++--
 include/fs.h   | 12 +
 10 files changed, 79 insertions(+), 28 deletions(-)

-- 
2.30.2


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 1/3] cdev: rename partuuid to uuid

2022-01-24 Thread Michael Olbrich
Partitions are not the only devices that can have UUIDs. Change the name to
something more generic to prepare for other users.

Signed-off-by: Michael Olbrich 
---
 common/bootm.c | 6 +++---
 common/partitions.c| 2 +-
 common/partitions/parser.h | 2 +-
 fs/devfs-core.c| 2 +-
 fs/fs.c| 4 ++--
 include/driver.h   | 4 ++--
 6 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/common/bootm.c b/common/bootm.c
index 89e3e93f2ce0..4652467448eb 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -709,15 +709,15 @@ int bootm_boot(struct bootm_data *bootm_data)
const char *root_dev_name = 
devpath_to_name(bootm_data->root_dev);
const struct cdev *root_cdev = 
cdev_by_name(root_dev_name);
 
-   if (root_cdev && root_cdev->partuuid[0] != 0) {
-   rootarg = basprintf("root=PARTUUID=%s", 
root_cdev->partuuid);
+   if (root_cdev && root_cdev->uuid[0] != 0) {
+   rootarg = basprintf("root=PARTUUID=%s", 
root_cdev->uuid);
} else {
rootarg = ERR_PTR(-EINVAL);
 
if (!root_cdev)
pr_err("no cdev found for %s, cannot 
set root= option\n",
root_dev_name);
-   else if (!root_cdev->partuuid[0])
+   else if (!root_cdev->uuid[0])
pr_err("%s doesn't have a PARTUUID, 
cannot set root= option\n",
root_dev_name);
}
diff --git a/common/partitions.c b/common/partitions.c
index b579559672a0..9cca5c4a1546 100644
--- a/common/partitions.c
+++ b/common/partitions.c
@@ -51,7 +51,7 @@ static int register_one_partition(struct block_device *blk,
cdev->flags |= DEVFS_PARTITION_FROM_TABLE;
 
cdev->dos_partition_type = part->dos_partition_type;
-   strcpy(cdev->partuuid, part->partuuid);
+   strcpy(cdev->uuid, part->partuuid);
 
free(partition_name);
 
diff --git a/common/partitions/parser.h b/common/partitions/parser.h
index 69508932b361..d67f8e1d6a09 100644
--- a/common/partitions/parser.h
+++ b/common/partitions/parser.h
@@ -17,7 +17,7 @@
 struct partition {
char name[MAX_PARTITION_NAME];
u8 dos_partition_type;
-   char partuuid[MAX_PARTUUID_STR];
+   char partuuid[MAX_UUID_STR];
uint64_t first_sec;
uint64_t size;
 };
diff --git a/fs/devfs-core.c b/fs/devfs-core.c
index 2d016e0e4861..82e4811b384a 100644
--- a/fs/devfs-core.c
+++ b/fs/devfs-core.c
@@ -101,7 +101,7 @@ struct cdev *cdev_by_partuuid(const char *partuuid)
return NULL;
 
list_for_each_entry(cdev, _list, list) {
-   if (!strcasecmp(cdev->partuuid, partuuid))
+   if (cdev->master && !strcasecmp(cdev->uuid, partuuid))
return cdev;
}
return NULL;
diff --git a/fs/fs.c b/fs/fs.c
index 7da3a050c1cb..a92b4e9dfca1 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -2969,8 +2969,8 @@ int mount(const char *device, const char *fsname, const 
char *pathname,
cdev_is_mci_main_part_dev(fsdev->cdev->master))
str = get_linux_mmcblkdev(fsdev);
 
-   if (!str && fsdev->cdev->partuuid[0] != 0)
-   str = basprintf("root=PARTUUID=%s", 
fsdev->cdev->partuuid);
+   if (!str && fsdev->cdev->uuid[0] != 0)
+   str = basprintf("root=PARTUUID=%s", fsdev->cdev->uuid);
 
if (str)
fsdev_set_linux_rootarg(fsdev, str);
diff --git a/include/driver.h b/include/driver.h
index 4f6d40e17c14..409ed7e02afd 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -447,7 +447,7 @@ struct cdev_operations {
int (*truncate)(struct cdev*, size_t size);
 };
 
-#define MAX_PARTUUID_STR   sizeof("00112233-4455-6677-8899-AABBCCDDEEFF")
+#define MAX_UUID_STR   sizeof("00112233-4455-6677-8899-AABBCCDDEEFF")
 
 struct cdev {
const struct cdev_operations *ops;
@@ -460,7 +460,7 @@ struct cdev {
char *partname; /* the partition name, usually the above without the
 * device part, i.e. name = "nand0.barebox" -> partname 
= "barebox"
 */
-   char partuuid[MAX_PARTUUID_STR];
+   char uuid[MAX_UUID_STR];
loff_t offset;
loff_t size;
unsigned int flags;
-- 
2.30.2


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH] kbuild: dtc: use env to resolve echo

2022-01-20 Thread Michael Olbrich
On Thu, Jan 20, 2022 at 09:56:49AM +0100, Sascha Hauer wrote:
> On Thu, Jan 20, 2022 at 08:47:33AM +0100, Rouven Czerwinski wrote:
> > Posix does not mandate to have binaries within a certain path, but
> > rather that the utilities may be available. Use env to resolve and call
> > echo from PATH.
> > 
> > Fixes: 2ae7ac7ab2f1 ("kbuild: dtc: Allow adding device tree fragments via 
> > config")
> > 
> > Signed-off-by: Rouven Czerwinski 
> > ---
> >  scripts/Makefile.lib | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
> > index 13b1789c01..94ca1b771b 100644
> > --- a/scripts/Makefile.lib
> > +++ b/scripts/Makefile.lib
> > @@ -340,7 +340,7 @@ dts-frags = $(subst 
> > $(quote),,$(CONFIG_EXTERNAL_DTS_FRAGMENTS))
> >  quiet_cmd_dtc = DTC $@
> >  # For compatibility between make 4.2 and 4.3
> >  H := \#
> > -cmd_dtc = /bin/echo -e '$(H)define $(subst -,_,$(*F))_dts 1\n'$(foreach 
> > f,$< $(dts-frags),'$(H)include "$(f)"\n') | \
> 
> Why hardcode /bin/echo anyway and not use plain 'echo' instead. I assume
> because echo can be a shell builtin, but are there shells out there
> where the builtin is not enough?

The builtin echo implementations are not very compatible. Better use printf
instead. For example, echo from dash (the default /bin/sh in Debian) does
not support '-e'.

Michael

-- 
Pengutronix e.K.   | |
Steuerwalder Str. 21   | http://www.pengutronix.de/  |
31137 Hildesheim, Germany  | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |

___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH] efi: skip devices without driver in efi_pause/continue_devices()

2022-01-18 Thread Michael Olbrich
On Tue, Jan 18, 2022 at 02:43:17PM +0100, Philipp Zabel wrote:
> Skip devices on the EFI bus that do not have a driver assigned.
> 
> Fixes: f68a547deebd ("efi: add efi_device hook to be called before an image 
> is started")
> Signed-off-by: Philipp Zabel 

Tested-by: Michael Olbrich 

Regards,
Michael

> ---
>  drivers/efi/efi-device.c | 14 --
>  1 file changed, 12 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/efi/efi-device.c b/drivers/efi/efi-device.c
> index 39724ec2f431..f91d09e8eaa5 100644
> --- a/drivers/efi/efi-device.c
> +++ b/drivers/efi/efi-device.c
> @@ -473,7 +473,12 @@ void efi_pause_devices(void)
>   bus_for_each_device(_bus, dev) {
>   struct driver_d *drv = dev->driver;
>   struct efi_device *efidev = to_efi_device(dev);
> - struct efi_driver *efidrv = to_efi_driver(drv);
> + struct efi_driver *efidrv;
> +
> + if (!drv)
> + continue;
> +
> + efidrv = to_efi_driver(drv);
>  
>   if (efidrv->dev_pause)
>   efidrv->dev_pause(efidev);
> @@ -487,7 +492,12 @@ void efi_continue_devices(void)
>   bus_for_each_device(_bus, dev) {
>   struct driver_d *drv = dev->driver;
>   struct efi_device *efidev = to_efi_device(dev);
> - struct efi_driver *efidrv = to_efi_driver(drv);
> + struct efi_driver *efidrv;
> +
> + if (!drv)
> + continue;
> +
> + efidrv = to_efi_driver(drv);
>  
>   if (efidrv->dev_continue)
>   efidrv->dev_continue(efidev);
> -- 
> 2.30.2
> 
> 
> ___
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.   | |
Steuerwalder Str. 21   | http://www.pengutronix.de/  |
31137 Hildesheim, Germany  | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |

___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: Build failures with CC=arm-linux-gnueabihf-gcc-11

2021-11-19 Thread Michael Olbrich
On Thu, Nov 18, 2021 at 03:32:04PM +, Ian Abbott wrote:
> Hi,
> 
> My Debian "testing" build system updated the default version of
> arm-linux-gnueabihf-gcc from 10.x to 11.x.  Building barebox in thumb-2 mode
> for an ARMv7 (it's a SoCFPGA) with this compiler fails with assembler errors
> such as:
> 
>   CC  common/state/state_variables.o
> {standard input}: Assembler messages:
> {standard input}:1535: Error: selected processor does not support `rev
> r3,r3' in Thumb mode
> {standard input}:1576: Error: selected processor does not support `rev
> r3,r3' in Thumb mode
> 
> Building in verbose mode (V=1) shows that "make" has selected the compile
> flags `-march=armv5t -Wa,-march=armv7-a` instead of the usual
> `-march=armv7-a`.
> 
> Looking a little deeper, all of the following lines in "arch/arm/Makefile"
> are failing to select the first option and defaulting to the second option
> (if any):

It probably is added from here:

arch-$(CONFIG_CPU_32v7) :=-D__LINUX_ARM_ARCH__=7 $(call 
cc-option,-march=armv7-a,-march=armv5t -Wa$(comma)-march=armv7-a)

The check for -march=armv7-a fails for some reason so the fallback is used.

I've seen this when CC is a wrapper and already adds -mcpu=... to the
commandline. In that case gcc now complains about the combination and the
check fails.

Michael

> arch-$(CONFIG_CPU_64v8)   := -D__LINUX_ARM_ARCH__=8 $(call
> cc-option,-march=armv8-a)
> arch-$(CONFIG_CPU_32v7)   :=-D__LINUX_ARM_ARCH__=7 $(call
> cc-option,-march=armv7-a,-march=armv5t -Wa$(comma)-march=armv7-a)
> arch-$(CONFIG_CPU_32v6)   :=-D__LINUX_ARM_ARCH__=6 $(call
> cc-option,-march=armv6,-march=armv5t -Wa$(comma)-march=armv6)
> arch-$(CONFIG_CPU_32v5)   :=-D__LINUX_ARM_ARCH__=5 $(call
> cc-option,-march=armv5te,-march=armv4t)
> 
> The error from the compiler is:
> 
> cc1: error: ‘-mfloat-abi=hard’: selected architecture lacks an FPU
> 
> (Note: the error is only shown after tweaking the `try-run` command in
> "scripts/Kbuild.include" so that it does not send error output to
> "/dev/null".)
> 
> That error seems to be a change in behaviour between GCC 10.x and GCC 11.x.
> 
> At the point in the Makefile that the error occurs, the `-msoft-float`
> option has not been added to `KBUILD_CPPFLAGS` yet. That is done further
> down the Makefile except for `CONFIG_CPU_V8`.  I guess it needs to be added
> somewhere before problematic lines in the Makefile.  I'm not sure if
> `-msoft-float` is also needed for 64-bit ARMv8, but the error suggests it is
> required there too.

-- 
Pengutronix e.K.   | |
Steuerwalder Str. 21   | http://www.pengutronix.de/  |
31137 Hildesheim, Germany  | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |

___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH] mtd: spi-nor: Add support for gd25q16

2021-05-20 Thread Michael Olbrich
The entry is imported from Linux v5.12.

It can befound on new versions of the Boundary Devices i.MX6 Quad
Nitrogen6x boards.

Signed-off-by: Michael Olbrich 
---
 drivers/mtd/spi-nor/spi-nor.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
index 383916e3f4b0..3ced84049d58 100644
--- a/drivers/mtd/spi-nor/spi-nor.c
+++ b/drivers/mtd/spi-nor/spi-nor.c
@@ -666,6 +666,7 @@ static const struct spi_device_id spi_nor_ids[] = {
{ "mb85rs1mt", INFO(0x047f27, 0, 128 * 1024, 1, SPI_NOR_NO_ERASE) },
 
/* GigaDevice */
+   { "gd25q16", INFO(0xc84015, 0, 64 * 1024,  32, SECT_4K) },
{ "gd25q32", INFO(0xc84016, 0, 64 * 1024,  64, SECT_4K) },
{ "gd25q64", INFO(0xc84017, 0, 64 * 1024, 128, SECT_4K) },
{ "gd25q128", INFO(0xc84018, 0, 64 * 1024, 256, SECT_4K) },
-- 
2.31.1


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH] readline_simple: Fix compiler warning

2021-05-12 Thread Michael Olbrich
On Wed, May 12, 2021 at 07:44:40AM +0200, Sascha Hauer wrote:
> char is an unsigned type.

That's incorrect. In the C standard it is explicitly undefined whether char
is signed or unsigned. gcc implements this differently depending on the
architecture. I think ARM and x86 differ here.

Michael

> To test the getchar() return value against
> negative values we have to use a signed type. Use int instead.
> 
> Signed-off-by: Sascha Hauer 
> ---
>  lib/readline_simple.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/lib/readline_simple.c b/lib/readline_simple.c
> index fcdbca41a9..2e52bfc2a0 100644
> --- a/lib/readline_simple.c
> +++ b/lib/readline_simple.c
> @@ -44,7 +44,7 @@ int readline (const char *prompt, char *line, int len)
>   int n = 0;  /* buffer index */
>   int plen = 0;   /* prompt length*/
>   int col;/* output column cnt*/
> - charc;
> + int c;
>  
>   /* print prompt */
>   if (prompt) {
> -- 
> 2.29.2
> 
> 
> ___
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.   | |
Steuerwalder Str. 21   | http://www.pengutronix.de/  |
31137 Hildesheim, Germany  | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |

___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH 1/2] blspec: allow board files to overwrite config file settings

2021-01-20 Thread Michael Olbrich
On Wed, Jan 20, 2021 at 11:54:22AM +0100, Marco Felsch wrote:
> On 21-01-20 10:03, Sascha Hauer wrote:
> > On Tue, Jan 19, 2021 at 12:42:08PM +0100, Marco Felsch wrote:
> > > Hi Sascha,
> > > 
> > > On 21-01-19 12:01, Sascha Hauer wrote:
> > > > Hi Marco,
> > > > On Mon, Jan 18, 2021 at 09:48:49PM +0100, Marco Felsch wrote:
> > > > > This commit adds the support to overwrite and/or adapt blspec config
> > > > > files by the following global variables:
> > > > >   - global.blspec.fixup.devicetree
> > > > >   - global.blspec.fixup.initrd
> > > > >   - global.blspec.fixup.options
> > > > >   - global.blspec.fixup.linux
> > > > >   - global.blspec.fixup.devicetree-overlay.
> > > > > 
> > > > > Overwriting blspec-config's shouldn't be the normal case but there are
> > > > > cases where this support is needed. One use-case can be a special
> > > > > handling during update. E.g. the normal boot-flow don't need the 
> > > > > initrd
> > > > > but the update-flow uses it because the update system is on the 
> > > > > initrd.
> > > > 
> > > > When you have an update system and a regular system on the same
> > > > filesystem then I would expect an additional bootspec entry for the
> > > > update system.
> > > 
> > > AFAIK, barebox tries to find the correct entry by checking all config
> > > files and loads the first matching config file. Is there a way to
> > > specify an explicite config file?
> > 
> > Not yet, but maybe we are at a point where a way should be added.
> 
> Maybe but how do you decide it? Also IMHO this wouldn't be that flexible
> as this solution.

Maybe allow globing?

So I can say I want to boot 'default.conf' and create that as a symlink in
the filesystem. That would be for the desktop use-case with multiple kernel
versions.

Or I could switch between '*-regular.conf' and '*-update.conf'. And then
provide two entries for each device-tree.

Michael


-- 
Pengutronix e.K.   | |
Steuerwalder Str. 21   | http://www.pengutronix.de/  |
31137 Hildesheim, Germany  | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |

___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH 2/2] x86/config/efi: drop DRIVER_SERIAL_NS16550

2020-10-26 Thread Michael Olbrich
On Tue, Oct 20, 2020 at 09:35:30AM +0200, Ahmad Fatoum wrote:
> On 10/20/20 9:26 AM, Uwe Kleine-König wrote:
> > On Tue, Oct 20, 2020 at 07:08:47AM +0200, Ahmad Fatoum wrote:
> >> Hello Uwe,
> >>
> >> On 9/18/20 1:04 PM, Uwe Kleine-König wrote:
> >>> For most machines having DRIVER_SERIAL_NS16550 and DRIVER_SERIAL_EFI_STDIO
> >>> both enabled results in the output appearing twice on the serial output.
> >>> So remove disable the lowlevel driver and rely on the EFI bios for serial.
> > 
> > How embarrassing, s/remove //.
> > 
> >> On the flip-side, some systems now won't output anything over serial with
> >> the defconfig, like the one I just ran into. Maybe we should keep both
> >> enabled, but have a quirk table, which boards to disable the 16550 for?
> > 
> > Expecting that most systems are happy with EFI_STDIO I would suggest a
> > quirk table for those systems which are not?!
> 
> Doubled output is better than no output, so a defconfig that
> by default displays anything if the BIOS is not in the quirk
> table sounds like it's the better choice?

Maybe disable CONSOLE_ACTIVATE_ALL instead? Then you should only get the
output from one driver.

Michael

> > 
> >> My board is
> >>   EFI v2.40 by American Megatrends v327691". What's yours?
> >>   barebox@barebox EFI payload:/ devinfo acpi-FACP0
> >>   [...]
> >>   Revision: 5
> >>   OemId: ALASKA
> >>   OemTableId: A M I
> >>   OemRevision: 17244169
> >>   CreatorId: 0x20494d41
> >>   CreatorRevision: 6
> >>
> >> What's yours?
> > 
> > I saw the doubled output on my Laptop (Lenovo T460p).
> 
> You have serial output on your laptop?
> 
> > 
> > dmidecode has:
> > 
> > BIOS Information
> > Vendor: LENOVO
> > Version: R07ET81W (2.21 )
> > Release Date: 12/18/2017
> > Address: 0xE
> > Runtime Size: 128 kB
> > ROM Size: 16 MB
> > Characteristics:
> > PCI is supported
> > PNP is supported
> > BIOS is upgradeable
> > BIOS shadowing is allowed
> > Boot from CD is supported
> > Selectable boot is supported
> > EDD is supported
> > 3.5"/720 kB floppy services are supported (int 13h)
> > Print screen service is supported (int 5h)
> > 8042 keyboard services are supported (int 9h)
> > Serial services are supported (int 14h)
> > Printer services are supported (int 17h)
> > CGA/mono video services are supported (int 10h)
> > ACPI is supported
> > USB legacy is supported
> > BIOS boot specification is supported
> > Targeted content distribution is supported
> > UEFI is supported
> > BIOS Revision: 2.21
> > Firmware Revision: 1.4
> > 
> > (This is the system I write this mail on, I don't feel like rebooting to 
> > check
> > devinfo in barebox, take a picture and then type the stuff into a mail
> > by hand.)
> > 
> > Best regards
> > Uwe
> > 
> > 
> 
> -- 
> Pengutronix e.K.   | |
> Steuerwalder Str. 21   | http://www.pengutronix.de/  |
> 31137 Hildesheim, Germany  | Phone: +49-5121-206917-0|
> Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |
> 
> ___
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.   | |
Steuerwalder Str. 21   | http://www.pengutronix.de/  |
31137 Hildesheim, Germany  | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |

___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH 1/3] scripts: use #!/usr/bin/env bash shebang instead of #!/bin/bash

2019-12-03 Thread Michael Olbrich
On Tue, Dec 03, 2019 at 09:45:28AM +0100, Sascha Hauer wrote:
> On Tue, Dec 03, 2019 at 07:46:03AM +0100, Michael Olbrich wrote:
> > On Thu, Nov 28, 2019 at 12:19:44AM +0100, Florian Klink wrote:
> > > Some distributions might not have bash in /bin, but in $PATH.
> > > 
> > > Using #!/usr/bin/env bash solves this, and is consistent with how the
> > > perl and python shebangs look like in the tree.
> > > ---
> > >  scripts/canon-a1100-image| 2 +-
> > >  scripts/check_size   | 2 +-
> > >  scripts/dfuboot.sh   | 2 +-
> > >  scripts/extract_symbol_offset| 2 +-
> > >  scripts/gen-dtb-s| 2 +-
> > >  scripts/genenv   | 2 +-
> > >  scripts/socfpga_get_sequencer| 2 +-
> > >  scripts/socfpga_import_preloader | 2 +-
> > >  scripts/socfpga_xml_to_config.sh | 2 +-
> > >  9 files changed, 9 insertions(+), 9 deletions(-)
> > > 
> > > diff --git a/scripts/canon-a1100-image b/scripts/canon-a1100-image
> > > index 6c08d7493..237ce26d8 100755
> > > --- a/scripts/canon-a1100-image
> > > +++ b/scripts/canon-a1100-image
> > > @@ -1,4 +1,4 @@
> > > -#!/bin/bash -e
> > > +#!/usr/bin/env bash -e
> > 
> > This does not work:
> > 
> > /usr/bin/env: ‘bash -e’: No such file or directory
> > /usr/bin/env: use -[v]S to pass options in shebang lines
> > 
> > Using '/usr/bin/env -S bash -e' works, but I'm not sure how portable that
> > is.
> 
> Why not:
> 
> #!/usr/bin/env bash
> 
> set -e

Yes, that should work.

Michael

-- 
Pengutronix e.K.   | |
Steuerwalder Str. 21   | http://www.pengutronix.de/  |
31137 Hildesheim, Germany  | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |

___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH 1/3] scripts: use #!/usr/bin/env bash shebang instead of #!/bin/bash

2019-12-02 Thread Michael Olbrich
On Thu, Nov 28, 2019 at 12:19:44AM +0100, Florian Klink wrote:
> Some distributions might not have bash in /bin, but in $PATH.
> 
> Using #!/usr/bin/env bash solves this, and is consistent with how the
> perl and python shebangs look like in the tree.
> ---
>  scripts/canon-a1100-image| 2 +-
>  scripts/check_size   | 2 +-
>  scripts/dfuboot.sh   | 2 +-
>  scripts/extract_symbol_offset| 2 +-
>  scripts/gen-dtb-s| 2 +-
>  scripts/genenv   | 2 +-
>  scripts/socfpga_get_sequencer| 2 +-
>  scripts/socfpga_import_preloader | 2 +-
>  scripts/socfpga_xml_to_config.sh | 2 +-
>  9 files changed, 9 insertions(+), 9 deletions(-)
> 
> diff --git a/scripts/canon-a1100-image b/scripts/canon-a1100-image
> index 6c08d7493..237ce26d8 100755
> --- a/scripts/canon-a1100-image
> +++ b/scripts/canon-a1100-image
> @@ -1,4 +1,4 @@
> -#!/bin/bash -e
> +#!/usr/bin/env bash -e

This does not work:

/usr/bin/env: ‘bash -e’: No such file or directory
/usr/bin/env: use -[v]S to pass options in shebang lines

Using '/usr/bin/env -S bash -e' works, but I'm not sure how portable that
is.

Michael

>  
>  IFILE=$1
>  OFILE=$2
> diff --git a/scripts/check_size b/scripts/check_size
> index 8530435d3..76608eccc 100755
> --- a/scripts/check_size
> +++ b/scripts/check_size
> @@ -1,4 +1,4 @@
> -#!/bin/bash
> +#!/usr/bin/env bash
>  
>  symbol="$1"
>  file="$2"
> diff --git a/scripts/dfuboot.sh b/scripts/dfuboot.sh
> index 524113b61..9847579ce 100755
> --- a/scripts/dfuboot.sh
> +++ b/scripts/dfuboot.sh
> @@ -1,4 +1,4 @@
> -#!/bin/bash
> +#!/usr/bin/env bash
>  
>  DEVICETREE=
>  KERNEL=
> diff --git a/scripts/extract_symbol_offset b/scripts/extract_symbol_offset
> index 78b866830..d0ea22434 100755
> --- a/scripts/extract_symbol_offset
> +++ b/scripts/extract_symbol_offset
> @@ -1,4 +1,4 @@
> -#!/bin/bash
> +#!/usr/bin/env bash
>  
>  symbol="$1"
>  file="$2"
> diff --git a/scripts/gen-dtb-s b/scripts/gen-dtb-s
> index b2dd253c2..0649247f9 100755
> --- a/scripts/gen-dtb-s
> +++ b/scripts/gen-dtb-s
> @@ -1,4 +1,4 @@
> -#!/bin/bash
> +#!/usr/bin/env bash
>  
>  name=$1
>  dtb=$2
> diff --git a/scripts/genenv b/scripts/genenv
> index 5ebe69963..454f2327b 100755
> --- a/scripts/genenv
> +++ b/scripts/genenv
> @@ -1,4 +1,4 @@
> -#!/bin/bash
> +#!/usr/bin/env bash
>  
>  # Generate the default environment file from a list of directories
>  # usage: genenv...
> diff --git a/scripts/socfpga_get_sequencer b/scripts/socfpga_get_sequencer
> index 36f67498b..5405bfa6b 100755
> --- a/scripts/socfpga_get_sequencer
> +++ b/scripts/socfpga_get_sequencer
> @@ -1,4 +1,4 @@
> -#!/bin/bash
> +#!/usr/bin/env bash
>  
>  if [ "$#" -lt "2" ]
>  then
> diff --git a/scripts/socfpga_import_preloader 
> b/scripts/socfpga_import_preloader
> index 6c748fadb..23e3c380d 100755
> --- a/scripts/socfpga_import_preloader
> +++ b/scripts/socfpga_import_preloader
> @@ -1,4 +1,4 @@
> -#!/bin/bash
> +#!/usr/bin/env bash
>  
>  if [ "$#" -lt "2" ]
>  then
> diff --git a/scripts/socfpga_xml_to_config.sh 
> b/scripts/socfpga_xml_to_config.sh
> index 7e22ebb9e..3bb0dd283 100755
> --- a/scripts/socfpga_xml_to_config.sh
> +++ b/scripts/socfpga_xml_to_config.sh
> @@ -1,4 +1,4 @@
> -#!/bin/bash
> +#!/usr/bin/env bash
>  
>  ## TODO:
>  ## - read in mpuclk and nocclk, must be calculated by hand at the moment
> -- 
> 2.24.0
> 
> 
> ___
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.   | |
Steuerwalder Str. 21   | http://www.pengutronix.de/  |
31137 Hildesheim, Germany  | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |

___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH 03/11] complete: remove unused variable

2019-08-22 Thread Michael Olbrich
On Thu, Aug 22, 2019 at 07:51:06AM +0200, Ahmad Fatoum wrote:
> instr_param serves no purpose in the function. Thus remove it.
> 
> Signed-off-by: Ahmad Fatoum 
> ---
>  common/complete.c   | 2 --
>  include/ata_drive.h | 4 ++--
>  2 files changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/common/complete.c b/common/complete.c
> index 2dab7d1dde1e..919e5abc6a62 100644
> --- a/common/complete.c
> +++ b/common/complete.c
> @@ -277,7 +277,6 @@ static int env_param_complete(struct string_list *sl, 
> char *instr, int eval)
>   struct device_d *dev;
>   struct variable_d *var;
>   struct env_context *c;
> - char *instr_param;
>   int len;
>   char end = '=', *pos, *dot;
>   char *begin = "";
> @@ -317,7 +316,6 @@ static int env_param_complete(struct string_list *sl, 
> char *instr, int eval)
>  
>   devname = xstrndup(instr, dot - instr);
>  
> - instr_param++;
>  
>   dev = get_device_by_name(devname);
>   free(devname);
> diff --git a/include/ata_drive.h b/include/ata_drive.h
> index 11685eef12cf..d61c6f11d4d3 100644
> --- a/include/ata_drive.h
> +++ b/include/ata_drive.h
> @@ -14,7 +14,7 @@
>   */
>  
>  #ifndef ATA_DISK_H
> -# define ATA_DISK
> +#define ATA_DISK_H

Unrelated change?

Michael

>  
>  #include 
>  
> @@ -197,4 +197,4 @@ struct device_d;
>   *   0x400 data  data   16 bit area with 1 kiB in size
>   */
>  
> -#endif /* ATA_DISK */
> +#endif /* ATA_DISK_H */
> -- 
> 2.20.1
> 
> 
> ___
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |

___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH] i.MX habv3: add missing includes and make locally used function static

2019-03-02 Thread Michael Olbrich
Without this building fails with:

drivers/hab/habv3.c:80:12: error: static declaration of 'imx25_hab_get_status' 
follows non-static declaration
In file included from drivers/hab/habv3.c:14:
include/hab.h:39:5: note: previous declaration of 'imx25_hab_get_status' was 
here
drivers/hab/habv3.c:87:1: warning: data definition has no type or storage class
drivers/hab/habv3.c:87:1: warning: type defaults to 'int' in declaration of 
'postmmu_initcall' [-Wimplicit-int]
drivers/hab/habv3.c:87:1: warning: parameter names (without types) in function 
declaration
drivers/hab/habv3.c:80:12: warning: 'imx25_hab_get_status' defined but not used 
[-Wunused-function]

Signed-off-by: Michael Olbrich 
---
 drivers/hab/habv3.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/hab/habv3.c b/drivers/hab/habv3.c
index 47d3caf864ec..f3f94bc44c8c 100644
--- a/drivers/hab/habv3.c
+++ b/drivers/hab/habv3.c
@@ -10,9 +10,11 @@
  */
 #define pr_fmt(fmt) "HABv3: " fmt
 
+#include 
 #include 
 #include 
 #include 
+#include 
 
 struct hab_status {
u8 value;
@@ -55,7 +57,7 @@ static struct hab_status hab_status[] = {
{ 0x8e, "algorithm type is either invalid or ortherwise unsupported" },
 };
 
-int imx_habv3_get_status(uint32_t status)
+static int imx_habv3_get_status(uint32_t status)
 {
int i;
 
-- 
2.20.1


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: MIPS parallel build breakage

2018-03-01 Thread Michael Olbrich
Hi,

On Thu, Mar 01, 2018 at 12:07:29PM +0100, Sascha Hauer wrote:
> (Antony because you introduced this and Sam because you have intimate
> knowledge with our build system ;)
> 
> I am trying to solve a problem that annoys me for some years now. The
> problem is that the MIPS defconfigs regularly fail in my autobuilder.
> I usually help myself with trying it again and most of the time it
> then works, but doing this for years increases the pressure to do
> something.
> 
> What happens is that the MIPS builds use include/generated/compile.h:
> 
> > arch/mips/include/asm/pbl_macros.h:28:#include 
> 
> This often ends in:
> 
> > In file included from arch/mips/boot/start.S:20:0: 
> > arch/mips/include/asm/pbl_macros.h:28:31:
> > fatal error: generated/compile.h: No such file or directory
> > compilation terminated.
> 
> include/generated/compile.h is generated in common/Makefile:
> 
> > include/generated/compile.h: FORCE
> > @$($(quiet)chk_compile.h)
> > $(Q)$(CONFIG_SHELL) $(srctree)/scripts/mkcompile_h $@ \
> > "$(UTS_MACHINE)" "$(CC) $(KBUILD_CFLAGS)"
> 
> Other users of this file add an explicit dependency on it:
> 
> > # dependencies on generated files need to be listed explicitly
> > $(obj)/version.o: include/generated/compile.h
> 
> This only seems to work though when the dependent file is in the same
> directory, but not when the file is in arch/mips/boot/.
> 
> I tried doing the include/generated/compile.h in Makefile instead of
> common/Makefile, but then the version counting gets confused and causes
> unnecessary rebuilds.
> 
> Any ideas how to solve this?

arch/mips/boot/: common/

in arch/mips/Makefile or something like that? These two are both targets of the
toplevel make call, so that should work. The same for $(BOARD), I think and
maybe others that include generated/compile.h.

Michael

-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |

___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH] scripts/compiler.h: inline functions in headers must be static

2018-02-06 Thread Michael Olbrich
Without this building bareboxenv-target with gcc 7.3 fails with:

  CC  scripts/bareboxenv-target
/tmp/cc9G2oOY.o: In function `file_action':
bareboxenv.c:(.text+0x14): undefined reference to `xzalloc'
/tmp/cc9G2oOY.o: In function `concat_path_file':
bareboxenv.c:(.text+0xf4): undefined reference to `xmalloc'
/tmp/cc9G2oOY.o: In function `envfs_save':
bareboxenv.c:(.text+0x5b4): undefined reference to `xzalloc'
/tmp/cc9G2oOY.o: In function `envfs_load':
bareboxenv.c:(.text+0x7d8): undefined reference to `xmalloc'
collect2: error: ld returned 1 exit status

Signed-off-by: Michael Olbrich <m.olbr...@pengutronix.de>
---
 scripts/compiler.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/scripts/compiler.h b/scripts/compiler.h
index 0891c3bfa6fa..4cf179bb9b13 100644
--- a/scripts/compiler.h
+++ b/scripts/compiler.h
@@ -113,7 +113,7 @@ typedef uint32_t __u32;
(void) (&_min1 == &_min2);  \
_min1 < _min2 ? _min1 : _min2; })
 
-inline void *xmalloc(size_t size)
+static inline void *xmalloc(size_t size)
 {
void *p = NULL;
 
@@ -125,7 +125,7 @@ inline void *xmalloc(size_t size)
return p;
 }
 
-inline void *xzalloc(size_t size)
+static inline void *xzalloc(size_t size)
 {
void *p = xmalloc(size);
memset(p, 0, size);
-- 
2.16.1


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH 2/2] efi-block: detect when the block device is a USB Disk

2017-11-02 Thread Michael Olbrich
On Fri, Oct 27, 2017 at 09:05:48AM +0200, Jean-Christophe PLAGNIOL-VILLARD 
wrote:
> use usbdisk as a basename
> 
> This will be usefull as example when we want to search for a usb disk for
> failsafe update or install.

I understand the use-case, but this breaks a different setup: Until now
'disk0' is usually the 'boot' device (the one barebox was loaded from). So
it was rather simple to create one image with bootloader, kernel and rootfs
that can be booted from USB and SATA.

Regards,
Michael

> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD 
> ---
>  drivers/block/efi-block-io.c | 17 -
>  1 file changed, 16 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/block/efi-block-io.c b/drivers/block/efi-block-io.c
> index a4d9d3a95..2bbeb99e6 100644
> --- a/drivers/block/efi-block-io.c
> +++ b/drivers/block/efi-block-io.c
> @@ -130,6 +130,18 @@ static void efi_bio_print_info(struct efi_bio_priv *priv)
>   media->optimal_transfer_length_granularity);
>  }
>  
> +static int is_bio_usbdev(struct efi_device *efidev)
> +{
> + int i;
> +
> + for (i = 0; i < efidev->num_guids; i++) {
> + if (!efi_guidcmp(efidev->guids[i], EFI_USB_IO_PROTOCOL_GUID))
> + return 1;
> + }
> +
> + return 0;
> +}
> +
>  int efi_bio_probe(struct efi_device *efidev)
>  {
>   int ret;
> @@ -147,7 +159,10 @@ int efi_bio_probe(struct efi_device *efidev)
>   efi_bio_print_info(priv);
>   priv->dev = >dev;
>  
> - priv->blk.cdev.name = xasprintf("disk%d", cdev_find_free_index("disk"));
> + if (is_bio_usbdev(efidev))
> + priv->blk.cdev.name = xasprintf("usbdisk%d", 
> cdev_find_free_index("usbdisk"));
> + else
> + 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 = _bio_ops;
> -- 
> 2.11.0
> 
> 
> ___
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |

___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: stable release v2017.05.4, v2017.06.2, v2017.07.1

2017-07-16 Thread Michael Olbrich
Hi,

On Fri, Jul 14, 2017 at 05:04:25PM +0200, Lucas Stach wrote:
> I've just pushed out a new set of Barebox stable releases:
[...]

Can you please sign the tags next time? It's usefull in general and
CONFIG_LOCALVERSION_AUTO for these tags.

Regards,
Michael

-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |

___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH 2/8] common: efi: do not use undefined kconfig option

2017-07-06 Thread Michael Olbrich
On Wed, Jul 05, 2017 at 01:05:25PM +0200, Lucas Stach wrote:
> Am Mittwoch, den 05.07.2017, 12:56 +0200 schrieb Steffen Trumtrar:
> > Signed-off-by: Steffen Trumtrar 
> > ---
> >  common/efi/efi.c | 3 +--
> >  1 file changed, 1 insertion(+), 2 deletions(-)
> > 
> > diff --git a/common/efi/efi.c b/common/efi/efi.c
> > index 05c58250f4a7..f924385958e1 100644
> > --- a/common/efi/efi.c
> > +++ b/common/efi/efi.c
> > @@ -266,8 +266,7 @@ static int efi_console_init(void)
> >  
> > add_generic_device("efi-stdio", DEVICE_ID_SINGLE, NULL, 0 , 0, 0, NULL);
> >  
> > -   if (IS_ENABLED(CONFIG_ARCH_EFI_REGISTER_COM1))
> 
> It seems we lost this option when moving arch/efi to arch/x86. As
> unconditionally enabling the serial console may break some boards, the
> proper fix should be to bring back the Kconfig option.

I think that option is pretty much redundant. This is x86. There is no
device tree to enable devices.
There are only two possible scenarios: use ns16550 or not. Building the
driver and maybe use it does not exist. And we can use
CONFIG_DRIVER_SERIAL_NS16550 to choose.

Somewhat unrelated: I think this driver should be avoided if possible. I'm
quite certain, that the original use-case for this was a bug in barebox and
not a broken EFI serial driver.

Michael

> > -   add_ns16550_device(0, 0x3f8, 0x10, IORESOURCE_IO | 
> > IORESOURCE_MEM_8BIT,
> > +   add_ns16550_device(0, 0x3f8, 0x10, IORESOURCE_IO | IORESOURCE_MEM_8BIT,
> > _plat);
> >  
> > return 0;

-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |

___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH 11/13] efi: fix lds for secure boot support

2017-03-26 Thread Michael Olbrich
On Sun, Mar 26, 2017 at 04:45:02AM +0200, Jean-Christophe PLAGNIOL-VILLARD 
wrote:
> everythink need to be aligned to 4096

As Lucas noted the last time, this deserves a comment why this is needed.
Just a reference to the EFI spec (I think?) or something like that.

> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD 
> ---
>  arch/x86/mach-efi/elf_ia32_efi.lds.S | 10 +++---
>  arch/x86/mach-efi/elf_x86_64_efi.lds.S   | 10 ++
>  arch/x86/mach-efi/include/mach/barebox.lds.h | 14 +-
>  include/asm-generic/barebox.lds.h|  8 +---
>  4 files changed, 31 insertions(+), 11 deletions(-)
> 
> diff --git a/arch/x86/mach-efi/elf_ia32_efi.lds.S 
> b/arch/x86/mach-efi/elf_ia32_efi.lds.S
> index 69f43f554..6d9cb973c 100644
> --- a/arch/x86/mach-efi/elf_ia32_efi.lds.S
> +++ b/arch/x86/mach-efi/elf_ia32_efi.lds.S
> @@ -50,22 +50,23 @@ SECTIONS
>   *(COMMON)
>   }
>  
> - . = ALIGN(64);
> + . = ALIGN(4096);
>  
>   __barebox_initcalls_start = .;
>   __barebox_initcalls : { INITCALLS }
>   __barebox_initcalls_end = .;
> + . = ALIGN(4096);
>  
>   __barebox_exitcalls_start = .;
>   __barebox_exitcalls : { EXITCALLS }
>   __barebox_exitcalls_end = .;
>  
> - . = ALIGN(64);
> + . = ALIGN(4096);
>   __barebox_magicvar_start = .;
>   .barebox_magicvar : { BAREBOX_MAGICVARS }
>   __barebox_magicvar_end = .;
>  
> - . = ALIGN(64);
> + . = ALIGN(4096);
>   __barebox_cmd_start = .;
>   __barebox_cmd : { BAREBOX_CMDS }
>   __barebox_cmd_end = .;
> @@ -76,6 +77,9 @@ SECTIONS
>   .rel : {
>   *(.rel.data)
>   *(.rel.data.*)
> + *(.rela.barebox*)
> + *(.rela.initcall*)
> + *(.rela.exitcall*)

This is unrelated and should be a different patch.

>   *(.rel.got)
>   *(.rel.stab)
>   *(.data.rel.ro.local)
> diff --git a/arch/x86/mach-efi/elf_x86_64_efi.lds.S 
> b/arch/x86/mach-efi/elf_x86_64_efi.lds.S
> index 93d34d17a..8216d1d70 100644
> --- a/arch/x86/mach-efi/elf_x86_64_efi.lds.S
> +++ b/arch/x86/mach-efi/elf_x86_64_efi.lds.S
> @@ -23,6 +23,7 @@ SECTIONS
>   *(.text)
>   *(.text.*)
>   *(.gnu.linkonce.t.*)
> + . = ALIGN(16);

Why 16 here?

Regards,
Michael

>   }
>  
>   _etext = .;
> @@ -33,8 +34,8 @@ SECTIONS
>   *(.reloc)
>   }
>  
> - . = ALIGN(4096);
>   _sdata = .;
> + . = ALIGN(4096);
>  
>   .data : {
>   *(.rodata*)
> @@ -52,22 +53,23 @@ SECTIONS
>   *(.rel.local)
>   }
>  
> - . = ALIGN(64);
> + . = ALIGN(4096);
>  
>   __barebox_initcalls_start = .;
>   __barebox_initcalls : { INITCALLS }
>   __barebox_initcalls_end = .;
> + . = ALIGN(4096);
>  
>   __barebox_exitcalls_start = .;
>   __barebox_exitcalls : { EXITCALLS }
>   __barebox_exitcalls_end = .;
>  
> - . = ALIGN(64);
> + . = ALIGN(4096);
>   __barebox_magicvar_start = .;
>   .barebox_magicvar : { BAREBOX_MAGICVARS }
>   __barebox_magicvar_end = .;
>  
> - . = ALIGN(64);
> + . = ALIGN(4096);
>   __barebox_cmd_start = .;
>   __barebox_cmd : { BAREBOX_CMDS }
>   __barebox_cmd_end = .;
> diff --git a/arch/x86/mach-efi/include/mach/barebox.lds.h 
> b/arch/x86/mach-efi/include/mach/barebox.lds.h
> index 40a8c178f..e7a3bb9cd 100644
> --- a/arch/x86/mach-efi/include/mach/barebox.lds.h
> +++ b/arch/x86/mach-efi/include/mach/barebox.lds.h
> @@ -1 +1,13 @@
> -/* empty */
> +/*
> + * Copyright (C) 2017 Jean-Christophe PLAGNIOL-VILLARD 
> + *
> + * Under GPL v2
> + */
> +
> +#ifndef __EFI_MACH_BAREBOX_LDS_H__
> +#define __EFI_MACH_BAREBOX_LDS_H__
> +
> +/* For secure boot we need all the section to be 4096 alligned */
> +#define STRUCT_ALIGNMENT 4096
> +
> +#endif /* __EFI_MACH_BAREBOX_LDS_H__ */
> diff --git a/include/asm-generic/barebox.lds.h 
> b/include/asm-generic/barebox.lds.h
> index c8a919b92..6c37751b3 100644
> --- a/include/asm-generic/barebox.lds.h
> +++ b/include/asm-generic/barebox.lds.h
> @@ -3,15 +3,17 @@
>   * Align to a 32 byte boundary equal to the
>   * alignment gcc 4.5 uses for a struct
>   */
> -#define STRUCT_ALIGNMENT 32
> -#define STRUCT_ALIGN() . = ALIGN(STRUCT_ALIGNMENT)
> -
>  #if defined CONFIG_X86 || \
>   defined CONFIG_ARCH_EP93XX || \
>   defined CONFIG_ARCH_ZYNQ
>  #include 
>  #endif
>  
> +#ifndef STRUCT_ALIGNMENT
> +#define STRUCT_ALIGNMENT 32
> +#endif
> +#define STRUCT_ALIGN() . = ALIGN(STRUCT_ALIGNMENT)
> +
>  #ifndef PRE_IMAGE
>  #define PRE_IMAGE
>  #endif
> -- 
> 2.11.0
> 
> 
> ___
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | 

Re: [PATCH 08/13] boot_verify: allow to force unsigned image to boot

2017-03-26 Thread Michael Olbrich
On Sun, Mar 26, 2017 at 04:44:59AM +0200, Jean-Christophe PLAGNIOL-VILLARD 
wrote:
> request confirmation before booting an unsigned image
> 
> with a default timeout
> 
> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD 
> ---
>  commands/go.c |  9 +++--
>  common/Kconfig|  8 
>  common/boot_verify.c  | 47 ---
>  common/bootm.c|  6 ++
>  common/image-fit.c|  1 +
>  common/uimage.c   |  1 +
>  include/boot_verify.h |  7 +++
>  7 files changed, 74 insertions(+), 5 deletions(-)
> 
> diff --git a/commands/go.c b/commands/go.c
> index e0385a977..919bcddc7 100644
> --- a/commands/go.c
> +++ b/commands/go.c
> @@ -38,8 +38,13 @@ static int do_go(int argc, char *argv[])
>   if (argc < 2)
>   return COMMAND_ERROR_USAGE;
>  
> - if (boot_get_verify_mode() < BOOT_VERIFY_AVAILABLE)
> - return -ESECVIOLATION;
> + if (boot_get_verify_mode() < BOOT_VERIFY_AVAILABLE) {
> + int is_sec;
> +
> + is_sec = boot_can_start_unsigned();
> + if (is_sec)
> + return is_sec;
> + }
>  
>   if (!isdigit(*argv[1])) {
>   fd = open(argv[1], O_RDONLY);
> diff --git a/common/Kconfig b/common/Kconfig
> index 00e98e859..2588651ae 100644
> --- a/common/Kconfig
> +++ b/common/Kconfig
> @@ -648,6 +648,14 @@ config BOOT_FORCE_SIGNED_IMAGES
> are refused to boot. Effectively this means only Signed images can
> be booted.
>  
> +config BOOT_FORCE_USER_SIGNED_IMAGES
> + bool
> + prompt "Force booting of signed images or confirm them"
> + depends on HAS_SECURE_BOOT
> + help
> +   With this option enabled only signed images can be booted, unsigned 
> images
> +   need a user confirmation to boot.
> +
>  config BLSPEC
>   depends on BLOCK
>   depends on FLEXIBLE_BOOTARGS
> diff --git a/common/boot_verify.c b/common/boot_verify.c
> index 9cbeb7a65..07ae07e16 100644
> --- a/common/boot_verify.c
> +++ b/common/boot_verify.c
> @@ -1,9 +1,17 @@
> +/*
> + * Copyright (c) 2016 Sascha Hauer , Pengutronix
> + * Copyright (c) 2017 Jean-Christophe PLAGNIOL-VILLARD 
> 
> + *
> + * Under GPLv2 Only
> + */

This belongs in the patch that introduces the file.

Michael

>  #include 
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
>  
> +static unsigned int boot_verify_confirm_timeout = 10;
>  static enum boot_verify boot_verify_mode = BOOT_VERIFY_HASH;
>  
>  enum boot_verify boot_get_verify_mode(void)
> @@ -14,6 +22,7 @@ enum boot_verify boot_get_verify_mode(void)
>  /* keep it for the most secure to the less */
>  static const char * const boot_verify_names[] = {
>   [BOOT_VERIFY_SIGNATURE] = "signature",
> + [BOOT_VERIFY_SIGNATURE_USER] = "signature-user",
>   [BOOT_VERIFY_AVAILABLE] = "available",
>   [BOOT_VERIFY_HASH] = "hash",
>   [BOOT_VERIFY_NONE] = "none",
> @@ -40,6 +49,29 @@ void boot_set_is_secure_mode(int (*fn)(void))
>   __is_secure_mode = fn;
>  }
>  
> +int boot_can_start_unsigned(void)
> +{
> + int ret;
> + char c;
> + int timeout = boot_verify_confirm_timeout;
> +
> + if (!is_secure_mode())
> + return 0;
> +
> + if (boot_verify_mode != BOOT_VERIFY_SIGNATURE_USER)
> + return -ESECVIOLATION;
> +
> + printf("Are you sure you wish to run an unsigned binary\n");
> + printf("in a secure environment?\n");
> + printf("press y to confirm\n");
> +
> + ret = console_countdown(timeout, CONSOLE_COUNTDOWN_ANYKEY, );
> + if (ret != -EINTR)
> + return -ESECVIOLATION;
> +
> + return c == 'y' ? 0 : -ESECVIOLATION;
> +}
> +
>  static int init_boot_verify(void)
>  {
>   int size;
> @@ -47,16 +79,25 @@ static int init_boot_verify(void)
>   if (IS_ENABLED(CONFIG_BOOT_FORCE_SIGNED_IMAGES))
>   boot_verify_mode = BOOT_VERIFY_SIGNATURE;
>  
> - if (is_secure_mode())
> - size = 1;
> - else
> + if (is_secure_mode()) {
> + if (IS_ENABLED(CONFIG_BOOT_FORCE_USER_SIGNED_IMAGES))
> + size = 2;
> + else
> + size = 1;
> + } else {
>   size = ARRAY_SIZE(boot_verify_names);
> + }
>  
>   globalvar_add_simple_enum("boot.verify", (unsigned int 
> *)_verify_mode,
> boot_verify_names, size);
>  
> + globalvar_add_simple_int("boot.verify_confirm_timeout",
> +  _verify_confirm_timeout, "%u");
> +
>   return 0;
>  }
>  late_initcall(init_boot_verify);
>  
>  BAREBOX_MAGICVAR_NAMED(global_boot_verify, global.boot.verify, "boot default 
> verify level");
> +BAREBOX_MAGICVAR_NAMED(global_boot_verify_confirm_timeout, 
> global.boot.verify_confirm_timeout,
> + "Secure Boot Comfirm timeout in seconds before booting an 
> unsigned image");
> diff --git 

Re: [PATCH 07/13] go: only use it if boot signature is not required

2017-03-26 Thread Michael Olbrich
On Sun, Mar 26, 2017 at 04:44:58AM +0200, Jean-Christophe PLAGNIOL-VILLARD 
wrote:
> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD 

Does this realy help? If someone has access to the barebox shell, then
there are many ways to overwrite the secure boot check.

Michael

> ---
>  commands/go.c | 4 
>  1 file changed, 4 insertions(+)
> 
> diff --git a/commands/go.c b/commands/go.c
> index fb319b320..e0385a977 100644
> --- a/commands/go.c
> +++ b/commands/go.c
> @@ -26,6 +26,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  
>  static int do_go(int argc, char *argv[])
>  {
> @@ -37,6 +38,9 @@ static int do_go(int argc, char *argv[])
>   if (argc < 2)
>   return COMMAND_ERROR_USAGE;
>  
> + if (boot_get_verify_mode() < BOOT_VERIFY_AVAILABLE)
> + return -ESECVIOLATION;
> +
>   if (!isdigit(*argv[1])) {
>   fd = open(argv[1], O_RDONLY);
>   if (fd < 0) {
> -- 
> 2.11.0
> 
> 
> ___
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |

___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH 06/13] boot_verify: make it modifiable at start time

2017-03-26 Thread Michael Olbrich
On Sun, Mar 26, 2017 at 04:44:57AM +0200, Jean-Christophe PLAGNIOL-VILLARD 
wrote:
> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD 
> ---
>  commands/bootm.c  |  2 +-
>  common/boot_verify.c  | 39 +--
>  common/bootm.c|  2 +-
>  include/boot_verify.h | 15 ---
>  4 files changed, 47 insertions(+), 11 deletions(-)
> 
> diff --git a/commands/bootm.c b/commands/bootm.c
> index b35aaa914..cb520a1ba 100644
> --- a/commands/bootm.c
> +++ b/commands/bootm.c
> @@ -64,7 +64,7 @@ static int do_bootm(int argc, char *argv[])
>   while ((opt = getopt(argc, argv, BOOTM_OPTS)) > 0) {
>   switch(opt) {
>   case 'c':
> - if (data.verify < BOOT_VERIFY_HASH)
> + if (data.verify > BOOT_VERIFY_HASH)

This is very confusing without a comment. It took me a while to figure out
that this does not actually change anything.
I think you could change the order in the array without modifying the enum.
Or at least comment on it in the commit message.

Regards,
Michael

>   data.verify = BOOT_VERIFY_HASH;
>   break;
>   case 's':
> diff --git a/common/boot_verify.c b/common/boot_verify.c
> index afe929e68..9cbeb7a65 100644
> --- a/common/boot_verify.c
> +++ b/common/boot_verify.c
> @@ -11,22 +11,49 @@ enum boot_verify boot_get_verify_mode(void)
>   return boot_verify_mode;
>  }
>  
> +/* keep it for the most secure to the less */
>  static const char * const boot_verify_names[] = {
> -#ifndef CONFIG_BOOT_FORCE_SIGNED_IMAGES
> - [BOOT_VERIFY_NONE] = "none",
> - [BOOT_VERIFY_HASH] = "hash",
> - [BOOT_VERIFY_AVAILABLE] = "available",
> -#endif
>   [BOOT_VERIFY_SIGNATURE] = "signature",
> + [BOOT_VERIFY_AVAILABLE] = "available",
> + [BOOT_VERIFY_HASH] = "hash",
> + [BOOT_VERIFY_NONE] = "none",
>  };
>  
> +/* allow architecture to overwrite it such as EFI */
> +static int default_is_secure_mode(void)
> +{
> + if (IS_ENABLED(CONFIG_BOOT_FORCE_SIGNED_IMAGES))
> + return 1;
> +
> + return 0;
> +}
> +
> +static int (*__is_secure_mode)(void) = default_is_secure_mode;
> +
> +int is_secure_mode(void)
> +{
> + return __is_secure_mode();
> +}
> +
> +void boot_set_is_secure_mode(int (*fn)(void))
> +{
> + __is_secure_mode = fn;
> +}
> +
>  static int init_boot_verify(void)
>  {
> + int size;
> +
>   if (IS_ENABLED(CONFIG_BOOT_FORCE_SIGNED_IMAGES))
>   boot_verify_mode = BOOT_VERIFY_SIGNATURE;
>  
> + if (is_secure_mode())
> + size = 1;
> + else
> + size = ARRAY_SIZE(boot_verify_names);
> +
>   globalvar_add_simple_enum("boot.verify", (unsigned int 
> *)_verify_mode,
> -   boot_verify_names, 
> ARRAY_SIZE(boot_verify_names));
> +   boot_verify_names, size);
>  
>   return 0;
>  }
> diff --git a/common/bootm.c b/common/bootm.c
> index 74202a829..1558f3c5d 100644
> --- a/common/bootm.c
> +++ b/common/bootm.c
> @@ -159,7 +159,7 @@ static int bootm_open_initrd_uimage(struct image_data 
> *data)
>   if (!data->initrd)
>   return -EINVAL;
>  
> - if (boot_get_verify_mode() > BOOT_VERIFY_NONE) {
> + if (boot_get_verify_mode() != BOOT_VERIFY_NONE) {
>   ret = uimage_verify(data->initrd);
>   if (ret) {
>   printf("Checking data crc failed with %s\n",
> diff --git a/include/boot_verify.h b/include/boot_verify.h
> index 3a4436584..ee830bf5c 100644
> --- a/include/boot_verify.h
> +++ b/include/boot_verify.h
> @@ -2,10 +2,10 @@
>  #define __BOOT_VERIFY_H__
>  
>  enum boot_verify {
> - BOOT_VERIFY_NONE,
> - BOOT_VERIFY_HASH,
> - BOOT_VERIFY_AVAILABLE,
>   BOOT_VERIFY_SIGNATURE,
> + BOOT_VERIFY_AVAILABLE,
> + BOOT_VERIFY_HASH,
> + BOOT_VERIFY_NONE,
>  };
>  
>  #ifndef CONFIG_BOOT_VERIFY
> @@ -13,8 +13,17 @@ static inline enum boot_verify boot_get_verify_mode(void)
>  {
>   return BOOT_VERIFY_NONE;
>  }
> +
> +static int inline is_secure_mode(void)
> +{
> + return 0;
> +}
> +
> +static void inline boot_set_is_secure_mode(int (*fn)(void)) {}
>  #else
>  enum boot_verify boot_get_verify_mode(void);
> +int is_secure_mode(void);
> +void boot_set_is_secure_mode(int (*fn)(void));
>  #endif
>  
>  #endif /* __BOOT_VERIFY_H__ */
> -- 
> 2.11.0
> 
> 
> ___
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |


Re: [PATCH 01/13] bootm: move open to image_handler

2017-03-26 Thread Michael Olbrich
On Sun, Mar 26, 2017 at 04:44:52AM +0200, Jean-Christophe PLAGNIOL-VILLARD 
wrote:
> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD 
> ---
>  arch/arm/lib/bootm.c   |  2 +
>  arch/blackfin/lib/blackfin_linux.c |  1 +
>  arch/nios2/lib/bootm.c |  1 +
>  arch/ppc/lib/ppclinux.c|  1 +
>  common/bootm.c | 79 
> --
>  common/image-fit.c | 14 +++
>  common/misc.c  |  1 +
>  common/uimage.c| 32 +++
>  include/bootm.h|  1 +
>  include/image-fit.h|  1 +
>  include/image.h|  2 +
>  11 files changed, 80 insertions(+), 55 deletions(-)
> 
> diff --git a/arch/arm/lib/bootm.c b/arch/arm/lib/bootm.c
> index 8068a53be..204344f87 100644
> --- a/arch/arm/lib/bootm.c
> +++ b/arch/arm/lib/bootm.c
> @@ -217,6 +217,7 @@ static int do_bootm_linux(struct image_data *data)
>  
>  static struct image_handler uimage_handler = {
>   .name = "ARM Linux uImage",
> + .open = uimage_bootm_open,
>   .bootm = do_bootm_linux,
>   .filetype = filetype_uimage,
>   .ih_os = IH_OS_LINUX,
> @@ -579,6 +580,7 @@ BAREBOX_MAGICVAR(aimage_noverwrite_tags, "Disable 
> overwrite of the tags addr wit
>  
>  static struct image_handler arm_fit_handler = {
>  .name = "FIT image",
> + .open = fit_bootm_open,
>  .bootm = do_bootm_linux,
>  .filetype = filetype_oftree,
>  };
> diff --git a/arch/blackfin/lib/blackfin_linux.c 
> b/arch/blackfin/lib/blackfin_linux.c
> index 5ebd284d1..27002eadb 100644
> --- a/arch/blackfin/lib/blackfin_linux.c
> +++ b/arch/blackfin/lib/blackfin_linux.c
> @@ -68,6 +68,7 @@ static int do_bootm_linux(struct image_data *idata)
>  
>  static struct image_handler handler = {
>   .name = "Blackfin Linux",
> + .open = uimage_bootm_open,
>   .bootm = do_bootm_linux,
>   .filetype = filetype_uimage,
>   .ih_os = IH_OS_LINUX,
> diff --git a/arch/nios2/lib/bootm.c b/arch/nios2/lib/bootm.c
> index 34908bde3..f1b3c2624 100644
> --- a/arch/nios2/lib/bootm.c
> +++ b/arch/nios2/lib/bootm.c
> @@ -69,6 +69,7 @@ static int do_bootm_linux(struct image_data *idata)
>  
>  static struct image_handler handler = {
>   .name = "NIOS2 Linux",
> + .open = uimage_bootm_open,
>   .bootm = do_bootm_linux,
>   .filetype = filetype_uimage,
>   .ih_os = IH_OS_LINUX,
> diff --git a/arch/ppc/lib/ppclinux.c b/arch/ppc/lib/ppclinux.c
> index 3fca6b272..c882938fa 100644
> --- a/arch/ppc/lib/ppclinux.c
> +++ b/arch/ppc/lib/ppclinux.c
> @@ -100,6 +100,7 @@ error:
>  
>  static struct image_handler handler = {
>   .name = "PowerPC Linux",
> + .open = uimage_bootm_open,
>   .bootm = do_bootm_linux,
>   .filetype = filetype_uimage,
>   .ih_os = IH_OS_LINUX,
> diff --git a/common/bootm.c b/common/bootm.c
> index 81625d915..64c933b3c 100644
> --- a/common/bootm.c
> +++ b/common/bootm.c
> @@ -34,7 +34,7 @@ int register_image_handler(struct image_handler *handler)
>  }
>  
>  static struct image_handler *bootm_find_handler(enum filetype filetype,
> - struct image_data *data)
> + struct image_data *data, int enforce_os)
>  {
>   struct image_handler *handler;
>  
> @@ -42,9 +42,16 @@ static struct image_handler *bootm_find_handler(enum 
> filetype filetype,
>   if (filetype != filetype_uimage &&
>   handler->filetype == filetype)
>   return handler;
> - if  (filetype == filetype_uimage &&
> - handler->ih_os == data->os->header.ih_os)
> - return handler;
> + if (filetype == filetype_uimage) {
> + /*
> +  * we can take the first one as open is the same
> +  * not matter the OS
> +  */
> + if (enforce_os && handler->ih_os == 
> data->os->header.ih_os)
> + return handler;
> + else
> + return handler;
> + }
>   }
>  
>   return NULL;
> @@ -441,38 +448,6 @@ int bootm_get_os_size(struct image_data *data)
>   return -EINVAL;
>  }
>  
> -static int bootm_open_os_uimage(struct image_data *data)
> -{
> - int ret;
> -
> - data->os = uimage_open(data->os_file);
> - if (!data->os)
> - return -EINVAL;
> -
> - if (bootm_get_verify_mode() > BOOTM_VERIFY_NONE) {
> - ret = uimage_verify(data->os);
> - if (ret) {
> - printf("Checking data crc failed with %s\n",
> - strerror(-ret));
> - uimage_close(data->os);
> - return ret;
> - }
> - }
> -
> - uimage_print_contents(data->os);
> -
> - if (data->os->header.ih_arch != IH_ARCH) {
> 

[PATCH] efi: clocksoure: make sure the meassured frequency is valid

2017-03-14 Thread Michael Olbrich
Some EFI implementations have a even slower tick rate and the meassured
frequency may be zero.

Signed-off-by: Michael Olbrich <m.olbr...@pengutronix.de>
Acked-by: Jean-Christophe PLAGNIOL-VILLARD <plagn...@jcrosoft.com>
---
 drivers/clocksource/efi.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/drivers/clocksource/efi.c b/drivers/clocksource/efi.c
index 89906c452eb7..fb5b7ca63de9 100644
--- a/drivers/clocksource/efi.c
+++ b/drivers/clocksource/efi.c
@@ -71,6 +71,10 @@ static int efi_cs_init(struct clocksource *cs)
uint64_t nb_100ns;
 
freq = ticks_freq_x86();
+   if (freq == 0) {
+   BS->close_event(efi_cs_evt);
+   return -ENODEV;
+   }
nb_100ns = 10 * 1000 * 1000 / freq;
pr_warn("EFI Event timer too slow freq = %llu Hz\n", freq);
efiret = BS->set_timer(efi_cs_evt, EFI_TIMER_PERIODIC, 
nb_100ns);
-- 
2.11.0


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH] fixup! efi: clocksoure: add EFI event timer

2017-03-13 Thread Michael Olbrich
---

I played with the numbers a bit. This hardware has a 18 Hz tick :-/.
That's not really useful so just skipping the clocksource is probably the
best solution.

Michael

 drivers/clocksource/efi.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/drivers/clocksource/efi.c b/drivers/clocksource/efi.c
index 89906c452eb7..fb5b7ca63de9 100644
--- a/drivers/clocksource/efi.c
+++ b/drivers/clocksource/efi.c
@@ -71,6 +71,10 @@ static int efi_cs_init(struct clocksource *cs)
uint64_t nb_100ns;
 
freq = ticks_freq_x86();
+   if (freq == 0) {
+   BS->close_event(efi_cs_evt);
+   return -ENODEV;
+   }
nb_100ns = 10 * 1000 * 1000 / freq;
pr_warn("EFI Event timer too slow freq = %llu Hz\n", freq);
efiret = BS->set_timer(efi_cs_evt, EFI_TIMER_PERIODIC, 
nb_100ns);
-- 
2.11.0


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH 7/8] efi: clocksoure: use event for timer

2017-03-13 Thread Michael Olbrich
On Mon, Feb 27, 2017 at 11:19:29AM +0100, Jean-Christophe PLAGNIOL-VILLARD 
wrote:
> with this we can be hw generic
> 
> If the EFI implement timestamp protocol we could use instead of event
> but even EDK2 Never Ever compile it for any target.
> 
> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD 
> ---
>  common/efi/efi.c |   8 
>  drivers/clocksource/Kconfig  |   4 ++
>  drivers/clocksource/Makefile |   1 +
>  drivers/clocksource/efi.c| 110 
> +++
>  4 files changed, 123 insertions(+)
>  create mode 100644 drivers/clocksource/efi.c
> 
> diff --git a/common/efi/efi.c b/common/efi/efi.c
> index 4b589b600..05c58250f 100644
> --- a/common/efi/efi.c
> +++ b/common/efi/efi.c
> @@ -353,6 +353,14 @@ efi_status_t efi_main(efi_handle_t image, 
> efi_system_table_t *sys_table)
>   return EFI_SUCCESS;
>  }
>  
> +static int efi_core_init(void)
> +{
> + struct device_d *dev = device_alloc("efi-cs", DEVICE_ID_SINGLE);
> +
> + return platform_device_register(dev);
> +}
> +core_initcall(efi_core_init);
> +
>  static int efi_postcore_init(void)
>  {
>   char *uuid;
> diff --git a/drivers/clocksource/Kconfig b/drivers/clocksource/Kconfig
> index 9b7f0a9d7..b12a85403 100644
> --- a/drivers/clocksource/Kconfig
> +++ b/drivers/clocksource/Kconfig
> @@ -34,6 +34,10 @@ config CLOCKSOURCE_DUMMY_RATE
> The option CONFIG_CLOCKSOURCE_DUMMY_RATE is used to adjust this 
> clocksource.
> The bigger rate valuest makes clocksource "faster".
>  
> +config CLOCKSOURCE_EFI
> + bool "Generic EFI Driver"
> + depends on EFI_BOOTUP
> +
>  config CLOCKSOURCE_EFI_X86
>   bool "EFI X86 HW driver"
>   depends on EFI_BOOTUP && X86
> diff --git a/drivers/clocksource/Makefile b/drivers/clocksource/Makefile
> index 1fd18296e..f69b33d0b 100644
> --- a/drivers/clocksource/Makefile
> +++ b/drivers/clocksource/Makefile
> @@ -3,6 +3,7 @@ obj-$(CONFIG_ARM_SMP_TWD) += arm_smp_twd.o
>  obj-$(CONFIG_CLOCKSOURCE_BCM283X) += bcm2835.o
>  obj-$(CONFIG_CLOCKSOURCE_CLPS711X) += clps711x.o
>  obj-$(CONFIG_CLOCKSOURCE_DIGIC)   += digic.o
> +obj-$(CONFIG_CLOCKSOURCE_EFI) += efi.o
>  obj-$(CONFIG_CLOCKSOURCE_EFI_X86) += efi_x86.o
>  obj-$(CONFIG_CLOCKSOURCE_MVEBU)   += mvebu.o
>  obj-$(CONFIG_CLOCKSOURCE_NOMADIK) += nomadik.o
> diff --git a/drivers/clocksource/efi.c b/drivers/clocksource/efi.c
> new file mode 100644
> index 0..df65dd86c
> --- /dev/null
> +++ b/drivers/clocksource/efi.c
> @@ -0,0 +1,110 @@
> +/*
> + * Copyright (C) 2012 Jean-Christophe PLAGNIOL-VILLARD 
> + *
> + * Under GPL v2
> + */
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +static uint64_t ticks = 1;
> +static void *efi_cs_evt;
> +
> +static uint64_t efi_cs_read(void)
> +{
> + return ticks;
> +}
> +
> +static void efi_cs_inc(void *event, void *ctx)
> +{
> + ticks++;
> +}
> +
> +/* count ticks during a 1dms */
> +static uint64_t ticks_freq(void)
> +{
> + uint64_t ticks_start, ticks_end;
> +
> + ticks_start = ticks;
> + BS->stall(1000);
> + ticks_end = ticks;
> +
> + return (ticks_end - ticks_start) * 1000;
> +}
> +
> +/* count ticks during a 20ms delay as on qemu x86_64 the max is 100Hz */
> +static uint64_t ticks_freq_x86(void)
> +{
> + uint64_t ticks_start, ticks_end;
> +
> + ticks_start = ticks;
> + BS->stall(20 * 1000);
> + ticks_end = ticks;
> +
> + return (ticks_end - ticks_start) * 50;
> +}
> +
> +static int efi_cs_init(struct clocksource *cs)
> +{
> + efi_status_t efiret;
> + uint64_t freq;
> +
> + efiret = BS->create_event(EFI_EVT_TIMER | EFI_EVT_NOTIFY_SIGNAL,
> + EFI_TPL_CALLBACK, efi_cs_inc, NULL, _cs_evt);
> +
> + if (EFI_ERROR(efiret))
> + return -efi_errno(efiret);
> +
> + efiret = BS->set_timer(efi_cs_evt, EFI_TIMER_PERIODIC, 10);
> + if (EFI_ERROR(efiret)) {
> + BS->close_event(efi_cs_evt);
> + return -efi_errno(efiret);
> + }
> +
> + freq = 1000 * 1000;
> + if (ticks_freq() < 800 * 1000) {
> + uint64_t nb_100ns;
> +
> + freq = ticks_freq_x86();

This needs a sanity ckeck. On one hardware that I have here 'freq' is often
(but not always) zero.

Michael

> + nb_100ns = 10 * 1000 * 1000 / freq;
> + pr_warn("EFI Event timer too slow freq = %llu Hz\n", freq);
> + efiret = BS->set_timer(efi_cs_evt, EFI_TIMER_PERIODIC, 
> nb_100ns);
> + if (EFI_ERROR(efiret)) {
> + BS->close_event(efi_cs_evt);
> + return -efi_errno(efiret);
> + }
> + }
> +
> + cs->mult = clocksource_hz2mult(freq, cs->shift);
> +
> + return 0;
> +}
> +
> +static struct clocksource efi_cs = {
> + .read   = efi_cs_read,
> + .mask   = CLOCKSOURCE_MASK(64),
> + .shift  = 0,
> + .init   = efi_cs_init,
> +};
> +
> 

Re: [PATCH 0/12] EFI: drop arch efi

2017-03-13 Thread Michael Olbrich
On Sun, Mar 12, 2017 at 01:05:38PM +0100, Jean-Christophe PLAGNIOL-VILLARD 
wrote:
> On 17:26 Sat 11 Mar , Michael Olbrich wrote:
> > On Wed, Feb 15, 2017 at 08:29:32PM +0100, Jean-Christophe PLAGNIOL-VILLARD 
> > wrote:
> > > Today the EFI is build as an other ARCH when in fact it's just a boot mode
> > > 
> > > so move it back to arch/x86 for the spicific x86 part and the common
> > > to common and driver
> > > 
> > > The last 3 patches allow to debug EFI and prepare for more efi support
> > > 
> > > The following changes since commit 
> > > b225bbf295c92263adbcec2c385c5e8d83542c72:
> > > 
> > >   i.MX: esdhc: fix imx-esdhc driver for non-OF boards (2017-02-14 
> > > 08:48:34 +0100)
> > > 
> > > are available in the git repository at:
> > > 
> > >   git://git.jcrosoft.org/barebox.git
> > > 
> > > for you to fetch changes up to df12536f83b485c9a4ee28f78637356c6abab6f6:
> > > 
> > >   efi: add efi handle dump command (2017-02-15 07:32:24 +0800)
> > 
> > While testing the serial stuff I noticed that the
> > CONFIG_ARCH_EFI_REGISTER_COM1 option got lost during this rework.
> I did not merge it as it's a hack more than a feature as this by pass the EFI
> API and access the hw directly instead of using Serial IO
> 
> Which was add after
> 
> And I plan to drop this hack

You cannot assume a sane EFI. I have a hardware with a serial port that
works just fine with the ns16550 driver but the EFI does not implement the
serial IO protocol. So this hack is still needed in some way.

Maybe we could register the ns16550 console if no efi serial IO protocol is
found?

Michael

-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |

___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH 0/2] efivarfs: rework the filesystem to make it human readable

2017-03-13 Thread Michael Olbrich
Hi,

On Mon, Mar 13, 2017 at 08:24:42AM +0100, Sascha Hauer wrote:
> On Thu, Mar 09, 2017 at 03:38:40PM +0100, Jean-Christophe PLAGNIOL-VILLARD 
> wrote:
> > Sascha is this one ok?
> 
> I asked Michael to have a look at this series, so far he didn't find
> time.

I'm not sure I like it this way. The old way matches what the Linux kernel
does so it's familiar. And the mix of guids and 'names' is rather
cluttered because they are not grouped separately.
Maybe keep the old version and add something like the by-name etc. symlinks
used in udev:

-bar

  EFI
[...]
  foo
bar -> ../../-bar


Michael

-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |

___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH 0/12] EFI: drop arch efi

2017-03-11 Thread Michael Olbrich
On Wed, Feb 15, 2017 at 08:29:32PM +0100, Jean-Christophe PLAGNIOL-VILLARD 
wrote:
> Today the EFI is build as an other ARCH when in fact it's just a boot mode
> 
> so move it back to arch/x86 for the spicific x86 part and the common
> to common and driver
> 
> The last 3 patches allow to debug EFI and prepare for more efi support
> 
> The following changes since commit b225bbf295c92263adbcec2c385c5e8d83542c72:
> 
>   i.MX: esdhc: fix imx-esdhc driver for non-OF boards (2017-02-14 08:48:34 
> +0100)
> 
> are available in the git repository at:
> 
>   git://git.jcrosoft.org/barebox.git
> 
> for you to fetch changes up to df12536f83b485c9a4ee28f78637356c6abab6f6:
> 
>   efi: add efi handle dump command (2017-02-15 07:32:24 +0800)

While testing the serial stuff I noticed that the
CONFIG_ARCH_EFI_REGISTER_COM1 option got lost during this rework.

Michael

-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |

___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH 2/2 v2] efi: add serial driver support

2017-03-11 Thread Michael Olbrich
On Mon, Mar 06, 2017 at 10:34:47AM +0100, Jean-Christophe PLAGNIOL-VILLARD 
wrote:
> So now we can stop to use the efi-stdio as this driver
> print on the Framebuffer and the serial at the same time.
> 
> This is specially usefull if we want to use the framebuffer via efi-gop for
> something else.
> 
> Do not forget to disable the efi-stdio device before enabling the console
> otherwise you will get double printing.

Works nicely here (with a unrelated fix). However, it might be better to
implement this as a console_platform_driver. The efi drivers are loaded
rather late during startup and this makes early debugging impossible.

Michael

> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD 
> ---
> Fix copyright
> 
>  drivers/serial/Kconfig  |   4 +
>  drivers/serial/Makefile |   1 +
>  drivers/serial/serial_efi.c | 221 
> 
>  3 files changed, 226 insertions(+)
>  create mode 100644 drivers/serial/serial_efi.c
> 
> diff --git a/drivers/serial/Kconfig b/drivers/serial/Kconfig
> index ced30530a..cfddc2ee9 100644
> --- a/drivers/serial/Kconfig
> +++ b/drivers/serial/Kconfig
> @@ -21,6 +21,10 @@ config DRIVER_SERIAL_AR933X
> If you have an Atheros AR933X SOC based board and want to use the
> built-in UART of the SoC, say Y to this option.
>  
> +config DRIVER_SERIAL_EFI
> + bool "EFI serial"
> + depends on EFI_BOOTUP
> +
>  config DRIVER_SERIAL_IMX
>   depends on ARCH_IMX
>   default y
> diff --git a/drivers/serial/Makefile b/drivers/serial/Makefile
> index 7d1bae195..3d9f735ed 100644
> --- a/drivers/serial/Makefile
> +++ b/drivers/serial/Makefile
> @@ -1,6 +1,7 @@
>  obj-$(CONFIG_DRIVER_SERIAL_ARM_DCC)  += arm_dcc.o
>  obj-$(CONFIG_SERIAL_AMBA_PL011)  += amba-pl011.o
>  obj-$(CONFIG_DRIVER_SERIAL_AR933X)   += serial_ar933x.o
> +obj-$(CONFIG_DRIVER_SERIAL_EFI)  += serial_efi.o
>  obj-$(CONFIG_DRIVER_SERIAL_IMX)  += serial_imx.o
>  obj-$(CONFIG_DRIVER_SERIAL_STM378X)  += stm-serial.o
>  obj-$(CONFIG_DRIVER_SERIAL_ATMEL)+= atmel.o
> diff --git a/drivers/serial/serial_efi.c b/drivers/serial/serial_efi.c
> new file mode 100644
> index 0..f0a2b22c2
> --- /dev/null
> +++ b/drivers/serial/serial_efi.c
> @@ -0,0 +1,221 @@
> +/*
> + * Copyright (C) 2017 Jean-Christophe PLAGNIOL-VILLARD 
> 
> + *
> + * Under GPLv2 Only
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +/*
> + * define for Control bits, grouped by read only, write only, and read write
> + *
> + * Read Only
> + */
> +#define EFI_SERIAL_CLEAR_TO_SEND0x0010
> +#define EFI_SERIAL_DATA_SET_READY   0x0020
> +#define EFI_SERIAL_RING_INDICATE0x0040
> +#define EFI_SERIAL_CARRIER_DETECT   0x0080
> +#define EFI_SERIAL_INPUT_BUFFER_EMPTY   0x0100
> +#define EFI_SERIAL_OUTPUT_BUFFER_EMPTY  0x0200
> +
> +/*
> + * Write Only
> + */
> +#define EFI_SERIAL_REQUEST_TO_SEND  0x0002
> +#define EFI_SERIAL_DATA_TERMINAL_READY  0x0001
> +
> +/*
> + * Read Write
> + */
> +#define EFI_SERIAL_HARDWARE_LOOPBACK_ENABLE 0x1000
> +#define EFI_SERIAL_SOFTWARE_LOOPBACK_ENABLE 0x2000
> +#define EFI_SERIAL_HARDWARE_FLOW_CONTROL_ENABLE 0x4000
> +
> +typedef enum {
> + DefaultParity,
> + NoParity,
> + EvenParity,
> + OddParity,
> + MarkParity,
> + SpaceParity
> +} efi_parity_type;
> +
> +typedef enum {
> + DefaultStopBits,
> + OneStopBit,
> + OneFiveStopBits,
> + TwoStopBits
> +} efi_stop_bits_type;
> +
> +struct efi_serial_io_mode {
> + uint32_t controlmask;
> + uint32_t timeout;
> + uint64_t baudrate;
> + uint32_t receivefifodepth;
> + uint32_t databits;
> + uint32_t parity;
> + uint32_t stopbits;
> +};
> +
> +struct efi_serial_io_protocol {
> + uint32_t revision;
> +
> + efi_status_t (EFIAPI *reset) (struct efi_serial_io_protocol *This);
> + efi_status_t (EFIAPI *set_attributes) (struct efi_serial_io_protocol 
> *This,
> + uint64_t baudrate, uint32_t receivefifodepth,
> + uint32_t timeout, efi_parity_type parity,
> + uint8_t databits, efi_stop_bits_type stopbits);
> + efi_status_t (EFIAPI *setcontrol) (struct efi_serial_io_protocol *This,
> + uint32_t control);
> + efi_status_t (EFIAPI *getcontrol) (struct efi_serial_io_protocol *This,
> + uint32_t *control);
> + efi_status_t (EFIAPI *write) (struct efi_serial_io_protocol *This,
> + unsigned long *buffersize, void *buffer);
> + efi_status_t (EFIAPI *read) (struct efi_serial_io_protocol *This,
> + unsigned long *buffersize, void *buffer);
> +
> + struct efi_serial_io_mode *mode;
> +};
> +
> +/*
> + * We wrap our port structure around the 

[PATCH 2/2] efi: only iterate over handles that provide the device path protocol

2017-03-11 Thread Michael Olbrich
All other handled are skipped anyways.

Signed-off-by: Michael Olbrich <m.olbr...@pengutronix.de>
---
 drivers/efi/efi-device.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/efi/efi-device.c b/drivers/efi/efi-device.c
index c5fb404cd36b..db3c0afe3361 100644
--- a/drivers/efi/efi-device.c
+++ b/drivers/efi/efi-device.c
@@ -102,7 +102,8 @@ static efi_handle_t *efi_find_parent(efi_handle_t *handle)
struct efi_open_protocol_information_entry *entry_buffer;
unsigned long entry_count;
 
-   ret = efi_locate_handle(all_handles, NULL, NULL, _count, 
);
+   ret = efi_locate_handle(by_protocol, _device_path_protocol_guid,
+   NULL, _count, );
if (ret)
return NULL;
 
@@ -244,7 +245,8 @@ void efi_register_devices(void)
struct efi_device **efidevs;
int registered;
 
-   ret = efi_locate_handle(all_handles, NULL, NULL, _count, 
);
+   ret = efi_locate_handle(by_protocol, _device_path_protocol_guid,
+   NULL, _count, );
if (ret)
return;
 
-- 
2.11.0


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 1/2] efi: load the protocol expected by the driver

2017-03-11 Thread Michael Olbrich
The drivers are loaded if any guid provided by the device matches. So load
the protocol for the matched guid and not for the first guid.
Otherwise the driver may cast the protocol to the wrong type and proably
crash.

Signed-off-by: Michael Olbrich <m.olbr...@pengutronix.de>
---
 drivers/efi/efi-device.c | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/efi/efi-device.c b/drivers/efi/efi-device.c
index 959878e7f5cf..c5fb404cd36b 100644
--- a/drivers/efi/efi-device.c
+++ b/drivers/efi/efi-device.c
@@ -184,8 +184,6 @@ static struct efi_device *efi_add_device(efi_handle_t 
*handle, efi_guid_t **guid
efidev->dev.info = efi_devinfo;
efidev->devpath = devpath;
 
-   BS->handle_protocol(handle, [0], >protocol);
-
sprintf(efidev->dev.name, "handle-%p", handle);
 
efidev->parent_handle = efi_find_parent(efidev->handle);
@@ -311,8 +309,11 @@ static int efi_bus_match(struct device_d *dev, struct 
driver_d *drv)
int i;
 
for (i = 0; i < efidev->num_guids; i++) {
-   if (!memcmp(>guid, >guids[i], 
sizeof(efi_guid_t)))
+   if (!memcmp(>guid, >guids[i], 
sizeof(efi_guid_t))) {
+   BS->handle_protocol(efidev->handle, >guids[i],
+   >protocol);
return 0;
+   }
}
 
return 1;
-- 
2.11.0


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH 1/2] video: add EFI Graphics Output Protocol support

2017-03-09 Thread Michael Olbrich
On Mon, Mar 06, 2017 at 06:04:10AM +0100, Jean-Christophe PLAGNIOL-VILLARD 
wrote:
> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD 
> ---
>  drivers/video/Kconfig   |   4 +
>  drivers/video/Makefile  |   2 +
>  drivers/video/efi_gop.c | 267 
> 
>  3 files changed, 273 insertions(+)
>  create mode 100644 drivers/video/efi_gop.c
> 
[...]
> diff --git a/drivers/video/efi_gop.c b/drivers/video/efi_gop.c
> new file mode 100644
> index 0..ccb4af3d9
[...]
> +static struct fb_ops efi_gop_ops = {
> + .fb_activate_var = efi_gop_fb_activate_var,
> +};

This is missing the fb_enable/fb_disable callbacks. Both are not optional.
The framebuffer console is broken without this.

Michael


-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |

___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH] fixup! efi: move x86 efi boot support to x86 arch

2017-03-07 Thread Michael Olbrich
As I noted in my other mail, this got lost during the move.

Regards,
Michael

---
 arch/x86/Makefile  | 4 ++--
 arch/x86/mach-efi/elf_x86_64_efi.lds.S | 1 +
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/arch/x86/Makefile b/arch/x86/Makefile
index e837a2df972c..c36104c2c07f 100644
--- a/arch/x86/Makefile
+++ b/arch/x86/Makefile
@@ -84,8 +84,8 @@ cmd_barebox__ ?= $(LD) $(LDFLAGS) $(LDFLAGS_barebox) -o $@
\
 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_cmd -j .barebox_magicvar -j .bbenv.* \
- --target=$(TARGET) $< $@
+ -j __barebox_exitcalls -j __barebox_cmd -j 
.barebox_magicvar \
+ -j .bbenv.* --target=$(TARGET) $< $@
 
 KBUILD_BINARY := barebox
 
diff --git a/arch/x86/mach-efi/elf_x86_64_efi.lds.S 
b/arch/x86/mach-efi/elf_x86_64_efi.lds.S
index e1bc2120fabc..93d34d17ab1f 100644
--- a/arch/x86/mach-efi/elf_x86_64_efi.lds.S
+++ b/arch/x86/mach-efi/elf_x86_64_efi.lds.S
@@ -80,6 +80,7 @@ SECTIONS
*(.rela.data*)
*(.rela.barebox*)
*(.rela.initcall*)
+   *(.rela.exitcall*)
*(.rela.got)
*(.rela.stab)
}
-- 
2.11.0


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH 0/12] EFI: drop arch efi

2017-02-15 Thread Michael Olbrich
Hi,

On Thu, Feb 16, 2017 at 08:38:11AM +0100, Michael Olbrich wrote:
> On Wed, Feb 15, 2017 at 08:29:32PM +0100, Jean-Christophe PLAGNIOL-VILLARD 
> wrote:
> > Today the EFI is build as an other ARCH when in fact it's just a boot mode
> > 
> > so move it back to arch/x86 for the spicific x86 part and the common
> > to common and driver
> > 
> > The last 3 patches allow to debug EFI and prepare for more efi support
> > 
> > The following changes since commit b225bbf295c92263adbcec2c385c5e8d83542c72:
> > 
> >   i.MX: esdhc: fix imx-esdhc driver for non-OF boards (2017-02-14 08:48:34 
> > +0100)
> 
> I've commented on one patch where stuff got lost. I think that was all.
> "efi-image.c" was moved so git could handle that correctly.
> 
> With that fixed, barebox seemed to work as expected in a short test.

Oh, and I've only tested patches 1-9. I've not seen 10-12 so far.

Michael

-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |

___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH 0/12] EFI: drop arch efi

2017-02-15 Thread Michael Olbrich
Hi,

On Wed, Feb 15, 2017 at 08:29:32PM +0100, Jean-Christophe PLAGNIOL-VILLARD 
wrote:
> Today the EFI is build as an other ARCH when in fact it's just a boot mode
> 
> so move it back to arch/x86 for the spicific x86 part and the common
> to common and driver
> 
> The last 3 patches allow to debug EFI and prepare for more efi support
> 
> The following changes since commit b225bbf295c92263adbcec2c385c5e8d83542c72:
> 
>   i.MX: esdhc: fix imx-esdhc driver for non-OF boards (2017-02-14 08:48:34 
> +0100)

I've commented on one patch where stuff got lost. I think that was all.
"efi-image.c" was moved so git could handle that correctly.

With that fixed, barebox seemed to work as expected in a short test.

Regards,
Michael

> 
> are available in the git repository at:
> 
>   git://git.jcrosoft.org/barebox.git
> 
> for you to fetch changes up to df12536f83b485c9a4ee28f78637356c6abab6f6:
> 
>   efi: add efi handle dump command (2017-02-15 07:32:24 +0800)
> 
> 
> Jean-Christophe PLAGNIOL-VILLARD (12):
>   efi: move block io driver to driver/block
>   efi: move clocksource out of arch
>   efi: move bus driver to driver/efi
>   efi: move debug_ll.h to include/efi
>   efi: move startup and payload to common/efi
>   x86: move bios bootup code to arch/x86/bios
>   efi: move x86 efi boot support to x86 arch
>   ARCH: efi: Finally drop it as now we can build efi bootup from x86
>   efi: bus: add firmware vendor and resision and tables info
>   efi: add minor and major to the bus and display it at boot
>   efi-gui: add Timestamp Protocol GUID definition
>   efi: add efi handle dump command
> 
>  Documentation/boards/efi.rst|   2 +-
>  arch/efi/Kconfig|  51 
> ---
>  arch/efi/Makefile   |  43 
> ---
>  arch/efi/efi/Makefile   |   2 --
>  arch/efi/include/asm/barebox.h  |   1 -
>  arch/efi/include/asm/bitops.h   |  22 
> --
>  arch/efi/include/asm/bitsperlong.h  |  10 --
>  arch/efi/include/asm/byteorder.h|   8 
>  arch/efi/include/asm/common.h   |   4 
>  arch/efi/include/asm/dma.h  |  13 -
>  arch/efi/include/asm/elf.h  |  60 
> 
>  arch/efi/include/asm/io.h   |  55 
> ---
>  arch/efi/include/asm/posix_types.h  |   1 -
>  arch/efi/include/asm/sections.h |   1 -
>  arch/efi/include/asm/string.h   |   1 -
>  arch/efi/include/asm/swab.h |   6 --
>  arch/efi/include/asm/types.h|  65 
> -
>  arch/efi/include/asm/unaligned.h|  19 
> ---
>  arch/efi/lib/asm-offsets.c  |  12 
>  arch/x86/Kconfig|  53 
> ++---
>  arch/x86/Makefile   |  75 
> ---
>  arch/x86/bios/Makefile  |   3 +++
>  arch/x86/{lib => bios}/bios_disk.S  |   0
>  arch/x86/{lib => bios}/memory16.S   |   0
>  arch/x86/{lib => bios}/traveler.S   |   0
>  arch/{efi => x86}/configs/efi_defconfig |   2 +-
>  arch/x86/configs/generic_defconfig  |   1 +
>  arch/x86/include/asm/elf.h  |  74 
> ++
>  arch/x86/include/asm/io.h   |  71 
> +--
>  arch/x86/include/asm/types.h|  51 
> +--
>  arch/x86/include/asm/unaligned.h|   5 +
>  arch/x86/lib/Makefile   |   5 ++---
>  arch/x86/lib/asm-offsets.c  |   7 +++
>  arch/{efi/lib => x86/mach-efi}/.gitignore   |   0
>  arch/{efi/lib => x86/mach-efi}/Makefile |   0
>  arch/{efi/lib => x86/mach-efi}/crt0-efi-ia32.S  |   0
>  arch/{efi/lib => x86/mach-efi}/crt0-efi-x86_64.S|   0
>  arch/{efi/lib => x86/mach-efi}/elf_ia32_efi.lds.S   |   0
>  arch/{efi/lib => 

Re: [PATCH 07/12] efi: move x86 efi boot support to x86 arch

2017-02-15 Thread Michael Olbrich
On Wed, Feb 15, 2017 at 08:34:15PM +0100, Jean-Christophe PLAGNIOL-VILLARD 
wrote:
> prepare to drop the efi arch as efi boot up is not arch sepecific
> 
> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD 
> ---
>  Documentation/boards/efi.rst |   2 +-
>  arch/x86/Kconfig |  53 --
>  arch/x86/Makefile|  74 +--
>  arch/x86/configs/efi_defconfig   |  78 
>  arch/x86/configs/generic_defconfig   |   1 +
>  arch/x86/include/asm/elf.h   |  86 +++---
>  arch/x86/include/asm/io.h|  71 +-
>  arch/x86/include/asm/types.h |  51 -
>  arch/x86/include/asm/unaligned.h |   5 ++
>  arch/x86/lib/Makefile|   2 +
>  arch/x86/lib/asm-offsets.c   |   7 ++
>  arch/x86/mach-efi/.gitignore |   2 +
>  arch/x86/mach-efi/Makefile   |   4 +
>  arch/x86/mach-efi/crt0-efi-ia32.S|  76 +++
>  arch/x86/mach-efi/crt0-efi-x86_64.S  |  75 +++
>  arch/x86/mach-efi/elf_ia32_efi.lds.S | 106 
> +++
>  arch/x86/mach-efi/elf_x86_64_efi.lds.S   |  99 +
>  arch/x86/mach-efi/include/mach/barebox.lds.h |   0

I think this should be done instead of adding an empty file:

diff --git a/include/asm-generic/barebox.lds.h 
b/include/asm-generic/barebox.lds.h
index c8a919b928c9..dd2d286d32ec 100644
--- a/include/asm-generic/barebox.lds.h
+++ b/include/asm-generic/barebox.lds.h
@@ -6,7 +6,7 @@
 #define STRUCT_ALIGNMENT 32
 #define STRUCT_ALIGN() . = ALIGN(STRUCT_ALIGNMENT)
 
-#if defined CONFIG_X86 || \
+#if defined CONFIG_X86_32 || \
defined CONFIG_ARCH_EP93XX || \
defined CONFIG_ARCH_ZYNQ
 #include 

>  arch/x86/mach-efi/include/mach/debug_ll.h|   1 +
>  arch/x86/mach-efi/reloc_ia32.c   |  97 
>  arch/x86/mach-efi/reloc_x86_64.c |  96 
>  commands/Kconfig |   2 +-
>  commands/edit.c  |   2 +-
>  common/memory.c  |   2 +-
>  drivers/clocksource/Kconfig  |   2 +-
>  drivers/net/Kconfig  |   2 +-
>  drivers/of/Kconfig   |   2 +-
>  drivers/serial/Kconfig   |   2 +-
>  fs/Kconfig   |   4 +-
>  include/efi.h|   2 +-
>  30 files changed, 899 insertions(+), 107 deletions(-)
>  create mode 100644 arch/x86/configs/efi_defconfig
>  rewrite arch/x86/include/asm/elf.h (97%)
>  create mode 100644 arch/x86/mach-efi/.gitignore
>  create mode 100644 arch/x86/mach-efi/Makefile
>  create mode 100644 arch/x86/mach-efi/crt0-efi-ia32.S
>  create mode 100644 arch/x86/mach-efi/crt0-efi-x86_64.S
>  create mode 100644 arch/x86/mach-efi/elf_ia32_efi.lds.S
>  create mode 100644 arch/x86/mach-efi/elf_x86_64_efi.lds.S
>  create mode 100644 arch/x86/mach-efi/include/mach/barebox.lds.h
>  create mode 100644 arch/x86/mach-efi/include/mach/debug_ll.h
>  create mode 100644 arch/x86/mach-efi/reloc_ia32.c
>  create mode 100644 arch/x86/mach-efi/reloc_x86_64.c
> 
> diff --git a/Documentation/boards/efi.rst b/Documentation/boards/efi.rst
> index b7ad40e47..ecadb3ebb 100644
> --- a/Documentation/boards/efi.rst
> +++ b/Documentation/boards/efi.rst
> @@ -25,7 +25,7 @@ Use the following to build barebox for EFI:
>  
>  .. code-block:: sh
>  
> -  export ARCH=efi
> +  export ARCH=x86
>make efi_defconfig
>make
>  
> diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
> index 346640dcd..9803f3f95 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 0x7c00 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 

[PATCH 4/5] efi: include and execute exit calls

2017-01-23 Thread Michael Olbrich
Signed-off-by: Michael Olbrich <m.olbr...@pengutronix.de>
---
 arch/efi/Makefile | 4 ++--
 arch/efi/efi/efi-image.c  | 2 ++
 arch/efi/lib/elf_x86_64_efi.lds.S | 1 +
 3 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/arch/efi/Makefile b/arch/efi/Makefile
index b078bd0e356d..32a1c152b791 100644
--- a/arch/efi/Makefile
+++ b/arch/efi/Makefile
@@ -28,8 +28,8 @@ cmd_barebox__ ?= $(LD) $(LDFLAGS) $(LDFLAGS_barebox) -o $@
\
 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_cmd -j .barebox_magicvar -j .bbenv.* \
- --target=$(TARGET) $< $@
+ -j __barebox_exitcalls -j __barebox_cmd -j 
.barebox_magicvar \
+ -j .bbenv.* --target=$(TARGET) $< $@
 
 KBUILD_BINARY := barebox
 
diff --git a/arch/efi/efi/efi-image.c b/arch/efi/efi/efi-image.c
index 32e060886a33..c780cad6d447 100644
--- a/arch/efi/efi/efi-image.c
+++ b/arch/efi/efi/efi-image.c
@@ -145,6 +145,7 @@ static int efi_execute_image(const char *file)
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);
@@ -255,6 +256,7 @@ static int do_bootm_efi(struct image_data *data)
efi_set_variable_usec("LoaderTimeExecUSec", _systemd_vendor_guid,
  get_time_ns()/1000);
 
+   shutdown_barebox();
linux_efi_handover(handle, boot_header);
 
return 0;
diff --git a/arch/efi/lib/elf_x86_64_efi.lds.S 
b/arch/efi/lib/elf_x86_64_efi.lds.S
index e1bc2120fabc..93d34d17ab1f 100644
--- a/arch/efi/lib/elf_x86_64_efi.lds.S
+++ b/arch/efi/lib/elf_x86_64_efi.lds.S
@@ -80,6 +80,7 @@ SECTIONS
*(.rela.data*)
*(.rela.barebox*)
*(.rela.initcall*)
+   *(.rela.exitcall*)
*(.rela.got)
*(.rela.stab)
}
-- 
2.11.0


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 3/5] output: use '[0m' to reset colors

2017-01-23 Thread Michael Olbrich
'[m' is supposed to have the same effect as '[0m'. However, some EFI
implementations seem to ignore '[m', so use '[0m' everywhere to avoid
rendering issues.

Signed-off-by: Michael Olbrich <m.olbr...@pengutronix.de>
---
 commands/2048.c   | 2 +-
 common/menu.c | 2 +-
 include/readkey.h | 4 ++--
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/commands/2048.c b/commands/2048.c
index 5ceb5cfb7d12..865803a5a616 100644
--- a/commands/2048.c
+++ b/commands/2048.c
@@ -53,7 +53,7 @@ static void getColor(uint16_t value, char *color, size_t 
length)
 static void drawBoard(uint16_t board[SIZE][SIZE])
 {
int8_t x,y;
-   char color[40], reset[] = "\033[m";
+   char color[40], reset[] = "\033[0m";
printf("\033[H");
 
printf("2048.c %17d pts\n\n",score);
diff --git a/common/menu.c b/common/menu.c
index e757216c5adf..31e5c90a0f27 100644
--- a/common/menu.c
+++ b/common/menu.c
@@ -185,7 +185,7 @@ static void print_menu_entry(struct menu *m, struct 
menu_entry *me,
__print_entry(me->display);
 
if (selected)
-   puts("\e[m");
+   puts("\e[0m");
 }
 
 int menu_set_selected_entry(struct menu *m, struct menu_entry* me)
diff --git a/include/readkey.h b/include/readkey.h
index 8398ec2e516e..ed1cd1542d6f 100644
--- a/include/readkey.h
+++ b/include/readkey.h
@@ -26,8 +26,8 @@
 
 #define ANSI_CLEAR_SCREEN "\e[2J\e[;H"
 
-#define printf_reverse(fmt,args...)printf("\e[7m" fmt "\e[m",##args)
-#define puts_reverse(fmt)  puts("\e[7m" fmt "\e[m")
+#define printf_reverse(fmt,args...)printf("\e[7m" fmt "\e[0m",##args)
+#define puts_reverse(fmt)  puts("\e[7m" fmt "\e[0m")
 #define gotoXY(row, col)   printf("\e[%d;%dH", col, row)
 #define clear()puts("\e[2J")
 
-- 
2.11.0


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 2/5] serial: efi: improve input handling

2017-01-23 Thread Michael Olbrich
0x08 is the scan-code for 'backspace' not 'delete'.
0x17 indicates the start of an escape sequence, such as "[3~" for
'delete'.

Signed-off-by: Michael Olbrich <m.olbr...@pengutronix.de>
---
 drivers/serial/efi-stdio.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/serial/efi-stdio.c b/drivers/serial/efi-stdio.c
index bf14c5e24aa5..5ab917386e60 100644
--- a/drivers/serial/efi-stdio.c
+++ b/drivers/serial/efi-stdio.c
@@ -99,9 +99,10 @@ static struct efi_ctrlkey ctrlkeys[] = {
{ 0x05, BB_KEY_HOME },
{ 0x06, BB_KEY_END },
{ 0x07, BB_KEY_INSERT },
-   { 0x08, BB_KEY_DEL },
+   { 0x08, BB_KEY_DEL7 },
{ 0x09, BB_KEY_PAGEUP },
{ 0x0a, BB_KEY_PAGEDOWN },
+   { 0x17, 27 /* escape key */ },
 };
 
 static int efi_read_key(struct efi_console_priv *priv, bool wait)
-- 
2.11.0


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 0/5] EFI fixes

2017-01-23 Thread Michael Olbrich
A few small fixes to improve the barebox experience on EFI. Not all are
strictly EFI specific, but that's where I came across the problems.

Regards,
Michael

Michael Olbrich (5):
  readkey: keys are unsigned char
  serial: efi: improve input handling
  output: use '[0m' to reset colors
  efi: include and execute exit calls
  efi: don't unload drivers

 arch/efi/Makefile | 4 ++--
 arch/efi/efi/efi-image.c  | 9 -
 arch/efi/lib/elf_x86_64_efi.lds.S | 1 +
 commands/2048.c   | 2 +-
 common/menu.c | 2 +-
 drivers/serial/efi-stdio.c| 3 ++-
 include/readkey.h | 4 ++--
 lib/readkey.c | 4 ++--
 8 files changed, 19 insertions(+), 10 deletions(-)

-- 
2.11.0


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH v2 3/3] state: fix finding the correct parent node

2016-09-16 Thread Michael Olbrich
Looking for the parent node during fixup is broken. The path of the parent
node is not correctly terminated ('0' vs '\0'). Also, the new state node
should be added to the supplied device tree not the barebox device tree
used by of_find_node_by_path().

Signed-off-by: Michael Olbrich <m.olbr...@pengutronix.de>
---
 common/state/state.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/common/state/state.c b/common/state/state.c
index 0c329cd67548..075618e5bb8f 100644
--- a/common/state/state.c
+++ b/common/state/state.c
@@ -307,8 +307,8 @@ static int of_state_fixup(struct device_node *root, void 
*ctx)
c = strrchr(of_path, '/');
if (!c)
return -ENODEV;
-   *c = '0';
-   parent = of_find_node_by_path(of_path);
+   *c = '\0';
+   parent = of_find_node_by_path_from(root, of_path);
if (!parent)
parent = root;
 
-- 
2.8.1


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH v2 2/3] state: don't keep pointers to device tree nodes

2016-09-16 Thread Michael Olbrich
Caching pointers to device tree nodes or is not save. The barebox internal
device tree may be changed by loading a new device tree or through fixup
handlers. As a result, the node may be deleted and replaced with a new one.
Keep a copy of the full path instead and resolve the node as needed.

Signed-off-by: Michael Olbrich <m.olbr...@pengutronix.de>
---
Changes since v1:
- First patch split into two patches

 common/state/state.c | 19 ---
 common/state/state.h |  2 +-
 2 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/common/state/state.c b/common/state/state.c
index 9b1d4edef132..0c329cd67548 100644
--- a/common/state/state.c
+++ b/common/state/state.c
@@ -202,15 +202,19 @@ struct device_node *state_to_node(struct state *state,
  enum state_convert conv)
 {
struct device_node *child;
-   struct device_node *root;
+   struct device_node *root, *state_root;
int ret;
 
-   root = of_new_node(parent, state->root->name);
+   state_root = of_find_node_by_path(state->of_path);
+   if (!state_root)
+   return ERR_PTR(-ENODEV);
+
+   root = of_new_node(parent, state_root->name);
ret = of_property_write_u32(root, "magic", state->magic);
if (ret)
goto out;
 
-   for_each_child_of_node(state->root, child) {
+   for_each_child_of_node(state_root, child) {
ret = state_convert_node_variable(state, child, root, "", conv);
if (ret)
goto out;
@@ -234,7 +238,7 @@ int state_from_node(struct state *state, struct device_node 
*node, bool create)
 
if (create) {
conv = STATE_CONVERT_FROM_NODE_CREATE;
-   state->root = node;
+   state->of_path = xstrdup(node->full_name);
state->magic = magic;
} else {
conv = STATE_CONVERT_FROM_NODE;
@@ -291,7 +295,7 @@ static int of_state_fixup(struct device_node *root, void 
*ctx)
int ret;
phandle phandle;
 
-   node = of_find_node_by_path_from(root, state->root->full_name);
+   node = of_find_node_by_path_from(root, state->of_path);
if (node) {
/* replace existing node - it will be deleted later */
parent = node->parent;
@@ -299,7 +303,7 @@ static int of_state_fixup(struct device_node *root, void 
*ctx)
char *of_path, *c;
 
/* look for parent, remove last '/' from path */
-   of_path = xstrdup(state->root->full_name);
+   of_path = xstrdup(state->of_path);
c = strrchr(of_path, '/');
if (!c)
return -ENODEV;
@@ -406,6 +410,7 @@ void state_release(struct state *state)
list_del(>list);
unregister_device(>dev);
state_backend_free(>backend);
+   free(state->of_path);
free(state);
 }
 
@@ -545,7 +550,7 @@ struct state *state_by_node(const struct device_node *node)
struct state *state;
 
list_for_each_entry(state, _list, list) {
-   if (state->root == node)
+   if (!strcmp(state->of_path, node->full_name))
return state;
}
 
diff --git a/common/state/state.h b/common/state/state.h
index f930d06195b2..7b3e49512e37 100644
--- a/common/state/state.h
+++ b/common/state/state.h
@@ -94,7 +94,7 @@ struct state {
struct list_head list; /* Entry to enqueue on list of states */
 
struct device_d dev;
-   struct device_node *root;
+   char *of_path;
const char *name;
uint32_t magic;
 
-- 
2.8.1


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH v2 1/3] state: copy backend of_path string

2016-09-16 Thread Michael Olbrich
Caching pointers to device tree nodes or names is not save. The barebox
internal device tree may be changed by loading a new device tree or through
fixup handlers. As a result, the string may be deleted.
Use local copies of the full path instead.

Signed-off-by: Michael Olbrich <m.olbr...@pengutronix.de>
---
Changes since v1:
- First patch split into two patches

 common/state/backend.c | 3 ++-
 common/state/state.h   | 2 +-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/common/state/backend.c b/common/state/backend.c
index 2f2e6dfd32d1..5235bb0283dd 100644
--- a/common/state/backend.c
+++ b/common/state/backend.c
@@ -164,7 +164,7 @@ int state_backend_init(struct state_backend *backend, 
struct device_d *dev,
if (ret)
goto out_free_format;
 
-   backend->of_path = of_path;
+   backend->of_path = xstrdup(of_path);
 
return 0;
 
@@ -185,4 +185,5 @@ void state_backend_free(struct state_backend *backend)
state_storage_free(>storage);
if (backend->format)
state_format_free(backend->format);
+   free(backend->of_path);
 }
diff --git a/common/state/state.h b/common/state/state.h
index 32146ca1bbc7..f930d06195b2 100644
--- a/common/state/state.h
+++ b/common/state/state.h
@@ -87,7 +87,7 @@ struct state_backend_storage {
 struct state_backend {
struct state_backend_format *format;
struct state_backend_storage storage;
-   const char *of_path;
+   char *of_path;
 };
 
 struct state {
-- 
2.8.1


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH 1/2] state: don't keep pointers to any device tree data

2016-09-15 Thread Michael Olbrich
On Thu, Sep 15, 2016 at 10:13:36AM +0200, Sascha Hauer wrote:
> On Thu, Sep 15, 2016 at 08:10:13AM +0200, Michael Olbrich wrote:
> > Caching pointers to device tree nodes or names is not save. The barebox
> > internal device tree may be changed by loading a new device tree or through
> > fixup handlers.
> > Use local copies of the full path instead and resolve the node as needed.
> >
> 
> This should be two patches, one for backend->of_path and one
> state->root. When reviewing this I first had to understand that this
> patch has two unrelated changes.

Ok.

> > Signed-off-by: Michael Olbrich <m.olbr...@pengutronix.de>
> > ---
> >  common/state/backend.c |  3 ++-
> >  common/state/state.c   | 19 ---
> >  common/state/state.h   |  4 ++--
> >  3 files changed, 16 insertions(+), 10 deletions(-)
> > 
> > diff --git a/common/state/backend.c b/common/state/backend.c
> > index 2f2e6dfd32d1..5235bb0283dd 100644
> > --- a/common/state/backend.c
> > +++ b/common/state/backend.c
> > @@ -164,7 +164,7 @@ int state_backend_init(struct state_backend *backend, 
> > struct device_d *dev,
> > if (ret)
> > goto out_free_format;
> >  
> > -   backend->of_path = of_path;
> > +   backend->of_path = xstrdup(of_path);
> >  
> > return 0;
> >  
> > @@ -185,4 +185,5 @@ void state_backend_free(struct state_backend *backend)
> > state_storage_free(>storage);
> > if (backend->format)
> > state_format_free(backend->format);
> > +   free(backend->of_path);
> >  }
> > diff --git a/common/state/state.c b/common/state/state.c
> > index 9b1d4edef132..0c329cd67548 100644
> > --- a/common/state/state.c
> > +++ b/common/state/state.c
> > @@ -202,15 +202,19 @@ struct device_node *state_to_node(struct state *state,
> >   enum state_convert conv)
> >  {
> > struct device_node *child;
> > -   struct device_node *root;
> > +   struct device_node *root, *state_root;
> > int ret;
> >  
> > -   root = of_new_node(parent, state->root->name);
> > +   state_root = of_find_node_by_path(state->of_path);
> > +   if (!state_root)
> > +   return ERR_PTR(-ENODEV);
> 
> Shouldn't you create the node if it's not there in the target device
> tree?

This looks for the node in the barebox internal device tree, not the target
device tree. If this node is missing, then state does not work any more.

Michael

-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |

___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 2/2] state: fix finding the correct parent node

2016-09-15 Thread Michael Olbrich
Looking for the parent node during fixup is broken. The path of the parent
node is not correctly terminated ('0' vs '\0'). Also, the new state node
should be added to the supplied device tree not the barebox device tree
used by of_find_node_by_path().

Signed-off-by: Michael Olbrich <m.olbr...@pengutronix.de>
---
 common/state/state.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/common/state/state.c b/common/state/state.c
index 0c329cd67548..075618e5bb8f 100644
--- a/common/state/state.c
+++ b/common/state/state.c
@@ -307,8 +307,8 @@ static int of_state_fixup(struct device_node *root, void 
*ctx)
c = strrchr(of_path, '/');
if (!c)
return -ENODEV;
-   *c = '0';
-   parent = of_find_node_by_path(of_path);
+   *c = '\0';
+   parent = of_find_node_by_path_from(root, of_path);
if (!parent)
parent = root;
 
-- 
2.9.3


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 1/2] state: don't keep pointers to any device tree data

2016-09-15 Thread Michael Olbrich
Caching pointers to device tree nodes or names is not save. The barebox
internal device tree may be changed by loading a new device tree or through
fixup handlers.
Use local copies of the full path instead and resolve the node as needed.

Signed-off-by: Michael Olbrich <m.olbr...@pengutronix.de>
---
 common/state/backend.c |  3 ++-
 common/state/state.c   | 19 ---
 common/state/state.h   |  4 ++--
 3 files changed, 16 insertions(+), 10 deletions(-)

diff --git a/common/state/backend.c b/common/state/backend.c
index 2f2e6dfd32d1..5235bb0283dd 100644
--- a/common/state/backend.c
+++ b/common/state/backend.c
@@ -164,7 +164,7 @@ int state_backend_init(struct state_backend *backend, 
struct device_d *dev,
if (ret)
goto out_free_format;
 
-   backend->of_path = of_path;
+   backend->of_path = xstrdup(of_path);
 
return 0;
 
@@ -185,4 +185,5 @@ void state_backend_free(struct state_backend *backend)
state_storage_free(>storage);
if (backend->format)
state_format_free(backend->format);
+   free(backend->of_path);
 }
diff --git a/common/state/state.c b/common/state/state.c
index 9b1d4edef132..0c329cd67548 100644
--- a/common/state/state.c
+++ b/common/state/state.c
@@ -202,15 +202,19 @@ struct device_node *state_to_node(struct state *state,
  enum state_convert conv)
 {
struct device_node *child;
-   struct device_node *root;
+   struct device_node *root, *state_root;
int ret;
 
-   root = of_new_node(parent, state->root->name);
+   state_root = of_find_node_by_path(state->of_path);
+   if (!state_root)
+   return ERR_PTR(-ENODEV);
+
+   root = of_new_node(parent, state_root->name);
ret = of_property_write_u32(root, "magic", state->magic);
if (ret)
goto out;
 
-   for_each_child_of_node(state->root, child) {
+   for_each_child_of_node(state_root, child) {
ret = state_convert_node_variable(state, child, root, "", conv);
if (ret)
goto out;
@@ -234,7 +238,7 @@ int state_from_node(struct state *state, struct device_node 
*node, bool create)
 
if (create) {
conv = STATE_CONVERT_FROM_NODE_CREATE;
-   state->root = node;
+   state->of_path = xstrdup(node->full_name);
state->magic = magic;
} else {
conv = STATE_CONVERT_FROM_NODE;
@@ -291,7 +295,7 @@ static int of_state_fixup(struct device_node *root, void 
*ctx)
int ret;
phandle phandle;
 
-   node = of_find_node_by_path_from(root, state->root->full_name);
+   node = of_find_node_by_path_from(root, state->of_path);
if (node) {
/* replace existing node - it will be deleted later */
parent = node->parent;
@@ -299,7 +303,7 @@ static int of_state_fixup(struct device_node *root, void 
*ctx)
char *of_path, *c;
 
/* look for parent, remove last '/' from path */
-   of_path = xstrdup(state->root->full_name);
+   of_path = xstrdup(state->of_path);
c = strrchr(of_path, '/');
if (!c)
return -ENODEV;
@@ -406,6 +410,7 @@ void state_release(struct state *state)
list_del(>list);
unregister_device(>dev);
state_backend_free(>backend);
+   free(state->of_path);
free(state);
 }
 
@@ -545,7 +550,7 @@ struct state *state_by_node(const struct device_node *node)
struct state *state;
 
list_for_each_entry(state, _list, list) {
-   if (state->root == node)
+   if (!strcmp(state->of_path, node->full_name))
return state;
}
 
diff --git a/common/state/state.h b/common/state/state.h
index 32146ca1bbc7..7b3e49512e37 100644
--- a/common/state/state.h
+++ b/common/state/state.h
@@ -87,14 +87,14 @@ struct state_backend_storage {
 struct state_backend {
struct state_backend_format *format;
struct state_backend_storage storage;
-   const char *of_path;
+   char *of_path;
 };
 
 struct state {
struct list_head list; /* Entry to enqueue on list of states */
 
struct device_d dev;
-   struct device_node *root;
+   char *of_path;
const char *name;
uint32_t magic;
 
-- 
2.9.3


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH] mci: mmci: Fix read FIFO handling

2016-09-02 Thread Michael Olbrich
According to the Linux kernel and the qemu code, the MMCIFIFOCNT contains
the remaining number of words to read, excluding those that are already in
the FIFO. So the current number of bytes in the FIFO is
host_remain - (readl(base + MMCIFIFOCNT) << 2).

Also writing to MMCIDATACTRL will reset the read counter. As a result,
MCI_DATABLOCKEND is never set and read_bytes() waits forever.

With this change, SD-Card support on qemu vexpress works correctly.

Signed-off-by: Michael Olbrich <m.olbr...@pengutronix.de>
---
 drivers/mci/mmci.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/mci/mmci.c b/drivers/mci/mmci.c
index 9d1e858917de..7489ee03a13c 100644
--- a/drivers/mci/mmci.c
+++ b/drivers/mci/mmci.c
@@ -212,7 +212,7 @@ static u64 mmci_pio_read(struct mmci_host *host, char 
*buffer, unsigned int host
struct variant_data *variant = host->variant;
 
do {
-   int count = readl(base + MMCIFIFOCNT) << 2;
+   int count = host_remain - (readl(base + MMCIFIFOCNT) << 2);
 
if (count > host_remain)
count = host_remain;
@@ -264,7 +264,6 @@ static int read_bytes(struct mci_host *mci, char *dest, 
unsigned int blkcount, u
dev_dbg(host->hw_dev, "read_bytes: blkcount=%u blksize=%u\n", blkcount, 
blksize);
 
do {
-   mmci_writel(host, MMCIDATACTRL, mmci_readl(host, MMCIDATACTRL));
len = mmci_pio_read(host, dest, xfercount);
xfercount -= len;
dest += len;
-- 
2.9.3


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH] efi: let the generic relocate code handle all relocations

2016-04-05 Thread Michael Olbrich
Part of the barebox code and variables are put in separate sections
(.barebox* and .initcall*). When this code is compiled as position
independent code then the compiler creates corresponding .rela.barebox* and
.rela.initcall* sections with the relocation table entries.
These sections don't match the .rela.data* wildcard in the linker script.
As a result, they are not added to the .rela section during linking but are
added individually after it instead. And when the EFI binary is created
from the ELF binary, these sections are not copied.
This has two side effects:

1. The corresponding relocations are not handled by the generic relocation
code. 'fixup_tables()' was added to do these relocations manually.

2. In the DYNAMIC section, the RELASZ entry contains the total size of
relocations in bytes. This includes the .rela.barebox* and .rela.initcall*
sections. This value is not modified when the EFI binary is created. So the
value is too large.
The generic relocation code in _relocate() used this value when iterating
over all relocation entries. With the wrong RELASZ value it iterates beyond
the end of the .rela section into uninitialized memory. After power-on this
memory is zero and the relocation code interprets this as 'nothing to do',
so there is no visible effect. After a soft reset, random data in that area
may produce a seemingly valid relocation entry, a random address is
modified and barebox crashes.

This patch adds the .rela.barebox* and .rela.initcall* sections to the
normal .rela section. The RELASZ now contains the correct size and the
generic relocation code works correctly. 'fixup_tables()' must be removed
at the same time to avoid relocating these entries twice.

Signed-off-by: Michael Olbrich <m.olbr...@pengutronix.de>
---
 arch/efi/efi/efi.c| 42 ---
 arch/efi/lib/elf_x86_64_efi.lds.S |  2 ++
 2 files changed, 2 insertions(+), 42 deletions(-)

diff --git a/arch/efi/efi/efi.c b/arch/efi/efi/efi.c
index ed449dc8db86..9c270a597ee5 100644
--- a/arch/efi/efi/efi.c
+++ b/arch/efi/efi/efi.c
@@ -293,46 +293,6 @@ extern char image_base[];
 extern initcall_t __barebox_initcalls_start[], __barebox_early_initcalls_end[],
  __barebox_initcalls_end[];
 
-/*
- * We have a position independent binary generated with -fpic. This function
- * fixes the linker generated tables.
- */
-static void fixup_tables(void)
-{
-   initcall_t *initcall;
-   unsigned long offset = (unsigned long)image_base;
-   struct command *cmdtp;
-   struct magicvar *m;
-
-   for (initcall = __barebox_initcalls_start;
-   initcall < __barebox_initcalls_end; initcall++)
-   *initcall += offset;
-
-   for (cmdtp = &__barebox_cmd_start;
-   cmdtp != &__barebox_cmd_end;
-   cmdtp++) {
-   cmdtp->name += offset;
-   cmdtp->cmd += offset;
-   if (cmdtp->complete)
-   cmdtp->complete += offset;
-   if (cmdtp->desc)
-   cmdtp->desc += offset;
-   if (cmdtp->help)
-   cmdtp->help += offset;
-   if (cmdtp->opts)
-   cmdtp->opts += offset;
-   if (cmdtp->aliases)
-   cmdtp->aliases = (void *)cmdtp->aliases + offset;
-   }
-
-   for (m = &__barebox_magicvar_start;
-   m != &__barebox_magicvar_end;
-   m++) {
-   m->name += offset;
-   m->description += offset;
-   }
-}
-
 static int efi_init(void)
 {
char *env;
@@ -373,8 +333,6 @@ efi_status_t efi_main(efi_handle_t image, 
efi_system_table_t *sys_table)
BS->handle_protocol(efi_loaded_image->device_handle,
_device_path_protocol_guid, (void 
**)_device_path);
 
-   fixup_tables();
-
mem = 0x3fff;
for (memsize = SZ_256M; memsize >= SZ_8M; memsize /= 2) {
efiret  = BS->allocate_pages(EFI_ALLOCATE_MAX_ADDRESS,
diff --git a/arch/efi/lib/elf_x86_64_efi.lds.S 
b/arch/efi/lib/elf_x86_64_efi.lds.S
index 9aa4e8d8299b..e1bc2120fabc 100644
--- a/arch/efi/lib/elf_x86_64_efi.lds.S
+++ b/arch/efi/lib/elf_x86_64_efi.lds.S
@@ -78,6 +78,8 @@ SECTIONS
 
.rela : {
*(.rela.data*)
+   *(.rela.barebox*)
+   *(.rela.initcall*)
*(.rela.got)
*(.rela.stab)
}
-- 
2.7.0


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH v2 4/4] fastboot: Add a ARM Barebox filetype handler

2016-02-18 Thread Michael Olbrich
On Wed, Feb 17, 2016 at 12:28:20PM +0100, Markus Pargmann wrote:
> This will automatically call barebox_update for the transfered file if
> it is an ARM Barebox image and the destination file is defined by some
> update handler.
> 
> Signed-off-by: Markus Pargmann 
> ---
>  common/filetype.c   | 13 +
>  drivers/usb/gadget/f_fastboot.c | 29 +
>  include/filetype.h  |  2 ++
>  3 files changed, 44 insertions(+)
> 
> diff --git a/common/filetype.c b/common/filetype.c
> index 8cfae88aeb35..74baf514466a 100644
> --- a/common/filetype.c
> +++ b/common/filetype.c
> @@ -369,3 +369,16 @@ err_out:
>   cdev_close(cdev);
>   return type;
>  }
> +
> +bool filetype_is_barebox_image(enum filetype ft)
> +{
> + switch (ft) {
> + case filetype_arm_barebox:
> + case filetype_mips_barebox:
> + case filetype_ch_image:
> + case filetype_ch_image_be:
> + return true;
> + default:
> + return false;
> + }
> +}
> diff --git a/drivers/usb/gadget/f_fastboot.c b/drivers/usb/gadget/f_fastboot.c
> index bc06c58d8dcb..9a1058a9670b 100644
> --- a/drivers/usb/gadget/f_fastboot.c
> +++ b/drivers/usb/gadget/f_fastboot.c
> @@ -23,6 +23,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -716,6 +717,34 @@ static void cb_flash(struct usb_ep *ep, struct 
> usb_request *req, const char *cmd
>   goto out;
>   }
>  
> + if (filetype_is_barebox_image(filetype)) {
> + struct bbu_data data = {
> + .devicefile = filename,
> + .imagefile = FASTBOOT_TMPFILE,
> + .flags = BBU_FLAG_YES,
> + };
> +
> + if (!barebox_update_handler_exists())
> + goto copy;
> +
> + fastboot_tx_print(f_fb, "INFOThis is an ARM Barebox image...");

With the change above, it may not be an _ARM_ image.

Michael

> +
> + data.image = read_file(data.imagefile, );
> + if (!data.image) {
> + fastboot_tx_print(f_fb, "FAILreading barebox");
> + return;
> + }
> +
> + ret = barebox_update();
> +
> + if (ret) {
> + fastboot_tx_print(f_fb, "FAILupdate barebox: %s", 
> strerror(-ret));
> + return;
> + }
> +
> + goto out;
> + }
> +
>  copy:
>   ret = copy_file(FASTBOOT_TMPFILE, filename, 1);
>   if (ret) {
> diff --git a/include/filetype.h b/include/filetype.h
> index cde543e5b061..e87ca174a89d 100644
> --- a/include/filetype.h
> +++ b/include/filetype.h
> @@ -2,6 +2,7 @@
>  #define __FILE_TYPE_H
>  
>  #include 
> +#include 
>  
>  /*
>   * List of file types we know
> @@ -48,6 +49,7 @@ enum filetype file_name_detect_type(const char *filename);
>  enum filetype cdev_detect_type(const char *name);
>  enum filetype is_fat_or_mbr(const unsigned char *sector, unsigned long 
> *bootsec);
>  int is_fat_boot_sector(const void *_buf);
> +bool filetype_is_barebox_image(enum filetype ft);
>  
>  #define ARM_HEAD_SIZE0x30
>  #define ARM_HEAD_MAGICWORD_OFFSET0x20
> -- 
> 2.7.0
> 
> 
> ___
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |

___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: Booting Linux bzImage on x86_64

2015-10-30 Thread Michael Olbrich
Hi,

On Wed, Oct 28, 2015 at 09:50:06PM +0100, Viktor Stark wrote:
> I recently discovered barebox and I am trying to boot a Linux bzImage on an
> x86_64 embedded platform.
> 
> Some background: My project involves an x86_64 embedded device for which I am
> building a bzImage and a root filesystem with buildroot. The idea is to have
> multiple combinations of these in order to serve different use cases, but
> also for fallback situations.
> 
> I went down both possible ways on x86, but cannot really find a way to boot a 
> bzImage.
> 
> Both configurations are tested under QEMU with barebox 2015.10.0.
> 
> 1. EFI - I have a working barebox.efi living inside an EF00 partition. The
> issue I am having is that I cannot really find any pointers as to how to boot
> a bzImage from these. I have found some earlier posts on the list indicating
> that it is not possible to boot a bzImage from EFI, but also a G+ post saying
> that it is possible.

I'm running my Laptop with Barebox on EFI, so it's certainly possible.
Without any error messages I can only guess what the problem might be.
Have you enabled CONFIG_EFI_STUB in your kernel config? This is necessary
for barebox to boot your kernel.

> 2. Non-EFI - I have compiled barebox with the attached config file, but it
> seems to triple fault according to qemu. AFAICT (zero asm knowledge here), it
> seems to be in pmjump.S.
> Triple fault

This is _really_ old code. Nobody has tested this in a long time. It's most
likely broken in many ways. Don't use it unless you're interested in
barebox development and want to fix it :-).

Regards,
Michael


-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |

___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH] efi: enable blspec in the defconfig

2015-07-25 Thread Michael Olbrich
Signed-off-by: Michael Olbrich m.olbr...@pengutronix.de
---
 arch/efi/configs/efi_defconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/efi/configs/efi_defconfig b/arch/efi/configs/efi_defconfig
index 456f70d32b59..3c9a9dcb956e 100644
--- a/arch/efi/configs/efi_defconfig
+++ b/arch/efi/configs/efi_defconfig
@@ -7,6 +7,7 @@ CONFIG_CMDLINE_EDITING=y
 CONFIG_AUTO_COMPLETE=y
 CONFIG_MENU=y
 # CONFIG_TIMESTAMP is not set
+CONFIG_BLSPEC=y
 CONFIG_CONSOLE_ACTIVATE_ALL=y
 CONFIG_PARTITION_DISK_EFI=y
 CONFIG_DEFAULT_ENVIRONMENT_GENERIC_NEW=y
-- 
2.1.4


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH] fixup! efi: add helper to get the GPT partition UUID for a device

2015-07-25 Thread Michael Olbrich
---

I'm not sure why I didn't notice this before. This is needed to generate
the correct UUID. Otherwise systemd fails to mount the EFI partition.

Michael

 common/efi-devicepath.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/common/efi-devicepath.c b/common/efi-devicepath.c
index a1cd0952f929..54c2f4e3c54e 100644
--- a/common/efi-devicepath.c
+++ b/common/efi-devicepath.c
@@ -1406,7 +1406,7 @@ char *device_path_to_partuuid(struct efi_device_path 
*dev_path)
if (hd-signature_type != SIGNATURE_TYPE_GUID)
continue;
 
-   str = xasprintf(%pU), (efi_guid_t *)(hd-signature[0]));
+   str = xasprintf(%pUl, (efi_guid_t *)(hd-signature[0]));
break;
}
 
-- 
2.1.4


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 07/16] efi: export device_path_from_handle()

2015-07-17 Thread Michael Olbrich
Signed-off-by: Michael Olbrich m.olbr...@pengutronix.de
---
 include/efi.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/efi.h b/include/efi.h
index b6ee42b3fd49..830e0457dd1c 100644
--- a/include/efi.h
+++ b/include/efi.h
@@ -622,6 +622,7 @@ static inline int efi_compare_guid(efi_guid_t *a, 
efi_guid_t *b)
return memcmp(a, b, sizeof(efi_guid_t));
 }
 
+struct efi_device_path *device_path_from_handle(efi_handle_t Handle);
 char *device_path_to_str(struct efi_device_path *dev_path);
 u8 device_path_to_type(struct efi_device_path *dev_path);
 char *device_path_to_partuuid(struct efi_device_path *dev_path);
-- 
2.1.4


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 16/16] efi: use an EFI variable to save the environment

2015-07-17 Thread Michael Olbrich
Signed-off-by: Michael Olbrich m.olbr...@pengutronix.de
---
 arch/efi/efi/efi.c | 5 +
 common/efi-guid.c  | 1 +
 include/efi.h  | 1 +
 3 files changed, 7 insertions(+)

diff --git a/arch/efi/efi/efi.c b/arch/efi/efi/efi.c
index 07a4d9d0fc57..d3f520f60f14 100644
--- a/arch/efi/efi/efi.c
+++ b/arch/efi/efi/efi.c
@@ -326,8 +326,13 @@ static void fixup_tables(void)
 
 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);
diff --git a/common/efi-guid.c b/common/efi-guid.c
index f4ff7feadfe4..64f3b1f65fd3 100644
--- a/common/efi-guid.c
+++ b/common/efi-guid.c
@@ -9,6 +9,7 @@ efi_guid_t efi_unknown_device_guid = EFI_UNKNOWN_DEVICE_GUID;
 efi_guid_t efi_null_guid = EFI_NULL_GUID;
 efi_guid_t efi_global_variable_guid = EFI_GLOBAL_VARIABLE_GUID;
 efi_guid_t efi_block_io_protocol_guid = EFI_BLOCK_IO_PROTOCOL_GUID;
+efi_guid_t efi_barebox_vendor_guid = EFI_BAREBOX_VENDOR_GUID;
 efi_guid_t efi_systemd_vendor_guid = EFI_SYSTEMD_VENDOR_GUID;
 
 #define EFI_GUID_STRING(guid, short, long) do {\
diff --git a/include/efi.h b/include/efi.h
index 5b0de119fb74..b2e965bae1d4 100644
--- a/include/efi.h
+++ b/include/efi.h
@@ -485,6 +485,7 @@ extern efi_guid_t efi_unknown_device_guid;
 extern efi_guid_t efi_null_guid;
 extern efi_guid_t efi_global_variable_guid;
 extern efi_guid_t efi_block_io_protocol_guid;
+extern efi_guid_t efi_barebox_vendor_guid;
 extern efi_guid_t efi_systemd_vendor_guid;
 
 #define EFI_SYSTEM_TABLE_SIGNATURE ((u64)0x5453595320494249ULL)
-- 
2.1.4


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 15/16] fs: efivars: read the attributes on the second get_variable()

2015-07-17 Thread Michael Olbrich
Some EFI get_variable() implementations don't set the attributes when
returning EFI_BUFFER_TOO_SMALL.

Signed-off-by: Michael Olbrich m.olbr...@pengutronix.de
---
 fs/efivarfs.c | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/fs/efivarfs.c b/fs/efivarfs.c
index 87fc771739e2..c7a282b05c63 100644
--- a/fs/efivarfs.c
+++ b/fs/efivarfs.c
@@ -216,7 +216,7 @@ static int efivarfs_open(struct device_d *dev, FILE *f, 
const char *filename)
return -ENOENT;
 
efiret = RT-get_variable(efile-name, efile-vendor,
- efile-attributes, efile-size, NULL);
+ NULL, efile-size, NULL);
if (EFI_ERROR(efiret)  efiret != EFI_BUFFER_TOO_SMALL) {
ret = -efi_errno(efiret);
goto out;
@@ -228,8 +228,9 @@ static int efivarfs_open(struct device_d *dev, FILE *f, 
const char *filename)
goto out;
}
 
-   efiret = RT-get_variable(efile-name, efile-vendor, NULL, 
efile-size,
-   efile-buf);
+   efiret = RT-get_variable(efile-name, efile-vendor,
+ efile-attributes, efile-size,
+ efile-buf);
if (EFI_ERROR(efiret)) {
ret = -efi_errno(efiret);
goto out;
-- 
2.1.4


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCHv2 00/16] EFI updates

2015-07-17 Thread Michael Olbrich
Hi,

I've added a patch for xasprintf() and one to add xfuncs for the relevant
wchar functions. I've replaced all occurrences in the EFI code but I'm not
confident enough to do this elsewhere without being able to test it.

And I've added some patches to save the environment in an EFI variable.

Michael Olbrich (16):
  xfuncs: add xasprintf() and xvasprintf()
  xfuncs: add wrapper for wchar strdup functions
  efi: improve malloc pool allocation
  efi: refactor  improve application loading code
  efi: add support for initrd loading
  efi: add helper to get the GPT partition UUID for a device
  efi: export device_path_from_handle()
  efi: add helper functions to write EFI variables
  efi: write volatile EFI variables used by systemd
  efi: use xasprintf() when appropriate
  efi: use xstrdup_* when appropriate
  fs: efi: use xstrdup_* when appropriate
  fs: efivars: use xstrdup_* when appropriate
  fs: efivars: add more error checking
  fs: efivars: read the attributes on the second get_variable()
  efi: use an EFI variable to save the environment

 arch/efi/efi/efi-block-io.c |   2 +-
 arch/efi/efi/efi-image.c| 198 +---
 arch/efi/efi/efi.c  |  74 +++--
 arch/efi/include/mach/efi.h |   4 +
 common/efi-devicepath.c |  30 +++
 common/efi-guid.c   |   2 +
 fs/efi.c|   4 +-
 fs/efivarfs.c   |  29 ---
 include/efi.h   |  10 ++-
 include/xfuncs.h|   8 ++
 lib/xfuncs.c|  55 
 11 files changed, 383 insertions(+), 33 deletions(-)

-- 
2.1.4


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 12/16] fs: efi: use xstrdup_* when appropriate

2015-07-17 Thread Michael Olbrich
Signed-off-by: Michael Olbrich m.olbr...@pengutronix.de
---
 fs/efi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/efi.c b/fs/efi.c
index 8f4739a99e24..a7adcb98db57 100644
--- a/fs/efi.c
+++ b/fs/efi.c
@@ -114,9 +114,9 @@ static wchar_t *path_to_efi(const char *path)
wchar_t *ret;
 
if (!*path)
-   return strdup_char_to_wchar(\\);
+   return xstrdup_char_to_wchar(\\);
 
-   dst = strdup_char_to_wchar(path);
+   dst = xstrdup_char_to_wchar(path);
if (!dst)
return NULL;
 
-- 
2.1.4


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 14/16] fs: efivars: add more error checking

2015-07-17 Thread Michael Olbrich
Signed-off-by: Michael Olbrich m.olbr...@pengutronix.de
---
 fs/efivarfs.c | 16 
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/fs/efivarfs.c b/fs/efivarfs.c
index 925e8e8be113..87fc771739e2 100644
--- a/fs/efivarfs.c
+++ b/fs/efivarfs.c
@@ -269,6 +269,7 @@ static int efivarfs_read(struct device_d *_dev, FILE *f, 
void *buf, size_t insiz
 static int efivarfs_write(struct device_d *_dev, FILE *f, const void *buf, 
size_t insize)
 {
struct efivars_file *efile = f-priv;
+   efi_status_t efiret;
 
if (efile-size  f-pos + insize) {
efile-buf = realloc(efile-buf, f-pos + insize);
@@ -277,8 +278,11 @@ static int efivarfs_write(struct device_d *_dev, FILE *f, 
const void *buf, size_
 
memcpy(efile-buf + f-pos, buf, insize);
 
-   RT-set_variable(efile-name, efile-vendor, efile-attributes,
-efile-size ? efile-size : 1, efile-buf);
+   efiret = RT-set_variable(efile-name, efile-vendor,
+ efile-attributes,
+ efile-size ? efile-size : 1, efile-buf);
+   if (EFI_ERROR(efiret))
+   return -efi_errno(efiret);
 
return insize;
 }
@@ -286,12 +290,16 @@ static int efivarfs_write(struct device_d *_dev, FILE *f, 
const void *buf, size_
 static int efivarfs_truncate(struct device_d *dev, FILE *f, ulong size)
 {
struct efivars_file *efile = f-priv;
+   efi_status_t efiret;
 
efile-size = size;
efile-buf = realloc(efile-buf, efile-size + sizeof(uint32_t));
 
-   RT-set_variable(efile-name, efile-vendor, efile-attributes,
-efile-size ? efile-size : 1, efile-buf);
+   efiret = RT-set_variable(efile-name, efile-vendor,
+ efile-attributes,
+ efile-size ? efile-size : 1, efile-buf);
+   if (EFI_ERROR(efiret))
+   return -efi_errno(efiret);
 
f-size = efile-size;
 
-- 
2.1.4


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 02/16] xfuncs: add wrapper for wchar strdup functions

2015-07-17 Thread Michael Olbrich
Signed-off-by: Michael Olbrich m.olbr...@pengutronix.de
---
 include/xfuncs.h |  5 +
 lib/xfuncs.c | 31 +++
 2 files changed, 36 insertions(+)

diff --git a/include/xfuncs.h b/include/xfuncs.h
index c7c0203f375b..b53cfdcddd31 100644
--- a/include/xfuncs.h
+++ b/include/xfuncs.h
@@ -3,6 +3,7 @@
 
 #include linux/types.h
 #include stdarg.h
+#include wchar.h
 
 void *xmalloc(size_t size);
 void *xrealloc(void *ptr, size_t size);
@@ -13,4 +14,8 @@ void* xmemdup(const void *orig, size_t size);
 char *xasprintf(const char *fmt, ...) __attribute__ ((format(__printf__, 1, 
2)));
 char *xvasprintf(const char *fmt, va_list ap);
 
+wchar_t *xstrdup_wchar(const wchar_t *src);
+wchar_t *xstrdup_char_to_wchar(const char *src);
+char *xstrdup_wchar_to_char(const wchar_t *src);
+
 #endif /* __XFUNCS_H */
diff --git a/lib/xfuncs.c b/lib/xfuncs.c
index ce89169547a4..c8c1da7dad7f 100644
--- a/lib/xfuncs.c
+++ b/lib/xfuncs.c
@@ -22,6 +22,7 @@
 #include common.h
 #include malloc.h
 #include module.h
+#include wchar.h
 
 void *xmalloc(size_t size)
 {
@@ -105,3 +106,33 @@ char *xasprintf(const char *fmt, ...)
return p;
 }
 EXPORT_SYMBOL(xasprintf);
+
+wchar_t *xstrdup_wchar(const wchar_t *s)
+{
+   wchar_t *p = strdup_wchar(s);
+
+   if (!p)
+   panic(ERROR: out of memory\n);
+   return p;
+}
+EXPORT_SYMBOL(xstrdup_wchar);
+
+wchar_t *xstrdup_char_to_wchar(const char *s)
+{
+   wchar_t *p = strdup_char_to_wchar(s);
+
+   if (!p)
+   panic(ERROR: out of memory\n);
+   return p;
+}
+EXPORT_SYMBOL(xstrdup_char_to_wchar);
+
+char *xstrdup_wchar_to_char(const wchar_t *s)
+{
+   char *p = strdup_wchar_to_char(s);
+
+   if (!p)
+   panic(ERROR: out of memory\n);
+   return p;
+}
+EXPORT_SYMBOL(xstrdup_wchar_to_char);
-- 
2.1.4


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 01/16] xfuncs: add xasprintf() and xvasprintf()

2015-07-17 Thread Michael Olbrich
Signed-off-by: Michael Olbrich m.olbr...@pengutronix.de
---
 include/xfuncs.h |  3 +++
 lib/xfuncs.c | 24 
 2 files changed, 27 insertions(+)

diff --git a/include/xfuncs.h b/include/xfuncs.h
index 8efc99dbc455..c7c0203f375b 100644
--- a/include/xfuncs.h
+++ b/include/xfuncs.h
@@ -2,6 +2,7 @@
 #define __XFUNCS_H
 
 #include linux/types.h
+#include stdarg.h
 
 void *xmalloc(size_t size);
 void *xrealloc(void *ptr, size_t size);
@@ -9,5 +10,7 @@ void *xzalloc(size_t size);
 char *xstrdup(const char *s);
 void* xmemalign(size_t alignment, size_t bytes);
 void* xmemdup(const void *orig, size_t size);
+char *xasprintf(const char *fmt, ...) __attribute__ ((format(__printf__, 1, 
2)));
+char *xvasprintf(const char *fmt, va_list ap);
 
 #endif /* __XFUNCS_H */
diff --git a/lib/xfuncs.c b/lib/xfuncs.c
index 0e78b670a5d4..ce89169547a4 100644
--- a/lib/xfuncs.c
+++ b/lib/xfuncs.c
@@ -81,3 +81,27 @@ void *xmemdup(const void *orig, size_t size)
return buf;
 }
 EXPORT_SYMBOL(xmemdup);
+
+char *xvasprintf(const char *fmt, va_list ap)
+{
+   char *p;
+
+   p = vasprintf(fmt, ap);
+   if (!p)
+   panic(ERROR: out of memory\n);
+   return p;
+}
+EXPORT_SYMBOL(xvasprintf)
+
+char *xasprintf(const char *fmt, ...)
+{
+   va_list ap;
+   char *p;
+
+   va_start(ap, fmt);
+   p = xvasprintf(fmt, ap);
+   va_end(ap);
+
+   return p;
+}
+EXPORT_SYMBOL(xasprintf);
-- 
2.1.4


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 05/16] efi: add support for initrd loading

2015-07-17 Thread Michael Olbrich
Signed-off-by: Michael Olbrich m.olbr...@pengutronix.de
---
v2: xmemalign

 arch/efi/efi/efi-image.c | 136 ++-
 1 file changed, 135 insertions(+), 1 deletion(-)

diff --git a/arch/efi/efi/efi-image.c b/arch/efi/efi/efi-image.c
index c88b3a0766ed..de9b27755663 100644
--- a/arch/efi/efi/efi-image.c
+++ b/arch/efi/efi/efi-image.c
@@ -37,6 +37,55 @@
 #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)
 {
@@ -108,9 +157,94 @@ static int efi_execute_image(const char *file)
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)
 {
-   return efi_execute_image(data-os_file);
+   void *tmp;
+   void *initrd;
+   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

[PATCH 10/16] efi: use xasprintf() when appropriate

2015-07-17 Thread Michael Olbrich
Signed-off-by: Michael Olbrich m.olbr...@pengutronix.de
---
 arch/efi/efi/efi-block-io.c | 2 +-
 arch/efi/efi/efi.c  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/efi/efi/efi-block-io.c b/arch/efi/efi/efi-block-io.c
index 85603d913d5b..e02d3b49cc99 100644
--- a/arch/efi/efi/efi-block-io.c
+++ b/arch/efi/efi/efi-block-io.c
@@ -147,7 +147,7 @@ int efi_bio_probe(struct efi_device *efidev)
efi_bio_print_info(priv);
priv-dev = efidev-dev;
 
-   priv-blk.cdev.name = asprintf(disk%d, cdev_find_free_index(disk));
+   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;
diff --git a/arch/efi/efi/efi.c b/arch/efi/efi/efi.c
index 1f0deed577f0..6cffac60f54b 100644
--- a/arch/efi/efi/efi.c
+++ b/arch/efi/efi/efi.c
@@ -125,7 +125,7 @@ struct efi_boot *efi_get_boot(int num)
int size;
char *name;
 
-   name = asprintf(Boot%04X, num);
+   name = xasprintf(Boot%04X, num);
 
buf = efi_get_global_var(name, size);
 
-- 
2.1.4


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 13/16] fs: efivars: use xstrdup_* when appropriate

2015-07-17 Thread Michael Olbrich
Signed-off-by: Michael Olbrich m.olbr...@pengutronix.de
---
 fs/efivarfs.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/fs/efivarfs.c b/fs/efivarfs.c
index ebace8bc8fb1..925e8e8be113 100644
--- a/fs/efivarfs.c
+++ b/fs/efivarfs.c
@@ -153,7 +153,7 @@ static int efivars_create(struct device_d *dev, const char 
*pathname, mode_t mod
inode-vendor = vendor;
 
 
-   name8 = strdup_wchar_to_char(inode-name);
+   name8 = xstrdup_wchar_to_char(inode-name);
inode-full_name = asprintf(%s-%pUl, name8, inode-vendor);
free(name8);
 
@@ -391,11 +391,11 @@ static int efivarfs_probe(struct device_d *dev)
break;
 
inode = xzalloc(sizeof(*inode));
-   inode-name = strdup_wchar(name);
+   inode-name = xstrdup_wchar(name);
 
inode-vendor = vendor;
 
-   name8 = strdup_wchar_to_char(inode-name);
+   name8 = xstrdup_wchar_to_char(inode-name);
inode-full_name = asprintf(%s-%pUl, name8, vendor);
free(name8);
 
-- 
2.1.4


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 04/16] efi: refactor improve application loading code

2015-07-17 Thread Michael Olbrich
Signed-off-by: Michael Olbrich m.olbr...@pengutronix.de
---
v2: use xstrdup_char_to_wchar()

 arch/efi/efi/efi-image.c | 57 ++--
 include/efi.h|  2 +-
 2 files changed, 46 insertions(+), 13 deletions(-)

diff --git a/arch/efi/efi/efi-image.c b/arch/efi/efi/efi-image.c
index f7bda8dfcb2a..c88b3a0766ed 100644
--- a/arch/efi/efi/efi-image.c
+++ b/arch/efi/efi/efi-image.c
@@ -37,14 +37,13 @@
 #include mach/efi.h
 #include mach/efi-device.h
 
-static int efi_execute_image(const char *file)
+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;
-   const char *options;
-   efi_loaded_image_t *loaded_image;
+   efi_status_t efiret = EFI_SUCCESS;
 
exe = read_file(file, size);
if (!exe)
@@ -54,25 +53,59 @@ static int efi_execute_image(const char *file)
handle);
if (EFI_ERROR(efiret)) {
pr_err(failed to LoadImage: %s\n, efi_strerror(efiret));
-   return -efi_errno(efiret);;
+   goto out;
};
 
efiret = BS-open_protocol(handle, efi_loaded_image_protocol_guid,
-   (void **)loaded_image,
+   (void **)loaded_image,
efi_parent_image, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL);
-   if (EFI_ERROR(efiret))
-   return -efi_errno(efiret);
+   if (EFI_ERROR(efiret)) {
+   pr_err(failed to OpenProtocol: %s\n, efi_strerror(efiret));
+   BS-unload_image(handle);
+   goto out;
+   }
 
-   options = linux_bootargs_get();
-   loaded_image-load_options = strdup_char_to_wchar(options);
-   loaded_image-load_options_size = (strlen(options) + 1) * 
sizeof(wchar_t);
+   *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;
+   int ret;
+
+   ret = efi_load_image(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) {
+   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);
+   }
 
efiret = BS-start_image(handle, NULL, NULL);
+   if (EFI_ERROR(efiret))
+   pr_err(failed to StartImage: %s\n, efi_strerror(efiret));
+
+   BS-unload_image(handle);
 
efi_connect_all();
efi_register_devices();
 
-   return 0;
+   return -efi_errno(efiret);
 }
 
 static int do_bootm_efi(struct image_data *data)
diff --git a/include/efi.h b/include/efi.h
index 9b4f16bd9f54..e79a407bc2c8 100644
--- a/include/efi.h
+++ b/include/efi.h
@@ -211,7 +211,7 @@ typedef struct {
unsigned long *exitdata_size, s16 **exitdata);
efi_status_t(EFIAPI *exit)(efi_handle_t handle,  efi_status_t 
exit_status,
unsigned long exitdata_size, s16 *exitdata);
-   void *unload_image;
+   efi_status_t (EFIAPI *unload_image)(efi_handle_t handle);
efi_status_t (EFIAPI *exit_boot_services)(efi_handle_t, unsigned long);
void *get_next_monotonic_count;
efi_status_t (EFIAPI *stall)(unsigned long usecs);
-- 
2.1.4


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 09/16] efi: write volatile EFI variables used by systemd

2015-07-17 Thread Michael Olbrich
LoaderTimeInitUSec and LoaderTimeExecUSec are used e.g. in systemd-analyze
to calculate the time spent in the firmare and barebox.

LoaderDevicePartUUID is used to mount the EFI partition to /boot.

Signed-off-by: Michael Olbrich m.olbr...@pengutronix.de
---
v2: use xstrdup_char_to_wchar() and free uuid/uuid16

 arch/efi/efi/efi-image.c |  5 +
 arch/efi/efi/efi.c   | 16 
 common/efi-guid.c|  1 +
 include/efi.h|  5 +
 4 files changed, 27 insertions(+)

diff --git a/arch/efi/efi/efi-image.c b/arch/efi/efi/efi-image.c
index de9b27755663..b6437f40787b 100644
--- a/arch/efi/efi/efi-image.c
+++ b/arch/efi/efi/efi-image.c
@@ -17,6 +17,7 @@
  *
  */
 
+#include clock.h
 #include common.h
 #include linux/sizes.h
 #include memory.h
@@ -242,6 +243,10 @@ static int do_bootm_efi(struct image_data *data)
   boot_header-ramdisk_image);
printf(...\n);
}
+
+   efi_set_variable_usec(LoaderTimeExecUSec, efi_systemd_vendor_guid,
+ get_time_ns()/1000);
+
linux_efi_handover(handle, boot_header);
 
return 0;
diff --git a/arch/efi/efi/efi.c b/arch/efi/efi/efi.c
index b0e98f95b02b..1f0deed577f0 100644
--- a/arch/efi/efi/efi.c
+++ b/arch/efi/efi/efi.c
@@ -340,6 +340,7 @@ 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, Lbarebox\n);
@@ -377,6 +378,21 @@ efi_status_t efi_main(efi_handle_t image, 
efi_system_table_t *sys_table)
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();
 
diff --git a/common/efi-guid.c b/common/efi-guid.c
index f6b040410522..f4ff7feadfe4 100644
--- a/common/efi-guid.c
+++ b/common/efi-guid.c
@@ -9,6 +9,7 @@ efi_guid_t efi_unknown_device_guid = EFI_UNKNOWN_DEVICE_GUID;
 efi_guid_t efi_null_guid = EFI_NULL_GUID;
 efi_guid_t efi_global_variable_guid = EFI_GLOBAL_VARIABLE_GUID;
 efi_guid_t efi_block_io_protocol_guid = EFI_BLOCK_IO_PROTOCOL_GUID;
+efi_guid_t efi_systemd_vendor_guid = EFI_SYSTEMD_VENDOR_GUID;
 
 #define EFI_GUID_STRING(guid, short, long) do {\
if (!efi_guidcmp(guid, *g)) \
diff --git a/include/efi.h b/include/efi.h
index 830e0457dd1c..5b0de119fb74 100644
--- a/include/efi.h
+++ b/include/efi.h
@@ -473,6 +473,10 @@ extern efi_runtime_services_t *RT;
 #define EFI_BAREBOX_VENDOR_GUID \
EFI_GUID(0x5b91f69c, 0x8b88, 0x4a2b, 0x92, 0x69, 0x5f, 0x1d, 0x80, 
0x2b, 0x51, 0x75)
 
+/* for systemd */
+#define EFI_SYSTEMD_VENDOR_GUID \
+   EFI_GUID(0x4a67b082, 0x0a4c, 0x41cf, 0xb6, 0xc7, 0x44, 0x0b, 0x29, 
0xbb, 0x8c, 0x4f)
+
 extern efi_guid_t efi_file_info_id;
 extern efi_guid_t efi_simple_file_system_protocol_guid;
 extern efi_guid_t efi_device_path_protocol_guid;
@@ -481,6 +485,7 @@ extern efi_guid_t efi_unknown_device_guid;
 extern efi_guid_t efi_null_guid;
 extern efi_guid_t efi_global_variable_guid;
 extern efi_guid_t efi_block_io_protocol_guid;
+extern efi_guid_t efi_systemd_vendor_guid;
 
 #define EFI_SYSTEM_TABLE_SIGNATURE ((u64)0x5453595320494249ULL)
 
-- 
2.1.4


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 11/16] efi: use xstrdup_* when appropriate

2015-07-17 Thread Michael Olbrich
Signed-off-by: Michael Olbrich m.olbr...@pengutronix.de
---
 arch/efi/efi/efi.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/efi/efi/efi.c b/arch/efi/efi/efi.c
index 6cffac60f54b..07a4d9d0fc57 100644
--- a/arch/efi/efi/efi.c
+++ b/arch/efi/efi/efi.c
@@ -52,7 +52,7 @@ 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 = strdup_char_to_wchar(name);
+   s16 *name16 = xstrdup_char_to_wchar(name);
 
efiret = RT-get_variable(name16, vendor, NULL, size, NULL);
 
@@ -87,7 +87,7 @@ 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 = strdup_char_to_wchar(name);
+   s16 *name16 = xstrdup_char_to_wchar(name);
 
efiret = RT-set_variable(name16, vendor, attributes, size, buf);
 
@@ -146,7 +146,7 @@ struct efi_boot *efi_get_boot(int num)
 
ptr += sizeof(u16);
 
-   boot-description = strdup_wchar_to_char(ptr);
+   boot-description = xstrdup_wchar_to_char(ptr);
 
ptr += (strlen(boot-description) + 1) * 2;
 
-- 
2.1.4


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 03/16] efi: improve malloc pool allocation

2015-07-17 Thread Michael Olbrich
Use allocate_pages() instead of allocate_pool(). With allocate_pages() we
can specify the address. This way, any address passed to the kernel will
never exceed the lower 32 bit.
If possible, try to allocate a larger pool.

Signed-off-by: Michael Olbrich m.olbr...@pengutronix.de
---
 arch/efi/efi/efi.c | 20 +---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/arch/efi/efi/efi.c b/arch/efi/efi/efi.c
index d351775a2868..c05d183c02fa 100644
--- a/arch/efi/efi/efi.c
+++ b/arch/efi/efi/efi.c
@@ -310,7 +310,8 @@ device_initcall(efi_init);
  */
 efi_status_t efi_main(efi_handle_t image, efi_system_table_t *sys_table)
 {
-   void *mem;
+   efi_physical_addr_t mem;
+   size_t memsize;
efi_status_t efiret;
 
 #ifdef DEBUG
@@ -332,8 +333,21 @@ efi_status_t efi_main(efi_handle_t image, 
efi_system_table_t *sys_table)
 
fixup_tables();
 
-   BS-allocate_pool(efi_loaded_image-image_data_type, SZ_16M, mem);
-   mem_malloc_init(mem, mem + SZ_16M);
+   mem = 0x3fff;
+   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();
 
-- 
2.1.4


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 08/16] efi: add helper functions to write EFI variables

2015-07-17 Thread Michael Olbrich
Signed-off-by: Michael Olbrich m.olbr...@pengutronix.de
---
 arch/efi/efi/efi.c  | 27 +++
 arch/efi/include/mach/efi.h |  4 
 2 files changed, 31 insertions(+)

diff --git a/arch/efi/efi/efi.c b/arch/efi/efi/efi.c
index c05d183c02fa..b0e98f95b02b 100644
--- a/arch/efi/efi/efi.c
+++ b/arch/efi/efi/efi.c
@@ -83,6 +83,33 @@ out:
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 = strdup_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;
diff --git a/arch/efi/include/mach/efi.h b/arch/efi/include/mach/efi.h
index 1e9782a136c2..2b25cf1868ad 100644
--- a/arch/efi/include/mach/efi.h
+++ b/arch/efi/include/mach/efi.h
@@ -21,4 +21,8 @@ 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 */
-- 
2.1.4


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 06/16] efi: add helper to get the GPT partition UUID for a device

2015-07-17 Thread Michael Olbrich
Signed-off-by: Michael Olbrich m.olbr...@pengutronix.de
---
v2: use xasprintf()

 common/efi-devicepath.c | 30 ++
 include/efi.h   |  1 +
 2 files changed, 31 insertions(+)

diff --git a/common/efi-devicepath.c b/common/efi-devicepath.c
index a53c6d2e8b9b..a1cd0952f929 100644
--- a/common/efi-devicepath.c
+++ b/common/efi-devicepath.c
@@ -1383,3 +1383,33 @@ u8 device_path_to_type(struct efi_device_path *dev_path)
 
return device_path_type(dev_path);
 }
+
+char *device_path_to_partuuid(struct efi_device_path *dev_path)
+{
+   struct efi_device_path *dev_path_node;
+   struct harddrive_device_path *hd;
+   char *str = NULL;;
+
+   dev_path = unpack_device_path(dev_path);
+
+   for (dev_path_node = dev_path; !is_device_path_end(dev_path_node);
+dev_path_node = next_device_path_node(dev_path_node)) {
+
+   if (device_path_type(dev_path_node) != MEDIA_DEVICE_PATH)
+   continue;
+
+   if (dev_path_node-sub_type != MEDIA_HARDDRIVE_DP)
+   continue;
+
+   hd = (struct harddrive_device_path *)dev_path_node;
+
+   if (hd-signature_type != SIGNATURE_TYPE_GUID)
+   continue;
+
+   str = xasprintf(%pU), (efi_guid_t *)(hd-signature[0]));
+   break;
+   }
+
+   return str;
+}
+
diff --git a/include/efi.h b/include/efi.h
index e79a407bc2c8..b6ee42b3fd49 100644
--- a/include/efi.h
+++ b/include/efi.h
@@ -624,6 +624,7 @@ static inline int efi_compare_guid(efi_guid_t *a, 
efi_guid_t *b)
 
 char *device_path_to_str(struct efi_device_path *dev_path);
 u8 device_path_to_type(struct efi_device_path *dev_path);
+char *device_path_to_partuuid(struct efi_device_path *dev_path);
 
 const char *efi_guid_string(efi_guid_t *g);
 
-- 
2.1.4


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH 4/7] efi: add helper to get the GPT partition UUID for a device

2015-07-16 Thread Michael Olbrich
On Thu, Jul 16, 2015 at 11:34:25AM +0200, Marc Kleine-Budde wrote:
 On 07/16/2015 10:43 AM, Michael Olbrich wrote:
  Signed-off-by: Michael Olbrich m.olbr...@pengutronix.de
  ---
   common/efi-devicepath.c | 31 +++
   include/efi.h   |  1 +
   2 files changed, 32 insertions(+)
  
  diff --git a/common/efi-devicepath.c b/common/efi-devicepath.c
  index a53c6d2e8b9b..fdb86afc8eca 100644
  --- a/common/efi-devicepath.c
  +++ b/common/efi-devicepath.c
  @@ -1383,3 +1383,34 @@ u8 device_path_to_type(struct efi_device_path 
  *dev_path)
   
  return device_path_type(dev_path);
   }
  +
  +char *device_path_to_partuuid(struct efi_device_path *dev_path)
  +{
  +   struct efi_device_path *dev_path_node;
  +   struct harddrive_device_path *hd;
  +   char *str = NULL;;
  +
  +   dev_path = unpack_device_path(dev_path);
  +
  +   for (dev_path_node = dev_path; !is_device_path_end(dev_path_node);
  +dev_path_node = next_device_path_node(dev_path_node)) {
  +
  +   if (device_path_type(dev_path_node) != MEDIA_DEVICE_PATH)
  +   continue;
  +
  +   if (dev_path_node-sub_type != MEDIA_HARDDRIVE_DP)
  +   continue;
  +
  +   hd = (struct harddrive_device_path *)dev_path_node;
  +
  +   if (hd-signature_type != SIGNATURE_TYPE_GUID)
  +   continue;
  +
  +   str = malloc(sizeof(----)+1);
  +   sprintf(str, %pU), (efi_guid_t *)(hd-signature[0]));
  +   break;
 asprintf()?

Good idea. And I need to add a OOM check.

Michael

-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |

___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 4/7] efi: add helper to get the GPT partition UUID for a device

2015-07-16 Thread Michael Olbrich
Signed-off-by: Michael Olbrich m.olbr...@pengutronix.de
---
 common/efi-devicepath.c | 31 +++
 include/efi.h   |  1 +
 2 files changed, 32 insertions(+)

diff --git a/common/efi-devicepath.c b/common/efi-devicepath.c
index a53c6d2e8b9b..fdb86afc8eca 100644
--- a/common/efi-devicepath.c
+++ b/common/efi-devicepath.c
@@ -1383,3 +1383,34 @@ u8 device_path_to_type(struct efi_device_path *dev_path)
 
return device_path_type(dev_path);
 }
+
+char *device_path_to_partuuid(struct efi_device_path *dev_path)
+{
+   struct efi_device_path *dev_path_node;
+   struct harddrive_device_path *hd;
+   char *str = NULL;;
+
+   dev_path = unpack_device_path(dev_path);
+
+   for (dev_path_node = dev_path; !is_device_path_end(dev_path_node);
+dev_path_node = next_device_path_node(dev_path_node)) {
+
+   if (device_path_type(dev_path_node) != MEDIA_DEVICE_PATH)
+   continue;
+
+   if (dev_path_node-sub_type != MEDIA_HARDDRIVE_DP)
+   continue;
+
+   hd = (struct harddrive_device_path *)dev_path_node;
+
+   if (hd-signature_type != SIGNATURE_TYPE_GUID)
+   continue;
+
+   str = malloc(sizeof(----)+1);
+   sprintf(str, %pU), (efi_guid_t *)(hd-signature[0]));
+   break;
+   }
+
+   return str;
+}
+
diff --git a/include/efi.h b/include/efi.h
index e79a407bc2c8..b6ee42b3fd49 100644
--- a/include/efi.h
+++ b/include/efi.h
@@ -624,6 +624,7 @@ static inline int efi_compare_guid(efi_guid_t *a, 
efi_guid_t *b)
 
 char *device_path_to_str(struct efi_device_path *dev_path);
 u8 device_path_to_type(struct efi_device_path *dev_path);
+char *device_path_to_partuuid(struct efi_device_path *dev_path);
 
 const char *efi_guid_string(efi_guid_t *g);
 
-- 
2.1.4


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 7/7] efi: write volatile EFI variables used by systemd

2015-07-16 Thread Michael Olbrich
LoaderTimeInitUSec and LoaderTimeExecUSec are used e.g. in systemd-analyze
to calculate the time spent in the firmare and barebox.

LoaderDevicePartUUID is used to mount the EFI partition to /boot.

Signed-off-by: Michael Olbrich m.olbr...@pengutronix.de
---
 arch/efi/efi/efi-image.c |  5 +
 arch/efi/efi/efi.c   | 14 ++
 common/efi-guid.c|  1 +
 include/efi.h|  5 +
 4 files changed, 25 insertions(+)

diff --git a/arch/efi/efi/efi-image.c b/arch/efi/efi/efi-image.c
index f41322744bbc..89b712baab1f 100644
--- a/arch/efi/efi/efi-image.c
+++ b/arch/efi/efi/efi-image.c
@@ -17,6 +17,7 @@
  *
  */
 
+#include clock.h
 #include common.h
 #include linux/sizes.h
 #include memory.h
@@ -242,6 +243,10 @@ static int do_bootm_efi(struct image_data *data)
   boot_header-ramdisk_image);
printf(...\n);
}
+
+   efi_set_variable_usec(LoaderTimeExecUSec, efi_systemd_vendor_guid,
+ get_time_ns()/1000);
+
linux_efi_handover(handle, boot_header);
 
return 0;
diff --git a/arch/efi/efi/efi.c b/arch/efi/efi/efi.c
index b0e98f95b02b..a665a546be90 100644
--- a/arch/efi/efi/efi.c
+++ b/arch/efi/efi/efi.c
@@ -340,6 +340,7 @@ 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, Lbarebox\n);
@@ -377,6 +378,19 @@ efi_status_t efi_main(efi_handle_t image, 
efi_system_table_t *sys_table)
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 = strdup_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));
+   }
 
start_barebox();
 
diff --git a/common/efi-guid.c b/common/efi-guid.c
index f6b040410522..f4ff7feadfe4 100644
--- a/common/efi-guid.c
+++ b/common/efi-guid.c
@@ -9,6 +9,7 @@ efi_guid_t efi_unknown_device_guid = EFI_UNKNOWN_DEVICE_GUID;
 efi_guid_t efi_null_guid = EFI_NULL_GUID;
 efi_guid_t efi_global_variable_guid = EFI_GLOBAL_VARIABLE_GUID;
 efi_guid_t efi_block_io_protocol_guid = EFI_BLOCK_IO_PROTOCOL_GUID;
+efi_guid_t efi_systemd_vendor_guid = EFI_SYSTEMD_VENDOR_GUID;
 
 #define EFI_GUID_STRING(guid, short, long) do {\
if (!efi_guidcmp(guid, *g)) \
diff --git a/include/efi.h b/include/efi.h
index 830e0457dd1c..5b0de119fb74 100644
--- a/include/efi.h
+++ b/include/efi.h
@@ -473,6 +473,10 @@ extern efi_runtime_services_t *RT;
 #define EFI_BAREBOX_VENDOR_GUID \
EFI_GUID(0x5b91f69c, 0x8b88, 0x4a2b, 0x92, 0x69, 0x5f, 0x1d, 0x80, 
0x2b, 0x51, 0x75)
 
+/* for systemd */
+#define EFI_SYSTEMD_VENDOR_GUID \
+   EFI_GUID(0x4a67b082, 0x0a4c, 0x41cf, 0xb6, 0xc7, 0x44, 0x0b, 0x29, 
0xbb, 0x8c, 0x4f)
+
 extern efi_guid_t efi_file_info_id;
 extern efi_guid_t efi_simple_file_system_protocol_guid;
 extern efi_guid_t efi_device_path_protocol_guid;
@@ -481,6 +485,7 @@ extern efi_guid_t efi_unknown_device_guid;
 extern efi_guid_t efi_null_guid;
 extern efi_guid_t efi_global_variable_guid;
 extern efi_guid_t efi_block_io_protocol_guid;
+extern efi_guid_t efi_systemd_vendor_guid;
 
 #define EFI_SYSTEM_TABLE_SIGNATURE ((u64)0x5453595320494249ULL)
 
-- 
2.1.4


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 1/7] efi: improve malloc pool allocation

2015-07-16 Thread Michael Olbrich
Use allocate_pages() instead of allocate_pool(). With allocate_pages() we
can specify the address. This way, any address passed to the kernel will
never exceed the lower 32 bit.
If possible, try to allocate a larger pool.

Signed-off-by: Michael Olbrich m.olbr...@pengutronix.de
---
 arch/efi/efi/efi.c | 20 +---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/arch/efi/efi/efi.c b/arch/efi/efi/efi.c
index d351775a2868..c05d183c02fa 100644
--- a/arch/efi/efi/efi.c
+++ b/arch/efi/efi/efi.c
@@ -310,7 +310,8 @@ device_initcall(efi_init);
  */
 efi_status_t efi_main(efi_handle_t image, efi_system_table_t *sys_table)
 {
-   void *mem;
+   efi_physical_addr_t mem;
+   size_t memsize;
efi_status_t efiret;
 
 #ifdef DEBUG
@@ -332,8 +333,21 @@ efi_status_t efi_main(efi_handle_t image, 
efi_system_table_t *sys_table)
 
fixup_tables();
 
-   BS-allocate_pool(efi_loaded_image-image_data_type, SZ_16M, mem);
-   mem_malloc_init(mem, mem + SZ_16M);
+   mem = 0x3fff;
+   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();
 
-- 
2.1.4


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 0/7] EFI updates

2015-07-16 Thread Michael Olbrich
Hi,

Just some changes to improve initrd handling and better integration with
systemd. Tested with qemu and my laptop. Booting Debian with works without
problems.

Michael

Michael Olbrich (7):
  efi: improve malloc pool allocation
  efi: refactor  improve application loading code
  efi: add support for initrd loading
  efi: add helper to get the GPT partition UUID for a device
  efi: export device_path_from_handle()
  efi: add helper functions to write EFI variables
  efi: write volatile EFI variables used by systemd

 arch/efi/efi/efi-image.c| 198 +---
 arch/efi/efi/efi.c  |  61 +-
 arch/efi/include/mach/efi.h |   4 +
 common/efi-devicepath.c |  31 +++
 common/efi-guid.c   |   1 +
 include/efi.h   |   9 +-
 6 files changed, 287 insertions(+), 17 deletions(-)

-- 
2.1.4


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 2/7] efi: refactor improve application loading code

2015-07-16 Thread Michael Olbrich
Signed-off-by: Michael Olbrich m.olbr...@pengutronix.de
---

checkpatch.pl complains about the header change here. My change matches the
surrounding declarations, so I left it like this.

 arch/efi/efi/efi-image.c | 57 ++--
 include/efi.h|  2 +-
 2 files changed, 46 insertions(+), 13 deletions(-)

diff --git a/arch/efi/efi/efi-image.c b/arch/efi/efi/efi-image.c
index f7bda8dfcb2a..a36a38147657 100644
--- a/arch/efi/efi/efi-image.c
+++ b/arch/efi/efi/efi-image.c
@@ -37,14 +37,13 @@
 #include mach/efi.h
 #include mach/efi-device.h
 
-static int efi_execute_image(const char *file)
+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;
-   const char *options;
-   efi_loaded_image_t *loaded_image;
+   efi_status_t efiret = EFI_SUCCESS;
 
exe = read_file(file, size);
if (!exe)
@@ -54,25 +53,59 @@ static int efi_execute_image(const char *file)
handle);
if (EFI_ERROR(efiret)) {
pr_err(failed to LoadImage: %s\n, efi_strerror(efiret));
-   return -efi_errno(efiret);;
+   goto out;
};
 
efiret = BS-open_protocol(handle, efi_loaded_image_protocol_guid,
-   (void **)loaded_image,
+   (void **)loaded_image,
efi_parent_image, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL);
-   if (EFI_ERROR(efiret))
-   return -efi_errno(efiret);
+   if (EFI_ERROR(efiret)) {
+   pr_err(failed to OpenProtocol: %s\n, efi_strerror(efiret));
+   BS-unload_image(handle);
+   goto out;
+   }
 
-   options = linux_bootargs_get();
-   loaded_image-load_options = strdup_char_to_wchar(options);
-   loaded_image-load_options_size = (strlen(options) + 1) * 
sizeof(wchar_t);
+   *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;
+   int ret;
+
+   ret = efi_load_image(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) {
+   pr_debug(Linux kernel detected. Adding bootargs.);
+   options = linux_bootargs_get();
+   pr_err(add linux options '%s'\n, options);
+   loaded_image-load_options = strdup_char_to_wchar(options);
+   loaded_image-load_options_size =
+   (strlen(options) + 1) * sizeof(wchar_t);
+   }
 
efiret = BS-start_image(handle, NULL, NULL);
+   if (EFI_ERROR(efiret))
+   pr_err(failed to StartImage: %s\n, efi_strerror(efiret));
+
+   BS-unload_image(handle);
 
efi_connect_all();
efi_register_devices();
 
-   return 0;
+   return -efi_errno(efiret);
 }
 
 static int do_bootm_efi(struct image_data *data)
diff --git a/include/efi.h b/include/efi.h
index 9b4f16bd9f54..e79a407bc2c8 100644
--- a/include/efi.h
+++ b/include/efi.h
@@ -211,7 +211,7 @@ typedef struct {
unsigned long *exitdata_size, s16 **exitdata);
efi_status_t(EFIAPI *exit)(efi_handle_t handle,  efi_status_t 
exit_status,
unsigned long exitdata_size, s16 *exitdata);
-   void *unload_image;
+   efi_status_t (EFIAPI *unload_image)(efi_handle_t handle);
efi_status_t (EFIAPI *exit_boot_services)(efi_handle_t, unsigned long);
void *get_next_monotonic_count;
efi_status_t (EFIAPI *stall)(unsigned long usecs);
-- 
2.1.4


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 3/7] efi: add support for initrd loading

2015-07-16 Thread Michael Olbrich
The kernel EFI code can load the initrd from a path. However, that only
works if the initrd is in the EFI boot partition. With these changes, any
initrd accessible by barebox can be used.

Signed-off-by: Michael Olbrich m.olbr...@pengutronix.de
---
 arch/efi/efi/efi-image.c | 136 ++-
 1 file changed, 135 insertions(+), 1 deletion(-)

diff --git a/arch/efi/efi/efi-image.c b/arch/efi/efi/efi-image.c
index a36a38147657..f41322744bbc 100644
--- a/arch/efi/efi/efi-image.c
+++ b/arch/efi/efi/efi-image.c
@@ -37,6 +37,55 @@
 #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)
 {
@@ -108,9 +157,94 @@ static int efi_execute_image(const char *file)
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)
 {
-   return efi_execute_image(data-os_file);
+   void *tmp;
+   void *initrd;
+   size_t size;
+   efi_handle_t handle;
+   int ret;
+   const char *options;
+   efi_loaded_image_t *loaded_image;
+   struct linux_kernel_header

[PATCH 6/7] efi: add helper functions to write EFI variables

2015-07-16 Thread Michael Olbrich
Signed-off-by: Michael Olbrich m.olbr...@pengutronix.de
---
 arch/efi/efi/efi.c  | 27 +++
 arch/efi/include/mach/efi.h |  4 
 2 files changed, 31 insertions(+)

diff --git a/arch/efi/efi/efi.c b/arch/efi/efi/efi.c
index c05d183c02fa..b0e98f95b02b 100644
--- a/arch/efi/efi/efi.c
+++ b/arch/efi/efi/efi.c
@@ -83,6 +83,33 @@ out:
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 = strdup_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;
diff --git a/arch/efi/include/mach/efi.h b/arch/efi/include/mach/efi.h
index 1e9782a136c2..2b25cf1868ad 100644
--- a/arch/efi/include/mach/efi.h
+++ b/arch/efi/include/mach/efi.h
@@ -21,4 +21,8 @@ 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 */
-- 
2.1.4


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 5/7] efi: export device_path_from_handle()

2015-07-16 Thread Michael Olbrich
Signed-off-by: Michael Olbrich m.olbr...@pengutronix.de
---
 include/efi.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/efi.h b/include/efi.h
index b6ee42b3fd49..830e0457dd1c 100644
--- a/include/efi.h
+++ b/include/efi.h
@@ -622,6 +622,7 @@ static inline int efi_compare_guid(efi_guid_t *a, 
efi_guid_t *b)
return memcmp(a, b, sizeof(efi_guid_t));
 }
 
+struct efi_device_path *device_path_from_handle(efi_handle_t Handle);
 char *device_path_to_str(struct efi_device_path *dev_path);
 u8 device_path_to_type(struct efi_device_path *dev_path);
 char *device_path_to_partuuid(struct efi_device_path *dev_path);
-- 
2.1.4


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH] ARM Samsung: add simple NAND barebox update handler

2015-02-25 Thread Michael Olbrich
Signed-off-by: Michael Olbrich m.olbr...@pengutronix.de
---
v2: write to the non bb device.

That means, write() will fail, when it hits a bad block, right?

Michael

 arch/arm/boards/friendlyarm-mini2440/mini2440.c |  3 +
 arch/arm/mach-samsung/Kconfig   |  6 ++
 arch/arm/mach-samsung/Makefile  |  1 +
 arch/arm/mach-samsung/bbu-nand-s3c24x0.c| 87 +
 arch/arm/mach-samsung/include/mach/bbu.h| 20 ++
 5 files changed, 117 insertions(+)
 create mode 100644 arch/arm/mach-samsung/bbu-nand-s3c24x0.c
 create mode 100644 arch/arm/mach-samsung/include/mach/bbu.h

diff --git a/arch/arm/boards/friendlyarm-mini2440/mini2440.c 
b/arch/arm/boards/friendlyarm-mini2440/mini2440.c
index 2dcb7db4dbde..b9e1b6bb9d52 100644
--- a/arch/arm/boards/friendlyarm-mini2440/mini2440.c
+++ b/arch/arm/boards/friendlyarm-mini2440/mini2440.c
@@ -29,6 +29,7 @@
 #include asm/sections.h
 #include io.h
 #include gpio.h
+#include mach/bbu.h
 #include mach/iomux.h
 #include mach/s3c-iomap.h
 #include mach/devices-s3c24xx.h
@@ -300,6 +301,8 @@ static int mini2440_devices_init(void)
devfs_del_partition(env_raw);
devfs_add_partition(nand0, 0x4, 0x2, DEVFS_PARTITION_FIXED, 
env_raw);
dev_add_bb_dev(env_raw, env0);
+
+   s3c24x0_bbu_nand_register_handler();
 #endif
s3c24xx_add_mci(mci_data);
s3c24xx_add_fb(s3c24x0_fb_data);
diff --git a/arch/arm/mach-samsung/Kconfig b/arch/arm/mach-samsung/Kconfig
index 13dac29dcc88..8f421bb83970 100644
--- a/arch/arm/mach-samsung/Kconfig
+++ b/arch/arm/mach-samsung/Kconfig
@@ -166,6 +166,12 @@ config S3C_NAND_BOOT
  Add generic support to boot from NAND flash. Image loading will be
  skipped if the code is running from NOR or already from SDRAM.
 
+config BAREBOX_UPDATE_NAND_S3C24XX
+   bool
+   depends on BAREBOX_UPDATE
+   depends on S3C_NAND_BOOT
+   default y
+
 endmenu
 
 endif
diff --git a/arch/arm/mach-samsung/Makefile b/arch/arm/mach-samsung/Makefile
index 46393e17257c..284c80a2ad43 100644
--- a/arch/arm/mach-samsung/Makefile
+++ b/arch/arm/mach-samsung/Makefile
@@ -8,4 +8,5 @@ obj-$(CONFIG_ARCH_S3C24xx) += gpio-s3c24x0.o clocks-s3c24xx.o 
mem-s3c24x0.o
 obj-$(CONFIG_ARCH_S3C64xx) += gpio-s3c64xx.o clocks-s3c64xx.o mem-s3c64xx.o
 obj-$(CONFIG_ARCH_S5PCxx) += gpio-s5pcxx.o clocks-s5pcxx.o mem-s5pcxx.o
 pbl-$(CONFIG_ARCH_S5PCxx) += mem-s5pcxx.o
+obj-$(CONFIG_BAREBOX_UPDATE_NAND_S3C24XX) += bbu-nand-s3c24x0.o
 obj-$(CONFIG_S3C_LOWLEVEL_INIT) += $(obj-lowlevel-y)
diff --git a/arch/arm/mach-samsung/bbu-nand-s3c24x0.c 
b/arch/arm/mach-samsung/bbu-nand-s3c24x0.c
new file mode 100644
index ..f3584eaa5a0c
--- /dev/null
+++ b/arch/arm/mach-samsung/bbu-nand-s3c24x0.c
@@ -0,0 +1,87 @@
+/*
+ * Copyright (C) 2014 Michael Olbrich, Pengutronix
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation.
+ *
+ */
+
+#define DEBUG
+#include common.h
+#include malloc.h
+#include bbu.h
+#include fs.h
+#include fcntl.h
+
+static int nand_update(struct bbu_handler *handler, struct bbu_data *data)
+{
+   int fd, ret;
+
+   if (file_detect_type(data-image, data-len) != filetype_arm_barebox 
+   !bbu_force(data, Not an ARM barebox image))
+   return -EINVAL;
+
+   ret = bbu_confirm(data);
+   if (ret)
+   return ret;
+
+   fd = open(data-devicefile, O_WRONLY);
+   if (fd  0)
+   return fd;
+
+   debug(%s: eraseing %s from 0 to 0x%08x\n, __func__,
+   data-devicefile, data-len);
+   ret = erase(fd, data-len, 0);
+   if (ret) {
+   printf(erasing %s failed with %s\n, data-devicefile,
+   strerror(-ret));
+   goto err_close;
+   }
+
+   ret = write(fd, data-image, data-len);
+   if (ret  0) {
+   printf(writing update to %s failed with %s\n, 
data-devicefile,
+   strerror(-ret));
+   goto err_close;
+   }
+
+   ret = 0;
+
+err_close:
+   close(fd);
+
+   return ret;
+}
+
+/*
+ * Register a s3c24x0 update handler for NAND
+ */
+int s3c24x0_bbu_nand_register_handler(void)
+{
+   struct bbu_handler *handler;
+   int ret;
+
+   handler = xzalloc(sizeof(*handler));
+   handler-devicefile = /dev/nand0.barebox

[PATCH 3/3] ARM Samsung: add simple NAND barebox update handler

2015-02-24 Thread Michael Olbrich
Signed-off-by: Michael Olbrich m.olbr...@pengutronix.de
---

I'm not sure if writing to /dev/nand0.barebox.bb is correct. But from what
I can tell, the nand boot code cannot handle bad blocks, so it probably
doesn't matter anyways.

Michael

 arch/arm/boards/friendlyarm-mini2440/mini2440.c |  3 +
 arch/arm/mach-samsung/Kconfig   |  6 ++
 arch/arm/mach-samsung/Makefile  |  1 +
 arch/arm/mach-samsung/bbu-nand-s3c24x0.c| 84 +
 arch/arm/mach-samsung/include/mach/bbu.h| 20 ++
 5 files changed, 114 insertions(+)
 create mode 100644 arch/arm/mach-samsung/bbu-nand-s3c24x0.c
 create mode 100644 arch/arm/mach-samsung/include/mach/bbu.h

diff --git a/arch/arm/boards/friendlyarm-mini2440/mini2440.c 
b/arch/arm/boards/friendlyarm-mini2440/mini2440.c
index af6da72d3a2f..b59c8367f306 100644
--- a/arch/arm/boards/friendlyarm-mini2440/mini2440.c
+++ b/arch/arm/boards/friendlyarm-mini2440/mini2440.c
@@ -29,6 +29,7 @@
 #include asm/sections.h
 #include io.h
 #include gpio.h
+#include mach/bbu.h
 #include mach/iomux.h
 #include mach/s3c-iomap.h
 #include mach/devices-s3c24xx.h
@@ -317,6 +318,8 @@ static int mini2440_devices_init(void)
devfs_del_partition(env_raw);
devfs_add_partition(nand0, 0x4, 0x2, DEVFS_PARTITION_FIXED, 
env_raw);
dev_add_bb_dev(env_raw, env0);
+
+   s3c24x0_bbu_nand_register_handler();
 #endif
s3c24xx_add_mci(mci_data);
s3c24xx_add_fb(s3c24x0_fb_data);
diff --git a/arch/arm/mach-samsung/Kconfig b/arch/arm/mach-samsung/Kconfig
index 13dac29dcc88..8f421bb83970 100644
--- a/arch/arm/mach-samsung/Kconfig
+++ b/arch/arm/mach-samsung/Kconfig
@@ -166,6 +166,12 @@ config S3C_NAND_BOOT
  Add generic support to boot from NAND flash. Image loading will be
  skipped if the code is running from NOR or already from SDRAM.
 
+config BAREBOX_UPDATE_NAND_S3C24XX
+   bool
+   depends on BAREBOX_UPDATE
+   depends on S3C_NAND_BOOT
+   default y
+
 endmenu
 
 endif
diff --git a/arch/arm/mach-samsung/Makefile b/arch/arm/mach-samsung/Makefile
index 46393e17257c..284c80a2ad43 100644
--- a/arch/arm/mach-samsung/Makefile
+++ b/arch/arm/mach-samsung/Makefile
@@ -8,4 +8,5 @@ obj-$(CONFIG_ARCH_S3C24xx) += gpio-s3c24x0.o clocks-s3c24xx.o 
mem-s3c24x0.o
 obj-$(CONFIG_ARCH_S3C64xx) += gpio-s3c64xx.o clocks-s3c64xx.o mem-s3c64xx.o
 obj-$(CONFIG_ARCH_S5PCxx) += gpio-s5pcxx.o clocks-s5pcxx.o mem-s5pcxx.o
 pbl-$(CONFIG_ARCH_S5PCxx) += mem-s5pcxx.o
+obj-$(CONFIG_BAREBOX_UPDATE_NAND_S3C24XX) += bbu-nand-s3c24x0.o
 obj-$(CONFIG_S3C_LOWLEVEL_INIT) += $(obj-lowlevel-y)
diff --git a/arch/arm/mach-samsung/bbu-nand-s3c24x0.c 
b/arch/arm/mach-samsung/bbu-nand-s3c24x0.c
new file mode 100644
index ..6009151c88be
--- /dev/null
+++ b/arch/arm/mach-samsung/bbu-nand-s3c24x0.c
@@ -0,0 +1,84 @@
+/*
+ * Copyright (C) 2014 Michael Olbrich, Pengutronix
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation.
+ *
+ */
+
+#define DEBUG
+#include common.h
+#include malloc.h
+#include bbu.h
+#include fs.h
+#include fcntl.h
+
+static int nand_update(struct bbu_handler *handler, struct bbu_data *data)
+{
+   int fd, ret;
+
+   if (file_detect_type(data-image, data-len) != filetype_arm_barebox 
+   !bbu_force(data, Not an ARM barebox image))
+   return -EINVAL;
+
+   ret = bbu_confirm(data);
+   if (ret)
+   return ret;
+
+   fd = open(data-devicefile, O_WRONLY);
+   if (fd  0)
+   return fd;
+
+   debug(%s: eraseing %s from 0 to 0x%08x\n, __func__,
+   data-devicefile, data-len);
+   ret = erase(fd, data-len, 0);
+   if (ret) {
+   printf(erasing %s failed with %s\n, data-devicefile,
+   strerror(-ret));
+   goto err_close;
+   }
+
+   ret = write(fd, data-image, data-len);
+   if (ret  0)
+   goto err_close;
+
+   ret = 0;
+
+err_close:
+   close(fd);
+
+   return ret;
+}
+
+/*
+ * Register a s3c24x0 update handler for NAND
+ */
+int s3c24x0_bbu_nand_register_handler(void)
+{
+   struct bbu_handler *handler;
+   int ret;
+
+   handler = xzalloc(sizeof(*handler));
+   handler-devicefile = /dev/nand0.barebox.bb;
+   handler-name = nand;
+   handler-handler = nand_update

[PATCH 2/3] friendlyarm-mini2440: add support for the W35 display

2015-02-24 Thread Michael Olbrich
Signed-off-by: Michael Olbrich m.olbr...@pengutronix.de
---

I'm not quite sure about the sync flags. I tried to match what the kernel
does and it looks correct here.

Michael

 arch/arm/boards/friendlyarm-mini2440/Kconfig|  6 ++
 arch/arm/boards/friendlyarm-mini2440/mini2440.c | 17 +
 2 files changed, 23 insertions(+)

diff --git a/arch/arm/boards/friendlyarm-mini2440/Kconfig 
b/arch/arm/boards/friendlyarm-mini2440/Kconfig
index a8e79b3b076b..feb905e96e33 100644
--- a/arch/arm/boards/friendlyarm-mini2440/Kconfig
+++ b/arch/arm/boards/friendlyarm-mini2440/Kconfig
@@ -25,4 +25,10 @@ config MINI2440_VIDEO_SVGA
help
  This adds support for MINI2440 SVGA (1024x768) video output adapter.
 
+config MINI2440_VIDEO_W35
+   bool Support W35 display (320x240)
+   select MINI2440_VIDEO
+   help
+ This adds support for Sharp 3.5 inch TFT display.
+
 endif
diff --git a/arch/arm/boards/friendlyarm-mini2440/mini2440.c 
b/arch/arm/boards/friendlyarm-mini2440/mini2440.c
index 2dcb7db4dbde..af6da72d3a2f 100644
--- a/arch/arm/boards/friendlyarm-mini2440/mini2440.c
+++ b/arch/arm/boards/friendlyarm-mini2440/mini2440.c
@@ -116,6 +116,23 @@ static struct fb_videomode s3c24x0_fb_modes[] = {
.vmode  = FB_VMODE_NONINTERLACED,
},
 #endif
+#ifdef CONFIG_MINI2440_VIDEO_W35
+   {
+   .name   = W35,
+   .refresh= 60,
+   .xres   = 320,
+   .left_margin= 68,
+   .right_margin   = 66,
+   .hsync_len  = 4,
+   .yres   = 240,
+   .upper_margin   = 4,
+   .lower_margin   = 4,
+   .vsync_len  = 9,
+   .pixclock   = 115913,
+   .sync   = FB_SYNC_USE_PWREN | FB_SYNC_CLK_INVERT,
+   .vmode  = FB_VMODE_NONINTERLACED,
+   },
+#endif
 };
 
 static struct s3c_fb_platform_data s3c24x0_fb_data = {
-- 
2.1.4


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 1/3] ARM Samsung: fix booting from NAND without pbl

2015-02-24 Thread Michael Olbrich
This was broken in 558d72dc5116 (ARM Samsung: fix booting from NAND with
pbl). '_text' is TEXT_BASE when building without pbl and (TEXT_BASE -
SZ_2M) when building with pbl, so this works in both cases.

Signed-off-by: Michael Olbrich m.olbr...@pengutronix.de
---

I hope I understood how this should work and this is correct now. It worked
for me with and without pbl. Anything else that could mess this up?

Michael

 arch/arm/mach-samsung/lowlevel-s3c24x0.S | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/arch/arm/mach-samsung/lowlevel-s3c24x0.S 
b/arch/arm/mach-samsung/lowlevel-s3c24x0.S
index 626ad0418778..d43cdff52863 100644
--- a/arch/arm/mach-samsung/lowlevel-s3c24x0.S
+++ b/arch/arm/mach-samsung/lowlevel-s3c24x0.S
@@ -15,7 +15,6 @@
  */
 
 #include config.h
-#include linux/sizes.h
 #include mach/s3c-iomap.h
 
.section .text_bare_init.s3c24x0_disable_wd,ax
@@ -251,7 +250,7 @@ s3c24x0_nand_boot:
beq 2f
mov pc, lr  /* NOR case: nothing to do here */
 
-2: ldr sp, =(TEXT_BASE - SZ_2M)/* Setup a temporary stack in SDRAM */
+2: ldr sp, =_text  /* Setup a temporary stack in SDRAM */
 /*
  * We still run at a location we are not linked to. But lets still running
  * from the internal SRAM, this may speed up the boot
@@ -262,7 +261,7 @@ s3c24x0_nand_boot:
 /*
  * Adjust the return address to the correct address in SDRAM
  */
-   ldr r1, =(TEXT_BASE - SZ_2M)
+   ldr r1, =_text
add lr, lr, r1
 
mov pc, lr
-- 
2.1.4


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH] defaultenv-2: init: don't call timeout again if the user intervened

2015-02-16 Thread Michael Olbrich
With autoboot_timeout=0 the second 'timeout' might not get another
character even if the user keeps a key pressed. So just reuse the key from
the first call.

Signed-off-by: Michael Olbrich m.olbr...@pengutronix.de
---
 defaultenv/defaultenv-2-base/bin/init | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/defaultenv/defaultenv-2-base/bin/init 
b/defaultenv/defaultenv-2-base/bin/init
index 34807bcf585d..30651e55d277 100644
--- a/defaultenv/defaultenv-2-base/bin/init
+++ b/defaultenv/defaultenv-2-base/bin/init
@@ -37,6 +37,7 @@ fi
 # allow to stop the boot before execute the /env/init/*
 # but without waiting
 timeout -s -a -v key 0
+autoboot=$?
 
 if [ ${key} = q ]; then
${login_cmd}
@@ -57,8 +58,10 @@ fi
 
 [ -n ${login_cmd} ]  global.console.input_allow=1
 
-timeout -a $global.autoboot_timeout -v key
-autoboot=$?
+if [ $autoboot = 0 ]; then
+   timeout -a $global.autoboot_timeout -v key
+   autoboot=$?
+fi
 
 [ -n ${login_cmd} ]  global.console.input_allow=0
 
-- 
2.1.4


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


  1   2   >