Re: [U-Boot] Unable to saveenv to MMC

2018-12-17 Thread Lothar Waßmann
Hi,

On Thu, 6 Dec 2018 10:12:11 -0800 Robin Polak wrote:
> Hello.
> 
>   I'm having trouble persisting my environment variables to the SD Card
> onto which I have FAT formatted and then written U-Boot to using the
> following command:
> 
> sudo dd if=u-boot-sunxi-with-spl.bin of=/dev/disk2 bs=1024 seek=8
> 
I have no idea how your SD card is partitioned but I guess that with
this command you are overwriting your FAT formatted partition.



Lothar Waßmann
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v3 8/8] cmd: env: add "-e" option for handling UEFI variables

2018-12-17 Thread Heinrich Schuchardt
On 12/18/18 6:05 AM, AKASHI Takahiro wrote:
> "env [print|set] -e" allows for handling uefi variables without
> knowing details about mapping to corresponding u-boot variables.
> 
> Signed-off-by: AKASHI Takahiro 

Hello Takahiro,

in several patch series you are implementing multiple interactive
commands that concern

- handling of EFI variables
- executing EFI binaries
- managing boot sequence

I very much appreciate your effort to provide an independent UEFI shell
implementation. What I am worried about is that your current patches
make it part of the monolithic U-Boot binary.

This design has multiple drawbacks:

The memory size available for U-Boot is very limited for many devices.
We already had to disable EFI_LOADER for some boards due to this
limitations. Hence we want to keep everything out of the U-Boot binary
that does not serve the primary goal of loading and executing the next
binary.

The UEFI forum has published a UEFI Shell specification which is very
extensive. We still have a lot of deficiencies in U-Boot's UEFI API
implementation. By merging in parts of an UEFI shell implementation our
project looses focus. There is an EDK2 implementation of said
specification. If we fix the remaining bugs of the EFI API
implementation in U-Boot we could simply run the EDK2 shell which
provides all that is needed for interactive work.

With you monolithic approach your UEFI shell implementation can neither
be used with other UEFI API implementations than U-Boot nor can it be
tested against other API implementations.

Due to these considerations I suggest that you build your UEFI shell
implementation as a separate UEFI binary (like helloworld.efi). You may
offer an embedding of the binary (like the bootefi hello command) into
the finally linked U-Boot binary via a configuration variable. Please,
put the shell implementation into a separate directory. You may want to
designate yourself as maintainer (in file MAINTAINERS).

Best regards

Heinrich


> ---
>  cmd/nvedit.c | 61 ++--
>  1 file changed, 59 insertions(+), 2 deletions(-)
> 
> diff --git a/cmd/nvedit.c b/cmd/nvedit.c
> index c0facabfc4fe..8168c963ac9d 100644
> --- a/cmd/nvedit.c
> +++ b/cmd/nvedit.c
> @@ -27,6 +27,8 @@
>  #include 
>  #include 
>  #include 
> +#include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -119,6 +121,25 @@ static int do_env_print(cmd_tbl_t *cmdtp, int flag, int 
> argc,
>   int rcode = 0;
>   int env_flag = H_HIDE_DOT;
>  
> +#if defined(CONFIG_CMD_EFISHELL)
> + if (argc > 1 && argv[1][0] == '-' && argv[1][1] == 'e') {
> + efi_status_t r;
> +
> + argc--;
> + argv++;
> +
> + /* Initialize EFI drivers */
> + r = efi_init_obj_list();
> + if (r != EFI_SUCCESS) {
> + printf("Error: Cannot set up EFI drivers, r = %lu\n",
> +r & ~EFI_ERROR_MASK);
> + return CMD_RET_FAILURE;
> + }
> +
> + return do_efi_dump_var(argc, argv);
> + }
> +#endif
> +
>   if (argc > 1 && argv[1][0] == '-' && argv[1][1] == 'a') {
>   argc--;
>   argv++;
> @@ -216,6 +237,26 @@ static int _do_env_set(int flag, int argc, char * const 
> argv[], int env_flag)
>   ENTRY e, *ep;
>  
>   debug("Initial value for argc=%d\n", argc);
> +
> +#if defined(CONFIG_CMD_EFISHELL)
> + if (argc > 1 && argv[1][0] == '-' && argv[1][1] == 'e') {
> + efi_status_t r;
> +
> + argc--;
> + argv++;
> +
> + /* Initialize EFI drivers */
> + r = efi_init_obj_list();
> + if (r != EFI_SUCCESS) {
> + printf("Error: Cannot set up EFI drivers, r = %lu\n",
> +r & ~EFI_ERROR_MASK);
> + return CMD_RET_FAILURE;
> + }
> +
> + return do_efi_set_var(argc, argv);
> + }
> +#endif
> +
>   while (argc > 1 && **(argv + 1) == '-') {
>   char *arg = *++argv;
>  
> @@ -1262,15 +1303,23 @@ static char env_help_text[] =
>  #if defined(CONFIG_CMD_IMPORTENV)
>   "env import [-d] [-t [-r] | -b | -c] addr [size] [var ...] - import 
> environment\n"
>  #endif
> +#if defined(CONFIG_CMD_EFISHELL)
> + "env print [-a | -e [name] | name ...] - print environment\n"
> +#else
>   "env print [-a | name ...] - print environment\n"
> +#endif
>  #if defined(CONFIG_CMD_RUN)
>   "env run var [...] - run commands in an environment variable\n"
>  #endif
>  #if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE)
>   "env save - save environment\n"
>  #endif
> +#if defined(CONFIG_CMD_EFISHELL)
> + "env set [-e | -f] name [arg ...]\n";
> +#else
>   "env set [-f] name [arg ...]\n";
>  #endif
> +#endif
>  
>  U_BOOT_CMD(
>   env, CONFIG_SYS_MAXARGS, 1, do_env,
> @@ -1295,6 +1344,10 @@ U_BOOT_CMD_COMPLETE(
>   printenv, 

Re: [U-Boot] [PATCH] am57xx_evm_defconfig: Enable YMODEM support

2018-12-17 Thread Lokesh Vutla

+Tom

On 17/12/18 7:57 PM, yan-...@ti.com wrote:

From: Yan Liu 

Enable CONFIG_SPL_YMODEM_SUPPORT to support UART boot

Signed-off-by: Yan Liu 


Reviewed-by: Lokesh Vutla 

Thanks and regards,
Lokesh


---
  configs/am57xx_evm_defconfig | 1 +
  1 file changed, 1 insertion(+)

diff --git a/configs/am57xx_evm_defconfig b/configs/am57xx_evm_defconfig
index aa82830..cc814a8 100644
--- a/configs/am57xx_evm_defconfig
+++ b/configs/am57xx_evm_defconfig
@@ -25,6 +25,7 @@ CONFIG_SPL_DMA_SUPPORT=y
  # CONFIG_SPL_NAND_SUPPORT is not set
  CONFIG_SPL_OS_BOOT=y
  CONFIG_SPL_SPI_LOAD=y
+CONFIG_SPL_YMODEM_SUPPORT=y
  CONFIG_CMD_SPL=y
  # CONFIG_CMD_FLASH is not set
  # CONFIG_CMD_SETEXPR is not set


___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v3 1/8] cmd: add efishell command

2018-12-17 Thread AKASHI Takahiro
Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/Boot variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efishell, helps address these issues and give us
more friendly interfaces:
 * efishell boot add: add Boot variable
 * efishell boot rm: remove Boot variable
 * efishell boot dump: display all Boot variables
 * efishell boot order: set/display a boot order (BootOrder)
 * efishell setvar: set an UEFI variable (with limited functionality)
 * efishell dumpvar: display all UEFI variables

As the name suggests, this command basically provides a subset fo UEFI
shell commands with simplified functionality.

Signed-off-by: AKASHI Takahiro 
---
 cmd/Kconfig|  10 +
 cmd/Makefile   |   1 +
 cmd/efishell.c | 673 +
 3 files changed, 684 insertions(+)
 create mode 100644 cmd/efishell.c

diff --git a/cmd/Kconfig b/cmd/Kconfig
index f2f3b5e2b76b..a8a4bf7db45e 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -1390,6 +1390,16 @@ config CMD_DISPLAY
  displayed on a simple board-specific display. Implement
  display_putc() to use it.
 
+config CMD_EFISHELL
+   bool "Enable the 'efishell' command for EFI environment"
+   depends on EFI_LOADER
+   default n
+   help
+ Enable the 'efishell' command which provides a subset of UEFI
+ shell utility with simplified functionality. It will be useful
+ particularly for managing boot parameters as  well as examining
+ various EFI status for debugging.
+
 config CMD_LED
bool "led"
default y if LED
diff --git a/cmd/Makefile b/cmd/Makefile
index 5ec2f9e8ebfd..0258d8a373b1 100644
--- a/cmd/Makefile
+++ b/cmd/Makefile
@@ -49,6 +49,7 @@ obj-$(CONFIG_CMD_ECHO) += echo.o
 obj-$(CONFIG_ENV_IS_IN_EEPROM) += eeprom.o
 obj-$(CONFIG_CMD_EEPROM) += eeprom.o
 obj-$(CONFIG_EFI_STUB) += efi.o
+obj-$(CONFIG_CMD_EFISHELL) += efishell.o
 obj-$(CONFIG_CMD_ELF) += elf.o
 obj-$(CONFIG_HUSH_PARSER) += exit.o
 obj-$(CONFIG_CMD_EXT4) += ext4.o
diff --git a/cmd/efishell.c b/cmd/efishell.c
new file mode 100644
index ..5819e52cf575
--- /dev/null
+++ b/cmd/efishell.c
@@ -0,0 +1,673 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ *  EFI Shell-like command
+ *
+ *  Copyright (c) 2018 AKASHI Takahiro, Linaro Limited
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+static void dump_var_data(char *data, unsigned long len)
+{
+   char *start, *end, *p;
+   unsigned long pos, count;
+   char hex[3], line[9];
+   int i;
+
+   end = data + len;
+   for (start = data, pos = 0; start < end; start += count, pos += count) {
+   count = end - start;
+   if (count > 16)
+   count = 16;
+
+   /* count should be multiple of two */
+   printf("%08lx: ", pos);
+
+   /* in hex format */
+   p = start;
+   for (i = 0; i < count / 2; p += 2, i++)
+   printf(" %c%c", *p, *(p + 1));
+   for (; i < 8; i++)
+   printf("   ");
+
+   /* in character format */
+   p = start;
+   hex[2] = '\0';
+   for (i = 0; i < count / 2; i++) {
+   hex[0] = *p++;
+   hex[1] = *p++;
+   line[i] = simple_strtoul(hex, 0, 16);
+   if (line[i] < 0x20 || line[i] > 0x7f)
+   line[i] = '.';
+   }
+   line[i] = '\0';
+   printf("  %s\n", line);
+   }
+}
+
+/*
+ * From efi_variable.c,
+ *
+ * Mapping between EFI variables and u-boot variables:
+ *
+ *   efi_$guid_$varname = {attributes}(type)value
+ */
+static int do_efi_dump_var(int argc, char * const argv[])
+{
+   char regex[256];
+   char * const regexlist[] = {regex};
+   char *res = NULL, *start, *end;
+   int len;
+
+   if (argc > 2)
+   return CMD_RET_USAGE;
+
+   if (argc == 2)
+   snprintf(regex, 256, "efi_.*-.*-.*-.*-.*_%s", argv[1]);
+   else
+   snprintf(regex, 256, "efi_.*-.*-.*-.*-.*_.*");
+   debug("%s:%d grep uefi var %s\n", __func__, __LINE__, regex);
+
+   len = hexport_r(_htab, '\n', H_MATCH_REGEX | H_MATCH_KEY,
+   , 0, 1, regexlist);
+
+   if (len < 0)
+   return CMD_RET_FAILURE;
+
+   if (len > 0) {
+   end = res;
+   while (true) {
+   /* variable name */
+   start = strchr(end, '_');
+   if (!start)
+   break;
+   start = strchr(++start, '_');
+   if (!start)
+

[U-Boot] [PATCH v3 5/8] cmd: efishell: add memmap command

2018-12-17 Thread AKASHI Takahiro
"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type StartEnd  Attributes
   ==
CONVENTIONAL 4000-7de27000 WB
RUNTIME DATA 7de27000-7de28000 WB|RT
RESERVED 7de28000-7de2a000 WB
RUNTIME DATA 7de2a000-7de2b000 WB|RT
RESERVED 7de2b000-7de2c000 WB
RUNTIME DATA 7de2c000-7de2d000 WB|RT
LOADER DATA  7de2d000-7ff37000 WB
RUNTIME CODE 7ff37000-7ff38000 WB|RT
LOADER DATA  7ff38000-8000 WB

Signed-off-by: AKASHI Takahiro 
---
 cmd/efishell.c | 78 +-
 1 file changed, 77 insertions(+), 1 deletion(-)

diff --git a/cmd/efishell.c b/cmd/efishell.c
index 010870df63c8..5a81a627d616 100644
--- a/cmd/efishell.c
+++ b/cmd/efishell.c
@@ -439,6 +439,78 @@ static int do_efi_show_images(int argc, char * const 
argv[])
return CMD_RET_SUCCESS;
 }
 
+static const char * const efi_mem_type_string[] = {
+   [EFI_RESERVED_MEMORY_TYPE] = "RESERVED",
+   [EFI_LOADER_CODE] = "LOADER CODE",
+   [EFI_LOADER_DATA] = "LOADER DATA",
+   [EFI_BOOT_SERVICES_CODE] = "BOOT CODE",
+   [EFI_BOOT_SERVICES_DATA] = "BOOT DATA",
+   [EFI_RUNTIME_SERVICES_CODE] = "RUNTIME CODE",
+   [EFI_RUNTIME_SERVICES_DATA] = "RUNTIME DATA",
+   [EFI_CONVENTIONAL_MEMORY] = "CONVENTIONAL",
+   [EFI_UNUSABLE_MEMORY] = "UNUSABLE MEM",
+   [EFI_ACPI_RECLAIM_MEMORY] = "ACPI RECLAIM MEM",
+   [EFI_ACPI_MEMORY_NVS] = "ACPI NVS",
+   [EFI_MMAP_IO] = "IO",
+   [EFI_MMAP_IO_PORT] = "IO PORT",
+   [EFI_PAL_CODE] = "PAL",
+};
+
+#define EFI_MEM_ATTR(attribute, bit, string) \
+   if ((attribute) & (bit)) {  \
+   if (sep)\
+   putc('|');  \
+   sep = 1;\
+   printf(string); \
+   }
+
+static int do_efi_show_memmap(int argc, char * const argv[])
+{
+   struct efi_mem_desc *map = NULL;
+   efi_uintn_t map_size = 0;
+   int i, sep;
+   efi_status_t ret;
+
+   ret = efi_get_memory_map(_size, map, NULL, NULL, NULL);
+   if (ret == EFI_BUFFER_TOO_SMALL) {
+   map = malloc(map_size);
+   if (!map)
+   return CMD_RET_FAILURE;
+   ret = efi_get_memory_map(_size, map, NULL, NULL, NULL);
+   }
+   if (ret != EFI_SUCCESS) {
+   free(map);
+   return CMD_RET_FAILURE;
+   }
+
+   printf("Type StartEnd  
Attributes\n");
+   printf("   
==\n");
+   for (i = 0; i < map_size / sizeof(*map); map++, i++) {
+   sep = 0;
+   printf("%-16s %016llx-%016llx ",
+  efi_mem_type_string[map->type],
+  map->physical_start,
+  map->physical_start + map->num_pages * EFI_PAGE_SIZE);
+   EFI_MEM_ATTR(map->attribute, EFI_MEMORY_UC, "UC");
+   EFI_MEM_ATTR(map->attribute, EFI_MEMORY_WC, "WC");
+   EFI_MEM_ATTR(map->attribute, EFI_MEMORY_WT, "WT");
+   EFI_MEM_ATTR(map->attribute, EFI_MEMORY_WB, "WB");
+   EFI_MEM_ATTR(map->attribute, EFI_MEMORY_UCE, "UCE");
+   EFI_MEM_ATTR(map->attribute, EFI_MEMORY_WP, "WP");
+   EFI_MEM_ATTR(map->attribute, EFI_MEMORY_RP, "RP");
+   EFI_MEM_ATTR(map->attribute, EFI_MEMORY_XP, "WP");
+   EFI_MEM_ATTR(map->attribute, EFI_MEMORY_NV, "NV");
+   EFI_MEM_ATTR(map->attribute, EFI_MEMORY_MORE_RELIABLE, "REL");
+   EFI_MEM_ATTR(map->attribute, EFI_MEMORY_RO, "RO");
+   EFI_MEM_ATTR(map->attribute, EFI_MEMORY_RUNTIME, "RT");
+   putc('\n');
+   }
+
+   free(map);
+
+   return CMD_RET_SUCCESS;
+}
+
 static int do_efi_boot_add(int argc, char * const argv[])
 {
int id;
@@ -826,6 +898,8 @@ static int do_efishell(cmd_tbl_t *cmdtp, int flag,
return do_efi_show_drivers(argc, argv);
else if (!strcmp(command, "images"))
return do_efi_show_images(argc, argv);
+   else if (!strcmp(command, "memmap"))
+   return do_efi_show_memmap(argc, argv);
else
return CMD_RET_USAGE;
 }
@@ -853,7 +927,9 @@ static char efishell_help_text[] =
"efishell drivers\n"
"  - show uefi drivers\n"
"efishell images\n"
-   "  - show loaded images\n";
+   "  - show loaded images\n"
+   "efishell memmap\n"
+   "  - show uefi memory map\n";
 #endif
 
 U_BOOT_CMD(
-- 
2.19.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v3 0/8] cmd: add efishell for efi environment

2018-12-17 Thread AKASHI Takahiro
# This patch set contains only efishell-specific part of my original
  patch[1]. See also the other patch[2].

This patch set is a collection of patches to enhance efi user interfaces
/commands. It will help improve user experience on efi boot and make it
more usable *without* edk2's shell utility.

Let's see how it works:
=> efishell boot add 1 SHELL mmc 0:1 /Shell.efi ""
=> efishell boot add 2 HELLO mmc 0:1 /hello.efi ""
=> efishell boot dump
Boot0001:
attributes: A-- (0x0001)
label: SHELL
file_path: 
/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/SD(0)/SD(0)/HD(1,MBR,0x086246ba,0x800,0x4)/\\Shell.efi
data: 
Boot0002:
attributes: A-- (0x0001)
label: HELLO
file_path: 
/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/SD(0)/SD(0)/HD(1,MBR,0x086246ba,0x800,0x4)/\\hello.efi
data: 

=> efishell boot order 1 2
=> efishell boot order
 1: Boot0001: SHELL
 2: Boot0002: HELLO

=> run -e Boot0002 (or bootefi bootmgr - 2) ; '-' means no dtb specified
WARNING: booting without device tree
Booting: HELLO
## Starting EFI application at 7db8b040 ...
Hello, world!
## Application terminated, r = 0

=> env set -e PlatformLang en   ; important!
   (or you can do "efishell setvar PlatformLang en")
=> env print -e
Boot0001: {boot,run}(blob)
:  01 00 00 00 68 00 53 00  h.S.
0010:  48 00 45 00 4c 00 4c 00  H.E.L.L.
0020:  00 00 01 04 14 00 b9 73  ...s
0030:  1d e6 84 a3 cc 4a ae ab  .J..
0040:  82 e8 28 f3 62 8b 03 1a  ..(.b...
0050:  05 00 00 03 1a 05 00 00  
0060:  04 01 2a 00 01 00 00 00  ..*.
0070:  00 08 00 00 00 00 00 00  
0080:  00 00 04 00 00 00 00 00  
0090:  ba 46 62 08 00 00 00 00  .Fb.
00a0:  00 00 00 00 00 00 00 00  
00b0:  01 01 04 04 1c 00 5c 00  ..\.
00c0:  5c 00 53 00 68 00 65 00  \.S.h.e.
00d0:  6c 00 6c 00 2e 00 65 00  l.l...e.
00e0:  66 00 69 00 00 00 7f ff  f.i
00f0:  04 00 00 ...
Boot0002: {boot,run}(blob)
:  01 00 00 00 68 00 48 00  h.H.
0010:  45 00 4c 00 4c 00 4f 00  E.L.L.O.
0020:  00 00 01 04 14 00 b9 73  ...s
0030:  1d e6 84 a3 cc 4a ae ab  .J..
0040:  82 e8 28 f3 62 8b 03 1a  ..(.b...
0050:  05 00 00 03 1a 05 00 00  
0060:  04 01 2a 00 01 00 00 00  ..*.
0070:  00 08 00 00 00 00 00 00  
0080:  00 00 04 00 00 00 00 00  
0090:  ba 46 62 08 00 00 00 00  .Fb.
00a0:  00 00 00 00 00 00 00 00  
00b0:  01 01 04 04 1c 00 5c 00  ..\.
00c0:  5c 00 68 00 65 00 6c 00  \.h.e.l.
00d0:  6c 00 6f 00 2e 00 65 00  l.o...e.
00e0:  66 00 69 00 00 00 7f ff  f.i
00f0:  04 00 00 ...
BootOrder: {boot,run}(blob)
:  01 00 02 00  
OsIndicationsSupported: {ro,boot}(blob)
:  00 00 00 00 00 00 00 00  
PlatformLang: {boot,run}(blob)
:  65 6een

=> run -e Boot0001 or bootefi bootmgr

   (shell ...)

"setvar" command now supports efi shell-like syntax:

=> env set -e foo =S\"akashi\" =0x012345 =Habcdef  
=> env print -e foo  
foo: {boot,run}(blob)
:  61 6b 61 73 68 69 45 23  akashiE#
0010:  01 00 ab cd ef   .


Other useful sub commands are:
=> efishell devices ; print uefi devices
=> efishell drivers ; print uefi drivers
=> efishell images  ; print loaded images
=> efishell dh  ; print uefi handles
=> efishell memmap  ; dump uefi memory map

# I admit there is some room to improve the output from those commands.

[1] https://lists.denx.de/pipermail/u-boot/2018-November/346450.html
[2] https://lists.denx.de/pipermail/u-boot/2018-December/352403.html

Enjoy!
-Takahiro Akashi

Changes in v3 (Dec 18, 2018)
* split v2 into two separate patch series
* add CONFIG_CMD_EFISHELL to enable/disable efishell command
* add missing free() at several places in efishell command

Changes in v2 (Nov 5, 2018)
* modify efi_dp_from_name() for use in efishell
* rename efi_marshal_load_option() to efi_serialize_load_option(),
  taking a "struct efi_load_option" as an argument
* improve a format in dumping uefi variables
* enhance a setvar syntax as efi's shell does
* change a syntax from "bootefi bootmgr -2" to "bootefi bootmgr - 2"
* add -e option to run command
* add -e option to env command
* add more sub-commands

AKASHI Takahiro (8):
  cmd: add efishell command
  cmd: efishell: add devices command
  cmd: efishell: add drivers command
  cmd: efishell: add images command
  cmd: efishell: add memmap command
  cmd: efishell: add dh command
  cmd: efishell: export uefi variable helper functions
  cmd: env: add "-e" option for handling UEFI variables

 cmd/Kconfig   |   10 +
 cmd/Makefile  |1 +
 

[U-Boot] [PATCH v3 8/8] cmd: env: add "-e" option for handling UEFI variables

2018-12-17 Thread AKASHI Takahiro
"env [print|set] -e" allows for handling uefi variables without
knowing details about mapping to corresponding u-boot variables.

Signed-off-by: AKASHI Takahiro 
---
 cmd/nvedit.c | 61 ++--
 1 file changed, 59 insertions(+), 2 deletions(-)

diff --git a/cmd/nvedit.c b/cmd/nvedit.c
index c0facabfc4fe..8168c963ac9d 100644
--- a/cmd/nvedit.c
+++ b/cmd/nvedit.c
@@ -27,6 +27,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 #include 
 #include 
 #include 
@@ -119,6 +121,25 @@ static int do_env_print(cmd_tbl_t *cmdtp, int flag, int 
argc,
int rcode = 0;
int env_flag = H_HIDE_DOT;
 
+#if defined(CONFIG_CMD_EFISHELL)
+   if (argc > 1 && argv[1][0] == '-' && argv[1][1] == 'e') {
+   efi_status_t r;
+
+   argc--;
+   argv++;
+
+   /* Initialize EFI drivers */
+   r = efi_init_obj_list();
+   if (r != EFI_SUCCESS) {
+   printf("Error: Cannot set up EFI drivers, r = %lu\n",
+  r & ~EFI_ERROR_MASK);
+   return CMD_RET_FAILURE;
+   }
+
+   return do_efi_dump_var(argc, argv);
+   }
+#endif
+
if (argc > 1 && argv[1][0] == '-' && argv[1][1] == 'a') {
argc--;
argv++;
@@ -216,6 +237,26 @@ static int _do_env_set(int flag, int argc, char * const 
argv[], int env_flag)
ENTRY e, *ep;
 
debug("Initial value for argc=%d\n", argc);
+
+#if defined(CONFIG_CMD_EFISHELL)
+   if (argc > 1 && argv[1][0] == '-' && argv[1][1] == 'e') {
+   efi_status_t r;
+
+   argc--;
+   argv++;
+
+   /* Initialize EFI drivers */
+   r = efi_init_obj_list();
+   if (r != EFI_SUCCESS) {
+   printf("Error: Cannot set up EFI drivers, r = %lu\n",
+  r & ~EFI_ERROR_MASK);
+   return CMD_RET_FAILURE;
+   }
+
+   return do_efi_set_var(argc, argv);
+   }
+#endif
+
while (argc > 1 && **(argv + 1) == '-') {
char *arg = *++argv;
 
@@ -1262,15 +1303,23 @@ static char env_help_text[] =
 #if defined(CONFIG_CMD_IMPORTENV)
"env import [-d] [-t [-r] | -b | -c] addr [size] [var ...] - import 
environment\n"
 #endif
+#if defined(CONFIG_CMD_EFISHELL)
+   "env print [-a | -e [name] | name ...] - print environment\n"
+#else
"env print [-a | name ...] - print environment\n"
+#endif
 #if defined(CONFIG_CMD_RUN)
"env run var [...] - run commands in an environment variable\n"
 #endif
 #if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE)
"env save - save environment\n"
 #endif
+#if defined(CONFIG_CMD_EFISHELL)
+   "env set [-e | -f] name [arg ...]\n";
+#else
"env set [-f] name [arg ...]\n";
 #endif
+#endif
 
 U_BOOT_CMD(
env, CONFIG_SYS_MAXARGS, 1, do_env,
@@ -1295,6 +1344,10 @@ U_BOOT_CMD_COMPLETE(
printenv, CONFIG_SYS_MAXARGS, 1,do_env_print,
"print environment variables",
"[-a]\n- print [all] values of all environment variables\n"
+#if defined(CONFIG_CMD_EFISHELL)
+   "printenv -e []\n"
+   "- print UEFI variable 'name' or all the variables\n"
+#endif
"printenv name ...\n"
"- print value of environment variable 'name'",
var_complete
@@ -1322,7 +1375,11 @@ U_BOOT_CMD_COMPLETE(
 U_BOOT_CMD_COMPLETE(
setenv, CONFIG_SYS_MAXARGS, 0,  do_env_set,
"set environment variables",
-   "[-f] name value ...\n"
+#if defined(CONFIG_CMD_EFISHELL)
+   "-e  []\n"
+   "- set UEFI variable 'name' to 'value' ...'\n"
+#endif
+   "setenv [-f] name value ...\n"
"- [forcibly] set environment variable 'name' to 'value ...'\n"
"setenv [-f] name\n"
"- [forcibly] delete environment variable 'name'",
@@ -1343,7 +1400,7 @@ U_BOOT_CMD(
 U_BOOT_CMD_COMPLETE(
run,CONFIG_SYS_MAXARGS, 1,  do_run,
"run commands in an environment variable",
-#if defined(CONFIG_CMD_BOOTEFI)
+#if defined(CONFIG_CMD_EFISHELL)
"var -e [Boot]\n"
"- load and run UEFI app based on 'Boot' UEFI variable",
 #else
-- 
2.19.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v3 2/8] cmd: efishell: add devices command

2018-12-17 Thread AKASHI Takahiro
"devices" command prints all the uefi variables on the system.
=> efishell devices
Device Name

/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/SD(0)/SD(0)
/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/SD(0)/SD(0)/\
HD(2,MBR,0x086246ba,0x40800,0x3f800)
/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/SD(0)/SD(0)/\
HD(1,MBR,0x086246ba,0x800,0x4)

Signed-off-by: AKASHI Takahiro 
---
 cmd/efishell.c | 88 +-
 1 file changed, 87 insertions(+), 1 deletion(-)

diff --git a/cmd/efishell.c b/cmd/efishell.c
index 5819e52cf575..929b6343b1b2 100644
--- a/cmd/efishell.c
+++ b/cmd/efishell.c
@@ -18,6 +18,8 @@
 #include 
 #include 
 
+static const struct efi_boot_services *bs;
+
 static void dump_var_data(char *data, unsigned long len)
 {
char *start, *end, *p;
@@ -263,6 +265,84 @@ out:
return ret;
 }
 
+static efi_handle_t *efi_get_handles_by_proto(efi_guid_t *guid)
+{
+   efi_handle_t *handles = NULL;
+   efi_uintn_t size = 0;
+   efi_status_t ret;
+
+   if (guid) {
+   ret = bs->locate_handle(BY_PROTOCOL, guid, NULL, ,
+   handles);
+   if (ret == EFI_BUFFER_TOO_SMALL) {
+   handles = calloc(1, size);
+   if (!handles)
+   return NULL;
+
+   ret = bs->locate_handle(BY_PROTOCOL, guid, NULL, ,
+   handles);
+   }
+   if (ret != EFI_SUCCESS) {
+   free(handles);
+   return NULL;
+   }
+   } else {
+   ret = bs->locate_handle(ALL_HANDLES, NULL, NULL, , NULL);
+   if (ret == EFI_BUFFER_TOO_SMALL) {
+   handles = calloc(1, size);
+   if (!handles)
+   return NULL;
+
+   ret = bs->locate_handle(ALL_HANDLES, NULL, NULL, ,
+   handles);
+   }
+   if (ret != EFI_SUCCESS) {
+   free(handles);
+   return NULL;
+   }
+   }
+
+   return handles;
+}
+
+static int efi_get_device_handle_info(efi_handle_t handle, u16 **name)
+{
+   struct efi_device_path *dp;
+   efi_status_t ret;
+
+   ret = bs->open_protocol(handle, _guid_device_path,
+   (void **), NULL /* FIXME */, NULL,
+   EFI_OPEN_PROTOCOL_GET_PROTOCOL);
+   if (ret == EFI_SUCCESS) {
+   *name = efi_dp_str(dp);
+   return 0;
+   } else {
+   return -1;
+   }
+}
+
+static int do_efi_show_devices(int argc, char * const argv[])
+{
+   efi_handle_t *handles = NULL, *handle;
+   u16 *devname;
+
+   handles = efi_get_handles_by_proto(NULL);
+   if (!handles)
+   return CMD_RET_SUCCESS;
+
+   printf("Device Name\n");
+   printf("\n");
+   for (handle = handles; *handle; handle++) {
+   if (!efi_get_device_handle_info(*handle, )) {
+   printf("%ls\n", devname);
+   efi_free_pool(devname);
+   }
+   handle++;
+   }
+
+   return CMD_RET_SUCCESS;
+}
+
 static int do_efi_boot_add(int argc, char * const argv[])
 {
int id;
@@ -625,6 +705,8 @@ static int do_efishell(cmd_tbl_t *cmdtp, int flag,
if (argc < 2)
return CMD_RET_USAGE;
 
+   bs = systab.boottime;
+
argc--; argv++;
command = argv[0];
 
@@ -642,6 +724,8 @@ static int do_efishell(cmd_tbl_t *cmdtp, int flag,
return do_efi_dump_var(argc, argv);
else if (!strcmp(command, "setvar"))
return do_efi_set_var(argc, argv);
+   else if (!strcmp(command, "devices"))
+   return do_efi_show_devices(argc, argv);
else
return CMD_RET_USAGE;
 }
@@ -663,7 +747,9 @@ static char efishell_help_text[] =
"  - get uefi variable's value\n"
"efishell setvar  []\n"
"  - set/delete uefi variable's value\n"
-   " may be \"=\"...\"\", \"=0x...\" (set) or \"=\" (delete)\n";
+   " may be \"=\"...\"\", \"=0x...\" (set) or \"=\" (delete)\n"
+   "efishell devices\n"
+   "  - show uefi devices\n";
 #endif
 
 U_BOOT_CMD(
-- 
2.19.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v3 3/8] cmd: efishell: add drivers command

2018-12-17 Thread AKASHI Takahiro
"drivers" command prints all the uefi drivers on the system.
=> efi drivers
Driver Name Image Path

(unknown)   +(not found)
guid: 18a031ab-b443-4d1a-a5c0-0c09261e9f71

Currently, no useful information can be printed.

Signed-off-by: AKASHI Takahiro 
---
 cmd/efishell.c | 95 +-
 1 file changed, 94 insertions(+), 1 deletion(-)

diff --git a/cmd/efishell.c b/cmd/efishell.c
index 929b6343b1b2..ed8de9e0355d 100644
--- a/cmd/efishell.c
+++ b/cmd/efishell.c
@@ -343,6 +343,95 @@ static int do_efi_show_devices(int argc, char * const 
argv[])
return CMD_RET_SUCCESS;
 }
 
+static int efi_get_driver_handle_info(efi_handle_t handle, u16 **name,
+ u16 **devname, u16 **filename)
+{
+   struct efi_driver_binding_protocol *binding;
+   struct efi_loaded_image *image;
+   efi_status_t ret;
+
+   ret = bs->open_protocol(handle, _guid_driver_binding_protocol,
+   (void **), NULL, NULL,
+   EFI_OPEN_PROTOCOL_GET_PROTOCOL);
+   if (ret != EFI_SUCCESS)
+   return -1;
+
+   ret = bs->open_protocol(binding->image_handle, _guid_loaded_image,
+   (void **), NULL /* FIXME */, NULL,
+   EFI_OPEN_PROTOCOL_GET_PROTOCOL);
+   if (ret != EFI_SUCCESS)
+   goto e_out;
+
+   /*
+* TODO:
+* handle image->device_handle,
+* use append_device_path()
+*/
+   *devname = NULL;
+   *filename = efi_dp_str(image->file_path);
+
+   return 0;
+
+e_out:
+   *devname = NULL;
+   *filename = NULL;
+
+   return 0;
+}
+
+static int do_efi_show_drivers(int argc, char * const argv[])
+{
+   efi_handle_t *handles = NULL, *handle;
+   efi_uintn_t size = 0;
+   u16 *drvname, *devname, *filename;
+   efi_status_t ret;
+   int i;
+
+   ret = bs->locate_handle(BY_PROTOCOL, _guid_driver_binding_protocol,
+   NULL, , NULL);
+   if (ret == EFI_BUFFER_TOO_SMALL) {
+   handles = calloc(1, size);
+   if (!handles)
+   return CMD_RET_FAILURE;
+
+   ret = bs->locate_handle(BY_PROTOCOL,
+   _guid_driver_binding_protocol,
+   NULL, , handles);
+   }
+   if (ret != EFI_SUCCESS) {
+   free(handles);
+   return CMD_RET_FAILURE;
+   }
+
+   printf("Driver Name Image Path\n");
+   printf("\n");
+   handle = handles;
+   for (i = 0; i < size / sizeof(*handle); i++) {
+   if (!efi_get_driver_handle_info(*handle, , ,
+   )) {
+   printf("%-16s%ls+%ls\n",
+  "(unknown)", devname, filename);
+   efi_free_pool(devname);
+   efi_free_pool(filename);
+
+   /* TODO: no other info */
+   struct efi_object *efiobj;
+   struct list_head *lhandle;
+   struct efi_handler *protocol;
+
+   efiobj = efi_search_obj(*handle);
+   list_for_each(lhandle, >protocols) {
+   protocol = list_entry(lhandle,
+ struct efi_handler, link);
+   printf("guid: %pUl\n", protocol->guid);
+   }
+   }
+   handle++;
+   }
+
+   return CMD_RET_SUCCESS;
+}
+
 static int do_efi_boot_add(int argc, char * const argv[])
 {
int id;
@@ -726,6 +815,8 @@ static int do_efishell(cmd_tbl_t *cmdtp, int flag,
return do_efi_set_var(argc, argv);
else if (!strcmp(command, "devices"))
return do_efi_show_devices(argc, argv);
+   else if (!strcmp(command, "drivers"))
+   return do_efi_show_drivers(argc, argv);
else
return CMD_RET_USAGE;
 }
@@ -749,7 +840,9 @@ static char efishell_help_text[] =
"  - set/delete uefi variable's value\n"
" may be \"=\"...\"\", \"=0x...\" (set) or \"=\" (delete)\n"
"efishell devices\n"
-   "  - show uefi devices\n";
+   "  - show uefi devices\n"
+   "efishell drivers\n"
+   "  - show uefi drivers\n";
 #endif
 
 U_BOOT_CMD(
-- 
2.19.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v3 7/8] cmd: efishell: export uefi variable helper functions

2018-12-17 Thread AKASHI Takahiro
Those function will be used for integration with 'env' command
so as to handle uefi variables.

Signed-off-by: AKASHI Takahiro 
---
 cmd/efishell.c| 38 ++
 include/command.h |  4 
 2 files changed, 38 insertions(+), 4 deletions(-)

diff --git a/cmd/efishell.c b/cmd/efishell.c
index 47ad77606062..42a29de7617c 100644
--- a/cmd/efishell.c
+++ b/cmd/efishell.c
@@ -65,7 +65,7 @@ static void dump_var_data(char *data, unsigned long len)
  *
  *   efi_$guid_$varname = {attributes}(type)value
  */
-static int do_efi_dump_var(int argc, char * const argv[])
+static int _do_efi_dump_var(int argc, char * const argv[])
 {
char regex[256];
char * const regexlist[] = {regex};
@@ -128,6 +128,21 @@ static int do_efi_dump_var(int argc, char * const argv[])
return CMD_RET_SUCCESS;
 }
 
+int do_efi_dump_var(int argc, char * const argv[])
+{
+   efi_status_t r;
+
+   /* Initialize EFI drivers */
+   r = efi_init_obj_list();
+   if (r != EFI_SUCCESS) {
+   printf("Error: Cannot set up EFI drivers, r = %lu\n",
+  r & ~EFI_ERROR_MASK);
+   return CMD_RET_FAILURE;
+   }
+
+   return _do_efi_dump_var(argc, argv);
+}
+
 static int append_value(char **bufp, unsigned long *sizep, char *data)
 {
char *tmp_buf = NULL, *new_buf = NULL, *value;
@@ -225,7 +240,7 @@ out:
return 0;
 }
 
-static int do_efi_set_var(int argc, char * const argv[])
+static int _do_efi_set_var(int argc, char * const argv[])
 {
char *var_name, *value = NULL;
unsigned long size = 0;
@@ -265,6 +280,21 @@ out:
return ret;
 }
 
+int do_efi_set_var(int argc, char * const argv[])
+{
+   efi_status_t r;
+
+   /* Initialize EFI drivers */
+   r = efi_init_obj_list();
+   if (r != EFI_SUCCESS) {
+   printf("Error: Cannot set up EFI drivers, r = %lu\n",
+  r & ~EFI_ERROR_MASK);
+   return CMD_RET_FAILURE;
+   }
+
+   return _do_efi_set_var(argc, argv);
+}
+
 static efi_handle_t *efi_get_handles_by_proto(efi_guid_t *guid)
 {
efi_handle_t *handles = NULL;
@@ -916,9 +946,9 @@ static int do_efishell(cmd_tbl_t *cmdtp, int flag,
if (!strcmp(command, "boot"))
return do_efi_boot_opt(argc, argv);
else if (!strcmp(command, "dumpvar") || !strcmp(command, "dmpstore"))
-   return do_efi_dump_var(argc, argv);
+   return _do_efi_dump_var(argc, argv);
else if (!strcmp(command, "setvar"))
-   return do_efi_set_var(argc, argv);
+   return _do_efi_set_var(argc, argv);
else if (!strcmp(command, "devices"))
return do_efi_show_devices(argc, argv);
else if (!strcmp(command, "drivers"))
diff --git a/include/command.h b/include/command.h
index 9b7b876585d9..5b081ae94cf3 100644
--- a/include/command.h
+++ b/include/command.h
@@ -51,6 +51,10 @@ extern int do_run(cmd_tbl_t *cmdtp, int flag, int argc, char 
* const argv[]);
 #if defined(CONFIG_CMD_BOOTEFI)
 int do_bootefi_bootmgr_exec(int boot_id);
 #endif
+#if defined(CONFIG_CMD_EFISHELL)
+int do_efi_dump_var(int argc, char * const argv[]);
+int do_efi_set_var(int argc, char * const argv[]);
+#endif
 
 /* common/command.c */
 int _do_help (cmd_tbl_t *cmd_start, int cmd_items, cmd_tbl_t * cmdtp, int
-- 
2.19.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v3 4/8] cmd: efishell: add images command

2018-12-17 Thread AKASHI Takahiro
"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro 
---
 cmd/efishell.c | 13 -
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/cmd/efishell.c b/cmd/efishell.c
index ed8de9e0355d..010870df63c8 100644
--- a/cmd/efishell.c
+++ b/cmd/efishell.c
@@ -432,6 +432,13 @@ static int do_efi_show_drivers(int argc, char * const 
argv[])
return CMD_RET_SUCCESS;
 }
 
+static int do_efi_show_images(int argc, char * const argv[])
+{
+   efi_print_image_infos(NULL);
+
+   return CMD_RET_SUCCESS;
+}
+
 static int do_efi_boot_add(int argc, char * const argv[])
 {
int id;
@@ -817,6 +824,8 @@ static int do_efishell(cmd_tbl_t *cmdtp, int flag,
return do_efi_show_devices(argc, argv);
else if (!strcmp(command, "drivers"))
return do_efi_show_drivers(argc, argv);
+   else if (!strcmp(command, "images"))
+   return do_efi_show_images(argc, argv);
else
return CMD_RET_USAGE;
 }
@@ -842,7 +851,9 @@ static char efishell_help_text[] =
"efishell devices\n"
"  - show uefi devices\n"
"efishell drivers\n"
-   "  - show uefi drivers\n";
+   "  - show uefi drivers\n"
+   "efishell images\n"
+   "  - show loaded images\n";
 #endif
 
 U_BOOT_CMD(
-- 
2.19.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v3 6/8] cmd: efishell: add dh command

2018-12-17 Thread AKASHI Takahiro
"dh" command prints all the uefi handles used in the system.
=> efishell dh
(T.B.D.)
0: (protocol info not available)
1: (protocol info not available)
2: (protocol info not available)
3: (protocol info not available)
4: (protocol info not available)
5: (protocol info not available)
6: (protocol info not available)
7: (protocol info not available)
8: (protocol info not available)
9: (protocol info not available)
10: (protocol info not available)
11: (protocol info not available)
12: (protocol info not available)
13: (protocol info not available)
14: (protocol info not available)
15: (protocol info not available)

Signed-off-by: AKASHI Takahiro 
---
 cmd/efishell.c | 33 -
 1 file changed, 32 insertions(+), 1 deletion(-)

diff --git a/cmd/efishell.c b/cmd/efishell.c
index 5a81a627d616..47ad77606062 100644
--- a/cmd/efishell.c
+++ b/cmd/efishell.c
@@ -511,6 +511,33 @@ static int do_efi_show_memmap(int argc, char * const 
argv[])
return CMD_RET_SUCCESS;
 }
 
+static char *efi_get_proto_info(efi_handle_t handle)
+{
+   return strdup("(protocol info not available)");
+}
+
+static int do_efi_show_handles(int argc, char * const argv[])
+{
+   efi_handle_t *handles = NULL, *handle;
+   char *info;
+   int i;
+
+   handles = efi_get_handles_by_proto(NULL);
+   if (!handles)
+   return CMD_RET_SUCCESS;
+
+   for (handle = handles, i = 0; *handle; handle++, i++) {
+   /* TODO: depends on protocols */
+   info = efi_get_proto_info(*handle);
+   printf("%d: %s\n", i, info ?: "");
+   free(info);
+   }
+
+   free(handles);
+
+   return CMD_RET_SUCCESS;
+}
+
 static int do_efi_boot_add(int argc, char * const argv[])
 {
int id;
@@ -900,6 +927,8 @@ static int do_efishell(cmd_tbl_t *cmdtp, int flag,
return do_efi_show_images(argc, argv);
else if (!strcmp(command, "memmap"))
return do_efi_show_memmap(argc, argv);
+   else if (!strcmp(command, "dh"))
+   return do_efi_show_handles(argc, argv);
else
return CMD_RET_USAGE;
 }
@@ -929,7 +958,9 @@ static char efishell_help_text[] =
"efishell images\n"
"  - show loaded images\n"
"efishell memmap\n"
-   "  - show uefi memory map\n";
+   "  - show uefi memory map\n"
+   "efishell dh\n"
+   "  - show uefi handles\n";
 #endif
 
 U_BOOT_CMD(
-- 
2.19.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH 2/5] efi_loader: bootmgr: allow for running a given load option

2018-12-17 Thread AKASHI Takahiro
With an extra argument, efi_bootmgr_load() can now load an efi binary
based on a "Boot" variable specified.

Signed-off-by: AKASHI Takahiro 
---
 cmd/bootefi.c| 2 +-
 include/efi_loader.h | 3 ++-
 lib/efi_loader/efi_bootmgr.c | 9 -
 3 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/cmd/bootefi.c b/cmd/bootefi.c
index 7012d72ab50d..3ebae1cdad08 100644
--- a/cmd/bootefi.c
+++ b/cmd/bootefi.c
@@ -452,7 +452,7 @@ static int do_bootefi_bootmgr_exec(void)
void *addr;
efi_status_t r;
 
-   addr = efi_bootmgr_load(_path, _path);
+   addr = efi_bootmgr_load(-1, _path, _path);
if (!addr)
return 1;
 
diff --git a/include/efi_loader.h b/include/efi_loader.h
index dd68cfce5c65..5a6321122c9c 100644
--- a/include/efi_loader.h
+++ b/include/efi_loader.h
@@ -551,7 +551,8 @@ struct efi_load_option {
 
 void efi_deserialize_load_option(struct efi_load_option *lo, u8 *data);
 unsigned long efi_serialize_load_option(struct efi_load_option *lo, u8 **data);
-void *efi_bootmgr_load(struct efi_device_path **device_path,
+void *efi_bootmgr_load(int boot_id,
+  struct efi_device_path **device_path,
   struct efi_device_path **file_path);
 
 #else /* CONFIG_IS_ENABLED(EFI_LOADER) */
diff --git a/lib/efi_loader/efi_bootmgr.c b/lib/efi_loader/efi_bootmgr.c
index a54ae28343ce..db391147fb2d 100644
--- a/lib/efi_loader/efi_bootmgr.c
+++ b/lib/efi_loader/efi_bootmgr.c
@@ -180,7 +180,8 @@ error:
  * available load-options, finding and returning the first one that can
  * be loaded successfully.
  */
-void *efi_bootmgr_load(struct efi_device_path **device_path,
+void *efi_bootmgr_load(int boot_id,
+  struct efi_device_path **device_path,
   struct efi_device_path **file_path)
 {
u16 bootnext, *bootorder;
@@ -195,6 +196,12 @@ void *efi_bootmgr_load(struct efi_device_path 
**device_path,
bs = systab.boottime;
rs = systab.runtime;
 
+   /* specified boot option */
+   if (boot_id != -1) {
+   image = try_load_entry(boot_id, device_path, file_path);
+   goto error;
+   }
+
/* BootNext */
size = sizeof(bootnext);
ret = rs->get_variable(L"BootNext",
-- 
2.19.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH 3/5] cmd: bootefi: carve out fdt parameter handling

2018-12-17 Thread AKASHI Takahiro
The current way how command parameters, particularly "fdt addr," are
handled makes it a bit complicated to add a subcommand-specific parameter.
So just refactor the code and extract efi_handle_fdt().

This commit is a preparatory change for enhancing bootmgr sub-command.

Signed-off-by: AKASHI Takahiro 

Revert "fixup! fixup! cmd: bootefi: carve out fdt parameter handling"

This reverts commit abc315426e37bdfb96a48d23c1fc96399b68baa5.
---
 cmd/bootefi.c | 49 +
 cmd/bootefi.h |  3 +++
 2 files changed, 36 insertions(+), 16 deletions(-)
 create mode 100644 cmd/bootefi.h

diff --git a/cmd/bootefi.c b/cmd/bootefi.c
index 3ebae1cdad08..796ca6ee69ec 100644
--- a/cmd/bootefi.c
+++ b/cmd/bootefi.c
@@ -279,6 +279,31 @@ static void bootefi_run_finish(struct efi_loaded_image_obj 
*image_obj,
efi_delete_handle(_obj->header);
 }
 
+int efi_handle_fdt(char *fdt_opt)
+{
+   unsigned long fdt_addr;
+   efi_status_t r;
+
+   if (fdt_opt) {
+   fdt_addr = simple_strtoul(fdt_opt, NULL, 16);
+   if (!fdt_addr && *fdt_opt != '0')
+   return CMD_RET_USAGE;
+
+   /* Install device tree */
+   r = efi_install_fdt(fdt_addr);
+   if (r != EFI_SUCCESS) {
+   printf("ERROR: failed to install device tree\n");
+   return CMD_RET_FAILURE;
+   }
+   } else {
+   /* Remove device tree. EFI_NOT_FOUND can be ignored here */
+   efi_install_configuration_table(_guid_fdt, NULL);
+   printf("WARNING: booting without device tree\n");
+   }
+
+   return CMD_RET_SUCCESS;
+}
+
 /**
  * do_bootefi_exec() - execute EFI binary
  *
@@ -473,7 +498,6 @@ static int do_bootefi(cmd_tbl_t *cmdtp, int flag, int argc, 
char * const argv[])
unsigned long addr;
char *saddr;
efi_status_t r;
-   unsigned long fdt_addr;
 
/* Allow unaligned memory access */
allow_unaligned();
@@ -489,21 +513,6 @@ static int do_bootefi(cmd_tbl_t *cmdtp, int flag, int 
argc, char * const argv[])
if (argc < 2)
return CMD_RET_USAGE;
 
-   if (argc > 2) {
-   fdt_addr = simple_strtoul(argv[2], NULL, 16);
-   if (!fdt_addr && *argv[2] != '0')
-   return CMD_RET_USAGE;
-   /* Install device tree */
-   r = efi_install_fdt(fdt_addr);
-   if (r != EFI_SUCCESS) {
-   printf("ERROR: failed to install device tree\n");
-   return CMD_RET_FAILURE;
-   }
-   } else {
-   /* Remove device tree. EFI_NOT_FOUND can be ignored here */
-   efi_install_configuration_table(_guid_fdt, NULL);
-   printf("WARNING: booting without device tree\n");
-   }
 #ifdef CONFIG_CMD_BOOTEFI_HELLO
if (!strcmp(argv[1], "hello")) {
ulong size = __efi_helloworld_end - __efi_helloworld_begin;
@@ -521,6 +530,9 @@ static int do_bootefi(cmd_tbl_t *cmdtp, int flag, int argc, 
char * const argv[])
struct efi_loaded_image_obj *image_obj;
struct efi_loaded_image *loaded_image_info;
 
+   if (efi_handle_fdt(argc > 2 ? argv[2] : NULL))
+   return CMD_RET_FAILURE;
+
if (bootefi_test_prepare(_obj, _image_info,
 "\\selftest", (uintptr_t)_selftest,
 "efi_selftest"))
@@ -533,6 +545,9 @@ static int do_bootefi(cmd_tbl_t *cmdtp, int flag, int argc, 
char * const argv[])
} else
 #endif
if (!strcmp(argv[1], "bootmgr")) {
+   if (efi_handle_fdt(argc > 2 ? argv[2] : NULL))
+   return CMD_RET_FAILURE;
+
return do_bootefi_bootmgr_exec();
} else {
saddr = argv[1];
@@ -542,6 +557,8 @@ static int do_bootefi(cmd_tbl_t *cmdtp, int flag, int argc, 
char * const argv[])
if (!addr && *saddr != '0')
return CMD_RET_USAGE;
 
+   if (efi_handle_fdt(argc > 2 ? argv[2] : NULL))
+   return CMD_RET_FAILURE;
}
 
printf("## Starting EFI application at %08lx ...\n", addr);
diff --git a/cmd/bootefi.h b/cmd/bootefi.h
new file mode 100644
index ..4e11ab1211cb
--- /dev/null
+++ b/cmd/bootefi.h
@@ -0,0 +1,3 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+
+int efi_handle_fdt(char *fdt_opt);
-- 
2.19.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH 1/5] efi_loader: bootmgr: support BootNext and BootCurrent variable behavior

2018-12-17 Thread AKASHI Takahiro
See UEFI v2.7, section 3.1.2 for details of the specification.

With my efishell command[1], you can try as the following:
  => efi boot add 1 SHELL ...
  => efi boot add 2 HELLO ...
  => efi boot order 1 2
  => efi bootmgr
 (starting SHELL ...)
  => efi setvar BootNext =H0200
  => efi bootmgr
 (starting HELLO ...)
  => efi dumpvar
  
  BootCurrent: {boot,run}(blob)
  :  02 00..
  BootOrder: {boot,run}(blob)
  :  01 00 02 00  

Using "run -e" would be more human-friendly, though.

[1] https://lists.denx.de/pipermail/u-boot/2018-November/346450.html

Signed-off-by: AKASHI Takahiro 
---
 lib/efi_loader/efi_bootmgr.c | 37 +++-
 1 file changed, 36 insertions(+), 1 deletion(-)

diff --git a/lib/efi_loader/efi_bootmgr.c b/lib/efi_loader/efi_bootmgr.c
index a095df3f540b..a54ae28343ce 100644
--- a/lib/efi_loader/efi_bootmgr.c
+++ b/lib/efi_loader/efi_bootmgr.c
@@ -145,11 +145,21 @@ static void *try_load_entry(uint16_t n, struct 
efi_device_path **device_path,
efi_deserialize_load_option(, load_option);
 
if (lo.attributes & LOAD_OPTION_ACTIVE) {
+   u32 attributes;
efi_status_t ret;
 
debug("%s: trying to load \"%ls\" from %pD\n",
  __func__, lo.label, lo.file_path);
 
+   attributes = EFI_VARIABLE_BOOTSERVICE_ACCESS |
+EFI_VARIABLE_RUNTIME_ACCESS;
+   size = sizeof(n);
+   ret = rs->set_variable(L"BootCurrent",
+  (efi_guid_t *)_global_variable_guid,
+  attributes, size, );
+   if (ret != EFI_SUCCESS)
+   goto error;
+
ret = efi_load_image_from_path(lo.file_path, );
 
if (ret != EFI_SUCCESS)
@@ -173,16 +183,41 @@ error:
 void *efi_bootmgr_load(struct efi_device_path **device_path,
   struct efi_device_path **file_path)
 {
-   uint16_t *bootorder;
+   u16 bootnext, *bootorder;
+   u32 attributes;
efi_uintn_t size;
void *image = NULL;
int i, num;
+   efi_status_t ret;
 
__efi_entry_check();
 
bs = systab.boottime;
rs = systab.runtime;
 
+   /* BootNext */
+   size = sizeof(bootnext);
+   ret = rs->get_variable(L"BootNext",
+  (efi_guid_t *)_global_variable_guid,
+  NULL, , );
+   if (!bootnext)
+   goto run_list;
+
+   attributes = EFI_VARIABLE_BOOTSERVICE_ACCESS |
+EFI_VARIABLE_RUNTIME_ACCESS;
+   size = 0;
+   ret = rs->set_variable(L"BootNext",
+  (efi_guid_t *)_global_variable_guid,
+  attributes, size, );
+   if (ret != EFI_SUCCESS)
+   goto error;
+
+   image = try_load_entry(bootnext, device_path, file_path);
+   if (image)
+   goto error;
+
+run_list:
+   /* BootOrder */
bootorder = get_var(L"BootOrder", _global_variable_guid, );
if (!bootorder)
goto error;
-- 
2.19.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH 4/5] cmd: bootefi: run an EFI application of a specific load option

2018-12-17 Thread AKASHI Takahiro
With this patch applied, we will be able to selectively execute
an EFI application by specifying a load option, say "1" for Boot0001,
"2" for Boot0002 and so on.

  => bootefi bootmgr  1, or
 bootefi bootmgr - 1

Please note that Boot need not be included in "BootOrder".

Signed-off-by: AKASHI Takahiro 
---
 cmd/bootefi.c | 26 +++---
 1 file changed, 19 insertions(+), 7 deletions(-)

diff --git a/cmd/bootefi.c b/cmd/bootefi.c
index 796ca6ee69ec..2fc52e3056d2 100644
--- a/cmd/bootefi.c
+++ b/cmd/bootefi.c
@@ -471,13 +471,13 @@ static efi_status_t bootefi_test_prepare
 
 #endif /* CONFIG_CMD_BOOTEFI_SELFTEST */
 
-static int do_bootefi_bootmgr_exec(void)
+static int do_bootefi_bootmgr_exec(int boot_id)
 {
struct efi_device_path *device_path, *file_path;
void *addr;
efi_status_t r;
 
-   addr = efi_bootmgr_load(-1, _path, _path);
+   addr = efi_bootmgr_load(boot_id, _path, _path);
if (!addr)
return 1;
 
@@ -545,10 +545,22 @@ static int do_bootefi(cmd_tbl_t *cmdtp, int flag, int 
argc, char * const argv[])
} else
 #endif
if (!strcmp(argv[1], "bootmgr")) {
-   if (efi_handle_fdt(argc > 2 ? argv[2] : NULL))
-   return CMD_RET_FAILURE;
+   char *endp;
+   int boot_id = -1;
+
+   if (argc > 2)
+   if (efi_handle_fdt((argv[2][0] == '-') ?
+  NULL : argv[2]))
+   return CMD_RET_FAILURE;
+
+   if (argc > 3) {
+   boot_id = (int)simple_strtoul(argv[3], , 0);
+   if ((argv[3] + strlen(argv[3]) != endp) ||
+   boot_id > 0x)
+   return CMD_RET_USAGE;
+   }
 
-   return do_bootefi_bootmgr_exec();
+   return do_bootefi_bootmgr_exec(boot_id);
} else {
saddr = argv[1];
 
@@ -589,7 +601,7 @@ static char bootefi_help_text[] =
"Use environment variable efi_selftest to select a single test.\n"
"Use 'setenv efi_selftest list' to enumerate all tests.\n"
 #endif
-   "bootefi bootmgr [fdt addr]\n"
+   "bootefi bootmgr [|'-' []]\n"
"  - load and boot EFI payload based on BootOrder/Boot variables.\n"
"\n"
"If specified, the device tree located at  gets\n"
@@ -597,7 +609,7 @@ static char bootefi_help_text[] =
 #endif
 
 U_BOOT_CMD(
-   bootefi, 3, 0, do_bootefi,
+   bootefi, 5, 0, do_bootefi,
"Boots an EFI payload from memory",
bootefi_help_text
 );
-- 
2.19.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH 5/5] cmd: run: add "-e" option to run an EFI application

2018-12-17 Thread AKASHI Takahiro
"run -e" allows for executing EFI application with a specific "Boot"
variable. If no "Boot" is specified or "BootOrder" is specified,
it tries to run an EFI application specified in the order of "bootOrder."

Signed-off-by: AKASHI Takahiro 
---
 cmd/bootefi.c |  2 +-
 cmd/nvedit.c  |  5 +
 common/cli.c  | 31 +++
 include/command.h |  3 +++
 4 files changed, 40 insertions(+), 1 deletion(-)

diff --git a/cmd/bootefi.c b/cmd/bootefi.c
index 2fc52e3056d2..8122793d11c5 100644
--- a/cmd/bootefi.c
+++ b/cmd/bootefi.c
@@ -471,7 +471,7 @@ static efi_status_t bootefi_test_prepare
 
 #endif /* CONFIG_CMD_BOOTEFI_SELFTEST */
 
-static int do_bootefi_bootmgr_exec(int boot_id)
+int do_bootefi_bootmgr_exec(int boot_id)
 {
struct efi_device_path *device_path, *file_path;
void *addr;
diff --git a/cmd/nvedit.c b/cmd/nvedit.c
index de16c72c23f2..c0facabfc4fe 100644
--- a/cmd/nvedit.c
+++ b/cmd/nvedit.c
@@ -1343,8 +1343,13 @@ U_BOOT_CMD(
 U_BOOT_CMD_COMPLETE(
run,CONFIG_SYS_MAXARGS, 1,  do_run,
"run commands in an environment variable",
+#if defined(CONFIG_CMD_BOOTEFI)
+   "var -e [Boot]\n"
+   "- load and run UEFI app based on 'Boot' UEFI variable",
+#else
"var [...]\n"
"- run the commands in the environment variable(s) 'var'",
+#endif
var_complete
 );
 #endif
diff --git a/common/cli.c b/common/cli.c
index 51b8d5f85cbb..013dd2e51936 100644
--- a/common/cli.c
+++ b/common/cli.c
@@ -12,8 +12,10 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
+#include "../cmd/bootefi.h"
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -125,6 +127,35 @@ int do_run(cmd_tbl_t *cmdtp, int flag, int argc, char * 
const argv[])
if (argc < 2)
return CMD_RET_USAGE;
 
+#ifdef CONFIG_CMD_BOOTEFI
+   if (!strcmp(argv[1], "-e")) {
+   int boot_id = -1;
+   char *endp;
+
+   if (argc == 3) {
+   if (!strcmp(argv[2], "BootOrder")) {
+   boot_id = -1;
+   } else if (!strncmp(argv[2], "Boot", 4)) {
+   boot_id = (int)simple_strtoul([2][4],
+ , 0);
+   if ((argv[2] + strlen(argv[2]) != endp) ||
+   boot_id > 0x)
+   return CMD_RET_USAGE;
+   } else {
+   return CMD_RET_USAGE;
+   }
+   }
+
+   if (efi_init_obj_list())
+   return CMD_RET_FAILURE;
+
+   if (efi_handle_fdt(NULL))
+   return CMD_RET_FAILURE;
+
+   return do_bootefi_bootmgr_exec(boot_id);
+   }
+#endif
+
for (i = 1; i < argc; ++i) {
char *arg;
 
diff --git a/include/command.h b/include/command.h
index 200c7a5e9f4e..9b7b876585d9 100644
--- a/include/command.h
+++ b/include/command.h
@@ -48,6 +48,9 @@ typedef struct cmd_tbl_s  cmd_tbl_t;
 #if defined(CONFIG_CMD_RUN)
 extern int do_run(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
 #endif
+#if defined(CONFIG_CMD_BOOTEFI)
+int do_bootefi_bootmgr_exec(int boot_id);
+#endif
 
 /* common/command.c */
 int _do_help (cmd_tbl_t *cmd_start, int cmd_items, cmd_tbl_t * cmdtp, int
-- 
2.19.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH 0/5] efi_loader: run a specific efi application more easily

2018-12-17 Thread AKASHI Takahiro
This patch is a result from re-organizing my previous patches;
a combination of [1] and part of [2] so as solely to provide several ways
of executing a specific efi application explicitly.
  * bootmanager via BootNext variable
  * bootefi with boot id
  * run -e

[1] https://lists.denx.de/pipermail/u-boot/2018-November/349281.html
[2] https://lists.denx.de/pipermail/u-boot/2018-November/346450.html

AKASHI Takahiro (5):
  efi_loader: bootmgr: support BootNext and BootCurrent variable
behavior
  efi_loader: bootmgr: allow for running a given load option
  cmd: bootefi: carve out fdt parameter handling
  cmd: bootefi: run an EFI application of a specific load option
  cmd: run: add "-e" option to run an EFI application

 cmd/bootefi.c| 71 +---
 cmd/bootefi.h|  3 ++
 cmd/nvedit.c |  5 +++
 common/cli.c | 31 
 include/command.h|  3 ++
 include/efi_loader.h |  3 +-
 lib/efi_loader/efi_bootmgr.c | 46 ++-
 7 files changed, 138 insertions(+), 24 deletions(-)
 create mode 100644 cmd/bootefi.h

-- 
2.19.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH] efi_loader: move efi_init_obj_list() to a new efi_setup.c

2018-12-17 Thread AKASHI Takahiro
The function, efi_init_obj_list(), can be shared in different pseudo efi
applications, like bootefi/bootmgr as well as my efishell. Moreover, it
will be utilized to extend efi initialization, for example, my "removable
disk support" patch and "capsule-on-disk support" patch in the future.

So with this patch, it will be moved to a new file, efi_setup.c, under
lib/efi_loader and exported, making no changes in functionality.

Signed-off-by: AKASHI Takahiro 
---
 cmd/bootefi.c  |  75 -
 include/efi_loader.h   |   2 +
 lib/efi_loader/Makefile|   1 +
 lib/efi_loader/efi_setup.c | 112 +
 4 files changed, 115 insertions(+), 75 deletions(-)
 create mode 100644 lib/efi_loader/efi_setup.c

diff --git a/cmd/bootefi.c b/cmd/bootefi.c
index 38679ffc56a9..7012d72ab50d 100644
--- a/cmd/bootefi.c
+++ b/cmd/bootefi.c
@@ -30,84 +30,9 @@ DECLARE_GLOBAL_DATA_PTR;
 
 #define OBJ_LIST_NOT_INITIALIZED 1
 
-static efi_status_t efi_obj_list_initialized = OBJ_LIST_NOT_INITIALIZED;
-
 static struct efi_device_path *bootefi_image_path;
 static struct efi_device_path *bootefi_device_path;
 
-/* Initialize and populate EFI object list */
-efi_status_t efi_init_obj_list(void)
-{
-   efi_status_t ret = EFI_SUCCESS;
-
-   /*
-* On the ARM architecture gd is mapped to a fixed register (r9 or x18).
-* As this register may be overwritten by an EFI payload we save it here
-* and restore it on every callback entered.
-*/
-   efi_save_gd();
-
-   /* Initialize once only */
-   if (efi_obj_list_initialized != OBJ_LIST_NOT_INITIALIZED)
-   return efi_obj_list_initialized;
-
-   /* Initialize system table */
-   ret = efi_initialize_system_table();
-   if (ret != EFI_SUCCESS)
-   goto out;
-
-   /* Initialize root node */
-   ret = efi_root_node_register();
-   if (ret != EFI_SUCCESS)
-   goto out;
-
-   /* Initialize EFI driver uclass */
-   ret = efi_driver_init();
-   if (ret != EFI_SUCCESS)
-   goto out;
-
-   ret = efi_console_register();
-   if (ret != EFI_SUCCESS)
-   goto out;
-#ifdef CONFIG_PARTITIONS
-   ret = efi_disk_register();
-   if (ret != EFI_SUCCESS)
-   goto out;
-#endif
-#if defined(CONFIG_LCD) || defined(CONFIG_DM_VIDEO)
-   ret = efi_gop_register();
-   if (ret != EFI_SUCCESS)
-   goto out;
-#endif
-#ifdef CONFIG_NET
-   ret = efi_net_register();
-   if (ret != EFI_SUCCESS)
-   goto out;
-#endif
-#ifdef CONFIG_GENERATE_ACPI_TABLE
-   ret = efi_acpi_register();
-   if (ret != EFI_SUCCESS)
-   goto out;
-#endif
-#ifdef CONFIG_GENERATE_SMBIOS_TABLE
-   ret = efi_smbios_register();
-   if (ret != EFI_SUCCESS)
-   goto out;
-#endif
-   ret = efi_watchdog_register();
-   if (ret != EFI_SUCCESS)
-   goto out;
-
-   /* Initialize EFI runtime services */
-   ret = efi_reset_system_init();
-   if (ret != EFI_SUCCESS)
-   goto out;
-
-out:
-   efi_obj_list_initialized = ret;
-   return ret;
-}
-
 /*
  * Allow unaligned memory access.
  *
diff --git a/include/efi_loader.h b/include/efi_loader.h
index 16633d6da0d5..dd68cfce5c65 100644
--- a/include/efi_loader.h
+++ b/include/efi_loader.h
@@ -252,6 +252,8 @@ extern struct list_head efi_obj_list;
 /* List of all events */
 extern struct list_head efi_events;
 
+/* Initialize efi execution environment */
+efi_status_t efi_init_obj_list(void);
 /* Called by bootefi to initialize root node */
 efi_status_t efi_root_node_register(void);
 /* Called by bootefi to initialize runtime */
diff --git a/lib/efi_loader/Makefile b/lib/efi_loader/Makefile
index 26b999bf7c51..3ba539314aee 100644
--- a/lib/efi_loader/Makefile
+++ b/lib/efi_loader/Makefile
@@ -29,6 +29,7 @@ obj-y += efi_image_loader.o
 obj-y += efi_memory.o
 obj-y += efi_root_node.o
 obj-y += efi_runtime.o
+obj-y += efi_setup.o
 obj-y += efi_unicode_collation.o
 obj-y += efi_variable.o
 obj-y += efi_watchdog.o
diff --git a/lib/efi_loader/efi_setup.c b/lib/efi_loader/efi_setup.c
new file mode 100644
index ..215c163380ee
--- /dev/null
+++ b/lib/efi_loader/efi_setup.c
@@ -0,0 +1,112 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ *  EFI setup code
+ *
+ *  Copyright (c) 2016 Alexander Graf
+ *  Copyright (c) 2018 AKASHI Takahiro, Linaro Limited
+ */
+
+#if 1 /* TODO: cleanup */
+#include 
+#include 
+#else
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#ifdef CONFIG_ARMV7_NONSEC
+#include 
+#include 
+#endif
+#endif
+
+DECLARE_GLOBAL_DATA_PTR;
+
+#define OBJ_LIST_NOT_INITIALIZED 1
+
+static efi_status_t efi_obj_list_initialized = OBJ_LIST_NOT_INITIALIZED;
+
+/* Initialize and populate EFI object list */
+efi_status_t 

Re: [U-Boot] [PATCH v4 1/2] riscv: configs: Rename ax25-ae350 defconfig

2018-12-17 Thread Bin Meng
On Tue, Dec 18, 2018 at 11:17 AM Andes  wrote:
>
> From: Rick Chen 
>
> Remove cpu name from the defconfig naming.
> Because other cpus maybe run on AE350 platform.
> So only use platfrom name in defconfig naming
> will be better.
>
> Also sync MAINTAINERS:
> Rename
> a25-ae350_32_defconfig as ae350_rv32_defconfig
> ax25-ae350_64_defconfig as ae350_rv64_defconfig
>
> Signed-off-by: Rick Chen 
> Cc: Greentime Hu 
> ---
>  board/AndesTech/ax25-ae350/MAINTAINERS| 5 ++---
>  configs/{a25-ae350_32_defconfig => ae350_rv32_defconfig}  | 0
>  configs/{ax25-ae350_64_defconfig => ae350_rv64_defconfig} | 0
>  3 files changed, 2 insertions(+), 3 deletions(-)
>  rename configs/{a25-ae350_32_defconfig => ae350_rv32_defconfig} (100%)
>  rename configs/{ax25-ae350_64_defconfig => ae350_rv64_defconfig} (100%)
>

Reviewed-by: Bin Meng 
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v4 2/2] doc: README.ae350: Sync for ax25-ae350 rename

2018-12-17 Thread Andes
From: Rick Chen 

Rename ax25-ae350 as ae350_rv[32|64] for 32 or 64 bit.

Signed-off-by: Rick Chen 
Cc: Greentime Hu 
Reviewed-by: Bin Meng 
---
 doc/README.ae350 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/doc/README.ae350 b/doc/README.ae350
index fe75b80..189a6b7 100644
--- a/doc/README.ae350
+++ b/doc/README.ae350
@@ -25,7 +25,7 @@ Build and boot steps
 
 build:
 1. Prepare the toolchains and make sure the $PATH to toolchains is correct.
-2. Use `make ax25-ae350_defconfig` in u-boot root to build the image.
+2. Use `make ae350_rv[32|64]_defconfig` in u-boot root to build the image for 
32 or 64 bit.
 
 Verification
 
-- 
2.7.4

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v4 1/2] riscv: configs: Rename ax25-ae350 defconfig

2018-12-17 Thread Andes
From: Rick Chen 

Remove cpu name from the defconfig naming.
Because other cpus maybe run on AE350 platform.
So only use platfrom name in defconfig naming
will be better.

Also sync MAINTAINERS:
Rename
a25-ae350_32_defconfig as ae350_rv32_defconfig
ax25-ae350_64_defconfig as ae350_rv64_defconfig

Signed-off-by: Rick Chen 
Cc: Greentime Hu 
---
 board/AndesTech/ax25-ae350/MAINTAINERS| 5 ++---
 configs/{a25-ae350_32_defconfig => ae350_rv32_defconfig}  | 0
 configs/{ax25-ae350_64_defconfig => ae350_rv64_defconfig} | 0
 3 files changed, 2 insertions(+), 3 deletions(-)
 rename configs/{a25-ae350_32_defconfig => ae350_rv32_defconfig} (100%)
 rename configs/{ax25-ae350_64_defconfig => ae350_rv64_defconfig} (100%)

diff --git a/board/AndesTech/ax25-ae350/MAINTAINERS 
b/board/AndesTech/ax25-ae350/MAINTAINERS
index d87446e..b0a99e4 100644
--- a/board/AndesTech/ax25-ae350/MAINTAINERS
+++ b/board/AndesTech/ax25-ae350/MAINTAINERS
@@ -3,6 +3,5 @@ M:  Rick Chen 
 S: Maintained
 F: board/AndesTech/ax25-ae350/
 F: include/configs/ax25-ae350.h
-F: configs/a25-ae350_32_defconfig
-F: configs/ax25-ae350_64_defconfig
-F: configs/ax25-ae350_defconfig
+F: configs/ae350_rv32_defconfig
+F: configs/ae350_rv64_defconfig
diff --git a/configs/a25-ae350_32_defconfig b/configs/ae350_rv32_defconfig
similarity index 100%
rename from configs/a25-ae350_32_defconfig
rename to configs/ae350_rv32_defconfig
diff --git a/configs/ax25-ae350_64_defconfig b/configs/ae350_rv64_defconfig
similarity index 100%
rename from configs/ax25-ae350_64_defconfig
rename to configs/ae350_rv64_defconfig
-- 
2.7.4

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v4 0/2] Rename ax25-ae350 defconfig

2018-12-17 Thread Andes
From: Rick Chen 

Remove cpu name from the defconfig naming.
Because other cpus maybe run on AE350 platform.
So only use platfrom name in defconfig naming
will be better.

Changes since v3:
 - squashed
   [PATCH v3 2/3] MAINTAINERS: Sync for ax25-ae350 rename
 into
   [PATCH v3 1/3] riscv: configs: Rename ax25-ae350 defconfig

Changes since v2:
 - Fix travis failure case 6.51 Checkfor configs without MAINTAINERS entry.
 https://travis-ci.org/rickchen36/u-boot-riscv/builds/468881778
 So add this two patchs:
 MAINTAINERS: Sync for ax25-ae350 rename
 doc: README.ae350: Sync for ax25-ae350 rename

Changes since v1:
 - Use git mv and git format-patch -M to show delta when rename.

Rick Chen (2):
  riscv: configs: Rename ax25-ae350 defconfig
  doc: README.ae350: Sync for ax25-ae350 rename

 board/AndesTech/ax25-ae350/MAINTAINERS| 5 ++---
 configs/{a25-ae350_32_defconfig => ae350_rv32_defconfig}  | 0
 configs/{ax25-ae350_64_defconfig => ae350_rv64_defconfig} | 0
 doc/README.ae350  | 2 +-
 4 files changed, 3 insertions(+), 4 deletions(-)
 rename configs/{a25-ae350_32_defconfig => ae350_rv32_defconfig} (100%)
 rename configs/{ax25-ae350_64_defconfig => ae350_rv64_defconfig} (100%)

-- 
2.7.4

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] i.MX8M layout, rephrased

2018-12-17 Thread Sergey Kubushyn

On Mon, 17 Dec 2018, Sergey Kubushyn wrote:

Yet another thought -- maybe it's time to move all 64-bit ARM stuff to its
own arch/arm64 as it is in Linux kernel since I don't remember when? There
are quite a few SoCs out there to justify such a move...


I'm looking at U-Boot master tree and u-boot-imx repository. What we have
now is quite a mess for i.MX8M.

In master we have the following directories:

 arch/arm/mach-imx/imx8
 arch/arm/mach-imx/mx8m

 arch/arm/include/asm/arch-imx8
 arch/arm/include/asm/arch-mx8m

In u-boot-imx it is different:

 arch/arm/mach-imx/imx8
 arch/arm/mach-imx/imx8m (vs ../mx8m in master)

 arch/arm/include/asm/arch/arch-imx8
 arch/arm/include/asm/arch/arch-imx8m (vs ../mx8m in master)

The question is which one is going to make it in the master tree?

The problem here is that files from those directories are referenced in
multiple places and the "imx8m"/"mx8m" is all over in the header files and
sources so once we decided on either naming one tree would have to make a
lot of changes either adding or removing that 'i' before "mx8m".

Can anybody responsible tell _WHICH_ one is going to make it into the main
source tree? Would it be better if we decide on it sooner than later (i.e.
_NOW_) so we won't have to hunt it all over the tree later on?

I assume it should be "mx8m" as it is in master tree following suit for
other flavors so it is u-boot-imx tree that has to be fixed.


Another issue is that ARCH_IMX8 and ARCH_IMX8M are treated as different
ARCHITECTURES in u-boot-imx unlike e.g. IMX6 that is treated as one ARCH
with different flavors (SX/DL/Q/whatever). That makes a lot of unnecessary
confusion and, IMHO, should be somehow cleaned up to make it consistent.


Can anybody tell something on this? Any thoughts, ideas, recomendations?


---
**
*  KSI@homeKOI8 Net  < >  The impossible we do immediately.  *
*  Las Vegas   NV, USA   < >  Miracles require 24-hour notice.   *
**
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH] poplar: save environment at a different offset

2018-12-17 Thread Shawn Guo
From: Alex Elder 

Change CONFIG_ENV_OFFSET for Poplar to be 1MB further into the eMMC
than before.  This puts it immediately prior to the space we are
reserving offset 0x20-0x40 for UEFI to save its persistent
data.  Define CONFIG_ENV_SIZE as a product of env_mmc_nblks and the
sector size, like CONFIG_ENV_OFFSET is.

Signed-off-by: Alex Elder 
Signed-off-by: Shawn Guo 
---
 include/configs/poplar.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/include/configs/poplar.h b/include/configs/poplar.h
index 0a126002d7f9..6b93b76ab9ba 100644
--- a/include/configs/poplar.h
+++ b/include/configs/poplar.h
@@ -44,7 +44,7 @@
 #define CONFIG_EXTRA_ENV_SETTINGS  \
"loader_mmc_blknum=0x0\0"   \
"loader_mmc_nblks=0x780\0"  \
-   "env_mmc_blknum=0x780\0"\
+   "env_mmc_blknum=0xf80\0"\
"env_mmc_nblks=0x80\0"  \
"kernel_addr_r=0x3000\0"\
"pxefile_addr_r=0x3200\0"   \
@@ -57,8 +57,8 @@
 
 /* Command line configuration */
 #define CONFIG_SYS_MMC_ENV_DEV 0
-#define CONFIG_ENV_OFFSET  (0x780 * 512)   /* env_mmc_blknum */
-#define CONFIG_ENV_SIZE0x1 /* env_mmc_nblks bytes 
*/
+#define CONFIG_ENV_OFFSET  (0xf80 * 512) /* env_mmc_blknum bytes */
+#define CONFIG_ENV_SIZE(0x80 * 512)  /* env_mmc_nblks 
bytes */
 
 /* Monitor Command Prompt */
 #define CONFIG_SYS_CBSIZE  512
-- 
2.18.0

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v3 2/3] MAINTAINERS: Sync for ax25-ae350 rename

2018-12-17 Thread Rick Chen
Hi Bin

Bin Meng  於 2018年12月18日 週二 上午10:50寫道:
>
> Hi Rick,
>
> On Tue, Dec 18, 2018 at 10:23 AM Rick Chen  wrote:
> >
> > Hi Bin
> >
> > Bin Meng  於 2018年12月18日 週二 上午10:12寫道:
> > >
> > > Hi Rick,
> > >
> > > On Tue, Dec 18, 2018 at 9:51 AM Andes  wrote:
> > > >
> > > > From: Rick Chen 
> > > >
> > > > Rename
> > > > a25-ae350_32_defconfig as ae350_rv32_defconfig
> > > > ax25-ae350_64_defconfig as ae350_rv64_defconfig
> > > >
> > > > Signed-off-by: Rick Chen 
> > > > Cc: Greentime Hu 
> > > > ---
> > > >  board/AndesTech/ax25-ae350/MAINTAINERS | 5 ++---
> > > >  1 file changed, 2 insertions(+), 3 deletions(-)
> > > >
> > >
> > > This patch should be squashed into patch 1 in this series, as it
> > > causes buildman warnings and should be in one single patch.
> > >
> >
> > Do you mean I shall re-send [PATCH v3 2/3] MAINTAINERS: Sync for
> > ax25-ae350 rename,
> > as a single patch, right ?
>
> I mean this patch should be squashed into patch
>
> [U-Boot,v3,1/3] riscv: configs: Rename ax25-ae350 defconfig
>
> So in v4, you should only have:
>
> [U-Boot,v4,1/2] riscv: configs: Rename ax25-ae350 defconfig
> [U-Boot,v4,2/2] doc: README.ae350: Sync for ax25-ae350 rename
>

OK

Thanks
Rick

> Regards,
> Bin
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v3 2/3] MAINTAINERS: Sync for ax25-ae350 rename

2018-12-17 Thread Bin Meng
Hi Rick,

On Tue, Dec 18, 2018 at 10:23 AM Rick Chen  wrote:
>
> Hi Bin
>
> Bin Meng  於 2018年12月18日 週二 上午10:12寫道:
> >
> > Hi Rick,
> >
> > On Tue, Dec 18, 2018 at 9:51 AM Andes  wrote:
> > >
> > > From: Rick Chen 
> > >
> > > Rename
> > > a25-ae350_32_defconfig as ae350_rv32_defconfig
> > > ax25-ae350_64_defconfig as ae350_rv64_defconfig
> > >
> > > Signed-off-by: Rick Chen 
> > > Cc: Greentime Hu 
> > > ---
> > >  board/AndesTech/ax25-ae350/MAINTAINERS | 5 ++---
> > >  1 file changed, 2 insertions(+), 3 deletions(-)
> > >
> >
> > This patch should be squashed into patch 1 in this series, as it
> > causes buildman warnings and should be in one single patch.
> >
>
> Do you mean I shall re-send [PATCH v3 2/3] MAINTAINERS: Sync for
> ax25-ae350 rename,
> as a single patch, right ?

I mean this patch should be squashed into patch

[U-Boot,v3,1/3] riscv: configs: Rename ax25-ae350 defconfig

So in v4, you should only have:

[U-Boot,v4,1/2] riscv: configs: Rename ax25-ae350 defconfig
[U-Boot,v4,2/2] doc: README.ae350: Sync for ax25-ae350 rename

Regards,
Bin
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v3 2/3] MAINTAINERS: Sync for ax25-ae350 rename

2018-12-17 Thread Rick Chen
Hi Bin

Bin Meng  於 2018年12月18日 週二 上午10:12寫道:
>
> Hi Rick,
>
> On Tue, Dec 18, 2018 at 9:51 AM Andes  wrote:
> >
> > From: Rick Chen 
> >
> > Rename
> > a25-ae350_32_defconfig as ae350_rv32_defconfig
> > ax25-ae350_64_defconfig as ae350_rv64_defconfig
> >
> > Signed-off-by: Rick Chen 
> > Cc: Greentime Hu 
> > ---
> >  board/AndesTech/ax25-ae350/MAINTAINERS | 5 ++---
> >  1 file changed, 2 insertions(+), 3 deletions(-)
> >
>
> This patch should be squashed into patch 1 in this series, as it
> causes buildman warnings and should be in one single patch.
>

Do you mean I shall re-send [PATCH v3 2/3] MAINTAINERS: Sync for
ax25-ae350 rename,
as a single patch, right ?

Rick

> Regards,
> Bin
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v3 3/3] doc: README.ae350: Sync for ax25-ae350 rename

2018-12-17 Thread Bin Meng
On Tue, Dec 18, 2018 at 9:51 AM Andes  wrote:
>
> From: Rick Chen 
>
> Rename
> ax25-ae350 as ae350_rv[32|64] for 32 or 64 bit.
>
> Signed-off-by: Rick Chen 
> Cc: Greentime Hu 
> ---
>  doc/README.ae350 | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>

Reviewed-by: Bin Meng 
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v3 2/3] MAINTAINERS: Sync for ax25-ae350 rename

2018-12-17 Thread Bin Meng
Hi Rick,

On Tue, Dec 18, 2018 at 9:51 AM Andes  wrote:
>
> From: Rick Chen 
>
> Rename
> a25-ae350_32_defconfig as ae350_rv32_defconfig
> ax25-ae350_64_defconfig as ae350_rv64_defconfig
>
> Signed-off-by: Rick Chen 
> Cc: Greentime Hu 
> ---
>  board/AndesTech/ax25-ae350/MAINTAINERS | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
>

This patch should be squashed into patch 1 in this series, as it
causes buildman warnings and should be in one single patch.

Regards,
Bin
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] i.MX8M layout, rephrased

2018-12-17 Thread Sergey Kubushyn

I'm looking at U-Boot master tree and u-boot-imx repository. What we have
now is quite a mess for i.MX8M.

In master we have the following directories:

arch/arm/mach-imx/imx8
arch/arm/mach-imx/mx8m

arch/arm/include/asm/arch-imx8
arch/arm/include/asm/arch-mx8m

In u-boot-imx it is different:

arch/arm/mach-imx/imx8
arch/arm/mach-imx/imx8m (vs ../mx8m in master)

arch/arm/include/asm/arch/arch-imx8
arch/arm/include/asm/arch/arch-imx8m (vs ../mx8m in master)

The question is which one is going to make it in the master tree?

The problem here is that files from those directories are referenced in
multiple places and the "imx8m"/"mx8m" is all over in the header files and
sources so once we decided on either naming one tree would have to make a
lot of changes either adding or removing that 'i' before "mx8m".

Can anybody responsible tell _WHICH_ one is going to make it into the main
source tree? Would it be better if we decide on it sooner than later (i.e.
_NOW_) so we won't have to hunt it all over the tree later on?

I assume it should be "mx8m" as it is in master tree following suit for
other flavors so it is u-boot-imx tree that has to be fixed.


Another issue is that ARCH_IMX8 and ARCH_IMX8M are treated as different
ARCHITECTURES in u-boot-imx unlike e.g. IMX6 that is treated as one ARCH
with different flavors (SX/DL/Q/whatever). That makes a lot of unnecessary
confusion and, IMHO, should be somehow cleaned up to make it consistent.


Can anybody tell something on this? Any thoughts, ideas, recomendations?

---
**
*  KSI@homeKOI8 Net  < >  The impossible we do immediately.  *
*  Las Vegas   NV, USA   < >  Miracles require 24-hour notice.   *
**
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v3 3/3] doc: README.ae350: Sync for ax25-ae350 rename

2018-12-17 Thread Andes
From: Rick Chen 

Rename
ax25-ae350 as ae350_rv[32|64] for 32 or 64 bit.

Signed-off-by: Rick Chen 
Cc: Greentime Hu 
---
 doc/README.ae350 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/doc/README.ae350 b/doc/README.ae350
index fe75b80..189a6b7 100644
--- a/doc/README.ae350
+++ b/doc/README.ae350
@@ -25,7 +25,7 @@ Build and boot steps
 
 build:
 1. Prepare the toolchains and make sure the $PATH to toolchains is correct.
-2. Use `make ax25-ae350_defconfig` in u-boot root to build the image.
+2. Use `make ae350_rv[32|64]_defconfig` in u-boot root to build the image for 
32 or 64 bit.
 
 Verification
 
-- 
2.7.4

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v3 2/3] MAINTAINERS: Sync for ax25-ae350 rename

2018-12-17 Thread Andes
From: Rick Chen 

Rename
a25-ae350_32_defconfig as ae350_rv32_defconfig
ax25-ae350_64_defconfig as ae350_rv64_defconfig

Signed-off-by: Rick Chen 
Cc: Greentime Hu 
---
 board/AndesTech/ax25-ae350/MAINTAINERS | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/board/AndesTech/ax25-ae350/MAINTAINERS 
b/board/AndesTech/ax25-ae350/MAINTAINERS
index d87446e..b0a99e4 100644
--- a/board/AndesTech/ax25-ae350/MAINTAINERS
+++ b/board/AndesTech/ax25-ae350/MAINTAINERS
@@ -3,6 +3,5 @@ M:  Rick Chen 
 S: Maintained
 F: board/AndesTech/ax25-ae350/
 F: include/configs/ax25-ae350.h
-F: configs/a25-ae350_32_defconfig
-F: configs/ax25-ae350_64_defconfig
-F: configs/ax25-ae350_defconfig
+F: configs/ae350_rv32_defconfig
+F: configs/ae350_rv64_defconfig
-- 
2.7.4

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v3 1/3] riscv: configs: Rename ax25-ae350 defconfig

2018-12-17 Thread Andes
From: Rick Chen 

Remove cpu name from the defconfig naming.
Because other cpus maybe run on AE350 platform.
So only use platfrom name in defconfig naming
will be better.

Signed-off-by: Rick Chen 
Cc: Greentime Hu 
Reviewed-by: Bin Meng 
---
 configs/a25-ae350_32_defconfig  | 36 
 configs/ae350_rv32_defconfig| 36 
 configs/ae350_rv64_defconfig| 37 +
 configs/ax25-ae350_64_defconfig | 37 -
 4 files changed, 73 insertions(+), 73 deletions(-)
 delete mode 100644 configs/a25-ae350_32_defconfig
 create mode 100644 configs/ae350_rv32_defconfig
 create mode 100644 configs/ae350_rv64_defconfig
 delete mode 100644 configs/ax25-ae350_64_defconfig

diff --git a/configs/a25-ae350_32_defconfig b/configs/a25-ae350_32_defconfig
deleted file mode 100644
index 5837b48..000
--- a/configs/a25-ae350_32_defconfig
+++ /dev/null
@@ -1,36 +0,0 @@
-CONFIG_RISCV=y
-CONFIG_SYS_TEXT_BASE=0x
-CONFIG_TARGET_AX25_AE350=y
-CONFIG_DISTRO_DEFAULTS=y
-CONFIG_NR_DRAM_BANKS=2
-CONFIG_FIT=y
-CONFIG_BOOTDELAY=3
-CONFIG_BOARD_EARLY_INIT_F=y
-CONFIG_SYS_PROMPT="RISC-V # "
-CONFIG_CMD_IMLS=y
-CONFIG_CMD_MMC=y
-CONFIG_CMD_SF=y
-CONFIG_CMD_SF_TEST=y
-# CONFIG_CMD_SETEXPR is not set
-CONFIG_BOOTP_PREFER_SERVERIP=y
-CONFIG_CMD_CACHE=y
-CONFIG_OF_BOARD=y
-CONFIG_DEFAULT_DEVICE_TREE="ae350_32"
-CONFIG_ENV_IS_IN_SPI_FLASH=y
-CONFIG_NET_RANDOM_ETHADDR=y
-CONFIG_MMC=y
-CONFIG_FTSDC010=y
-CONFIG_FTSDC010_SDIO=y
-CONFIG_MTD_NOR_FLASH=y
-CONFIG_FLASH_CFI_DRIVER=y
-CONFIG_CFI_FLASH=y
-CONFIG_SYS_FLASH_USE_BUFFER_WRITE=y
-CONFIG_SYS_FLASH_CFI=y
-CONFIG_SPI_FLASH=y
-CONFIG_SPI_FLASH_MACRONIX=y
-CONFIG_FTMAC100=y
-CONFIG_BAUDRATE=38400
-CONFIG_SYS_NS16550=y
-CONFIG_SPI=y
-CONFIG_ATCSPI200_SPI=y
-CONFIG_ATCPIT100_TIMER=y
diff --git a/configs/ae350_rv32_defconfig b/configs/ae350_rv32_defconfig
new file mode 100644
index 000..5837b48
--- /dev/null
+++ b/configs/ae350_rv32_defconfig
@@ -0,0 +1,36 @@
+CONFIG_RISCV=y
+CONFIG_SYS_TEXT_BASE=0x
+CONFIG_TARGET_AX25_AE350=y
+CONFIG_DISTRO_DEFAULTS=y
+CONFIG_NR_DRAM_BANKS=2
+CONFIG_FIT=y
+CONFIG_BOOTDELAY=3
+CONFIG_BOARD_EARLY_INIT_F=y
+CONFIG_SYS_PROMPT="RISC-V # "
+CONFIG_CMD_IMLS=y
+CONFIG_CMD_MMC=y
+CONFIG_CMD_SF=y
+CONFIG_CMD_SF_TEST=y
+# CONFIG_CMD_SETEXPR is not set
+CONFIG_BOOTP_PREFER_SERVERIP=y
+CONFIG_CMD_CACHE=y
+CONFIG_OF_BOARD=y
+CONFIG_DEFAULT_DEVICE_TREE="ae350_32"
+CONFIG_ENV_IS_IN_SPI_FLASH=y
+CONFIG_NET_RANDOM_ETHADDR=y
+CONFIG_MMC=y
+CONFIG_FTSDC010=y
+CONFIG_FTSDC010_SDIO=y
+CONFIG_MTD_NOR_FLASH=y
+CONFIG_FLASH_CFI_DRIVER=y
+CONFIG_CFI_FLASH=y
+CONFIG_SYS_FLASH_USE_BUFFER_WRITE=y
+CONFIG_SYS_FLASH_CFI=y
+CONFIG_SPI_FLASH=y
+CONFIG_SPI_FLASH_MACRONIX=y
+CONFIG_FTMAC100=y
+CONFIG_BAUDRATE=38400
+CONFIG_SYS_NS16550=y
+CONFIG_SPI=y
+CONFIG_ATCSPI200_SPI=y
+CONFIG_ATCPIT100_TIMER=y
diff --git a/configs/ae350_rv64_defconfig b/configs/ae350_rv64_defconfig
new file mode 100644
index 000..b250d3f
--- /dev/null
+++ b/configs/ae350_rv64_defconfig
@@ -0,0 +1,37 @@
+CONFIG_RISCV=y
+CONFIG_SYS_TEXT_BASE=0x
+CONFIG_TARGET_AX25_AE350=y
+CONFIG_ARCH_RV64I=y
+CONFIG_DISTRO_DEFAULTS=y
+CONFIG_NR_DRAM_BANKS=2
+CONFIG_FIT=y
+CONFIG_BOOTDELAY=3
+CONFIG_BOARD_EARLY_INIT_F=y
+CONFIG_SYS_PROMPT="RISC-V # "
+CONFIG_CMD_IMLS=y
+CONFIG_CMD_MMC=y
+CONFIG_CMD_SF=y
+CONFIG_CMD_SF_TEST=y
+# CONFIG_CMD_SETEXPR is not set
+CONFIG_BOOTP_PREFER_SERVERIP=y
+CONFIG_CMD_CACHE=y
+CONFIG_OF_BOARD=y
+CONFIG_DEFAULT_DEVICE_TREE="ae350_64"
+CONFIG_ENV_IS_IN_SPI_FLASH=y
+CONFIG_NET_RANDOM_ETHADDR=y
+CONFIG_MMC=y
+CONFIG_FTSDC010=y
+CONFIG_FTSDC010_SDIO=y
+CONFIG_MTD_NOR_FLASH=y
+CONFIG_FLASH_CFI_DRIVER=y
+CONFIG_CFI_FLASH=y
+CONFIG_SYS_FLASH_USE_BUFFER_WRITE=y
+CONFIG_SYS_FLASH_CFI=y
+CONFIG_SPI_FLASH=y
+CONFIG_SPI_FLASH_MACRONIX=y
+CONFIG_FTMAC100=y
+CONFIG_BAUDRATE=38400
+CONFIG_SYS_NS16550=y
+CONFIG_SPI=y
+CONFIG_ATCSPI200_SPI=y
+CONFIG_ATCPIT100_TIMER=y
diff --git a/configs/ax25-ae350_64_defconfig b/configs/ax25-ae350_64_defconfig
deleted file mode 100644
index b250d3f..000
--- a/configs/ax25-ae350_64_defconfig
+++ /dev/null
@@ -1,37 +0,0 @@
-CONFIG_RISCV=y
-CONFIG_SYS_TEXT_BASE=0x
-CONFIG_TARGET_AX25_AE350=y
-CONFIG_ARCH_RV64I=y
-CONFIG_DISTRO_DEFAULTS=y
-CONFIG_NR_DRAM_BANKS=2
-CONFIG_FIT=y
-CONFIG_BOOTDELAY=3
-CONFIG_BOARD_EARLY_INIT_F=y
-CONFIG_SYS_PROMPT="RISC-V # "
-CONFIG_CMD_IMLS=y
-CONFIG_CMD_MMC=y
-CONFIG_CMD_SF=y
-CONFIG_CMD_SF_TEST=y
-# CONFIG_CMD_SETEXPR is not set
-CONFIG_BOOTP_PREFER_SERVERIP=y
-CONFIG_CMD_CACHE=y
-CONFIG_OF_BOARD=y
-CONFIG_DEFAULT_DEVICE_TREE="ae350_64"
-CONFIG_ENV_IS_IN_SPI_FLASH=y
-CONFIG_NET_RANDOM_ETHADDR=y
-CONFIG_MMC=y
-CONFIG_FTSDC010=y
-CONFIG_FTSDC010_SDIO=y
-CONFIG_MTD_NOR_FLASH=y
-CONFIG_FLASH_CFI_DRIVER=y
-CONFIG_CFI_FLASH=y
-CONFIG_SYS_FLASH_USE_BUFFER_WRITE=y
-CONFIG_SYS_FLASH_CFI=y
-CONFIG_SPI_FLASH=y
-CONFIG_SPI_FLASH_MACRONIX=y
-CONFIG_FTMAC100=y
-CONFIG_BAUDRATE=38400
-CONFIG_SYS_NS16550=y

[U-Boot] [PATCH v3 0/3] Rename ax25-ae350 defconfig

2018-12-17 Thread Andes
From: Rick Chen 

Remove cpu name from the defconfig naming.
Because other cpus maybe run on AE350 platform.
So only use platfrom name in defconfig naming
will be better.

Changes since v2:
 - Fix travis failure case 6.51 Checkfor configs without MAINTAINERS entry.
   https://travis-ci.org/rickchen36/u-boot-riscv/builds/468881778
 So add this two patchs:
 MAINTAINERS: Sync for ax25-ae350 rename
 doc: README.ae350: Sync for ax25-ae350 rename

Changes since v1:
 - Use git mv and git format-patch -M to show delta when rename.

Rick Chen (3):
  riscv: configs: Rename ax25-ae350 defconfig
  MAINTAINERS: Sync for ax25-ae350 rename
  doc: README.ae350: Sync for ax25-ae350 rename

 board/AndesTech/ax25-ae350/MAINTAINERS |  5 ++---
 configs/a25-ae350_32_defconfig | 36 -
 configs/ae350_rv32_defconfig   | 36 +
 configs/ae350_rv64_defconfig   | 37 ++
 configs/ax25-ae350_64_defconfig| 37 --
 doc/README.ae350   |  2 +-
 6 files changed, 76 insertions(+), 77 deletions(-)
 delete mode 100644 configs/a25-ae350_32_defconfig
 create mode 100644 configs/ae350_rv32_defconfig
 create mode 100644 configs/ae350_rv64_defconfig
 delete mode 100644 configs/ax25-ae350_64_defconfig

-- 
2.7.4

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [ANN] U-Boot v2019.01-rc2 released

2018-12-17 Thread Tom Rini
Hey all,

So it's release day and I've put up v2019.01-rc2, I've updated git and
the tarballs are also up now.

Thanks again to having signed tags, between -rc1 and -rc2 we have
(including but not limited to):
- Various important DT syncs with Linux
- Risc-V S-Mode
- Important NAND/MTD fixups
- TPM, sound updates
- FAT fixes
- amlogic, sunxi, marvel, rockchip, x86, mips, layerscape and other updates
- USB Gadget DM work, and some other related USB fixes.
- DM_I2C_COMPAT code removal for TI platforms.

We're looking at release on January 7th, 2019.

Thanks all!

-- 
Tom


signature.asc
Description: PGP signature
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH] omap3: beagle: Enable DM_MMC and BLK for u-boot only, not SPL

2018-12-17 Thread Tom Rini
On Mon, Dec 17, 2018 at 01:34:53PM -0600, Adam Ford wrote:
> On Mon, Dec 17, 2018 at 11:04 AM Guillaume Gardet
>  wrote:
> >
> >
> > Le 21/11/2018 à 18:06, Tom Rini a écrit :
> > > On Wed, Nov 21, 2018 at 04:13:20PM +0100, Guillaume GARDET wrote:
> > >
> > >> Also disable USB_STORAGE as it is not ready for the switch.
> > >> Tested on a Beagleboard xM rev. B.
> > >>
> > >> Signed-off-by: Guillaume GARDET 
> > >>
> > >> Cc: Tom Rini 
> > >> Cc: Simon Glass 
> > > In the case of USB_STORAGE we need to turn on DM_USB and then it works.
> >
> >
> > If DM_USB is enabled, no USB controller are detected, so we loose Ethernet. 
> > Did I miss an additional option to enable?
> 
> AFASK, the MUSB driver didn't yet support gadget mode when used with
> DM_USB... at least until recently.  I noticed that part of the MUSB
> driver was updated, but the omap2430 glue hasn't been updated yet.  I
> am not 100% sure, but I think the Beagle xM is a DM3730 which uses the
> omap2430 glue.  I doubt TI will update the omap2430 glue, so I started
> some stuff. I've got on patch that seems to show the usb gadget
> controller in the DM tree, but my board hangs when I try to use a
> gadget.
> 
> It's not ready for the mailing list yet, but I can push this stuff to
> my github later today if someone wants to look at it and/or
> test/improve it.

Thanks for looking into all this.  Another thing missing right now is
the logic to move to SPL FIT images and pick the right DTB for the
variant we're on as for example my bb xM doesn't work at all once we
switch to mostly DM :)

-- 
Tom


signature.asc
Description: PGP signature
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v3 0/5] Add support for MIPS Creator CI20

2018-12-17 Thread Daniel Schwierzeck


Am 16.12.18 um 23:25 schrieb Ezequiel Garcia:
> A new round, addressing feedback from Daniel.
> 
> Daniel: do you think this is acceptable as a first submission?
> 
> v3:
>  * Cleanup SoC reset logic.
>  * Move gpio driver to SoC specific code, to be used by SPL.
>A proper dm gpio driver will be added later.
>  * Cleaned up SPDX.
>  * Added myself as JZ4780 maintainer.
>  * Added TODO file.
> 
> v2:
> 
>  * Replaced infinite while loop with wait_for_bit.
>  * Added a MAINTAINERS file. If anyone wants to co-maintain this,
>please let me know.
> 
> This is based on master and has been tested by SD-card booting
> both U-Boot and Linux. Booting Linux via TFTP was also tested.
> 
> I've pushed a branch to https://github.com/ezequielgarcia/u-boot/tree/ci20-v3
> and started travis.
> 
> Note that Paul's contributions are recorded using his imgtec.com
> mail although it's no longer valid, and that we will rely on mailmap
> to map it to mips.com.
> 
> It would be terrific to fit this on the next release.
> 
> Thanks!
> 
> Paul Burton (5):
>   misc: Add JZ47xx efuse driver
>   mmc: Add JZ47xx SD/MMC controller driver
>   mips: Add SPL header
>   mips: jz47xx: Add JZ4780 SoC support
>   mips: jz47xx: Add Creator CI20 platform

applied to u-boot-mips, thanks.

I fixed some additional SPDX license identifiers because not all files
got updated ;) I also fixed some minor checkpatch.pl issues.

I renamed the defconfig to ci20_mmc to clearly indicate the MMC boot
mode in case someone wants to add boot from NAND or USB later. The
latter could be useful for developing. I hope you don't mind ;)

I also moved CONFIG_MISC_INIT_R from ci20.h to defconfig as this option
has been converted to Kconfig some time ago. Finally I enabled cmd_dm to
quickly test current DM integration.

The updated series still booted on my rev1 board.

Maybe one of the next improvements should be to enable
CONFIG_DISTRO_DEFAULTS and CONFIG_MIPS_BOOT_FDT.

-- 
- Daniel
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v4 0/7] Add support for the SoCs found in Microsemi switches

2018-12-17 Thread Daniel Schwierzeck


Am 14.12.18 um 16:16 schrieb Gregory CLEMENT:
> Hello,
> 
> For the record this the fourth version of the series adding the
> support of 2 SoCs: Ocelot and Luton from Microsemi. Both of them
> belongs to the same family Vcore III.
> 
> We found them on various advanced switches product.
> 
> The support for Ocelot already have been submit to Linux, but not yet
> the Luton support.
> 
> The comments on v3 were fewer and quite easy to address, so I am able
> to send a new version right one (hopping it will be the final one :)
> ).
> 
> Gregory
> 
> Changelog:
> 
> v3 -> v4:
> 
>  - add the support for the legacy kernel more generic and more related
>to the old bootloader: redboot
>  - removed useless test on CONFIG_ARCH_MSCC in
>arch/mips/mach-mscc/include/ioremap.h
>  - add an explanation about the cache instruction lock in
>hal_vcoreiii_ddr_failed()
>  - use __raw_read/write instead of directly use pointer dereferencing
>  - use rmb instead of asm volatile("" : : : "memory");
>  - remove remaining C++ style comment
>  - use __maybe_unused instead of __attribute__ ((unused))
>  - indent by an extra space the instructions in the delay slot
> 
> 
> v2 -> v3:
>  - Added n entry in the MAINTAINER file for the SoCs
>  - Fixup the last errors from checkpatch, the remaining ones are only
>about volatile, long line and Kconfig, but each ones have good
>reason to be here.
>  - Add SPI NAND flash support in device tree and configuration files,
>the driver are already be merged in U-Boot.
>  - In order to improve boot time, setup the TLB to allow using cache
>in the memory mapped to the SPI NOR.
>  - Removed all the macro REG_CFG to only keep direct access to memory.
>  - Put back the setting of the interrupt map as it is needed by
>mainline kernel (without it the kernel doesn't finish to boot)
>  - During DDR training, prevent the compiler reordering the
>instruction.
>  - Add early debug support to Ocelot (it was already done for Luton)
> 
> v1 -> v2:
>  - a big clean-up for indentation and some style issue
>  - usage of the clrsetbits family functions where it was possible
>  - split the patches for Ocelot and Luton
>  - add a new patch to introduce the icache_lock function which was in
>the mscc directory in the first version
>  - remove more unused define in the platform header files
>  - use the automatic cache size detection instead of hard coding it
>  - reduce the tlb init to only two entries for the IO as needed by the
> kernel
>  - remove the interrupt disabling
>  - fix the ddr init for luton
> 
> Gregory CLEMENT (7):
>   MIPS: move create_tlb() in an proper header: mipsregs.h
>   MIPS: Allow to prefetch and lock instructions into cache
>   MSCC: add support for Ocelot SoCs
>   MSCC: add support for Luton SoCs
>   MSCC: add board support for the Ocelots based evaluation boards
>   MSCC: add board support for the Luton based evaluation board
>   MIPS: bootm: Add support for compatibility with redboot
> 
>  MAINTAINERS   |  13 +
>  arch/mips/Kconfig |  10 +
>  arch/mips/Makefile|   1 +
>  arch/mips/cpu/cpu.c   |  10 -
>  arch/mips/dts/luton_pcb091.dts|  36 +
>  arch/mips/dts/mscc,luton.dtsi |  87 ++
>  arch/mips/dts/mscc,ocelot.dtsi| 152 
>  arch/mips/dts/mscc,ocelot_pcb.dtsi|  42 +
>  arch/mips/dts/ocelot_pcb120.dts   |  12 +
>  arch/mips/dts/ocelot_pcb123.dts   |  12 +
>  arch/mips/include/asm/cacheops.h  |  19 +
>  arch/mips/include/asm/mipsregs.h  |  11 +
>  arch/mips/lib/bootm.c |  76 +-
>  arch/mips/mach-mscc/Kconfig   |  86 ++
>  arch/mips/mach-mscc/Makefile  |   6 +
>  arch/mips/mach-mscc/cpu.c | 102 +++
>  arch/mips/mach-mscc/dram.c|  73 ++
>  arch/mips/mach-mscc/include/ioremap.h |  49 ++
>  arch/mips/mach-mscc/include/mach/common.h |  28 +
>  arch/mips/mach-mscc/include/mach/ddr.h| 814 ++
>  .../mips/mach-mscc/include/mach/luton/luton.h |  24 +
>  .../include/mach/luton/luton_devcpu_gcb.h |  14 +
>  .../include/mach/luton/luton_icpu_cfg.h   | 245 ++
>  .../mach-mscc/include/mach/ocelot/ocelot.h|  24 +
>  .../include/mach/ocelot/ocelot_devcpu_gcb.h   |  21 +
>  .../include/mach/ocelot/ocelot_icpu_cfg.h | 274 ++
>  arch/mips/mach-mscc/include/mach/tlb.h|  55 ++
>  arch/mips/mach-mscc/lowlevel_init.S   |  30 +
>  arch/mips/mach-mscc/lowlevel_init_luton.S |  62 ++
>  arch/mips/mach-mscc/reset.c   |  30 +
>  board/mscc/luton/Kconfig  |  14 +
>  board/mscc/luton/Makefile |   3 +
>  board/mscc/luton/luton.c  |  28 +
>  board/mscc/ocelot/Kconfig |  14 +
>  

[U-Boot] [PATCH 1/1] efi_loader: struct efi_configuration_table

2018-12-17 Thread Heinrich Schuchardt
Commit 393fccdf6c73 ("efi_loader: efi_guid_t must be 64-bit aligned")
has changed the alignment of efi_guid_t. This changed the size of
struct efi_configuration_table on 32-bit systems form 20 to 24 bytes. As
an array of this type is pointed to by the system table this breaks
compatibility with existing versions of GRUB and Linux. Let's get back the
original size by using the attribute __packed.

Fixes: 393fccdf6c73 ("efi_loader: efi_guid_t must be 64-bit aligned")
Signed-off-by: Heinrich Schuchardt 
---
 include/efi_api.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/efi_api.h b/include/efi_api.h
index e850b951eb..10bcb5a1df 100644
--- a/include/efi_api.h
+++ b/include/efi_api.h
@@ -299,7 +299,7 @@ struct efi_runtime_services {
 struct efi_configuration_table {
efi_guid_t guid;
void *table;
-};
+} __packed;
 
 #define EFI_SYSTEM_TABLE_SIGNATURE ((u64)0x5453595320494249ULL)
 
-- 
2.19.2

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH 1/1] efi_loader: efi_guid_t must be 64-bit aligned

2018-12-17 Thread Heinrich Schuchardt
On 12/16/18 10:32 AM, Ard Biesheuvel wrote:
> On Sat, 15 Dec 2018 at 22:40, Heinrich Schuchardt  wrote:
>>
>> The UEFI Specification Version 2.7 Errata A defines:
>>
>> "EFI_GUID
>> 128-bit buffer containing a unique identifier value.
>> Unless otherwise specified, aligned on a 64-bit boundary."
>>
>> Before this patch efi_guid_t was 8-bit aligned.
>>
>> Signed-off-by: Heinrich Schuchardt 
> 
> Acked-by: Ard Biesheuvel 
> 
>> ---
>>  include/efi.h | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/include/efi.h b/include/efi.h
>> index b5e2c64f38b..3018c61b373 100644
>> --- a/include/efi.h
>> +++ b/include/efi.h
>> @@ -49,7 +49,7 @@ struct efi_device_path;
>>
>>  typedef struct {
>> u8 b[16];
>> -} efi_guid_t;
>> +} efi_guid_t __attribute__ ((aligned (8)));
>>
>>  #define EFI_BITS_PER_LONG  (sizeof(long) * 8)
>>
>> --
>> 2.19.2
>>
> 

Hello Alex,

we should carefully evaluate which side effects this patch has. The
system table contains a link to an array of struct
efi_configuration_table. On 32 bit-systems the patch changes the size of
the entries from 20 to 24 bytes.

So at least this structure we will have to changed to __packed to stay
in sync with GRUB and Linux.

It is unfortunate that the UEFI spec has been written with little detail
on the alignment of structures. Cf. Takahiro's patches concerning the
HII protocols.

Best regards

Heinrich
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] Unable to saveenv to MMC

2018-12-17 Thread Robin Polak
The output I'm getting is:

=>  ls mmc 0:0
** Unrecognized filesystem type **

On Sun, Dec 9, 2018 at 1:43 AM  wrote:

> just try the ls-command i wrote in uboot-console ;)
>
>
> Gesendet: Sonntag, 09. Dezember 2018 um 04:20 Uhr
> Von: "Robin Polak" 
> An: fran...@public-files.de
> Cc: u-boot@lists.denx.de
> Betreff: Re: [U-Boot] Unable to saveenv to MMC
>
> How would I go about validating whether I can access the partition from
> u-boot?
>
> On Fri, Dec 7, 2018 at 1:47 AM Frank Wunderlich  [mailto:fran...@public-files.de]> wrote:can you try to access the
> partiton from uboot?
>
> ls mmc 0:0
>
> regards Frank
>
> > Von: "Robin Polak" mailto:ad...@robinpolak.com]>
> >   I'm having trouble persisting my environment variables to the SD Card
> > onto which I have FAT formatted and then written U-Boot to using the
> > following command:
> > ...
> > => saveenv
> > Saving Environment to FAT... Unable to use mmc 0:0... Failed (1)
>
> --
>
> --Robin polakro...@robinpolak.com[mailto:ro...@robinpolak.com]
> 917-494-2080
>


-- 
--
Robin Polak
ro...@robinpolak.com
917-494-2080
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v8 10/10] arm: bootm: fix sp detection at end of address range

2018-12-17 Thread Stephen Warren

On 12/17/18 1:08 PM, Simon Goldschmidt wrote:

This fixes  'arch_lmb_reserve()' for ARM that tries to detect in which
DRAM bank 'sp' is in.

This code failed if a bank was at the end of physical address range
(i.e. size + length overflowed to 0).

To fix this, calculate 'bank_end' as 'size + length - 1' so that such
banks end at 0x, not 0.

Fixes: 15751403b6 ("ARM: bootm: don't assume sp is in DRAM bank 0")
Reported-by: Frank Wunderlich 
Signed-off-by: Simon Goldschmidt 


This patch,
Reviewed-by: Stephen Warren 
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH] omap3: beagle: Enable DM_MMC and BLK for u-boot only, not SPL

2018-12-17 Thread Adam Ford
On Mon, Dec 17, 2018 at 1:34 PM Adam Ford  wrote:
>
> On Mon, Dec 17, 2018 at 11:04 AM Guillaume Gardet
>  wrote:
> >
> >
> > Le 21/11/2018 à 18:06, Tom Rini a écrit :
> > > On Wed, Nov 21, 2018 at 04:13:20PM +0100, Guillaume GARDET wrote:
> > >
> > >> Also disable USB_STORAGE as it is not ready for the switch.
> > >> Tested on a Beagleboard xM rev. B.
> > >>
> > >> Signed-off-by: Guillaume GARDET 
> > >>
> > >> Cc: Tom Rini 
> > >> Cc: Simon Glass 
> > > In the case of USB_STORAGE we need to turn on DM_USB and then it works.
> >
> >
> > If DM_USB is enabled, no USB controller are detected, so we loose Ethernet. 
> > Did I miss an additional option to enable?
>
> AFASK, the MUSB driver didn't yet support gadget mode when used with
> DM_USB... at least until recently.  I noticed that part of the MUSB
> driver was updated, but the omap2430 glue hasn't been updated yet.  I
> am not 100% sure, but I think the Beagle xM is a DM3730 which uses the
> omap2430 glue.  I doubt TI will update the omap2430 glue, so I started
> some stuff. I've got on patch that seems to show the usb gadget
> controller in the DM tree, but my board hangs when I try to use a
> gadget.
>
> It's not ready for the mailing list yet, but I can push this stuff to
> my github later today if someone wants to look at it and/or
> test/improve it.

Guillaume,

I 'think' I got the peripheral mode working on my DM3730.  Like
before, it only supports host or gadget, and I set the patch up to
look at whether or not CONFIG_USB_MUSB_GADGET is set.

I was able to get Fastboot devices to appear and an sdp device to
appear.  I wasn't setup to actually run data through those interfaces,
but my host machine recognized them.

Feel free to try the patches and please give feedback.  They are
located: https://patchwork.ozlabs.org/project/uboot/list/?series=82418

adam

>
> adam
> >
> > Guillaume
> >
> >
> > ___
> > U-Boot mailing list
> > U-Boot@lists.denx.de
> > https://lists.denx.de/listinfo/u-boot
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH 2/2] USB: musb-new: omap2430: Add hooks for Peripheral support.

2018-12-17 Thread Adam Ford
Borrowing from the updates to ti-musb.c, this glue layer checks
to see if the MUSB controller is gadget or host.  Going under
the assumpution there is only one MUSB controller, this only builds
either the host probe or the gadget probe.  OTG would be preferred,
but it doesn't appear to be working yet.

Signed-off-by: Adam Ford 

diff --git a/drivers/usb/musb-new/omap2430.c b/drivers/usb/musb-new/omap2430.c
index b6e1320538..780d21c693 100644
--- a/drivers/usb/musb-new/omap2430.c
+++ b/drivers/usb/musb-new/omap2430.c
@@ -203,7 +203,7 @@ static int omap2430_musb_ofdata_to_platdata(struct udevice 
*dev)
return 0;
 }
 
-#ifdef CONFIG_USB_MUSB_HOST
+#ifndef CONFIG_USB_MUSB_GADGET
 static int omap2430_musb_probe(struct udevice *dev)
 {
struct musb_host_data *host = dev_get_priv(dev);
@@ -241,7 +241,7 @@ static int omap2430_musb_remove(struct udevice *dev)
 #if CONFIG_IS_ENABLED(OF_CONTROL)
 static int omap2430_musb_host_ofdata_to_platdata(struct udevice *dev)
 {
-   struct ti_musb_platdata *platdata = dev_get_platdata(dev);
+   struct omap2430_musb_platdata *platdata = dev_get_platdata(dev);
const void *fdt = gd->fdt_blob;
int node = dev_of_offset(dev);
int ret;
@@ -272,6 +272,83 @@ U_BOOT_DRIVER(omap2430_musb) = {
.priv_auto_alloc_size = sizeof(struct musb_host_data),
 };
 
+#else
+
+struct omap2430_musb_peripheral {
+   struct musb *periph;
+};
+
+#if CONFIG_IS_ENABLED(OF_CONTROL)
+static int omap2430_musb_peripheral_ofdata_to_platdata(struct udevice *dev)
+{
+   struct ti_musb_platdata *platdata = dev_get_platdata(dev);
+   const void *fdt = gd->fdt_blob;
+   int node = dev_of_offset(dev);
+   int ret;
+
+   ret = omap2430_musb_ofdata_to_platdata(dev);
+   if (ret) {
+   pr_err("platdata dt parse error\n");
+   return ret;
+   }
+   platdata->plat.mode = MUSB_PERIPHERAL;
+
+   return 0;
+}
+#endif
+
+int dm_usb_gadget_handle_interrupts(struct udevice *dev)
+{
+   struct omap2430_musb_peripheral *priv = dev_get_priv(dev);
+
+   priv->periph->isr(0, priv->periph);
+
+   return 0;
+}
+
+static int omap2430_musb_peripheral_probe(struct udevice *dev)
+{
+   struct omap2430_musb_peripheral *priv = dev_get_priv(dev);
+   struct omap2430_musb_platdata *platdata = dev_get_platdata(dev);
+   struct omap_musb_board_data *otg_board_data;
+   int ret;
+
+   otg_board_data = >otg_board_data;
+   priv->periph = musb_init_controller(>plat,
+   (struct device *)otg_board_data,
+   platdata->base);
+   if (!priv->periph)
+   return -EIO;
+
+   /* ti_musb_set_phy_power(dev, 1); */
+   musb_gadget_setup(priv->periph);
+   return usb_add_gadget_udc((struct device *)dev, >periph->g);
+}
+
+static int omap2430_musb_peripheral_remove(struct udevice *dev)
+{
+   struct omap2430_musb_peripheral *priv = dev_get_priv(dev);
+
+   usb_del_gadget_udc(>periph->g);
+   /* ti_musb_set_phy_power(dev, 0); */
+
+   return 0;
+}
+
+U_BOOT_DRIVER(omap2430_musb_peripheral) = {
+   .name   = "ti-musb-peripheral",
+   .id = UCLASS_USB_GADGET_GENERIC,
+   .of_match = omap2430_musb_ids,
+#if CONFIG_IS_ENABLED(OF_CONTROL)
+   .ofdata_to_platdata = omap2430_musb_peripheral_ofdata_to_platdata,
+#endif
+   .probe = omap2430_musb_peripheral_probe,
+   .remove = omap2430_musb_peripheral_remove,
+   .ops= _usb_ops,
+   .platdata_auto_alloc_size = sizeof(struct omap2430_musb_platdata),
+   .priv_auto_alloc_size = sizeof(struct omap2430_musb_peripheral),
+   .flags = DM_FLAG_PRE_RELOC,
+};
 #endif
 
 #endif /* CONFIG_IS_ENABLED(DM_USB) */
-- 
2.17.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH 1/2] USB: musb-new: omap2430: Prep driver for Peripheral support.

2018-12-17 Thread Adam Ford
The omap2430 driver only currently supports host only.  In
preparation for supporting peripheral mode, this patch makes
the driver support only the host by creating a ofdata_to_platdata
function host/peripheral agnostic with a host helper version.

Signed-off-by: Adam Ford 

diff --git a/drivers/usb/musb-new/omap2430.c b/drivers/usb/musb-new/omap2430.c
index 32743aa72c..b6e1320538 100644
--- a/drivers/usb/musb-new/omap2430.c
+++ b/drivers/usb/musb-new/omap2430.c
@@ -137,6 +137,12 @@ const struct musb_platform_ops omap2430_ops = {
 
 #if CONFIG_IS_ENABLED(DM_USB)
 
+static const struct udevice_id omap2430_musb_ids[] = {
+   { .compatible = "ti,omap3-musb" },
+   { .compatible = "ti,omap4-musb" },
+   { }
+};
+
 struct omap2430_musb_platdata {
void *base;
void *ctrl_mod_base;
@@ -190,20 +196,6 @@ static int omap2430_musb_ofdata_to_platdata(struct udevice 
*dev)
return -ENOENT;
}
 
-#if 0 /* In a perfect world, mode would be set to OTG, mode 3 from DT */
-   platdata->plat.mode = fdtdec_get_int(fdt, node,
-   
"mode", -1);
-   if (platdata->plat.mode < 0) {
-   pr_err("MUSB mode DT entry missing\n");
-   return -ENOENT;
-   }
-#else /* MUSB_OTG, it doesn't work */
-#ifdef CONFIG_USB_MUSB_HOST /* Host seems to be the only option that works */
-   platdata->plat.mode = MUSB_HOST;
-#else /* For that matter, MUSB_PERIPHERAL doesn't either */
-   platdata->plat.mode = MUSB_PERIPHERAL;
-#endif
-#endif
platdata->otg_board_data.dev = dev;
platdata->plat.config = >musb_config;
platdata->plat.platform_ops = _ops;
@@ -211,11 +203,10 @@ static int omap2430_musb_ofdata_to_platdata(struct 
udevice *dev)
return 0;
 }
 
+#ifdef CONFIG_USB_MUSB_HOST
 static int omap2430_musb_probe(struct udevice *dev)
 {
-#ifdef CONFIG_USB_MUSB_HOST
struct musb_host_data *host = dev_get_priv(dev);
-#endif
struct omap2430_musb_platdata *platdata = dev_get_platdata(dev);
struct usb_bus_priv *priv = dev_get_uclass_priv(dev);
struct omap_musb_board_data *otg_board_data;
@@ -226,7 +217,6 @@ static int omap2430_musb_probe(struct udevice *dev)
 
otg_board_data = >otg_board_data;
 
-#ifdef CONFIG_USB_MUSB_HOST
host->host = musb_init_controller(>plat,
  (struct device *)otg_board_data,
  platdata->base);
@@ -235,11 +225,7 @@ static int omap2430_musb_probe(struct udevice *dev)
}
 
ret = musb_lowlevel_init(host);
-#else
-   ret = musb_register(>plat,
- (struct device *)otg_board_data,
- platdata->base);
-#endif
+
return ret;
 }
 
@@ -252,28 +238,40 @@ static int omap2430_musb_remove(struct udevice *dev)
return 0;
 }
 
-static const struct udevice_id omap2430_musb_ids[] = {
-   { .compatible = "ti,omap3-musb" },
-   { .compatible = "ti,omap4-musb" },
-   { }
-};
+#if CONFIG_IS_ENABLED(OF_CONTROL)
+static int omap2430_musb_host_ofdata_to_platdata(struct udevice *dev)
+{
+   struct ti_musb_platdata *platdata = dev_get_platdata(dev);
+   const void *fdt = gd->fdt_blob;
+   int node = dev_of_offset(dev);
+   int ret;
+
+   ret = omap2430_musb_ofdata_to_platdata(dev);
+   if (ret) {
+   pr_err("platdata dt parse error\n");
+   return ret;
+   }
+
+   platdata->plat.mode = MUSB_HOST;
+
+   return 0;
+}
+#endif
 
 U_BOOT_DRIVER(omap2430_musb) = {
.name   = "omap2430-musb",
-#ifdef CONFIG_USB_MUSB_HOST
.id = UCLASS_USB,
-#else
-   .id = UCLASS_USB_GADGET_GENERIC,
-#endif
.of_match = omap2430_musb_ids,
-   .ofdata_to_platdata = omap2430_musb_ofdata_to_platdata,
+#if CONFIG_IS_ENABLED(OF_CONTROL)
+   .ofdata_to_platdata = omap2430_musb_host_ofdata_to_platdata,
+#endif
.probe = omap2430_musb_probe,
.remove = omap2430_musb_remove,
-#ifdef CONFIG_USB_MUSB_HOST
.ops = _usb_ops,
-#endif
.platdata_auto_alloc_size = sizeof(struct omap2430_musb_platdata),
.priv_auto_alloc_size = sizeof(struct musb_host_data),
 };
 
+#endif
+
 #endif /* CONFIG_IS_ENABLED(DM_USB) */
-- 
2.17.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v8 08/10] lmb: remove unused extern declaration

2018-12-17 Thread Simon Goldschmidt
lmb.h includes an extern declaration of "struct lmb lmb;" which
is not used anywhere, so remove it.

Signed-off-by: Simon Goldschmidt 
---

Changes in v8: None
Changes in v7: None
Changes in v6: None
Changes in v5: None
Changes in v4: None
Changes in v2:
- this patch is new in v2

 include/lmb.h | 2 --
 1 file changed, 2 deletions(-)

diff --git a/include/lmb.h b/include/lmb.h
index 62da85e716..1bb003e35e 100644
--- a/include/lmb.h
+++ b/include/lmb.h
@@ -28,8 +28,6 @@ struct lmb {
struct lmb_region reserved;
 };
 
-extern struct lmb lmb;
-
 extern void lmb_init(struct lmb *lmb);
 extern void lmb_init_and_reserve(struct lmb *lmb, phys_addr_t base,
 phys_size_t size, void *fdt_blob);
-- 
2.17.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v8 06/10] fs: prevent overwriting reserved memory

2018-12-17 Thread Simon Goldschmidt
This fixes CVE-2018-18440 ("insufficient boundary checks in filesystem
image load") by using lmb to check the load size of a file against
reserved memory addresses.

Signed-off-by: Simon Goldschmidt 
---

Changes in v8: None
Changes in v7: None
Changes in v6:
- fixed NULL pointer access in 'fdt_blob' passed to
  'boot_fdt_add_mem_rsv_regions'

Changes in v5: None
Changes in v4: None
Changes in v2: None

 fs/fs.c   | 56 ---
 include/lmb.h |  2 ++
 lib/lmb.c | 13 
 3 files changed, 68 insertions(+), 3 deletions(-)

diff --git a/fs/fs.c b/fs/fs.c
index cb265174e2..400aa921a7 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -429,13 +429,57 @@ int fs_size(const char *filename, loff_t *size)
return ret;
 }
 
-int fs_read(const char *filename, ulong addr, loff_t offset, loff_t len,
-   loff_t *actread)
+#ifdef CONFIG_LMB
+/* Check if a file may be read to the given address */
+static int fs_read_lmb_check(const char *filename, ulong addr, loff_t offset,
+loff_t len, struct fstype_info *info)
+{
+   struct lmb lmb;
+   int ret;
+   loff_t size;
+   loff_t read_len;
+
+   /* get the actual size of the file */
+   ret = info->size(filename, );
+   if (ret)
+   return ret;
+   if (offset >= size) {
+   /* offset >= EOF, no bytes will be written */
+   return 0;
+   }
+   read_len = size - offset;
+
+   /* limit to 'len' if it is smaller */
+   if (len && len < read_len)
+   read_len = len;
+
+   lmb_init_and_reserve(, gd->bd->bi_dram[0].start,
+gd->bd->bi_dram[0].size, (void *)gd->fdt_blob);
+   lmb_dump_all();
+
+   if (lmb_alloc_addr(, addr, read_len) == addr)
+   return 0;
+
+   printf("** Reading file would overwrite reserved memory **\n");
+   return -1;
+}
+#endif
+
+static int _fs_read(const char *filename, ulong addr, loff_t offset, loff_t 
len,
+   int do_lmb_check, loff_t *actread)
 {
struct fstype_info *info = fs_get_info(fs_type);
void *buf;
int ret;
 
+#ifdef CONFIG_LMB
+   if (do_lmb_check) {
+   ret = fs_read_lmb_check(filename, addr, offset, len, info);
+   if (ret)
+   return ret;
+   }
+#endif
+
/*
 * We don't actually know how many bytes are being read, since len==0
 * means read the whole file.
@@ -452,6 +496,12 @@ int fs_read(const char *filename, ulong addr, loff_t 
offset, loff_t len,
return ret;
 }
 
+int fs_read(const char *filename, ulong addr, loff_t offset, loff_t len,
+   loff_t *actread)
+{
+   return _fs_read(filename, addr, offset, len, 0, actread);
+}
+
 int fs_write(const char *filename, ulong addr, loff_t offset, loff_t len,
 loff_t *actwrite)
 {
@@ -622,7 +672,7 @@ int do_load(cmd_tbl_t *cmdtp, int flag, int argc, char * 
const argv[],
pos = 0;
 
time = get_timer(0);
-   ret = fs_read(filename, addr, pos, bytes, _read);
+   ret = _fs_read(filename, addr, pos, bytes, 1, _read);
time = get_timer(time);
if (ret < 0)
return 1;
diff --git a/include/lmb.h b/include/lmb.h
index 7d7e2a78dc..62da85e716 100644
--- a/include/lmb.h
+++ b/include/lmb.h
@@ -31,6 +31,8 @@ struct lmb {
 extern struct lmb lmb;
 
 extern void lmb_init(struct lmb *lmb);
+extern void lmb_init_and_reserve(struct lmb *lmb, phys_addr_t base,
+phys_size_t size, void *fdt_blob);
 extern long lmb_add(struct lmb *lmb, phys_addr_t base, phys_size_t size);
 extern long lmb_reserve(struct lmb *lmb, phys_addr_t base, phys_size_t size);
 extern phys_addr_t lmb_alloc(struct lmb *lmb, phys_size_t size, ulong align);
diff --git a/lib/lmb.c b/lib/lmb.c
index e380a0a722..3407705fa7 100644
--- a/lib/lmb.c
+++ b/lib/lmb.c
@@ -98,6 +98,19 @@ void lmb_init(struct lmb *lmb)
lmb->reserved.size = 0;
 }
 
+/* Initialize the struct, add memory and call arch/board reserve functions */
+void lmb_init_and_reserve(struct lmb *lmb, phys_addr_t base, phys_size_t size,
+ void *fdt_blob)
+{
+   lmb_init(lmb);
+   lmb_add(lmb, base, size);
+   arch_lmb_reserve(lmb);
+   board_lmb_reserve(lmb);
+
+   if (IMAGE_ENABLE_OF_LIBFDT && fdt_blob)
+   boot_fdt_add_mem_rsv_regions(lmb, fdt_blob);
+}
+
 /* This routine called with relocation disabled. */
 static long lmb_add_region(struct lmb_region *rgn, phys_addr_t base, 
phys_size_t size)
 {
-- 
2.17.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v8 09/10] tftp: prevent overwriting reserved memory

2018-12-17 Thread Simon Goldschmidt
This fixes CVE-2018-18439 ("insufficient boundary checks in network
image boot") by using lmb to check for a valid range to store
received blocks.

Signed-off-by: Simon Goldschmidt 
---

Changes in v8: None
Changes in v7:
- fix compiling without CONFIG_LMB

Changes in v6: None
Changes in v5: None
Changes in v4:
- this was patch 8, is now patch 7
- lines changed because v3 patch 7 got removed and MCAST_TFTP still
  exists

Changes in v2:
- this patch is new in v2

 net/tftp.c | 73 ++
 1 file changed, 63 insertions(+), 10 deletions(-)

diff --git a/net/tftp.c b/net/tftp.c
index 68ffd81414..a9335b1b7e 100644
--- a/net/tftp.c
+++ b/net/tftp.c
@@ -17,6 +17,8 @@
 #include 
 #endif
 
+DECLARE_GLOBAL_DATA_PTR;
+
 /* Well known TFTP port # */
 #define WELL_KNOWN_PORT69
 /* Millisecs to timeout for lost pkt */
@@ -81,6 +83,10 @@ static ulong tftp_block_wrap;
 /* memory offset due to wrapping */
 static ulong   tftp_block_wrap_offset;
 static int tftp_state;
+static ulong   tftp_load_addr;
+#ifdef CONFIG_LMB
+static ulong   tftp_load_size;
+#endif
 #ifdef CONFIG_TFTP_TSIZE
 /* The file size reported by the server */
 static int tftp_tsize;
@@ -164,10 +170,11 @@ static void mcast_cleanup(void)
 
 #endif /* CONFIG_MCAST_TFTP */
 
-static inline void store_block(int block, uchar *src, unsigned len)
+static inline int store_block(int block, uchar *src, unsigned int len)
 {
ulong offset = block * tftp_block_size + tftp_block_wrap_offset;
ulong newsize = offset + len;
+   ulong store_addr = tftp_load_addr + offset;
 #ifdef CONFIG_SYS_DIRECT_FLASH_TFTP
int i, rc = 0;
 
@@ -175,24 +182,32 @@ static inline void store_block(int block, uchar *src, 
unsigned len)
/* start address in flash? */
if (flash_info[i].flash_id == FLASH_UNKNOWN)
continue;
-   if (load_addr + offset >= flash_info[i].start[0]) {
+   if (store_addr >= flash_info[i].start[0]) {
rc = 1;
break;
}
}
 
if (rc) { /* Flash is destination for this packet */
-   rc = flash_write((char *)src, (ulong)(load_addr+offset), len);
+   rc = flash_write((char *)src, store_addr, len);
if (rc) {
flash_perror(rc);
-   net_set_state(NETLOOP_FAIL);
-   return;
+   return rc;
}
} else
 #endif /* CONFIG_SYS_DIRECT_FLASH_TFTP */
{
-   void *ptr = map_sysmem(load_addr + offset, len);
-
+   void *ptr;
+
+#ifdef CONFIG_LMB
+   if (store_addr < tftp_load_addr ||
+   store_addr + len > tftp_load_addr + tftp_load_size) {
+   puts("\nTFTP error: ");
+   puts("trying to overwrite reserved memory...\n");
+   return -1;
+   }
+#endif
+   ptr = map_sysmem(store_addr, len);
memcpy(ptr, src, len);
unmap_sysmem(ptr);
}
@@ -203,6 +218,8 @@ static inline void store_block(int block, uchar *src, 
unsigned len)
 
if (net_boot_file_size < newsize)
net_boot_file_size = newsize;
+
+   return 0;
 }
 
 /* Clear our state ready for a new transfer */
@@ -606,7 +623,11 @@ static void tftp_handler(uchar *pkt, unsigned dest, struct 
in_addr sip,
timeout_count_max = tftp_timeout_count_max;
net_set_timeout_handler(timeout_ms, tftp_timeout_handler);
 
-   store_block(tftp_cur_block - 1, pkt + 2, len);
+   if (store_block(tftp_cur_block - 1, pkt + 2, len)) {
+   eth_halt();
+   net_set_state(NETLOOP_FAIL);
+   break;
+   }
 
/*
 *  Acknowledge the block just received, which will prompt
@@ -695,6 +716,25 @@ static void tftp_timeout_handler(void)
}
 }
 
+/* Initialize tftp_load_addr and tftp_load_size from load_addr and lmb */
+static int tftp_init_load_addr(void)
+{
+#ifdef CONFIG_LMB
+   struct lmb lmb;
+   phys_size_t max_size;
+
+   lmb_init_and_reserve(, gd->bd->bi_dram[0].start,
+gd->bd->bi_dram[0].size, (void *)gd->fdt_blob);
+
+   max_size = lmb_get_unreserved_size(, load_addr);
+   if (!max_size)
+   return -1;
+
+   tftp_load_size = max_size;
+#endif
+   tftp_load_addr = load_addr;
+   return 0;
+}
 
 void tftp_start(enum proto_t protocol)
 {
@@ -791,7 +831,14 @@ void tftp_start(enum proto_t protocol)
} else
 #endif
{
-   printf("Load address: 0x%lx\n", load_addr);
+   if (tftp_init_load_addr()) {
+   eth_halt();
+   net_set_state(NETLOOP_FAIL);
+   puts("\nTFTP 

[U-Boot] [PATCH v8 10/10] arm: bootm: fix sp detection at end of address range

2018-12-17 Thread Simon Goldschmidt
This fixes  'arch_lmb_reserve()' for ARM that tries to detect in which
DRAM bank 'sp' is in.

This code failed if a bank was at the end of physical address range
(i.e. size + length overflowed to 0).

To fix this, calculate 'bank_end' as 'size + length - 1' so that such
banks end at 0x, not 0.

Fixes: 15751403b6 ("ARM: bootm: don't assume sp is in DRAM bank 0")
Reported-by: Frank Wunderlich 
Signed-off-by: Simon Goldschmidt 
---

Changes in v8:
- this patch is new in v8

Changes in v7: None
Changes in v6: None
Changes in v5: None
Changes in v4: None
Changes in v2: None

 arch/arm/lib/bootm.c | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/arch/arm/lib/bootm.c b/arch/arm/lib/bootm.c
index c3c1d2fdfa..e9a333af0e 100644
--- a/arch/arm/lib/bootm.c
+++ b/arch/arm/lib/bootm.c
@@ -64,13 +64,14 @@ void arch_lmb_reserve(struct lmb *lmb)
/* adjust sp by 4K to be safe */
sp -= 4096;
for (bank = 0; bank < CONFIG_NR_DRAM_BANKS; bank++) {
-   if (sp < gd->bd->bi_dram[bank].start)
+   if (!bi_dram[bank].size || sp < gd->bd->bi_dram[bank].start)
continue;
+   /* Watch out for RAM at end of address space! */
bank_end = gd->bd->bi_dram[bank].start +
-   gd->bd->bi_dram[bank].size;
-   if (sp >= bank_end)
+   gd->bd->bi_dram[bank].size - 1;
+   if (sp > bank_end)
continue;
-   lmb_reserve(lmb, sp, bank_end - sp);
+   lmb_reserve(lmb, sp, bank_end - sp + 1);
break;
}
 }
-- 
2.17.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v8 07/10] bootm: use new common function lmb_init_and_reserve

2018-12-17 Thread Simon Goldschmidt
This reduces duplicate code only.

Signed-off-by: Simon Goldschmidt 
---

Changes in v8: None
Changes in v7: None
Changes in v6: None
Changes in v5: None
Changes in v4: None
Changes in v2: None

 common/bootm.c | 8 ++--
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/common/bootm.c b/common/bootm.c
index 8bf84ebcb7..31e4f0f794 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -56,15 +56,11 @@ static void boot_start_lmb(bootm_headers_t *images)
ulong   mem_start;
phys_size_t mem_size;
 
-   lmb_init(>lmb);
-
mem_start = env_get_bootm_low();
mem_size = env_get_bootm_size();
 
-   lmb_add(>lmb, (phys_addr_t)mem_start, mem_size);
-
-   arch_lmb_reserve(>lmb);
-   board_lmb_reserve(>lmb);
+   lmb_init_and_reserve(>lmb, (phys_addr_t)mem_start, mem_size,
+NULL);
 }
 #else
 #define lmb_reserve(lmb, base, size)
-- 
2.17.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v8 05/10] lib: lmb: extend lmb for checks at load time

2018-12-17 Thread Simon Goldschmidt
This adds two new functions, lmb_alloc_addr and
lmb_get_unreserved_size.

lmb_alloc_addr behaves like lmb_alloc, but it tries to allocate a
pre-specified address range. Unlike lmb_reserve, this address range
must be inside one of the memory ranges that has been set up with
lmb_add.

lmb_get_unreserved_size returns the number of bytes that can be
used up to the next reserved region or the end of valid ram. This
can be 0 if the address passed is reserved.

Added test for these new functions.

Signed-off-by: Simon Goldschmidt 
---

Changes in v8: None
Changes in v7: None
Changes in v6: None
Changes in v5:
- fixed lmb_alloc_addr when resulting reserved ranges get combined
- added test for these new functions

Changes in v4: None
Changes in v2:
- added lmb_get_unreserved_size() for tftp

 include/lmb.h  |   3 +
 lib/lmb.c  |  53 +
 test/lib/lmb.c | 202 +
 3 files changed, 258 insertions(+)

diff --git a/include/lmb.h b/include/lmb.h
index f04d058093..7d7e2a78dc 100644
--- a/include/lmb.h
+++ b/include/lmb.h
@@ -38,6 +38,9 @@ extern phys_addr_t lmb_alloc_base(struct lmb *lmb, 
phys_size_t size, ulong align
phys_addr_t max_addr);
 extern phys_addr_t __lmb_alloc_base(struct lmb *lmb, phys_size_t size, ulong 
align,
  phys_addr_t max_addr);
+extern phys_addr_t lmb_alloc_addr(struct lmb *lmb, phys_addr_t base,
+ phys_size_t size);
+extern phys_size_t lmb_get_unreserved_size(struct lmb *lmb, phys_addr_t addr);
 extern int lmb_is_reserved(struct lmb *lmb, phys_addr_t addr);
 extern long lmb_free(struct lmb *lmb, phys_addr_t base, phys_size_t size);
 
diff --git a/lib/lmb.c b/lib/lmb.c
index cd297f8202..e380a0a722 100644
--- a/lib/lmb.c
+++ b/lib/lmb.c
@@ -313,6 +313,59 @@ phys_addr_t __lmb_alloc_base(struct lmb *lmb, phys_size_t 
size, ulong align, phy
return 0;
 }
 
+/*
+ * Try to allocate a specific address range: must be in defined memory but not
+ * reserved
+ */
+phys_addr_t lmb_alloc_addr(struct lmb *lmb, phys_addr_t base, phys_size_t size)
+{
+   long j;
+
+   /* Check if the requested address is in one of the memory regions */
+   j = lmb_overlaps_region(>memory, base, size);
+   if (j >= 0) {
+   /*
+* Check if the requested end address is in the same memory
+* region we found.
+*/
+   if (lmb_addrs_overlap(lmb->memory.region[j].base,
+ lmb->memory.region[j].size, base + size -
+ 1, 1)) {
+   /* ok, reserve the memory */
+   if (lmb_reserve(lmb, base, size) >= 0)
+   return base;
+   }
+   }
+   return 0;
+}
+
+/* Return number of bytes from a given address that are free */
+phys_size_t lmb_get_unreserved_size(struct lmb *lmb, phys_addr_t addr)
+{
+   int i;
+   long j;
+
+   /* check if the requested address is in the memory regions */
+   j = lmb_overlaps_region(>memory, addr, 1);
+   if (j >= 0) {
+   for (i = 0; i < lmb->reserved.cnt; i++) {
+   if (addr < lmb->reserved.region[i].base) {
+   /* first reserved range > requested address */
+   return lmb->reserved.region[i].base - addr;
+   }
+   if (lmb->reserved.region[i].base +
+   lmb->reserved.region[i].size > addr) {
+   /* requested addr is in this reserved range */
+   return 0;
+   }
+   }
+   /* if we come here: no reserved ranges above requested addr */
+   return lmb->memory.region[lmb->memory.cnt - 1].base +
+  lmb->memory.region[lmb->memory.cnt - 1].size - addr;
+   }
+   return 0;
+}
+
 int lmb_is_reserved(struct lmb *lmb, phys_addr_t addr)
 {
int i;
diff --git a/test/lib/lmb.c b/test/lib/lmb.c
index e6acb70e76..058d3c332b 100644
--- a/test/lib/lmb.c
+++ b/test/lib/lmb.c
@@ -397,3 +397,205 @@ static int lib_test_lmb_overlapping_reserve(struct 
unit_test_state *uts)
 
 DM_TEST(lib_test_lmb_overlapping_reserve,
DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
+
+/*
+ * Simulate 512 MiB RAM, reserve 3 blocks, allocate addresses in between.
+ * Expect addresses outside the memory range to fail.
+ */
+static int test_alloc_addr(struct unit_test_state *uts, const phys_addr_t ram)
+{
+   const phys_size_t ram_size = 0x2000;
+   const phys_addr_t ram_end = ram + ram_size;
+   const phys_size_t alloc_addr_a = ram + 0x800;
+   const phys_size_t alloc_addr_b = ram + 0x800 * 2;
+   const phys_size_t alloc_addr_c = ram + 0x800 * 3;
+   struct lmb lmb;
+   long ret;
+   phys_addr_t a, b, c, d, 

[U-Boot] [PATCH v8 04/10] fdt: parse "reserved-memory" for memory reservation

2018-12-17 Thread Simon Goldschmidt
boot_fdt_add_mem_rsv_regions() adds reserved memory sections to an lmb
struct. Currently, it only parses regions described by /memreserve/
entries.

Extend this to the more commonly used scheme of the "reserved-memory"
node.

Signed-off-by: Simon Goldschmidt 
---

Changes in v8: None
Changes in v7:
- fix compiling without CONFIG_FIT

Changes in v6:
- fix compiling without OF_CONTROL

Changes in v5: None
Changes in v4:
- fixed invalid 'if' statement without braces in boot_fdt_reserve_region

Changes in v2:
- this patch is new in v2

 common/image-fdt.c | 53 +++---
 lib/Makefile   |  1 +
 2 files changed, 46 insertions(+), 8 deletions(-)

diff --git a/common/image-fdt.c b/common/image-fdt.c
index 95748f0ae1..5c0d6db3fe 100644
--- a/common/image-fdt.c
+++ b/common/image-fdt.c
@@ -10,6 +10,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -67,30 +68,66 @@ static const image_header_t *image_get_fdt(ulong fdt_addr)
 }
 #endif
 
+static void boot_fdt_reserve_region(struct lmb *lmb, uint64_t addr,
+   uint64_t size)
+{
+   int ret;
+
+   ret = lmb_reserve(lmb, addr, size);
+   if (!ret) {
+   debug("   reserving fdt memory region: addr=%llx size=%llx\n",
+ (unsigned long long)addr, (unsigned long long)size);
+   } else {
+   puts("ERROR: reserving fdt memory region failed ");
+   printf("(addr=%llx size=%llx)\n",
+  (unsigned long long)addr, (unsigned long long)size);
+   }
+}
+
 /**
- * boot_fdt_add_mem_rsv_regions - Mark the memreserve sections as unusable
+ * boot_fdt_add_mem_rsv_regions - Mark the memreserve and reserved-memory
+ * sections as unusable
  * @lmb: pointer to lmb handle, will be used for memory mgmt
  * @fdt_blob: pointer to fdt blob base address
  *
- * Adds the memreserve regions in the dtb to the lmb block.  Adding the
- * memreserve regions prevents u-boot from using them to store the initrd
- * or the fdt blob.
+ * Adds the and reserved-memorymemreserve regions in the dtb to the lmb block.
+ * Adding the memreserve regions prevents u-boot from using them to store the
+ * initrd or the fdt blob.
  */
 void boot_fdt_add_mem_rsv_regions(struct lmb *lmb, void *fdt_blob)
 {
uint64_t addr, size;
-   int i, total;
+   int i, total, ret;
+   int nodeoffset, subnode;
+   struct fdt_resource res;
 
if (fdt_check_header(fdt_blob) != 0)
return;
 
+   /* process memreserve sections */
total = fdt_num_mem_rsv(fdt_blob);
for (i = 0; i < total; i++) {
if (fdt_get_mem_rsv(fdt_blob, i, , ) != 0)
continue;
-   printf("   reserving fdt memory region: addr=%llx size=%llx\n",
-  (unsigned long long)addr, (unsigned long long)size);
-   lmb_reserve(lmb, addr, size);
+   boot_fdt_reserve_region(lmb, addr, size);
+   }
+
+   /* process reserved-memory */
+   nodeoffset = fdt_subnode_offset(fdt_blob, 0, "reserved-memory");
+   if (nodeoffset >= 0) {
+   subnode = fdt_first_subnode(fdt_blob, nodeoffset);
+   while (subnode >= 0) {
+   /* check if this subnode has a reg property */
+   ret = fdt_get_resource(fdt_blob, subnode, "reg", 0,
+  );
+   if (!ret) {
+   addr = res.start;
+   size = res.end - res.start + 1;
+   boot_fdt_reserve_region(lmb, addr, size);
+   }
+
+   subnode = fdt_next_subnode(fdt_blob, subnode);
+   }
}
 }
 
diff --git a/lib/Makefile b/lib/Makefile
index a6dd928a92..358789ff12 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -30,6 +30,7 @@ obj-y += crc7.o
 obj-y += crc8.o
 obj-y += crc16.o
 obj-$(CONFIG_ERRNO_STR) += errno_str.o
+obj-$(CONFIG_OF_LIBFDT) += fdtdec.o
 obj-$(CONFIG_FIT) += fdtdec_common.o
 obj-$(CONFIG_TEST_FDTDEC) += fdtdec_test.o
 obj-$(CONFIG_GZIP_COMPRESSED) += gzip.o
-- 
2.17.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v8 03/10] lib: lmb: reserving overlapping regions should fail

2018-12-17 Thread Simon Goldschmidt
lmb_add_region handles overlapping regions wrong: instead of merging
or rejecting to add a new reserved region that overlaps an existing
one, it just adds the new region.

Since internally the same function is used for lmb_alloc, change
lmb_add_region to reject overlapping regions.

Also, to keep reserved memory correct after 'free', reserved entries
created by allocating memory must not set their size to a multiple
of alignment but to the original size. This ensures the reserved
region is completely removed when the caller calls 'lmb_free', as
this one takes the same size as passed to 'lmb_alloc' etc.

Add test to assert this.

Signed-off-by: Simon Goldschmidt 
---

Changes in v8: None
Changes in v7:
- add braces around if/else with macros accross more than one line

Changes in v6:
- fix size of allocated regions that need alignment padding

Changes in v5:
- added a test for this bug

Changes in v4: None
Changes in v2: None

 lib/lmb.c  | 11 +++---
 test/lib/lmb.c | 95 +-
 2 files changed, 91 insertions(+), 15 deletions(-)

diff --git a/lib/lmb.c b/lib/lmb.c
index 6d3dcf4e09..cd297f8202 100644
--- a/lib/lmb.c
+++ b/lib/lmb.c
@@ -131,6 +131,9 @@ static long lmb_add_region(struct lmb_region *rgn, 
phys_addr_t base, phys_size_t
rgn->region[i].size += size;
coalesced++;
break;
+   } else if (lmb_addrs_overlap(base, size, rgnbase, rgnsize)) {
+   /* regions overlap */
+   return -1;
}
}
 
@@ -269,11 +272,6 @@ static phys_addr_t lmb_align_down(phys_addr_t addr, 
phys_size_t size)
return addr & ~(size - 1);
 }
 
-static phys_addr_t lmb_align_up(phys_addr_t addr, ulong size)
-{
-   return (addr + (size - 1)) & ~(size - 1);
-}
-
 phys_addr_t __lmb_alloc_base(struct lmb *lmb, phys_size_t size, ulong align, 
phys_addr_t max_addr)
 {
long i, j;
@@ -302,8 +300,7 @@ phys_addr_t __lmb_alloc_base(struct lmb *lmb, phys_size_t 
size, ulong align, phy
if (j < 0) {
/* This area isn't reserved, take it */
if (lmb_add_region(>reserved, base,
-   lmb_align_up(size,
-   align)) < 0)
+  size) < 0)
return 0;
return base;
}
diff --git a/test/lib/lmb.c b/test/lib/lmb.c
index fb7ca45ef1..e6acb70e76 100644
--- a/test/lib/lmb.c
+++ b/test/lib/lmb.c
@@ -227,13 +227,16 @@ static int lib_test_lmb_big(struct unit_test_state *uts)
 DM_TEST(lib_test_lmb_big, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
 
 /* Simulate 512 MiB RAM, allocate a block without previous reservation */
-static int test_noreserved(struct unit_test_state *uts, const phys_addr_t ram)
+static int test_noreserved(struct unit_test_state *uts, const phys_addr_t ram,
+  const phys_addr_t alloc_size, const ulong align)
 {
const phys_size_t ram_size = 0x2000;
const phys_addr_t ram_end = ram + ram_size;
struct lmb lmb;
long ret;
phys_addr_t a, b;
+   const phys_addr_t alloc_size_aligned = (alloc_size + align - 1) &
+   ~(align - 1);
 
/* check for overflow */
ut_assert(ram_end == 0 || ram_end > ram);
@@ -242,20 +245,43 @@ static int test_noreserved(struct unit_test_state *uts, 
const phys_addr_t ram)
 
ret = lmb_add(, ram, ram_size);
ut_asserteq(ret, 0);
+   ASSERT_LMB(, ram, ram_size, 0, 0, 0, 0, 0, 0, 0);
 
/* allocate a block */
-   a = lmb_alloc(, 4, 1);
+   a = lmb_alloc(, alloc_size, align);
ut_assert(a != 0);
-   /* and free it */
-   ret = lmb_free(, a, 4);
+   ASSERT_LMB(, ram, ram_size, 1, ram + ram_size - alloc_size_aligned,
+  alloc_size, 0, 0, 0, 0);
+   /* allocate another block */
+   b = lmb_alloc(, alloc_size, align);
+   ut_assert(b != 0);
+   if (alloc_size == alloc_size_aligned) {
+   ASSERT_LMB(, ram, ram_size, 1, ram + ram_size -
+  (alloc_size_aligned * 2), alloc_size * 2, 0, 0, 0,
+  0);
+   } else {
+   ASSERT_LMB(, ram, ram_size, 2, ram + ram_size -
+  (alloc_size_aligned * 2), alloc_size, ram + ram_size
+  - alloc_size_aligned, alloc_size, 0, 0);
+   }
+   /* and free them */
+   ret = lmb_free(, b, alloc_size);
ut_asserteq(ret, 0);
+   ASSERT_LMB(, ram, ram_size, 1, ram + ram_size - alloc_size_aligned,
+  alloc_size, 0, 0, 0, 0);
+   ret = lmb_free(, a, alloc_size);
+   ut_asserteq(ret, 0);
+   ASSERT_LMB(, ram, ram_size, 0, 0, 0, 0, 0, 0, 

[U-Boot] [PATCH v8 02/10] lmb: fix allocation at end of address range

2018-12-17 Thread Simon Goldschmidt
The lmb code fails if base + size of RAM overflows to zero.

Fix this by calculating end as 'base + size - 1' instead of 'base + size'
where appropriate.

Added tests to assert this is fixed.

Signed-off-by: Simon Goldschmidt 
---

Changes in v8: None
Changes in v7: None
Changes in v6: None
Changes in v5:
- this patch is new in v5

Changes in v4: None
Changes in v2: None

 lib/lmb.c  | 29 -
 test/lib/lmb.c | 29 ++---
 2 files changed, 38 insertions(+), 20 deletions(-)

diff --git a/lib/lmb.c b/lib/lmb.c
index 1705417348..6d3dcf4e09 100644
--- a/lib/lmb.c
+++ b/lib/lmb.c
@@ -43,7 +43,10 @@ void lmb_dump_all(struct lmb *lmb)
 static long lmb_addrs_overlap(phys_addr_t base1,
phys_size_t size1, phys_addr_t base2, phys_size_t size2)
 {
-   return ((base1 < (base2+size2)) && (base2 < (base1+size1)));
+   const phys_addr_t base1_end = base1 + size1 - 1;
+   const phys_addr_t base2_end = base2 + size2 - 1;
+
+   return ((base1 <= base2_end) && (base2 <= base1_end));
 }
 
 static long lmb_addrs_adjacent(phys_addr_t base1, phys_size_t size1,
@@ -89,18 +92,9 @@ static void lmb_coalesce_regions(struct lmb_region *rgn,
 
 void lmb_init(struct lmb *lmb)
 {
-   /* Create a dummy zero size LMB which will get coalesced away later.
-* This simplifies the lmb_add() code below...
-*/
-   lmb->memory.region[0].base = 0;
-   lmb->memory.region[0].size = 0;
-   lmb->memory.cnt = 1;
+   lmb->memory.cnt = 0;
lmb->memory.size = 0;
-
-   /* Ditto. */
-   lmb->reserved.region[0].base = 0;
-   lmb->reserved.region[0].size = 0;
-   lmb->reserved.cnt = 1;
+   lmb->reserved.cnt = 0;
lmb->reserved.size = 0;
 }
 
@@ -110,9 +104,10 @@ static long lmb_add_region(struct lmb_region *rgn, 
phys_addr_t base, phys_size_t
unsigned long coalesced = 0;
long adjacent, i;
 
-   if ((rgn->cnt == 1) && (rgn->region[0].size == 0)) {
+   if (rgn->cnt == 0) {
rgn->region[0].base = base;
rgn->region[0].size = size;
+   rgn->cnt = 1;
return 0;
}
 
@@ -183,7 +178,7 @@ long lmb_free(struct lmb *lmb, phys_addr_t base, 
phys_size_t size)
 {
struct lmb_region *rgn = &(lmb->reserved);
phys_addr_t rgnbegin, rgnend;
-   phys_addr_t end = base + size;
+   phys_addr_t end = base + size - 1;
int i;
 
rgnbegin = rgnend = 0; /* supress gcc warnings */
@@ -191,7 +186,7 @@ long lmb_free(struct lmb *lmb, phys_addr_t base, 
phys_size_t size)
/* Find the region where (base, size) belongs to */
for (i=0; i < rgn->cnt; i++) {
rgnbegin = rgn->region[i].base;
-   rgnend = rgnbegin + rgn->region[i].size;
+   rgnend = rgnbegin + rgn->region[i].size - 1;
 
if ((rgnbegin <= base) && (end <= rgnend))
break;
@@ -209,7 +204,7 @@ long lmb_free(struct lmb *lmb, phys_addr_t base, 
phys_size_t size)
 
/* Check to see if region is matching at the front */
if (rgnbegin == base) {
-   rgn->region[i].base = end;
+   rgn->region[i].base = end + 1;
rgn->region[i].size -= size;
return 0;
}
@@ -225,7 +220,7 @@ long lmb_free(struct lmb *lmb, phys_addr_t base, 
phys_size_t size)
 * beginging of the hole and add the region after hole.
 */
rgn->region[i].size = base - rgn->region[i].base;
-   return lmb_add_region(rgn, end, rgnend - end);
+   return lmb_add_region(rgn, end + 1, rgnend - end);
 }
 
 long lmb_reserve(struct lmb *lmb, phys_addr_t base, phys_size_t size)
diff --git a/test/lib/lmb.c b/test/lib/lmb.c
index dd7ba14b34..fb7ca45ef1 100644
--- a/test/lib/lmb.c
+++ b/test/lib/lmb.c
@@ -146,8 +146,15 @@ static int test_multi_alloc_512mb(struct unit_test_state 
*uts,
 /* Create a memory region with one reserved region and allocate */
 static int lib_test_lmb_simple(struct unit_test_state *uts)
 {
+   int ret;
+
/* simulate 512 MiB RAM beginning at 1GiB */
-   return test_multi_alloc_512mb(uts, 0x4000);
+   ret = test_multi_alloc_512mb(uts, 0x4000);
+   if (ret)
+   return ret;
+
+   /* simulate 512 MiB RAM beginning at 1.5GiB */
+   return test_multi_alloc_512mb(uts, 0xE000);
 }
 
 DM_TEST(lib_test_lmb_simple, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
@@ -206,7 +213,15 @@ static int test_bigblock(struct unit_test_state *uts, 
const phys_addr_t ram)
 
 static int lib_test_lmb_big(struct unit_test_state *uts)
 {
-   return test_bigblock(uts, 0x4000);
+   int ret;
+
+   /* simulate 512 MiB RAM beginning at 1GiB */
+   ret = test_bigblock(uts, 0x4000);
+   if (ret)
+   return ret;
+
+   /* simulate 512 MiB RAM beginning at 1.5GiB */
+   return test_bigblock(uts, 0xE000);
 }
 
 DM_TEST(lib_test_lmb_big, 

[U-Boot] [PATCH v8 01/10] test: add test for lib/lmb.c

2018-12-17 Thread Simon Goldschmidt
Add basic tests for the lmb memory allocation code used to reserve and
allocate memory during boot.

Signed-off-by: Simon Goldschmidt 
---

Changes in v8: None
Changes in v7: None
Changes in v6: None
Changes in v5:
- this patch is new in v5

Changes in v4: None
Changes in v2: None

 test/lib/Makefile |   1 +
 test/lib/lmb.c| 297 ++
 2 files changed, 298 insertions(+)
 create mode 100644 test/lib/lmb.c

diff --git a/test/lib/Makefile b/test/lib/Makefile
index ea68fae566..5a636aac74 100644
--- a/test/lib/Makefile
+++ b/test/lib/Makefile
@@ -3,3 +3,4 @@
 # (C) Copyright 2018
 # Mario Six, Guntermann & Drunck GmbH, mario@gdsys.cc
 obj-y += hexdump.o
+obj-y += lmb.o
diff --git a/test/lib/lmb.c b/test/lib/lmb.c
new file mode 100644
index 00..dd7ba14b34
--- /dev/null
+++ b/test/lib/lmb.c
@@ -0,0 +1,297 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2018 Simon Goldschmidt
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+static int check_lmb(struct unit_test_state *uts, struct lmb *lmb,
+phys_addr_t ram_base, phys_size_t ram_size,
+unsigned long num_reserved,
+phys_addr_t base1, phys_size_t size1,
+phys_addr_t base2, phys_size_t size2,
+phys_addr_t base3, phys_size_t size3)
+{
+   ut_asserteq(lmb->memory.cnt, 1);
+   ut_asserteq(lmb->memory.region[0].base, ram_base);
+   ut_asserteq(lmb->memory.region[0].size, ram_size);
+
+   ut_asserteq(lmb->reserved.cnt, num_reserved);
+   if (num_reserved > 0) {
+   ut_asserteq(lmb->reserved.region[0].base, base1);
+   ut_asserteq(lmb->reserved.region[0].size, size1);
+   }
+   if (num_reserved > 1) {
+   ut_asserteq(lmb->reserved.region[1].base, base2);
+   ut_asserteq(lmb->reserved.region[1].size, size2);
+   }
+   if (num_reserved > 2) {
+   ut_asserteq(lmb->reserved.region[2].base, base3);
+   ut_asserteq(lmb->reserved.region[2].size, size3);
+   }
+   return 0;
+}
+
+#define ASSERT_LMB(lmb, ram_base, ram_size, num_reserved, base1, size1, \
+  base2, size2, base3, size3) \
+  ut_assert(!check_lmb(uts, lmb, ram_base, ram_size, \
+num_reserved, base1, size1, base2, size2, base3, \
+size3))
+
+/*
+ * Test helper function that reserves 64 KiB somewhere in the simulated RAM and
+ * then does some alloc + free tests.
+ */
+static int test_multi_alloc(struct unit_test_state *uts,
+   const phys_addr_t ram, const phys_size_t ram_size,
+   const phys_addr_t alloc_64k_addr)
+{
+   const phys_addr_t ram_end = ram + ram_size;
+   const phys_addr_t alloc_64k_end = alloc_64k_addr + 0x1;
+
+   struct lmb lmb;
+   long ret;
+   phys_addr_t a, a2, b, b2, c, d;
+
+   /* check for overflow */
+   ut_assert(ram_end == 0 || ram_end > ram);
+   ut_assert(alloc_64k_end > alloc_64k_addr);
+   /* check input addresses + size */
+   ut_assert(alloc_64k_addr >= ram + 8);
+   ut_assert(alloc_64k_end <= ram_end - 8);
+
+   lmb_init();
+
+   ret = lmb_add(, ram, ram_size);
+   ut_asserteq(ret, 0);
+
+   /* reserve 64KiB somewhere */
+   ret = lmb_reserve(, alloc_64k_addr, 0x1);
+   ut_asserteq(ret, 0);
+   ASSERT_LMB(, ram, ram_size, 1, alloc_64k_addr, 0x1,
+  0, 0, 0, 0);
+
+   /* allocate somewhere, should be at the end of RAM */
+   a = lmb_alloc(, 4, 1);
+   ut_asserteq(a, ram_end - 4);
+   ASSERT_LMB(, ram, ram_size, 2, alloc_64k_addr, 0x1,
+  ram_end - 4, 4, 0, 0);
+   /* alloc below end of reserved region -> below reserved region */
+   b = lmb_alloc_base(, 4, 1, alloc_64k_end);
+   ut_asserteq(b, alloc_64k_addr - 4);
+   ASSERT_LMB(, ram, ram_size, 2,
+  alloc_64k_addr - 4, 0x1 + 4, ram_end - 4, 4, 0, 0);
+
+   /* 2nd time */
+   c = lmb_alloc(, 4, 1);
+   ut_asserteq(c, ram_end - 8);
+   ASSERT_LMB(, ram, ram_size, 2,
+  alloc_64k_addr - 4, 0x1 + 4, ram_end - 8, 8, 0, 0);
+   d = lmb_alloc_base(, 4, 1, alloc_64k_end);
+   ut_asserteq(d, alloc_64k_addr - 8);
+   ASSERT_LMB(, ram, ram_size, 2,
+  alloc_64k_addr - 8, 0x1 + 8, ram_end - 8, 8, 0, 0);
+
+   ret = lmb_free(, a, 4);
+   ut_asserteq(ret, 0);
+   ASSERT_LMB(, ram, ram_size, 2,
+  alloc_64k_addr - 8, 0x1 + 8, ram_end - 8, 4, 0, 0);
+   /* allocate again to ensure we get the same address */
+   a2 = lmb_alloc(, 4, 1);
+   ut_asserteq(a, a2);
+   ASSERT_LMB(, ram, ram_size, 2,
+  alloc_64k_addr - 8, 0x1 + 8, ram_end - 8, 8, 0, 0);
+   ret = lmb_free(, a2, 4);
+   ut_asserteq(ret, 0);
+   ASSERT_LMB(, 

Re: [U-Boot] [PATCH v7 0/9] Fix CVE-2018-18440 and CVE-2018-18439

2018-12-17 Thread Simon Goldschmidt

Am 17.12.2018 um 20:06 schrieb Simon Goldschmidt:

This series fixes CVE-2018-18440 ("insufficient boundary checks in
filesystem image load") by adding restrictions to the 'load'
command and fixes CVE-2018-18439 ("insufficient boundary checks in
network image boot") by adding restrictions to the tftp code.
The functions from lmb.c are used to setup regions of allowed and
reserved memory. Then, the file size to load is checked against these
addresses and loading the file is aborted if it would overwrite
reserved memory.

The memory reservation code is reused from bootm/image.

Changes in v7:
- add braces around if/else with macros accross more than one line
- fix compiling without CONFIG_FIT
- fix compiling without CONFIG_LMB


Please ignore v7: I've just found an overflow bug in the ARM port of 
'arch_lmb_reserve' that should go in as well. I'm preparing v8.


Regards,
Simon



Changes in v6:
- fix size of allocated regions that need alignment padding
- fix compiling without OF_CONTROL
- fixed NULL pointer access in 'fdt_blob' passed to
   'boot_fdt_add_mem_rsv_regions'

Changes in v5:
- added tests for lib/lmb.c
- fixed bug in lmb.c when ram is at the end of 32-bit address range
- fixed a bug in lmb_alloc_addr when resulting reserved ranges get
   combined

Changes in v4:
- fixed invalid 'if' statement without braces in boot_fdt_reserve_region
- removed patch 7 ("net: remove CONFIG_MCAST_TFTP), adapted patch 8

Changes in v3:
- No patch changes, but needed to resend since patman added too many cc
   addresses that gmail seemed to detect as spam :-(

Changes in v2:
- added code to reserve devicetree reserved-memory in lmb
- added tftp fixes (patches 7 and 8)
- fixed a bug in new function lmb_alloc_addr

Simon Goldschmidt (9):
   test: add test for lib/lmb.c
   lmb: fix allocation at end of address range
   lib: lmb: reserving overlapping regions should fail
   fdt: parse "reserved-memory" for memory reservation
   lib: lmb: extend lmb for checks at load time
   fs: prevent overwriting reserved memory
   bootm: use new common function lmb_init_and_reserve
   lmb: remove unused extern declaration
   tftp: prevent overwriting reserved memory

  common/bootm.c |   8 +-
  common/image-fdt.c |  53 +++-
  fs/fs.c|  56 -
  include/lmb.h  |   7 +-
  lib/Makefile   |   1 +
  lib/lmb.c  | 106 ++--
  net/tftp.c |  73 +-
  test/lib/Makefile  |   1 +
  test/lib/lmb.c | 601 +
  9 files changed, 853 insertions(+), 53 deletions(-)
  create mode 100644 test/lib/lmb.c



___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH] omap3: beagle: Enable DM_MMC and BLK for u-boot only, not SPL

2018-12-17 Thread Adam Ford
On Mon, Dec 17, 2018 at 11:04 AM Guillaume Gardet
 wrote:
>
>
> Le 21/11/2018 à 18:06, Tom Rini a écrit :
> > On Wed, Nov 21, 2018 at 04:13:20PM +0100, Guillaume GARDET wrote:
> >
> >> Also disable USB_STORAGE as it is not ready for the switch.
> >> Tested on a Beagleboard xM rev. B.
> >>
> >> Signed-off-by: Guillaume GARDET 
> >>
> >> Cc: Tom Rini 
> >> Cc: Simon Glass 
> > In the case of USB_STORAGE we need to turn on DM_USB and then it works.
>
>
> If DM_USB is enabled, no USB controller are detected, so we loose Ethernet. 
> Did I miss an additional option to enable?

AFASK, the MUSB driver didn't yet support gadget mode when used with
DM_USB... at least until recently.  I noticed that part of the MUSB
driver was updated, but the omap2430 glue hasn't been updated yet.  I
am not 100% sure, but I think the Beagle xM is a DM3730 which uses the
omap2430 glue.  I doubt TI will update the omap2430 glue, so I started
some stuff. I've got on patch that seems to show the usb gadget
controller in the DM tree, but my board hangs when I try to use a
gadget.

It's not ready for the mailing list yet, but I can push this stuff to
my github later today if someone wants to look at it and/or
test/improve it.

adam
>
> Guillaume
>
>
> ___
> U-Boot mailing list
> U-Boot@lists.denx.de
> https://lists.denx.de/listinfo/u-boot
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v2] image: fix compiling without CMD_FDT

2018-12-17 Thread Simon Goldschmidt


Booting an image currently sets the environment variable "fdtaddr"
by calling into 'cmd/fdt.c'. As a result, linking U-Boot fails if
CMD_FDT is not enabled.

Fix this by adding 'if (CONFIG_IS_ENABLED(CMD_FDT))' to the two
places where 'set_working_fdt_addr()' is called.

Signed-off-by: Simon Goldschmidt 
---

Changes in v2:
- fixed whitespace (v1 had spaces instead of tabs)

 common/bootm.c | 3 ++-
 common/image-fdt.c | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/common/bootm.c b/common/bootm.c
index 8bf84ebcb7..80f304ce9f 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -262,7 +262,8 @@ int bootm_find_images(int flag, int argc, char * 
const argv[])

puts("Could not find a valid device tree\n");
return 1;
}
-   set_working_fdt_addr(map_to_sysmem(images.ft_addr));
+   if (CONFIG_IS_ENABLED(CMD_FDT))
+   set_working_fdt_addr(map_to_sysmem(images.ft_addr));
 #endif
  #if IMAGE_ENABLE_FIT
diff --git a/common/image-fdt.c b/common/image-fdt.c
index 95748f0ae1..8ee5a13352 100644
--- a/common/image-fdt.c
+++ b/common/image-fdt.c
@@ -193,7 +193,8 @@ int boot_relocate_fdt(struct lmb *lmb, char 
**of_flat_tree, ulong *of_size)

*of_flat_tree = of_start;
*of_size = of_len;
 -  set_working_fdt_addr(map_to_sysmem(*of_flat_tree));
+   if (CONFIG_IS_ENABLED(CMD_FDT))
+   set_working_fdt_addr(map_to_sysmem(*of_flat_tree));
return 0;
  error:
--
2.17.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v2] image: fix compiling without CMD_FDT

2018-12-17 Thread Simon Goldschmidt
From: Simon Goldschmidt 

Booting an image currently sets the environment variable "fdtaddr"
by calling into 'cmd/fdt.c'. As a result, linking U-Boot fails if
CMD_FDT is not enabled.

Fix this by adding 'if (CONFIG_IS_ENABLED(CMD_FDT))' to the two
places where 'set_working_fdt_addr()' is called.

Signed-off-by: Simon Goldschmidt 
---

Changes in v2:
- fixed whitespace (v1 had spaces instead of tabs)

 common/bootm.c | 3 ++-
 common/image-fdt.c | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/common/bootm.c b/common/bootm.c
index 8bf84ebcb7..80f304ce9f 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -262,7 +262,8 @@ int bootm_find_images(int flag, int argc, char * const 
argv[])
puts("Could not find a valid device tree\n");
return 1;
}
-   set_working_fdt_addr(map_to_sysmem(images.ft_addr));
+   if (CONFIG_IS_ENABLED(CMD_FDT))
+   set_working_fdt_addr(map_to_sysmem(images.ft_addr));
 #endif
 
 #if IMAGE_ENABLE_FIT
diff --git a/common/image-fdt.c b/common/image-fdt.c
index 95748f0ae1..8ee5a13352 100644
--- a/common/image-fdt.c
+++ b/common/image-fdt.c
@@ -193,7 +193,8 @@ int boot_relocate_fdt(struct lmb *lmb, char **of_flat_tree, 
ulong *of_size)
*of_flat_tree = of_start;
*of_size = of_len;
 
-   set_working_fdt_addr(map_to_sysmem(*of_flat_tree));
+   if (CONFIG_IS_ENABLED(CMD_FDT))
+   set_working_fdt_addr(map_to_sysmem(*of_flat_tree));
return 0;
 
 error:
-- 
2.17.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v7 8/9] lmb: remove unused extern declaration

2018-12-17 Thread Simon Goldschmidt
lmb.h includes an extern declaration of "struct lmb lmb;" which
is not used anywhere, so remove it.

Signed-off-by: Simon Goldschmidt 
---

Changes in v7: None
Changes in v6: None
Changes in v5: None
Changes in v4: None
Changes in v2:
- this patch is new in v2

 include/lmb.h | 2 --
 1 file changed, 2 deletions(-)

diff --git a/include/lmb.h b/include/lmb.h
index 62da85e716..1bb003e35e 100644
--- a/include/lmb.h
+++ b/include/lmb.h
@@ -28,8 +28,6 @@ struct lmb {
struct lmb_region reserved;
 };
 
-extern struct lmb lmb;
-
 extern void lmb_init(struct lmb *lmb);
 extern void lmb_init_and_reserve(struct lmb *lmb, phys_addr_t base,
 phys_size_t size, void *fdt_blob);
-- 
2.17.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v7 5/9] lib: lmb: extend lmb for checks at load time

2018-12-17 Thread Simon Goldschmidt
This adds two new functions, lmb_alloc_addr and
lmb_get_unreserved_size.

lmb_alloc_addr behaves like lmb_alloc, but it tries to allocate a
pre-specified address range. Unlike lmb_reserve, this address range
must be inside one of the memory ranges that has been set up with
lmb_add.

lmb_get_unreserved_size returns the number of bytes that can be
used up to the next reserved region or the end of valid ram. This
can be 0 if the address passed is reserved.

Added test for these new functions.

Signed-off-by: Simon Goldschmidt 
---

Changes in v7: None
Changes in v6: None
Changes in v5:
- fixed lmb_alloc_addr when resulting reserved ranges get combined
- added test for these new functions

Changes in v4: None
Changes in v2:
- added lmb_get_unreserved_size() for tftp

 include/lmb.h  |   3 +
 lib/lmb.c  |  53 +
 test/lib/lmb.c | 202 +
 3 files changed, 258 insertions(+)

diff --git a/include/lmb.h b/include/lmb.h
index f04d058093..7d7e2a78dc 100644
--- a/include/lmb.h
+++ b/include/lmb.h
@@ -38,6 +38,9 @@ extern phys_addr_t lmb_alloc_base(struct lmb *lmb, 
phys_size_t size, ulong align
phys_addr_t max_addr);
 extern phys_addr_t __lmb_alloc_base(struct lmb *lmb, phys_size_t size, ulong 
align,
  phys_addr_t max_addr);
+extern phys_addr_t lmb_alloc_addr(struct lmb *lmb, phys_addr_t base,
+ phys_size_t size);
+extern phys_size_t lmb_get_unreserved_size(struct lmb *lmb, phys_addr_t addr);
 extern int lmb_is_reserved(struct lmb *lmb, phys_addr_t addr);
 extern long lmb_free(struct lmb *lmb, phys_addr_t base, phys_size_t size);
 
diff --git a/lib/lmb.c b/lib/lmb.c
index cd297f8202..e380a0a722 100644
--- a/lib/lmb.c
+++ b/lib/lmb.c
@@ -313,6 +313,59 @@ phys_addr_t __lmb_alloc_base(struct lmb *lmb, phys_size_t 
size, ulong align, phy
return 0;
 }
 
+/*
+ * Try to allocate a specific address range: must be in defined memory but not
+ * reserved
+ */
+phys_addr_t lmb_alloc_addr(struct lmb *lmb, phys_addr_t base, phys_size_t size)
+{
+   long j;
+
+   /* Check if the requested address is in one of the memory regions */
+   j = lmb_overlaps_region(>memory, base, size);
+   if (j >= 0) {
+   /*
+* Check if the requested end address is in the same memory
+* region we found.
+*/
+   if (lmb_addrs_overlap(lmb->memory.region[j].base,
+ lmb->memory.region[j].size, base + size -
+ 1, 1)) {
+   /* ok, reserve the memory */
+   if (lmb_reserve(lmb, base, size) >= 0)
+   return base;
+   }
+   }
+   return 0;
+}
+
+/* Return number of bytes from a given address that are free */
+phys_size_t lmb_get_unreserved_size(struct lmb *lmb, phys_addr_t addr)
+{
+   int i;
+   long j;
+
+   /* check if the requested address is in the memory regions */
+   j = lmb_overlaps_region(>memory, addr, 1);
+   if (j >= 0) {
+   for (i = 0; i < lmb->reserved.cnt; i++) {
+   if (addr < lmb->reserved.region[i].base) {
+   /* first reserved range > requested address */
+   return lmb->reserved.region[i].base - addr;
+   }
+   if (lmb->reserved.region[i].base +
+   lmb->reserved.region[i].size > addr) {
+   /* requested addr is in this reserved range */
+   return 0;
+   }
+   }
+   /* if we come here: no reserved ranges above requested addr */
+   return lmb->memory.region[lmb->memory.cnt - 1].base +
+  lmb->memory.region[lmb->memory.cnt - 1].size - addr;
+   }
+   return 0;
+}
+
 int lmb_is_reserved(struct lmb *lmb, phys_addr_t addr)
 {
int i;
diff --git a/test/lib/lmb.c b/test/lib/lmb.c
index e6acb70e76..058d3c332b 100644
--- a/test/lib/lmb.c
+++ b/test/lib/lmb.c
@@ -397,3 +397,205 @@ static int lib_test_lmb_overlapping_reserve(struct 
unit_test_state *uts)
 
 DM_TEST(lib_test_lmb_overlapping_reserve,
DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
+
+/*
+ * Simulate 512 MiB RAM, reserve 3 blocks, allocate addresses in between.
+ * Expect addresses outside the memory range to fail.
+ */
+static int test_alloc_addr(struct unit_test_state *uts, const phys_addr_t ram)
+{
+   const phys_size_t ram_size = 0x2000;
+   const phys_addr_t ram_end = ram + ram_size;
+   const phys_size_t alloc_addr_a = ram + 0x800;
+   const phys_size_t alloc_addr_b = ram + 0x800 * 2;
+   const phys_size_t alloc_addr_c = ram + 0x800 * 3;
+   struct lmb lmb;
+   long ret;
+   phys_addr_t a, b, c, d, e;
+
+   /* 

[U-Boot] [PATCH v7 4/9] fdt: parse "reserved-memory" for memory reservation

2018-12-17 Thread Simon Goldschmidt
boot_fdt_add_mem_rsv_regions() adds reserved memory sections to an lmb
struct. Currently, it only parses regions described by /memreserve/
entries.

Extend this to the more commonly used scheme of the "reserved-memory"
node.

Signed-off-by: Simon Goldschmidt 
---

Changes in v7:
- fix compiling without CONFIG_FIT

Changes in v6:
- fix compiling without OF_CONTROL

Changes in v5: None
Changes in v4:
- fixed invalid 'if' statement without braces in boot_fdt_reserve_region

Changes in v2:
- this patch is new in v2

 common/image-fdt.c | 53 +++---
 lib/Makefile   |  1 +
 2 files changed, 46 insertions(+), 8 deletions(-)

diff --git a/common/image-fdt.c b/common/image-fdt.c
index 95748f0ae1..5c0d6db3fe 100644
--- a/common/image-fdt.c
+++ b/common/image-fdt.c
@@ -10,6 +10,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -67,30 +68,66 @@ static const image_header_t *image_get_fdt(ulong fdt_addr)
 }
 #endif
 
+static void boot_fdt_reserve_region(struct lmb *lmb, uint64_t addr,
+   uint64_t size)
+{
+   int ret;
+
+   ret = lmb_reserve(lmb, addr, size);
+   if (!ret) {
+   debug("   reserving fdt memory region: addr=%llx size=%llx\n",
+ (unsigned long long)addr, (unsigned long long)size);
+   } else {
+   puts("ERROR: reserving fdt memory region failed ");
+   printf("(addr=%llx size=%llx)\n",
+  (unsigned long long)addr, (unsigned long long)size);
+   }
+}
+
 /**
- * boot_fdt_add_mem_rsv_regions - Mark the memreserve sections as unusable
+ * boot_fdt_add_mem_rsv_regions - Mark the memreserve and reserved-memory
+ * sections as unusable
  * @lmb: pointer to lmb handle, will be used for memory mgmt
  * @fdt_blob: pointer to fdt blob base address
  *
- * Adds the memreserve regions in the dtb to the lmb block.  Adding the
- * memreserve regions prevents u-boot from using them to store the initrd
- * or the fdt blob.
+ * Adds the and reserved-memorymemreserve regions in the dtb to the lmb block.
+ * Adding the memreserve regions prevents u-boot from using them to store the
+ * initrd or the fdt blob.
  */
 void boot_fdt_add_mem_rsv_regions(struct lmb *lmb, void *fdt_blob)
 {
uint64_t addr, size;
-   int i, total;
+   int i, total, ret;
+   int nodeoffset, subnode;
+   struct fdt_resource res;
 
if (fdt_check_header(fdt_blob) != 0)
return;
 
+   /* process memreserve sections */
total = fdt_num_mem_rsv(fdt_blob);
for (i = 0; i < total; i++) {
if (fdt_get_mem_rsv(fdt_blob, i, , ) != 0)
continue;
-   printf("   reserving fdt memory region: addr=%llx size=%llx\n",
-  (unsigned long long)addr, (unsigned long long)size);
-   lmb_reserve(lmb, addr, size);
+   boot_fdt_reserve_region(lmb, addr, size);
+   }
+
+   /* process reserved-memory */
+   nodeoffset = fdt_subnode_offset(fdt_blob, 0, "reserved-memory");
+   if (nodeoffset >= 0) {
+   subnode = fdt_first_subnode(fdt_blob, nodeoffset);
+   while (subnode >= 0) {
+   /* check if this subnode has a reg property */
+   ret = fdt_get_resource(fdt_blob, subnode, "reg", 0,
+  );
+   if (!ret) {
+   addr = res.start;
+   size = res.end - res.start + 1;
+   boot_fdt_reserve_region(lmb, addr, size);
+   }
+
+   subnode = fdt_next_subnode(fdt_blob, subnode);
+   }
}
 }
 
diff --git a/lib/Makefile b/lib/Makefile
index a6dd928a92..358789ff12 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -30,6 +30,7 @@ obj-y += crc7.o
 obj-y += crc8.o
 obj-y += crc16.o
 obj-$(CONFIG_ERRNO_STR) += errno_str.o
+obj-$(CONFIG_OF_LIBFDT) += fdtdec.o
 obj-$(CONFIG_FIT) += fdtdec_common.o
 obj-$(CONFIG_TEST_FDTDEC) += fdtdec_test.o
 obj-$(CONFIG_GZIP_COMPRESSED) += gzip.o
-- 
2.17.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v7 9/9] tftp: prevent overwriting reserved memory

2018-12-17 Thread Simon Goldschmidt
This fixes CVE-2018-18439 ("insufficient boundary checks in network
image boot") by using lmb to check for a valid range to store
received blocks.

Signed-off-by: Simon Goldschmidt 
---

Changes in v7:
- fix compiling without CONFIG_LMB

Changes in v6: None
Changes in v5: None
Changes in v4:
- this was patch 8, is now patch 7
- lines changed because v3 patch 7 got removed and MCAST_TFTP still
  exists

Changes in v2:
- this patch is new in v2

 net/tftp.c | 73 ++
 1 file changed, 63 insertions(+), 10 deletions(-)

diff --git a/net/tftp.c b/net/tftp.c
index 68ffd81414..a9335b1b7e 100644
--- a/net/tftp.c
+++ b/net/tftp.c
@@ -17,6 +17,8 @@
 #include 
 #endif
 
+DECLARE_GLOBAL_DATA_PTR;
+
 /* Well known TFTP port # */
 #define WELL_KNOWN_PORT69
 /* Millisecs to timeout for lost pkt */
@@ -81,6 +83,10 @@ static ulong tftp_block_wrap;
 /* memory offset due to wrapping */
 static ulong   tftp_block_wrap_offset;
 static int tftp_state;
+static ulong   tftp_load_addr;
+#ifdef CONFIG_LMB
+static ulong   tftp_load_size;
+#endif
 #ifdef CONFIG_TFTP_TSIZE
 /* The file size reported by the server */
 static int tftp_tsize;
@@ -164,10 +170,11 @@ static void mcast_cleanup(void)
 
 #endif /* CONFIG_MCAST_TFTP */
 
-static inline void store_block(int block, uchar *src, unsigned len)
+static inline int store_block(int block, uchar *src, unsigned int len)
 {
ulong offset = block * tftp_block_size + tftp_block_wrap_offset;
ulong newsize = offset + len;
+   ulong store_addr = tftp_load_addr + offset;
 #ifdef CONFIG_SYS_DIRECT_FLASH_TFTP
int i, rc = 0;
 
@@ -175,24 +182,32 @@ static inline void store_block(int block, uchar *src, 
unsigned len)
/* start address in flash? */
if (flash_info[i].flash_id == FLASH_UNKNOWN)
continue;
-   if (load_addr + offset >= flash_info[i].start[0]) {
+   if (store_addr >= flash_info[i].start[0]) {
rc = 1;
break;
}
}
 
if (rc) { /* Flash is destination for this packet */
-   rc = flash_write((char *)src, (ulong)(load_addr+offset), len);
+   rc = flash_write((char *)src, store_addr, len);
if (rc) {
flash_perror(rc);
-   net_set_state(NETLOOP_FAIL);
-   return;
+   return rc;
}
} else
 #endif /* CONFIG_SYS_DIRECT_FLASH_TFTP */
{
-   void *ptr = map_sysmem(load_addr + offset, len);
-
+   void *ptr;
+
+#ifdef CONFIG_LMB
+   if (store_addr < tftp_load_addr ||
+   store_addr + len > tftp_load_addr + tftp_load_size) {
+   puts("\nTFTP error: ");
+   puts("trying to overwrite reserved memory...\n");
+   return -1;
+   }
+#endif
+   ptr = map_sysmem(store_addr, len);
memcpy(ptr, src, len);
unmap_sysmem(ptr);
}
@@ -203,6 +218,8 @@ static inline void store_block(int block, uchar *src, 
unsigned len)
 
if (net_boot_file_size < newsize)
net_boot_file_size = newsize;
+
+   return 0;
 }
 
 /* Clear our state ready for a new transfer */
@@ -606,7 +623,11 @@ static void tftp_handler(uchar *pkt, unsigned dest, struct 
in_addr sip,
timeout_count_max = tftp_timeout_count_max;
net_set_timeout_handler(timeout_ms, tftp_timeout_handler);
 
-   store_block(tftp_cur_block - 1, pkt + 2, len);
+   if (store_block(tftp_cur_block - 1, pkt + 2, len)) {
+   eth_halt();
+   net_set_state(NETLOOP_FAIL);
+   break;
+   }
 
/*
 *  Acknowledge the block just received, which will prompt
@@ -695,6 +716,25 @@ static void tftp_timeout_handler(void)
}
 }
 
+/* Initialize tftp_load_addr and tftp_load_size from load_addr and lmb */
+static int tftp_init_load_addr(void)
+{
+#ifdef CONFIG_LMB
+   struct lmb lmb;
+   phys_size_t max_size;
+
+   lmb_init_and_reserve(, gd->bd->bi_dram[0].start,
+gd->bd->bi_dram[0].size, (void *)gd->fdt_blob);
+
+   max_size = lmb_get_unreserved_size(, load_addr);
+   if (!max_size)
+   return -1;
+
+   tftp_load_size = max_size;
+#endif
+   tftp_load_addr = load_addr;
+   return 0;
+}
 
 void tftp_start(enum proto_t protocol)
 {
@@ -791,7 +831,14 @@ void tftp_start(enum proto_t protocol)
} else
 #endif
{
-   printf("Load address: 0x%lx\n", load_addr);
+   if (tftp_init_load_addr()) {
+   eth_halt();
+   net_set_state(NETLOOP_FAIL);
+   puts("\nTFTP error: ");
+   

[U-Boot] [PATCH v7 7/9] bootm: use new common function lmb_init_and_reserve

2018-12-17 Thread Simon Goldschmidt
This reduces duplicate code only.

Signed-off-by: Simon Goldschmidt 
---

Changes in v7: None
Changes in v6: None
Changes in v5: None
Changes in v4: None
Changes in v2: None

 common/bootm.c | 8 ++--
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/common/bootm.c b/common/bootm.c
index 8bf84ebcb7..31e4f0f794 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -56,15 +56,11 @@ static void boot_start_lmb(bootm_headers_t *images)
ulong   mem_start;
phys_size_t mem_size;
 
-   lmb_init(>lmb);
-
mem_start = env_get_bootm_low();
mem_size = env_get_bootm_size();
 
-   lmb_add(>lmb, (phys_addr_t)mem_start, mem_size);
-
-   arch_lmb_reserve(>lmb);
-   board_lmb_reserve(>lmb);
+   lmb_init_and_reserve(>lmb, (phys_addr_t)mem_start, mem_size,
+NULL);
 }
 #else
 #define lmb_reserve(lmb, base, size)
-- 
2.17.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v7 2/9] lmb: fix allocation at end of address range

2018-12-17 Thread Simon Goldschmidt
The lmb code fails if base + size of RAM overflows to zero.

Fix this by calculating end as 'base + size - 1' instead of 'base + size'
where appropriate.

Added tests to assert this is fixed.

Signed-off-by: Simon Goldschmidt 
---

Changes in v7: None
Changes in v6: None
Changes in v5:
- this patch is new in v5

Changes in v4: None
Changes in v2: None

 lib/lmb.c  | 29 -
 test/lib/lmb.c | 29 ++---
 2 files changed, 38 insertions(+), 20 deletions(-)

diff --git a/lib/lmb.c b/lib/lmb.c
index 1705417348..6d3dcf4e09 100644
--- a/lib/lmb.c
+++ b/lib/lmb.c
@@ -43,7 +43,10 @@ void lmb_dump_all(struct lmb *lmb)
 static long lmb_addrs_overlap(phys_addr_t base1,
phys_size_t size1, phys_addr_t base2, phys_size_t size2)
 {
-   return ((base1 < (base2+size2)) && (base2 < (base1+size1)));
+   const phys_addr_t base1_end = base1 + size1 - 1;
+   const phys_addr_t base2_end = base2 + size2 - 1;
+
+   return ((base1 <= base2_end) && (base2 <= base1_end));
 }
 
 static long lmb_addrs_adjacent(phys_addr_t base1, phys_size_t size1,
@@ -89,18 +92,9 @@ static void lmb_coalesce_regions(struct lmb_region *rgn,
 
 void lmb_init(struct lmb *lmb)
 {
-   /* Create a dummy zero size LMB which will get coalesced away later.
-* This simplifies the lmb_add() code below...
-*/
-   lmb->memory.region[0].base = 0;
-   lmb->memory.region[0].size = 0;
-   lmb->memory.cnt = 1;
+   lmb->memory.cnt = 0;
lmb->memory.size = 0;
-
-   /* Ditto. */
-   lmb->reserved.region[0].base = 0;
-   lmb->reserved.region[0].size = 0;
-   lmb->reserved.cnt = 1;
+   lmb->reserved.cnt = 0;
lmb->reserved.size = 0;
 }
 
@@ -110,9 +104,10 @@ static long lmb_add_region(struct lmb_region *rgn, 
phys_addr_t base, phys_size_t
unsigned long coalesced = 0;
long adjacent, i;
 
-   if ((rgn->cnt == 1) && (rgn->region[0].size == 0)) {
+   if (rgn->cnt == 0) {
rgn->region[0].base = base;
rgn->region[0].size = size;
+   rgn->cnt = 1;
return 0;
}
 
@@ -183,7 +178,7 @@ long lmb_free(struct lmb *lmb, phys_addr_t base, 
phys_size_t size)
 {
struct lmb_region *rgn = &(lmb->reserved);
phys_addr_t rgnbegin, rgnend;
-   phys_addr_t end = base + size;
+   phys_addr_t end = base + size - 1;
int i;
 
rgnbegin = rgnend = 0; /* supress gcc warnings */
@@ -191,7 +186,7 @@ long lmb_free(struct lmb *lmb, phys_addr_t base, 
phys_size_t size)
/* Find the region where (base, size) belongs to */
for (i=0; i < rgn->cnt; i++) {
rgnbegin = rgn->region[i].base;
-   rgnend = rgnbegin + rgn->region[i].size;
+   rgnend = rgnbegin + rgn->region[i].size - 1;
 
if ((rgnbegin <= base) && (end <= rgnend))
break;
@@ -209,7 +204,7 @@ long lmb_free(struct lmb *lmb, phys_addr_t base, 
phys_size_t size)
 
/* Check to see if region is matching at the front */
if (rgnbegin == base) {
-   rgn->region[i].base = end;
+   rgn->region[i].base = end + 1;
rgn->region[i].size -= size;
return 0;
}
@@ -225,7 +220,7 @@ long lmb_free(struct lmb *lmb, phys_addr_t base, 
phys_size_t size)
 * beginging of the hole and add the region after hole.
 */
rgn->region[i].size = base - rgn->region[i].base;
-   return lmb_add_region(rgn, end, rgnend - end);
+   return lmb_add_region(rgn, end + 1, rgnend - end);
 }
 
 long lmb_reserve(struct lmb *lmb, phys_addr_t base, phys_size_t size)
diff --git a/test/lib/lmb.c b/test/lib/lmb.c
index dd7ba14b34..fb7ca45ef1 100644
--- a/test/lib/lmb.c
+++ b/test/lib/lmb.c
@@ -146,8 +146,15 @@ static int test_multi_alloc_512mb(struct unit_test_state 
*uts,
 /* Create a memory region with one reserved region and allocate */
 static int lib_test_lmb_simple(struct unit_test_state *uts)
 {
+   int ret;
+
/* simulate 512 MiB RAM beginning at 1GiB */
-   return test_multi_alloc_512mb(uts, 0x4000);
+   ret = test_multi_alloc_512mb(uts, 0x4000);
+   if (ret)
+   return ret;
+
+   /* simulate 512 MiB RAM beginning at 1.5GiB */
+   return test_multi_alloc_512mb(uts, 0xE000);
 }
 
 DM_TEST(lib_test_lmb_simple, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
@@ -206,7 +213,15 @@ static int test_bigblock(struct unit_test_state *uts, 
const phys_addr_t ram)
 
 static int lib_test_lmb_big(struct unit_test_state *uts)
 {
-   return test_bigblock(uts, 0x4000);
+   int ret;
+
+   /* simulate 512 MiB RAM beginning at 1GiB */
+   ret = test_bigblock(uts, 0x4000);
+   if (ret)
+   return ret;
+
+   /* simulate 512 MiB RAM beginning at 1.5GiB */
+   return test_bigblock(uts, 0xE000);
 }
 
 DM_TEST(lib_test_lmb_big, DM_TESTF_SCAN_PDATA | 

[U-Boot] [PATCH v7 6/9] fs: prevent overwriting reserved memory

2018-12-17 Thread Simon Goldschmidt
This fixes CVE-2018-18440 ("insufficient boundary checks in filesystem
image load") by using lmb to check the load size of a file against
reserved memory addresses.

Signed-off-by: Simon Goldschmidt 
---

Changes in v7: None
Changes in v6:
- fixed NULL pointer access in 'fdt_blob' passed to
  'boot_fdt_add_mem_rsv_regions'

Changes in v5: None
Changes in v4: None
Changes in v2: None

 fs/fs.c   | 56 ---
 include/lmb.h |  2 ++
 lib/lmb.c | 13 
 3 files changed, 68 insertions(+), 3 deletions(-)

diff --git a/fs/fs.c b/fs/fs.c
index cb265174e2..400aa921a7 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -429,13 +429,57 @@ int fs_size(const char *filename, loff_t *size)
return ret;
 }
 
-int fs_read(const char *filename, ulong addr, loff_t offset, loff_t len,
-   loff_t *actread)
+#ifdef CONFIG_LMB
+/* Check if a file may be read to the given address */
+static int fs_read_lmb_check(const char *filename, ulong addr, loff_t offset,
+loff_t len, struct fstype_info *info)
+{
+   struct lmb lmb;
+   int ret;
+   loff_t size;
+   loff_t read_len;
+
+   /* get the actual size of the file */
+   ret = info->size(filename, );
+   if (ret)
+   return ret;
+   if (offset >= size) {
+   /* offset >= EOF, no bytes will be written */
+   return 0;
+   }
+   read_len = size - offset;
+
+   /* limit to 'len' if it is smaller */
+   if (len && len < read_len)
+   read_len = len;
+
+   lmb_init_and_reserve(, gd->bd->bi_dram[0].start,
+gd->bd->bi_dram[0].size, (void *)gd->fdt_blob);
+   lmb_dump_all();
+
+   if (lmb_alloc_addr(, addr, read_len) == addr)
+   return 0;
+
+   printf("** Reading file would overwrite reserved memory **\n");
+   return -1;
+}
+#endif
+
+static int _fs_read(const char *filename, ulong addr, loff_t offset, loff_t 
len,
+   int do_lmb_check, loff_t *actread)
 {
struct fstype_info *info = fs_get_info(fs_type);
void *buf;
int ret;
 
+#ifdef CONFIG_LMB
+   if (do_lmb_check) {
+   ret = fs_read_lmb_check(filename, addr, offset, len, info);
+   if (ret)
+   return ret;
+   }
+#endif
+
/*
 * We don't actually know how many bytes are being read, since len==0
 * means read the whole file.
@@ -452,6 +496,12 @@ int fs_read(const char *filename, ulong addr, loff_t 
offset, loff_t len,
return ret;
 }
 
+int fs_read(const char *filename, ulong addr, loff_t offset, loff_t len,
+   loff_t *actread)
+{
+   return _fs_read(filename, addr, offset, len, 0, actread);
+}
+
 int fs_write(const char *filename, ulong addr, loff_t offset, loff_t len,
 loff_t *actwrite)
 {
@@ -622,7 +672,7 @@ int do_load(cmd_tbl_t *cmdtp, int flag, int argc, char * 
const argv[],
pos = 0;
 
time = get_timer(0);
-   ret = fs_read(filename, addr, pos, bytes, _read);
+   ret = _fs_read(filename, addr, pos, bytes, 1, _read);
time = get_timer(time);
if (ret < 0)
return 1;
diff --git a/include/lmb.h b/include/lmb.h
index 7d7e2a78dc..62da85e716 100644
--- a/include/lmb.h
+++ b/include/lmb.h
@@ -31,6 +31,8 @@ struct lmb {
 extern struct lmb lmb;
 
 extern void lmb_init(struct lmb *lmb);
+extern void lmb_init_and_reserve(struct lmb *lmb, phys_addr_t base,
+phys_size_t size, void *fdt_blob);
 extern long lmb_add(struct lmb *lmb, phys_addr_t base, phys_size_t size);
 extern long lmb_reserve(struct lmb *lmb, phys_addr_t base, phys_size_t size);
 extern phys_addr_t lmb_alloc(struct lmb *lmb, phys_size_t size, ulong align);
diff --git a/lib/lmb.c b/lib/lmb.c
index e380a0a722..3407705fa7 100644
--- a/lib/lmb.c
+++ b/lib/lmb.c
@@ -98,6 +98,19 @@ void lmb_init(struct lmb *lmb)
lmb->reserved.size = 0;
 }
 
+/* Initialize the struct, add memory and call arch/board reserve functions */
+void lmb_init_and_reserve(struct lmb *lmb, phys_addr_t base, phys_size_t size,
+ void *fdt_blob)
+{
+   lmb_init(lmb);
+   lmb_add(lmb, base, size);
+   arch_lmb_reserve(lmb);
+   board_lmb_reserve(lmb);
+
+   if (IMAGE_ENABLE_OF_LIBFDT && fdt_blob)
+   boot_fdt_add_mem_rsv_regions(lmb, fdt_blob);
+}
+
 /* This routine called with relocation disabled. */
 static long lmb_add_region(struct lmb_region *rgn, phys_addr_t base, 
phys_size_t size)
 {
-- 
2.17.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v7 3/9] lib: lmb: reserving overlapping regions should fail

2018-12-17 Thread Simon Goldschmidt
lmb_add_region handles overlapping regions wrong: instead of merging
or rejecting to add a new reserved region that overlaps an existing
one, it just adds the new region.

Since internally the same function is used for lmb_alloc, change
lmb_add_region to reject overlapping regions.

Also, to keep reserved memory correct after 'free', reserved entries
created by allocating memory must not set their size to a multiple
of alignment but to the original size. This ensures the reserved
region is completely removed when the caller calls 'lmb_free', as
this one takes the same size as passed to 'lmb_alloc' etc.

Add test to assert this.

Signed-off-by: Simon Goldschmidt 
---

Changes in v7:
- add braces around if/else with macros accross more than one line

Changes in v6:
- fix size of allocated regions that need alignment padding

Changes in v5:
- added a test for this bug

Changes in v4: None
Changes in v2: None

 lib/lmb.c  | 11 +++---
 test/lib/lmb.c | 95 +-
 2 files changed, 91 insertions(+), 15 deletions(-)

diff --git a/lib/lmb.c b/lib/lmb.c
index 6d3dcf4e09..cd297f8202 100644
--- a/lib/lmb.c
+++ b/lib/lmb.c
@@ -131,6 +131,9 @@ static long lmb_add_region(struct lmb_region *rgn, 
phys_addr_t base, phys_size_t
rgn->region[i].size += size;
coalesced++;
break;
+   } else if (lmb_addrs_overlap(base, size, rgnbase, rgnsize)) {
+   /* regions overlap */
+   return -1;
}
}
 
@@ -269,11 +272,6 @@ static phys_addr_t lmb_align_down(phys_addr_t addr, 
phys_size_t size)
return addr & ~(size - 1);
 }
 
-static phys_addr_t lmb_align_up(phys_addr_t addr, ulong size)
-{
-   return (addr + (size - 1)) & ~(size - 1);
-}
-
 phys_addr_t __lmb_alloc_base(struct lmb *lmb, phys_size_t size, ulong align, 
phys_addr_t max_addr)
 {
long i, j;
@@ -302,8 +300,7 @@ phys_addr_t __lmb_alloc_base(struct lmb *lmb, phys_size_t 
size, ulong align, phy
if (j < 0) {
/* This area isn't reserved, take it */
if (lmb_add_region(>reserved, base,
-   lmb_align_up(size,
-   align)) < 0)
+  size) < 0)
return 0;
return base;
}
diff --git a/test/lib/lmb.c b/test/lib/lmb.c
index fb7ca45ef1..e6acb70e76 100644
--- a/test/lib/lmb.c
+++ b/test/lib/lmb.c
@@ -227,13 +227,16 @@ static int lib_test_lmb_big(struct unit_test_state *uts)
 DM_TEST(lib_test_lmb_big, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
 
 /* Simulate 512 MiB RAM, allocate a block without previous reservation */
-static int test_noreserved(struct unit_test_state *uts, const phys_addr_t ram)
+static int test_noreserved(struct unit_test_state *uts, const phys_addr_t ram,
+  const phys_addr_t alloc_size, const ulong align)
 {
const phys_size_t ram_size = 0x2000;
const phys_addr_t ram_end = ram + ram_size;
struct lmb lmb;
long ret;
phys_addr_t a, b;
+   const phys_addr_t alloc_size_aligned = (alloc_size + align - 1) &
+   ~(align - 1);
 
/* check for overflow */
ut_assert(ram_end == 0 || ram_end > ram);
@@ -242,20 +245,43 @@ static int test_noreserved(struct unit_test_state *uts, 
const phys_addr_t ram)
 
ret = lmb_add(, ram, ram_size);
ut_asserteq(ret, 0);
+   ASSERT_LMB(, ram, ram_size, 0, 0, 0, 0, 0, 0, 0);
 
/* allocate a block */
-   a = lmb_alloc(, 4, 1);
+   a = lmb_alloc(, alloc_size, align);
ut_assert(a != 0);
-   /* and free it */
-   ret = lmb_free(, a, 4);
+   ASSERT_LMB(, ram, ram_size, 1, ram + ram_size - alloc_size_aligned,
+  alloc_size, 0, 0, 0, 0);
+   /* allocate another block */
+   b = lmb_alloc(, alloc_size, align);
+   ut_assert(b != 0);
+   if (alloc_size == alloc_size_aligned) {
+   ASSERT_LMB(, ram, ram_size, 1, ram + ram_size -
+  (alloc_size_aligned * 2), alloc_size * 2, 0, 0, 0,
+  0);
+   } else {
+   ASSERT_LMB(, ram, ram_size, 2, ram + ram_size -
+  (alloc_size_aligned * 2), alloc_size, ram + ram_size
+  - alloc_size_aligned, alloc_size, 0, 0);
+   }
+   /* and free them */
+   ret = lmb_free(, b, alloc_size);
ut_asserteq(ret, 0);
+   ASSERT_LMB(, ram, ram_size, 1, ram + ram_size - alloc_size_aligned,
+  alloc_size, 0, 0, 0, 0);
+   ret = lmb_free(, a, alloc_size);
+   ut_asserteq(ret, 0);
+   ASSERT_LMB(, ram, ram_size, 0, 0, 0, 0, 0, 0, 0);
 
/* 

[U-Boot] [PATCH v7 1/9] test: add test for lib/lmb.c

2018-12-17 Thread Simon Goldschmidt
Add basic tests for the lmb memory allocation code used to reserve and
allocate memory during boot.

Signed-off-by: Simon Goldschmidt 
---

Changes in v7: None
Changes in v6: None
Changes in v5:
- this patch is new in v5

Changes in v4: None
Changes in v2: None

 test/lib/Makefile |   1 +
 test/lib/lmb.c| 297 ++
 2 files changed, 298 insertions(+)
 create mode 100644 test/lib/lmb.c

diff --git a/test/lib/Makefile b/test/lib/Makefile
index ea68fae566..5a636aac74 100644
--- a/test/lib/Makefile
+++ b/test/lib/Makefile
@@ -3,3 +3,4 @@
 # (C) Copyright 2018
 # Mario Six, Guntermann & Drunck GmbH, mario@gdsys.cc
 obj-y += hexdump.o
+obj-y += lmb.o
diff --git a/test/lib/lmb.c b/test/lib/lmb.c
new file mode 100644
index 00..dd7ba14b34
--- /dev/null
+++ b/test/lib/lmb.c
@@ -0,0 +1,297 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2018 Simon Goldschmidt
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+static int check_lmb(struct unit_test_state *uts, struct lmb *lmb,
+phys_addr_t ram_base, phys_size_t ram_size,
+unsigned long num_reserved,
+phys_addr_t base1, phys_size_t size1,
+phys_addr_t base2, phys_size_t size2,
+phys_addr_t base3, phys_size_t size3)
+{
+   ut_asserteq(lmb->memory.cnt, 1);
+   ut_asserteq(lmb->memory.region[0].base, ram_base);
+   ut_asserteq(lmb->memory.region[0].size, ram_size);
+
+   ut_asserteq(lmb->reserved.cnt, num_reserved);
+   if (num_reserved > 0) {
+   ut_asserteq(lmb->reserved.region[0].base, base1);
+   ut_asserteq(lmb->reserved.region[0].size, size1);
+   }
+   if (num_reserved > 1) {
+   ut_asserteq(lmb->reserved.region[1].base, base2);
+   ut_asserteq(lmb->reserved.region[1].size, size2);
+   }
+   if (num_reserved > 2) {
+   ut_asserteq(lmb->reserved.region[2].base, base3);
+   ut_asserteq(lmb->reserved.region[2].size, size3);
+   }
+   return 0;
+}
+
+#define ASSERT_LMB(lmb, ram_base, ram_size, num_reserved, base1, size1, \
+  base2, size2, base3, size3) \
+  ut_assert(!check_lmb(uts, lmb, ram_base, ram_size, \
+num_reserved, base1, size1, base2, size2, base3, \
+size3))
+
+/*
+ * Test helper function that reserves 64 KiB somewhere in the simulated RAM and
+ * then does some alloc + free tests.
+ */
+static int test_multi_alloc(struct unit_test_state *uts,
+   const phys_addr_t ram, const phys_size_t ram_size,
+   const phys_addr_t alloc_64k_addr)
+{
+   const phys_addr_t ram_end = ram + ram_size;
+   const phys_addr_t alloc_64k_end = alloc_64k_addr + 0x1;
+
+   struct lmb lmb;
+   long ret;
+   phys_addr_t a, a2, b, b2, c, d;
+
+   /* check for overflow */
+   ut_assert(ram_end == 0 || ram_end > ram);
+   ut_assert(alloc_64k_end > alloc_64k_addr);
+   /* check input addresses + size */
+   ut_assert(alloc_64k_addr >= ram + 8);
+   ut_assert(alloc_64k_end <= ram_end - 8);
+
+   lmb_init();
+
+   ret = lmb_add(, ram, ram_size);
+   ut_asserteq(ret, 0);
+
+   /* reserve 64KiB somewhere */
+   ret = lmb_reserve(, alloc_64k_addr, 0x1);
+   ut_asserteq(ret, 0);
+   ASSERT_LMB(, ram, ram_size, 1, alloc_64k_addr, 0x1,
+  0, 0, 0, 0);
+
+   /* allocate somewhere, should be at the end of RAM */
+   a = lmb_alloc(, 4, 1);
+   ut_asserteq(a, ram_end - 4);
+   ASSERT_LMB(, ram, ram_size, 2, alloc_64k_addr, 0x1,
+  ram_end - 4, 4, 0, 0);
+   /* alloc below end of reserved region -> below reserved region */
+   b = lmb_alloc_base(, 4, 1, alloc_64k_end);
+   ut_asserteq(b, alloc_64k_addr - 4);
+   ASSERT_LMB(, ram, ram_size, 2,
+  alloc_64k_addr - 4, 0x1 + 4, ram_end - 4, 4, 0, 0);
+
+   /* 2nd time */
+   c = lmb_alloc(, 4, 1);
+   ut_asserteq(c, ram_end - 8);
+   ASSERT_LMB(, ram, ram_size, 2,
+  alloc_64k_addr - 4, 0x1 + 4, ram_end - 8, 8, 0, 0);
+   d = lmb_alloc_base(, 4, 1, alloc_64k_end);
+   ut_asserteq(d, alloc_64k_addr - 8);
+   ASSERT_LMB(, ram, ram_size, 2,
+  alloc_64k_addr - 8, 0x1 + 8, ram_end - 8, 8, 0, 0);
+
+   ret = lmb_free(, a, 4);
+   ut_asserteq(ret, 0);
+   ASSERT_LMB(, ram, ram_size, 2,
+  alloc_64k_addr - 8, 0x1 + 8, ram_end - 8, 4, 0, 0);
+   /* allocate again to ensure we get the same address */
+   a2 = lmb_alloc(, 4, 1);
+   ut_asserteq(a, a2);
+   ASSERT_LMB(, ram, ram_size, 2,
+  alloc_64k_addr - 8, 0x1 + 8, ram_end - 8, 8, 0, 0);
+   ret = lmb_free(, a2, 4);
+   ut_asserteq(ret, 0);
+   ASSERT_LMB(, ram, ram_size, 2,
+  

[U-Boot] [PATCH v7 0/9] Fix CVE-2018-18440 and CVE-2018-18439

2018-12-17 Thread Simon Goldschmidt
This series fixes CVE-2018-18440 ("insufficient boundary checks in
filesystem image load") by adding restrictions to the 'load'
command and fixes CVE-2018-18439 ("insufficient boundary checks in
network image boot") by adding restrictions to the tftp code.
The functions from lmb.c are used to setup regions of allowed and
reserved memory. Then, the file size to load is checked against these
addresses and loading the file is aborted if it would overwrite
reserved memory.

The memory reservation code is reused from bootm/image.

Changes in v7:
- add braces around if/else with macros accross more than one line
- fix compiling without CONFIG_FIT
- fix compiling without CONFIG_LMB

Changes in v6:
- fix size of allocated regions that need alignment padding
- fix compiling without OF_CONTROL
- fixed NULL pointer access in 'fdt_blob' passed to
  'boot_fdt_add_mem_rsv_regions'

Changes in v5:
- added tests for lib/lmb.c
- fixed bug in lmb.c when ram is at the end of 32-bit address range
- fixed a bug in lmb_alloc_addr when resulting reserved ranges get
  combined

Changes in v4:
- fixed invalid 'if' statement without braces in boot_fdt_reserve_region
- removed patch 7 ("net: remove CONFIG_MCAST_TFTP), adapted patch 8

Changes in v3:
- No patch changes, but needed to resend since patman added too many cc
  addresses that gmail seemed to detect as spam :-(

Changes in v2:
- added code to reserve devicetree reserved-memory in lmb
- added tftp fixes (patches 7 and 8)
- fixed a bug in new function lmb_alloc_addr

Simon Goldschmidt (9):
  test: add test for lib/lmb.c
  lmb: fix allocation at end of address range
  lib: lmb: reserving overlapping regions should fail
  fdt: parse "reserved-memory" for memory reservation
  lib: lmb: extend lmb for checks at load time
  fs: prevent overwriting reserved memory
  bootm: use new common function lmb_init_and_reserve
  lmb: remove unused extern declaration
  tftp: prevent overwriting reserved memory

 common/bootm.c |   8 +-
 common/image-fdt.c |  53 +++-
 fs/fs.c|  56 -
 include/lmb.h  |   7 +-
 lib/Makefile   |   1 +
 lib/lmb.c  | 106 ++--
 net/tftp.c |  73 +-
 test/lib/Makefile  |   1 +
 test/lib/lmb.c | 601 +
 9 files changed, 853 insertions(+), 53 deletions(-)
 create mode 100644 test/lib/lmb.c

-- 
2.17.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH] tools: zynqmpimage: round up partition size

2018-12-17 Thread Michael Tretter
On Mon, 17 Dec 2018 14:27:38 +0100, Michal Simek wrote:
> On 03. 12. 18 14:42, Alexander Graf wrote:
> > On 03.12.18 14:14, Michal Simek wrote:  
> >> +Alex
> >>
> >> On 28. 11. 18 11:47, Michael Tretter wrote:  
> >>> The FSBL copies "Total Partition Word Length" * 4 bytes from the boot.bin,
> >>> which implies that the partition size is 4 byte aligned. When writing the
> >>> partition, mkimage calculates "Total Partition Word Length" by dividing
> >>> the size by 4. This implicitly cuts unaligned bytes at the end of the
> >>> added binary.
> >>>
> >>> Instead of rounding down, the size must be round up to 4 bytes and the
> >>> binary padded accordingly.
> >>>
> >>> Signed-off-by: Michael Tretter 
> >>> ---
> >>>  tools/zynqmpbif.c | 18 ++
> >>>  1 file changed, 14 insertions(+), 4 deletions(-)
> >>>
> >>> diff --git a/tools/zynqmpbif.c b/tools/zynqmpbif.c
> >>> index 6c8f66055d..885a037da6 100644
> >>> --- a/tools/zynqmpbif.c
> >>> +++ b/tools/zynqmpbif.c
> >>> @@ -316,19 +316,29 @@ static int bif_add_pmufw(struct bif_entry *bf, 
> >>> const char *data, size_t len)
> >>>   return 0;
> >>>  }
> >>>  
> >>> -static int bif_add_part(struct bif_entry *bf, const char *data, size_t 
> >>> len)
> >>> +static int bif_add_part(struct bif_entry *bf, char *data, size_t len)
> >>>  {
> >>>   size_t parthdr_offset = 0;
> >>> + size_t len_padded = ROUND(len, 4);
> >>> +
> >>>   struct partition_header parthdr = {
> >>> - .len_enc = cpu_to_le32(len / 4),
> >>> - .len_unenc = cpu_to_le32(len / 4),
> >>> - .len = cpu_to_le32(len / 4),
> >>> + .len_enc = cpu_to_le32(len_padded / 4),
> >>> + .len_unenc = cpu_to_le32(len_padded / 4),
> >>> + .len = cpu_to_le32(len_padded / 4),
> >>>   .entry_point = cpu_to_le64(bf->entry),
> >>>   .load_address = cpu_to_le64(bf->load),
> >>>   };
> >>>   int r;
> >>>   uint32_t csum;
> >>>  
> >>> + if (len != len_padded) {
> >>> + data = realloc(data, len_padded);
> >>> + while (len < len_padded) {
> >>> + data[len] = 0;
> >>> + len++;
> >>> + }
> >>> + }
> >>> +
> >>>   if (bf->flags & (1ULL << BIF_FLAG_PMUFW_IMAGE))
> >>>   return bif_add_pmufw(bf, data, len);
> >>>  
> >>>  
> >>
> >> I am not using this for creating boot image but I have tested it on
> >> regular example and it is still working.
> >>
> >> I have applied this to my branch.
> >> Alex: If you have any comment on this please let us know and I can
> >> remove it from my queue.  
> > 
> > I don't think I've ever had a not-multiple-of-4 payload, so I never ran
> > into this.  
> 
> I was playing with U-Boot on Friday and I found one thing related to
> this commit. You can get "not-multiple-of-4 payload" quite simply just
> but enabling OF_SEPARATE for SPL which is generating (I am not 100% sure
> if all case) aligned u-boot-spl-nodtb.bin and then appends cat
>  >> u-boot-spl-nodtb.bin which is ending up in
> "not-multiple-of-4 payload" very often.
> 
> I was trying to enable OF_SEPARATE because of
> "fdt: Add warning about CONFIG_OF_EMBED"
> (sha1: 841d5fbae4e993476fa87d8933db0cd58d3c2d41)
> which is working fine for jtag bootmode but not for SD one (I expect
> also others will be broken).
> 
> But I found that you are still pure len(non aligned) in
> image_size/image_stored_size instead of aligned one. Which caused that
> boot.bin with "not-multiple-of-4 payload" is not handled properly by
> bootrom.
> 
> After this patch, boot.bin started to work.
> 
> --- a/tools/zynqmpbif.c
> +++ b/tools/zynqmpbif.c
> @@ -425,8 +425,8 @@ static int bif_add_part(struct bif_entry *bf, const
> char *data, size_t len)
> if (!bif_output.header->image_offset)
> bif_output.header->image_offset =
> cpu_to_le32(bf->offset);
> -   bif_output.header->image_size = cpu_to_le32(len);
> -   bif_output.header->image_stored_size = cpu_to_le32(len);
> +   bif_output.header->image_size = cpu_to_le32(len_padded);
> +   bif_output.header->image_stored_size =
> cpu_to_le32(len_padded);
> 
> 
> Anyway xilinx bootgen has issue with this too and also zynqmpimage.c.
> 
> Can you please retest it again but I am quite sure you need to also
> update header with padded len?

The image_size affects only the first stage bootloader. As I use the
FSBL for that, I didn't run into this issue.

I can reproduce the issue by writing a size that is not multiple of 4
into either image_size or image_stored_size. The FSBL does not
boot, if the image_size is larger than the size of the image, but not 4
byte aligned. It does boot, if image_size is larger and 4 byte aligned.

I would have expected that the bootrom ignores the bytes between
image_size and partition_size and just reads image_size bytes.
Therefore, aligning the image_size looks like a proper fix, but the
reason for the patch is different.

Michael

> 
> 

Re: [U-Boot] [PATCH] omap3: beagle: Enable DM_MMC and BLK for u-boot only, not SPL

2018-12-17 Thread Guillaume Gardet


Le 21/11/2018 à 18:06, Tom Rini a écrit :

On Wed, Nov 21, 2018 at 04:13:20PM +0100, Guillaume GARDET wrote:


Also disable USB_STORAGE as it is not ready for the switch.
Tested on a Beagleboard xM rev. B.

Signed-off-by: Guillaume GARDET 

Cc: Tom Rini 
Cc: Simon Glass 

In the case of USB_STORAGE we need to turn on DM_USB and then it works.



If DM_USB is enabled, no USB controller are detected, so we loose Ethernet. Did 
I miss an additional option to enable?

Guillaume


___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [BeagleBone Black] Possible bug in U-Boot efi loader for BeagleBone Black

2018-12-17 Thread Heinrich Schuchardt
On 12/14/18 9:15 PM, Heinrich Schuchardt wrote:
> On 12/14/18 3:58 PM, Dominik Adamski wrote:
>> On 12/12/18 7:11 PM, Heinrich Schuchardt wrote:
>>> On 12/12/18 3:02 PM, Dominik Adamski wrote:
 Hello,
 I think that I have found a bug in U-Boot UEFI implementation for
 BeagleBone Black board.

 I have tested U-Boot UEFI implementation for BeagleBone Black. I am able
 to load Linux successfully via GRUB bootloader with U-Boot v2018.09-rc2
 . U-Boot v2018.09-rc3 and above versions cause that the platform
 restarts over and over again. It starts booting, then it loads GRUB and
 when GRUB finishes its work an error occurs and the board restarts.

 I have looked through U-Boot repository and I have found the commit,
 which breaks booting. It's name is as follows: "efi_loader: update
 runtime services table crc32" (commit ID:
 a39f39cdd8be5cd3e7a8b696a463b621e3d827e0 ) . I have figured out, that
 when I comment out function call:
 efi_update_table_header_crc32(_runtime_services.hdr); in function
 efi_runtime_detach then I am able to launch Linux successfully.

 My setup of U-Boot, GRUB and Linux was as follows:
 https://github.com/DominikAdamski/Beaglebone_GRUB_Manual . For U-Boot
 v2018.09 I get following log when booting:

 U-Boot 2018.09 (Dec 11 2018 - 11:11:16 +0100)

 CPU  : AM335X-GP rev 2.1
 Model: TI AM335x BeagleBone Black
 DRAM:  512 MiB
 NAND:  0 MiB
 MMC:   OMAP SD/MMC: 0, OMAP SD/MMC: 1
 Loading Environment from FAT... *** Warning - bad CRC, using default
 environment

 No USB device found
  not set. Validating first E-fuse MAC
 Net:   eth0: ethernet@4a10
 Hit any key to stop autoboot:  2 ^H^H^H 1 ^H^H^H 0
 switch to partitions #0, OK
 mmc0 is current device
 SD/MMC found on device 0
 ** Unable to read file boot.scr **
 85 bytes read in 1 ms (83 KiB/s)
 Loaded env from uEnv.txt
 Importing environment from mmc0 ...
 Running uenvcmd ...
 403968 bytes read in 28 ms (13.8 MiB/s)
 ^[[18tScanning disks on usb...
 Disk usb0 not ready
 Disk usb1 not ready
 Disk usb2 not ready
 Disk usb3 not ready
 Scanning disks on mmc...
 MMC Device 2 not found
 MMC Device 3 not found
 Found 4 disks
 WARNING: booting without device tree
 ## Starting EFI application at 8200 ...
 ^[[?25h^[[0;30;47mWelcome to GRUB!
 ^M
 ^M^[[0;37;40m^[[0;37;40m^[[0;37;40mEFI stub: Booting Linux Kernel...^M
 EFI stub: Using DTB from configuration table^M
 EFI stub: Exiting boot services and installing virtual address map...^M
 U-Boot EFI: Relocation at 9ff4a8a8 is out of range (2008214f)
 data abort
 pc : [<9ff4a7cc>]  lr : [<9ff4a8b9>]
 reloc pc : [<808007cc>]    lr : [<808008b9>]
 sp : 9df1ebac  ip : 0020 fp : 
 r10: 1000  r9 : 9df29eb8 r8 : 0028
 r7 : 9ff4aa10  r6 : 9ff4aec4 r5 : 0003  r4 : 9ff4aa70
 r3 : 2002aac0  r2 : 0050 r1 : 9ff4aa70  r0 : 
 Flags: NzCv  IRQs off  FIQs on  Mode SVC_32
 Code: 61204621 f876f000 bd106120 b5f04b36 (b31c681c)
 UEFI image [0x9ceb1000:0x9cf139ff] '/\grub.efi'
 UEFI image [0x94728000:0x9510bfff]
 Resetting CPU ...

 resetting ...

 Please let me know, if I should add more detailed logs.

 Dominik Adamski


>>> Hello Dominik,
>>>
>>> you refer to an outdated release candidate v2018.09-rc2.
>>>
>>> The following patch is missing in the release candidate:
>>>
>>> commit 483dbab9f9318149e5ea97daacbfae320f53e35a
>>> Author: Heinrich Schuchardt 
>>> Date:   Sun Jul 29 09:49:03 2018 +0200
>>>
>>>  lib: crc32: mark function crc32() as __efi_runtime
>>>
>>> It is contained in the v2018.09 release. Please, update your page
>>> https://github.com/DominikAdamski/Beaglebone_GRUB_Manual accordingly.
>>>
>>> The latest release is v2018.11. Release v2018.11 will require a recent
>>> GRUB (later than patch d0c070179d4d). Or apply the following patch
>>> http://git.denx.de/?p=u-boot.git;a=commit;h=f31239acff61f7def88a06eef1f091fce74ecd61
>>>
>>> Revert "efi_loader: remove efi_exit_caches()"
>>>
>>> Best regards
>>>
>>> Heinrich
>>
>> Hello Heinrich,
>>
>> I am resending my mail, because I haven't noticed that I should answer
>> below your response. I am also adding some more information just to be
>> sure, that everything is clear.
>>
>> I have build the newest GRUB from master branch and I have checked out
>> U-Boot with this patch:
>>
>> http://git.denx.de/?p=u-boot.git;a=commit;h=f31239acff61f7def88a06eef1f091fce74ecd61
>>
>> Revert "efi_loader: remove efi_exit_caches()"
>>
>> and I still get an error while Linux booting :
>>
>> EFI stub: Booting Linux Kernel...
>> EFI stub: Using DTB from configuration table
>> EFI stub: Exiting boot services and installing virtual address map...
>> efi_runtime_relocate: Relocation at 9ff57a20 is 

[U-Boot] [PATCH] Add an empty stdint.h file

2018-12-17 Thread Simon Glass
Some libraries build by U-Boot may include stdint.h. This is not used by
U-Boot itself and causes conflicts with the types defined in
linux/types.h. To work around this, add an empty file with this name so
that it will be used in preference to the compiler version.

Signed-off-by: Simon Glass 
---

 include/stdint.h | 7 +++
 1 file changed, 7 insertions(+)
 create mode 100644 include/stdint.h

diff --git a/include/stdint.h b/include/stdint.h
new file mode 100644
index 000..2e126d14bd9
--- /dev/null
+++ b/include/stdint.h
@@ -0,0 +1,7 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Dummy file to allow libraries linked with U-Boot to include stdint.h without
+ * getting the system version.
+ *
+ * U-Boot uses linux types (linux/types.h) so does not make use of stdint.h
+ */
-- 
2.20.0.405.gbc1bbc6f85-goog

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH] sandbox: Correct SDL build flags

2018-12-17 Thread Simon Glass
The check for CONFIG_SANDBOX_SDL in config.mk does not work since the
build config is not available by the time that file is included. Remove it
so that we always call sdl-config except when NO_SDL is used.

Signed-off-by: Simon Glass 
---

 arch/sandbox/config.mk | 2 --
 arch/sandbox/cpu/sdl.c | 2 +-
 2 files changed, 1 insertion(+), 3 deletions(-)

diff --git a/arch/sandbox/config.mk b/arch/sandbox/config.mk
index 07ede076b83..3be1c0361e5 100644
--- a/arch/sandbox/config.mk
+++ b/arch/sandbox/config.mk
@@ -12,11 +12,9 @@ SDL_CONFIG ?= sdl-config
 ifneq ($(NO_SDL),)
 PLATFORM_CPPFLAGS += -DSANDBOX_NO_SDL
 else
-ifdef CONFIG_SANDBOX_SDL
 PLATFORM_LIBS += $(shell $(SDL_CONFIG) --libs)
 PLATFORM_CPPFLAGS += $(shell $(SDL_CONFIG) --cflags)
 endif
-endif
 
 cmd_u-boot__ = $(CC) -o $@ -Wl,-T u-boot.lds \
u-boot.o  $(u-boot-init) \
diff --git a/arch/sandbox/cpu/sdl.c b/arch/sandbox/cpu/sdl.c
index c7a8d945492..3abe718a417 100644
--- a/arch/sandbox/cpu/sdl.c
+++ b/arch/sandbox/cpu/sdl.c
@@ -5,7 +5,7 @@
 
 #include 
 #include 
-#include 
+#include 
 #include 
 #include 
 
-- 
2.20.0.405.gbc1bbc6f85-goog

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PULL] Please pull u-boot-imx: u-boot-imx-20181217

2018-12-17 Thread Stefano Babic
Hi Tom,

please pull from u-boot-imx, u-boot-imx-20181217, thanks !

- fix missing MAINTANERS for embestmx6boards
- drop Wolfgang's patch
- apply V4 of "pico-imx7d: Increase the CONFIG_ENV_OFFSET size " that
use fix values for size.

The following changes since commit d117d8f19b0625f88309e47a8a32c2faa384dddc:

  Merge branch 'master' of git://git.denx.de/u-boot-i2c (2018-12-13
09:36:55 -0500)

are available in the Git repository at:

  git://www.denx.de/git/u-boot-imx.git tags/u-boot-imx-20181217

for you to fetch changes up to 22f219feb807df91d958c3cc5a8634b6218b2565:

  pico-imx7d: Increase the CONFIG_ENV_OFFSET size (2018-12-17 16:51:02
+0100)


imx for 2019.01

- introduce support for i.MX8M
- fix size limit for Vhybrid / pico boards
- several board fixes
- w1 driver for MX2x / MX5x


Denis Zalevskiy (6):
  board: ge: Remove EEPROM bus param from read_vpd()
  board: ge: Move VPD EEPROM configuration to the defconfig
  bootcount: i2c: Add bus switching to the I2C bootcount driver
  bootcount: Configure length limit for I2C bootcount
  board: ge: Move VPD reading to the vpd_reader
  board: ge: Store bootcount in EEPROM on PPD and Bx50v3

Fabien Lahoudere (1):
  embestmx6boards: Add SPL support

Fabio Estevam (1):
  pico-imx7d: Increase the CONFIG_ENV_OFFSET size

Gary Bisson (2):
  imx: mx8m: add memory mapping for CAAM and TCM
  imx: bootaux: fix stack and pc assignment on 64-bit platforms

Harald Seiler (1):
  pcm058: fix NAND flash not using badblock table

Lukasz Majewski (6):
  ARM: vybrid: Provide pinctrl driver for Vybrid (vf610)
  ARM: DTS: Add iomux node to vf.dtsi for Vybrid devices
  ARM: DTS: Provide pinfunc definitions for vybrid vf610 from Linux
kernel
  nand: vybrid: Use calloc() instead of malloc() to allocate struct nfc
  Kconfig: Add entry for VF610 NAND NFC device tree aware driver
  nand: vybrid: Extend the vf610 NFC NAND driver to support device
tree (and DM)

Martin Fuzzey (1):
  w1: Add driver for i.MX bus master controller

Martin Husemann (1):
  tools: improve portability of imx_cntr_image.sh

Michael Heimpold (4):
  configs: mx23_olinuxino_defconfig: fix status led definition
  configs: mx23_olinuxino_defconfig: disable bootefi command
  doc: imx: fix typo in imximage.txt
  doc: imx: fix typos in mxsimage.txt

Parthiban Nallathambi (1):
  imx: hab: extend hab_auth_img to calculate ivt_offset

Peng Fan (19):
  imx: imx8qxp_mek: imximage: remove config.h
  spl: introduce function prototypes
  tools: add i.MX8M image support
  arm: imx8qxp: build u-boot-dtb.cfgout before checking files
  Introduce CONFIG_FIT_EXTERNAL_OFFSET
  imx: cpu: add CHIP_REV_2_1 macro
  imx: introduce is_imx8mq helper
  imx: rename mx8m,MX8M to imx8m,IMX8M
  imx: spl: add MMC BOOT Device for i.MX8M
  imx: imx8m: clock refactor dram pll part
  imx: imx8m: introduce script to generate fit image
  imx: imx8m: introduce imximage cfg file
  imx: imx8mq: build flash.bin
  imx: imx8m: not build bootaux when building SPL
  imx: imx8m: add lpddr4 header file
  drivers: ddr: introduce DDR driver for i.MX8M
  imx: add i.MX8MQ EVK support
  imx8m: ddr: removed unused macros
  imx: mx53ppd: fix build error

Pierre-Jean Texier (1):
  warp7: configs: add CONFIG_FIT option

Xiaoliang Yang (2):
  watchdog: driver support for fsl-lsch2
  watchdog: imx: add config to disable wdog reset

Yaniv Levinsky (1):
  arm: imx7d: cl-som-imx7: migration to CONFIG_BLK

Ye Li (2):
  SPL: Add HAB image authentication to FIT
  imx8m: Enable CONFIG_SPL_FIT_IMAGE_TINY for iMX8M

 Kconfig
   |   10 ++
 Makefile
   |7 +-
 arch/arm/Kconfig
   |4 +-
 arch/arm/Makefile
   |4 +-
 arch/arm/cpu/armv8/fsl-layerscape/doc/README.lsch2
   |   11 ++
 arch/arm/dts/Makefile
   |2 +
 arch/arm/dts/fsl-imx8mq-evk.dts
   |  414 ++
 arch/arm/dts/vf.dtsi
   |6 +
 arch/arm/dts/vf610-pinfunc.h
   |  810

 arch/arm/include/asm/arch-imx/cpu.h
   |5 +-
 arch/arm/include/asm/{arch-mx8m => arch-imx8m}/clock.h
   |   22 
 arch/arm/include/asm/{arch-mx8m => arch-imx8m}/crm_regs.h
   |4 +-
 arch/arm/include/asm/arch-imx8m/ddr.h
   |  740
+
 arch/arm/include/asm/{arch-mx8m => arch-imx8m}/gpio.h
   |4 +-
 arch/arm/include/asm/{arch-mx8m => arch-imx8m}/imx-regs.h
   |4 +-
 arch/arm/include/asm/{arch-mx8m/mx8mq_pins.h =>
arch-imx8m/imx8mq_pins.h} |4 +-
 arch/arm/include/asm/arch-imx8m/

Re: [U-Boot] Please pull u-boot-imx: u-boot-imx-20181217

2018-12-17 Thread Stefano Babic
On 17/12/18 16:47, Fabio Estevam wrote:
> Hi Stefano,
> 
> On Mon, Dec 17, 2018 at 1:43 PM Stefano Babic  wrote:
>>
>> Hi Tom,
>>
>> this is like u-boot-imx-20191214 with:
>>
>> - fix missing MAINTANERS for embestmx6boards
>> - drop Wolfgang's patch
>> - apply V3 of "pico-imx7d: Increase the CONFIG_ENV_OFFSET size " that
>> use fix values for size.
> 
> v3 is wrong because it does not take the u-boot.img 69k offset into account.
> 
> v4 is correct the correct one:
> http://u-boot.10912.n7.nabble.com/PATCH-v4-pico-imx7d-Increase-the-CONFIG-ENV-OFFSET-size-td350166.html

Ouch... thanks ! Tom, please ignore PR, I pick V4 up.

Regards,
Stefano


-- 
=
DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sba...@denx.de
=
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] Please pull u-boot-imx: u-boot-imx-20181217

2018-12-17 Thread Fabio Estevam
Hi Stefano,

On Mon, Dec 17, 2018 at 1:43 PM Stefano Babic  wrote:
>
> Hi Tom,
>
> this is like u-boot-imx-20191214 with:
>
> - fix missing MAINTANERS for embestmx6boards
> - drop Wolfgang's patch
> - apply V3 of "pico-imx7d: Increase the CONFIG_ENV_OFFSET size " that
> use fix values for size.

v3 is wrong because it does not take the u-boot.img 69k offset into account.

v4 is correct the correct one:
http://u-boot.10912.n7.nabble.com/PATCH-v4-pico-imx7d-Increase-the-CONFIG-ENV-OFFSET-size-td350166.html

Thanks
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] Please pull u-boot-imx: u-boot-imx-20181217

2018-12-17 Thread Stefano Babic
Hi Tom,

this is like u-boot-imx-20191214 with:

- fix missing MAINTANERS for embestmx6boards
- drop Wolfgang's patch
- apply V3 of "pico-imx7d: Increase the CONFIG_ENV_OFFSET size " that
use fix values for size.


The following changes since commit d117d8f19b0625f88309e47a8a32c2faa384dddc:

  Merge branch 'master' of git://git.denx.de/u-boot-i2c (2018-12-13
09:36:55 -0500)

are available in the Git repository at:

  git://www.denx.de/git/u-boot-imx.git tags/u-boot-imx-20181217

for you to fetch changes up to 2e3690b18ae968ce44e72b5ff12051ad75be899e:

  pico-imx7d: Increase the CONFIG_ENV_OFFSET size (2018-12-17 16:34:31
+0100)


imx for 2019.01

- introduce support for i.MX8M
- fix size limit for Vhybrid / pico boards
- several board fixes
- w1 driver for MX2x / MX5x


Denis Zalevskiy (6):
  board: ge: Remove EEPROM bus param from read_vpd()
  board: ge: Move VPD EEPROM configuration to the defconfig
  bootcount: i2c: Add bus switching to the I2C bootcount driver
  bootcount: Configure length limit for I2C bootcount
  board: ge: Move VPD reading to the vpd_reader
  board: ge: Store bootcount in EEPROM on PPD and Bx50v3

Fabien Lahoudere (1):
  embestmx6boards: Add SPL support

Fabio Estevam (1):
  pico-imx7d: Increase the CONFIG_ENV_OFFSET size

Gary Bisson (2):
  imx: mx8m: add memory mapping for CAAM and TCM
  imx: bootaux: fix stack and pc assignment on 64-bit platforms

Harald Seiler (1):
  pcm058: fix NAND flash not using badblock table

Lukasz Majewski (6):
  ARM: vybrid: Provide pinctrl driver for Vybrid (vf610)
  ARM: DTS: Add iomux node to vf.dtsi for Vybrid devices
  ARM: DTS: Provide pinfunc definitions for vybrid vf610 from Linux
kernel
  nand: vybrid: Use calloc() instead of malloc() to allocate struct nfc
  Kconfig: Add entry for VF610 NAND NFC device tree aware driver
  nand: vybrid: Extend the vf610 NFC NAND driver to support device
tree (and DM)

Martin Fuzzey (1):
  w1: Add driver for i.MX bus master controller

Martin Husemann (1):
  tools: improve portability of imx_cntr_image.sh

Michael Heimpold (4):
  configs: mx23_olinuxino_defconfig: fix status led definition
  configs: mx23_olinuxino_defconfig: disable bootefi command
  doc: imx: fix typo in imximage.txt
  doc: imx: fix typos in mxsimage.txt

Parthiban Nallathambi (1):
  imx: hab: extend hab_auth_img to calculate ivt_offset

Peng Fan (19):
  imx: imx8qxp_mek: imximage: remove config.h
  spl: introduce function prototypes
  tools: add i.MX8M image support
  arm: imx8qxp: build u-boot-dtb.cfgout before checking files
  Introduce CONFIG_FIT_EXTERNAL_OFFSET
  imx: cpu: add CHIP_REV_2_1 macro
  imx: introduce is_imx8mq helper
  imx: rename mx8m,MX8M to imx8m,IMX8M
  imx: spl: add MMC BOOT Device for i.MX8M
  imx: imx8m: clock refactor dram pll part
  imx: imx8m: introduce script to generate fit image
  imx: imx8m: introduce imximage cfg file
  imx: imx8mq: build flash.bin
  imx: imx8m: not build bootaux when building SPL
  imx: imx8m: add lpddr4 header file
  drivers: ddr: introduce DDR driver for i.MX8M
  imx: add i.MX8MQ EVK support
  imx8m: ddr: removed unused macros
  imx: mx53ppd: fix build error

Pierre-Jean Texier (1):
  warp7: configs: add CONFIG_FIT option

Xiaoliang Yang (2):
  watchdog: driver support for fsl-lsch2
  watchdog: imx: add config to disable wdog reset

Yaniv Levinsky (1):
  arm: imx7d: cl-som-imx7: migration to CONFIG_BLK

Ye Li (2):
  SPL: Add HAB image authentication to FIT
  imx8m: Enable CONFIG_SPL_FIT_IMAGE_TINY for iMX8M

 Kconfig
   |   10 ++
 Makefile
   |7 +-
 arch/arm/Kconfig
   |4 +-
 arch/arm/Makefile
   |4 +-
 arch/arm/cpu/armv8/fsl-layerscape/doc/README.lsch2
   |   11 ++
 arch/arm/dts/Makefile
   |2 +
 arch/arm/dts/fsl-imx8mq-evk.dts
   |  414 ++
 arch/arm/dts/vf.dtsi
   |6 +
 arch/arm/dts/vf610-pinfunc.h
   |  810

 arch/arm/include/asm/arch-imx/cpu.h
   |5 +-
 arch/arm/include/asm/{arch-mx8m => arch-imx8m}/clock.h
   |   22 
 arch/arm/include/asm/{arch-mx8m => arch-imx8m}/crm_regs.h
   |4 +-
 arch/arm/include/asm/arch-imx8m/ddr.h
   |  740
+
 arch/arm/include/asm/{arch-mx8m => arch-imx8m}/gpio.h
   |4 +-
 arch/arm/include/asm/{arch-mx8m => arch-imx8m}/imx-regs.h
   |4 +-
 arch/arm/include/asm/{arch-mx8m/mx8mq_pins.h =>
arch-imx8m/imx8mq_pins.h} |4 +-
 arch/arm/include/asm/arch-imx8m/lpddr4_define.h
   |   

[U-Boot] [PATCH v4 03/10] arm: mvebu: turris_mox: Check and configure modules

2018-12-17 Thread Marek Behún
Check if Mox modules are connected in supported mode, then configure
the MDIO addresses of switch modules.

Signed-off-by: Marek Behún 
---
 arch/arm/dts/armada-3720-turris-mox.dts |  11 ++
 board/CZ.NIC/turris_mox/turris_mox.c| 234 +++-
 2 files changed, 244 insertions(+), 1 deletion(-)

diff --git a/arch/arm/dts/armada-3720-turris-mox.dts 
b/arch/arm/dts/armada-3720-turris-mox.dts
index 7babc16679..ff54ce5d0f 100644
--- a/arch/arm/dts/armada-3720-turris-mox.dts
+++ b/arch/arm/dts/armada-3720-turris-mox.dts
@@ -110,6 +110,17 @@
spi-max-frequency = <2000>;
m25p,fast-read;
};
+
+   moxtet@1 {
+   #address-cells = <1>;
+   #size-cells = <0>;
+   compatible = "cznic,moxtet";
+   reg = <1>;
+   reset-gpios = < 2 GPIO_ACTIVE_LOW>;
+   spi-max-frequency = <100>;
+   spi-cpol;
+   spi-cpha;
+   };
 };
 
  {
diff --git a/board/CZ.NIC/turris_mox/turris_mox.c 
b/board/CZ.NIC/turris_mox/turris_mox.c
index 3c0ab58756..4426ee3446 100644
--- a/board/CZ.NIC/turris_mox/turris_mox.c
+++ b/board/CZ.NIC/turris_mox/turris_mox.c
@@ -4,11 +4,13 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -239,11 +241,138 @@ int comphy_update_map(struct comphy_map *serdes_map, int 
count)
return 0;
 }
 
+#define SW_SMI_CMD_R(d, r) (0x9800 | (((d) & 0x1f) << 5) | ((r) & 0x1f))
+#define SW_SMI_CMD_W(d, r) (0x9400 | (((d) & 0x1f) << 5) | ((r) & 0x1f))
+
+static int sw_multi_read(struct mii_dev *bus, int sw, int dev, int reg)
+{
+   bus->write(bus, sw, 0, 0, SW_SMI_CMD_R(dev, reg));
+   mdelay(5);
+   return bus->read(bus, sw, 0, 1);
+}
+
+static void sw_multi_write(struct mii_dev *bus, int sw, int dev, int reg,
+  u16 val)
+{
+   bus->write(bus, sw, 0, 1, val);
+   bus->write(bus, sw, 0, 0, SW_SMI_CMD_W(dev, reg));
+   mdelay(5);
+}
+
+static int sw_scratch_read(struct mii_dev *bus, int sw, int reg)
+{
+   sw_multi_write(bus, sw, 0x1c, 0x1a, (reg & 0x7f) << 8);
+   return sw_multi_read(bus, sw, 0x1c, 0x1a) & 0xff;
+}
+
+static void sw_led_write(struct mii_dev *bus, int sw, int port, int reg,
+u16 val)
+{
+   sw_multi_write(bus, sw, port, 0x16, 0x8000 | ((reg & 7) << 12)
+   | (val & 0x7ff));
+}
+
+static void sw_blink_leds(struct mii_dev *bus, int peridot, int topaz)
+{
+   int i, p;
+   struct {
+   int port;
+   u16 val;
+   int wait;
+   } regs[] = {
+   { 2, 0xef, 1 }, { 2, 0xfe, 1 }, { 2, 0x33, 0 },
+   { 4, 0xef, 1 }, { 4, 0xfe, 1 }, { 4, 0x33, 0 },
+   { 3, 0xfe, 1 }, { 3, 0xef, 1 }, { 3, 0x33, 0 },
+   { 1, 0xfe, 1 }, { 1, 0xef, 1 }, { 1, 0x33, 0 }
+   };
+
+   for (i = 0; i < 12; ++i) {
+   for (p = 0; p < peridot; ++p) {
+   sw_led_write(bus, 0x10 + p, regs[i].port, 0,
+regs[i].val);
+   sw_led_write(bus, 0x10 + p, regs[i].port + 4, 0,
+regs[i].val);
+   }
+   if (topaz) {
+   sw_led_write(bus, 0x2, 0x10 + regs[i].port, 0,
+regs[i].val);
+   }
+
+   if (regs[i].wait)
+   mdelay(75);
+   }
+}
+
+static void check_switch_address(struct mii_dev *bus, int addr)
+{
+   if (sw_scratch_read(bus, addr, 0x70) >> 3 != addr)
+   printf("Check of switch MDIO address failed for 0x%02x\n",
+  addr);
+}
+
+static int sfp, pci, topaz, peridot, usb, passpci;
+static int sfp_pos, peridot_pos[3];
+static int module_count;
+
+static int configure_peridots(struct gpio_desc *reset_gpio)
+{
+   int i, ret;
+   u8 dout[MAX_MOX_MODULES];
+
+   memset(dout, 0, MAX_MOX_MODULES);
+
+   /* set addresses of Peridot modules */
+   for (i = 0; i < peridot; ++i)
+   dout[module_count - peridot_pos[i]] = (~i) & 3;
+
+   /*
+* if there is a SFP module connected to the last Peridot module, set
+* the P10_SMODE to 1 for the Peridot module
+*/
+   if (sfp)
+   dout[module_count - peridot_pos[i - 1]] |= 1 << 3;
+
+   dm_gpio_set_value(reset_gpio, 1);
+   mdelay(10);
+
+   ret = mox_do_spi(NULL, dout, module_count + 1);
+
+   mdelay(10);
+   dm_gpio_set_value(reset_gpio, 0);
+
+   mdelay(50);
+
+   return ret;
+}
+
+static int get_reset_gpio(struct gpio_desc *reset_gpio)
+{
+   int node;
+
+   node = fdt_node_offset_by_compatible(gd->fdt_blob, 0, "cznic,moxtet");
+   if (node < 0) {
+   printf("Cannot find Moxtet bus device node!\n");
+   return -1;
+   

[U-Boot] [PATCH v4 09/10] arm: mvebu: turris_mox: Support 1 GB version of Turris Mox

2018-12-17 Thread Marek Behún
Use get_ram_size to determine if the RAM size on Turris Mox is 512 MiB
or 1 GiB.

Signed-off-by: Marek Behún 
---
 arch/arm/mach-mvebu/arm64-common.c   |  4 ++--
 board/CZ.NIC/turris_mox/turris_mox.c | 16 
 2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/arch/arm/mach-mvebu/arm64-common.c 
b/arch/arm/mach-mvebu/arm64-common.c
index 47bbf69944..aaf7b7c447 100644
--- a/arch/arm/mach-mvebu/arm64-common.c
+++ b/arch/arm/mach-mvebu/arm64-common.c
@@ -84,7 +84,7 @@ static void a8k_dram_init_banksize(void)
}
 }
 
-int dram_init_banksize(void)
+__weak int dram_init_banksize(void)
 {
if (CONFIG_IS_ENABLED(ARMADA_8K))
a8k_dram_init_banksize();
@@ -94,7 +94,7 @@ int dram_init_banksize(void)
return 0;
 }
 
-int dram_init(void)
+__weak int dram_init(void)
 {
if (CONFIG_IS_ENABLED(ARMADA_8K)) {
gd->ram_size = a8k_dram_scan_ap_sz();
diff --git a/board/CZ.NIC/turris_mox/turris_mox.c 
b/board/CZ.NIC/turris_mox/turris_mox.c
index d16d6fd124..65d50a92dd 100644
--- a/board/CZ.NIC/turris_mox/turris_mox.c
+++ b/board/CZ.NIC/turris_mox/turris_mox.c
@@ -41,6 +41,22 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
+int dram_init(void)
+{
+   gd->ram_base = 0;
+   gd->ram_size = (phys_size_t)get_ram_size(0, 0x4000);
+
+   return 0;
+}
+
+int dram_init_banksize(void)
+{
+   gd->bd->bi_dram[0].start = (phys_addr_t)0;
+   gd->bd->bi_dram[0].size = gd->ram_size;
+
+   return 0;
+}
+
 #if defined(CONFIG_OF_BOARD_FIXUP)
 int board_fix_fdt(void *blob)
 {
-- 
2.18.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v4 06/10] watchdog: armada_37xx: Fix compliance with kernel's driver

2018-12-17 Thread Marek Behún
The Armada 37xx watchdog driver was recently accepted for mainline
kernel by watchdog subsystem maintainer, but the driver works a little
different than the one in U-Boot. This patch fixes this.

In the previous implementation there was a tiny period of time when the
watchdog was disabled and the system was vulnerables - this was during
pinging, which was done by disabling, setting, and enabling the counter.

Now pinging is done without disabling the watchdog. We use 2 counters:
Counter 1 is the watchdog counter - on expiry, the system is reset.
Counter 0 is used to reset Counter 1 to start counting from the set
timeout again. So Counter 1 is set to be reset on Counter 0 expiry event
event and pinging is done by forcing an immediate expiry event on
Counter 0.

Signed-off-by: Marek Behún 
---
 drivers/watchdog/armada-37xx-wdt.c | 109 ++---
 1 file changed, 67 insertions(+), 42 deletions(-)

diff --git a/drivers/watchdog/armada-37xx-wdt.c 
b/drivers/watchdog/armada-37xx-wdt.c
index 0fa4fda4fc..91cd8a6e6a 100644
--- a/drivers/watchdog/armada-37xx-wdt.c
+++ b/drivers/watchdog/armada-37xx-wdt.c
@@ -22,42 +22,63 @@ struct a37xx_wdt {
 };
 
 /*
- * We use Counter 1 for watchdog timer, because so does Marvell's Linux by
- * default.
+ * We use Counter 1 as watchdog timer, and Counter 0 for re-triggering Counter 
1
  */
 
-#define CNTR_CTRL  0x10
+#define CNTR_CTRL(id)  ((id) * 0x10)
 #define CNTR_CTRL_ENABLE   0x0001
 #define CNTR_CTRL_ACTIVE   0x0002
 #define CNTR_CTRL_MODE_MASK0x000c
 #define CNTR_CTRL_MODE_ONESHOT 0x
+#define CNTR_CTRL_MODE_HWSIG   0x000c
+#define CNTR_CTRL_TRIG_SRC_MASK0x00f0
+#define CNTR_CTRL_TRIG_SRC_PREV_CNTR   0x0050
 #define CNTR_CTRL_PRESCALE_MASK0xff00
 #define CNTR_CTRL_PRESCALE_MIN 2
 #define CNTR_CTRL_PRESCALE_SHIFT   8
 
-#define CNTR_COUNT_LOW 0x14
-#define CNTR_COUNT_HIGH0x18
+#define CNTR_COUNT_LOW(id) (CNTR_CTRL(id) + 0x4)
+#define CNTR_COUNT_HIGH(id)(CNTR_CTRL(id) + 0x8)
 
-static void set_counter_value(struct a37xx_wdt *priv)
+static void set_counter_value(struct a37xx_wdt *priv, int id, u64 val)
 {
-   writel(priv->timeout & 0x, priv->reg + CNTR_COUNT_LOW);
-   writel(priv->timeout >> 32, priv->reg + CNTR_COUNT_HIGH);
+   writel(val & 0x, priv->reg + CNTR_COUNT_LOW(id));
+   writel(val >> 32, priv->reg + CNTR_COUNT_HIGH(id));
 }
 
-static void a37xx_wdt_enable(struct a37xx_wdt *priv)
+static void counter_enable(struct a37xx_wdt *priv, int id)
 {
-   u32 reg = readl(priv->reg + CNTR_CTRL);
+   setbits_le32(priv->reg + CNTR_CTRL(id), CNTR_CTRL_ENABLE);
+}
 
-   reg |= CNTR_CTRL_ENABLE;
-   writel(reg, priv->reg + CNTR_CTRL);
+static void counter_disable(struct a37xx_wdt *priv, int id)
+{
+   clrbits_le32(priv->reg + CNTR_CTRL(id), CNTR_CTRL_ENABLE);
 }
 
-static void a37xx_wdt_disable(struct a37xx_wdt *priv)
+static int init_counter(struct a37xx_wdt *priv, int id, u32 mode, u32 trig_src)
 {
-   u32 reg = readl(priv->reg + CNTR_CTRL);
+   u32 reg;
+
+   reg = readl(priv->reg + CNTR_CTRL(id));
+   if (reg & CNTR_CTRL_ACTIVE)
+   return -EBUSY;
+
+   reg &= ~(CNTR_CTRL_MODE_MASK | CNTR_CTRL_PRESCALE_MASK |
+CNTR_CTRL_TRIG_SRC_MASK);
+
+   /* set mode */
+   reg |= mode;
+
+   /* set prescaler to the min value */
+   reg |= CNTR_CTRL_PRESCALE_MIN << CNTR_CTRL_PRESCALE_SHIFT;
+
+   /* set trigger source */
+   reg |= trig_src;
 
-   reg &= ~CNTR_CTRL_ENABLE;
-   writel(reg, priv->reg + CNTR_CTRL);
+   writel(reg, priv->reg + CNTR_CTRL(id));
+
+   return 0;
 }
 
 static int a37xx_wdt_reset(struct udevice *dev)
@@ -67,9 +88,9 @@ static int a37xx_wdt_reset(struct udevice *dev)
if (!priv->timeout)
return -EINVAL;
 
-   a37xx_wdt_disable(priv);
-   set_counter_value(priv);
-   a37xx_wdt_enable(priv);
+   /* counter 1 is retriggered by forcing end count on counter 0 */
+   counter_disable(priv, 0);
+   counter_enable(priv, 0);
 
return 0;
 }
@@ -78,10 +99,14 @@ static int a37xx_wdt_expire_now(struct udevice *dev, ulong 
flags)
 {
struct a37xx_wdt *priv = dev_get_priv(dev);
 
-   a37xx_wdt_disable(priv);
-   priv->timeout = 0;
-   set_counter_value(priv);
-   a37xx_wdt_enable(priv);
+   /* first we set timeout to 0 */
+   counter_disable(priv, 1);
+   set_counter_value(priv, 1, 0);
+   counter_enable(priv, 1);
+
+   /* and then we start counter 1 by forcing end count on counter 0 */
+   counter_disable(priv, 0);
+   counter_enable(priv, 0);
 
return 0;
 }
@@ -89,26 +114,25 @@ static int a37xx_wdt_expire_now(struct udevice *dev, ulong 
flags)
 static int a37xx_wdt_start(struct udevice *dev, u64 ms, ulong flags)
 {

[U-Boot] [PATCH v4 10/10] arm: mvebu: configs: turris_mox: Add 64 MiB of boot memory

2018-12-17 Thread Marek Behún
This is needed for some scenarios, such as booting large FIT image.

Signed-off-by: Marek Behún 
Reviewed-by: Stefan Roese 
---
 include/configs/turris_mox.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/include/configs/turris_mox.h b/include/configs/turris_mox.h
index 0aebe2100b..82cdccecc1 100644
--- a/include/configs/turris_mox.h
+++ b/include/configs/turris_mox.h
@@ -8,6 +8,8 @@
 #ifndef _CONFIG_TURRIS_MOX_H
 #define _CONFIG_TURRIS_MOX_H
 
+#define CONFIG_SYS_BOOTM_LEN (64 << 20)
+
 #define CONFIG_LAST_STAGE_INIT
 
 /*
-- 
2.18.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v4 05/10] arm: mvebu: turris_mox: Update defconfig

2018-12-17 Thread Marek Behún
Add gpio command to defconfig - this can be used to detect whether the
button is pressed or light LEDs.
Add DS1307 RTC driver and the date command.
Add CONFIG_WATCHDOG, so that U-Boot calls watchdog_reset.
Add CONFIG_MISC_INIT_R so that ethernet addresses are read from OTP
before network controller is initialized.

Signed-off-by: Marek Behún 
Reviewed-by: Stefan Roese 
---
 configs/turris_mox_defconfig | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/configs/turris_mox_defconfig b/configs/turris_mox_defconfig
index 749ed31acd..e89e6617ca 100644
--- a/configs/turris_mox_defconfig
+++ b/configs/turris_mox_defconfig
@@ -13,7 +13,9 @@ CONFIG_SYS_CONSOLE_INFO_QUIET=y
 # CONFIG_DISPLAY_CPUINFO is not set
 # CONFIG_DISPLAY_BOARDINFO is not set
 CONFIG_ARCH_EARLY_INIT_R=y
+CONFIG_MISC_INIT_R=y
 CONFIG_CMD_CLK=y
+CONFIG_CMD_GPIO=y
 # CONFIG_CMD_FLASH is not set
 CONFIG_CMD_I2C=y
 CONFIG_CMD_MMC=y
@@ -24,6 +26,7 @@ CONFIG_CMD_USB=y
 # CONFIG_CMD_SETEXPR is not set
 CONFIG_CMD_TFTPPUT=y
 CONFIG_CMD_CACHE=y
+CONFIG_CMD_DATE=y
 CONFIG_CMD_TIME=y
 CONFIG_CMD_MVEBU_BUBT=y
 CONFIG_CMD_BTRFS=y
@@ -63,6 +66,8 @@ CONFIG_DEBUG_UART_SHIFT=2
 CONFIG_DEBUG_UART_ANNOUNCE=y
 CONFIG_MVEBU_A3700_UART=y
 CONFIG_MVEBU_A3700_SPI=y
+CONFIG_DM_RTC=y
+CONFIG_RTC_DS1307=y
 CONFIG_USB=y
 CONFIG_DM_USB=y
 CONFIG_USB_XHCI_HCD=y
@@ -73,6 +78,7 @@ CONFIG_USB_ETHER_ASIX=y
 CONFIG_USB_ETHER_MCS7830=y
 CONFIG_USB_ETHER_RTL8152=y
 CONFIG_USB_ETHER_SMSC95XX=y
+CONFIG_WATCHDOG=y
 CONFIG_WDT=y
 CONFIG_WDT_ARMADA_37XX=y
 CONFIG_SHA1=y
-- 
2.18.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v4 07/10] MAINTAINERS: Add entry for CZ.NIC's Turris project

2018-12-17 Thread Marek Behún
Add myself as the maintainer of CZ.NIC's Turris Omnia and Turris Mox
projects.

Signed-off-by: Marek Behún 
Reviewed-by: Stefan Roese 
---
 MAINTAINERS | 8 
 1 file changed, 8 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 0fb089807c..83f7d8fc08 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -120,6 +120,14 @@ F: doc/README.bcm7xxx
 F: drivers/mmc/bcmstb_sdhci.c
 F: drivers/spi/bcmstb_spi.c
 
+ARM/CZ.NIC TURRIS MOX SUPPORT
+M: Marek Behun 
+S: Maintained
+F: arch/arm/dts/armada-3720-turris-mox.dts
+F: board/CZ.NIC/
+F: configs/turris_*_defconfig
+F: include/configs/turris_*.h
+
 ARM FREESCALE IMX
 M: Stefano Babic 
 M: Fabio Estevam 
-- 
2.18.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v4 08/10] arm: mvebu: turris_mox: Read info (and ethaddrs) from OTP

2018-12-17 Thread Marek Behún
Add support for reading One-Time Programmable memory via mailbox, which
communicates with CZ.NIC's firmware on the Secure Processor (Cortex-M3)
of Armada 3720.

Display product serial number and additional info, and also set MAC
addresses.

Signed-off-by: Marek Behún 
Reviewed-by: Stefan Roese 
---
 board/CZ.NIC/turris_mox/Makefile |   2 +-
 board/CZ.NIC/turris_mox/mox_sp.c | 136 +++
 board/CZ.NIC/turris_mox/mox_sp.h |  15 +++
 board/CZ.NIC/turris_mox/turris_mox.c |  55 ++-
 4 files changed, 205 insertions(+), 3 deletions(-)
 create mode 100644 board/CZ.NIC/turris_mox/mox_sp.c
 create mode 100644 board/CZ.NIC/turris_mox/mox_sp.h

diff --git a/board/CZ.NIC/turris_mox/Makefile b/board/CZ.NIC/turris_mox/Makefile
index 619704288b..33a52b63d7 100644
--- a/board/CZ.NIC/turris_mox/Makefile
+++ b/board/CZ.NIC/turris_mox/Makefile
@@ -2,4 +2,4 @@
 #
 # Copyright (C) 2018 Marek Behun 
 
-obj-y  := turris_mox.o
+obj-y  := turris_mox.o mox_sp.o
diff --git a/board/CZ.NIC/turris_mox/mox_sp.c b/board/CZ.NIC/turris_mox/mox_sp.c
new file mode 100644
index 00..0b29ffcc67
--- /dev/null
+++ b/board/CZ.NIC/turris_mox/mox_sp.c
@@ -0,0 +1,136 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2018 Marek Behun 
+ */
+
+#include 
+#include 
+
+#define RWTM_CMD_PARAM(i)  (size_t)(0xd00b + (i) * 4)
+#define RWTM_CMD   0xd00b0040
+#define RWTM_CMD_RETSTATUS 0xd00b0080
+#define RWTM_CMD_STATUS(i) (size_t)(0xd00b0084 + (i) * 4)
+
+#define RWTM_HOST_INT_RESET0xd00b00c8
+#define RWTM_HOST_INT_MASK 0xd00b00cc
+#define SP_CMD_COMPLETEBIT(0)
+
+#define MBOX_STS_SUCCESS   (0x0 << 30)
+#define MBOX_STS_FAIL  (0x1 << 30)
+#define MBOX_STS_BADCMD(0x2 << 30)
+#define MBOX_STS_LATER (0x3 << 30)
+#define MBOX_STS_ERROR(s)  ((s) & (3 << 30))
+#define MBOX_STS_VALUE(s)  (((s) >> 10) & 0xf)
+#define MBOX_STS_CMD(s)((s) & 0x3ff)
+
+enum mbox_cmd {
+   MBOX_CMD_GET_RANDOM = 1,
+   MBOX_CMD_BOARD_INFO,
+   MBOX_CMD_ECDSA_PUB_KEY,
+   MBOX_CMD_HASH,
+   MBOX_CMD_SIGN,
+   MBOX_CMD_VERIFY,
+
+   MBOX_CMD_OTP_READ,
+   MBOX_CMD_OTP_WRITE
+};
+
+static int mbox_do_cmd(enum mbox_cmd cmd, u32 *out, int nout)
+{
+   const int tries = 50;
+   int i;
+   u32 status;
+
+   clrbits_le32(RWTM_HOST_INT_MASK, SP_CMD_COMPLETE);
+
+   writel(cmd, RWTM_CMD);
+
+   for (i = 0; i < tries; ++i) {
+   mdelay(10);
+   if (readl(RWTM_HOST_INT_RESET) & SP_CMD_COMPLETE)
+   break;
+   }
+
+   if (i == tries) {
+   /* if timed out, don't read status */
+   setbits_le32(RWTM_HOST_INT_RESET, SP_CMD_COMPLETE);
+   return -ETIMEDOUT;
+   }
+
+   for (i = 0; i < nout; ++i)
+   out[i] = readl(RWTM_CMD_STATUS(i));
+   status = readl(RWTM_CMD_RETSTATUS);
+
+   setbits_le32(RWTM_HOST_INT_RESET, SP_CMD_COMPLETE);
+
+   if (MBOX_STS_CMD(status) != cmd)
+   return -EIO;
+   else if (MBOX_STS_ERROR(status) == MBOX_STS_FAIL)
+   return -(int)MBOX_STS_VALUE(status);
+   else if (MBOX_STS_ERROR(status) != MBOX_STS_SUCCESS)
+   return -EIO;
+   else
+   return MBOX_STS_VALUE(status);
+}
+
+const char *mox_sp_get_ecdsa_public_key(void)
+{
+   static char public_key[135];
+   u32 out[16];
+   int res;
+
+   if (public_key[0])
+   return public_key;
+
+   res = mbox_do_cmd(MBOX_CMD_ECDSA_PUB_KEY, out, 16);
+   if (res < 0)
+   return NULL;
+
+   sprintf(public_key,
+   
"%06x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x",
+   (u32)res, out[0], out[1], out[2], out[3], out[4], out[5],
+   out[6], out[7], out[8], out[9], out[10], out[11], out[12],
+   out[13], out[14], out[15]);
+
+   return public_key;
+}
+
+static inline void res_to_mac(u8 *mac, u32 t1, u32 t2)
+{
+   mac[0] = t1 >> 8;
+   mac[1] = t1;
+   mac[2] = t2 >> 24;
+   mac[3] = t2 >> 16;
+   mac[4] = t2 >> 8;
+   mac[5] = t2;
+}
+
+int mbox_sp_get_board_info(u64 *sn, u8 *mac1, u8 *mac2, int *bv, int *ram)
+{
+   u32 out[8];
+   int res;
+
+   res = mbox_do_cmd(MBOX_CMD_BOARD_INFO, out, 8);
+   if (res < 0)
+   return res;
+
+   if (sn) {
+   *sn = out[1];
+   *sn <<= 32;
+   *sn |= out[0];
+   }
+
+   if (bv)
+   *bv = out[2];
+
+   if (ram)
+   *ram = out[3];
+
+   if (mac1)
+   res_to_mac(mac1, out[4], out[5]);
+
+   if (mac2)
+   res_to_mac(mac2, out[6], out[7]);
+
+   return 0;
+}
diff --git a/board/CZ.NIC/turris_mox/mox_sp.h b/board/CZ.NIC/turris_mox/mox_sp.h
new file mode 100644
index 

[U-Boot] [PATCH v4 02/10] arm: mvebu: turris_mox: Change SERDES map depending on module topology

2018-12-17 Thread Marek Behún
When SFP module is connected directly to CPU module we want the SGMII
lane speed at 1.25 Gbps.

This is a temporary solution till there is a comphy driver in the kernel
capable of changing SGMII speed at runtime.

Signed-off-by: Marek Behún 
Reviewed-by: Stefan Roese 
---
 board/CZ.NIC/turris_mox/turris_mox.c | 33 
 1 file changed, 33 insertions(+)

diff --git a/board/CZ.NIC/turris_mox/turris_mox.c 
b/board/CZ.NIC/turris_mox/turris_mox.c
index 415c462493..3c0ab58756 100644
--- a/board/CZ.NIC/turris_mox/turris_mox.c
+++ b/board/CZ.NIC/turris_mox/turris_mox.c
@@ -8,6 +8,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -206,6 +207,38 @@ static int mox_get_topology(const u8 **ptopology, int 
*psize, int *pis_sd)
return 0;
 }
 
+int comphy_update_map(struct comphy_map *serdes_map, int count)
+{
+   int ret, i, size, sfpindex = -1, swindex = -1;
+   const u8 *topology;
+
+   ret = mox_get_topology(, , NULL);
+   if (ret)
+   return ret;
+
+   for (i = 0; i < size; ++i) {
+   if (topology[i] == MOX_MODULE_SFP && sfpindex == -1)
+   sfpindex = i;
+   else if ((topology[i] == MOX_MODULE_TOPAZ ||
+ topology[i] == MOX_MODULE_PERIDOT) &&
+swindex == -1)
+   swindex = i;
+   }
+
+   if (sfpindex >= 0 && swindex >= 0) {
+   if (sfpindex < swindex)
+   serdes_map[0].speed = PHY_SPEED_1_25G;
+   else
+   serdes_map[0].speed = PHY_SPEED_3_125G;
+   } else if (sfpindex >= 0) {
+   serdes_map[0].speed = PHY_SPEED_1_25G;
+   } else if (swindex >= 0) {
+   serdes_map[0].speed = PHY_SPEED_3_125G;
+   }
+
+   return 0;
+}
+
 int last_stage_init(void)
 {
int ret, i;
-- 
2.18.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v4 01/10] arm: mvebu: turris_mox: Cosmetic restructurization

2018-12-17 Thread Marek Behún
Restructure the board initialization source.
Remove the module_topology environment variable since it won't be
needed.

Signed-off-by: Marek Behún 
Reviewed-by: Stefan Roese 
---
 board/CZ.NIC/turris_mox/turris_mox.c | 136 ++-
 1 file changed, 89 insertions(+), 47 deletions(-)

diff --git a/board/CZ.NIC/turris_mox/turris_mox.c 
b/board/CZ.NIC/turris_mox/turris_mox.c
index c4622a49c2..415c462493 100644
--- a/board/CZ.NIC/turris_mox/turris_mox.c
+++ b/board/CZ.NIC/turris_mox/turris_mox.c
@@ -135,17 +135,15 @@ int board_init(void)
return 0;
 }
 
-int last_stage_init(void)
+static int mox_do_spi(u8 *in, u8 *out, size_t size)
 {
struct spi_slave *slave;
struct udevice *dev;
-   u8 din[10], dout[10];
-   int ret, i;
-   size_t len = 0;
-   char module_topology[128];
+   int ret;
 
-   ret = spi_get_bus_and_cs(0, 1, 2000, SPI_CPHA, "spi_generic_drv",
-"mox-modules@1", , );
+   ret = spi_get_bus_and_cs(0, 1, 100, SPI_CPHA | SPI_CPOL,
+"spi_generic_drv", "moxtet@1", ,
+);
if (ret)
goto fail;
 
@@ -153,57 +151,101 @@ int last_stage_init(void)
if (ret)
goto fail_free;
 
-   memset(din, 0, 10);
-   memset(dout, 0, 10);
+   ret = spi_xfer(slave, size * 8, out, in, SPI_XFER_ONCE);
+
+   spi_release_bus(slave);
+fail_free:
+   spi_free_slave(slave);
+fail:
+   return ret;
+}
+
+static int mox_get_topology(const u8 **ptopology, int *psize, int *pis_sd)
+{
+   static int is_sd;
+   static u8 topology[MAX_MOX_MODULES - 1];
+   static int size;
+   u8 din[MAX_MOX_MODULES], dout[MAX_MOX_MODULES];
+   int ret, i;
 
-   ret = spi_xfer(slave, 80, dout, din, SPI_XFER_ONCE);
+   if (size) {
+   if (ptopology)
+   *ptopology = topology;
+   if (psize)
+   *psize = size;
+   if (pis_sd)
+   *pis_sd = is_sd;
+   return 0;
+   }
+
+   memset(din, 0, MAX_MOX_MODULES);
+   memset(dout, 0, MAX_MOX_MODULES);
+
+   ret = mox_do_spi(din, dout, MAX_MOX_MODULES);
if (ret)
-   goto fail_release;
+   return ret;
+
+   if (din[0] == 0x10)
+   is_sd = 1;
+   else if (din[0] == 0x00)
+   is_sd = 0;
+   else
+   return -ENODEV;
+
+   for (i = 1; i < MAX_MOX_MODULES && din[i] != 0xff; ++i)
+   topology[i - 1] = din[i] & 0xf;
+   size = i - 1;
+
+   if (ptopology)
+   *ptopology = topology;
+   if (psize)
+   *psize = size;
+   if (pis_sd)
+   *pis_sd = is_sd;
+
+   return 0;
+}
 
-   if (din[0] != 0x00 && din[0] != 0xff)
-   goto fail_release;
+int last_stage_init(void)
+{
+   int ret, i;
+   const u8 *topology;
+   int module_count, is_sd;
+
+   ret = mox_get_topology(, _count, _sd);
+   if (ret) {
+   printf("Cannot read module topology!\n");
+   return 0;
+   }
 
+   printf("Found Turris Mox %s version\n", is_sd ? "SD" : "eMMC");
printf("Module Topology:\n");
-   for (i = 1; i < 10 && din[i] != 0xff; ++i) {
-   u8 mid = din[i] & 0xf;
-   size_t mlen;
-   const char *mname = "";
-
-   switch (mid) {
-   case 0x1:
-   mname = "sfp-";
-   printf("% 4i: SFP Module\n", i);
+   for (i = 0; i < module_count; ++i) {
+   switch (topology[i]) {
+   case MOX_MODULE_SFP:
+   printf("% 4i: SFP Module\n", i + 1);
+   break;
+   case MOX_MODULE_PCI:
+   printf("% 4i: Mini-PCIe Module\n", i + 1);
+   break;
+   case MOX_MODULE_TOPAZ:
+   printf("% 4i: Topaz Switch Module (4-port)\n", i + 1);
break;
-   case 0x2:
-   mname = "pci-";
-   printf("% 4i: Mini-PCIe Module\n", i);
+   case MOX_MODULE_PERIDOT:
+   printf("% 4i: Peridot Switch Module (8-port)\n", i + 1);
break;
-   case 0x3:
-   mname = "topaz-";
-   printf("% 4i: Topaz Switch Module\n", i);
+   case MOX_MODULE_USB3:
+   printf("% 4i: USB 3.0 Module (4 ports)\n", i + 1);
+   break;
+   case MOX_MODULE_PASSPCI:
+   printf("% 4i: Passthrough Mini-PCIe Module\n", i + 1);
break;
default:
-   printf("% 4i: unknown (ID %i)\n", i, mid);
-   }
-
-   mlen = strlen(mname);
-   if (len 

[U-Boot] [PATCH v4 04/10] arm: mvebu: dts: Fix Turris Mox device tree

2018-12-17 Thread Marek Behún
DTC issues a warning because #address-cells and #size-cells properties
are not set in the mdio node.
Also add ethernet1 alias.
Also add RTC node.
Also fix USB3 regulator startup delay time.
Also fix PCI Express SERDES speed to 5 GHz (this is only cosmetic, the
speed value is not used byt the comphy driver for PCI Express, but
should be 5 GHz nonetheless).

Signed-off-by: Marek Behún 
Reviewed-by: Stefan Roese 
---
 arch/arm/dts/armada-3720-turris-mox.dts | 12 +++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/arch/arm/dts/armada-3720-turris-mox.dts 
b/arch/arm/dts/armada-3720-turris-mox.dts
index ff54ce5d0f..14bec0977e 100644
--- a/arch/arm/dts/armada-3720-turris-mox.dts
+++ b/arch/arm/dts/armada-3720-turris-mox.dts
@@ -24,6 +24,7 @@
 
aliases {
ethernet0 = 
+   ethernet1 = 
i2c0 = 
spi0 = 
};
@@ -38,12 +39,16 @@
regulator-name = "usb3-vbus";
regulator-min-microvolt = <500>;
regulator-max-microvolt = <500>;
+   startup-delay-us = <200>;
shutdown-delay-us = <100>;
gpio = < 0 GPIO_ACTIVE_HIGH>;
regulator-boot-on;
};
 
mdio {
+   #address-cells = <1>;
+   #size-cells = <0>;
+
eth_phy1: ethernet-phy@1 {
reg = <1>;
};
@@ -59,7 +64,7 @@
 
phy1 {
phy-type = ;
-   phy-speed = ;
+   phy-speed = ;
};
 
phy2 {
@@ -80,6 +85,11 @@
pinctrl-names = "default";
pinctrl-0 = <_pins>;
status = "okay";
+
+   rtc@6f {
+   compatible = "microchip,mcp7941x";
+   reg = <0x6f>;
+   };
 };
 
  {
-- 
2.18.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v4 00/10] Changes for Turris Mox

2018-12-17 Thread Marek Behún
This is the fourth version of patches for Turris Mox.

Changes from previous version:

- changed patch subject prefix from board: turris_mox to arm: mvebu: turris_mox 
as requested by Stefan

- added Reviewed-by Stefan

- add description of the changes for watchdog in patch 6

- patch 9 reworked to use get_ram_size instead of reading OTP

Marek


___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v4 6/7] MSCC: add board support for the Luton based evaluation board

2018-12-17 Thread Gregory CLEMENT
Hi Daniel,
 
 On lun., déc. 17 2018, Daniel Schwierzeck  wrote:

> Am 17.12.18 um 10:55 schrieb Gregory CLEMENT:
>> Hi Daniel,
>>  
>>  On dim., déc. 16 2018, Gregory CLEMENT  wrote:
>> 
>>> Hi Daniel,
>>>  
>>>  On sam., déc. 15 2018, Daniel Schwierzeck  
>>> wrote:
>>>
 Am 14.12.18 um 16:16 schrieb Gregory CLEMENT:
> Adding the support for the Luton boards PCB91 which share common code with
> the Ocelots boards, including board code, device tree and configuration.
>
> Signed-off-by: Gregory CLEMENT 
> ---
>  MAINTAINERS|  1 +
>  arch/mips/dts/luton_pcb091.dts | 36 ++
>  arch/mips/dts/mscc,luton.dtsi  | 87 ++
>  arch/mips/mach-mscc/Kconfig|  2 +
>  board/mscc/luton/Kconfig   | 14 ++
>  board/mscc/luton/Makefile  |  3 ++
>  board/mscc/luton/luton.c   | 28 +++
>  configs/mscc_luton_defconfig   | 66 ++
>  8 files changed, 237 insertions(+)
>  create mode 100644 arch/mips/dts/luton_pcb091.dts
>  create mode 100644 arch/mips/dts/mscc,luton.dtsi
>  create mode 100644 board/mscc/luton/Kconfig
>  create mode 100644 board/mscc/luton/Makefile
>  create mode 100644 board/mscc/luton/luton.c
>  create mode 100644 configs/mscc_luton_defconfig
>

> diff --git a/configs/mscc_luton_defconfig b/configs/mscc_luton_defconfig
> new file mode 100644
> index 00..47fe12b6ee
> --- /dev/null
> +++ b/configs/mscc_luton_defconfig
> @@ -0,0 +1,66 @@
> +CONFIG_MIPS=y
> +CONFIG_SYS_TEXT_BASE=0x4000
> +CONFIG_SYS_MALLOC_F_LEN=0x2000
> +CONFIG_DEBUG_UART_BOARD_INIT=y
> +CONFIG_DEBUG_UART_BASE=0x7010
> +CONFIG_DEBUG_UART_CLOCK=20833
> +CONFIG_ARCH_MSCC=y
> +CONFIG_TARGET_LUTON_PCB091=y
> +CONFIG_DDRTYPE_MT47H128M8HQ=y
> +CONFIG_SYS_LITTLE_ENDIAN=y
> +CONFIG_MIPS_BOOT_FDT=y
> +CONFIG_DEFAULT_DEVICE_TREE="luton_pcb091"
> +CONFIG_DEBUG_UART=y
> +CONFIG_FIT=y
> +CONFIG_BOOTDELAY=3
> +CONFIG_USE_BOOTARGS=y
> +CONFIG_BOOTARGS="console=ttyS0,115200"
> +CONFIG_LOGLEVEL=7
> +CONFIG_DISPLAY_CPUINFO=y
> +CONFIG_SYS_PROMPT="pcb091 # "
> +# CONFIG_CMD_BDI is not set
> +# CONFIG_CMD_CONSOLE is not set
> +# CONFIG_CMD_ELF is not set
> +# CONFIG_CMD_EXPORTENV is not set
> +# CONFIG_CMD_IMPORTENV is not set
> +# CONFIG_CMD_CRC32 is not set
> +CONFIG_CMD_MD5SUM=y
> +CONFIG_CMD_MEMINFO=y
> +CONFIG_CMD_MEMTEST=y
> +# CONFIG_CMD_FLASH is not set
> +CONFIG_CMD_GPIO=y
> +CONFIG_CMD_SF=y
> +CONFIG_CMD_SPI=y
> +CONFIG_CMD_DHCP=y
> +# CONFIG_NET_TFTP_VARS is not set
> +# CONFIG_CMD_NFS is not set
> +CONFIG_CMD_PING=y
> +CONFIG_CMD_MTDPARTS=y
> +CONFIG_MTDIDS_DEFAULT="nor0=spi_flash"
> +CONFIG_MTDPARTS_DEFAULT="mtdparts=spi_flash:512k(UBoot),256k(Env),256k(conf),6m@1m(linux)"
> +# CONFIG_ISO_PARTITION is not set
> +CONFIG_OF_EMBED=y

 this gives now a build warning

 = WARNING ==
 CONFIG_OF_EMBED is enabled. This option should only
 be used for debugging purposes. Please use
 CONFIG_OF_SEPARATE for boards in mainline.
 See doc/README.fdt-control for more info.
 
>>>
>>> I did not get this warning. For now I base my series on v2018.11,
>>> should I base it on v2019.01-rc1 (i didn't realized it was already
>>> released) ?
>>>


 Shall I change it when applying or do you want to test it first and send
 a follow-up patch?
>>>
>>> I'd like to test it to be sure it continue to work.
>> 
>> I had a closer look on this issue and actually we have already a patch
>> series to apply which it is planned to be sent very soon. With this new
>> series we will be able to support multiple boards with this series
>> CONFIG_OF_SEPARATE will be used instead of CONFIG_OF_EMBED.
>> 
>> Would it be possible to keep this series as is ?
>> 
>
> I asked because I had to fix some minor merge conflicts when applying
> and I had to re-sync the defconfig files due to various changes in
> mainline. Thus I need to update your patches anyway and a simply
> removing CONFIG_OF_EMBED=y would be a trivial fix.
>
> You can review the current patch queue at u-boot-mips/microsemi which is
> based on u-boot-mips/next.

I tested you branch and it worked on both Ocelot and Luton. So I'm fine
with your changes.

Thanks !

Gregory

>
> -- 
> - Daniel

-- 
Gregory Clement, Bootlin
Embedded Linux and Kernel engineering
http://bootlin.com
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v4] pico-imx7d: Increase the CONFIG_ENV_OFFSET size

2018-12-17 Thread Fabio Estevam
Hi Stefano,

On Mon, Dec 17, 2018 at 12:47 PM Stefano Babic  wrote:

> Yes, I agree with you - we could have a follow up patch when Wolfgang's
> patch will be merged.

Yes, I will send a follow up patch after Wolfgang's patch is accepted.

Thanks
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v4] pico-imx7d: Increase the CONFIG_ENV_OFFSET size

2018-12-17 Thread Stefano Babic
On 17/12/18 15:13, Fabio Estevam wrote:
> Hi Stefano,
> 
> On Fri, Nov 30, 2018 at 12:52 PM Fabio Estevam  wrote:
>>
>> U-Boot binary has grown in such a way that it goes beyond the reserved
>> area for the environment variables.
>>
>> Running "saveenv" causes U-Boot to hang because of this overlap.
>>
>> Fix this problem by increasing the CONFIG_ENV_OFFSET size.
>>
>> Also, in order to prevent this same problem in the future, use
>> CONFIG_BOARD_SIZE_LIMIT, which will detect the overlap in build-time.
>>
>> CONFIG_BOARD_SIZE_LIMIT does not accept math expressions, so declare
>> CONFIG_ENV_OFFSET with its direct value instead.
>>
>> Signed-off-by: Fabio Estevam 
>> ---
>> Changes since v3:
>> - Take the 69k u-boot.img offset into account when calculating
>> CONFIG_BOARD_SIZE_LIMIT (Wolfgang)
> 
> Could you please consider applying this version?
> 
> Wolfgang's patch causes breakage on some systems as reported by Tom
> and I would prefer we fix the critical problem soon independently of
> Wolgang's fix.

Yes, I agree with you - we could have a follow up patch when Wolfgang's
patch will be merged.

Best regards,
Stefano


-- 
=
DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sba...@denx.de
=
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH] am57xx_evm_defconfig: Enable YMODEM support

2018-12-17 Thread yan-liu
From: Yan Liu 

Enable CONFIG_SPL_YMODEM_SUPPORT to support UART boot

Signed-off-by: Yan Liu 
---
 configs/am57xx_evm_defconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/configs/am57xx_evm_defconfig b/configs/am57xx_evm_defconfig
index aa82830..cc814a8 100644
--- a/configs/am57xx_evm_defconfig
+++ b/configs/am57xx_evm_defconfig
@@ -25,6 +25,7 @@ CONFIG_SPL_DMA_SUPPORT=y
 # CONFIG_SPL_NAND_SUPPORT is not set
 CONFIG_SPL_OS_BOOT=y
 CONFIG_SPL_SPI_LOAD=y
+CONFIG_SPL_YMODEM_SUPPORT=y
 CONFIG_CMD_SPL=y
 # CONFIG_CMD_FLASH is not set
 # CONFIG_CMD_SETEXPR is not set
-- 
2.7.4

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v4] pico-imx7d: Increase the CONFIG_ENV_OFFSET size

2018-12-17 Thread Fabio Estevam
Hi Stefano,

On Fri, Nov 30, 2018 at 12:52 PM Fabio Estevam  wrote:
>
> U-Boot binary has grown in such a way that it goes beyond the reserved
> area for the environment variables.
>
> Running "saveenv" causes U-Boot to hang because of this overlap.
>
> Fix this problem by increasing the CONFIG_ENV_OFFSET size.
>
> Also, in order to prevent this same problem in the future, use
> CONFIG_BOARD_SIZE_LIMIT, which will detect the overlap in build-time.
>
> CONFIG_BOARD_SIZE_LIMIT does not accept math expressions, so declare
> CONFIG_ENV_OFFSET with its direct value instead.
>
> Signed-off-by: Fabio Estevam 
> ---
> Changes since v3:
> - Take the 69k u-boot.img offset into account when calculating
> CONFIG_BOARD_SIZE_LIMIT (Wolfgang)

Could you please consider applying this version?

Wolfgang's patch causes breakage on some systems as reported by Tom
and I would prefer we fix the critical problem soon independently of
Wolgang's fix.

Thanks
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH] net: macb: fix mapping of registers

2018-12-17 Thread Ramon Fried
On Mon, Dec 17, 2018 at 2:08 PM Daniel Schwierzeck
 wrote:
>
>
>
> Am 17.12.18 um 02:01 schrieb Ramon Fried:
> > Some architectures (MIPS) needs mapping to access IOMEM.
> > Fix that.
> >
> > Fixes: f1dcc19b213d ("net: macb: Convert to driver model")
> >
> > Signed-off-by: Ramon Fried 
> > ---
> >
> >  drivers/net/macb.c | 12 +++-
> >  1 file changed, 11 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/net/macb.c b/drivers/net/macb.c
> > index 94c89c762b..6e1b479813 100644
> > --- a/drivers/net/macb.c
> > +++ b/drivers/net/macb.c
> > @@ -36,6 +36,7 @@
> >  #include 
> >
> >  #include 
> > +#include 
> >  #include 
> >  #include 
> >  #include 
> > @@ -1149,9 +1150,18 @@ int __weak macb_late_eth_ofdata_to_platdata(struct 
> > udevice *dev)
> >
> >  static int macb_eth_ofdata_to_platdata(struct udevice *dev)
> >  {
> > + fdt_addr_t addr;
> > + fdt_size_t size;
> > + int node = dev_of_offset(dev);
> >   struct eth_pdata *pdata = dev_get_platdata(dev);
> >
> > - pdata->iobase = devfdt_get_addr(dev);
> > + addr = fdtdec_get_addr_size(gd->fdt_blob, node, "reg", );
> > + if (addr == FDT_ADDR_T_NONE)
> > + return -EINVAL;
> > +
> > + pdata->iobase = (phys_addr_t)ioremap(addr, size);
> > + if (!pdata->iobase)
> > + return -EINVAL;
> >
> >   return macb_late_eth_ofdata_to_platdata(dev);
> >  }
> >
>
> you should use dev_remap_addr() to avoid all the boiler plate code
>
Will check it out. Thanks
>
> --
> - Daniel
>
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] arm: ti: boot: Increase system partition size

2018-12-17 Thread Tom Rini
On Tue, Dec 11, 2018 at 06:20:21PM +0200, Sam Protsenko wrote:

> Android code base is growing, so since Android "Pie" the size of
> system.img grew up to be about 740 MiB. Let's increase system.img to
> 1 GiB to accommodate for those changes and leave some margin for future
> changes. We don't want to make it more than 1 GiB, because we should
> keep userdata partition big enough (for user files, like media etc.),
> and eMMC size on BeagleBoard-X15 is only 3.5 GiB.
> 
> Signed-off-by: Sam Protsenko 
> Acked-by: Praneeth Bajjuri 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [RFC PATCH] bitops: Fix GENMASK definition for Sandbox

2018-12-17 Thread Vignesh R
In arch/sandbox/include/asm/types.h we have
Therefore for 32 bit Sandbox build BITS_PER_LONG turns out to be 32 as
CONFIG_PHYS64 is not set

This messes up the current logic of GENMASK macro due to mismatch b/w
size of unsigned long (64 bit) and that of BITS_PER_LONG.
Fix this by using CONFIG_SANDBOX_BITS_PER_LONG which is set to 64/32
based on the host machine on which its being compiled.

Without this patch:
GENMASK(14,0) => 0x7fff
After this patch:
GENMASK(14,0) => 0x7fff

Signed-off-by: Vignesh R 
---

I marked it as RFC because, I am not really sure if I am running Sandbox
tests properly.
My host machine is x86_64 (Ubuntu 18.04). Running below command[1] with
some of my yet to be upstreamed patches that use GENMASK macro shows this issue.

[1]:
$ make check


 include/linux/bitops.h | 5 +
 1 file changed, 5 insertions(+)

diff --git a/include/linux/bitops.h b/include/linux/bitops.h
index a47f6d17bb5f..259df43fb00f 100644
--- a/include/linux/bitops.h
+++ b/include/linux/bitops.h
@@ -21,8 +21,13 @@
  * position @h. For example
  * GENMASK_ULL(39, 21) gives us the 64bit vector 0x00e0.
  */
+#ifdef CONFIG_SANDBOX
+#define GENMASK(h, l) \
+   (((~0UL) << (l)) & (~0UL >> (CONFIG_SANDBOX_BITS_PER_LONG - 1 - (h
+#else
 #define GENMASK(h, l) \
(((~0UL) << (l)) & (~0UL >> (BITS_PER_LONG - 1 - (h
+#endif
 
 #define GENMASK_ULL(h, l) \
(((~0ULL) << (l)) & (~0ULL >> (BITS_PER_LONG_LONG - 1 - (h
-- 
2.20.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v3 7/8] rockchip: rk3399-puma: enable full pinctrl driver in Puma defconfig.

2018-12-17 Thread Christoph Muellner
This patch enables the full pinctrl driver in the defconfig
for the RK3399-Q7.

Signed-off-by: Christoph Muellner 
---

Changes in v3: None
Changes in v2: None

 configs/puma-rk3399_defconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/configs/puma-rk3399_defconfig b/configs/puma-rk3399_defconfig
index 1afa5a75f9..3c293b69e4 100644
--- a/configs/puma-rk3399_defconfig
+++ b/configs/puma-rk3399_defconfig
@@ -75,6 +75,7 @@ CONFIG_GMAC_ROCKCHIP=y
 CONFIG_PINCTRL=y
 CONFIG_SPL_PINCTRL=y
 CONFIG_PINCTRL_ROCKCHIP_RK3399=y
+CONFIG_PINCTRL_ROCKCHIP_RK3399_FULL=y
 CONFIG_DM_PMIC=y
 CONFIG_DM_PMIC_FAN53555=y
 CONFIG_PMIC_RK8XX=y
-- 
2.11.0

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v3 5/8] rockchip: rk3399: Add improved pinctrl driver.

2018-12-17 Thread Christoph Muellner
The current pinctrl driver for the RK3399 has a range of qulity issues.
E.g. it only implements the .set_state_simple() callback, it
does not parse the available pinctrl information from the DTS
(instead uses hardcoded values), is not flexible enough to cover
devices without 'interrupt' field in the DTS (e.g. PWM),
is not written generic enough to make code reusable among other
rockchip SoCs...

This patch addresses these issues by reimplementing the whole driver
from scratch using the .set_state() callback.
The new implementation covers all featurese of the old code
(i.e. it supports pinmuxing and pullup/pulldown configuration).

This patch has been tested on a RK3399-Q7 SoM (Puma).

Signed-off-by: Christoph Muellner 
---

Changes in v3: None
Changes in v2: None

 drivers/pinctrl/rockchip/pinctrl_rk3399.c | 226 ++
 1 file changed, 226 insertions(+)

diff --git a/drivers/pinctrl/rockchip/pinctrl_rk3399.c 
b/drivers/pinctrl/rockchip/pinctrl_rk3399.c
index bc92dd7c06..ed9828989f 100644
--- a/drivers/pinctrl/rockchip/pinctrl_rk3399.c
+++ b/drivers/pinctrl/rockchip/pinctrl_rk3399.c
@@ -1,6 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0+
 /*
  * (C) Copyright 2016 Rockchip Electronics Co., Ltd
+ * (C) 2018 Theobroma Systems Design und Consulting GmbH
  */
 
 #include 
@@ -14,11 +15,234 @@
 #include 
 #include 
 
+static const u32 RK_GRF_P_PULLUP = 1;
+static const u32 RK_GRF_P_PULLDOWN = 2;
+
 struct rk3399_pinctrl_priv {
struct rk3399_grf_regs *grf;
struct rk3399_pmugrf_regs *pmugrf;
+   struct rockchip_pin_bank *banks;
+};
+
+/**
+ * Location of pinctrl/pinconf registers.
+ */
+enum rk_grf_location {
+   RK_GRF,
+   RK_PMUGRF,
+};
+
+/**
+ * @nr_pins: number of pins in this bank
+ * @bank_num: number of the bank, to account for holes
+ * @iomux: array describing the 4 iomux sources of the bank
+ */
+struct rockchip_pin_bank {
+   u8 nr_pins;
+   enum rk_grf_location grf_location;
+   size_t iomux_offset;
+   size_t pupd_offset;
 };
 
+#define PIN_BANK(pins, grf, iomux, pupd)   \
+   {   \
+   .nr_pins = pins,\
+   .grf_location = grf,\
+   .iomux_offset = iomux,  \
+   .pupd_offset = pupd,\
+   }
+
+static struct rockchip_pin_bank rk3399_pin_banks[] = {
+   PIN_BANK(16, RK_PMUGRF,
+offsetof(struct rk3399_pmugrf_regs, gpio0a_iomux),
+offsetof(struct rk3399_pmugrf_regs, gpio0_p)),
+   PIN_BANK(32, RK_PMUGRF,
+offsetof(struct rk3399_pmugrf_regs, gpio1a_iomux),
+offsetof(struct rk3399_pmugrf_regs, gpio1_p)),
+   PIN_BANK(32, RK_GRF,
+offsetof(struct rk3399_grf_regs, gpio2a_iomux),
+offsetof(struct rk3399_grf_regs, gpio2_p)),
+   PIN_BANK(32, RK_GRF,
+offsetof(struct rk3399_grf_regs, gpio3a_iomux),
+offsetof(struct rk3399_grf_regs, gpio3_p)),
+   PIN_BANK(32, RK_GRF,
+offsetof(struct rk3399_grf_regs, gpio4a_iomux),
+offsetof(struct rk3399_grf_regs, gpio4_p)),
+};
+
+static void rk_pinctrl_get_info(uintptr_t base, u32 index, uintptr_t *addr,
+   u32 *shift, u32 *mask)
+{
+   /*
+* In general we four subsequent 32-bit configuration registers
+* per bank (e.g. GPIO2A_P, GPIO2B_P, GPIO2C_P, GPIO2D_P).
+* The configuration for each pin has two bits.
+*
+* @base...contains the address to the first register.
+* @index...defines the pin within the bank (0..31).
+* @addr...will be the address of the actual register to use
+*/
+
+   const u32 pins_per_register = 8;
+   const u32 config_bits_per_pin = 2;
+
+   /* Get the address of the configuration register. */
+   *addr = base + (index / pins_per_register) * sizeof(u32);
+
+   /* Get the bit offset within the configruation register. */
+   *shift = (index & (pins_per_register - 1)) * config_bits_per_pin;
+
+   /* Get the (unshifted) mask for the configuration pins. */
+   *mask = ((1 << config_bits_per_pin) - 1);
+
+   pr_debug("%s: addr=0x%lx, mask=0x%x, shift=0x%x\n",
+__func__, *addr, *mask, *shift);
+}
+
+static void rk3399_pinctrl_set_pin_iomux(uintptr_t grf_addr,
+struct rockchip_pin_bank *bank,
+u32 index, u32 muxval)
+{
+   uintptr_t iomux_base, addr;
+   u32 shift, mask;
+
+   iomux_base = grf_addr + bank->iomux_offset;
+   rk_pinctrl_get_info(iomux_base, index, , , );
+
+   /* Set pinmux register */
+   rk_clrsetreg(addr, mask << shift, muxval << shift);
+}
+
+static void rk3399_pinctrl_set_pin_pupd(uintptr_t grf_addr,
+   struct 

  1   2   >