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

2017-10-27 Thread Jean-Christophe PLAGNIOL-VILLARD
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.

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagn...@jcrosoft.com>
---
 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


[PATCH 1/2] efi-gui: add USB IO Protocol GUID definition

2017-10-27 Thread Jean-Christophe PLAGNIOL-VILLARD
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagn...@jcrosoft.com>
---
 common/efi-guid.c | 1 +
 include/efi.h | 3 +++
 2 files changed, 4 insertions(+)

diff --git a/common/efi-guid.c b/common/efi-guid.c
index 71aa21ddd..1e45ccf4d 100644
--- a/common/efi-guid.c
+++ b/common/efi-guid.c
@@ -35,6 +35,7 @@ const char *efi_guid_string(efi_guid_t *g)
EFI_GUID_STRING(EFI_UGA_PROTOCOL_GUID, "UGA Draw Protocol", "EFI 1.1 
UGA Draw Protocol");
EFI_GUID_STRING(EFI_UGA_IO_PROTOCOL_GUID, "UGA Protocol", "EFI 1.1 UGA 
Protocol");
EFI_GUID_STRING(EFI_PCI_IO_PROTOCOL_GUID, "PCI IO Protocol", "EFI 1.1 
PCI IO Protocol");
+   EFI_GUID_STRING(EFI_USB_IO_PROTOCOL_GUID, "USB IO Protocol", "EFI 1.0 
USB IO Protocol");
EFI_GUID_STRING(EFI_FILE_INFO_GUID, "File Info", "EFI File Infom");
EFI_GUID_STRING(EFI_SIMPLE_FILE_SYSTEM_GUID, "Filesystem", "EFI 1.0 
Simple FileSystem");
EFI_GUID_STRING(EFI_DEVICE_TREE_GUID, "Device Tree", "EFI Device Tree 
GUID");
diff --git a/include/efi.h b/include/efi.h
index e1fc134ee..7cc5fe05f 100644
--- a/include/efi.h
+++ b/include/efi.h
@@ -358,6 +358,9 @@ extern efi_runtime_services_t *RT;
 #define EFI_PCI_IO_PROTOCOL_GUID \
 EFI_GUID(  0x4cf5b200, 0x68b8, 0x4ca5, 0x9e, 0xec, 0xb2, 0x3e, 0x3f, 0x50, 
0x2, 0x9a )
 
+#define EFI_USB_IO_PROTOCOL_GUID \
+EFI_GUID(0x2B2F68D6, 0x0CD2, 0x44cf, 0x8E, 0x8B, 0xBB, 0xA2, 0x0B, 0x1B, 
0x5B, 0x75)
+
 #define EFI_FILE_INFO_GUID \
 EFI_GUID(  0x9576e92, 0x6d3f, 0x11d2, 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 
0x72, 0x3b )
 
-- 
2.11.0


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


Re: [PATCH 1/1] EFI: add poweroff support

2017-10-26 Thread Jean-Christophe PLAGNIOL-VILLARD
wrong patch sorry

Best Regards,
J.

> On 26 Oct 2017, at 5:59 PM, Jean-Christophe PLAGNIOL-VILLARD 
> <plagn...@jcrosoft.com> wrote:
> 
> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagn...@jcrosoft.com>
> ---
> arch/x86/configs/efi_defconfig | 1 +
> common/efi/efi.c   | 7 +++
> drivers/efi/Kconfig| 1 +
> 3 files changed, 9 insertions(+)
> 
> diff --git a/arch/x86/configs/efi_defconfig b/arch/x86/configs/efi_defconfig
> index 0d9a44a4d..5f11c6c4e 100644
> --- a/arch/x86/configs/efi_defconfig
> +++ b/arch/x86/configs/efi_defconfig
> @@ -55,6 +55,7 @@ CONFIG_CMD_CRC_CMP=y
> CONFIG_CMD_MM=y
> CONFIG_CMD_DETECT=y
> CONFIG_CMD_FLASH=y
> +CONFIG_CMD_POWEROFF=y
> CONFIG_CMD_2048=y
> CONFIG_CMD_BAREBOX_UPDATE=y
> CONFIG_CMD_OF_NODE=y
> diff --git a/common/efi/efi.c b/common/efi/efi.c
> index cd4f5f029..96601cfce 100644
> --- a/common/efi/efi.c
> +++ b/common/efi/efi.c
> @@ -289,6 +289,13 @@ static int restart_register_feature(void)
> }
> coredevice_initcall(restart_register_feature);
> 
> +void __noreturn poweroff(void)
> +{
> + RT->reset_system(EFI_RESET_SHUTDOWN, EFI_SUCCESS, 0, NULL);
> +
> + hang();
> +}
> +
> extern char image_base[];
> extern initcall_t __barebox_initcalls_start[], 
> __barebox_early_initcalls_end[],
> __barebox_initcalls_end[];
> diff --git a/drivers/efi/Kconfig b/drivers/efi/Kconfig
> index 2cd9dd504..5c988d2e1 100644
> --- a/drivers/efi/Kconfig
> +++ b/drivers/efi/Kconfig
> @@ -1,2 +1,3 @@
> config EFI_BOOTUP
>   bool
> + select HAS_POWEROFF
> -- 
> 2.11.0
> 


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


[PATCH] EFI: add poweroff support

2017-10-26 Thread Jean-Christophe PLAGNIOL-VILLARD
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagn...@jcrosoft.com>
---
 arch/x86/configs/efi_defconfig |  1 +
 common/efi/efi.c   | 10 ++
 drivers/efi/Kconfig|  1 +
 3 files changed, 12 insertions(+)

diff --git a/arch/x86/configs/efi_defconfig b/arch/x86/configs/efi_defconfig
index 3e83fd92d..fdf092e9b 100644
--- a/arch/x86/configs/efi_defconfig
+++ b/arch/x86/configs/efi_defconfig
@@ -55,6 +55,7 @@ CONFIG_CMD_CRC_CMP=y
 CONFIG_CMD_MM=y
 CONFIG_CMD_DETECT=y
 CONFIG_CMD_FLASH=y
+CONFIG_CMD_POWEROFF=y
 CONFIG_CMD_2048=y
 CONFIG_CMD_BAREBOX_UPDATE=y
 CONFIG_CMD_OF_NODE=y
diff --git a/common/efi/efi.c b/common/efi/efi.c
index 4b42f5d67..561ce4c08 100644
--- a/common/efi/efi.c
+++ b/common/efi/efi.c
@@ -25,6 +25,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -283,9 +284,18 @@ static void __noreturn efi_restart_system(struct 
restart_handler *rst)
hang();
 }
 
+static void __noreturn efi_poweroff_system(struct poweroff_handler *handler)
+{
+   shutdown_barebox();
+   RT->reset_system(EFI_RESET_SHUTDOWN, EFI_SUCCESS, 0, NULL);
+
+   hang();
+}
+
 static int restart_register_feature(void)
 {
restart_handler_register_fn(efi_restart_system);
+   poweroff_handler_register_fn(efi_poweroff_system);
 
return 0;
 }
diff --git a/drivers/efi/Kconfig b/drivers/efi/Kconfig
index 2cd9dd504..5c988d2e1 100644
--- a/drivers/efi/Kconfig
+++ b/drivers/efi/Kconfig
@@ -1,2 +1,3 @@
 config EFI_BOOTUP
bool
+   select HAS_POWEROFF
-- 
2.11.0


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


[PATCH 1/1] EFI: add poweroff support

2017-10-26 Thread Jean-Christophe PLAGNIOL-VILLARD
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagn...@jcrosoft.com>
---
 arch/x86/configs/efi_defconfig | 1 +
 common/efi/efi.c   | 7 +++
 drivers/efi/Kconfig| 1 +
 3 files changed, 9 insertions(+)

diff --git a/arch/x86/configs/efi_defconfig b/arch/x86/configs/efi_defconfig
index 0d9a44a4d..5f11c6c4e 100644
--- a/arch/x86/configs/efi_defconfig
+++ b/arch/x86/configs/efi_defconfig
@@ -55,6 +55,7 @@ CONFIG_CMD_CRC_CMP=y
 CONFIG_CMD_MM=y
 CONFIG_CMD_DETECT=y
 CONFIG_CMD_FLASH=y
+CONFIG_CMD_POWEROFF=y
 CONFIG_CMD_2048=y
 CONFIG_CMD_BAREBOX_UPDATE=y
 CONFIG_CMD_OF_NODE=y
diff --git a/common/efi/efi.c b/common/efi/efi.c
index cd4f5f029..96601cfce 100644
--- a/common/efi/efi.c
+++ b/common/efi/efi.c
@@ -289,6 +289,13 @@ static int restart_register_feature(void)
 }
 coredevice_initcall(restart_register_feature);
 
+void __noreturn poweroff(void)
+{
+   RT->reset_system(EFI_RESET_SHUTDOWN, EFI_SUCCESS, 0, NULL);
+
+   hang();
+}
+
 extern char image_base[];
 extern initcall_t __barebox_initcalls_start[], __barebox_early_initcalls_end[],
  __barebox_initcalls_end[];
diff --git a/drivers/efi/Kconfig b/drivers/efi/Kconfig
index 2cd9dd504..5c988d2e1 100644
--- a/drivers/efi/Kconfig
+++ b/drivers/efi/Kconfig
@@ -1,2 +1,3 @@
 config EFI_BOOTUP
bool
+   select HAS_POWEROFF
-- 
2.11.0


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


Re: move to github

2017-09-19 Thread Jean-Christophe PLAGNIOL-VILLARD

> On 18 Sep 2017, at 3:14 PM, Sascha Hauer  wrote:
> 
> On Thu, Sep 14, 2017 at 05:46:52PM +0800, zjh wrote:
>> I suggest that Barebox migrate to GitHub, which makes it easier to develop.
> 
> Well it makes it easier for some people, but not for others (including
> me atm). I may be convinced if I get more feedback like this in the
> future, but until this is the case: No, sorry.

For people in China such as myself, yes github is quicker than pengutronix

but we can have an automatic mirror on github and keep pengutronix.de as the 
main repository

Best Regards,
J.
> 
> Sascha
> 
> 
> -- 
> 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


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


Re: Observations with AT91SAM9263-EK

2017-07-03 Thread Jean-Christophe PLAGNIOL-VILLARD

> On 4 Jul 2017, at 12:19 AM, Sam Ravnborg  wrote:
> 
> Hi all.
> 
> I recently purchased an AT91SAM9263-EK from ebay and
> have played around a little with barebox.
> For now only some observations.
> 
> I had the impression that I could
> drop AT91BootStrap when using barebox.

Yes Wrote the support for that but on the 9263 you are limited.

you have 2 choice boot a small barebox <= 72kiB

or use a console less barebox to boot the second barebox

as the rom code on at91 will load the barebox from the SD or Nand
into SRAM
> 
> But I could not make it boot until I deployed 
> at91bootstrap (named BOOT.BIN) on the SD-card.
> And I named arch/arm/pbl/zbarebox.bin => u-boot.bin
> on the SD-card.
> 

on 9263ek you have a nor flash so why not flash it

in this case barebox will boot by itself

without the bootstrap

Best Regards,
J. 
> I wanted to boot barebox - but nothing happened.
> So I tried older versions af barebox:
> 
> v2017.06.0 => Boots OK (did not try to load a kernel)
> 
> v2017.07.0 => Boots but emits:
> NULL pointer dereference at address 0x0014
> ### Please RESET the board ###
> (A bit more was written to the serial console)
> 

> master from git => Nothing written to the console at all
> 
> I will as time permits dig deeper into this.
> Seems like we are facing two bugs:
> One that causes the NULL pointer, and another that
> prevents any output.
> 
> As barebox is quick to build and the bug is simple to spot
> I will likely just try to bisect and see where I end up.
> 
>   Sam
> 
> ___
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox


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


Re: [BUG v2017.07.0] readlink -f command broken?

2017-06-30 Thread Jean-Christophe PLAGNIOL-VILLARD
HI,

I wrote the symlink support in barebox

But I Worte a partial support only end path file not dirs

As this is a boot loader not an OS

Best Regards,
J.
> On 30 Jun 2017, at 9:28 PM, Ian Abbott  wrote:
> 
> Hi folks,
> 
> I know there were changes to do with links to directories in v2017.07.0, but 
> this looks like a bug in readlink with the -f option:
> 
> barebox@fred:/ ls -l /mnt/root
> lrwxrwxrwx  7 bin -> usr/bin
> drwxr-xr-x304 boot
> drwxr-xr-x160 dev
> drwxr-xr-x   1920 etc
> drwxrwsr-x160 home
> lrwxrwxrwx  7 lib -> usr/lib
> drwxr-xr-x160 mnt
> dr-xr-xr-x160 proc
> drwx--160 root
> drwxr-xr-x160 run
> lrwxrwxrwx  8 sbin -> usr/sbin
> drwxr-xr-x224 srv
> drwxr-xr-x160 sys
> drwxrwxrwt160 tmp
> drwxr-xr-x480 usr
> drwxr-xr-x544 var
> barebox@fred:/ readlink -f /mnt/root/lib libdir
> barebox@fred:/ echo $libdir
> /usr
> 
> (I expected $libdir to contain "/mnt/root/usr/lib" here, as it did in barebox 
> v2017.06.1.)
> 
> (Let's try it without the -f option)
> 
> barebox@fred:/ readlink /mnt/root/lib libdir2
> barebox@fred:/ echo $libdir2
> usr/lib
> 
> (That is the same as barebox v2017.06.1.)
> 
> -- 
> -=( Ian Abbott @ MEV Ltd.E-mail:  )=-
> -=(  Web: http://www.mev.co.uk/  )=-
> 
> ___
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox


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


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

2017-03-27 Thread Jean-Christophe PLAGNIOL-VILLARD

> On 26 Mar 2017, at 4:23 PM, Michael Olbrich <m.olbr...@pengutronix.de> wrote:
> 
> On Sun, Mar 26, 2017 at 04:44:58AM +0200, Jean-Christophe PLAGNIOL-VILLARD 
> wrote:
>> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagn...@jcrosoft.com>
> 
> Does this realy help? If someone has access to the barebox shell, then
> there are many ways to overwrite the secure boot check.

No have shell support does not mean been allow to by pass secure boot
As you think user interaction vs script

And do not forget the boot sequence can be change by the OS (user)

So we may endup to try to boot other images or boot sequence that use go

Best Regards,
J.


> 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


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


[PATCH 13/13] efi: enable sercure boot support

2017-03-25 Thread Jean-Christophe PLAGNIOL-VILLARD
This will ensure that we just start secured binary
without user confirmation

But for now on we only support EFI correctly signed image to start
Later will allow both.

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagn...@jcrosoft.com>
---
 arch/x86/Kconfig |  1 +
 common/efi/efi-image.c   |  1 +
 drivers/efi/efi-device.c | 13 +++--
 3 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 52ccf4894..65e4c8b7c 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -78,6 +78,7 @@ choice
select EFI_DEVICEPATH
select PRINTF_UUID
select CLOCKSOURCE_EFI_X86
+   select HAS_SECURE_BOOT
 
config X86_BIOS_BRINGUP
bool "16 bit BIOS"
diff --git a/common/efi/efi-image.c b/common/efi/efi-image.c
index 885348da4..6552d803d 100644
--- a/common/efi/efi-image.c
+++ b/common/efi/efi-image.c
@@ -270,6 +270,7 @@ static int do_bootm_efi(struct image_data *data)
 static struct image_handler efi_handle_tr = {
.name = "EFI Application",
.bootm = do_bootm_efi,
+   .is_secure_supported = 1,
.filetype = filetype_exe,
 };
 
diff --git a/drivers/efi/efi-device.c b/drivers/efi/efi-device.c
index 998bda7c6..0a6d7ca4e 100644
--- a/drivers/efi/efi-device.c
+++ b/drivers/efi/efi-device.c
@@ -26,6 +26,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -382,13 +383,20 @@ static int efi_is_setup_mode(void)
return ret != 0;
 }
 
+static int efi_is_secure_mode(void)
+{
+   int secure_boot = efi_is_secure_boot();
+   int setup_mode = efi_is_setup_mode();
+
+   return secure_boot && !setup_mode;
+}
+
 static int efi_init_devices(void)
 {
char *fw_vendor = NULL;
u16 sys_major = efi_sys_table->hdr.revision >> 16;
u16 sys_minor = efi_sys_table->hdr.revision & 0x;
int secure_boot = efi_is_secure_boot();
-   int setup_mode = efi_is_setup_mode();
 
fw_vendor = strdup_wchar_to_char((const wchar_t 
*)efi_sys_table->fw_vendor);
 
@@ -406,9 +414,10 @@ static int efi_init_devices(void)
dev_add_param_int_ro(efi_bus.dev, "fw_revision", 
efi_sys_table->fw_revision, "%u");
dev_add_param_int_ro(efi_bus.dev, "secure_boot", secure_boot, "%d");
dev_add_param_int_ro(efi_bus.dev, "secure_mode",
-secure_boot && !setup_mode, "%u");
+efi_is_secure_mode(), "%u");
 
efi_bus.dev->info = efi_businfo;
+   boot_set_is_secure_mode(efi_is_secure_mode);
 
efi_register_devices();
 
-- 
2.11.0


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


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

2017-03-25 Thread Jean-Christophe PLAGNIOL-VILLARD
request confirmation before booting an unsigned image

with a default timeout

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagn...@jcrosoft.com>
---
 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 <s.ha...@pengutronix.de>, Pengutronix
+ * Copyright (c) 2017 Jean-Christophe PLAGNIOL-VILLARD <plagn...@jcrosoft.com>
+ *
+ * Under GPLv2 Only
+ */
 #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 a/common/bootm.c b/common/bootm.c
index 1558f3c5d..73a3a99dd 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -579,6 +579,12 @@ int bootm_boot(struct bo

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

2017-03-25 Thread Jean-Christophe PLAGNIOL-VILLARD
everythink need to be aligned to 4096

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagn...@jcrosoft.com>
---
 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*)
*(.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);
}
 
_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 <plag...@jcrosoft.com>
+ *
+ * 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


[PATCH 05/13] move boot verify to generic code

2017-03-25 Thread Jean-Christophe PLAGNIOL-VILLARD
so we can use it outside of bootm only

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagn...@jcrosoft.com>
---
 commands/bootm.c  |  6 +++---
 common/Kconfig|  4 
 common/Makefile   |  1 +
 common/boot_verify.c  | 35 +++
 common/bootm.c| 29 +++--
 common/image-fit.c| 14 +++---
 common/uimage.c   |  2 +-
 include/boot_verify.h | 20 
 include/bootm.h   | 14 +++---
 include/image-fit.h   |  4 ++--
 10 files changed, 79 insertions(+), 50 deletions(-)
 create mode 100644 common/boot_verify.c
 create mode 100644 include/boot_verify.h

diff --git a/commands/bootm.c b/commands/bootm.c
index c7cbdbe0f..b35aaa914 100644
--- a/commands/bootm.c
+++ b/commands/bootm.c
@@ -64,11 +64,11 @@ static int do_bootm(int argc, char *argv[])
while ((opt = getopt(argc, argv, BOOTM_OPTS)) > 0) {
switch(opt) {
case 'c':
-   if (data.verify < BOOTM_VERIFY_HASH)
-   data.verify = BOOTM_VERIFY_HASH;
+   if (data.verify < BOOT_VERIFY_HASH)
+   data.verify = BOOT_VERIFY_HASH;
break;
case 's':
-   data.verify = BOOTM_VERIFY_SIGNATURE;
+   data.verify = BOOT_VERIFY_SIGNATURE;
break;
 #ifdef CONFIG_BOOTM_INITRD
case 'L':
diff --git a/common/Kconfig b/common/Kconfig
index 895814ee9..00e98e859 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -24,6 +24,9 @@ config HAS_MODULES
 config HAS_SECURE_BOOT
bool
 
+config BOOT_VERIFY
+   bool
+
 config HAS_CACHE
bool
help
@@ -551,6 +554,7 @@ config TIMESTAMP
 
 menuconfig BOOTM
select UIMAGE
+   select BOOT_VERIFY
default y if COMMAND_SUPPORT
bool "bootm support"
 
diff --git a/common/Makefile b/common/Makefile
index 5f58c81d2..5d471a3a0 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -61,6 +61,7 @@ obj-$(CONFIG_UBIFORMAT)   += ubiformat.o
 obj-$(CONFIG_BAREBOX_UPDATE_IMX_NAND_FCB) += imx-bbu-nand-fcb.o
 obj-$(CONFIG_CONSOLE_RATP) += ratp.o
 obj-$(CONFIG_BOOT) += boot.o
+obj-$(CONFIG_BOOT_VERIFY)  += boot_verify.o
 
 quiet_cmd_pwd_h = PWDH$@
 ifdef CONFIG_PASSWORD
diff --git a/common/boot_verify.c b/common/boot_verify.c
new file mode 100644
index 0..afe929e68
--- /dev/null
+++ b/common/boot_verify.c
@@ -0,0 +1,35 @@
+#include 
+#include 
+#include 
+#include 
+#include 
+
+static enum boot_verify boot_verify_mode = BOOT_VERIFY_HASH;
+
+enum boot_verify boot_get_verify_mode(void)
+{
+   return boot_verify_mode;
+}
+
+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",
+};
+
+static int init_boot_verify(void)
+{
+   if (IS_ENABLED(CONFIG_BOOT_FORCE_SIGNED_IMAGES))
+   boot_verify_mode = BOOT_VERIFY_SIGNATURE;
+
+   globalvar_add_simple_enum("boot.verify", (unsigned int 
*)_verify_mode,
+ boot_verify_names, 
ARRAY_SIZE(boot_verify_names));
+
+   return 0;
+}
+late_initcall(init_boot_verify);
+
+BAREBOX_MAGICVAR_NAMED(global_boot_verify, global.boot.verify, "boot default 
verify level");
diff --git a/common/bootm.c b/common/bootm.c
index 885b09f81..74202a829 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -69,27 +69,11 @@ void bootm_data_init_defaults(struct bootm_data *data)
getenv_ul("global.bootm.image.loadaddr", >os_address);
getenv_ul("global.bootm.initrd.loadaddr", >initrd_address);
data->initrd_file = getenv_nonempty("global.bootm.initrd");
-   data->verify = bootm_get_verify_mode();
+   data->verify = boot_get_verify_mode();
data->appendroot = bootm_appendroot;
data->verbose = bootm_verbosity;
 }
 
-static enum bootm_verify bootm_verify_mode = BOOTM_VERIFY_HASH;
-
-enum bootm_verify bootm_get_verify_mode(void)
-{
-   return bootm_verify_mode;
-}
-
-static const char * const bootm_verify_names[] = {
-#ifndef CONFIG_BOOT_FORCE_SIGNED_IMAGES
-   [BOOTM_VERIFY_NONE] = "none",
-   [BOOTM_VERIFY_HASH] = "hash",
-   [BOOTM_VERIFY_AVAILABLE] = "available",
-#endif
-   [BOOTM_VERIFY_SIGNATURE] = "signature",
-};
-
 static int uimage_part_num(const char *partname)
 {
if (!partname)
@@ -175,7 +159,7 @@ static int bootm_open_initrd_uimage(struct image_data *data)
if (!data->initrd)
return -EINVAL;
 
-   if (bootm_get_verify_mode()

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

2017-03-25 Thread Jean-Christophe PLAGNIOL-VILLARD
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagn...@jcrosoft.com>
---
 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)
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


[PATCH 09/13] boot_verify: add password request support

2017-03-25 Thread Jean-Christophe PLAGNIOL-VILLARD
This will allow to let the user enter a password before booting more safe
than just a 'y'

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagn...@jcrosoft.com>
---
 common/boot_verify.c | 10 ++
 common/password.c| 18 ++
 include/password.h   |  6 ++
 3 files changed, 34 insertions(+)

diff --git a/common/boot_verify.c b/common/boot_verify.c
index 07ae07e16..2faa8d56c 100644
--- a/common/boot_verify.c
+++ b/common/boot_verify.c
@@ -10,6 +10,7 @@
 #include 
 #include 
 #include 
+#include 
 
 static unsigned int boot_verify_confirm_timeout = 10;
 static enum boot_verify boot_verify_mode = BOOT_VERIFY_HASH;
@@ -63,6 +64,14 @@ int boot_can_start_unsigned(void)
 
printf("Are you sure you wish to run an unsigned binary\n");
printf("in a secure environment?\n");
+   if (IS_ENABLED(CONFIG_PASSWORD)) {
+   printf("enter password to confirm\n");
+   ret = request_password(timeout);
+   if (ret != -ENOTSUPP)
+   return -ESECVIOLATION;
+
+   }
+
printf("press y to confirm\n");
 
ret = console_countdown(timeout, CONSOLE_COUNTDOWN_ANYKEY, );
@@ -72,6 +81,7 @@ int boot_can_start_unsigned(void)
return c == 'y' ? 0 : -ESECVIOLATION;
 }
 
+
 static int init_boot_verify(void)
 {
int size;
diff --git a/common/password.c b/common/password.c
index d52b746f0..1147111cd 100644
--- a/common/password.c
+++ b/common/password.c
@@ -435,6 +435,24 @@ void login(void)
}
 }
 
+int request_password(int timeout)
+{
+   unsigned char passwd[PASSWD_MAX_LENGTH];
+   int ret;
+
+   if (!is_passwd_default_enable() && !is_passwd_env_enable())
+   return -ENOTSUPP;
+
+   ret = password(passwd, PASSWD_MAX_LENGTH, LOGIN_MODE, timeout);
+   if (ret < 0)
+   return ret;
+
+   if (check_passwd(passwd, ret) == 1)
+   return 0;
+
+   return -EINVAL;
+}
+
 static int login_global_init(void)
 {
login_fail_command = xstrdup("boot");
diff --git a/include/password.h b/include/password.h
index 8b9961815..5e8964929 100644
--- a/include/password.h
+++ b/include/password.h
@@ -31,10 +31,16 @@ int set_env_passwd(unsigned char *passwd, size_t length);
 
 #ifdef CONFIG_PASSWORD
 void login(void);
+int request_password(int timeout);
 #else
 static inline void login(void)
 {
 }
+
+static inline int request_password(int timeout)
+{
+   return 0;
+}
 #endif
 
 #endif /* __PASSWORD_H__ */
-- 
2.11.0


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


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

2017-03-25 Thread Jean-Christophe PLAGNIOL-VILLARD
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagn...@jcrosoft.com>
---
 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


[PATCH 10/13] efi: add more security related guid for the efivars

2017-03-25 Thread Jean-Christophe PLAGNIOL-VILLARD
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagn...@jcrosoft.com>
---
 common/efi-guid.c |  6 ++
 include/efi.h | 18 ++
 2 files changed, 24 insertions(+)

diff --git a/common/efi-guid.c b/common/efi-guid.c
index 71aa21ddd..01b02bbb1 100644
--- a/common/efi-guid.c
+++ b/common/efi-guid.c
@@ -81,6 +81,12 @@ const char *efi_guid_string(efi_guid_t *g)
EFI_GUID_STRING( EFI_TCG_PROTOCOL_GUID, "TcgService", "TCGServices 
Protocol");
/* TPM 2.0 */
EFI_GUID_STRING( EFI_TCG2_PROTOCOL_GUID, "Tcg2Service", "TCG2Services 
Protocol");
+   EFI_GUID_STRING(EFI_VENDOR_KEYS_NV_VARIABLE_NAME_GUID, "VendorKeysNv", 
"Vendor Keys Non-Volatile");
+   EFI_GUID_STRING(EFI_AUTHENTICATED_VARIABLE_GUID, "AuthVar", 
"Authenticated Variable");
+   EFI_GUID_STRING(EFI_IMAGE_SECURITY_DATABASE_GUID, "ImageSecurityDB", 
"Image Security Database");
+   EFI_GUID_STRING(EFI_CERT_DB_GUID, "CertDB", "Certificate Database");
+   EFI_GUID_STRING(EFI_SECURE_BOOT_ENABLE_DISABLE_GUID, 
"SecureBootEnable", "Secure Boot Enable Disable");
+   EFI_GUID_STRING(EFI_CUSTOM_MODE_ENABLE_GUID, "CustomMode", 
"CustomMode");
 
/* File */
EFI_GUID_STRING(EFI_IDEBUSDXE_INF_GUID, "IdeBusDxe.inf", "EFI 
IdeBusDxe.inf File GUID");
diff --git a/include/efi.h b/include/efi.h
index e1fc134ee..31e7b283e 100644
--- a/include/efi.h
+++ b/include/efi.h
@@ -507,6 +507,24 @@ extern efi_runtime_services_t *RT;
 #define EFI_TCG2_PROTOCOL_GUID \
EFI_GUID(0x607f766c, 0x7455, 0x42be, 0x93, 0x0b, 0xe4, 0xd7, 0x6d, 
0xb2, 0x72, 0x0f)
 
+#define EFI_VENDOR_KEYS_NV_VARIABLE_NAME_GUID \
+   EFI_GUID(0x9073e4e0, 0x60ec, 0x4b6e, 0x99, 0x3, 0x4c, 0x22, 0x3c, 0x26, 
0x0f, 0x3c)
+
+#define EFI_AUTHENTICATED_VARIABLE_GUID \
+   EFI_GUID(0xaaf32c78, 0x947b, 0x439a, 0xa1, 0x80, 0x2e, 0x14, 0x4e, 
0xc3,0x77, 0x92)
+
+#define EFI_IMAGE_SECURITY_DATABASE_GUID \
+   EFI_GUID(0xd719b2cb, 0x3d3a, 0x4596, 0xa3, 0xbc, 0xda, 0xd0, 0xe, 0x67, 
0x65, 0x6f)
+
+#define EFI_CERT_DB_GUID \
+   EFI_GUID(0xd9bee56e, 0x75dc, 0x49d9, 0xb4, 0xd7, 0xb5, 0x34, 0x21, 0xf, 
0x63, 0x7a)
+
+#define EFI_SECURE_BOOT_ENABLE_DISABLE_GUID \
+   EFI_GUID(0xf0a30bc7, 0xaf08, 0x4556, 0x99, 0xc4, 0x00, 0x10, 0x9, 0xc9, 
0x3a, 0x44)
+
+#define EFI_CUSTOM_MODE_ENABLE_GUID \
+   EFI_GUID(0xc076ec0c, 0x7028, 0x4399, 0xa0, 0x72, 0x71, 0xee, 0x5c, 
0x44, 0x8b, 0x9f)
+
 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;
-- 
2.11.0


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


[PATCH 12/13] efi: fix secure and setup mode report

2017-03-25 Thread Jean-Christophe PLAGNIOL-VILLARD
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagn...@jcrosoft.com>
---
 drivers/efi/efi-device.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/efi/efi-device.c b/drivers/efi/efi-device.c
index 6ed7f12b3..998bda7c6 100644
--- a/drivers/efi/efi-device.c
+++ b/drivers/efi/efi-device.c
@@ -365,7 +365,7 @@ static int efi_is_secure_boot(void)
free(val);
}
 
-   return ret != 1;
+   return ret != 0;
 }
 
 static int efi_is_setup_mode(void)
@@ -379,7 +379,7 @@ static int efi_is_setup_mode(void)
free(val);
}
 
-   return ret != 1;
+   return ret != 0;
 }
 
 static int efi_init_devices(void)
@@ -406,7 +406,7 @@ static int efi_init_devices(void)
dev_add_param_int_ro(efi_bus.dev, "fw_revision", 
efi_sys_table->fw_revision, "%u");
dev_add_param_int_ro(efi_bus.dev, "secure_boot", secure_boot, "%d");
dev_add_param_int_ro(efi_bus.dev, "secure_mode",
-secure_boot & setup_mode, "%u");
+secure_boot && !setup_mode, "%u");
 
efi_bus.dev->info = efi_businfo;
 
-- 
2.11.0


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


[PATCH 03/13] bootm: make security generic

2017-03-25 Thread Jean-Christophe PLAGNIOL-VILLARD
so other secure format can be used

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagn...@jcrosoft.com>
---
 arch/arm/lib/bootm.c | 1 +
 common/image-fit.c   | 1 +
 include/bootm.h  | 1 +
 3 files changed, 3 insertions(+)

diff --git a/arch/arm/lib/bootm.c b/arch/arm/lib/bootm.c
index 204344f87..5b90705cd 100644
--- a/arch/arm/lib/bootm.c
+++ b/arch/arm/lib/bootm.c
@@ -580,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",
+   .is_secure_supported = 1,
.open = fit_bootm_open,
 .bootm = do_bootm_linux,
 .filetype = filetype_oftree,
diff --git a/common/image-fit.c b/common/image-fit.c
index 5750199c3..7563eb955 100644
--- a/common/image-fit.c
+++ b/common/image-fit.c
@@ -617,6 +617,7 @@ static int do_bootm_sandbox_fit(struct image_data *data)
 
 static struct image_handler sandbox_fit_handler = {
.name = "FIT image",
+   .is_secure_supported = 1,
.open = fit_bootm_open,
.bootm = do_bootm_sandbox_fit,
.filetype = filetype_oftree,
diff --git a/include/bootm.h b/include/bootm.h
index 1c7a145c6..27c9f571e 100644
--- a/include/bootm.h
+++ b/include/bootm.h
@@ -88,6 +88,7 @@ struct image_handler {
 
struct list_head list;
 
+   int is_secure_supported;
int ih_os;
 
enum filetype filetype;
-- 
2.11.0


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


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

2017-03-25 Thread Jean-Christophe PLAGNIOL-VILLARD
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagn...@jcrosoft.com>
---
 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) {
-   printf("Unsupported Architecture 0x%x\n",
-  dat

[PATCH 04/13] boot: invert the secure boot forcing support

2017-03-25 Thread Jean-Christophe PLAGNIOL-VILLARD
Add HAS_SECURE_BOOT as we will add other image format that support secure boot

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagn...@jcrosoft.com>
---
 common/Kconfig | 12 
 common/bootm.c |  6 +++---
 2 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/common/Kconfig b/common/Kconfig
index f7ff04664..895814ee9 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -21,6 +21,9 @@ config HAS_KALLSYMS
 config HAS_MODULES
bool
 
+config HAS_SECURE_BOOT
+   bool
+
 config HAS_CACHE
bool
help
@@ -624,6 +627,7 @@ config BOOTM_FITIMAGE_SIGNATURE
prompt "support verifying signed FIT images"
depends on BOOTM_FITIMAGE
select FITIMAGE_SIGNATURE
+   select HAS_SECURE_BOOT
help
  Support verifying signed FIT images. This requires FIT images
  as described in:
@@ -631,14 +635,14 @@ config BOOTM_FITIMAGE_SIGNATURE
  Additionally the barebox device tree needs a /signature node with the
  public key with which the image has been signed.
 
-config BOOTM_FORCE_SIGNED_IMAGES
+config BOOT_FORCE_SIGNED_IMAGES
bool
prompt "Force booting of signed images"
-   depends on BOOTM_FITIMAGE_SIGNATURE
+   depends on HAS_SECURE_BOOT
help
  With this option enabled only signed images can be booted, unsigned 
images
- are refused to boot. Effectively this means only FIT images can be 
booted
- since they are the only supported image type that support signing.
+ are refused to boot. Effectively this means only Signed images can
+ be booted.
 
 config BLSPEC
depends on BLOCK
diff --git a/common/bootm.c b/common/bootm.c
index 53311ab1c..885b09f81 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -82,7 +82,7 @@ enum bootm_verify bootm_get_verify_mode(void)
 }
 
 static const char * const bootm_verify_names[] = {
-#ifndef CONFIG_BOOTM_FORCE_SIGNED_IMAGES
+#ifndef CONFIG_BOOT_FORCE_SIGNED_IMAGES
[BOOTM_VERIFY_NONE] = "none",
[BOOTM_VERIFY_HASH] = "hash",
[BOOTM_VERIFY_AVAILABLE] = "available",
@@ -531,7 +531,7 @@ int bootm_boot(struct bootm_data *bootm_data)
goto err_out;
}
 
-   if (IS_ENABLED(CONFIG_BOOTM_FORCE_SIGNED_IMAGES)) {
+   if (IS_ENABLED(CONFIG_BOOT_FORCE_SIGNED_IMAGES)) {
data->verify = BOOTM_VERIFY_SIGNATURE;
 
/*
@@ -635,7 +635,7 @@ static int bootm_init(void)
globalvar_add_simple("bootm.initrd.loadaddr", NULL);
}
 
-   if (IS_ENABLED(CONFIG_BOOTM_FORCE_SIGNED_IMAGES))
+   if (IS_ENABLED(CONFIG_BOOT_FORCE_SIGNED_IMAGES))
bootm_verify_mode = BOOTM_VERIFY_SIGNATURE;
 
globalvar_add_simple_int("bootm.verbose", _verbosity, "%u");
-- 
2.11.0


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


[PATCH 00/13] add efi secure boot support

2017-03-25 Thread Jean-Christophe PLAGNIOL-VILLARD
Hi,

This patch series rework the secure boot support to make it generic
and we could use it on EFI too

The following changes since commit 2846e53d2d41742348459676edab737edf90604a:

  arm: baltos: define baltos_sram_init() return type as void (2017-03-13 
09:13:17 +0100)

are available in the git repository at:

  git://git.jcrosoft.org/barebox.git delivery/efi-sb

for you to fetch changes up to ff17500171e65d8c20c7c0acc803aa5a4d22d014:

  efi: enable sercure boot support (2017-03-15 03:09:09 +0800)


Jean-Christophe PLAGNIOL-VILLARD (13):
  bootm: move open to image_handler
  boot_verify: use a new error ESECVIOLATION
  bootm: make security generic
  boot: invert the secure boot forcing support
  move boot verify to generic code
  boot_verify: make it modifiable at start time
  go: only use it if boot signature is not required
  boot_verify: allow to force unsigned image to boot
  boot_verify: add password request support
  efi: add more security related guid for the efivars
  efi: fix lds for secure boot support
  efi: fix secure and setup mode report
  efi: enable sercure boot support

 arch/arm/lib/bootm.c |   3 +++
 arch/blackfin/lib/blackfin_linux.c   |   1 +
 arch/nios2/lib/bootm.c   |   1 +
 arch/ppc/lib/ppclinux.c  |   1 +
 arch/x86/Kconfig |   1 +
 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 +-
 commands/bootm.c |   6 +++---
 commands/go.c|   9 +
 common/Kconfig   |  24 
 common/Makefile  |   1 +
 common/boot_verify.c | 113 
+
 common/bootm.c   | 123 
++-
 common/efi-guid.c|   6 ++
 common/efi/efi-image.c   |   1 +
 common/efi/efi.c |   2 +-
 common/image-fit.c   |  42 
+-
 common/misc.c|   1 +
 common/password.c|  18 ++
 common/uimage.c  |  33 
+
 drivers/efi/efi-device.c |  17 +
 include/asm-generic/barebox.lds.h|   8 +---
 include/asm-generic/errno.h  |   1 +
 include/boot_verify.h|  36 

 include/bootm.h  |  16 +---
 include/efi.h|  18 ++
 include/image-fit.h  |   5 +++--
 include/image.h  |   2 ++
 include/password.h   |   6 ++
 30 files changed, 395 insertions(+), 134 deletions(-)

Best Regards,
J.

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


Re: [PATCH 3/5] efi: fix secure and setup mode report

2017-03-14 Thread Jean-Christophe PLAGNIOL-VILLARD
On 08:34 Mon 13 Mar , Sascha Hauer wrote:
> On Thu, Mar 09, 2017 at 03:34:08PM +0100, Jean-Christophe PLAGNIOL-VILLARD 
> wrote:
> > Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagn...@jcrosoft.com>
> > ---
> >  drivers/efi/efi-device.c | 6 +++---
> >  1 file changed, 3 insertions(+), 3 deletions(-)
> > 
> > diff --git a/drivers/efi/efi-device.c b/drivers/efi/efi-device.c
> > index 6ed7f12b3..7029bfb31 100644
> > --- a/drivers/efi/efi-device.c
> > +++ b/drivers/efi/efi-device.c
> > @@ -365,7 +365,7 @@ static int efi_is_secure_boot(void)
> > free(val);
> > }
> >  
> > -   return ret != 1;
> > +   return ret != 0;
> >  }
> >  
> >  static int efi_is_setup_mode(void)
> > @@ -379,7 +379,7 @@ static int efi_is_setup_mode(void)
> > free(val);
> > }
> >  
> > -   return ret != 1;
> > +   return ret != 0;
> >  }
> >  
> >  static int efi_init_devices(void)
> > @@ -406,7 +406,7 @@ static int efi_init_devices(void)
> > dev_add_param_int_ro(efi_bus.dev, "fw_revision", 
> > efi_sys_table->fw_revision, "%u");
> > dev_add_param_int_ro(efi_bus.dev, "secure_boot", secure_boot, "%d");
> > dev_add_param_int_ro(efi_bus.dev, "secure_mode",
> > -secure_boot & setup_mode, "%u");
> > +secure_boot & !setup_mode, "%u");
> 
> While a bitwise 'and' operator surely works with booleans here you should 
> still
> use a logical 'and' operator here.
ok

Best Regards,
J.
> 
> Sascha
> 
> -- 
> 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 4/5] boot: if we are in secure boot mode

2017-03-14 Thread Jean-Christophe PLAGNIOL-VILLARD
On 08:50 Mon 13 Mar , Sascha Hauer wrote:
> On Thu, Mar 09, 2017 at 03:34:09PM +0100, Jean-Christophe PLAGNIOL-VILLARD 
> wrote:
> > request confirmation before booting an unsigned image
> > 
> > with a default timeout
> > 
> > Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagn...@jcrosoft.com>
> > ---
> >  commands/go.c |  7 +++
> >  common/Kconfig|  8 
> >  common/Makefile   |  1 +
> >  common/bootm.c|  7 +++
> >  common/secure_boot.c  | 43 +++
> >  include/bootm.h   |  1 +
> >  include/secure_boot.h | 25 +
> >  7 files changed, 92 insertions(+)
> >  create mode 100644 common/secure_boot.c
> >  create mode 100644 include/secure_boot.h
> > 
> > diff --git a/commands/go.c b/commands/go.c
> > index fb319b320..61c9ce43f 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,12 @@ static int do_go(int argc, char *argv[])
> > if (argc < 2)
> > return COMMAND_ERROR_USAGE;
> >  
> > +   rcode = secure_boot_start_unsigned();
> > +   if (rcode)
> > +   return rcode ? 1 : 0;
> 
> When rcode is true, then if rcode is true, return 1, otherwise return 0?

I forget we could return a negative error on command too
> 
> > +
> > +   rcode = 1;
> > +
> > if (!isdigit(*argv[1])) {
> > fd = open(argv[1], O_RDONLY);
> > if (fd < 0) {
> > diff --git a/common/Kconfig b/common/Kconfig
> > index f7ff04664..9e7d027a2 100644
> > --- a/common/Kconfig
> > +++ b/common/Kconfig
> > @@ -21,6 +21,9 @@ config HAS_KALLSYMS
> >  config HAS_MODULES
> > bool
> >  
> > +config HAS_SECURE_BOOT
> > +   bool
> > +
> >  config HAS_CACHE
> > bool
> > help
> > @@ -184,6 +187,11 @@ config NVVAR
> >   while global variables can be changed during runtime without changing 
> > the
> >   default.
> >  
> > +config SECURE_BOOT_TIMEOUT
> > +   prompt "Secure Boot unsigned boot timeout"
> > +   int
> > +   default 3
> > +
> >  menu "memory layout"
> >  
> >  source "pbl/Kconfig"
> > diff --git a/common/Makefile b/common/Makefile
> > index 5f58c81d2..e57cc2c15 100644
> > --- a/common/Makefile
> > +++ b/common/Makefile
> > @@ -61,6 +61,7 @@ obj-$(CONFIG_UBIFORMAT)   += ubiformat.o
> >  obj-$(CONFIG_BAREBOX_UPDATE_IMX_NAND_FCB) += imx-bbu-nand-fcb.o
> >  obj-$(CONFIG_CONSOLE_RATP) += ratp.o
> >  obj-$(CONFIG_BOOT) += boot.o
> > +obj-$(CONFIG_HAS_SECURE_BOOT)  += secure_boot.o
> >  
> >  quiet_cmd_pwd_h = PWDH$@
> >  ifdef CONFIG_PASSWORD
> > diff --git a/common/bootm.c b/common/bootm.c
> > index 81625d915..0ebf65681 100644
> > --- a/common/bootm.c
> > +++ b/common/bootm.c
> > @@ -23,6 +23,7 @@
> >  #include 
> >  #include 
> >  #include 
> > +#include 
> >  
> >  static LIST_HEAD(handler_list);
> >  
> > @@ -625,6 +626,12 @@ int bootm_boot(struct bootm_data *bootm_data)
> >     printf("Passing control to %s handler\n", handler->name);
> > }
> >  
> > +   if (!handler->is_secure_supported && is_secure_mode()) {
> > +   ret = secure_boot_start_unsigned();
> > +   if (ret)
> > +   goto err_out;
> > +   }
> > +
> > ret = handler->bootm(data);
> > if (data->dryrun)
> > printf("Dryrun. Aborted\n");
> > diff --git a/common/secure_boot.c b/common/secure_boot.c
> > new file mode 100644
> > index 0..e625ef4e1
> > --- /dev/null
> > +++ b/common/secure_boot.c
> > @@ -0,0 +1,43 @@
> > +/*
> > + * Copyright (c) 2017 Jean-Christophe PLAGNIOL-VILLARD 
> > <plagn...@jcrosoft.com>
> > + *
> > + * Under GPLv2 Only
> > + */
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +
> > +static unsigned int sb_confirm_timeout = CONFIG_SECURE_BOOT_TIMEOUT;
> 
> Use globalvar_add_simple_int instead of putting this into the config.
> 
> > +
> > +int secure_boot_start_unsigned(void)
> 
> This function name is very misleading. It sounds like it starts an
> unsigned image, but this function doesn't start anything. Second guess
> is that it returns a boolean whether it's allowed to start an unsigned
> image, but actually it returns the opposite.

secure_boot_can_start_unsigned could be better

it return 0 if ok
an error otherwise

as we can return an security violation or other error

Best Regards,
J.

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


Re: [PATCH 4/5] boot: if we are in secure boot mode

2017-03-14 Thread Jean-Christophe PLAGNIOL-VILLARD
On 08:55 Mon 13 Mar , Sascha Hauer wrote:
> On Thu, Mar 09, 2017 at 03:34:09PM +0100, Jean-Christophe PLAGNIOL-VILLARD 
> wrote:
> > request confirmation before booting an unsigned image
> > 
> > with a default timeout
> > 
> > Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagn...@jcrosoft.com>
> > ---
> >  commands/go.c |  7 +++
> >  common/Kconfig|  8 
> >  common/Makefile   |  1 +
> >  common/bootm.c|  7 +++
> >  common/secure_boot.c  | 43 +++
> >  include/bootm.h   |  1 +
> >  include/secure_boot.h | 25 +
> >  7 files changed, 92 insertions(+)
> >  create mode 100644 common/secure_boot.c
> >  create mode 100644 include/secure_boot.h
> > 
> > diff --git a/commands/go.c b/commands/go.c
> > index fb319b320..61c9ce43f 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,12 @@ static int do_go(int argc, char *argv[])
> > if (argc < 2)
> > return COMMAND_ERROR_USAGE;
> >  
> > +   rcode = secure_boot_start_unsigned();
> > +   if (rcode)
> > +   return rcode ? 1 : 0;
> > +
> > +   rcode = 1;
> > +
> > if (!isdigit(*argv[1])) {
> > fd = open(argv[1], O_RDONLY);
> > if (fd < 0) {
> > diff --git a/common/Kconfig b/common/Kconfig
> > index f7ff04664..9e7d027a2 100644
> > --- a/common/Kconfig
> > +++ b/common/Kconfig
> > @@ -21,6 +21,9 @@ config HAS_KALLSYMS
> >  config HAS_MODULES
> > bool
> >  
> > +config HAS_SECURE_BOOT
> > +   bool
> > +
> >  config HAS_CACHE
> > bool
> > help
> > @@ -184,6 +187,11 @@ config NVVAR
> >   while global variables can be changed during runtime without changing 
> > the
> >   default.
> >  
> > +config SECURE_BOOT_TIMEOUT
> > +   prompt "Secure Boot unsigned boot timeout"
> > +   int
> > +   default 3
> > +
> >  menu "memory layout"
> >  
> >  source "pbl/Kconfig"
> > diff --git a/common/Makefile b/common/Makefile
> > index 5f58c81d2..e57cc2c15 100644
> > --- a/common/Makefile
> > +++ b/common/Makefile
> > @@ -61,6 +61,7 @@ obj-$(CONFIG_UBIFORMAT)   += ubiformat.o
> >  obj-$(CONFIG_BAREBOX_UPDATE_IMX_NAND_FCB) += imx-bbu-nand-fcb.o
> >  obj-$(CONFIG_CONSOLE_RATP) += ratp.o
> >  obj-$(CONFIG_BOOT) += boot.o
> > +obj-$(CONFIG_HAS_SECURE_BOOT)  += secure_boot.o
> >  
> >  quiet_cmd_pwd_h = PWDH$@
> >  ifdef CONFIG_PASSWORD
> > diff --git a/common/bootm.c b/common/bootm.c
> > index 81625d915..0ebf65681 100644
> > --- a/common/bootm.c
> > +++ b/common/bootm.c
> > @@ -23,6 +23,7 @@
> >  #include 
> >  #include 
> >  #include 
> > +#include 
> >  
> >  static LIST_HEAD(handler_list);
> >  
> > @@ -625,6 +626,12 @@ int bootm_boot(struct bootm_data *bootm_data)
> > printf("Passing control to %s handler\n", handler->name);
> > }
> >  
> > +   if (!handler->is_secure_supported && is_secure_mode()) {
> > +   ret = secure_boot_start_unsigned();
> > +   if (ret)
> > +   goto err_out;
> > +   }
> 
> We already have CONFIG_BOOTM_FORCE_SIGNED_IMAGES which admittedly is not
> the most generic implementation, but in the end we shouldn't have two
> different ways how secure boot is integrated in the bootm code.
Did not seen it

I check it and this is only for BOOTM as we have go command too

that need to call image check too

and on efi this is not done at config time but runtime

and this is really FIT image oriented :(

Can we have one for EFI sperately first and then merge them as this will need
a lot of testing and checking to ensure we break nothing

Best Regards,
J.
> 
> Sascha
> 
> -- 
> 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] fixup! efi: clocksoure: add EFI event timer

2017-03-13 Thread Jean-Christophe PLAGNIOL-VILLARD

> On 13 Mar 2017, at 9:16 PM, Michael Olbrich <m.olbr...@pengutronix.de> wrote:
> 
> ---
> 
> I played with the numbers a bit. This hardware has a 18 Hz tick :-/.
18Hz wow it’s unusable

how can they implement this

> That's not really useful so just skipping the clocksource is probably the
> best solution.
> 

Acked-by: Jean-Christophe PLAGNIOL-VILLARD <plagn...@jcrosoft.com>

Best Regards,
J.

___
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 Jean-Christophe PLAGNIOL-VILLARD

> On 13 Mar 2017, at 6:30 PM, Michael Olbrich <m.olbr...@pengutronix.de> wrote:
> 
> 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 <plagn...@jcrosoft.com>
>> ---
>> 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 
>> <plag...@jcrosoft.com>
>> + *
>> + * 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.
> 

Really :(

please send a patch

FYI on x86 this generic Timer will replace at runtime by the efi_x86 that use 
HW IP
directly

Best Regards,
J.
___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


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

2017-03-13 Thread Jean-Christophe PLAGNIOL-VILLARD

> On 13 Mar 2017, at 6:27 PM, Michael Olbrich <m.olbr...@pengutronix.de> wrote:
> 
> 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.
> 

I agree with you on that EFI implementation are erradict at best.

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

I’d prefer we use a DT to add more device at build time or runtime that hack in 
the 
general code.

Or Create a specific board code for you hardware

So we keep the generic code as generic as possible

Best Regards,
J.
___
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 Jean-Christophe PLAGNIOL-VILLARD

> On 13 Mar 2017, at 4:20 PM, Michael Olbrich <m.olbr...@pengutronix.de> wrote:
> 
> 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.
we can split them in sub dirs

/efivars/by-guid//var

and keep the known one in

/efivars/Efi/…
/efivars/barebox/…
/efivars/systemd/…

as we will use known guid for most of the time

as does linux too most of the time

> Maybe keep the old version and add something like the by-name etc. symlinks
> used in udev:
> 
> -bar
> 
>  EFI
>[...]
>  foo
>bar -> ../../-bar

-bar is un readable 

and we need to parse a filename which is a prone to error even when creating 
new variable
and today we only allow to create var for barebox guid in the "user space”
So this is easier to handle

and when you ls it at the end is hard to read

The efivarfs is for user not C Code 

That’s why I prefer to have a design that is easy to read

Best Regards,
J.
___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH] net/phy: marvell: import support for 88E1111 from the Linux

2017-03-12 Thread Jean-Christophe PLAGNIOL-VILLARD
Hi,

Why 2 patches?

Best Regards,
J/
On 18:18 Fri 10 Mar , pmamo...@gmail.com wrote:
> From: Peter Mamonov 
> 
> Signed-off-by: Peter Mamonov 
> ---
>  drivers/net/phy/marvell.c | 126 
> ++
>  1 file changed, 126 insertions(+)
> 
> diff --git a/drivers/net/phy/marvell.c b/drivers/net/phy/marvell.c
> index 38b2ad31f..ea5a4a9be 100644
> --- a/drivers/net/phy/marvell.c
> +++ b/drivers/net/phy/marvell.c
> @@ -31,6 +31,22 @@
>  #define MII_M1011_PHY_STATUS_RESOLVEDBIT(11)
>  #define MII_M1011_PHY_STATUS_LINKBIT(10)
>  
> +#define MII_M_PHY_LED_CONTROL0x18
> +#define MII_M_PHY_LED_DIRECT 0x4100
> +#define MII_M_PHY_LED_COMBINE0x411c
> +#define MII_M_PHY_EXT_CR 0x14
> +#define MII_M_RX_DELAY   0x80
> +#define MII_M_TX_DELAY   0x2
> +#define MII_M_PHY_EXT_SR 0x1b
> +
> +#define MII_M_HWCFG_MODE_MASK0xf
> +#define MII_M_HWCFG_MODE_COPPER_RGMII0xb
> +#define MII_M_HWCFG_MODE_FIBER_RGMII 0x3
> +#define MII_M_HWCFG_MODE_SGMII_NO_CLK0x4
> +#define MII_M_HWCFG_MODE_COPPER_RTBI 0x9
> +#define MII_M_HWCFG_FIBER_COPPER_AUTO0x8000
> +#define MII_M_HWCFG_FIBER_COPPER_RES 0x2000
> +
>  #define MII_M_COPPER 0
>  #define MII_M_FIBER  1
>  
> @@ -402,6 +418,107 @@ static int m88e1540_config_init(struct phy_device 
> *phydev)
>   return marvell_config_init(phydev);
>  }
>  
> +static int m88e_config_init(struct phy_device *phydev)
> +{
> + int err;
> + int temp;
> +
> + if ((phydev->interface == PHY_INTERFACE_MODE_RGMII) ||
> + (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID) ||
> + (phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID) ||
> + (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID)) {
> +
> + temp = phy_read(phydev, MII_M_PHY_EXT_CR);
> + if (temp < 0)
> + return temp;
> +
> + if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID) {
> + temp |= (MII_M_RX_DELAY | MII_M_TX_DELAY);
> + } else if (phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID) {
> + temp &= ~MII_M_TX_DELAY;
> + temp |= MII_M_RX_DELAY;
> + } else if (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID) {
> + temp &= ~MII_M_RX_DELAY;
> + temp |= MII_M_TX_DELAY;
> + }
> +
> + err = phy_write(phydev, MII_M_PHY_EXT_CR, temp);
> + if (err < 0)
> + return err;
> +
> + temp = phy_read(phydev, MII_M_PHY_EXT_SR);
> + if (temp < 0)
> + return temp;
> +
> + temp &= ~(MII_M_HWCFG_MODE_MASK);
> +
> + if (temp & MII_M_HWCFG_FIBER_COPPER_RES)
> + temp |= MII_M_HWCFG_MODE_FIBER_RGMII;
> + else
> + temp |= MII_M_HWCFG_MODE_COPPER_RGMII;
> +
> + err = phy_write(phydev, MII_M_PHY_EXT_SR, temp);
> + if (err < 0)
> + return err;
> + }
> +
> + if (phydev->interface == PHY_INTERFACE_MODE_SGMII) {
> + temp = phy_read(phydev, MII_M_PHY_EXT_SR);
> + if (temp < 0)
> + return temp;
> +
> + temp &= ~(MII_M_HWCFG_MODE_MASK);
> + temp |= MII_M_HWCFG_MODE_SGMII_NO_CLK;
> + temp |= MII_M_HWCFG_FIBER_COPPER_AUTO;
> +
> + err = phy_write(phydev, MII_M_PHY_EXT_SR, temp);
> + if (err < 0)
> + return err;
> + }
> +
> + if (phydev->interface == PHY_INTERFACE_MODE_RTBI) {
> + temp = phy_read(phydev, MII_M_PHY_EXT_CR);
> + if (temp < 0)
> + return temp;
> + temp |= (MII_M_RX_DELAY | MII_M_TX_DELAY);
> + err = phy_write(phydev, MII_M_PHY_EXT_CR, temp);
> + if (err < 0)
> + return err;
> +
> + temp = phy_read(phydev, MII_M_PHY_EXT_SR);
> + if (temp < 0)
> + return temp;
> + temp &= ~(MII_M_HWCFG_MODE_MASK | 
> MII_M_HWCFG_FIBER_COPPER_RES);
> + temp |= 0x7 | MII_M_HWCFG_FIBER_COPPER_AUTO;
> + err = phy_write(phydev, MII_M_PHY_EXT_SR, temp);
> + if (err < 0)
> + return err;
> +
> + /* soft reset */
> + err = phy_write(phydev, MII_BMCR, BMCR_RESET);
> + if (err < 0)
> + return err;
> + do
> + temp = phy_read(phydev, MII_BMCR);
> + while (temp & BMCR_RESET);
> +
> + temp = phy_read(phydev, MII_M_PHY_EXT_SR);
> + 

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

2017-03-12 Thread Jean-Christophe PLAGNIOL-VILLARD
On 17:23 Sat 11 Mar , Michael Olbrich wrote:
> 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.
I did not did it as you can use efi-stdio as early as possible

but we can take a look to probe it earlier

Best Regards,
J.

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


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

2017-03-12 Thread Jean-Christophe PLAGNIOL-VILLARD
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

Best Regards,
J.

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


[PATCH 1/1] fix: console: expose consoles in devfs

2017-03-10 Thread Jean-Christophe PLAGNIOL-VILLARD
on 64bit ssize_t is not an int but a long

so use the protype for fops_write ssize_t

common/console.c: In function ‘console_register’:
common/console.c:373:22: warning: assignment from incompatible pointer type 
[-Wincompatible-pointer-types]
  newcdev->fops.write = fops_write;

in commit b4f55fcf355a4d0ac456445a5f42f259f2812b57
By Bastian Stender <b...@pengutronix.de>

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagn...@jcrosoft.com>
---
 common/console.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/common/console.c b/common/console.c
index 668c870ab..4127e7617 100644
--- a/common/console.c
+++ b/common/console.c
@@ -296,7 +296,7 @@ static int fops_flush(struct cdev *dev)
return 0;
 }
 
-static int fops_write(struct cdev* dev, const void* buf, size_t count,
+static ssize_t fops_write(struct cdev* dev, const void* buf, size_t count,
  loff_t offset, ulong flags)
 {
struct console_device *priv = dev->priv;
-- 
2.11.0


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


Re: [PATCH 3/3] fbcon: use __iowrite{32/64} to speedup the framebuffer console scrolling

2017-03-10 Thread Jean-Christophe PLAGNIOL-VILLARD
On 08:00 Fri 10 Mar , Sascha Hauer wrote:
> On Thu, Mar 09, 2017 at 11:31:11AM +0100, Jean-Christophe PLAGNIOL-VILLARD 
> wrote:
> > this devide the time by 4 on x86
> > 
> > Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagn...@jcrosoft.com>
> > ---
> >  drivers/video/fbconsole.c | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/video/fbconsole.c b/drivers/video/fbconsole.c
> > index b261f1704..b5e951e23 100644
> > --- a/drivers/video/fbconsole.c
> > +++ b/drivers/video/fbconsole.c
> > @@ -6,6 +6,7 @@
> >  #include 
> >  #include 
> >  #include 
> > +#include 
> >  
> >  enum state_t {
> > LIT,/* Literal input */
> > @@ -202,7 +203,7 @@ static void printchar(struct fbc_priv *priv, int c)
> >  
> > buf = gui_screen_render_buffer(priv->sc);
> >  
> > -   memcpy(buf, buf + line_height, line_height * priv->rows);
> > +   __iowrite64_copy(buf, buf + line_height, (line_height * 
> > priv->rows) >> 2);
> 
> Shouldn't this be >> 3?
> 
> Besides, I'm not sure using __iowrite64_copy is the right weapon here.
> Maybe better port arch/x86/lib/memcpy_64.S to get an optimized memcpy?
My other issue to the current driver is so so slow

Normaly we need to have a shadow buffer with twice the size of the real buffer

And we should use a timer when we have to blit too much and add scroll support

I've those feature on an other barebox fbcon implementation

Best Regards,
J.
> 
> Sascha
> 
> 
> -- 
> 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/5] efi: fix lds for secure boot support

2017-03-10 Thread Jean-Christophe PLAGNIOL-VILLARD
On 14:54 Fri 10 Mar , Jean-Christophe PLAGNIOL-VILLARD wrote:
> On 12:05 Fri 10 Mar , Lucas Stach wrote:
> > Am Freitag, den 10.03.2017, 18:17 +0800 schrieb Jean-Christophe
> > PLAGNIOL-VILLARD:
> > > > On Mar 10, 2017, at 1:24 AM, Lucas Stach <l.st...@pengutronix.de> wrote:
> > > > 
> > > > Am Donnerstag, den 09.03.2017, 15:34 +0100 schrieb Jean-Christophe
> > > > PLAGNIOL-VILLARD:
> > > >> everythink need to be aligned to 4096
> > > > 
> > > > Why? The commit message isn't really telling anything.
> > > This is a requierment by EFI
> > 
> > This is in no way an EFI requirement.
> > 
> > Googling tells me that the signing procedure for EFI secure boot is
> > built around a PE binary. PE in turn is based on the COFF binary format
> > which, unlike ELF, has no section descriptions in the header and
> > therefore requires the sections to be placed page aligned (4K on x86, 4K
> > or 64K on ARM64).
> No COFF does not require to have section "page aligned" which is wrong here

This is the job of the loader to aligned them in memory but on EFI it's
required to sign the binary.

Best Regards,
J.

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


Re: [PATCH 3/3] fbcon: use __iowrite{32/64} to speedup the framebuffer console scrolling

2017-03-10 Thread Jean-Christophe PLAGNIOL-VILLARD
On 08:00 Fri 10 Mar , Sascha Hauer wrote:
> On Thu, Mar 09, 2017 at 11:31:11AM +0100, Jean-Christophe PLAGNIOL-VILLARD 
> wrote:
> > this devide the time by 4 on x86
> > 
> > Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagn...@jcrosoft.com>
> > ---
> >  drivers/video/fbconsole.c | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/video/fbconsole.c b/drivers/video/fbconsole.c
> > index b261f1704..b5e951e23 100644
> > --- a/drivers/video/fbconsole.c
> > +++ b/drivers/video/fbconsole.c
> > @@ -6,6 +6,7 @@
> >  #include 
> >  #include 
> >  #include 
> > +#include 
> >  
> >  enum state_t {
> > LIT,/* Literal input */
> > @@ -202,7 +203,7 @@ static void printchar(struct fbc_priv *priv, int c)
> >  
> > buf = gui_screen_render_buffer(priv->sc);
> >  
> > -   memcpy(buf, buf + line_height, line_height * priv->rows);
> > +   __iowrite64_copy(buf, buf + line_height, (line_height * 
> > priv->rows) >> 2);
> 
> Shouldn't this be >> 3?
yeah should be 3
> 
> Besides, I'm not sure using __iowrite64_copy is the right weapon here.
> Maybe better port arch/x86/lib/memcpy_64.S to get an optimized memcpy?
we need to test the performance

but as far as I remember __iowrite was kicker on ARM at least

Best Regards,
J.
> 
> Sascha
> 
> 
> -- 
> 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/5] efi: fix lds for secure boot support

2017-03-10 Thread Jean-Christophe PLAGNIOL-VILLARD
On 12:05 Fri 10 Mar , Lucas Stach wrote:
> Am Freitag, den 10.03.2017, 18:17 +0800 schrieb Jean-Christophe
> PLAGNIOL-VILLARD:
> > > On Mar 10, 2017, at 1:24 AM, Lucas Stach <l.st...@pengutronix.de> wrote:
> > > 
> > > Am Donnerstag, den 09.03.2017, 15:34 +0100 schrieb Jean-Christophe
> > > PLAGNIOL-VILLARD:
> > >> everythink need to be aligned to 4096
> > > 
> > > Why? The commit message isn't really telling anything.
> > This is a requierment by EFI
> 
> This is in no way an EFI requirement.
> 
> Googling tells me that the signing procedure for EFI secure boot is
> built around a PE binary. PE in turn is based on the COFF binary format
> which, unlike ELF, has no section descriptions in the header and
> therefore requires the sections to be placed page aligned (4K on x86, 4K
> or 64K on ARM64).
No COFF does not require to have section "page aligned" which is wrong here
The is a Requirement by EFI from secure boot

Otherwise EFI will not work today

> 
> All of the above is what should have been included in the commit
> message, to allow other people to understand the commit and not require
> them to google their way to the justification of this commit.
And read the Spec is required to undrestant EFI no?
Or I need to put the spec in the commit too?

Best Regards,
J
> 
> Regards,
> Lucas
> 
> > Best Regards,
> > J.
> > > 
> > > Regards,
> > > Lucas 
> > > 
> > >> 
> > >> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagn...@jcrosoft.com>
> > >> ---
> > >> 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*)
> > >>  *(.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);
> > >>  }
> > >> 
> > >>  _etext = .;
> > >> @@ -33,8 +34,8 @@ SECTIONS
> > >>  *(.reloc)
> > >>  }
> > >> 
> > >> -. = ALIGN(4096);
> > >>  _sdata = .;
> > >> +. = ALIGN(4096);
> > >> 
> > >>  .data : {
> > >>  *(.rodata*)
> > >> @@

Re: [PATCH 2/5] efi: fix lds for secure boot support

2017-03-10 Thread Jean-Christophe PLAGNIOL-VILLARD

> On Mar 10, 2017, at 1:24 AM, Lucas Stach <l.st...@pengutronix.de> wrote:
> 
> Am Donnerstag, den 09.03.2017, 15:34 +0100 schrieb Jean-Christophe
> PLAGNIOL-VILLARD:
>> everythink need to be aligned to 4096
> 
> Why? The commit message isn't really telling anything.
This is a requierment by EFI

Best Regards,
J.
> 
> Regards,
> Lucas 
> 
>> 
>> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagn...@jcrosoft.com>
>> ---
>> 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*)
>>  *(.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);
>>  }
>> 
>>  _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 
>> <plag...@jcrosoft.com>
>> + *
>> + * 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
> 
> 


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


Re: [PATCH 2/2] video: some framebuffer such as efi does support enable/disable

2017-03-10 Thread Jean-Christophe PLAGNIOL-VILLARD

> On Mar 10, 2017, at 3:26 PM, Sascha Hauer <s.ha...@pengutronix.de> wrote:
> 
> On Thu, Mar 09, 2017 at 10:57:21AM +0100, Jean-Christophe PLAGNIOL-VILLARD 
> wrote:
>> so allow them to do not pass this function via fbops
>> and indicate they are always on.
>> 
>> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagn...@jcrosoft.com>
>> ---
>> drivers/video/fb.c | 29 -
>> 1 file changed, 24 insertions(+), 5 deletions(-)
> 
> I partly applied this one on top of
> 
> [PATCH] video: call fb_[en|dis]able instead of fops directly
> 
>> 
>> diff --git a/drivers/video/fb.c b/drivers/video/fb.c
>> index 6b88f2df9..63a818eb2 100644
>> --- a/drivers/video/fb.c
>> +++ b/drivers/video/fb.c
>> @@ -19,10 +19,12 @@ static int fb_ioctl(struct cdev* cdev, int req, void 
>> *data)
>>  *fb = info;
>>  break;
>>  case FBIO_ENABLE:
>> -info->fbops->fb_enable(info);
>> +if (info->fbops->fb_enable)
>> +info->fbops->fb_enable(info);
>>  break;
>>  case FBIO_DISABLE:
>> -info->fbops->fb_disable(info);
>> +if (info->fbops->fb_disable)
>> +info->fbops->fb_disable(info);
>>  break;
>>  default:
>>  return -ENOSYS;
>> @@ -94,7 +96,8 @@ int fb_enable(struct fb_info *info)
>>  if (ret)
>>  return ret;
>> 
>> -info->fbops->fb_enable(info);
>> +if (info->fbops->fb_enable)
>> +info->fbops->fb_enable(info);
>> 
>>  info->enabled = true;
>> 
>> @@ -106,7 +109,8 @@ int fb_disable(struct fb_info *info)
>>  if (!info->enabled)
>>  return 0;
>> 
>> -info->fbops->fb_disable(info);
>> +if (info->fbops->fb_disable)
>> +info->fbops->fb_disable(info);
> 
> Making fb_enable/disable optional is fine and I applied this part.
> 
>> 
>>  fb_release_shadowfb(info);
>> 
>> @@ -266,6 +270,8 @@ static int fb_set_shadowfb(struct param_d *p, void *priv)
>>  return fb_alloc_shadowfb(info);
>> }
>> 
>> +struct fb_ops dummy_fbops;
>> +
>> int register_framebuffer(struct fb_info *info)
>> {
>>  int id = get_free_deviceid("fb");
>> @@ -273,6 +279,16 @@ int register_framebuffer(struct fb_info *info)
>>  int ret, num_modes, i;
>>  const char **names;
>> 
>> +if (!info->p_enable) {
>> +if (!info->fbops)
>> +return -EINVAL;
>> +if (!info->fbops->fb_enable && !info->fbops->fb_disable)
>> +return -EINVAL;
>> +} else {
>> +if (!info->fbops)
>> +info->fbops = _fbops;
>> +}
> 
> Making fbops optional is not what the patch descsription says.
It does as if you need nothing from fbops you will not even implement it
> 
>> +
>>  dev = >dev;
>> 
>>  /*
>> @@ -308,7 +324,10 @@ int register_framebuffer(struct fb_info *info)
>>  if (ret)
>>  goto err_free;
>> 
>> -dev_add_param_bool(dev, "enable", fb_enable_set, NULL,
>> +if (info->p_enable)
>> +dev_add_param_int_ro(dev, "enable", info->p_enable, "%d");
>> +else
>> +dev_add_param_bool(dev, "enable", fb_enable_set, NULL,
>>  >p_enable, info);
> 
> Even when the framebuffer cannot physically disabled I think we
> shouldn't throw an error when the user tries to.
this will be done by the env as I fixed the …_int_ro support
as enable will not we able to changed

Best Regards,
J.
> 
> Sascha
> 
> -- 
> 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 v3 2/3] console_countdown: add possibility to abort countdown by external commands

2017-03-10 Thread Jean-Christophe PLAGNIOL-VILLARD

> On Mar 10, 2017, at 2:05 PM, Oleksij Rempel  wrote:
> 
> From: Marc Kleine-Budde 
> 
> This patch makes it possible to abort a console countdown by an external
> command, for example when fastboot is used. This requires additional
> modifications in the external commands, a call to "console_countdown_abort()"
> has to be inserted.
> 
> Signed-off-by: Marc Kleine-Budde 
> Signed-off-by: Oleksij Rempel 
> ---
> commands/timeout.c  |  8 ++--
> common/console_countdown.c  | 15 +++
> include/console_countdown.h |  2 ++
> 3 files changed, 23 insertions(+), 2 deletions(-)
> 
> diff --git a/commands/timeout.c b/commands/timeout.c
> index ef1a037c1..d197cedd8 100644
> --- a/commands/timeout.c
> +++ b/commands/timeout.c
> @@ -32,7 +32,7 @@ static int do_timeout(int argc, char *argv[])
>   char str[2] = { };
>   const char *varname = NULL;
> 
> - while((opt = getopt(argc, argv, "crsav:")) > 0) {
> + while ((opt = getopt(argc, argv, "crsav:e")) > 0) {
>   switch(opt) {
>   case 'r':
>   flags |= CONSOLE_COUNTDOWN_RETURN;
> @@ -46,6 +46,9 @@ static int do_timeout(int argc, char *argv[])
>   case 's':
>   flags |= CONSOLE_COUNTDOWN_SILENT;
>   break;
> + case 'e':
> + flags |= CONSOLE_COUNTDOWN_EXTERN;
> + break;
>   case 'v':
>   varname = optarg;
>   break;
> @@ -73,6 +76,7 @@ BAREBOX_CMD_HELP_TEXT("Options:")
> BAREBOX_CMD_HELP_OPT("-a", "interrupt on any key")
> BAREBOX_CMD_HELP_OPT("-c", "interrupt on Ctrl-C")
> BAREBOX_CMD_HELP_OPT("-r", "interrupt on RETURN")
> +BAREBOX_CMD_HELP_OPT("-e", "interrupt on external commands (i.e. fastboot")
> BAREBOX_CMD_HELP_OPT("-s", "silent mode")
> BAREBOX_CMD_HELP_OPT("-v ", "export pressed key to environment")
> BAREBOX_CMD_HELP_END
> @@ -80,7 +84,7 @@ BAREBOX_CMD_HELP_END
> BAREBOX_CMD_START(timeout)
>   .cmd= do_timeout,
>   BAREBOX_CMD_DESC("wait for a specified timeout")
> - BAREBOX_CMD_OPTS("[-acrsv] SECONDS")
> + BAREBOX_CMD_OPTS("[-acrsev] SECONDS")
>   BAREBOX_CMD_GROUP(CMD_GRP_CONSOLE)
>   BAREBOX_CMD_HELP(cmd_timeout_help)
> BAREBOX_CMD_END
> diff --git a/common/console_countdown.c b/common/console_countdown.c
> index b2eec72b2..03b9b3353 100644
> --- a/common/console_countdown.c
> +++ b/common/console_countdown.c
> @@ -23,6 +23,13 @@
> #include 
> #include 
> 
> +static bool console_countdown_timeout_abort;
> +
> +void console_countdown_abort(void)
> +{
> + console_countdown_timeout_abort = true;
Nack 

this break the security support

If we enable password  you can not activate it by default

Best Regards,
J.
> +}
> +
> int console_countdown(int timeout_s, unsigned flags, char *out_key)
> {
>   uint64_t start, second;
> @@ -48,6 +55,9 @@ int console_countdown(int timeout_s, unsigned flags, char 
> *out_key)
>   goto out;
>   key = 0;
>   }
> + if ((flags & CONSOLE_COUNTDOWN_EXTERN) &&
> + console_countdown_timeout_abort)
> + goto out;
>   if (!(flags & CONSOLE_COUNTDOWN_SILENT) &&
>   is_timeout(second, SECOND)) {
>   printf("\b\b\b\b%4d", countdown--);
> @@ -55,6 +65,10 @@ int console_countdown(int timeout_s, unsigned flags, char 
> *out_key)
>   }
>   } while (!is_timeout(start, timeout_s * SECOND));
> 
> + if ((flags & CONSOLE_COUNTDOWN_EXTERN) &&
> + console_countdown_timeout_abort)
> + goto out;
> +
>   ret = 0;
> 
>  out:
> @@ -62,6 +76,7 @@ int console_countdown(int timeout_s, unsigned flags, char 
> *out_key)
>   printf("\n");
>   if (key && out_key)
>   *out_key = key;
> + console_countdown_timeout_abort = false;
> 
>   return ret;
> }
> diff --git a/include/console_countdown.h b/include/console_countdown.h
> index cb46964bc..c6c2d5c00 100644
> --- a/include/console_countdown.h
> +++ b/include/console_countdown.h
> @@ -5,7 +5,9 @@
> #define CONSOLE_COUNTDOWN_ANYKEY (1 << 1)
> #define CONSOLE_COUNTDOWN_RETURN (1 << 3)
> #define CONSOLE_COUNTDOWN_CTRLC (1 << 4)
> +#define CONSOLE_COUNTDOWN_EXTERN (1 << 5)
> 
> int console_countdown(int timeout_s, unsigned flags, char *out_key);
> +void console_countdown_abort(void);
> 
> #endif /* __CONSOLE_COUNTDOWN_H */
> -- 
> 2.11.0
> 
> 
> ___
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox


___
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-09 Thread Jean-Christophe PLAGNIOL-VILLARD
Hi,

Sascha is this one ok?

Best Regards,
J.
On 16:27 Fri 03 Mar , Jean-Christophe PLAGNIOL-VILLARD wrote:
> Hi,
> 
> efivarfs: rework the filesystem to make it human readable
> 
> today we use -
> 
> such as Boot-8be4df61-93ca-11d2-aa0d-00e098032b8c
> 
> now we will use a different approach where will represent first the vendor
> as a directory and then inside the associates variable.
> 
> But also create symlink on the vendor with readable name.
> 
> so it will look like this:
> 
> barebox@barebox EFI payload:/ ls -l /efivars/
> drwxrwxrwx 36 04b37fe8-f6ae-480b-bdd5-37d98c5e89aa
> drwxrwxrwx 36 4a67b082-0a4c-41cf-b6c7-440b29bb8c4f
> drwxrwxrwx 36 4c19049f-4137-4dd3-9c10-8b97a83ffdfa
> drwxrwxrwx 36 5b446ed1-e30b-4faa-871a-3654eca36080
> drwxrwxrwx 36 5b91f69c-8b88-4a2b-9269-5f1d802b5175
> drwxrwxrwx 36 8be4df61-93ca-11d2-aa0d-00e098032b8c
> lrwxrwxrwx  3 Efi -> 8be4df61-93ca-11d2-aa0d-00e098032b8c
> lrwxrwxrwx  7 barebox -> 5b91f69c-8b88-4a2b-9269-5f1d802b5175
> drwxrwxrwx 36 eb704011-1402-11d3-8e77-00a0c969723b
> lrwxrwxrwx  7 systemd -> 4a67b082-0a4c-41cf-b6c7-440b29bb8c4f
> barebox@barebox EFI payload:/ ls -l /efivars/Efi/
> -rw-rw-rw- 62 Boot
> -rw-rw-rw- 80 Boot0001
> -rw-rw-rw- 84 Boot0002
> -rw-rw-rw-106 Boot0003
> -rw-rw-rw-108 Boot0004
> -rw-rw-rw-141 Boot0005
> -rw-rw-rw- 88 Boot0006
> -rw-rw-rw-  2 BootCurrent
> -rw-rw-rw-  4 BootOptionSupport
> -rw-rw-rw- 14 BootOrder
> -rw-rw-rw-107 ConIn
> -rw-rw-rw-   1567 ConInDev
> -rw-rw-rw-103 ConOut
> -rw-rw-rw-   1855 ConOutDev
> -rw-rw-rw- 73 ErrOut
> -rw-rw-rw-   1563 ErrOutDev
> -rw-rw-rw- 14 Key
> -rw-rw-rw- 14 Key0001
> -rw-rw-rw-  4 Lang
> -rw-rw-rw- 13 LangCodes
> -rw-rw-rw-  8 OsIndicationsSupported
> -rw-rw-rw-  3 PlatformLang
> -rw-rw-rw- 18 PlatformLangCodes
> -rw-rw-rw-108 PlatformRecovery
> -rw-rw-rw-  2 Timeout
> barebox@barebox EFI payload:/ ls -l /efivars/barebox/
> barebox@barebox EFI payload:/ ls -l /efivars/systemd/
> -rw-rw-rw- 14 LoaderTimeInitUSec
> 
> please pull
> 
> The following changes since commit f14af7444ad9d8ce674382f222119f5fcd3f2576:
> 
>   efi: add veriable to report secure boot support and status (2017-02-28 
> 23:05:31 +0800)
> 
> are available in the git repository at:
> 
>   git://git.jcrosoft.org/barebox.git delivery/efivarfs
> 
> for you to fetch changes up to a757520bfccf17064181ebc15646efdb83ee581b:
> 
>   efivarfs: rework the filesystem to make it human readable (2017-03-01 
> 00:15:38 +0800)
> 
> 
> Jean-Christophe PLAGNIOL-VILLARD (2):
>   ls: allow to list a symlink ending with '/' as a dir
>   efivarfs: rework the filesystem to make it human readable
> 
>  commands/ls.c |  41 +
>  common/efi-guid.c |  17 +++--
>  common/efi/efi.c  |   2 +-
>  fs/efivarfs.c | 379 
> ++---
>  include/efi.h |   1 +
>  5 files changed, 347 insertions(+), 93 deletions(-)
> 
> Best Regards,
> J.
> 
> ___
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox

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


[PATCH 4/5] boot: if we are in secure boot mode

2017-03-09 Thread Jean-Christophe PLAGNIOL-VILLARD
request confirmation before booting an unsigned image

with a default timeout

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagn...@jcrosoft.com>
---
 commands/go.c |  7 +++
 common/Kconfig|  8 
 common/Makefile   |  1 +
 common/bootm.c|  7 +++
 common/secure_boot.c  | 43 +++
 include/bootm.h   |  1 +
 include/secure_boot.h | 25 +
 7 files changed, 92 insertions(+)
 create mode 100644 common/secure_boot.c
 create mode 100644 include/secure_boot.h

diff --git a/commands/go.c b/commands/go.c
index fb319b320..61c9ce43f 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,12 @@ static int do_go(int argc, char *argv[])
if (argc < 2)
return COMMAND_ERROR_USAGE;
 
+   rcode = secure_boot_start_unsigned();
+   if (rcode)
+   return rcode ? 1 : 0;
+
+   rcode = 1;
+
if (!isdigit(*argv[1])) {
fd = open(argv[1], O_RDONLY);
if (fd < 0) {
diff --git a/common/Kconfig b/common/Kconfig
index f7ff04664..9e7d027a2 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -21,6 +21,9 @@ config HAS_KALLSYMS
 config HAS_MODULES
bool
 
+config HAS_SECURE_BOOT
+   bool
+
 config HAS_CACHE
bool
help
@@ -184,6 +187,11 @@ config NVVAR
  while global variables can be changed during runtime without changing 
the
  default.
 
+config SECURE_BOOT_TIMEOUT
+   prompt "Secure Boot unsigned boot timeout"
+   int
+   default 3
+
 menu "memory layout"
 
 source "pbl/Kconfig"
diff --git a/common/Makefile b/common/Makefile
index 5f58c81d2..e57cc2c15 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -61,6 +61,7 @@ obj-$(CONFIG_UBIFORMAT)   += ubiformat.o
 obj-$(CONFIG_BAREBOX_UPDATE_IMX_NAND_FCB) += imx-bbu-nand-fcb.o
 obj-$(CONFIG_CONSOLE_RATP) += ratp.o
 obj-$(CONFIG_BOOT) += boot.o
+obj-$(CONFIG_HAS_SECURE_BOOT)  += secure_boot.o
 
 quiet_cmd_pwd_h = PWDH$@
 ifdef CONFIG_PASSWORD
diff --git a/common/bootm.c b/common/bootm.c
index 81625d915..0ebf65681 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -23,6 +23,7 @@
 #include 
 #include 
 #include 
+#include 
 
 static LIST_HEAD(handler_list);
 
@@ -625,6 +626,12 @@ int bootm_boot(struct bootm_data *bootm_data)
printf("Passing control to %s handler\n", handler->name);
}
 
+   if (!handler->is_secure_supported && is_secure_mode()) {
+   ret = secure_boot_start_unsigned();
+   if (ret)
+   goto err_out;
+   }
+
ret = handler->bootm(data);
if (data->dryrun)
printf("Dryrun. Aborted\n");
diff --git a/common/secure_boot.c b/common/secure_boot.c
new file mode 100644
index 0..e625ef4e1
--- /dev/null
+++ b/common/secure_boot.c
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2017 Jean-Christophe PLAGNIOL-VILLARD <plagn...@jcrosoft.com>
+ *
+ * Under GPLv2 Only
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+static unsigned int sb_confirm_timeout = CONFIG_SECURE_BOOT_TIMEOUT;
+
+int secure_boot_start_unsigned(void)
+{
+   int ret;
+   char str[2] = { };
+   int timeout = sb_confirm_timeout;
+
+   if (!is_secure_mode())
+   return 0;
+
+   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, str);
+   if (ret != -EINTR)
+   return -EINVAL;
+
+   return str[0] == 'y' ? 0 : -EINVAL;
+}
+
+static int init_sb_confirm_timeout(void)
+{
+   return globalvar_add_simple_int("sb.confirm_timeout",
+   _confirm_timeout, "%u");
+}
+late_initcall(init_sb_confirm_timeout);
+
+BAREBOX_MAGICVAR_NAMED(global_sb_confirm_timeout, global.sb.confirm_timeout,
+   "Secure Boot Comfirm timeout in seconds before booting an 
unsigned image");
diff --git a/include/bootm.h b/include/bootm.h
index 6e9777a9a..12a61c007 100644
--- a/include/bootm.h
+++ b/include/bootm.h
@@ -89,6 +89,7 @@ struct image_handler {
struct list_head list;
 
int ih_os;
+   int is_secure_supported;
 
enum filetype filetype;
int (*bootm)(struct image_data *data);
diff --git a/include/secure_boot.h b/include/secure_boot.h
new file mode 100644
index 0..3aa071012
--- /dev/null
+++ b/include/secure_boot.h
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2017 Jean-Christophe PLAGNIOL-VILLARD <plagn...@jcrosoft.com>
+ *
+ * Under GPLv2 Only
+ */
+
+#ifndef __SECURE_BOOT_H__
+#define __SECURE

[PATCH 3/5] efi: fix secure and setup mode report

2017-03-09 Thread Jean-Christophe PLAGNIOL-VILLARD
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagn...@jcrosoft.com>
---
 drivers/efi/efi-device.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/efi/efi-device.c b/drivers/efi/efi-device.c
index 6ed7f12b3..7029bfb31 100644
--- a/drivers/efi/efi-device.c
+++ b/drivers/efi/efi-device.c
@@ -365,7 +365,7 @@ static int efi_is_secure_boot(void)
free(val);
}
 
-   return ret != 1;
+   return ret != 0;
 }
 
 static int efi_is_setup_mode(void)
@@ -379,7 +379,7 @@ static int efi_is_setup_mode(void)
free(val);
}
 
-   return ret != 1;
+   return ret != 0;
 }
 
 static int efi_init_devices(void)
@@ -406,7 +406,7 @@ static int efi_init_devices(void)
dev_add_param_int_ro(efi_bus.dev, "fw_revision", 
efi_sys_table->fw_revision, "%u");
dev_add_param_int_ro(efi_bus.dev, "secure_boot", secure_boot, "%d");
dev_add_param_int_ro(efi_bus.dev, "secure_mode",
-secure_boot & setup_mode, "%u");
+secure_boot & !setup_mode, "%u");
 
efi_bus.dev->info = efi_businfo;
 
-- 
2.11.0


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


[PATCH 5/5] efi: enable sercure boot support

2017-03-09 Thread Jean-Christophe PLAGNIOL-VILLARD
This will ensure that we just start secured binary
without user confirmation

But for now on we only support EFI correctly signed image to start
Later will allow both.

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagn...@jcrosoft.com>
---
 arch/x86/Kconfig | 1 +
 common/efi/efi-image.c   | 1 +
 drivers/efi/efi-device.c | 9 +
 3 files changed, 11 insertions(+)

diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 52ccf4894..65e4c8b7c 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -78,6 +78,7 @@ choice
select EFI_DEVICEPATH
select PRINTF_UUID
select CLOCKSOURCE_EFI_X86
+   select HAS_SECURE_BOOT
 
config X86_BIOS_BRINGUP
bool "16 bit BIOS"
diff --git a/common/efi/efi-image.c b/common/efi/efi-image.c
index 885348da4..6552d803d 100644
--- a/common/efi/efi-image.c
+++ b/common/efi/efi-image.c
@@ -270,6 +270,7 @@ static int do_bootm_efi(struct image_data *data)
 static struct image_handler efi_handle_tr = {
.name = "EFI Application",
.bootm = do_bootm_efi,
+   .is_secure_supported = 1,
.filetype = filetype_exe,
 };
 
diff --git a/drivers/efi/efi-device.c b/drivers/efi/efi-device.c
index 7029bfb31..959878e7f 100644
--- a/drivers/efi/efi-device.c
+++ b/drivers/efi/efi-device.c
@@ -26,6 +26,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -382,6 +383,14 @@ static int efi_is_setup_mode(void)
return ret != 0;
 }
 
+int is_secure_mode(void)
+{
+   int secure_boot = efi_is_secure_boot();
+   int setup_mode = efi_is_setup_mode();
+
+   return secure_boot & !setup_mode;
+}
+
 static int efi_init_devices(void)
 {
char *fw_vendor = NULL;
-- 
2.11.0


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


[PATCH 2/5] efi: fix lds for secure boot support

2017-03-09 Thread Jean-Christophe PLAGNIOL-VILLARD
everythink need to be aligned to 4096

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagn...@jcrosoft.com>
---
 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*)
*(.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);
}
 
_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 <plag...@jcrosoft.com>
+ *
+ * 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


[PATCH 1/5] efi: add more security related guid for the efivars

2017-03-09 Thread Jean-Christophe PLAGNIOL-VILLARD
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagn...@jcrosoft.com>
---
 common/efi-guid.c |  6 ++
 include/efi.h | 18 ++
 2 files changed, 24 insertions(+)

diff --git a/common/efi-guid.c b/common/efi-guid.c
index 71aa21ddd..01b02bbb1 100644
--- a/common/efi-guid.c
+++ b/common/efi-guid.c
@@ -81,6 +81,12 @@ const char *efi_guid_string(efi_guid_t *g)
EFI_GUID_STRING( EFI_TCG_PROTOCOL_GUID, "TcgService", "TCGServices 
Protocol");
/* TPM 2.0 */
EFI_GUID_STRING( EFI_TCG2_PROTOCOL_GUID, "Tcg2Service", "TCG2Services 
Protocol");
+   EFI_GUID_STRING(EFI_VENDOR_KEYS_NV_VARIABLE_NAME_GUID, "VendorKeysNv", 
"Vendor Keys Non-Volatile");
+   EFI_GUID_STRING(EFI_AUTHENTICATED_VARIABLE_GUID, "AuthVar", 
"Authenticated Variable");
+   EFI_GUID_STRING(EFI_IMAGE_SECURITY_DATABASE_GUID, "ImageSecurityDB", 
"Image Security Database");
+   EFI_GUID_STRING(EFI_CERT_DB_GUID, "CertDB", "Certificate Database");
+   EFI_GUID_STRING(EFI_SECURE_BOOT_ENABLE_DISABLE_GUID, 
"SecureBootEnable", "Secure Boot Enable Disable");
+   EFI_GUID_STRING(EFI_CUSTOM_MODE_ENABLE_GUID, "CustomMode", 
"CustomMode");
 
/* File */
EFI_GUID_STRING(EFI_IDEBUSDXE_INF_GUID, "IdeBusDxe.inf", "EFI 
IdeBusDxe.inf File GUID");
diff --git a/include/efi.h b/include/efi.h
index e1fc134ee..31e7b283e 100644
--- a/include/efi.h
+++ b/include/efi.h
@@ -507,6 +507,24 @@ extern efi_runtime_services_t *RT;
 #define EFI_TCG2_PROTOCOL_GUID \
EFI_GUID(0x607f766c, 0x7455, 0x42be, 0x93, 0x0b, 0xe4, 0xd7, 0x6d, 
0xb2, 0x72, 0x0f)
 
+#define EFI_VENDOR_KEYS_NV_VARIABLE_NAME_GUID \
+   EFI_GUID(0x9073e4e0, 0x60ec, 0x4b6e, 0x99, 0x3, 0x4c, 0x22, 0x3c, 0x26, 
0x0f, 0x3c)
+
+#define EFI_AUTHENTICATED_VARIABLE_GUID \
+   EFI_GUID(0xaaf32c78, 0x947b, 0x439a, 0xa1, 0x80, 0x2e, 0x14, 0x4e, 
0xc3,0x77, 0x92)
+
+#define EFI_IMAGE_SECURITY_DATABASE_GUID \
+   EFI_GUID(0xd719b2cb, 0x3d3a, 0x4596, 0xa3, 0xbc, 0xda, 0xd0, 0xe, 0x67, 
0x65, 0x6f)
+
+#define EFI_CERT_DB_GUID \
+   EFI_GUID(0xd9bee56e, 0x75dc, 0x49d9, 0xb4, 0xd7, 0xb5, 0x34, 0x21, 0xf, 
0x63, 0x7a)
+
+#define EFI_SECURE_BOOT_ENABLE_DISABLE_GUID \
+   EFI_GUID(0xf0a30bc7, 0xaf08, 0x4556, 0x99, 0xc4, 0x00, 0x10, 0x9, 0xc9, 
0x3a, 0x44)
+
+#define EFI_CUSTOM_MODE_ENABLE_GUID \
+   EFI_GUID(0xc076ec0c, 0x7028, 0x4399, 0xa0, 0x72, 0x71, 0xee, 0x5c, 
0x44, 0x8b, 0x9f)
+
 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;
-- 
2.11.0


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


[PATCH 0/5] EFI Secure boot support

2017-03-09 Thread Jean-Christophe PLAGNIOL-VILLARD
Hi,

This patch serie is the first one to add the secure boot support
to barebox on efi

For now on this will allow you to execute only properly signed EFI
Application.

And request confirmation for non signed binary other than EFI

Later will add non signed EFI Application execution request at user
request and MoK Support, add other goodies.

Please pull
The following changes since commit 071eb906506d478a3d0b04460625e64edbcd1294:

  efi: fix secure and setup mode report (2017-03-04 13:20:38 +0800)

are available in the git repository at:

  git://git.jcrosoft.org/barebox.git delivery/efi-sb

for you to fetch changes up to 99e61a9be467fab5b5127b1233c4c4e70288e84c:

  efi: enable sercure boot support (2017-03-04 13:20:38 +0800)


Jean-Christophe PLAGNIOL-VILLARD (2):
  boot: if we are in secure boot mode
  efi: enable sercure boot support

 arch/x86/Kconfig |  1 +
 commands/go.c|  7 +++
 common/Kconfig   |  8 
 common/Makefile  |  1 +
 common/bootm.c   |  7 +++
 common/efi/efi-image.c   |  1 +
 common/secure_boot.c | 43 +++
 drivers/efi/efi-device.c |  9 +
 include/bootm.h  |  1 +
 include/secure_boot.h| 25 +
 10 files changed, 103 insertions(+)
 create mode 100644 common/secure_boot.c
 create mode 100644 include/secure_boot.h

Best Regards,
J.

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


[PATCH 2/3] x86: add __raw_read{b,w,l,q} and __raw_write{b,w,l,q}

2017-03-09 Thread Jean-Christophe PLAGNIOL-VILLARD
so we can use __iowrite{32/64} to speedup the framebuffer console scrolling

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagn...@jcrosoft.com>
---
 arch/x86/include/asm/io.h | 33 +
 1 file changed, 33 insertions(+)

diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
index df4bc99ec..189eb9aae 100644
--- a/arch/x86/include/asm/io.h
+++ b/arch/x86/include/asm/io.h
@@ -21,6 +21,10 @@ build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
 build_mmio_read(readw, "w", unsigned short, "=r", :"memory")
 build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
 
+build_mmio_read(__readb, "b", unsigned char, "=q", )
+build_mmio_read(__readw, "w", unsigned short, "=r", )
+build_mmio_read(__readl, "l", unsigned int, "=r", )
+
 #define build_mmio_write(name, size, type, reg, barrier) \
  static inline void name(type val, volatile void *addr) \
  { asm volatile("mov" size " %0,%1": :reg (val), \
@@ -30,6 +34,10 @@ build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
 build_mmio_write(writew, "w", unsigned short, "r", :"memory")
 build_mmio_write(writel, "l", unsigned int, "r", :"memory")
 
+build_mmio_write(__writeb, "b", unsigned char, "q", )
+build_mmio_write(__writew, "w", unsigned short, "r", )
+build_mmio_write(__writel, "l", unsigned int, "r", )
+
 #define BUILDIO(bwl, bw, type) \
 static inline void out##bwl(unsigned type value, int port) \
 {  \
@@ -61,6 +69,31 @@ BUILDIO(b, b, char)
 BUILDIO(w, w, short)
 BUILDIO(l, , int)
 
+#define __raw_readb __readb
+#define __raw_readw __readw
+#define __raw_readl __readl
+
+#define __raw_writeb __writeb
+#define __raw_writew __writew
+#define __raw_writel __writel
+
+#ifdef CONFIG_X86_64
+
+build_mmio_read(readq, "q", unsigned long, "=r", :"memory")
+build_mmio_write(writeq, "q", unsigned long, "r", :"memory")
+
+#define readq_relaxed(a)   readq(a)
+#define writeq_relaxed(v, a)   writeq(v, a)
+
+#define __raw_readq(a) readq(a)
+#define __raw_writeq(val, addr)writeq(val, addr)
+
+/* Let people know that we have them */
+#define readq  readq
+#define writeq writeq
+
+#endif
+
 #define  IO_SPACE_LIMIT  0x
 
 /* do a tiny io delay */
-- 
2.11.0


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


[PATCH 3/3] fbcon: use __iowrite{32/64} to speedup the framebuffer console scrolling

2017-03-09 Thread Jean-Christophe PLAGNIOL-VILLARD
this devide the time by 4 on x86

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagn...@jcrosoft.com>
---
 drivers/video/fbconsole.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/video/fbconsole.c b/drivers/video/fbconsole.c
index b261f1704..b5e951e23 100644
--- a/drivers/video/fbconsole.c
+++ b/drivers/video/fbconsole.c
@@ -6,6 +6,7 @@
 #include 
 #include 
 #include 
+#include 
 
 enum state_t {
LIT,/* Literal input */
@@ -202,7 +203,7 @@ static void printchar(struct fbc_priv *priv, int c)
 
buf = gui_screen_render_buffer(priv->sc);
 
-   memcpy(buf, buf + line_height, line_height * priv->rows);
+   __iowrite64_copy(buf, buf + line_height, (line_height * 
priv->rows) >> 2);
memset(buf + line_height * priv->rows, 0, line_height);
 
gu_screen_blit(priv->sc);
-- 
2.11.0


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


[PATCH 1/3] import linux __iowrite32/64_copy support

2017-03-09 Thread Jean-Christophe PLAGNIOL-VILLARD
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagn...@jcrosoft.com>
---
 include/linux/io.h | 27 +
 lib/Makefile   |  1 +
 lib/iomap_copy.c   | 70 ++
 3 files changed, 98 insertions(+)
 create mode 100644 include/linux/io.h
 create mode 100644 lib/iomap_copy.c

diff --git a/include/linux/io.h b/include/linux/io.h
new file mode 100644
index 0..a87501c6c
--- /dev/null
+++ b/include/linux/io.h
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2006 PathScale, Inc.  All Rights Reserved.
+ *
+ * This file is free software; you can redistribute it and/or modify
+ * it under the terms of version 2 of the GNU General Public License
+ * as published by the Free Software Foundation.
+ *
+ * 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,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#ifndef _LINUX_IO_H
+#define _LINUX_IO_H
+
+#include 
+#include 
+
+void __iowrite32_copy(void __iomem *to, const void *from, size_t count);
+void __iowrite64_copy(void __iomem *to, const void *from, size_t count);
+
+#endif /* _LINUX_IO_H */
diff --git a/lib/Makefile b/lib/Makefile
index 1be174249..052fe10f2 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -1,6 +1,7 @@
 obj-y  += bcd.o
 obj-$(CONFIG_BOOTSTRAP)+= bootstrap/
 obj-y  += ctype.o
+obj-y  += iomap_copy.o
 obj-y  += rbtree.o
 obj-y  += display_options.o
 obj-y  += string.o
diff --git a/lib/iomap_copy.c b/lib/iomap_copy.c
new file mode 100644
index 0..8732ae0e1
--- /dev/null
+++ b/lib/iomap_copy.c
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2006 PathScale, Inc.  All Rights Reserved.
+ *
+ * This file is free software; you can redistribute it and/or modify
+ * it under the terms of version 2 of the GNU General Public License
+ * as published by the Free Software Foundation.
+ *
+ * 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,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include 
+#include 
+
+/**
+ * __iowrite32_copy - copy data to MMIO space, in 32-bit units
+ * @to: destination, in MMIO space (must be 32-bit aligned)
+ * @from: source (must be 32-bit aligned)
+ * @count: number of 32-bit quantities to copy
+ *
+ * Copy data from kernel space to MMIO space, in units of 32 bits at a
+ * time.  Order of access is not guaranteed, nor is a memory barrier
+ * performed afterwards.
+ */
+void __attribute__((weak)) __iowrite32_copy(void __iomem *to,
+   const void *from,
+   size_t count)
+{
+   u32 __iomem *dst = to;
+   const u32 *src = from;
+   const u32 *end = src + count;
+
+   while (src < end)
+   __raw_writel(*src++, dst++);
+}
+EXPORT_SYMBOL_GPL(__iowrite32_copy);
+
+/**
+ * __iowrite64_copy - copy data to MMIO space, in 64-bit or 32-bit units
+ * @to: destination, in MMIO space (must be 64-bit aligned)
+ * @from: source (must be 64-bit aligned)
+ * @count: number of 64-bit quantities to copy
+ *
+ * Copy data from kernel space to MMIO space, in units of 32 or 64 bits at a
+ * time.  Order of access is not guaranteed, nor is a memory barrier
+ * performed afterwards.
+ */
+void __attribute__((weak)) __iowrite64_copy(void __iomem *to,
+   const void *from,
+   size_t count)
+{
+#ifdef CONFIG_64BIT
+   u64 __iomem *dst = to;
+   const u64 *src = from;
+   const u64 *end = src + count;
+
+   while (src < end)
+   __raw_writeq(*src++, dst++);
+#else
+   __iowrite32_copy(to, from, count * 2);
+#endif
+}
+
+EXPORT_SYMBOL_GPL(__iowrite64_copy);
-- 
2.11.0


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


[PATCH 2/2] video: some framebuffer such as efi does support enable/disable

2017-03-09 Thread Jean-Christophe PLAGNIOL-VILLARD
so allow them to do not pass this function via fbops
and indicate they are always on.

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagn...@jcrosoft.com>
---
 drivers/video/fb.c | 29 -
 1 file changed, 24 insertions(+), 5 deletions(-)

diff --git a/drivers/video/fb.c b/drivers/video/fb.c
index 6b88f2df9..63a818eb2 100644
--- a/drivers/video/fb.c
+++ b/drivers/video/fb.c
@@ -19,10 +19,12 @@ static int fb_ioctl(struct cdev* cdev, int req, void *data)
*fb = info;
break;
case FBIO_ENABLE:
-   info->fbops->fb_enable(info);
+   if (info->fbops->fb_enable)
+   info->fbops->fb_enable(info);
break;
case FBIO_DISABLE:
-   info->fbops->fb_disable(info);
+   if (info->fbops->fb_disable)
+   info->fbops->fb_disable(info);
break;
default:
return -ENOSYS;
@@ -94,7 +96,8 @@ int fb_enable(struct fb_info *info)
if (ret)
return ret;
 
-   info->fbops->fb_enable(info);
+   if (info->fbops->fb_enable)
+   info->fbops->fb_enable(info);
 
info->enabled = true;
 
@@ -106,7 +109,8 @@ int fb_disable(struct fb_info *info)
if (!info->enabled)
return 0;
 
-   info->fbops->fb_disable(info);
+   if (info->fbops->fb_disable)
+   info->fbops->fb_disable(info);
 
fb_release_shadowfb(info);
 
@@ -266,6 +270,8 @@ static int fb_set_shadowfb(struct param_d *p, void *priv)
return fb_alloc_shadowfb(info);
 }
 
+struct fb_ops dummy_fbops;
+
 int register_framebuffer(struct fb_info *info)
 {
int id = get_free_deviceid("fb");
@@ -273,6 +279,16 @@ int register_framebuffer(struct fb_info *info)
int ret, num_modes, i;
const char **names;
 
+   if (!info->p_enable) {
+   if (!info->fbops)
+   return -EINVAL;
+   if (!info->fbops->fb_enable && !info->fbops->fb_disable)
+   return -EINVAL;
+   } else {
+   if (!info->fbops)
+   info->fbops = _fbops;
+   }
+
dev = >dev;
 
/*
@@ -308,7 +324,10 @@ int register_framebuffer(struct fb_info *info)
if (ret)
goto err_free;
 
-   dev_add_param_bool(dev, "enable", fb_enable_set, NULL,
+   if (info->p_enable)
+   dev_add_param_int_ro(dev, "enable", info->p_enable, "%d");
+   else
+   dev_add_param_bool(dev, "enable", fb_enable_set, NULL,
>p_enable, info);
 
if (IS_ENABLED(CONFIG_DRIVER_VIDEO_EDID))
-- 
2.11.0


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


[PATCH 1/2] parameter: fix read only int support

2017-03-09 Thread Jean-Christophe PLAGNIOL-VILLARD
pass PARAM_FLAG_RO flag for read only it
so we can not change them

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagn...@jcrosoft.com>
---
 lib/parameter.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/parameter.c b/lib/parameter.c
index 9f96d0760..65d6c7c0d 100644
--- a/lib/parameter.c
+++ b/lib/parameter.c
@@ -692,7 +692,7 @@ struct param_d *dev_add_param_int_ro(struct device_d *dev, 
const char *name,
 
piro = xzalloc(sizeof(*piro));
 
-   ret = __dev_add_param(>param, dev, name, NULL, NULL, 0);
+   ret = __dev_add_param(>param, dev, name, NULL, NULL, 
PARAM_FLAG_RO);
if (ret) {
free(piro);
return ERR_PTR(ret);
@@ -718,7 +718,7 @@ struct param_d *dev_add_param_llint_ro(struct device_d 
*dev, const char *name,
 
piro = xzalloc(sizeof(*piro));
 
-   ret = __dev_add_param(>param, dev, name, NULL, NULL, 0);
+   ret = __dev_add_param(>param, dev, name, NULL, NULL, 
PARAM_FLAG_RO);
if (ret) {
free(piro);
return ERR_PTR(ret);
-- 
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 Jean-Christophe PLAGNIOL-VILLARD

> On Mar 9, 2017, at 4:46 PM, Michael Olbrich <m.olbr...@pengutronix.de> wrote:
> 
> On Mon, Mar 06, 2017 at 06:04:10AM +0100, Jean-Christophe PLAGNIOL-VILLARD 
> wrote:
>> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagn...@jcrosoft.com>
>> ---
>> 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.
you can not enable or disable them

so this need to be fix at framework level not driver

Best Regards,
J.
> 
> 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


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


Re: [PATCH 00/45] AT91, at91sam9x5ek updates

2017-03-07 Thread Jean-Christophe PLAGNIOL-VILLARD

> On Mar 8, 2017, at 5:18 AM, Andrey Smirnov  wrote:
> 
> On Tue, Mar 7, 2017 at 12:58 PM, Sam Ravnborg  wrote:
 
 When booting from an SD-Card/NOR-Flash/USB would I then need
 to use at91bootstrap, or can I use only barebox?
 
 If I move forward with this and I can find an 9263
 evaluation kit I would then also update this.
>>> On 9263 the sram is huge so you can build barebox as first stage
>> 
>> Good - simplicity is good.
>> 
> 
> For  at91sam9x5ek I had to use at91bootstrap since there is first
> stage loader in Barebox for it. I don't know about 9263, but I trust
> Jean-Christophe to be correct on this one.

I’ve patch for all the at91 soc for the pbl and nand and mmc

but I’m really busy those days on EFI boot support 
and secure boot. To be able to pass microsoft certification so we can use 
barebox
to boot linux or even windows.

So I’ll try to dig them later

Best Regards,
J.
> 
>>> 
>>> I add this a long time ago on usb_a9263_bootstrap_defconfig
>>> or other (all the EK).
>>> 
>>> This will build a barebox that can load you image from multiple source in a 
>>> sequence
>>> 
>>> and then use a std barebox
>>> 
>>> To switch to DT you will have to import the DT I did for the kernel
>> OK, should be straighforward.
>> 
>>> and replace the hw i2c by a i2c gpio as the i2c IP on at91 has a lot of 
>>> quirks
>>> and for barebox it will not make sense to port it
>> Seems less straightforward but doable.
>> 
> 
> Not sure what the situation on 9263 is, but FWIW, kernel DT file from
> the kernel for 9x5ek secifies I2C0 as GPIO bitbanged on, and I believe
> I had it working so hopefully it would be just a DT related change
> that you'd need to do.
> 
> Thanks,
> Andrey Smirnov


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


Re: [PATCH 00/45] AT91, at91sam9x5ek updates

2017-03-07 Thread Jean-Christophe PLAGNIOL-VILLARD

> On Mar 8, 2017, at 12:34 AM, Sam Ravnborg  wrote:
> 
> Hi Andrey.
> 
> On Mon, Mar 06, 2017 at 02:53:11PM -0800, Andrey Smirnov wrote:
>> Hi everyone,
>> 
>> I recently had a chance to work with at91sam9x5ek board and as a part
>> of that effort I converted the code to support features found in
>> Barebox for i.MX based SoCs. Most notably this patchset converts
>> at91sam9x5ek to use multi-image PBL build process as well as adds
>> support for board initialization from attached devicetree blob.
> 
> Impressive series - looks good! And timing was good.
> 
> I have a proprietary at91sam9263 based bord that is familiar
> with the 9263 evaluation kit.
> The current bootloader is latest bootstrap + an ancient U-Boot.
> As we have another board (i.MX6 based) there is some synergy into
> using the same bootloader on both boards.
> 
> Can you give any hints on what needs to be done on top of
> your patch-set to support the 9263 evalutation kit?
> 
> When booting from an SD-Card/NOR-Flash/USB would I then need
> to use at91bootstrap, or can I use only barebox?
> 
> If I move forward with this and I can find an 9263
> evaluation kit I would then also update this.
On 9263 the sram is huge so you can build barebox as first stage

I add this a long time ago on usb_a9263_bootstrap_defconfig
or other (all the EK).

This will build a barebox that can load you image from multiple source in a 
sequence

and then use a std barebox

To switch to DT you will have to import the DT I did for the kernel
and replace the hw i2c by a i2c gpio as the i2c IP on at91 has a lot of quirks
and for barebox it will not make sense to port it

Best Regards,
J.
___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 1/2] x86: efi: fix efiexit support

2017-03-07 Thread Jean-Christophe PLAGNIOL-VILLARD
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagn...@jcrosoft.com>
---
 arch/x86/mach-efi/elf_x86_64_efi.lds.S | 1 +
 1 file changed, 1 insertion(+)

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 e1bc2120f..93d34d17a 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


[PATCH 2/2] x86: efi: fix logo support

2017-03-07 Thread Jean-Christophe PLAGNIOL-VILLARD
we need to copy the logo section too

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagn...@jcrosoft.com>
---
 arch/x86/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/Makefile b/arch/x86/Makefile
index e837a2df9..6921b10a7 100644
--- a/arch/x86/Makefile
+++ b/arch/x86/Makefile
@@ -85,7 +85,7 @@ 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 .bblogo.* --target=$(TARGET) $< $@
 
 KBUILD_BINARY := barebox
 
-- 
2.11.0


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


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

2017-03-06 Thread Jean-Christophe PLAGNIOL-VILLARD
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.

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagn...@jcrosoft.com>
---
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 <plagn...@jcrosoft.com>
+ *
+ * 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 generic console_device.
+ */
+struct efi_serial_port {
+   struct efi_serial_io_protocol *serial;
+   struct console_device   uart;   /* uart */
+   struct efi_device *efidev;
+};
+
+static inline struct efi_serial_port *
+to_efi_serial_port(struct console_device *uart)
+{
+   return container_of(uart, struct efi_serial_port, uart);
+}
+
+static int efi_serial_setbaudrate(struct console_device *cdev, int baudrate)
+{
+   struct efi_serial_port *uar

[PATCH 1/1] video: sdl fix typo

2017-03-05 Thread Jean-Christophe PLAGNIOL-VILLARD
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagn...@jcrosoft.com>
---
 drivers/video/sdl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/video/sdl.c b/drivers/video/sdl.c
index 5e1dc8e57..8f5b409ef 100644
--- a/drivers/video/sdl.c
+++ b/drivers/video/sdl.c
@@ -53,7 +53,7 @@ static int sdlfb_probe(struct device_d *dev)
fb->yres = fb->mode->yres;
 
fb->priv = fb;
-   fb->fbops = _ops,
+   fb->fbops = _ops;
 
fb->dev.parent = dev;
fb->screen_base = xzalloc(fb->xres * fb->yres *
-- 
2.11.0


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


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

2017-03-05 Thread Jean-Christophe PLAGNIOL-VILLARD
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.

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagn...@jcrosoft.com>
---
 drivers/serial/Kconfig  |   4 +
 drivers/serial/Makefile |   1 +
 drivers/serial/serial_efi.c | 241 
 3 files changed, 246 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..35387bfd5
--- /dev/null
+++ b/drivers/serial/serial_efi.c
@@ -0,0 +1,241 @@
+/*
+ * (C) Copyright 2000
+ * Rob Taylor, Flying Pig Systems. r...@flyingpig.com.
+ *
+ * (C) Copyright 2004
+ * ARM Ltd.
+ * Philippe Robin, <philippe.ro...@arm.com>
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License 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.
+ *
+ */
+
+/* Simple U-Boot driver for the PrimeCell PL010/PL011 UARTs */
+
+#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);
+ 

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

2017-03-05 Thread Jean-Christophe PLAGNIOL-VILLARD
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagn...@jcrosoft.com>
---
 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/Kconfig b/drivers/video/Kconfig
index 8f31f5af7..8d50db6f6 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -24,6 +24,10 @@ config DRIVER_VIDEO_ATMEL_HLCD
bool "Atmel HLCDC framebuffer driver"
depends on ARCH_AT91
 
+config DRIVER_VIDEO_EFI_GOP
+   bool "EFI Graphics Output Protocol (GOP)"
+   depends on EFI_BOOTUP
+
 config DRIVER_VIDEO_IMX
bool "i.MX framebuffer driver"
depends on ARCH_IMX1 || ARCH_IMX21 || ARCH_IMX25 || ARCH_IMX27
diff --git a/drivers/video/Makefile b/drivers/video/Makefile
index 1bf2e1f3c..97712182e 100644
--- a/drivers/video/Makefile
+++ b/drivers/video/Makefile
@@ -21,3 +21,5 @@ obj-$(CONFIG_DRIVER_VIDEO_OMAP) += omap.o
 obj-$(CONFIG_DRIVER_VIDEO_BCM283X) += bcm2835.o
 obj-$(CONFIG_DRIVER_VIDEO_SIMPLEFB) += simplefb.o
 obj-$(CONFIG_DRIVER_VIDEO_IMX_IPUV3) += imx-ipu-v3/
+
+obj-$(CONFIG_DRIVER_VIDEO_EFI_GOP) += efi_gop.o
diff --git a/drivers/video/efi_gop.c b/drivers/video/efi_gop.c
new file mode 100644
index 0..ccb4af3d9
--- /dev/null
+++ b/drivers/video/efi_gop.c
@@ -0,0 +1,267 @@
+/*
+ * Copyright 2011 Intel Corporation; author Matt Fleming
+ * Copyright (c) 2017 Jean-Christophe PLAGNIOL-VILLARD <plagn...@jcrosoft.com>
+ *
+ * GPL v2
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define PIXEL_RGB_RESERVED_8BIT_PER_COLOR  0
+#define PIXEL_BGR_RESERVED_8BIT_PER_COLOR  1
+#define PIXEL_BIT_MASK 2
+#define PIXEL_BLT_ONLY 3
+#define PIXEL_FORMAT_MAX   4
+
+struct efi_pixel_bitmask {
+   u32 red_mask;
+   u32 green_mask;
+   u32 blue_mask;
+   u32 reserved_mask;
+};
+
+struct efi_graphics_output_mode_info {
+   u32 version;
+   u32 horizontal_resolution;
+   u32 vertical_resolution;
+   int pixel_format;
+   struct efi_pixel_bitmask pixel_information;
+   u32 pixels_per_scan_line;
+};
+
+struct efi_graphics_output_protocol_mode {
+   uint32_t max_mode;
+   uint32_t mode;
+   struct efi_graphics_output_mode_info *info;
+   unsigned long size_of_info;
+   void *frame_buffer_base;
+   unsigned long frame_buffer_size;
+};
+
+struct efi_graphics_output_protocol {
+   efi_status_t (EFIAPI *query_mode) (struct efi_graphics_output_protocol 
*This,
+   uint32_t mode_number, unsigned long *size_of_info,
+   struct efi_graphics_output_mode_info **info);
+   efi_status_t (EFIAPI *set_mode) (struct efi_graphics_output_protocol 
*This,
+   uint32_t mode_number);
+   efi_status_t (EFIAPI *blt)(struct efi_graphics_output_protocol *This,
+   void *buffer,
+   unsigned long operation,
+   unsigned long sourcex, unsigned long sourcey,
+   unsigned long destinationx, unsigned long destinationy,
+   unsigned long width, unsigned long height, unsigned
+   long delta);
+   struct efi_graphics_output_protocol_mode *mode;
+};
+
+struct efi_gop_priv {
+   struct device_d *dev;
+   struct fb_info fb;
+
+   uint32_t mode;
+   struct efi_graphics_output_protocol *gop;
+};
+
+static void find_bits(unsigned long mask, u32 *pos, u32 *size)
+{
+   u8 first, len;
+
+   first = 0;
+   len = 0;
+
+   if (mask) {
+   while (!(mask & 0x1)) {
+   mask = mask >> 1;
+   first++;
+   }
+
+   while (mask & 0x1) {
+   mask = mask >> 1;
+   len++;
+   }
+   }
+
+   *pos = first;
+   *size = len;
+}
+
+static void setup_pixel_info(struct fb_info *fb, u32 pixels_per_scan_line,
+struct efi_pixel_bitmask pixel_info, int pixel_format)
+{
+   if (pixel_format == PIXEL_RGB_RESERVED_8BIT_PER_COLOR) {
+   fb->bits_per_pixel = 32;
+   fb->line_length = pixels_per_scan_line * 4;
+   fb->red.length = 8;
+   fb->red.offset = 0;
+   fb->green.length = 8;
+   fb->green.offset = 8;
+   fb->blue.length = 8;
+   fb->blue.offset = 16;
+   fb->transp.length = 8;
+   fb->transp.offset = 24;
+   } else if (pixel_format == PIXEL_BGR_RESERVED_8BIT_PER_COLOR) {
+   fb->bits_per_pixel = 32;
+   fb-

[PATCH 0/2] add support of efi Serial IO and Graphics Output Protocol

2017-03-05 Thread Jean-Christophe PLAGNIOL-VILLARD
Hi,

The following changes since commit d92ed454107b4d6f0d30fa0271da191ae5911d18:

  Merge branch 'for-next/video' into next (2017-02-27 08:51:08 +0100)

are available in the git repository at:

  git://git.jcrosoft.org/barebox.git delivery/serial-gop

for you to fetch changes up to 6ecbe33539f20076bbc781b9e20a5a54d504fdf3:

  efi: add serial driver support (2017-03-01 22:11:37 +0800)


Jean-Christophe PLAGNIOL-VILLARD (2):
  video: add EFI Graphics Output Protocol support
  efi: add serial driver support

 drivers/serial/Kconfig  |   4 +++
 drivers/serial/Makefile |   1 +
 drivers/serial/serial_efi.c | 241 

 drivers/video/Kconfig   |   4 +++
 drivers/video/Makefile  |   2 ++
 drivers/video/efi_gop.c | 267 
+++
 6 files changed, 519 insertions(+)
 create mode 100644 drivers/serial/serial_efi.c
 create mode 100644 drivers/video/efi_gop.c

Best Regards,
J.

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


[PATCH 2/2] driver: generate hash at runtime to speed up device/driver matching

2017-03-03 Thread Jean-Christophe PLAGNIOL-VILLARD
use GNU Hash

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagn...@jcrosoft.com>
---
 drivers/base/bus.c| 12 
 drivers/base/driver.c | 27 ++-
 include/driver.h  |  5 +
 3 files changed, 39 insertions(+), 5 deletions(-)

diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index 03feba502..2da736a4b 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -58,13 +58,13 @@ int device_match(struct device_d *dev, struct driver_d *drv)
struct platform_device_id *id = drv->id_table;
 
while (id->name) {
-   if (!strcmp(id->name, dev->name)) {
+   if (dev->hash == id->hash && !strcmp(id->name, 
dev->name)) {
dev->id_entry = id;
return 0;
}
id++;
}
-   } else if (!strcmp(dev->name, drv->name)) {
+   } else if (dev->hash == drv->hash && !strcmp(dev->name, drv->name)) {
return 0;
}
 
@@ -77,6 +77,7 @@ int device_match_of_modalias(struct device_d *dev, struct 
driver_d *drv)
const char *of_modalias = NULL, *p;
int cplen;
const char *compat;
+   unsigned long hash;
 
if (!device_match(dev, drv))
return 0;
@@ -90,14 +91,17 @@ int device_match_of_modalias(struct device_d *dev, struct 
driver_d *drv)
 
p = strchr(compat, ',');
of_modalias = p ? p + 1 : compat;
+   if (of_modalias)
+   hash = gnu_hash(of_modalias);
 
while (id->name) {
-   if (!strcmp(id->name, dev->name)) {
+   if (id->hash == dev->hash && !strcmp(id->name, dev->name)) {
dev->id_entry = id;
return 0;
}
 
-   if (of_modalias && !strcmp(id->name, of_modalias)) {
+   if (of_modalias && id->hash == hash &&
+   !strcmp(id->name, of_modalias)) {
dev->id_entry = id;
return 0;
}
diff --git a/drivers/base/driver.c b/drivers/base/driver.c
index 5867fe45d..c3257f640 100644
--- a/drivers/base/driver.c
+++ b/drivers/base/driver.c
@@ -46,6 +46,17 @@ EXPORT_SYMBOL(driver_list);
 static LIST_HEAD(active);
 static LIST_HEAD(deferred);
 
+unsigned long gnu_hash(const unsigned char *name)
+{
+   unsigned long h = 5381;
+   unsigned char c;
+
+   for (c = *name; c != '\0'; c = *++name)
+   h = h * 33 + c;
+
+   return h & 0x;
+}
+
 struct device_d *get_device_by_name(const char *name)
 {
struct device_d *dev;
@@ -61,9 +72,10 @@ struct device_d *get_device_by_name(const char *name)
 static struct device_d *get_device_by_name_id(const char *name, int id)
 {
struct device_d *dev;
+   unsigned long hash = gnu_hash(name);
 
for_each_device(dev) {
-   if(!strcmp(dev->name, name) && id == dev->id)
+   if(hash == dev->hash && !strcmp(dev->name, name) && id == 
dev->id)
return dev;
}
 
@@ -165,6 +177,8 @@ int register_device(struct device_d *new_device)
 {
struct driver_d *drv;
 
+   new_device->hash = gnu_hash(new_device->name);
+
if (new_device->id == DEVICE_ID_DYNAMIC) {
new_device->id = get_free_deviceid(new_device->name);
} else {
@@ -302,6 +316,17 @@ int register_driver(struct driver_d *drv)
 
BUG_ON(!drv->bus);
 
+   drv->hash = gnu_hash(drv->name);
+
+   if (drv->id_table) {
+   struct platform_device_id *id = drv->id_table;
+
+   while (id->name) {
+   id->hash = gnu_hash(id->name);
+   id++;
+   }
+   }
+
list_add_tail(>list, _list);
list_add_tail(>bus_list, >bus->driver_list);
 
diff --git a/include/driver.h b/include/driver.h
index db7f9c780..64b59dc91 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -31,8 +31,11 @@
 struct filep;
 struct bus_type;
 
+unsigned long gnu_hash(const unsigned char *name);
+
 struct platform_device_id {
const char *name;
+   unsigned long hash;
unsigned long driver_data;
 };
 
@@ -42,6 +45,7 @@ struct device_d {
 * driver. This is a descriptive name and could be MPC5XXX_ether or
 * imx_serial. */
char name[MAX_DRIVER_NAME];
+   unsigned long hash;
/*! The id is used to uniquely identify a device in the system. The id
 * will show up under /dev/ as the device's name. Usually this is
 * something like eth0 or nor0. */
@@ -95,6 +99,7 @@ struct driver_d {
/*! The name o

[PATCH 1/2] driver: remove the const of struct platform_device_id *id_table

2017-03-03 Thread Jean-Christophe PLAGNIOL-VILLARD
so we can generate the hash at register time

This will allow speed up the device/driver matching as strcmp is slow.

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagn...@jcrosoft.com>
---
 drivers/base/bus.c | 4 ++--
 include/driver.h   | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index b889a4866..03feba502 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -55,7 +55,7 @@ int device_match(struct device_d *dev, struct driver_d *drv)
return of_match(dev, drv);
 
if (drv->id_table) {
-   const struct platform_device_id *id = drv->id_table;
+   struct platform_device_id *id = drv->id_table;
 
while (id->name) {
if (!strcmp(id->name, dev->name)) {
@@ -73,7 +73,7 @@ int device_match(struct device_d *dev, struct driver_d *drv)
 
 int device_match_of_modalias(struct device_d *dev, struct driver_d *drv)
 {
-   const struct platform_device_id *id = drv->id_table;
+   struct platform_device_id *id = drv->id_table;
const char *of_modalias = NULL, *p;
int cplen;
const char *compat;
diff --git a/include/driver.h b/include/driver.h
index 6abaaad8b..db7f9c780 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -107,7 +107,7 @@ struct driver_d {
 
struct bus_type *bus;
 
-   const struct platform_device_id *id_table;
+   struct platform_device_id *id_table;
const struct of_device_id *of_compatible;
 };
 
-- 
2.11.0


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


[RFC PATCH 0/2] use gnuhash to speed up device/driver match

2017-03-03 Thread Jean-Christophe PLAGNIOL-VILLARD
Hi,

The following patch series use the gnu hash to speedup device/driver
matching.

String compare is slow so we will calculate at runtime a hash that we
can compare quickly to speed up the match

in a second step we could speed up this more by calculating the hash
at compile time

The following changes since commit d92ed454107b4d6f0d30fa0271da191ae5911d18:

  Merge branch 'for-next/video' into next (2017-02-27 08:51:08 +0100)

are available in the git repository at:

  git://git.jcrosoft.org/barebox.git delivery/gnuhash

for you to fetch changes up to 5ede85afc958bdf488a3c5e56061e7f27c26cbc6:

  driver: generate hash at runtime to speed up device/driver matching 
(2017-03-01 03:49:34 +0800)


Jean-Christophe PLAGNIOL-VILLARD (2):
  driver: remove the const of struct platform_device_id *id_table
  driver: generate hash at runtime to speed up device/driver matching

 drivers/base/bus.c| 16 ++--
 drivers/base/driver.c | 27 ++-
 include/driver.h  |  7 ++-
 3 files changed, 42 insertions(+), 8 deletions(-)

Best Regards,
J.

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


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

2017-03-03 Thread Jean-Christophe PLAGNIOL-VILLARD
today we use -

such as Boot-8be4df61-93ca-11d2-aa0d-00e098032b8c

now we will use a different approach where will represent first the vendor
as a directory and then inside the associates variable.

But also create symlink on the vendor with readable name.

so it will look like this:

barebox@barebox EFI payload:/ ls -l /efivars/
drwxrwxrwx 36 04b37fe8-f6ae-480b-bdd5-37d98c5e89aa
drwxrwxrwx 36 4a67b082-0a4c-41cf-b6c7-440b29bb8c4f
drwxrwxrwx 36 4c19049f-4137-4dd3-9c10-8b97a83ffdfa
drwxrwxrwx 36 5b446ed1-e30b-4faa-871a-3654eca36080
drwxrwxrwx 36 5b91f69c-8b88-4a2b-9269-5f1d802b5175
drwxrwxrwx 36 8be4df61-93ca-11d2-aa0d-00e098032b8c
lrwxrwxrwx  3 Efi -> 8be4df61-93ca-11d2-aa0d-00e098032b8c
lrwxrwxrwx  7 barebox -> 5b91f69c-8b88-4a2b-9269-5f1d802b5175
drwxrwxrwx 36 eb704011-1402-11d3-8e77-00a0c969723b
lrwxrwxrwx  7 systemd -> 4a67b082-0a4c-41cf-b6c7-440b29bb8c4f
barebox@barebox EFI payload:/ ls -l /efivars/Efi/
-rw-rw-rw- 62 Boot
-rw-rw-rw- 80 Boot0001
-rw-rw-rw- 84 Boot0002
-rw-rw-rw-106 Boot0003
-rw-rw-rw-108 Boot0004
-rw-rw-rw-141 Boot0005
-rw-rw-rw- 88 Boot0006
-rw-rw-rw-  2 BootCurrent
-rw-rw-rw-  4 BootOptionSupport
-rw-rw-rw- 14 BootOrder
-rw-rw-rw-107 ConIn
-rw-rw-rw-   1567 ConInDev
-rw-rw-rw-103 ConOut
-rw-rw-rw-   1855 ConOutDev
-rw-rw-rw- 73 ErrOut
-rw-rw-rw-   1563 ErrOutDev
-rw-rw-rw- 14 Key
-rw-rw-rw- 14 Key0001
-rw-rw-rw-  4 Lang
-rw-rw-rw- 13 LangCodes
-rw-rw-rw-  8 OsIndicationsSupported
-rw-rw-rw-  3 PlatformLang
-rw-rw-rw- 18 PlatformLangCodes
-rw-rw-rw-108 PlatformRecovery
-rw-rw-rw-  2 Timeout
barebox@barebox EFI payload:/ ls -l /efivars/barebox/
barebox@barebox EFI payload:/ ls -l /efivars/systemd/
-rw-rw-rw- 14 LoaderTimeInitUSec

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagn...@jcrosoft.com>
---
 common/efi-guid.c |  17 ++-
 common/efi/efi.c  |   2 +-
 fs/efivarfs.c | 379 ++
 include/efi.h |   1 +
 4 files changed, 312 insertions(+), 87 deletions(-)

diff --git a/common/efi-guid.c b/common/efi-guid.c
index 71aa21ddd..6908012df 100644
--- a/common/efi-guid.c
+++ b/common/efi-guid.c
@@ -14,11 +14,21 @@ efi_guid_t efi_systemd_vendor_guid = 
EFI_SYSTEMD_VENDOR_GUID;
 
 #define EFI_GUID_STRING(guid, short, long) do {\
if (!efi_guidcmp(guid, *g)) \
-   return long;\
+   return is_long ? long : short;  \
} while(0)
 
+
 const char *efi_guid_string(efi_guid_t *g)
 {
+   const char *name;
+
+   name = efi_guid_string_type(g, 1);
+
+   return name ? name : "Unknown";
+}
+
+const char *efi_guid_string_type(efi_guid_t *g, int is_long)
+{
EFI_GUID_STRING(EFI_NULL_GUID, "NULL", "NULL GUID");
EFI_GUID_STRING(EFI_MPS_TABLE_GUID, "MPS Table", "MPS Table GUID in EFI 
System Table");
EFI_GUID_STRING(EFI_ACPI_TABLE_GUID, "ACPI Table", "ACPI 1.0 Table GUID 
in EFI System Table");
@@ -88,5 +98,8 @@ const char *efi_guid_string(efi_guid_t *g)
EFI_GUID_STRING(EFI_ISCSIDXE_INF_GUID, "IScsiDxe.inf", "EFI 
IScsiDxe.inf File GUID");
EFI_GUID_STRING(EFI_VLANCONFIGDXE_INF_GUID, "VlanConfigDxe.inf", "EFI 
VlanConfigDxe.inf File GUID");
 
-   return "unknown";
+   EFI_GUID_STRING(EFI_BAREBOX_VENDOR_GUID, "barebox", "Barebox 
Bootloader");
+   EFI_GUID_STRING(EFI_SYSTEMD_VENDOR_GUID, "systemd", "Linux systemd");
+
+   return NULL;
 }
diff --git a/common/efi/efi.c b/common/efi/efi.c
index 05c58250f..b4a5bb88e 100644
--- a/common/efi/efi.c
+++ b/common/efi/efi.c
@@ -299,7 +299,7 @@ static int efi_init(void)
 
defaultenv_append_directory(env_efi);
 
-   env = xasprintf("/efivars/barebox-env-%pUl", _barebox_vendor_guid);
+   env = xasprintf("/efivars/%pUl/barebox-env", _barebox_vendor_guid);
default_environment_path_set(env);
 
return 0;
diff --git a/fs/efivarfs.c b/fs/efivarfs.c
index bf7351e6d..90aa3cfcf 100644
--- a/fs/efivarfs.c
+++ b/fs/efivarfs.c
@@ -27,6 +27,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -35,21 +36,99 @@
 #include 
 
 struct efivarfs_inode {
+   int is_dir;
+   int is_symlink;
s16 *name;
efi_guid_t vendor;
char *full_name; /* name including vendor namespacing */
+   struct efivarfs_inode *parent;
struct list_head node;
-};
-
-struct efi

[PATCH 1/2] ls: allow to list a symlink ending with '/' as a dir

2017-03-03 Thread Jean-Christophe PLAGNIOL-VILLARD
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagn...@jcrosoft.com>
---
 commands/ls.c | 41 +++--
 1 file changed, 35 insertions(+), 6 deletions(-)

diff --git a/commands/ls.c b/commands/ls.c
index 331a4d201..3bd5e3ff8 100644
--- a/commands/ls.c
+++ b/commands/ls.c
@@ -64,6 +64,16 @@ int ls(const char *path, ulong flags)
if (flags & LS_SHOWARG && s.st_mode & S_IFDIR)
printf("%s:\n", path);
 
+   if (S_ISLNK(s.st_mode)) {
+   int len = strlen(path);
+   
+   if (path[len - 1] != '/') {
+   ls_one(path, path, );
+   return 0;
+   }
+   s.st_mode |= S_IFDIR;
+   }
+
if (!(s.st_mode & S_IFDIR)) {
ls_one(path, path, );
return 0;
@@ -171,13 +181,25 @@ static int do_ls(int argc, char *argv[])
continue;
}
 
-   if (!(s.st_mode & S_IFDIR)) {
-   if (flags & LS_COLUMN)
-   string_list_add_sorted(, argv[o]);
-   else
-   ls_one(argv[o], argv[o], );
+   if (s.st_mode & S_IFDIR) {
+   o++;
+   continue;
}
 
+   if (s.st_mode & S_IFLNK) {
+   int len = strlen(argv[o]);
+   
+   if (argv[o][len - 1] == '/') {
+   o++;
+   continue;
+   }
+   }
+
+   if (flags & LS_COLUMN)
+   string_list_add_sorted(, argv[o]);
+   else
+   ls_one(argv[o], argv[o], );
+
o++;
}
 
@@ -197,7 +219,14 @@ static int do_ls(int argc, char *argv[])
continue;
}
 
-   if (s.st_mode & S_IFDIR) {
+   if (s.st_mode & S_IFDIR || s.st_mode & S_IFLNK) {
+   int len = strlen(argv[o]);
+   
+   if (s.st_mode & S_IFLNK && argv[o][len - 1] != '/') {
+   o++;
+   continue;
+   }
+
ret = ls(argv[o], flags);
if (ret) {
perror("ls");
-- 
2.11.0


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


Re: [PATCH 2/3] ARM: correctly identify ARMv6 K/Z

2017-03-03 Thread Jean-Christophe PLAGNIOL-VILLARD
On 07:04 Fri 03 Mar , Sascha Hauer wrote:
> On Thu, Mar 02, 2017 at 11:42:48AM +0100, Lucas Stach wrote:
> > Am Mittwoch, den 01.03.2017, 18:55 +0100 schrieb Jean-Christophe
> > PLAGNIOL-VILLARD:
> > > On 15:26 Wed 01 Mar , Lucas Stach wrote:
> > > > The ARMv6 K/Z derivatives have a v7 compatible MMU, but all other
> > > > parts
> > > > (including the cache handling) is still at v6. As we don't make use
> > > > of
> > > > the more advanced features of the v7 MMU in Barebox, it's okay to
> > > > just
> > > > override this to properly identify the CPU as ARMv6.
> > > 
> > > evenif we do not use it now I do not liek the idea to report it as
> > > ARMv6
> > > 
> > > It will be better to report it correctly
> > > 
> > Weather you like it or not, ARM1176 is ARMv6 with a v7 MMU bolted on,
> > so reporting it as ARMv6 is the correct thing to do.

except when will want to use them we will have to fix the detection it's
better to do it at assignation to check the arm1176 or v6

Best Regards,
J.

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


[PATCH 1/9] efi: add prototype and definition for creating and closing event

2017-03-03 Thread Jean-Christophe PLAGNIOL-VILLARD
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagn...@jcrosoft.com>
---
 include/efi.h | 17 +++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/include/efi.h b/include/efi.h
index 5691f4e8f..f65980687 100644
--- a/include/efi.h
+++ b/include/efi.h
@@ -185,12 +185,25 @@ typedef struct {
   unsigned long *, u32 *);
efi_status_t (EFIAPI *allocate_pool)(int, unsigned long, void **);
efi_status_t (EFIAPI *free_pool)(void *);
-   void *create_event;
+#define EFI_EVT_TIMER  0x8000
+#define EFI_EVT_RUNTIME0x4000
+#define EFI_EVT_NOTIFY_WAIT0x0100
+#define EFI_EVT_NOTIFY_SIGNAL  0x0200
+#define EFI_EVT_SIGNAL_EXIT_BOOT_SERVICES  0x0201
+#define EFI_EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE  0x6202
+
+#define EFI_TPL_APPLICATION4
+#define EFI_TPL_CALLBACK   8
+#define EFI_TPL_NOTIFY 16
+#define EFI_TPL_HIGH_LEVEL 31
+   efi_status_t(EFIAPI *create_event)(u32 type , unsigned long tpl,
+   void (*fn) (void *event, void *ctx),
+   void *ctx, void **event);
void *set_timer;
efi_status_t(EFIAPI *wait_for_event)(unsigned long number_of_events, 
void *event,
unsigned long *index);
void *signal_event;
-   void *close_event;
+   efi_status_t(EFIAPI *close_event)(void *event);
void *check_event;
void *install_protocol_interface;
void *reinstall_protocol_interface;
-- 
2.11.0


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


[PATCH 7/9] efi: move x86 clocksource to device/driver

2017-03-03 Thread Jean-Christophe PLAGNIOL-VILLARD
so we can dynamicly register the device

As we may need to use HW IP for clocksource.

As on EFI we could use Timestamp GUID if present (Not often the case as it's
not even enabled by default on any Target on EDK II not even OVMF)

Or if we choose we could use a Simulated Timestamp driver that work on Event
(Add Later)

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagn...@jcrosoft.com>
---
 arch/x86/Kconfig |  2 +-
 arch/x86/mach-efi/Makefile   |  1 +
 arch/x86/mach-efi/clocksource.c  | 11 +++
 drivers/clocksource/Kconfig  |  6 +++---
 drivers/clocksource/Makefile |  2 +-
 drivers/clocksource/{efi.c => efi_x86.c} | 34 
 6 files changed, 43 insertions(+), 13 deletions(-)
 create mode 100644 arch/x86/mach-efi/clocksource.c
 rename drivers/clocksource/{efi.c => efi_x86.c} (56%)

diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 9803f3f95..52ccf4894 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -77,7 +77,7 @@ choice
select EFI_GUID
select EFI_DEVICEPATH
select PRINTF_UUID
-   select CLOCKSOURCE_EFI
+   select CLOCKSOURCE_EFI_X86
 
config X86_BIOS_BRINGUP
bool "16 bit BIOS"
diff --git a/arch/x86/mach-efi/Makefile b/arch/x86/mach-efi/Makefile
index c8a97bae0..f633e7c7e 100644
--- a/arch/x86/mach-efi/Makefile
+++ b/arch/x86/mach-efi/Makefile
@@ -1,4 +1,5 @@
 obj-$(CONFIG_X86_64) += reloc_x86_64.o crt0-efi-x86_64.o
 obj-$(CONFIG_X86_32) += reloc_ia32.o crt0-efi-ia32.o
+obj-y += clocksource.o
 extra-$(CONFIG_X86_32) += elf_ia32_efi.lds
 extra-$(CONFIG_X86_64) += elf_x86_64_efi.lds
diff --git a/arch/x86/mach-efi/clocksource.c b/arch/x86/mach-efi/clocksource.c
new file mode 100644
index 0..2023fa19a
--- /dev/null
+++ b/arch/x86/mach-efi/clocksource.c
@@ -0,0 +1,11 @@
+#include 
+#include 
+#include 
+
+static int efi_x86_pure_init(void)
+{
+   struct device_d *dev = device_alloc("efi-cs-x86", DEVICE_ID_SINGLE);
+
+   return platform_device_register(dev);
+}
+core_initcall(efi_x86_pure_init);
diff --git a/drivers/clocksource/Kconfig b/drivers/clocksource/Kconfig
index 54b05bbf3..9b7f0a9d7 100644
--- a/drivers/clocksource/Kconfig
+++ b/drivers/clocksource/Kconfig
@@ -34,9 +34,9 @@ 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
-   depends on EFI_BOOTUP
+config CLOCKSOURCE_EFI_X86
+   bool "EFI X86 HW driver"
+   depends on EFI_BOOTUP && X86
 
 config CLOCKSOURCE_MVEBU
bool
diff --git a/drivers/clocksource/Makefile b/drivers/clocksource/Makefile
index e83fdeeec..1fd18296e 100644
--- a/drivers/clocksource/Makefile
+++ b/drivers/clocksource/Makefile
@@ -3,7 +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
 obj-$(CONFIG_CLOCKSOURCE_ORION)   += orion.o
diff --git a/drivers/clocksource/efi.c b/drivers/clocksource/efi_x86.c
similarity index 56%
rename from drivers/clocksource/efi.c
rename to drivers/clocksource/efi_x86.c
index 6d2fee8eb..4d2657ea1 100644
--- a/drivers/clocksource/efi.c
+++ b/drivers/clocksource/efi_x86.c
@@ -1,5 +1,6 @@
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -38,24 +39,41 @@ static uint64_t ticks_freq(void)
return (ticks_end - ticks_start) * 1000;
 }
 
-static uint64_t efi_clocksource_read(void)
+static uint64_t efi_x86_cs_read(void)
 {
return 1000 * 1000 * ticks_read() / freq;
 }
 
-static struct clocksource cs = {
-   .read   = efi_clocksource_read,
+static int efi_x86_cs_init(struct clocksource *cs)
+{
+   cs->mult = clocksource_hz2mult(1000 * 1000, cs->shift);
+
+   freq = ticks_freq();
+
+   return 0;
+}
+
+static struct clocksource efi_x86_cs = {
+   .read   = efi_x86_cs_read,
.mask   = CLOCKSOURCE_MASK(64),
.shift  = 0,
+   .priority = 100,
+   .init   = efi_x86_cs_init,
 };
 
-static int efi_clocksource_init(void)
+static int efi_x86_cs_probe(struct device_d *dev)
 {
-   cs.mult = clocksource_hz2mult(1000 * 1000, cs.shift);
+   return init_clock(_x86_cs);
+}
 
-   freq = ticks_freq();
+static struct driver_d efi_x86_cs_driver = {
+   .name = "efi-cs-x86",
+   .probe = efi_x86_cs_probe,
+};
 
-   return init_clock();
+static int efi_x86_cs_initcall(void)
+{
+   return platform_driver_register(_x86_cs_driver);
 }
 /* for efi the time must be init at

[PATCH 8/9] efi: clocksoure: add EFI event timer

2017-03-03 Thread Jean-Christophe PLAGNIOL-VILLARD
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 <plagn...@jcrosoft.com>
---
 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..89906c452
--- /dev/null
+++ b/drivers/clocksource/efi.c
@@ -0,0 +1,110 @@
+/*
+ * Copyright (C) 2017 Jean-Christophe PLAGNIOL-VILLARD <plag...@jcrosoft.com>
+ *
+ * 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();
+   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,
+};
+
+static int efi_cs_probe(struct device_d *dev)
+{
+   return init_clock(_cs);
+}
+
+static struct driver_d efi_cs_driver = {
+   .name = "efi-cs",
+   .probe = efi_cs_probe,
+};
+
+static int efi_cs_initcall(void)
+{
+   return platform_driver_register(_cs_drive

[PATCH 5/9] clocksource: allow to have multiple device from clock source

2017-03-03 Thread Jean-Christophe PLAGNIOL-VILLARD
use the one with the most priority.

We can not select the clocksource at user level.

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagn...@jcrosoft.com>
---
 common/clock.c  | 11 +++
 include/clock.h |  3 ++-
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/common/clock.c b/common/clock.c
index 2c5dd91cc..1090b605f 100644
--- a/common/clock.c
+++ b/common/clock.c
@@ -213,6 +213,17 @@ EXPORT_SYMBOL(mdelay_non_interruptible);
 
 int init_clock(struct clocksource *cs)
 {
+   if (current_clock && cs->priority <= current_clock->priority)
+   return 0;
+
+   if (cs->init) {
+   int ret;
+
+   ret = cs->init(cs);
+   if (ret)
+   return ret;
+   }
+
current_clock = cs;
time_beginning = get_time_ns();
 
diff --git a/include/clock.h b/include/clock.h
index d65e404e8..5f2f53ab6 100644
--- a/include/clock.h
+++ b/include/clock.h
@@ -12,7 +12,8 @@ struct clocksource {
uint64_t(*read)(void);
uint64_tcycle_last;
uint64_tmask;
-
+   int priority;
+   int (*init)(struct clocksource*);
 };
 
 static inline uint32_t cyc2ns(struct clocksource *cs, uint64_t cycles)
-- 
2.11.0


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


[PATCH 9/9] efi: add veriable to report secure boot support and status

2017-03-03 Thread Jean-Christophe PLAGNIOL-VILLARD
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagn...@jcrosoft.com>
---
 drivers/efi/efi-device.c | 33 +
 1 file changed, 33 insertions(+)

diff --git a/drivers/efi/efi-device.c b/drivers/efi/efi-device.c
index db8b25147..6ed7f12b3 100644
--- a/drivers/efi/efi-device.c
+++ b/drivers/efi/efi-device.c
@@ -354,11 +354,41 @@ static void efi_businfo(struct device_d *dev)
}
 }
 
+static int efi_is_secure_boot(void)
+{
+   uint8_t *val;
+   int ret = 0;
+
+   val = efi_get_variable("SecureBoot", _global_variable_guid, NULL);
+   if (!IS_ERR(val)) {
+   ret = *val;
+   free(val);
+   }
+
+   return ret != 1;
+}
+
+static int efi_is_setup_mode(void)
+{
+   uint8_t *val;
+   int ret = 0;
+
+   val = efi_get_variable("SetupMode", _global_variable_guid, NULL);
+   if (!IS_ERR(val)) {
+   ret = *val;
+   free(val);
+   }
+
+   return ret != 1;
+}
+
 static int efi_init_devices(void)
 {
char *fw_vendor = NULL;
u16 sys_major = efi_sys_table->hdr.revision >> 16;
u16 sys_minor = efi_sys_table->hdr.revision & 0x;
+   int secure_boot = efi_is_secure_boot();
+   int setup_mode = efi_is_setup_mode();
 
fw_vendor = strdup_wchar_to_char((const wchar_t 
*)efi_sys_table->fw_vendor);
 
@@ -374,6 +404,9 @@ static int efi_init_devices(void)
dev_add_param_int_ro(efi_bus.dev, "major", sys_major, "%u");
dev_add_param_int_ro(efi_bus.dev, "minor", sys_minor, "%u");
dev_add_param_int_ro(efi_bus.dev, "fw_revision", 
efi_sys_table->fw_revision, "%u");
+   dev_add_param_int_ro(efi_bus.dev, "secure_boot", secure_boot, "%d");
+   dev_add_param_int_ro(efi_bus.dev, "secure_mode",
+secure_boot & setup_mode, "%u");
 
efi_bus.dev->info = efi_businfo;
 
-- 
2.11.0


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


[PATCH 4/9] efi: move x86 clocksource init at core initcall level

2017-03-03 Thread Jean-Christophe PLAGNIOL-VILLARD
so we can use device/driver model

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagn...@jcrosoft.com>
---
 common/efi/efi.c  | 1 -
 drivers/clocksource/efi.c | 5 -
 include/efi/efi.h | 2 --
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/common/efi/efi.c b/common/efi/efi.c
index 1c7aee872..4b589b600 100644
--- a/common/efi/efi.c
+++ b/common/efi/efi.c
@@ -348,7 +348,6 @@ efi_status_t efi_main(efi_handle_t image, 
efi_system_table_t *sys_table)
  efi_strerror(efiret));
mem_malloc_init((void *)mem, (void *)mem + memsize);
 
-   efi_clocksource_init();
start_barebox();
 
return EFI_SUCCESS;
diff --git a/drivers/clocksource/efi.c b/drivers/clocksource/efi.c
index 59fd9918a..6d2fee8eb 100644
--- a/drivers/clocksource/efi.c
+++ b/drivers/clocksource/efi.c
@@ -1,4 +1,5 @@
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -48,7 +49,7 @@ static struct clocksource cs = {
.shift  = 0,
 };
 
-int efi_clocksource_init(void)
+static int efi_clocksource_init(void)
 {
cs.mult = clocksource_hz2mult(1000 * 1000, cs.shift);
 
@@ -56,3 +57,5 @@ int efi_clocksource_init(void)
 
return init_clock();
 }
+/* for efi the time must be init at core initcall level */
+core_initcall(efi_clocksource_init);
diff --git a/include/efi/efi.h b/include/efi/efi.h
index 2b25cf186..648afb9ec 100644
--- a/include/efi/efi.h
+++ b/include/efi/efi.h
@@ -12,8 +12,6 @@ extern efi_loaded_image_t *efi_loaded_image;
 
 int efi_errno(efi_status_t err);
 
-int efi_clocksource_init(void);
-
 void *efi_get_variable(char *name, efi_guid_t *vendor, int *var_size);
 
 static inline void *efi_get_global_var(char *name, int *var_size)
-- 
2.11.0


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


[PATCH 3/9] efi: move LoaderTimeInitUSec and LoaderDevicePartUUID to postcore initcall

2017-03-03 Thread Jean-Christophe PLAGNIOL-VILLARD
so we can use device/driver for the timer

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagn...@jcrosoft.com>
---
 common/efi/efi.c | 15 +++
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/common/efi/efi.c b/common/efi/efi.c
index 217a6bea8..1c7aee872 100644
--- a/common/efi/efi.c
+++ b/common/efi/efi.c
@@ -314,7 +314,6 @@ efi_status_t efi_main(efi_handle_t image, 
efi_system_table_t *sys_table)
efi_physical_addr_t mem;
size_t memsize;
efi_status_t efiret;
-   char *uuid;
 
 #ifdef DEBUG
sys_table->con_out->output_string(sys_table->con_out, L"barebox\n");
@@ -350,6 +349,15 @@ 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();
+   start_barebox();
+
+   return EFI_SUCCESS;
+}
+
+static int efi_postcore_init(void)
+{
+   char *uuid;
+
efi_set_variable_usec("LoaderTimeInitUSec", _systemd_vendor_guid,
  get_time_ns()/1000);
 
@@ -366,10 +374,9 @@ efi_status_t efi_main(efi_handle_t image, 
efi_system_table_t *sys_table)
free(uuid16);
}
 
-   start_barebox();
-
-   return EFI_SUCCESS;
+   return 0;
 }
+postcore_initcall(efi_postcore_init);
 
 static int do_efiexit(int argc, char *argv[])
 {
-- 
2.11.0


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


[PATCH 6/9] clocksource: move dummy clock source to init_clock

2017-03-03 Thread Jean-Christophe PLAGNIOL-VILLARD
And registered it as soon as possible (at pure initcall).
So we not need to check the cs all the time.
As get_time_ns() is one of the most called function of barebox at runtime.

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagn...@jcrosoft.com>
---
 common/clock.c | 33 -
 1 file changed, 24 insertions(+), 9 deletions(-)

diff --git a/common/clock.c b/common/clock.c
index 1090b605f..0d581c2c7 100644
--- a/common/clock.c
+++ b/common/clock.c
@@ -36,9 +36,32 @@ static uint64_t time_ns;
  */
 uint64_t time_beginning;
 
+static uint64_t dummy_read(void)
+{
+   static uint64_t dummy_counter;
+
+   dummy_counter += CONFIG_CLOCKSOURCE_DUMMY_RATE;
+
+   return dummy_counter;
+}
+
+static struct clocksource dummy_cs = {
+   .shift = 0,
+   .mult = 1,
+   .read = dummy_read,
+   .mask = CLOCKSOURCE_MASK(64),
+   .priority = -1,
+};
+
+static int dummy_csrc_init(void)
+{
+   return init_clock(_cs);
+}
+pure_initcall(dummy_csrc_init);
+
 static int dummy_csrc_warn(void)
 {
-   if (!current_clock) {
+   if (current_clock == _cs) {
pr_warn("Warning: Using dummy clocksource\n");
}
 
@@ -55,14 +78,6 @@ uint64_t get_time_ns(void)
uint64_t cycle_now, cycle_delta;
uint64_t ns_offset;
 
-   if (!cs) {
-   static uint64_t dummy_counter;
-
-   dummy_counter += CONFIG_CLOCKSOURCE_DUMMY_RATE;
-
-   return dummy_counter;
-   }
-
/* read clocksource: */
cycle_now = cs->read() & cs->mask;
 
-- 
2.11.0


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


[PATCH 2/9] efi: add prototype and definition for setting timer

2017-03-03 Thread Jean-Christophe PLAGNIOL-VILLARD
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagn...@jcrosoft.com>
---
 include/efi.h | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/include/efi.h b/include/efi.h
index f65980687..e1fc134ee 100644
--- a/include/efi.h
+++ b/include/efi.h
@@ -171,6 +171,12 @@ struct efi_open_protocol_information_entry {
u32 open_count;
 };
 
+typedef enum {
+   EFI_TIMER_CANCEL = 0,
+   EFI_TIMER_PERIODIC = 1,
+   EFI_TIMER_RELATIVE = 2
+} efi_timer_delay_t;
+
 /*
  * EFI Boot Services table
  */
@@ -199,7 +205,7 @@ typedef struct {
efi_status_t(EFIAPI *create_event)(u32 type , unsigned long tpl,
void (*fn) (void *event, void *ctx),
void *ctx, void **event);
-   void *set_timer;
+   efi_status_t(EFIAPI *set_timer)(void *event, efi_timer_delay_t type, 
uint64_t time);
efi_status_t(EFIAPI *wait_for_event)(unsigned long number_of_events, 
void *event,
unsigned long *index);
void *signal_event;
-- 
2.11.0


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


[PATCH 0/9] add generic EFI timer

2017-03-03 Thread Jean-Christophe PLAGNIOL-VILLARD
Hi,

On EFI you have 3 ways to get to do "timer"

1: Simply by waiting X us and calling Boot Service udelay

2: By using event

3: By use the Timestamp GUID

for barebox this would be the best but even on EDK II this is never
ever compiled on any target.

So we have 2 choice, use a Hardware specific timer or implement the
timer using timestamp

This pull request allow you to enable 2 timers and use the best one at
runtime.

EFI x86 (HW specific)
EFI Generic (based on Event)

please pull

The following changes since commit d92ed454107b4d6f0d30fa0271da191ae5911d18:

  Merge branch 'for-next/video' into next (2017-02-27 08:51:08 +0100)

are available in the git repository at:

  git://git.jcrosoft.org/barebox.git delivery/efi-cs

for you to fetch changes up to f14af7444ad9d8ce674382f222119f5fcd3f2576:

  efi: add veriable to report secure boot support and status (2017-02-28 
23:05:31 +0800)

----
Jean-Christophe PLAGNIOL-VILLARD (9):
  efi: add prototype and definition for creating and closing event
  efi: add prototype and definition for setting timer
  efi: move LoaderTimeInitUSec and LoaderDevicePartUUID to postcore initcall
  efi: move x86 clocksource init at core initcall level
  clocksource: allow to have multiple device from clock source
  clocksource: move dummy clock source to init_clock
  efi: move x86 clocksource to device/driver
  efi: clocksoure: add EFI event timer
  efi: add veriable to report secure boot support and status

 arch/x86/Kconfig|   2 +-
 arch/x86/mach-efi/Makefile  |   1 +
 arch/x86/mach-efi/clocksource.c |  11 +++
 common/clock.c  |  44 
+++-
 common/efi/efi.c|  24 +++-
 drivers/clocksource/Kconfig |   6 +-
 drivers/clocksource/Makefile|   1 +
 drivers/clocksource/efi.c   | 110 
+-
 drivers/clocksource/efi_x86.c   |  79 
+++
 drivers/efi/efi-device.c|  33 +
 include/clock.h |   3 ++-
 include/efi.h   |  25 ++---
 include/efi/efi.h   |   2 --
 13 files changed, 290 insertions(+), 51 deletions(-)
 create mode 100644 arch/x86/mach-efi/clocksource.c
 create mode 100644 drivers/clocksource/efi_x86.c

Best Regards,
J.

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


Re: [PATCH 2/3] ARM: correctly identify ARMv6 K/Z

2017-03-01 Thread Jean-Christophe PLAGNIOL-VILLARD
On 15:26 Wed 01 Mar , Lucas Stach wrote:
> The ARMv6 K/Z derivatives have a v7 compatible MMU, but all other parts
> (including the cache handling) is still at v6. As we don't make use of
> the more advanced features of the v7 MMU in Barebox, it's okay to just
> override this to properly identify the CPU as ARMv6.
evenif we do not use it now I do not liek the idea to report it as ARMv6

It will be better to report it correctly

Best Regards,
J.
> 
> Signed-off-by: Lucas Stach 
> ---
>  arch/arm/cpu/cpuinfo.c | 8 
>  arch/arm/include/asm/system_info.h | 8 
>  2 files changed, 16 insertions(+)
> 
> diff --git a/arch/arm/cpu/cpuinfo.c b/arch/arm/cpu/cpuinfo.c
> index 86e19d9780d5..175475b038dc 100644
> --- a/arch/arm/cpu/cpuinfo.c
> +++ b/arch/arm/cpu/cpuinfo.c
> @@ -165,6 +165,14 @@ static int do_cpuinfo(int argc, char *argv[])
>   } else
>   cpu_arch = CPU_ARCH_UNKNOWN;
>  
> + /*
> +  * Special case for ARMv6 (K/Z) (has v7 compatible MMU, but is v6
> +  * otherwise). The below check just matches all ARMv6, as done in the
> +  * Linux kernel.
> +  */
> + if ((mainid & 0x7f000) == 0x7b000)
> + cpu_arch = CPU_ARCH_ARMv6;
> +
>   switch (cpu_arch) {
>   case CPU_ARCH_ARMv3:
>   architecture = "v3";
> diff --git a/arch/arm/include/asm/system_info.h 
> b/arch/arm/include/asm/system_info.h
> index 25fffd268177..a27b79e6dd08 100644
> --- a/arch/arm/include/asm/system_info.h
> +++ b/arch/arm/include/asm/system_info.h
> @@ -188,6 +188,14 @@ static inline int arm_early_get_cpu_architecture(void)
>   cpu_arch = CPU_ARCH_UNKNOWN;
>  #endif
>  
> + /*
> +  * Special case for ARMv6 (K/Z) (has v7 compatible MMU, but is v6
> +  * otherwise). The below check just matches all ARMv6, as done in the
> +  * Linux kernel.
> +  */
> + if ((read_cpuid_id() & 0x7f000) == 0x7b000)
> + cpu_arch = CPU_ARCH_ARMv6;
> +
>   return cpu_arch;
>  }
>  
> -- 
> 2.11.0
> 
> 
> ___
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox

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


Re: Zyxel NAS540 bricked?

2017-03-01 Thread Jean-Christophe PLAGNIOL-VILLARD
On 05:03 Mon 27 Feb , AndrewCz wrote:
> Hello all, hope you are well.
> 
> Recently, I followed a guide[1] to reflash my Zyxel NAS540[2] in order
> to put Debian on it. I'm pretty sure I bricked it and am just looking
> for confirmation.
> 
> I seem to be running into a bootloop where it will restart every two
> minutes or so. At least that is what seems to be indicated based on the
> frequency of the front panel lights lighting up. I reflashed the 'env'
> and 'kernel2' sections of the NOR flash, but neither went the right way.
> I can dive into the specifics if necessary. However, my concern is that
> I was unable to receive any output from the serial connection.
> 
> Given that the barebox 'env' may be corrupt as well as the kernel, is it
> correct to expect that there would be no serial output? Thanks for your
> consideration in this matter.

And evenif we would like to help you zyxel did not provide to source code of
theur barebox they modified. Just the source code of the 2011.06 version.

So you will have to request them and if they refuse we could then force them
to release it as Copyright holder.

Best Regards,
J.
> 
> --Andrew Cz
> 
> [1] https://l.unchti.me/2016/02/12/debian-nas540.html
> [2] http://zyxel.nas-central.org/wiki/Category:NAS540
> 
> -- 
> Only an idiot fights a war on two fronts. Only the heir to the throne
> of the kingdom of idiots would fight a war on twelve fronts.
> 
> ___
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox

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


Re: [PATCH 5/8] clocksource: allow to have multiple device from clock source

2017-03-01 Thread Jean-Christophe PLAGNIOL-VILLARD
On 08:09 Tue 28 Feb , Sascha Hauer wrote:
> On Mon, Feb 27, 2017 at 11:19:27AM +0100, Jean-Christophe PLAGNIOL-VILLARD 
> wrote:
> > use the one with the most priority.
> > 
> > We can not select the clocksource at user level.
> > 
> > Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagn...@jcrosoft.com>
> > ---
> >  common/clock.c  | 11 +++
> >  include/clock.h |  3 ++-
> >  2 files changed, 13 insertions(+), 1 deletion(-)
> > 
> > diff --git a/common/clock.c b/common/clock.c
> > index 2c5dd91cc..d99d06853 100644
> > --- a/common/clock.c
> > +++ b/common/clock.c
> > @@ -213,6 +213,17 @@ EXPORT_SYMBOL(mdelay_non_interruptible);
> >  
> >  int init_clock(struct clocksource *cs)
> >  {
> > +   if (current_clock && cs->priority < current_clock->priority)
> > +   return -EBUSY;
> 
> You should return successfully here. Otherwise driver probe functions
> return -EBUSY for something which is not the drivers fault. In fact,
> it's not an error, it's just that we currently don't have any use for an
> additional clock.
my issue is that we will report in barebox that the device is in use but in
fact is not as we exit the init_clock without doing event the init.

That's why I choosed to return -EBUSY instead of 0
> Also consider testing for <= current_clock->priority
> instead of <. All current clocks have priority 0 and we want to
> initialize only the first one.
ok

Best Regards,
J.

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


[PATCH 5/8] clocksource: allow to have multiple device from clock source

2017-02-27 Thread Jean-Christophe PLAGNIOL-VILLARD
use the one with the most priority.

We can not select the clocksource at user level.

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagn...@jcrosoft.com>
---
 common/clock.c  | 11 +++
 include/clock.h |  3 ++-
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/common/clock.c b/common/clock.c
index 2c5dd91cc..d99d06853 100644
--- a/common/clock.c
+++ b/common/clock.c
@@ -213,6 +213,17 @@ EXPORT_SYMBOL(mdelay_non_interruptible);
 
 int init_clock(struct clocksource *cs)
 {
+   if (current_clock && cs->priority < current_clock->priority)
+   return -EBUSY;
+
+   if (cs->init) {
+   int ret;
+
+   ret = cs->init(cs);
+   if (ret)
+   return ret;
+   }
+
current_clock = cs;
time_beginning = get_time_ns();
 
diff --git a/include/clock.h b/include/clock.h
index d65e404e8..5f2f53ab6 100644
--- a/include/clock.h
+++ b/include/clock.h
@@ -12,7 +12,8 @@ struct clocksource {
uint64_t(*read)(void);
uint64_tcycle_last;
uint64_tmask;
-
+   int priority;
+   int (*init)(struct clocksource*);
 };
 
 static inline uint32_t cyc2ns(struct clocksource *cs, uint64_t cycles)
-- 
2.11.0


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


[PATCH 8/8] efi: add veriable to report secure boot support and status

2017-02-27 Thread Jean-Christophe PLAGNIOL-VILLARD
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagn...@jcrosoft.com>
---
 drivers/efi/efi-device.c | 33 +
 1 file changed, 33 insertions(+)

diff --git a/drivers/efi/efi-device.c b/drivers/efi/efi-device.c
index db8b25147..6ed7f12b3 100644
--- a/drivers/efi/efi-device.c
+++ b/drivers/efi/efi-device.c
@@ -354,11 +354,41 @@ static void efi_businfo(struct device_d *dev)
}
 }
 
+static int efi_is_secure_boot(void)
+{
+   uint8_t *val;
+   int ret = 0;
+
+   val = efi_get_variable("SecureBoot", _global_variable_guid, NULL);
+   if (!IS_ERR(val)) {
+   ret = *val;
+   free(val);
+   }
+
+   return ret != 1;
+}
+
+static int efi_is_setup_mode(void)
+{
+   uint8_t *val;
+   int ret = 0;
+
+   val = efi_get_variable("SetupMode", _global_variable_guid, NULL);
+   if (!IS_ERR(val)) {
+   ret = *val;
+   free(val);
+   }
+
+   return ret != 1;
+}
+
 static int efi_init_devices(void)
 {
char *fw_vendor = NULL;
u16 sys_major = efi_sys_table->hdr.revision >> 16;
u16 sys_minor = efi_sys_table->hdr.revision & 0x;
+   int secure_boot = efi_is_secure_boot();
+   int setup_mode = efi_is_setup_mode();
 
fw_vendor = strdup_wchar_to_char((const wchar_t 
*)efi_sys_table->fw_vendor);
 
@@ -374,6 +404,9 @@ static int efi_init_devices(void)
dev_add_param_int_ro(efi_bus.dev, "major", sys_major, "%u");
dev_add_param_int_ro(efi_bus.dev, "minor", sys_minor, "%u");
dev_add_param_int_ro(efi_bus.dev, "fw_revision", 
efi_sys_table->fw_revision, "%u");
+   dev_add_param_int_ro(efi_bus.dev, "secure_boot", secure_boot, "%d");
+   dev_add_param_int_ro(efi_bus.dev, "secure_mode",
+secure_boot & setup_mode, "%u");
 
efi_bus.dev->info = efi_businfo;
 
-- 
2.11.0


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


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

2017-02-27 Thread Jean-Christophe PLAGNIOL-VILLARD
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 <plagn...@jcrosoft.com>
---
 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 <plag...@jcrosoft.com>
+ *
+ * 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();
+   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,
+};
+
+static int efi_cs_probe(struct device_d *dev)
+{
+   return init_clock(_cs);
+}
+
+static struct driver_d efi_cs_driver = {
+   .name = "efi-cs",
+   .probe = efi_cs_probe,
+};
+
+static int efi_cs_initcall(void)
+{
+   return platform_driver_register(_cs_drive

[PATCH 6/8] efi: move x86 clocksource to device/driver

2017-02-27 Thread Jean-Christophe PLAGNIOL-VILLARD
so we can dynamicly register the device

As we may need to use HW IP for clocksource.

As on EFI we could use Timestamp GUID if present (Not often the case as it's
not even enabled by default on any Target on EDK II not even OVMF)

Or if we choose we could use a Simulated Timestamp driver that work on Event
(Add Later)

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagn...@jcrosoft.com>
---
 arch/x86/Kconfig |  2 +-
 arch/x86/mach-efi/Makefile   |  1 +
 arch/x86/mach-efi/clocksource.c  | 11 +++
 drivers/clocksource/Kconfig  |  6 +++---
 drivers/clocksource/Makefile |  2 +-
 drivers/clocksource/{efi.c => efi_x86.c} | 34 
 6 files changed, 43 insertions(+), 13 deletions(-)
 create mode 100644 arch/x86/mach-efi/clocksource.c
 rename drivers/clocksource/{efi.c => efi_x86.c} (56%)

diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 9803f3f95..52ccf4894 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -77,7 +77,7 @@ choice
select EFI_GUID
select EFI_DEVICEPATH
select PRINTF_UUID
-   select CLOCKSOURCE_EFI
+   select CLOCKSOURCE_EFI_X86
 
config X86_BIOS_BRINGUP
bool "16 bit BIOS"
diff --git a/arch/x86/mach-efi/Makefile b/arch/x86/mach-efi/Makefile
index c8a97bae0..f633e7c7e 100644
--- a/arch/x86/mach-efi/Makefile
+++ b/arch/x86/mach-efi/Makefile
@@ -1,4 +1,5 @@
 obj-$(CONFIG_X86_64) += reloc_x86_64.o crt0-efi-x86_64.o
 obj-$(CONFIG_X86_32) += reloc_ia32.o crt0-efi-ia32.o
+obj-y += clocksource.o
 extra-$(CONFIG_X86_32) += elf_ia32_efi.lds
 extra-$(CONFIG_X86_64) += elf_x86_64_efi.lds
diff --git a/arch/x86/mach-efi/clocksource.c b/arch/x86/mach-efi/clocksource.c
new file mode 100644
index 0..2023fa19a
--- /dev/null
+++ b/arch/x86/mach-efi/clocksource.c
@@ -0,0 +1,11 @@
+#include 
+#include 
+#include 
+
+static int efi_x86_pure_init(void)
+{
+   struct device_d *dev = device_alloc("efi-cs-x86", DEVICE_ID_SINGLE);
+
+   return platform_device_register(dev);
+}
+core_initcall(efi_x86_pure_init);
diff --git a/drivers/clocksource/Kconfig b/drivers/clocksource/Kconfig
index 54b05bbf3..9b7f0a9d7 100644
--- a/drivers/clocksource/Kconfig
+++ b/drivers/clocksource/Kconfig
@@ -34,9 +34,9 @@ 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
-   depends on EFI_BOOTUP
+config CLOCKSOURCE_EFI_X86
+   bool "EFI X86 HW driver"
+   depends on EFI_BOOTUP && X86
 
 config CLOCKSOURCE_MVEBU
bool
diff --git a/drivers/clocksource/Makefile b/drivers/clocksource/Makefile
index e83fdeeec..1fd18296e 100644
--- a/drivers/clocksource/Makefile
+++ b/drivers/clocksource/Makefile
@@ -3,7 +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
 obj-$(CONFIG_CLOCKSOURCE_ORION)   += orion.o
diff --git a/drivers/clocksource/efi.c b/drivers/clocksource/efi_x86.c
similarity index 56%
rename from drivers/clocksource/efi.c
rename to drivers/clocksource/efi_x86.c
index 6d2fee8eb..4d2657ea1 100644
--- a/drivers/clocksource/efi.c
+++ b/drivers/clocksource/efi_x86.c
@@ -1,5 +1,6 @@
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -38,24 +39,41 @@ static uint64_t ticks_freq(void)
return (ticks_end - ticks_start) * 1000;
 }
 
-static uint64_t efi_clocksource_read(void)
+static uint64_t efi_x86_cs_read(void)
 {
return 1000 * 1000 * ticks_read() / freq;
 }
 
-static struct clocksource cs = {
-   .read   = efi_clocksource_read,
+static int efi_x86_cs_init(struct clocksource *cs)
+{
+   cs->mult = clocksource_hz2mult(1000 * 1000, cs->shift);
+
+   freq = ticks_freq();
+
+   return 0;
+}
+
+static struct clocksource efi_x86_cs = {
+   .read   = efi_x86_cs_read,
.mask   = CLOCKSOURCE_MASK(64),
.shift  = 0,
+   .priority = 100,
+   .init   = efi_x86_cs_init,
 };
 
-static int efi_clocksource_init(void)
+static int efi_x86_cs_probe(struct device_d *dev)
 {
-   cs.mult = clocksource_hz2mult(1000 * 1000, cs.shift);
+   return init_clock(_x86_cs);
+}
 
-   freq = ticks_freq();
+static struct driver_d efi_x86_cs_driver = {
+   .name = "efi-cs-x86",
+   .probe = efi_x86_cs_probe,
+};
 
-   return init_clock();
+static int efi_x86_cs_initcall(void)
+{
+   return platform_driver_register(_x86_cs_driver);
 }
 /* for efi the time must be init at

[PATCH 3/8] efi: move LoaderTimeInitUSec and LoaderDevicePartUUID to postcore initcall

2017-02-27 Thread Jean-Christophe PLAGNIOL-VILLARD
so we can use device/driver for the timer

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagn...@jcrosoft.com>
---
 common/efi/efi.c | 15 +++
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/common/efi/efi.c b/common/efi/efi.c
index 217a6bea8..1c7aee872 100644
--- a/common/efi/efi.c
+++ b/common/efi/efi.c
@@ -314,7 +314,6 @@ efi_status_t efi_main(efi_handle_t image, 
efi_system_table_t *sys_table)
efi_physical_addr_t mem;
size_t memsize;
efi_status_t efiret;
-   char *uuid;
 
 #ifdef DEBUG
sys_table->con_out->output_string(sys_table->con_out, L"barebox\n");
@@ -350,6 +349,15 @@ 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();
+   start_barebox();
+
+   return EFI_SUCCESS;
+}
+
+static int efi_postcore_init(void)
+{
+   char *uuid;
+
efi_set_variable_usec("LoaderTimeInitUSec", _systemd_vendor_guid,
  get_time_ns()/1000);
 
@@ -366,10 +374,9 @@ efi_status_t efi_main(efi_handle_t image, 
efi_system_table_t *sys_table)
free(uuid16);
}
 
-   start_barebox();
-
-   return EFI_SUCCESS;
+   return 0;
 }
+postcore_initcall(efi_postcore_init);
 
 static int do_efiexit(int argc, char *argv[])
 {
-- 
2.11.0


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


[PATCH 2/8] efi: add prototype and definition for setting timer

2017-02-27 Thread Jean-Christophe PLAGNIOL-VILLARD
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagn...@jcrosoft.com>
---
 include/efi.h | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/include/efi.h b/include/efi.h
index f65980687..e1fc134ee 100644
--- a/include/efi.h
+++ b/include/efi.h
@@ -171,6 +171,12 @@ struct efi_open_protocol_information_entry {
u32 open_count;
 };
 
+typedef enum {
+   EFI_TIMER_CANCEL = 0,
+   EFI_TIMER_PERIODIC = 1,
+   EFI_TIMER_RELATIVE = 2
+} efi_timer_delay_t;
+
 /*
  * EFI Boot Services table
  */
@@ -199,7 +205,7 @@ typedef struct {
efi_status_t(EFIAPI *create_event)(u32 type , unsigned long tpl,
void (*fn) (void *event, void *ctx),
void *ctx, void **event);
-   void *set_timer;
+   efi_status_t(EFIAPI *set_timer)(void *event, efi_timer_delay_t type, 
uint64_t time);
efi_status_t(EFIAPI *wait_for_event)(unsigned long number_of_events, 
void *event,
unsigned long *index);
void *signal_event;
-- 
2.11.0


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


[PATCH 4/8] efi: move x86 clocksource init at core initcall level

2017-02-27 Thread Jean-Christophe PLAGNIOL-VILLARD
so we can use device/driver model

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagn...@jcrosoft.com>
---
 common/efi/efi.c  | 1 -
 drivers/clocksource/efi.c | 5 -
 include/efi/efi.h | 2 --
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/common/efi/efi.c b/common/efi/efi.c
index 1c7aee872..4b589b600 100644
--- a/common/efi/efi.c
+++ b/common/efi/efi.c
@@ -348,7 +348,6 @@ efi_status_t efi_main(efi_handle_t image, 
efi_system_table_t *sys_table)
  efi_strerror(efiret));
mem_malloc_init((void *)mem, (void *)mem + memsize);
 
-   efi_clocksource_init();
start_barebox();
 
return EFI_SUCCESS;
diff --git a/drivers/clocksource/efi.c b/drivers/clocksource/efi.c
index 59fd9918a..6d2fee8eb 100644
--- a/drivers/clocksource/efi.c
+++ b/drivers/clocksource/efi.c
@@ -1,4 +1,5 @@
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -48,7 +49,7 @@ static struct clocksource cs = {
.shift  = 0,
 };
 
-int efi_clocksource_init(void)
+static int efi_clocksource_init(void)
 {
cs.mult = clocksource_hz2mult(1000 * 1000, cs.shift);
 
@@ -56,3 +57,5 @@ int efi_clocksource_init(void)
 
return init_clock();
 }
+/* for efi the time must be init at core initcall level */
+core_initcall(efi_clocksource_init);
diff --git a/include/efi/efi.h b/include/efi/efi.h
index 2b25cf186..648afb9ec 100644
--- a/include/efi/efi.h
+++ b/include/efi/efi.h
@@ -12,8 +12,6 @@ extern efi_loaded_image_t *efi_loaded_image;
 
 int efi_errno(efi_status_t err);
 
-int efi_clocksource_init(void);
-
 void *efi_get_variable(char *name, efi_guid_t *vendor, int *var_size);
 
 static inline void *efi_get_global_var(char *name, int *var_size)
-- 
2.11.0


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


[PATCH 1/8] efi: add prototype and definition for creating and closing event

2017-02-27 Thread Jean-Christophe PLAGNIOL-VILLARD
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagn...@jcrosoft.com>
---
 include/efi.h | 17 +++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/include/efi.h b/include/efi.h
index 5691f4e8f..f65980687 100644
--- a/include/efi.h
+++ b/include/efi.h
@@ -185,12 +185,25 @@ typedef struct {
   unsigned long *, u32 *);
efi_status_t (EFIAPI *allocate_pool)(int, unsigned long, void **);
efi_status_t (EFIAPI *free_pool)(void *);
-   void *create_event;
+#define EFI_EVT_TIMER  0x8000
+#define EFI_EVT_RUNTIME0x4000
+#define EFI_EVT_NOTIFY_WAIT0x0100
+#define EFI_EVT_NOTIFY_SIGNAL  0x0200
+#define EFI_EVT_SIGNAL_EXIT_BOOT_SERVICES  0x0201
+#define EFI_EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE  0x6202
+
+#define EFI_TPL_APPLICATION4
+#define EFI_TPL_CALLBACK   8
+#define EFI_TPL_NOTIFY 16
+#define EFI_TPL_HIGH_LEVEL 31
+   efi_status_t(EFIAPI *create_event)(u32 type , unsigned long tpl,
+   void (*fn) (void *event, void *ctx),
+   void *ctx, void **event);
void *set_timer;
efi_status_t(EFIAPI *wait_for_event)(unsigned long number_of_events, 
void *event,
unsigned long *index);
void *signal_event;
-   void *close_event;
+   efi_status_t(EFIAPI *close_event)(void *event);
void *check_event;
void *install_protocol_interface;
void *reinstall_protocol_interface;
-- 
2.11.0


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


[PATCH 0/8] add generic EFI timer

2017-02-27 Thread Jean-Christophe PLAGNIOL-VILLARD
Hi,

On EFI you have 3 ways to get to do "timer"

1: Simply by waiting X us and calling Boot Service udelay

2: By using event

3: By use the Timestamp GUID

for barebox this would be the best but even on EDK II this is never
ever compiled on any target.

So we have 2 choice, use a Hardware specific timer or implement the
timer using timestamp

This pull request allow you to enable 2 timers and use the best one at
runtime.

EFI x86 (HW specific)
EFI Generic (based on Event)

please pull
The following changes since commit d92ed454107b4d6f0d30fa0271da191ae5911d18:

  Merge branch 'for-next/video' into next (2017-02-27 08:51:08 +0100)

are available in the git repository at:

  git://git.jcrosoft.org/barebox.git

for you to fetch changes up to 169af081c48d6739a3727f07a4b8dbfb7ab48ebb:

  efi: add veriable to report secure boot support and status (2017-02-27 
18:20:37 +0800)

----
Jean-Christophe PLAGNIOL-VILLARD (8):
  efi: add prototype and definition for creating and closing event
  efi: add prototype and definition for setting timer
  efi: move LoaderTimeInitUSec and LoaderDevicePartUUID to postcore initcall
  efi: move x86 clocksource init at core initcall level
  clocksource: allow to have multiple device from clock source
  efi: move x86 clocksource to device/driver
  efi: clocksoure: use event for timer
  efi: add veriable to report secure boot support and status

 arch/x86/Kconfig|   2 +-
 arch/x86/mach-efi/Makefile  |   1 +
 arch/x86/mach-efi/clocksource.c |  11 +++
 common/clock.c  |  11 +++
 common/efi/efi.c|  24 +++-
 drivers/clocksource/Kconfig |   6 +-
 drivers/clocksource/Makefile|   1 +
 drivers/clocksource/efi.c   | 110 
+-
 drivers/clocksource/efi_x86.c   |  79 
+++
 drivers/efi/efi-device.c|  33 +
 include/clock.h |   3 ++-
 include/efi.h   |  25 ++---
 include/efi/efi.h   |   2 --
 13 files changed, 266 insertions(+), 42 deletions(-)
 create mode 100644 arch/x86/mach-efi/clocksource.c
 create mode 100644 drivers/clocksource/efi_x86.c

Best Regards,
J.

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


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

2017-02-23 Thread Jean-Christophe PLAGNIOL-VILLARD
On 08:27 Thu 16 Feb , Michael Olbrich wrote:
> 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 <plagn...@jcrosoft.com>
> > ---
> >  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

I don't like the idead to add more and more ifdef

It's better to switch to a Kconfig instead

and as we can build EFI for X86 32 this will not work anyway

Best Regards,
J.

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


Re: [PATCH] lib: xz: add support for bcj filters

2017-02-21 Thread Jean-Christophe PLAGNIOL-VILLARD

> On Feb 21, 2017, at 10:47 PM, yegorsli...@googlemail.com wrote:
> 
> From: Yegor Yefremov 
> 
> Add missing configuration options for various bcj filters. Without
> these options the lib/xz/xz_dec_bcj.c file will be compiled, but all
> filters will be disabled.
> 
> Signed-off-by: Yegor Yefremov 
> ---
> lib/Kconfig | 28 
> 1 file changed, 28 insertions(+)
> 
> diff --git a/lib/Kconfig b/lib/Kconfig
> index f9f25bdef..83dd8e0a4 100644
> --- a/lib/Kconfig
> +++ b/lib/Kconfig
> @@ -22,6 +22,34 @@ config XZ_DECOMPRESS
>   bool "include xz uncompression support"
>   select UNCOMPRESS
> 
> +if XZ_DECOMPRESS
> +
> +config XZ_DEC_X86
> +bool "x86 BCJ filter decoder"
> +default y
this need to be ARCH dependant 
> +
> +config XZ_DEC_POWERPC
> +bool "PowerPC BCJ filter decoder"
> +default y
> +
ditto
> +config XZ_DEC_IA64
> +bool "IA-64 BCJ filter decoder"
> +default y
ditto
> +config XZ_DEC_ARM
> +bool "ARM BCJ filter decoder"
> +default y
> +
ditto
> +config XZ_DEC_ARMTHUMB
> +bool "ARM-Thumb BCJ filter decoder"
> +default y
> +
ditto
> +config XZ_DEC_SPARC
> +bool "SPARC BCJ filter decoder"
> +default y
> +
> +endif
> +
> config REED_SOLOMON
>   bool
> 
> -- 
> 2.11.0
> 
> 
> ___
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox


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


[PATCH 10/12] efi: add minor and major to the bus and display it at boot

2017-02-19 Thread Jean-Christophe PLAGNIOL-VILLARD
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagn...@jcrosoft.com>
---
 drivers/efi/efi-device.c | 11 ++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/drivers/efi/efi-device.c b/drivers/efi/efi-device.c
index 7eb94de45..1877794c6 100644
--- a/drivers/efi/efi-device.c
+++ b/drivers/efi/efi-device.c
@@ -357,13 +357,22 @@ static void efi_businfo(struct device_d *dev)
 static int efi_init_devices(void)
 {
char *fw_vendor = NULL;
+   u16 sys_major = efi_sys_table->hdr.revision >> 16;
+   u16 sys_minor = efi_sys_table->hdr.revision & 0x;
+
+   fw_vendor = strdup_wchar_to_char((const wchar_t 
*)efi_sys_table->fw_vendor);
+
+   pr_info("EFI v%u.%.02u by %s v%u\n",
+   sys_major, sys_minor,
+   fw_vendor, efi_sys_table->fw_revision);
 
bus_register(_bus);
 
-   fw_vendor = strdup_wchar_to_char((const wchar_t 
*)efi_sys_table->fw_vendor);
dev_add_param_fixed(efi_bus.dev, "fw_vendor", fw_vendor);
free(fw_vendor);
 
+   dev_add_param_int_ro(efi_bus.dev, "major", sys_major, "%u");
+   dev_add_param_int_ro(efi_bus.dev, "minor", sys_minor, "%u");
dev_add_param_int_ro(efi_bus.dev, "fw_revision", 
efi_sys_table->fw_revision, "%u");
 
efi_bus.dev->info = efi_businfo;
-- 
2.11.0


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


[PATCH 11/12] efi-gui: add Timestamp Protocol GUID definition

2017-02-19 Thread Jean-Christophe PLAGNIOL-VILLARD
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagn...@jcrosoft.com>
---
 common/efi-guid.c | 1 +
 include/efi.h | 3 +++
 2 files changed, 4 insertions(+)

diff --git a/common/efi-guid.c b/common/efi-guid.c
index 64f3b1f65..04a00ee87 100644
--- a/common/efi-guid.c
+++ b/common/efi-guid.c
@@ -75,6 +75,7 @@ const char *efi_guid_string(efi_guid_t *g)
EFI_GUID_STRING(EFI_COMPONENT_NAME2_PROTOCOL_GUID, "Component Name2 
Protocol", "UEFI 2.0 Component Name2 Protocol");
EFI_GUID_STRING(EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL_GUID_31, 
"Network Interface Identifier Protocol_31",  "EFI1.1 Network Interface 
Identifier Protocol");
EFI_GUID_STRING(EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL_GUID, 
"Network Interface Identifier Protocol", "EFI Network Interface Identifier 
Protocol");
+   EFI_GUID_STRING(EFI_TIMESTAMP_PROTOCOL_GUID, "Timestamp", "Timestamp");
 
/* File */
EFI_GUID_STRING(EFI_IDEBUSDXE_INF_GUID, "IdeBusDxe.inf", "EFI 
IdeBusDxe.inf File GUID");
diff --git a/include/efi.h b/include/efi.h
index 4b812c9ab..d1b331ce5 100644
--- a/include/efi.h
+++ b/include/efi.h
@@ -469,6 +469,9 @@ extern efi_runtime_services_t *RT;
 #define EFI_VLANCONFIGDXE_INF_GUID \
EFI_GUID(0xe4f61863, 0xfe2c, 0x4b56, 0xa8, 0xf4, 0x08, 0x51, 0x9b, 
0xc4, 0x39, 0xdf)
 
+#define EFI_TIMESTAMP_PROTOCOL_GUID \
+   EFI_GUID(0xafbfde41, 0x2e6e, 0x4262, 0xba, 0x65, 0x62, 0xb9, 0x23, 
0x6e, 0x54, 0x95)
+
 /* barebox specific GUIDs */
 #define EFI_BAREBOX_VENDOR_GUID \
EFI_GUID(0x5b91f69c, 0x8b88, 0x4a2b, 0x92, 0x69, 0x5f, 0x1d, 0x80, 
0x2b, 0x51, 0x75)
-- 
2.11.0


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


[PATCH 12/12] efi: add efi handle dump command

2017-02-19 Thread Jean-Christophe PLAGNIOL-VILLARD
so we can inspect easly what is supported by the EFI implementation we running 
on

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagn...@jcrosoft.com>
---
 common/efi-guid.c|   5 ++
 drivers/efi/efi-device.c | 169 +++
 include/efi.h|   8 +++
 3 files changed, 182 insertions(+)

diff --git a/common/efi-guid.c b/common/efi-guid.c
index 04a00ee87..71aa21ddd 100644
--- a/common/efi-guid.c
+++ b/common/efi-guid.c
@@ -77,6 +77,11 @@ const char *efi_guid_string(efi_guid_t *g)
EFI_GUID_STRING(EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL_GUID, 
"Network Interface Identifier Protocol", "EFI Network Interface Identifier 
Protocol");
EFI_GUID_STRING(EFI_TIMESTAMP_PROTOCOL_GUID, "Timestamp", "Timestamp");
 
+   /* TPM 1.2 */
+   EFI_GUID_STRING( EFI_TCG_PROTOCOL_GUID, "TcgService", "TCGServices 
Protocol");
+   /* TPM 2.0 */
+   EFI_GUID_STRING( EFI_TCG2_PROTOCOL_GUID, "Tcg2Service", "TCG2Services 
Protocol");
+
/* File */
EFI_GUID_STRING(EFI_IDEBUSDXE_INF_GUID, "IdeBusDxe.inf", "EFI 
IdeBusDxe.inf File GUID");
EFI_GUID_STRING(EFI_TERMINALDXE_INF_GUID, "TerminalDxe.inf", "EFI 
TerminalDxe.inf File GUID");
diff --git a/drivers/efi/efi-device.c b/drivers/efi/efi-device.c
index 1877794c6..db8b25147 100644
--- a/drivers/efi/efi-device.c
+++ b/drivers/efi/efi-device.c
@@ -382,3 +382,172 @@ static int efi_init_devices(void)
return 0;
 }
 core_initcall(efi_init_devices);
+
+static void efi_devpath(efi_handle_t handle)
+{
+   efi_status_t efiret;
+   void *devpath;
+   char *dev_path_str;
+
+   efiret = BS->open_protocol(handle, _device_path_protocol_guid,
+  , NULL, NULL, 
EFI_OPEN_PROTOCOL_GET_PROTOCOL);
+   if (EFI_ERROR(efiret))
+   return;
+
+   dev_path_str = device_path_to_str(devpath);
+   if (dev_path_str) {
+   printf("  Devpath: \n  %s\n", dev_path_str);
+   free(dev_path_str);
+   }
+}
+
+static void efi_dump(efi_handle_t *handles, unsigned long handle_count)
+{
+   int i, j;
+   unsigned long num_guids;
+   efi_guid_t **guids;
+
+   if (!handles || !handle_count)
+   return;
+
+   for (i = 0; i < handle_count; i++) {
+   printf("handle-%p\n", handles[i]);
+
+   BS->protocols_per_handle(handles[i], , _guids);
+   printf("  Protocols:\n");
+   for (j = 0; j < num_guids; j++)
+   printf("  %d: %pUl: %s\n", j, guids[j],
+   efi_guid_string(guids[j]));
+   efi_devpath(handles[i]);
+   }
+   printf("\n");
+}
+
+static unsigned char to_digit(unsigned char c)
+{
+   if (c >= '0' && c <= '9')
+   c -= '0';
+   else if (c >= 'A' && c <= 'F')
+   c -= 'A' - 10;
+   else
+   c -= 'a' - 10;
+
+   return c;
+}
+
+#define read_xbit(src, dest, bit)  \
+   do {\
+   int __i;\
+   for (__i = (bit - 4); __i >= 0; __i -= 4, src++)\
+   dest |= to_digit(*src) << __i;  \
+   } while (0)
+
+static int do_efi_protocol_dump(int argc, char **argv)
+{
+   unsigned long handle_count = 0;
+   efi_handle_t *handles = NULL;
+   int ret;
+   efi_guid_t guid;
+   u32 a = 0;
+   u16 b = 0;
+   u16 c = 0;
+   u8 d0 = 0;
+   u8 d1 = 0;
+   u8 d2 = 0;
+   u8 d3 = 0;
+   u8 d4 = 0;
+   u8 d5 = 0;
+   u8 d6 = 0;
+   u8 d7 = 0;
+
+   /* Format 220e73b6-6bdb-4413-8405-b974b108619a */
+   if (argc == 1) {
+   char *s = argv[0];
+   int len = strlen(s);
+
+   if (len != 36)
+   return -EINVAL;
+   
+   read_xbit(s, a, 32);
+   if (*s != '-')
+   return -EINVAL;
+   s++;
+   read_xbit(s, b, 16);
+   if (*s != '-')
+   return -EINVAL;
+   s++;
+   read_xbit(s, c, 16);
+   if (*s != '-')
+   return -EINVAL;
+   s++;
+   read_xbit(s, d0, 8);
+   read_xbit(s, d1, 8);
+   if (*s != '-')
+   return -EINVAL;
+   s++;
+   read_xbit(s, d2, 8);
+   read_xbit(s, d3, 8);
+   read_xbit(s, d4, 8);
+   read_xbit(s, d5, 8);
+   read_xbit(s, d6, 8);
+   read_xbit(s, d7, 

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

2017-02-15 Thread Jean-Christophe PLAGNIOL-VILLARD
prepare to drop the efi arch as efi boot up is not arch sepecific

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagn...@jcrosoft.com>
---
 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
 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 HAVE_CONFIGURABLE_MEMORY_LAYOUT
select HAVE_CONFIGURABLE_TEXT_BASE
-   select GENERIC_FIND_NEXT_BIT
-   default y
-
-config X86_BOOTLOADER
-   bool
 
 choice
prompt "Select your board"
@@ -32,14 +55,30 @@ choice
 config MACH_X86_GENERIC
bool "Generic x86"
select X86_BOOTLOADER
+   depends on !X86_EFI 
help
  Say Y here if you want barebox to be your BIOS based bootloader
 
+config MACH_EFI_GENERIC
+   bool "Generic EFI"
+   depends on X86_EFI 
+   select HAS_DEBUG_LL
+   help
+ Say Y here if you want barebox to be your EFI based bootloader
+
 endchoice
 
 choice
prompt "Bring up type"
 
+   config X86_EFI
+   bool "

[PATCH 08/12] ARCH: efi: Finally drop it as now we can build efi bootup from x86

2017-02-15 Thread Jean-Christophe PLAGNIOL-VILLARD
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagn...@jcrosoft.com>
---
 arch/efi/Kconfig   |  53 ---
 arch/efi/Makefile  |  43 ---
 arch/efi/configs/efi_defconfig |  79 ---
 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/include/mach/debug_ll.h   |   1 -
 arch/efi/lib/.gitignore|   2 -
 arch/efi/lib/Makefile  |   4 --
 arch/efi/lib/asm-offsets.c |  12 -
 arch/efi/lib/crt0-efi-ia32.S   |  76 --
 arch/efi/lib/crt0-efi-x86_64.S |  75 --
 arch/efi/lib/elf_ia32_efi.lds.S| 106 -
 arch/efi/lib/elf_x86_64_efi.lds.S  | 100 --
 arch/efi/lib/reloc_ia32.c  |  97 -
 arch/efi/lib/reloc_x86_64.c|  96 -
 arch/x86/configs/efi_defconfig |   1 +
 28 files changed, 1 insertion(+), 1010 deletions(-)
 delete mode 100644 arch/efi/Kconfig
 delete mode 100644 arch/efi/Makefile
 delete mode 100644 arch/efi/configs/efi_defconfig
 delete mode 100644 arch/efi/include/asm/barebox.h
 delete mode 100644 arch/efi/include/asm/bitops.h
 delete mode 100644 arch/efi/include/asm/bitsperlong.h
 delete mode 100644 arch/efi/include/asm/byteorder.h
 delete mode 100644 arch/efi/include/asm/common.h
 delete mode 100644 arch/efi/include/asm/dma.h
 delete mode 100644 arch/efi/include/asm/elf.h
 delete mode 100644 arch/efi/include/asm/io.h
 delete mode 100644 arch/efi/include/asm/posix_types.h
 delete mode 100644 arch/efi/include/asm/sections.h
 delete mode 100644 arch/efi/include/asm/string.h
 delete mode 100644 arch/efi/include/asm/swab.h
 delete mode 100644 arch/efi/include/asm/types.h
 delete mode 100644 arch/efi/include/asm/unaligned.h
 delete mode 100644 arch/efi/include/mach/debug_ll.h
 delete mode 100644 arch/efi/lib/.gitignore
 delete mode 100644 arch/efi/lib/Makefile
 delete mode 100644 arch/efi/lib/asm-offsets.c
 delete mode 100644 arch/efi/lib/crt0-efi-ia32.S
 delete mode 100644 arch/efi/lib/crt0-efi-x86_64.S
 delete mode 100644 arch/efi/lib/elf_ia32_efi.lds.S
 delete mode 100644 arch/efi/lib/elf_x86_64_efi.lds.S
 delete mode 100644 arch/efi/lib/reloc_ia32.c
 delete mode 100644 arch/efi/lib/reloc_x86_64.c

diff --git a/arch/efi/Kconfig b/arch/efi/Kconfig
deleted file mode 100644
index 561aac2b2..0
--- a/arch/efi/Kconfig
+++ /dev/null
@@ -1,53 +0,0 @@
-config ARCH_EFI
-   bool
-   default y
-   select HAS_DEBUG_LL
-   select HAS_KALLSYMS
-   select EFI_GUID
-   select EFI_BOOTUP
-   select EFI_DEVICEPATH
-   select PRINTF_UUID
-   select GENERIC_FIND_NEXT_BIT
-   select CLOCKSOURCE_EFI
-
-config ARCH_TEXT_BASE
-   hex
-   default 0x0
-
-menu "EFI specific settings"
-
-config 64BIT
-   def_bool y
-   help
- Say yes to build a 64-bit binary - formerly known as x86_64
- Say no to build a 32-bit binary - formerly known as i386.
-
- 32-bit support currently does not compile and is not tested
- due to the lack of hardware.
-
-config X86_32
-   def_bool y
-   depends on !64BIT
-
-config X86_64
-   def_bool y
-   depends on 64BIT
-
-config ARCH_EFI_REGISTER_COM1
-   bool "Register first serial port"
-   help
- Say yes here to register the first serial port on ioport 0x3f8.
- This is useful to control barebox over a serial port if the board
- has one. Enabling this option may not work on boards which do not
- have a serial port. Also enable DRIVER_SERIAL_NS16550 to enable
- the NS16550 driver.
-
-endmenu
-
-source common/Kconfig
-source commands/Kconfig
-source net/Kconfig
-source drivers/Kconfig
-source fs/Kconfig
-source lib/Kconfig
-source crypto/Kconfig
diff --git a/arch/efi/Makefile b/arch/efi/Makefile
deleted file mode 100644
index c87a421ad..0
--- a/arch/efi/Makefile
+++ /dev/null
@@ -1,43 +0,0 @@
-KBUILD_DEFCONFIG := efi_defconfig
-
-CFLAGS += -fpic -fshort-wchar -mno-sse -mno-mmx
-
-ifeq ($(CONFIG_X86_32),y)
-   UTS_MACHINE := i386
-   biarch := $(call cc-option,-m32)
-   AFLAGS += $(biarch)
-   CFLAGS += $(biarch)
-   TARGET = efi-app-ia32

[PATCH 09/12] efi: bus: add firmware vendor and resision and tables info

2017-02-15 Thread Jean-Christophe PLAGNIOL-VILLARD
This alllow us to known where we boot from

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagn...@jcrosoft.com>
---
 drivers/efi/efi-device.c | 23 +++
 include/efi.h|  7 ++-
 2 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/drivers/efi/efi-device.c b/drivers/efi/efi-device.c
index 2864d0cf1..7eb94de45 100644
--- a/drivers/efi/efi-device.c
+++ b/drivers/efi/efi-device.c
@@ -341,10 +341,33 @@ struct bus_type efi_bus = {
.remove = efi_bus_remove,
 };
 
+static void efi_businfo(struct device_d *dev)
+{
+   int i;
+
+   printf("Tables:\n");
+   for (i = 0; i < efi_sys_table->nr_tables; i++) {
+   efi_config_table_t *t = _sys_table->tables[i];
+
+   printf("  %d: %pUl: %s\n", i, >guid,
+   efi_guid_string(>guid));
+   }
+}
+
 static int efi_init_devices(void)
 {
+   char *fw_vendor = NULL;
+
bus_register(_bus);
 
+   fw_vendor = strdup_wchar_to_char((const wchar_t 
*)efi_sys_table->fw_vendor);
+   dev_add_param_fixed(efi_bus.dev, "fw_vendor", fw_vendor);
+   free(fw_vendor);
+
+   dev_add_param_int_ro(efi_bus.dev, "fw_revision", 
efi_sys_table->fw_revision, "%u");
+
+   efi_bus.dev->info = efi_businfo;
+
efi_register_devices();
 
return 0;
diff --git a/include/efi.h b/include/efi.h
index fa6fb2782..4b812c9ab 100644
--- a/include/efi.h
+++ b/include/efi.h
@@ -488,6 +488,11 @@ 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;
 
+typedef struct {
+   efi_guid_t guid;
+   unsigned long table;
+} efi_config_table_t;
+
 #define EFI_SYSTEM_TABLE_SIGNATURE ((u64)0x5453595320494249ULL)
 
 #define EFI_2_30_SYSTEM_TABLE_REVISION  ((2 << 16) | (30))
@@ -510,7 +515,7 @@ typedef struct {
efi_runtime_services_t *runtime;
efi_boot_services_t *boottime;
unsigned long nr_tables;
-   unsigned long tables;
+   efi_config_table_t *tables;
 } efi_system_table_t;
 
 typedef struct {
-- 
2.11.0


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


[PATCH 05/12] efi: move startup and payload to common/efi

2017-02-15 Thread Jean-Christophe PLAGNIOL-VILLARD
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagn...@jcrosoft.com>
---
 arch/efi/Makefile  | 2 +-
 common/Makefile| 1 +
 {arch/efi => common}/efi/Makefile  | 0
 {arch/efi => common}/efi/efi-image.c   | 0
 {arch/efi => common}/efi/efi.c | 2 +-
 {arch/efi => common}/efi/env-efi/network/eth0-discover | 0
 6 files changed, 3 insertions(+), 2 deletions(-)
 rename {arch/efi => common}/efi/Makefile (100%)
 rename {arch/efi => common}/efi/efi-image.c (100%)
 rename {arch/efi => common}/efi/efi.c (99%)
 rename {arch/efi => common}/efi/env-efi/network/eth0-discover (100%)

diff --git a/arch/efi/Makefile b/arch/efi/Makefile
index 32a1c152b..c87a421ad 100644
--- a/arch/efi/Makefile
+++ b/arch/efi/Makefile
@@ -40,4 +40,4 @@ barebox.efi: $(KBUILD_BINARY) FORCE
 
 KBUILD_IMAGE := barebox.efi
 
-common-y += arch/efi/efi/ arch/efi/lib/
+common-y += arch/efi/lib/
diff --git a/common/Makefile b/common/Makefile
index 869b15a92..5f58c81d2 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -50,6 +50,7 @@ obj-$(CONFIG_BOOTCHOOSER) += bootchooser.o
 obj-$(CONFIG_UIMAGE)   += image.o uimage.o
 obj-$(CONFIG_FITIMAGE) += image-fit.o
 obj-$(CONFIG_MENUTREE) += menutree.o
+obj-$(CONFIG_EFI_BOOTUP)   += efi/
 obj-$(CONFIG_EFI_GUID) += efi-guid.o
 obj-$(CONFIG_EFI_DEVICEPATH)   += efi-devicepath.o
 lwl-$(CONFIG_IMD)  += imd-barebox.o
diff --git a/arch/efi/efi/Makefile b/common/efi/Makefile
similarity index 100%
rename from arch/efi/efi/Makefile
rename to common/efi/Makefile
diff --git a/arch/efi/efi/efi-image.c b/common/efi/efi-image.c
similarity index 100%
rename from arch/efi/efi/efi-image.c
rename to common/efi/efi-image.c
diff --git a/arch/efi/efi/efi.c b/common/efi/efi.c
similarity index 99%
rename from arch/efi/efi/efi.c
rename to common/efi/efi.c
index b14e1e823..217a6bea8 100644
--- a/arch/efi/efi/efi.c
+++ b/common/efi/efi.c
@@ -119,7 +119,7 @@ struct efi_boot {
void *binary;
 };
 
-struct efi_boot *efi_get_boot(int num)
+static struct efi_boot *efi_get_boot(int num)
 {
struct efi_boot *boot = xzalloc(sizeof(*boot));
void *buf, *ptr;
diff --git a/arch/efi/efi/env-efi/network/eth0-discover 
b/common/efi/env-efi/network/eth0-discover
similarity index 100%
rename from arch/efi/efi/env-efi/network/eth0-discover
rename to common/efi/env-efi/network/eth0-discover
-- 
2.11.0


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


[PATCH 06/12] x86: move bios bootup code to arch/x86/bios

2017-02-15 Thread Jean-Christophe PLAGNIOL-VILLARD
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagn...@jcrosoft.com>
---
 arch/x86/Makefile  | 1 +
 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/x86/lib/Makefile  | 3 ---
 6 files changed, 4 insertions(+), 3 deletions(-)
 create mode 100644 arch/x86/bios/Makefile
 rename arch/x86/{lib => bios}/bios_disk.S (100%)
 rename arch/x86/{lib => bios}/memory16.S (100%)
 rename arch/x86/{lib => bios}/traveler.S (100%)

diff --git a/arch/x86/Makefile b/arch/x86/Makefile
index da17d70bd..640c24b62 100644
--- a/arch/x86/Makefile
+++ b/arch/x86/Makefile
@@ -40,6 +40,7 @@ endif
 common-y += $(BOARD) $(MACH)
 common-y += arch/x86/lib/
 common-y += arch/x86/boot/
+common-$(CONFIG_X86_BIOS_BRINGUP) += arch/x86/bios/
 
 # arch/x86/cpu/
 
diff --git a/arch/x86/bios/Makefile b/arch/x86/bios/Makefile
new file mode 100644
index 0..414ee42a4
--- /dev/null
+++ b/arch/x86/bios/Makefile
@@ -0,0 +1,3 @@
+obj-y += memory16.o
+obj-y += traveler.o
+obj-y += bios_disk.o
diff --git a/arch/x86/lib/bios_disk.S b/arch/x86/bios/bios_disk.S
similarity index 100%
rename from arch/x86/lib/bios_disk.S
rename to arch/x86/bios/bios_disk.S
diff --git a/arch/x86/lib/memory16.S b/arch/x86/bios/memory16.S
similarity index 100%
rename from arch/x86/lib/memory16.S
rename to arch/x86/bios/memory16.S
diff --git a/arch/x86/lib/traveler.S b/arch/x86/bios/traveler.S
similarity index 100%
rename from arch/x86/lib/traveler.S
rename to arch/x86/bios/traveler.S
diff --git a/arch/x86/lib/Makefile b/arch/x86/lib/Makefile
index b67629f11..6054b9e3f 100644
--- a/arch/x86/lib/Makefile
+++ b/arch/x86/lib/Makefile
@@ -3,7 +3,4 @@ obj-y += memory.o
 obj-y += gdt.o
 
 # needed, when running via a 16 bit BIOS
-obj-$(CONFIG_X86_BIOS_BRINGUP) += memory16.o
-obj-$(CONFIG_X86_BIOS_BRINGUP) += traveler.o
-obj-$(CONFIG_X86_BIOS_BRINGUP) += bios_disk.o
 obj-$(CONFIG_CMD_LINUX16) += linux_start.o
-- 
2.11.0


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


  1   2   3   4   5   6   7   8   9   10   >