Re: [U-Boot] [PATCH 0/4] rockchip: Reduce prerequisites from the host

2018-06-18 Thread Vicente Bergas
On Wed, 13 Jun 2018 11:51:13 +0800, kever.yang at rock-chips.com wrote:
>(snip)
>I just not understand why remove the dependency on python is so important,
>there already many modules depend on python.

On Wed, 13 Jun 2018 11:57:48 +0800, kever.yang at rock-chips.com wrote:
>(snip)
> Could you share why you don't want to use python, can convert the
>script to C?

Hi Kever,
there are several reasons, here are the ones I can think of:
 1.- Python is a ~100MB weight dependency.
 2.- Because of (1) I don not have it installed by default.
 3.- My Linux distribution of choice defaults to python3 but
 u-boot requires 'python' to be python2.
 4.- "Shall use C language whenever possible."
 http://www.denx.de/wiki/U-Boot/DesignRequirements
 5.- It is not just a dependency on what needs to be installed
 on the host, is also a dependency on which programming
 languages u-boot's contributors need to know about.
 So, it can be considered an entry barrier.

I don not have strong feelings on this getting merged and certainly
will not get upset if it does not. It is entirely your decision.

I have submitted this patch series mostly "for your information" and
because Philipp thought that it "looks worthwhile":
On Fri, 1 Jun 2018 00:37:17 +0200, philipp.tomsich at
theobroma-systems.com wrote:
>(snip)
>> On 1 Jun 2018, at 00:28, Vicente Bergas  wrote:
>(snip)
>> SPL_FIT_GENERATOR and SPL_OF_PLATDATA require python.
>> In order to remove this dependency:
>> 1.- I have written a C version for SPL_FIT_GENERATOR.
>> 2.- Disabled SPL_OF_PLATDATA, it just works.
>>
>> MKIMAGE_DTC_PATH requires dtc in the PATH.
>> In order to remove this dependency, I have changed it to use the built-in 
>> one.
>>
>> If there is interest in those changes, I can post the full patch.
>
>Please submit a patch--it certainly looks worthwhile.

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


[U-Boot] [PATCH 4/4] rockchip: rk3399: set CONFIG_MKIMAGE_DTC_PATH

2018-06-01 Thread Vicente Bergas
From: Vicente Bergas 

U-Boot has a built-in dtc. Using it removes one dependency from the host.

Signed-off-by: Vicente Bergas 
---
 configs/evb-rk3399_defconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/configs/evb-rk3399_defconfig b/configs/evb-rk3399_defconfig
index 3f87722866..d1540ad6d1 100644
--- a/configs/evb-rk3399_defconfig
+++ b/configs/evb-rk3399_defconfig
@@ -27,6 +27,7 @@ CONFIG_CMD_USB=y
 CONFIG_CMD_TIME=y
 CONFIG_SPL_OF_CONTROL=y
 CONFIG_OF_SPL_REMOVE_PROPS="pinctrl-0 pinctrl-names clock-names 
interrupt-parent assigned-clocks assigned-clock-rates assigned-clock-parents"
+CONFIG_MKIMAGE_DTC_PATH="scripts/dtc/dtc"
 CONFIG_ENV_IS_IN_MMC=y
 CONFIG_NET_RANDOM_ETHADDR=y
 CONFIG_REGMAP=y
-- 
2.17.1

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


[U-Boot] [PATCH 2/4] rockchip: rk3399: use make_fit_atf instead of make_fit_atf.py

2018-06-01 Thread Vicente Bergas
From: Vicente Bergas 

Signed-off-by: Vicente Bergas 
---
 configs/evb-rk3399_defconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/configs/evb-rk3399_defconfig b/configs/evb-rk3399_defconfig
index 05ad0da336..69a4cc2239 100644
--- a/configs/evb-rk3399_defconfig
+++ b/configs/evb-rk3399_defconfig
@@ -11,7 +11,7 @@ CONFIG_DEFAULT_DEVICE_TREE="rk3399-evb"
 CONFIG_DEBUG_UART=y
 CONFIG_FIT=y
 CONFIG_SPL_LOAD_FIT=y
-CONFIG_SPL_FIT_GENERATOR="arch/arm/mach-rockchip/make_fit_atf.py"
+CONFIG_SPL_FIT_GENERATOR="tools/make_fit_atf"
 # CONFIG_DISPLAY_CPUINFO is not set
 CONFIG_DISPLAY_BOARDINFO_LATE=y
 CONFIG_SPL_STACK_R=y
-- 
2.17.1

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


[U-Boot] [PATCH 3/4] rockchip: rk3399: disable CONFIG_SPL_OF_PLATDATA

2018-06-01 Thread Vicente Bergas
From: Vicente Bergas 

It has been tested with this option disabled and it works fine.
The benefit of doing so is that this is the last dependency on python to
build U-Boot for the Sapphire board.

Signed-off-by: Vicente Bergas 
---
 configs/evb-rk3399_defconfig | 1 -
 1 file changed, 1 deletion(-)

diff --git a/configs/evb-rk3399_defconfig b/configs/evb-rk3399_defconfig
index 69a4cc2239..3f87722866 100644
--- a/configs/evb-rk3399_defconfig
+++ b/configs/evb-rk3399_defconfig
@@ -27,7 +27,6 @@ CONFIG_CMD_USB=y
 CONFIG_CMD_TIME=y
 CONFIG_SPL_OF_CONTROL=y
 CONFIG_OF_SPL_REMOVE_PROPS="pinctrl-0 pinctrl-names clock-names 
interrupt-parent assigned-clocks assigned-clock-rates assigned-clock-parents"
-CONFIG_SPL_OF_PLATDATA=y
 CONFIG_ENV_IS_IN_MMC=y
 CONFIG_NET_RANDOM_ETHADDR=y
 CONFIG_REGMAP=y
-- 
2.17.1

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


[U-Boot] [PATCH 1/4] add make_fit_atf in tools

2018-06-01 Thread Vicente Bergas
From: Vicente Bergas 

make_fit_atf generates an .its file based on U-Boot and ATF .elf files.
It also extracts all loadable sections from ATF.

It tries to somewhat mimic the behaviour of
arch/arm/mach-rockchip/make_fit_atf.py

Signed-off-by: Vicente Bergas 
---
 tools/Makefile   |   2 +
 tools/make_fit_atf.c | 360 +++
 2 files changed, 362 insertions(+)
 create mode 100644 tools/make_fit_atf.c

diff --git a/tools/Makefile b/tools/Makefile
index 5dd33ed4d5..a282f04f63 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -56,6 +56,8 @@ mkenvimage-objs := mkenvimage.o os_support.o lib/crc32.o
 hostprogs-y += dumpimage mkimage
 hostprogs-$(CONFIG_FIT_SIGNATURE) += fit_info fit_check_sign
 
+hostprogs-$(CONFIG_SPL_ATF) += make_fit_atf
+
 hostprogs-$(CONFIG_CMD_BOOTEFI_SELFTEST) += file2include
 
 FIT_SIG_OBJS-$(CONFIG_FIT_SIGNATURE) := common/image-sig.o
diff --git a/tools/make_fit_atf.c b/tools/make_fit_atf.c
new file mode 100644
index 00..91101aaf8a
--- /dev/null
+++ b/tools/make_fit_atf.c
@@ -0,0 +1,360 @@
+// SPDX-License-Identifier: 0BSD
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+static char const *dtb_basename (char const *path) {
+  enum { FILE_SEPARATOR = '/' };
+  size_t ln = strlen(path);
+  if (!ln || path[ln - 1] == FILE_SEPARATOR) {
+fprintf(stderr, "dtb file name error '%s'.\n", path);
+return NULL;
+  }
+  char const *base = path + ln - 1;
+  while (base > path && *base != FILE_SEPARATOR) --base;
+  if (*base == FILE_SEPARATOR) ++base;
+  return base;
+}
+
+/*
+  http://www.sco.com/developers/gabi/latest/ch4.intro.html
+  http://www.sco.com/developers/gabi/latest/ch4.eheader.html
+  http://www.sco.com/developers/gabi/latest/ch4.sheader.html
+  http://www.sco.com/developers/gabi/latest/ch5.pheader.html
+*/
+enum { EI_MAG0, EI_MAG1, EI_MAG2, EI_MAG3, EI_CLASS, EI_DATA, EI_VERSION, 
EI_NIDENT = 16 };
+enum { ELFMAG0 = 0x7F, ELFMAG1 = 'E', ELFMAG2 = 'L', ELFMAG3 = 'F' };
+enum { ELFCLASSNONE, ELFCLASS32, ELFCLASS64 };
+enum { ELFDATANONE, ELFDATA2LSB, ELFDATA2MSB };
+enum { ET_NONE, ET_REL, ET_EXEC, ET_DYN, ET_CORE };
+enum { EM_NONE, EM_ARM = 40, EM_AARCH64 = 183 };
+enum { EV_NONE, EV_CURRENT };
+enum { PT_NULL, PT_LOAD, PT_DYNAMIC, PT_INTERP, PT_NOTE, PT_SHLIB, PT_PHDR, 
PT_TLS };
+enum { SHT_NULL, SHT_PROGBITS, SHT_SYMTAB, SHT_STRTAB, SHT_RELA, SHT_HASH, 
SHT_DYNAMIC, SHT_NOTE, SHT_NOBITS };
+enum { SHF_ALLOC = 2 };
+typedef struct {
+  uint8_t  e_ident[EI_NIDENT];
+  uint16_t e_type;
+  uint16_t e_machine;
+  uint32_t e_version;
+  uint64_t e_entry;
+  uint64_t e_phoff;
+  uint64_t e_shoff;
+  uint32_t e_flags;
+  uint16_t e_ehsize;
+  uint16_t e_phentsize;
+  uint16_t e_phnum;
+  uint16_t e_shentsize;
+  uint16_t e_shnum;
+  uint16_t e_shstrndx;
+} Elf64_Ehdr;
+typedef struct {
+  uint32_t p_type;
+  uint32_t p_flags;
+  uint64_t p_offset;
+  uint64_t p_vaddr;
+  uint64_t p_paddr;
+  uint64_t p_filesz;
+  uint64_t p_memsz;
+  uint64_t p_align;
+} Elf64_Phdr;
+typedef struct {
+  uint32_t sh_name;
+  uint32_t sh_type;
+  uint64_t sh_flags;
+  uint64_t sh_addr;
+  uint64_t sh_offset;
+  uint64_t sh_size;
+  uint32_t sh_link;
+  uint32_t sh_info;
+  uint64_t sh_addralign;
+  uint64_t sh_entsize;
+} Elf64_Shdr;
+
+static FILE *elf_open(char const *file_name, Elf64_Ehdr *eh) {
+  FILE *f = fopen(file_name, "rb");
+  if (!f) {
+fprintf(stderr, "Error openning '%s': %s.\n", file_name, strerror(errno));
+return 0;
+  }
+  if (fread(eh, EI_NIDENT, 1, f) != 1) {
+if (feof(f)) {
+  fprintf(stderr, "Not ELF file.\n");
+  return 0;
+}
+fprintf(stderr, "Error reading '%s'.\n", file_name);
+return 0;
+  }
+  if (
+eh->e_ident[EI_MAG0] != ELFMAG0 ||
+eh->e_ident[EI_MAG1] != ELFMAG1 ||
+eh->e_ident[EI_MAG2] != ELFMAG2 ||
+eh->e_ident[EI_MAG3] != ELFMAG3
+  ) {
+fprintf(stderr, "Not ELF file.\n");
+return 0;
+  }
+  if (
+eh->e_ident[EI_CLASS]   != ELFCLASS64  ||
+eh->e_ident[EI_DATA]!= ELFDATA2LSB ||
+eh->e_ident[EI_VERSION] != EV_CURRENT
+  ) {
+fprintf(stderr, "Only version %u 64-bit little-endian ELF files 
supported.\n", EV_CURRENT);
+return 0;
+  }
+  if (!*(uint8_t *)&(uint32_t){1}) {
+fprintf(stderr, "Only little-endian hosts supported.\n");
+return 0;
+  }
+  if (fread(((void *)eh) + EI_NIDENT, sizeof(*eh) - EI_NIDENT, 1, f) != 1) {
+fprintf(stderr, "Error reading '%s'.\n", file_name);
+return 0;
+  }
+
+  if (
+eh->e_version   != EV_CURRENT ||
+eh->e_ehsize!= sizeof(Elf64_Ehdr) ||
+eh->e_phentsize != sizeof(Elf64_Phdr) ||
+eh->e_shentsize != sizeof(Elf64_Shdr)
+  ) {
+fprintf(stderr, "Unexpected ELF file.\n");
+return 0;
+  }
+  if (eh->e_machine != EM_AARCH64) {
+fprintf(stderr, "Only arm64 supported.\n");
+return 0;
+  }
+  ret

[U-Boot] [PATCH 0/4] rockchip: Reduce prerequisites from the host

2018-06-01 Thread Vicente Bergas
From: Vicente Bergas 

This patch series remove the dependency on python and dtc from the host
for the Sapphire board.

It does not conform to the U-Boot coding style. It has been posted here for
informational purposes only. If there is interest in merging it, feel free
to modify it at will, it is in the public domain.

Vicente Bergas (4):
  [U-Boot] add make_fit_atf in tools
  [U-Boot] rockchip: rk3399: use make_fit_atf instead of make_fit_atf.py
  [U-Boot] rockchip: rk3399: disable CONFIG_SPL_OF_PLATDATA
  [U-Boot] rockchip: rk3399: set CONFIG_MKIMAGE_DTC_PATH

 configs/evb-rk3399_defconfig |   4 +-
 tools/Makefile   |   2 +
 tools/make_fit_atf.c | 360 +++
 3 files changed, 364 insertions(+), 2 deletions(-)
 create mode 100644 tools/make_fit_atf.c

-- 
2.17.1

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


Re: [U-Boot] Exception Level switching seems broken on RK3399

2018-06-01 Thread Vicente Bergas
On Thu, May 24, 2018 at 7:05 PM, Dr. Philipp Tomsich
 wrote:
> Vincente,
>
> On 24 May 2018, at 18:48, Vicente Bergas  wrote:
>
> Hello Philipp,
> your answer is much appreciated.
>
> On Thu, May 24, 2018 at 1:07 PM, Dr. Philipp Tomsich
>  wrote:
>
> Vincente,
>
> On 19 May 2018, at 16:58, Vicente Bergas  wrote:
>
> Hello,
> I am writing this from a standalone Sapphire board [1],
> that is, without the Excavator base board.
> The CPU is the Rockchip RK3399, which implements ARMv8.0-A.
>
> Currently the boot process is:
> 1.- Boot ROM
> 2.- SPL, provided as closed source binary blob [2]
>
>
> SPL-support is available in mainline U-Boot.  We developed this for
> the RK3399-Q7 and it has been successfully used on other RK3399
> boards (e.g. I know that some Firefly-users are using this).
>
>
> Thank you!
>
>
> 3.- ATF, closed source binary blob [3]
>(not using the one from [2] because of stability issues)
>
>
> Why use the closed-source blob, if the RK3399 is supported in the ATF
> mainline and an ATF can be compiled from source?
>
>
> Currently I am using both binary blobs (SPL and ATF) because I could
> not make it work another way. I'll give it another try.
>
>
> 4.- Mainline u-boot, master branch
> 5.- Mainline linux, master branch
>
> I would like to use an opensource boot process.
> As a first approach I try to completely remove the ATF and
> replace the SPL with the one from u-boot.
> The modified boot process looks like:
> 1.- Boot ROM
> 2.- SPL, from mainline u-boot, master branch
> 3.- Mainline u-boot, master branch
> 4.- Mainline linux, master branch
> But it is not working.
>
> The replaced SPL works fine and loads u-boot.
> U-boot also works fine, loads linux and jumps into it.
>
>
> Yes, we’ve done some work to enable us to run U-Boot in EL3 on
> the RK3399 (as we use it for programming the secure e-fuses on
> the RK3399-Q7 in our factory programming setup).
>
>
> I can indeed confirm that U-Boot runs fine in EL3.
>
>
> But then, linux never gets executed.
>
> I have traced the issue to: arch/arm/include/asm/macro.h
> 202: msr  spsr_el3, \tmp
> 203: msr  elr_el3, \ep
> 204: eret // This is the last instruction executed
>
> For testing, I have also set CONFIG_ARMV8_SWITCH_TO_EL1 and
> checked that switch_to_el1 from arch/arm/lib/bootm.c is not reached.
>
> At this point I have a few questions:
> 1.- Is my first approach feasible? That is, is it possible to boot
>this CPU without ATF?
>
>
> It is feasible (i.e.: requires implementation work) but not recommended:
> Linux will use PSCI to bring up the secondary CPUs.  We have run Linux
> (limited to a single CPU) in EL3 on this CPU during our own board bringup,
> but I would strongly discourage this as it will entail unnecessary effort.
>
>
> There is a misunderstanding here. My intention was to run U-Boot in EL3,
> then switch to EL2 or EL1 from within U-Boot and afterwards run Linux
> in the lower EL.
>
>
> 2.- If so, what should I do to make it work? Probably it is just
>a configuration issue, but I do not know what to check. [4]
> 3.- Else, why do I need ATF?
>
>
> ATF is the secure monitor on ARMv8 and provides services such as PSCI
> to start up secondary CPUs.  It will usually also be part of
> power-management
> on most SoCs (after all: power configuration needs to be done in the secure
> envelope).
>
>
> Do you mean that without ATF I can only run a single CPU core?
>
>
> Linux (on the RK3399) uses PSCI to start the secondary CPUs and uses SMC
> (secure monitor call) to call into PSCI.  The PSCI handlers thus live within
> ATF.
>
> While it is technically possible to start up the other cores using other
> mechanisms,
> it is the ‘road less travelled’.
>
> Cheers,
> Philipp.
>
>
> Regards,
>  Vicenç.
>
>
> Regards,
> Philipp.
>
>
> Regards,
> Vicenç.

Hello Philipp,
I have managed to make it work. It turns out that support for
this platform was added to mainline after my first attempt.

In doing so I have modified the configuration this way:
--- a/configs/evb-rk3399_defconfig
+++ b/configs/evb-rk3399_defconfig
@@ -11,7 +11,7 @@
 CONFIG_DEBUG_UART=y
 CONFIG_FIT=y
 CONFIG_SPL_LOAD_FIT=y
-CONFIG_SPL_FIT_GENERATOR="arch/arm/mach-rockchip/make_fit_atf.py"
+CONFIG_SPL_FIT_GENERATOR="tools/make_fit_atf"
 # CONFIG_DISPLAY_CPUINFO is not set
 CONFIG_DISPLAY_BOARDINFO_LATE=y
 CONFIG_SPL_STACK_R=y
@@ -27,7 +27,7 @@
 CONFIG_CMD_TIME=y
 CONFIG_SPL_OF_CONTROL=y
 CONFIG_OF_SPL_REMOVE_PROPS="pinctrl-0 pinctrl-names clock-names
interrupt-parent assigned-clocks assigned-clock-rates
assigned-clock-parents"
-CONFIG_SPL_OF_PLAT

Re: [U-Boot] Exception Level switching seems broken on RK3399

2018-05-24 Thread Vicente Bergas
Hello Philipp,
your answer is much appreciated.

On Thu, May 24, 2018 at 1:07 PM, Dr. Philipp Tomsich
<philipp.toms...@theobroma-systems.com> wrote:
> Vincente,
>
>> On 19 May 2018, at 16:58, Vicente Bergas <vice...@gmail.com> wrote:
>>
>> Hello,
>> I am writing this from a standalone Sapphire board [1],
>> that is, without the Excavator base board.
>> The CPU is the Rockchip RK3399, which implements ARMv8.0-A.
>>
>> Currently the boot process is:
>> 1.- Boot ROM
>> 2.- SPL, provided as closed source binary blob [2]
>
> SPL-support is available in mainline U-Boot.  We developed this for
> the RK3399-Q7 and it has been successfully used on other RK3399
> boards (e.g. I know that some Firefly-users are using this).

Thank you!

>
>> 3.- ATF, closed source binary blob [3]
>> (not using the one from [2] because of stability issues)
>
> Why use the closed-source blob, if the RK3399 is supported in the ATF
> mainline and an ATF can be compiled from source?

Currently I am using both binary blobs (SPL and ATF) because I could
not make it work another way. I'll give it another try.

>
>> 4.- Mainline u-boot, master branch
>> 5.- Mainline linux, master branch
>>
>> I would like to use an opensource boot process.
>> As a first approach I try to completely remove the ATF and
>> replace the SPL with the one from u-boot.
>> The modified boot process looks like:
>> 1.- Boot ROM
>> 2.- SPL, from mainline u-boot, master branch
>> 3.- Mainline u-boot, master branch
>> 4.- Mainline linux, master branch
>> But it is not working.
>>
>> The replaced SPL works fine and loads u-boot.
>> U-boot also works fine, loads linux and jumps into it.
>
> Yes, we’ve done some work to enable us to run U-Boot in EL3 on
> the RK3399 (as we use it for programming the secure e-fuses on
> the RK3399-Q7 in our factory programming setup).

I can indeed confirm that U-Boot runs fine in EL3.

>
>> But then, linux never gets executed.
>>
>> I have traced the issue to: arch/arm/include/asm/macro.h
>> 202: msr  spsr_el3, \tmp
>> 203: msr  elr_el3, \ep
>> 204: eret // This is the last instruction executed
>>
>> For testing, I have also set CONFIG_ARMV8_SWITCH_TO_EL1 and
>> checked that switch_to_el1 from arch/arm/lib/bootm.c is not reached.
>>
>> At this point I have a few questions:
>> 1.- Is my first approach feasible? That is, is it possible to boot
>> this CPU without ATF?
>
> It is feasible (i.e.: requires implementation work) but not recommended:
> Linux will use PSCI to bring up the secondary CPUs.  We have run Linux
> (limited to a single CPU) in EL3 on this CPU during our own board bringup,
> but I would strongly discourage this as it will entail unnecessary effort.

There is a misunderstanding here. My intention was to run U-Boot in EL3,
then switch to EL2 or EL1 from within U-Boot and afterwards run Linux
in the lower EL.

>
>> 2.- If so, what should I do to make it work? Probably it is just
>> a configuration issue, but I do not know what to check. [4]
>> 3.- Else, why do I need ATF?
>
> ATF is the secure monitor on ARMv8 and provides services such as PSCI
> to start up secondary CPUs.  It will usually also be part of power-management
> on most SoCs (after all: power configuration needs to be done in the secure
> envelope).

Do you mean that without ATF I can only run a single CPU core?

Regards,
  Vicenç.

>
> Regards,
> Philipp.
>
>>
>> Regards,
>>  Vicenç.
>>
>> [1] http://opensource.rock-chips.com/wiki_Excavator_sapphire_board
>> [2] https://github.com/rockchip-linux/rkbin/tree/29mirror
>> [3] 
>> https://raw.githubusercontent.com/nightseas/armbian-build/master/packages/blobs/rockchip64/trust.img
>> [4]
>> CONFIG_ARM=y
>> CONFIG_ARCH_ROCKCHIP=y
>> CONFIG_SYS_TEXT_BASE=0x0020
>> CONFIG_SPL_LIBCOMMON_SUPPORT=y
>> CONFIG_SPL_LIBGENERIC_SUPPORT=y
>> CONFIG_SYS_MALLOC_F_LEN=0x4000
>> CONFIG_ROCKCHIP_RK3399=y
>> CONFIG_ROCKCHIP_SPL_RESERVE_IRAM=0x4000
>> CONFIG_SPL_STACK_R_ADDR=0x8
>> # CONFIG_PSCI_RESET is not set
>> CONFIG_CMD_HDMIDETECT=y
>> CONFIG_DEFAULT_DEVICE_TREE="rk3399-evb"
>> CONFIG_DEBUG_UART=y
>> CONFIG_BOOTDELAY=1
>> # CONFIG_DISPLAY_CPUINFO is not set
>> # CONFIG_DISPLAY_BOARDINFO is not set
>> CONFIG_SPL_STACK_R=y
>> CONFIG_SPL_STACK_R_MALLOC_SIMPLE_LEN=0x4000
>> # CONFIG_CMD_IMI is not set
>> # CONFIG_CMD_XIMG is not set
>> # CONFIG_CMD_SAVEENV is not set
>> # CONFIG_CMD_FLASH is not set
>> # CONFIG_CMD_LOADB is not set
>> # CONFI

[U-Boot] Exception Level switching seems broken on RK3399

2018-05-19 Thread Vicente Bergas
Hello,
I am writing this from a standalone Sapphire board [1],
 that is, without the Excavator base board.
The CPU is the Rockchip RK3399, which implements ARMv8.0-A.

Currently the boot process is:
 1.- Boot ROM
 2.- SPL, provided as closed source binary blob [2]
 3.- ATF, closed source binary blob [3]
 (not using the one from [2] because of stability issues)
 4.- Mainline u-boot, master branch
 5.- Mainline linux, master branch

I would like to use an opensource boot process.
As a first approach I try to completely remove the ATF and
replace the SPL with the one from u-boot.
The modified boot process looks like:
 1.- Boot ROM
 2.- SPL, from mainline u-boot, master branch
 3.- Mainline u-boot, master branch
 4.- Mainline linux, master branch
But it is not working.

The replaced SPL works fine and loads u-boot.
U-boot also works fine, loads linux and jumps into it.
But then, linux never gets executed.

I have traced the issue to: arch/arm/include/asm/macro.h
 202: msr  spsr_el3, \tmp
 203: msr  elr_el3, \ep
 204: eret // This is the last instruction executed

For testing, I have also set CONFIG_ARMV8_SWITCH_TO_EL1 and
checked that switch_to_el1 from arch/arm/lib/bootm.c is not reached.

At this point I have a few questions:
 1.- Is my first approach feasible? That is, is it possible to boot
 this CPU without ATF?
 2.- If so, what should I do to make it work? Probably it is just
 a configuration issue, but I do not know what to check. [4]
 3.- Else, why do I need ATF?

Regards,
  Vicenç.

[1] http://opensource.rock-chips.com/wiki_Excavator_sapphire_board
[2] https://github.com/rockchip-linux/rkbin/tree/29mirror
[3] 
https://raw.githubusercontent.com/nightseas/armbian-build/master/packages/blobs/rockchip64/trust.img
[4]
CONFIG_ARM=y
CONFIG_ARCH_ROCKCHIP=y
CONFIG_SYS_TEXT_BASE=0x0020
CONFIG_SPL_LIBCOMMON_SUPPORT=y
CONFIG_SPL_LIBGENERIC_SUPPORT=y
CONFIG_SYS_MALLOC_F_LEN=0x4000
CONFIG_ROCKCHIP_RK3399=y
CONFIG_ROCKCHIP_SPL_RESERVE_IRAM=0x4000
CONFIG_SPL_STACK_R_ADDR=0x8
# CONFIG_PSCI_RESET is not set
CONFIG_CMD_HDMIDETECT=y
CONFIG_DEFAULT_DEVICE_TREE="rk3399-evb"
CONFIG_DEBUG_UART=y
CONFIG_BOOTDELAY=1
# CONFIG_DISPLAY_CPUINFO is not set
# CONFIG_DISPLAY_BOARDINFO is not set
CONFIG_SPL_STACK_R=y
CONFIG_SPL_STACK_R_MALLOC_SIMPLE_LEN=0x4000
# CONFIG_CMD_IMI is not set
# CONFIG_CMD_XIMG is not set
# CONFIG_CMD_SAVEENV is not set
# CONFIG_CMD_FLASH is not set
# CONFIG_CMD_LOADB is not set
# CONFIG_CMD_LOADS is not set
CONFIG_CMD_MMC=y
CONFIG_CMD_USB=y
# CONFIG_CMD_SETEXPR is not set
# CONFIG_CMD_NET is not set
# CONFIG_DOS_PARTITION is not set
# CONFIG_ISO_PARTITION is not set
CONFIG_SPL_OF_CONTROL=y
CONFIG_REGMAP=y
CONFIG_SPL_REGMAP=y
CONFIG_SYSCON=y
CONFIG_SPL_SYSCON=y
CONFIG_CLK=y
CONFIG_SPL_CLK=y
CONFIG_ROCKCHIP_GPIO=y
CONFIG_SYS_I2C_ROCKCHIP=y
# CONFIG_MMC_WRITE is not set
# CONFIG_MMC_HW_PARTITIONING is not set
CONFIG_MMC_DW=y
CONFIG_MMC_SDHCI=y
CONFIG_MMC_SDHCI_ROCKCHIP=y
CONFIG_DM_ETH=y
# CONFIG_NETDEVICES is not set
CONFIG_PINCTRL=y
CONFIG_SPL_PINCTRL=y
CONFIG_PINCTRL_ROCKCHIP_RK3399=y
CONFIG_DM_PMIC=y
CONFIG_PMIC_RK8XX=y
CONFIG_REGULATOR_PWM=y
CONFIG_DM_REGULATOR_FIXED=y
CONFIG_REGULATOR_RK8XX=y
CONFIG_PWM_ROCKCHIP=y
CONFIG_RAM=y
CONFIG_SPL_RAM=y
CONFIG_BAUDRATE=150
CONFIG_DEBUG_UART_BASE=0xFF1A
CONFIG_DEBUG_UART_CLOCK=2400
CONFIG_DEBUG_UART_SHIFT=2
CONFIG_SYSRESET=y
CONFIG_USB=y
CONFIG_USB_XHCI_HCD=y
CONFIG_USB_XHCI_DWC3=y
CONFIG_USB_EHCI_HCD=y
CONFIG_USB_EHCI_GENERIC=y
CONFIG_USB_STORAGE=y
CONFIG_USB_KEYBOARD=y
CONFIG_USB_HOST_ETHER=y
CONFIG_USB_ETHER_ASIX=y
CONFIG_USB_ETHER_ASIX88179=y
CONFIG_USB_ETHER_MCS7830=y
CONFIG_USB_ETHER_RTL8152=y
CONFIG_USB_ETHER_SMSC95XX=y
CONFIG_DM_VIDEO=y
# CONFIG_BACKLIGHT_PWM is not set
# CONFIG_VIDEO_BPP8 is not set
# CONFIG_VIDEO_BPP16 is not set
# CONFIG_VIDEO_BPP32 is not set
# CONFIG_VIDEO_ANSI is not set
# CONFIG_SYS_WHITE_ON_BLACK is not set
CONFIG_DISPLAY=y
CONFIG_VIDEO_ROCKCHIP=y
CONFIG_DISPLAY_ROCKCHIP_HDMI=y
# CONFIG_FAT_WRITE is not set
CONFIG_USE_TINY_PRINTF=y
CONFIG_ERRNO_STR=y
# CONFIG_EFI_LOADER is not set
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot