Re: [PATCH] riscv: timer: Add support for an early timer

2020-11-26 Thread Rick Chen
Hi, Pragnesh

> Hi Rick,
>
> >-Original Message-
> >From: Rick Chen 
> >Sent: 26 November 2020 14:44
> >To: Pragnesh Patel 
> >Cc: Simon Glass ; U-Boot Mailing List  >b...@lists.denx.de>; Atish Patra ; Bin Meng
> >; Paul Walmsley ( Sifive) ;
> >Anup Patel ; Sagar Kadam
> >; Palmer Dabbelt ; rick
> >; Alan Kao ; Leo Liang
> >
> >Subject: Re: [PATCH] riscv: timer: Add support for an early timer
> >
> >[External Email] Do not click links or attachments unless you recognize the
> >sender and know the content is safe
> >
> >Hi Pragnesh
> >
> >> Hi Rick,
> >>
> >> >-Original Message-
> >> >From: Rick Chen 
> >> >Sent: 24 November 2020 13:08
> >> >To: Pragnesh Patel 
> >> >Cc: U-Boot Mailing List ; Atish Patra
> >> >; Bin Meng ; Paul Walmsley (
> >> >Sifive) ; Anup Patel ;
> >> >Sagar Kadam ; Palmer Dabbelt
> >> >; Simon Glass ; rick
> >> >; Alan Kao ; Leo Liang
> >> >
> >> >Subject: Re: [PATCH] riscv: timer: Add support for an early timer
> >> >
> >> >[External Email] Do not click links or attachments unless you
> >> >recognize the sender and know the content is safe
> >> >
> >> >Hi Pragnesh,
> >> >
> >> >> From: Pragnesh Patel [mailto:pragnesh.pa...@sifive.com]
> >> >> Sent: Tuesday, November 17, 2020 7:05 PM
> >> >> To: u-boot@lists.denx.de
> >> >> Cc: atish.pa...@wdc.com; palmerdabb...@google.com;
> >> >bmeng...@gmail.com;
> >> >> paul.walms...@sifive.com; anup.pa...@wdc.com;
> >> >> sagar.ka...@sifive.com; Rick Jian-Zhi Chen(陳建志); Pragnesh Patel;
> >> >> Palmer Dabbelt; Sean Anderson; Simon Glass; Bin Meng
> >> >> Subject: [PATCH] riscv: timer: Add support for an early timer
> >> >>
> >> >> Added support for timer_early_get_count() and
> >> >> timer_early_get_rate() This is mostly useful in tracing.
> >> >>
> >> >> Signed-off-by: Pragnesh Patel 
> >> >> ---
> >> >>  drivers/timer/andes_plmt_timer.c   | 21 -
> >> >>  drivers/timer/riscv_timer.c| 21 -
> >> >>  drivers/timer/sifive_clint_timer.c | 21 -
> >> >>  include/configs/ax25-ae350.h   |  5 +
> >> >>  include/configs/sifive-fu540.h |  5 +
> >> >>  5 files changed, 70 insertions(+), 3 deletions(-)
> >> >>
> >> >
> >> >I verify with ae350_rv64_defconfig
> >> >
> >> >make FTRACE=1 ae350_rv64_defconfig
> >> >make FTRACE=1
> >> >
> >> >and it boot fail as below:
> >> >
> >> >U-Boot 2021.01-rc2-00140-geb42715 (Nov 24 2020 - 15:02:18 +0800)
> >> >
> >> >DRAM:  1 GiB
> >> >trace: enabled
> >> >
> >> >DO you have any suggestions ?
> >>
> >> Please enable CONFIG_TIMER_EARLY=y in ae350_rv64_defconfig
> >>
> >> Actually in v2, I will make TRACE to select TIMER_EARLY like below,
> >>
> >> --- a/lib/Kconfig
> >> +++ b/lib/Kconfig
> >> @@ -210,6 +210,7 @@ config BITREVERSE
> >>  config TRACE
> >> bool "Support for tracing of function calls and timing"
> >> imply CMD_TRACE
> >> +   select TIMER_EARLY
> >>
> >> Let me know if you have any suggestion.
> >
> >OK.
> >
> >After add CONFIG_TIMER_EARLY, U-Boot boots ok.
> >But When I try to booting kernel with FTRACE=1, following are the test stats:
> >
> >ae350_rv64_spl_defconfig without FTRACE=1, kernel booting is ok.
> >ae350_rv64_spl_defconfig with FTRACE=1, kernel booting fail.
> >ae350_rv64_defconfig with FTRACE=1, kernel booting is ok
> >
> >The failure case seems not reasonable.
> >Any suggestions ?
>
> Strange, Can you please tell me which steps you follow and also send some 
> debug logs  if possible.
>

Following are the configurations, steps and debug logs:

+++ b/configs/ae350_rv64_defconfig
q+CONFIG_TRACE=y
+CONFIG_TRACE_BUFFER_SIZE=0x0100
+CONFIG_TRACE_CALL_DEPTH_LIMIT=15
+CONFIG_CMD_TRACE=y
+CONFIG_TIMER_EARLY=y

+++ b/configs/ae350_rv64_spl_defconfig
+CONFIG_TRACE=y
+CONFIG_TRACE_BUFFER_SIZE=0x0100
+CONFIG_TRACE_CALL_DEPTH_LIMIT=15
+CONFIG_CMD_TRACE=y
+CONFIG_TIMER_EARLY=y

 case 1
///
ae350_rv64_defconfig with FTRACE=1, kernel booting is ok
 case 1
///
make FTRACE=1 ae350_rv64_defconfig
make FTRACE=1
///
U-Boot 2021.01-rc2-00139-gb3d3d69-dirty (Nov 25 2020 - 11:14:28 +0800)

DRAM:  1 GiB
trace: enabled
Flash: 64 MiB
MMC:   mmc@f0e0: 0
Loading Environment from SPIFlash... SF: Detected mx25u1635e with page
size 256 Bytes, erase size 4 KiB, total 2 MiB
OK
In:serial@f030
Out:   serial@f030
Err:   serial@f030
Net:   no alias for ethernet0
Warning: mac@e010 (eth0) using random MAC address - de:fa:3e:1b:11:42
eth0: mac@e010
Hit any key to stop autoboot:  0
RISC-V # fatload mmc 0:1 0x2000 ae350_rv64_smp_4_no_fd_coherent.dtb
6455 bytes read in 67 ms (93.8 KiB/s)
RISC-V # fatload mmc 0:1 0x0060 bootm_ae350_rv64_smp_bbl.bin
22518836 bytes read in 11915 ms (1.8 MiB/s

[PATCH v2] tpm: use more than sha256 on pcr_extend

2020-11-26 Thread Ilias Apalodimas
The current tpm2_pcr_extend is hardcoded using SHA256.
Let's make the actual command to the TPM2 configurable so we can support
a wider range of algorithms and keep the current command line as-is i.e
limited to SHA256 only

Signed-off-by: Ilias Apalodimas 
Reviewed-by: Simon Glass 
---
changes since v1:
 - add reference to the algorithms a user can pass to the function
   in the comments

 cmd/tpm-v2.c |  3 ++-
 include/tpm-v2.h |  5 -
 lib/tpm-v2.c | 11 ++-
 3 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/cmd/tpm-v2.c b/cmd/tpm-v2.c
index 5fa4788a72de..daae91100a2b 100644
--- a/cmd/tpm-v2.c
+++ b/cmd/tpm-v2.c
@@ -116,7 +116,8 @@ static int do_tpm2_pcr_extend(struct cmd_tbl *cmdtp, int 
flag, int argc,
if (index >= priv->pcr_count)
return -EINVAL;
 
-   rc = tpm2_pcr_extend(dev, index, digest);
+   rc = tpm2_pcr_extend(dev, index, TPM2_ALG_SHA256, digest,
+TPM2_DIGEST_LEN);
 
unmap_sysmem(digest);
 
diff --git a/include/tpm-v2.h b/include/tpm-v2.h
index 74c14fe7c51d..f1826ff38589 100644
--- a/include/tpm-v2.h
+++ b/include/tpm-v2.h
@@ -309,11 +309,14 @@ u32 tpm2_clear(struct udevice *dev, u32 handle, const 
char *pw,
  *
  * @devTPM device
  * @index  Index of the PCR
+ * @algorithm  Algorithm used, defined in 'enum tpm2_algorithms'
  * @digest Value representing the event to be recorded
+ * @digest_len  len of the hash
  *
  * @return code of the operation
  */
-u32 tpm2_pcr_extend(struct udevice *dev, u32 index, const uint8_t *digest);
+u32 tpm2_pcr_extend(struct udevice *dev, u32 index, u32 algorithm,
+   const u8 *digest, u32 digest_len);
 
 /**
  * Issue a TPM2_PCR_Read command.
diff --git a/lib/tpm-v2.c b/lib/tpm-v2.c
index 91759068cf03..1f3deb06e487 100644
--- a/lib/tpm-v2.c
+++ b/lib/tpm-v2.c
@@ -80,11 +80,12 @@ u32 tpm2_clear(struct udevice *dev, u32 handle, const char 
*pw,
return tpm_sendrecv_command(dev, command_v2, NULL, NULL);
 }
 
-u32 tpm2_pcr_extend(struct udevice *dev, u32 index, const uint8_t *digest)
+u32 tpm2_pcr_extend(struct udevice *dev, u32 index, u32 algorithm,
+   const u8 *digest, u32 digest_len)
 {
u8 command_v2[COMMAND_BUFFER_SIZE] = {
tpm_u16(TPM2_ST_SESSIONS),  /* TAG */
-   tpm_u32(33 + TPM2_DIGEST_LEN),  /* Length */
+   tpm_u32(33 + digest_len),   /* Length */
tpm_u32(TPM2_CC_PCR_EXTEND),/* Command code */
 
/* HANDLE */
@@ -99,7 +100,7 @@ u32 tpm2_pcr_extend(struct udevice *dev, u32 index, const 
uint8_t *digest)
tpm_u16(0), /* Size of  */
/*  (if any) */
tpm_u32(1), /* Count (number of hashes) */
-   tpm_u16(TPM2_ALG_SHA256),   /* Algorithm of the hash */
+   tpm_u16(algorithm), /* Algorithm of the hash */
/* STRING(digest)  Digest */
};
unsigned int offset = 33;
@@ -110,8 +111,8 @@ u32 tpm2_pcr_extend(struct udevice *dev, u32 index, const 
uint8_t *digest)
 * - the digest
 */
ret = pack_byte_string(command_v2, sizeof(command_v2), "s",
-  offset, digest, TPM2_DIGEST_LEN);
-   offset += TPM2_DIGEST_LEN;
+  offset, digest, digest_len);
+   offset += digest_len;
if (ret)
return TPM_LIB_ERROR;
 
-- 
2.29.2



[PATCH 1/1] common: always compile fixup_cmdtable()

2020-11-26 Thread Heinrich Schuchardt
With our optimization settings the linker eliminates unused functions.

But for debugging it is better to compile with -Og or -O0. With -O0
compiling the sandbox fails due to the missing function fixup_cmdtable()
called by dm_reloc() and others.

Signed-off-by: Heinrich Schuchardt 
---
 common/command.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/common/command.c b/common/command.c
index 2c491e20a7..345846f165 100644
--- a/common/command.c
+++ b/common/command.c
@@ -16,6 +16,8 @@
 #include 
 #include 

+DECLARE_GLOBAL_DATA_PTR;
+
 /*
  * Use puts() instead of printf() to avoid printf buffer overflow
  * for long help messages
@@ -488,9 +490,6 @@ int cmd_get_data_size(char* arg, int default_size)
 }
 #endif

-#if defined(CONFIG_NEEDS_MANUAL_RELOC)
-DECLARE_GLOBAL_DATA_PTR;
-
 void fixup_cmdtable(struct cmd_tbl *cmdtp, int size)
 {
int i;
@@ -535,7 +534,6 @@ void fixup_cmdtable(struct cmd_tbl *cmdtp, int size)
cmdtp++;
}
 }
-#endif

 int cmd_always_repeatable(struct cmd_tbl *cmdtp, int flag, int argc,
  char *const argv[], int *repeatable)
--
2.29.2



[PATCH 10/14] efi_loader: Re-factor code to build the signature store from efi signature list

2020-11-26 Thread Sughosh Ganu
The efi_sigstore_parse_sigdb function reads the uefi authenticated
variable, stored in the signature database format and builds the
signature store structure. Factor out the code for building
the signature store. This can then be used by the capsule
authentication routine to build the signature store even when the
signature database is not stored as an uefi authenticated variable

Signed-off-by: Sughosh Ganu 
---
 include/efi_loader.h   |   2 +
 lib/efi_loader/efi_signature.c | 103 +++--
 2 files changed, 63 insertions(+), 42 deletions(-)

diff --git a/include/efi_loader.h b/include/efi_loader.h
index b9226208f5..8d8a6649b5 100644
--- a/include/efi_loader.h
+++ b/include/efi_loader.h
@@ -803,6 +803,8 @@ efi_status_t efi_image_region_add(struct efi_image_regions 
*regs,
  int nocheck);
 
 void efi_sigstore_free(struct efi_signature_store *sigstore);
+struct efi_signature_store *efi_build_signature_store(void *sig_list,
+ efi_uintn_t size);
 struct efi_signature_store *efi_sigstore_parse_sigdb(u16 *name);
 
 bool efi_secure_boot_enabled(void);
diff --git a/lib/efi_loader/efi_signature.c b/lib/efi_loader/efi_signature.c
index 9ab071b611..87525bdc80 100644
--- a/lib/efi_loader/efi_signature.c
+++ b/lib/efi_loader/efi_signature.c
@@ -736,6 +736,63 @@ err:
return NULL;
 }
 
+/**
+ * efi_sigstore_parse_sigdb - parse the signature list and populate
+ * the signature store
+ *
+ * @sig_list:  Pointer to the signature list
+ * @size:  Size of the signature list
+ *
+ * Parse the efi signature list and instantiate a signature store
+ * structure.
+ *
+ * Return: Pointer to signature store on success, NULL on error
+ */
+struct efi_signature_store *efi_build_signature_store(void *sig_list,
+ efi_uintn_t size)
+{
+   struct efi_signature_list *esl;
+   struct efi_signature_store *sigstore = NULL, *siglist;
+
+   esl = sig_list;
+   while (size > 0) {
+   /* List must exist if there is remaining data. */
+   if (size < sizeof(*esl)) {
+   EFI_PRINT("Signature list in wrong format\n");
+   goto err;
+   }
+
+   if (size < esl->signature_list_size) {
+   EFI_PRINT("Signature list in wrong format\n");
+   goto err;
+   }
+
+   /* Parse a single siglist. */
+   siglist = efi_sigstore_parse_siglist(esl);
+   if (!siglist) {
+   EFI_PRINT("Parsing of signature list of failed\n");
+   goto err;
+   }
+
+   /* Append siglist */
+   siglist->next = sigstore;
+   sigstore = siglist;
+
+   /* Next */
+   size -= esl->signature_list_size;
+   esl = (void *)esl + esl->signature_list_size;
+   }
+   free(sig_list);
+
+   return sigstore;
+
+err:
+   efi_sigstore_free(sigstore);
+   free(sig_list);
+
+   return NULL;
+}
+
 /**
  * efi_sigstore_parse_sigdb - parse a signature database variable
  * @name:  Variable's name
@@ -747,8 +804,7 @@ err:
  */
 struct efi_signature_store *efi_sigstore_parse_sigdb(u16 *name)
 {
-   struct efi_signature_store *sigstore = NULL, *siglist;
-   struct efi_signature_list *esl;
+   struct efi_signature_store *sigstore = NULL;
const efi_guid_t *vendor;
void *db;
efi_uintn_t db_size;
@@ -784,47 +840,10 @@ struct efi_signature_store *efi_sigstore_parse_sigdb(u16 
*name)
ret = EFI_CALL(efi_get_variable(name, vendor, NULL, &db_size, db));
if (ret != EFI_SUCCESS) {
EFI_PRINT("Getting variable, %ls, failed\n", name);
-   goto err;
-   }
-
-   /* Parse siglist list */
-   esl = db;
-   while (db_size > 0) {
-   /* List must exist if there is remaining data. */
-   if (db_size < sizeof(*esl)) {
-   EFI_PRINT("variable, %ls, in wrong format\n", name);
-   goto err;
-   }
-
-   if (db_size < esl->signature_list_size) {
-   EFI_PRINT("variable, %ls, in wrong format\n", name);
-   goto err;
-   }
-
-   /* Parse a single siglist. */
-   siglist = efi_sigstore_parse_siglist(esl);
-   if (!siglist) {
-   EFI_PRINT("Parsing signature list of %ls failed\n",
- name);
-   goto err;
-   }
-
-   /* Append siglist */
-   siglist->next = sigstore;
-   sigstore = siglist;
-
-   /* Next */
-   db_size -= esl->signature_list_size;
-   esl = (void *)esl + esl->signature_list_size;
+   

[PATCH 13/14] efidebug: capsule: Add a command to update capsule on disk

2020-11-26 Thread Sughosh Ganu
Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu 
---
 cmd/efidebug.c | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/cmd/efidebug.c b/cmd/efidebug.c
index 7d327c8268..b8fe9ad6d5 100644
--- a/cmd/efidebug.c
+++ b/cmd/efidebug.c
@@ -79,6 +79,16 @@ static int do_efi_capsule_update(struct cmd_tbl *cmdtp, int 
flag,
return CMD_RET_SUCCESS;
 }
 
+static int do_efi_capsule_on_disk_update(struct cmd_tbl *cmdtp, int flag,
+int argc, char * const argv[])
+{
+   efi_status_t ret;
+
+   ret = efi_launch_capsules();
+
+   return ret == EFI_SUCCESS ? CMD_RET_SUCCESS : CMD_RET_FAILURE;
+}
+
 /**
  * do_efi_capsule_show() - show capsule information
  *
@@ -207,6 +217,8 @@ static struct cmd_tbl cmd_efidebug_capsule_sub[] = {
 "", ""),
U_BOOT_CMD_MKENT(show, CONFIG_SYS_MAXARGS, 1, do_efi_capsule_show,
 "", ""),
+   U_BOOT_CMD_MKENT(disk-update, 0, 0, do_efi_capsule_on_disk_update,
+"", ""),
U_BOOT_CMD_MKENT(result, CONFIG_SYS_MAXARGS, 1, do_efi_capsule_res,
 "", ""),
 };
@@ -1540,6 +1552,8 @@ static char efidebug_help_text[] =
 #ifdef CONFIG_EFI_HAVE_CAPSULE_SUPPORT
"efidebug capsule update [-v] \n"
"  - process a capsule\n"
+   "efidebug capsule disk-update\n"
+   "  - update a capsule from disk\n"
"efidebug capsule show \n"
"  - show capsule information\n"
"efidebug capsule result []\n"
-- 
2.17.1



[PATCH 14/14] qemu: arm64: Add documentation for capsule update

2020-11-26 Thread Sughosh Ganu
Add documentation highlighting the steps for using the uefi capsule
update feature for updating the u-boot firmware image.

Signed-off-by: Sughosh Ganu 
---
 doc/board/emulation/qemu-arm.rst | 157 +++
 1 file changed, 157 insertions(+)

diff --git a/doc/board/emulation/qemu-arm.rst b/doc/board/emulation/qemu-arm.rst
index 8d7fda10f1..3978c13269 100644
--- a/doc/board/emulation/qemu-arm.rst
+++ b/doc/board/emulation/qemu-arm.rst
@@ -90,3 +90,160 @@ The debug UART on the ARM virt board uses these settings::
 CONFIG_DEBUG_UART_PL010=y
 CONFIG_DEBUG_UART_BASE=0x900
 CONFIG_DEBUG_UART_CLOCK=0
+
+Enabling Uefi Capsule Update feature
+
+
+Support has been added for the uefi capsule update feature which
+enables updating the u-boot image using the uefi firmware management
+protocol (fmp). The capsules are not passed to the firmware through
+the UpdateCapsule runtime service. Instead, capsule-on-disk
+functionality is used for fetching the capsule from the EFI System
+Partition (ESP).
+
+Currently, support has been added for updating the u-boot binary as a
+raw image when the platform is booted in non-secure mode, i.e with
+CONFIG_TFABOOT disabled. For this configuration, the qemu platform
+needs to be booted with 'secure=off'. The u-boot binary placed on the
+first bank of the Nor Flash at offset 0x0. The u-boot environment is
+placed on the second Nor Flash bank at offset 0x400.
+
+The capsule update feature is enabled with the following configs::
+
+CONFIG_MTD=y
+CONFIG_FLASH_CFI_MTD=y
+CONFIG_CMD_MTDPARTS=y
+CONFIG_CMD_DFU=y
+CONFIG_DFU_MTD=y
+CONFIG_EFI_CAPSULE_ON_DISK=y
+CONFIG_EFI_CAPSULE_FIRMWARE_MANAGEMENT=y
+CONFIG_EFI_CAPSULE_FIRMWARE=y
+CONFIG_EFI_CAPSULE_FIRMWARE_RAW=y
+CONFIG_EFI_CAPSULE_FMP_HEADER=y
+
+In addition, the following config needs to be disabled::
+CONFIG_TFABOOT
+
+The capsule file can be generated by using the GenerateCapsule.py
+script in edk2::
+
+$ ./BaseTools/BinWrappers/PosixLike/GenerateCapsule -e -o \
+ --fw-version  --lsv  --guid \
+e2bb9c06-70e9-4b14-97a3-5a7913176e3f --verbose --update-image-index \
+ --verbose 
+
+If the above edk2 script is being used for generating the capsule, the
+following additional config needs to be enabled::
+CONFIG_EFI_CAPSULE_FMP_HEADER=y
+
+As per the uefi specification, the capsule file needs to be placed on
+the EFI System Partition, under the EFI/UpdateCapsule/ directory. The
+EFI System Partition can be a virtio-blk-device.
+
+Before initiating the firmware update, the efi variables BootNext,
+Boot and OsIndications need to be set. The Boot variable needs
+to be pointing to the EFI System Partition which contains the capsule
+file. The BootNext, Boot and OsIndications variables can be set
+using the following commands::
+
+=> efidebug boot add 0 Boot virtio 0:1 
+=> efidebug boot next 0
+=> setenv -e -nv -bs -rt -v OsIndications =0x04
+=> saveenv
+
+Finally, the capsule update can be initiated with the following
+command::
+
+=> efidebug capsule disk-update
+
+The updated u-boot image will be booted on subsequent boot.
+
+Enabling Capsule Authentication
+^^^
+
+The uefi specification defines a way of authenticating the capsule to
+be updated by verifying the capsule signature. The capsule signature
+is computed and prepended to the capsule payload at the time of
+capsule generation. This signature is then verified by using the
+public key stored as part of the X509 certificate. This certificate is
+in the form of an efi signature list (esl) file, which is embedded as
+part of the platform's device tree blob using the mkeficapsule
+utility.
+
+The capsule authentication feature can be enabled through the
+following config, in addition to the configs listed above for capsule
+update::
+
+CONFIG_EFI_CAPSULE_AUTHENTICATE=y
+
+The public key esl file can be embedded in the dtb with the following
+command::
+./tools/mkeficapsule -K  -D 
+
+Running the above command results in the creation of a 'signature'
+node in the dtb, under which the public key is stored as a
+'capsule-key' property.
+
+Once the esl file has been embedded as part of the dtb, the platform
+needs to be be booted with this dtb. This can be done by disabling the
+CONFIG_OF_BOARD option, and then, passing the above dtb file to the
+u-boot build.
+
+The capsule update with authentication can be enabled on the platform
+with the following steps
+
+1. Install utility commands on your host
+* openssl
+* efitools
+
+2. Create signing keys and certificate files on your host::
+
+$ openssl req -x509 -sha256 -newkey rsa:2048 -subj /CN=CRT/ \
+-keyout CRT.key -out CRT.crt -nodes -days 365
+$ cert-to-efi-sig-list CRT.crt CRT.esl
+
+$ openssl x509 -in CRT.crt -out CRT.cer -outform DER
+$ openssl x509 -inform DER -in CRT.cer

[PATCH 12/14] efi_loader: Enable uefi capsule authentication

2020-11-26 Thread Sughosh Ganu
Add support for enabling uefi capsule authentication. This feature is
enabled by setting the environment variable
"capsule_authentication_enabled".

The following configs are needed for enabling uefi capsule update and
capsule authentication features on the platform.

CONFIG_EFI_HAVE_CAPSULE_SUPPORT=y
CONFIG_EFI_CAPSULE_ON_DISK=y
CONFIG_EFI_CAPSULE_FIRMWARE_MANAGEMENT=y
CONFIG_EFI_CAPSULE_FIRMWARE=y
CONFIG_EFI_CAPSULE_FIRMWARE_RAW=y
CONFIG_EFI_CAPSULE_AUTHENTICATE=y

Signed-off-by: Sughosh Ganu 
---
 lib/efi_loader/efi_firmware.c | 37 ++-
 1 file changed, 36 insertions(+), 1 deletion(-)

diff --git a/lib/efi_loader/efi_firmware.c b/lib/efi_loader/efi_firmware.c
index 6c97604d8b..5e17b2ab5a 100644
--- a/lib/efi_loader/efi_firmware.c
+++ b/lib/efi_loader/efi_firmware.c
@@ -162,9 +162,16 @@ static efi_status_t efi_get_dfu_info(
image_info[i].version_name = NULL; /* not supported */
image_info[i].size = 0;
image_info[i].attributes_supported =
-   IMAGE_ATTRIBUTE_IMAGE_UPDATABLE;
+   IMAGE_ATTRIBUTE_IMAGE_UPDATABLE |
+   IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED;
image_info[i].attributes_setting =
IMAGE_ATTRIBUTE_IMAGE_UPDATABLE;
+
+   /* Check if the capsule authentication is enabled */
+   if (env_get("capsule_authentication_enabled"))
+   image_info[0].attributes_setting |=
+   IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED;
+
image_info[i].lowest_supported_image_version = 0;
image_info[i].last_attempt_version = 0;
image_info[i].last_attempt_status = LAST_ATTEMPT_STATUS_SUCCESS;
@@ -379,12 +386,40 @@ efi_status_t EFIAPI efi_firmware_raw_set_image(
efi_status_t (*progress)(efi_uintn_t completion),
u16 **abort_reason)
 {
+   void *capsule_payload;
+   efi_status_t status;
+   efi_uintn_t capsule_payload_size;
+
EFI_ENTRY("%p %d %p %ld %p %p %p\n", this, image_index, image,
  image_size, vendor_code, progress, abort_reason);
 
if (!image)
return EFI_EXIT(EFI_INVALID_PARAMETER);
 
+   /* Authenticate the capsule if authentication enabled */
+   if (IS_ENABLED(CONFIG_EFI_CAPSULE_AUTHENTICATE) &&
+   env_get("capsule_authentication_enabled")) {
+   capsule_payload = NULL;
+   capsule_payload_size = 0;
+   status = efi_capsule_authenticate(image, image_size,
+ &capsule_payload,
+ &capsule_payload_size);
+
+   if (status == EFI_SECURITY_VIOLATION) {
+   printf("Capsule authentication check failed. Aborting 
update\n");
+   return EFI_EXIT(status);
+   } else if (status != EFI_SUCCESS) {
+   return EFI_EXIT(status);
+   }
+
+   debug("Capsule authentication successfull\n");
+   image = capsule_payload;
+   image_size = capsule_payload_size;
+   } else {
+   debug("Capsule authentication disabled. ");
+   debug("Updating capsule without authenticating.\n");
+   }
+
if (CONFIG_IS_ENABLED(EFI_CAPSULE_FMP_HEADER)) {
/*
 * When building the capsule with the scripts in
-- 
2.17.1



[PATCH 11/14] efi: capsule: Add support for uefi capsule authentication

2020-11-26 Thread Sughosh Ganu
Add support for authenticating uefi capsules. Most of the signature
verification functionality is shared with the uefi secure boot
feature.

The root certificate containing the public key used for the signature
verification is stored as part of the device tree blob. The root
certificate is stored as an efi signature list(esl) file -- this file
contains the x509 certificate which is the root certificate.

Signed-off-by: Sughosh Ganu 
---
 board/emulation/qemu-arm/qemu-arm.c |  35 
 include/efi_api.h   |  18 
 include/efi_loader.h|   6 ++
 lib/efi_loader/Kconfig  |  17 
 lib/efi_loader/efi_capsule.c| 122 
 lib/efi_loader/efi_signature.c  |   4 +-
 6 files changed, 200 insertions(+), 2 deletions(-)

diff --git a/board/emulation/qemu-arm/qemu-arm.c 
b/board/emulation/qemu-arm/qemu-arm.c
index 8cad54c76f..5794d4c669 100644
--- a/board/emulation/qemu-arm/qemu-arm.c
+++ b/board/emulation/qemu-arm/qemu-arm.c
@@ -208,6 +208,41 @@ void flash_write32(u32 value, void *addr)
 
 #define DFU_ALT_BUF_LENSZ_1K
 
+int efi_get_public_key_data(void **pkey, efi_uintn_t *pkey_len)
+{
+   const void *fdt_blob = gd->fdt_blob;
+   const void *blob;
+   const char *cnode_name = "capsule-key";
+   const char *snode_name = "signature";
+   int sig_node;
+   int len;
+
+   sig_node = fdt_subnode_offset(fdt_blob, 0, snode_name);
+   if (sig_node < 0) {
+   EFI_PRINT("Unable to get signature node offset\n");
+   return -FDT_ERR_NOTFOUND;
+   }
+
+   blob = fdt_getprop(fdt_blob, sig_node, cnode_name, &len);
+
+   if (!blob || len < 0) {
+   EFI_PRINT("Unable to get capsule-key value\n");
+   *pkey = NULL;
+   *pkey_len = 0;
+   return -FDT_ERR_NOTFOUND;
+   }
+
+   *pkey = (void *)blob;
+   *pkey_len = len;
+
+   return 0;
+}
+
+bool efi_capsule_auth_enabled(void)
+{
+   return env_get("capsule_authentication_enabled") != NULL ? true : false;
+}
+
 static void board_get_alt_info(struct mtd_info *mtd, char *buf)
 {
struct mtd_info *part;
diff --git a/include/efi_api.h b/include/efi_api.h
index c7038f863a..bcf6de6629 100644
--- a/include/efi_api.h
+++ b/include/efi_api.h
@@ -1808,6 +1808,24 @@ struct efi_variable_authentication_2 {
struct win_certificate_uefi_guid auth_info;
 } __attribute__((__packed__));
 
+/**
+ * efi_firmware_image_authentication - Capsule authentication method
+ * descriptor
+ *
+ * This structure describes an authentication information for
+ * a capsule with IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED set
+ * and should be included as part of the capsule.
+ * Only EFI_CERT_TYPE_PKCS7_GUID is accepted.
+ *
+ * @monotonic_count: Count to prevent replay
+ * @auth_info: Authentication info
+ */
+struct efi_firmware_image_authentication {
+   uint64_t monotonic_count;
+   struct win_certificate_uefi_guid auth_info;
+} __attribute__((__packed__));
+
+
 /**
  * efi_signature_data - A format of signature
  *
diff --git a/include/efi_loader.h b/include/efi_loader.h
index 8d8a6649b5..d311317fc1 100644
--- a/include/efi_loader.h
+++ b/include/efi_loader.h
@@ -809,6 +809,8 @@ struct efi_signature_store *efi_sigstore_parse_sigdb(u16 
*name);
 
 bool efi_secure_boot_enabled(void);
 
+bool efi_capsule_auth_enabled(void);
+
 bool efi_image_parse(void *efi, size_t len, struct efi_image_regions **regp,
 WIN_CERTIFICATE **auth, size_t *auth_len);
 
@@ -836,6 +838,10 @@ efi_status_t EFIAPI efi_query_capsule_caps(
u64 *maximum_capsule_size,
u32 *reset_type);
 
+efi_status_t efi_capsule_authenticate(const void *capsule,
+ efi_uintn_t capsule_size,
+ void **image, efi_uintn_t *image_size);
+
 #define EFI_CAPSULE_DIR L"\\EFI\\UpdateCapsule\\"
 
 /* Hook at initialization */
diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig
index 55e4787e32..597ad6b2a7 100644
--- a/lib/efi_loader/Kconfig
+++ b/lib/efi_loader/Kconfig
@@ -145,6 +145,23 @@ config EFI_CAPSULE_FMP_HEADER
  Select this option if the capsule is built using the
  scripts in edk2.
 
+config EFI_CAPSULE_AUTHENTICATE
+   bool "Update Capsule authentication"
+   depends on EFI_CAPSULE_FIRMWARE
+   depends on EFI_CAPSULE_ON_DISK
+   depends on EFI_CAPSULE_FIRMWARE_MANAGEMENT
+   select SHA256
+   select RSA
+   select RSA_VERIFY
+   select RSA_VERIFY_WITH_PKEY
+   select X509_CERTIFICATE_PARSER
+   select PKCS7_MESSAGE_PARSER
+   select PKCS7_VERIFY
+   default n
+   help
+ Select this option if you want to enable capsule
+ authentication
+
 config EFI_CAPSULE_FIRMWARE_FIT
bool "FMP driver for FIT image"
depends on EFI_CAPSULE_FIRMWARE_MANAGEMENT
diff --git a/lib/efi_loader/efi_capsule.c b/

[PATCH 09/14] efi_loader: Make the pkcs7 header parsing function an extern

2020-11-26 Thread Sughosh Ganu
The pkcs7 header parsing functionality is pretty generic, and can be
used by other features like capsule authentication. Make the function
an extern, also changing it's name to efi_parse_pkcs7_header

Signed-off-by: Sughosh Ganu 
---
 include/efi_loader.h   |  4 ++
 lib/efi_loader/efi_signature.c | 85 +++
 lib/efi_loader/efi_variable.c  | 93 ++
 3 files changed, 93 insertions(+), 89 deletions(-)

diff --git a/include/efi_loader.h b/include/efi_loader.h
index 76cd2b36f2..b9226208f5 100644
--- a/include/efi_loader.h
+++ b/include/efi_loader.h
@@ -810,6 +810,10 @@ bool efi_secure_boot_enabled(void);
 bool efi_image_parse(void *efi, size_t len, struct efi_image_regions **regp,
 WIN_CERTIFICATE **auth, size_t *auth_len);
 
+struct pkcs7_message *efi_parse_pkcs7_header(const void *buf,
+size_t buflen,
+u8 **tmpbuf);
+
 /* runtime implementation of memcpy() */
 void efi_memcpy_runtime(void *dest, const void *src, size_t n);
 
diff --git a/lib/efi_loader/efi_signature.c b/lib/efi_loader/efi_signature.c
index 79dee27421..9ab071b611 100644
--- a/lib/efi_loader/efi_signature.c
+++ b/lib/efi_loader/efi_signature.c
@@ -27,6 +27,91 @@ const efi_guid_t efi_guid_cert_x509_sha256 = 
EFI_CERT_X509_SHA256_GUID;
 const efi_guid_t efi_guid_cert_type_pkcs7 = EFI_CERT_TYPE_PKCS7_GUID;
 
 #ifdef CONFIG_EFI_SECURE_BOOT
+static u8 pkcs7_hdr[] = {
+   /* SEQUENCE */
+   0x30, 0x82, 0x05, 0xc7,
+   /* OID: pkcs7-signedData */
+   0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x07, 0x02,
+   /* Context Structured? */
+   0xa0, 0x82, 0x05, 0xb8,
+};
+
+/**
+ * efi_parse_pkcs7_header - parse a signature in payload
+ * @buf:   Pointer to payload's value
+ * @buflen:Length of @buf
+ * @tmpbuf:Pointer to temporary buffer
+ *
+ * Parse a signature embedded in payload's value and instantiate
+ * a pkcs7_message structure. Since pkcs7_parse_message() accepts only
+ * pkcs7's signedData, some header needed be prepended for correctly
+ * parsing authentication data
+ * A temporary buffer will be allocated if needed, and it should be
+ * kept valid during the authentication because some data in the buffer
+ * will be referenced by efi_signature_verify().
+ *
+ * Return: Pointer to pkcs7_message structure on success, NULL on error
+ */
+struct pkcs7_message *efi_parse_pkcs7_header(const void *buf,
+size_t buflen,
+u8 **tmpbuf)
+{
+   u8 *ebuf;
+   size_t ebuflen, len;
+   struct pkcs7_message *msg;
+
+   /*
+* This is the best assumption to check if the binary is
+* already in a form of pkcs7's signedData.
+*/
+   if (buflen > sizeof(pkcs7_hdr) &&
+   !memcmp(&((u8 *)buf)[4], &pkcs7_hdr[4], 11)) {
+   msg = pkcs7_parse_message(buf, buflen);
+   if (IS_ERR(msg))
+   return NULL;
+   return msg;
+   }
+
+   /*
+* Otherwise, we should add a dummy prefix sequence for pkcs7
+* message parser to be able to process.
+* NOTE: EDK2 also uses similar hack in WrapPkcs7Data()
+* in CryptoPkg/Library/BaseCryptLib/Pk/CryptPkcs7VerifyCommon.c
+* TODO:
+* The header should be composed in a more refined manner.
+*/
+   EFI_PRINT("Makeshift prefix added to authentication data\n");
+   ebuflen = sizeof(pkcs7_hdr) + buflen;
+   if (ebuflen <= 0x7f) {
+   EFI_PRINT("Data is too short\n");
+   return NULL;
+   }
+
+   ebuf = malloc(ebuflen);
+   if (!ebuf) {
+   EFI_PRINT("Out of memory\n");
+   return NULL;
+   }
+
+   memcpy(ebuf, pkcs7_hdr, sizeof(pkcs7_hdr));
+   memcpy(ebuf + sizeof(pkcs7_hdr), buf, buflen);
+   len = ebuflen - 4;
+   ebuf[2] = (len >> 8) & 0xff;
+   ebuf[3] = len & 0xff;
+   len = ebuflen - 0x13;
+   ebuf[0x11] = (len >> 8) & 0xff;
+   ebuf[0x12] = len & 0xff;
+
+   msg = pkcs7_parse_message(ebuf, ebuflen);
+
+   if (IS_ERR(msg)) {
+   free(ebuf);
+   return NULL;
+   }
+
+   *tmpbuf = ebuf;
+   return msg;
+}
 
 /**
  * efi_hash_regions - calculate a hash value
diff --git a/lib/efi_loader/efi_variable.c b/lib/efi_loader/efi_variable.c
index 0c689cfb47..ba0874e9e7 100644
--- a/lib/efi_loader/efi_variable.c
+++ b/lib/efi_loader/efi_variable.c
@@ -24,91 +24,6 @@
 #include 
 
 #ifdef CONFIG_EFI_SECURE_BOOT
-static u8 pkcs7_hdr[] = {
-   /* SEQUENCE */
-   0x30, 0x82, 0x05, 0xc7,
-   /* OID: pkcs7-signedData */
-   0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x07, 0x02,
-   /* Context Structured? */
-   0xa0, 0x82, 0x05, 0xb8,
-};
-
-/**
- * efi_variable_parse_signature - parse a signature in

[PATCH 08/14] dfu_mtd: Add provision to unlock mtd device

2020-11-26 Thread Sughosh Ganu
Prior to writing to an mtd device, mtd_erase is called. This call
fails in case the sector being erased is locked. Call mtd_unlock to
unlock the region which is to be erased and later written to. Lock the
region once the write to the region has completed.

Signed-off-by: Sughosh Ganu 
---
 drivers/dfu/dfu_mtd.c | 20 +---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/drivers/dfu/dfu_mtd.c b/drivers/dfu/dfu_mtd.c
index 36cd4e945b..b34975dbb0 100644
--- a/drivers/dfu/dfu_mtd.c
+++ b/drivers/dfu/dfu_mtd.c
@@ -21,7 +21,7 @@ static bool mtd_is_aligned_with_block_size(struct mtd_info 
*mtd, u64 size)
 static int mtd_block_op(enum dfu_op op, struct dfu_entity *dfu,
u64 offset, void *buf, long *len)
 {
-   u64 off, lim, remaining;
+   u64 off, lim, remaining, lock_ofs, lock_len;
struct mtd_info *mtd = dfu->data.mtd.info;
struct mtd_oob_ops io_op = {};
int ret = 0;
@@ -34,7 +34,7 @@ static int mtd_block_op(enum dfu_op op, struct dfu_entity 
*dfu,
return 0;
}
 
-   off = dfu->data.mtd.start + offset + dfu->bad_skip;
+   off = lock_ofs = dfu->data.mtd.start + offset + dfu->bad_skip;
lim = dfu->data.mtd.start + dfu->data.mtd.size;
 
if (off >= lim) {
@@ -56,12 +56,19 @@ static int mtd_block_op(enum dfu_op op, struct dfu_entity 
*dfu,
if (op == DFU_OP_WRITE) {
struct erase_info erase_op = {};
 
-   remaining = round_up(*len, mtd->erasesize);
+   remaining = lock_len = round_up(*len, mtd->erasesize);
erase_op.mtd = mtd;
erase_op.addr = off;
erase_op.len = mtd->erasesize;
erase_op.scrub = 0;
 
+   debug("Unlocking the mtd device\n");
+   ret = mtd_unlock(mtd, lock_ofs, lock_len);
+   if (ret && ret != -EOPNOTSUPP) {
+   printf("MTD device unlock failed\n");
+   return 0;
+   }
+
while (remaining) {
if (erase_op.addr + remaining > lim) {
printf("Limit reached 0x%llx while erasing at 
offset 0x%llx\n",
@@ -139,6 +146,13 @@ static int mtd_block_op(enum dfu_op op, struct dfu_entity 
*dfu,
io_op.len = mtd->writesize;
}
 
+   if (op == DFU_OP_WRITE) {
+   /* Write done, lock again */
+   debug("Locking the mtd device\n");
+   ret = mtd_lock(mtd, lock_ofs, lock_len);
+   if (ret && ret != -EOPNOTSUPP)
+   printf("MTD device lock failed\n");
+   }
return ret;
 }
 
-- 
2.17.1



[PATCH 07/14] efi_loader: Add config option to indicate fmp header presence

2020-11-26 Thread Sughosh Ganu
When building the capsule using scripts in edk2, an fmp header is
added on top of the binary payload. Add a config option to indicate
the presence of the header. When enabled, the pointer to the image
needs to be adjusted as per the size of the header to point to the
actual binary payload.

Signed-off-by: Sughosh Ganu 
---
 lib/efi_loader/Kconfig|  7 +++
 lib/efi_loader/efi_firmware.c | 12 
 2 files changed, 19 insertions(+)

diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig
index 0d1b1b5356..55e4787e32 100644
--- a/lib/efi_loader/Kconfig
+++ b/lib/efi_loader/Kconfig
@@ -138,6 +138,13 @@ config EFI_CAPSULE_FIRMWARE_MANAGEMENT
  Select this option if you want to enable capsule-based
  firmware update using Firmware Management Protocol.
 
+config EFI_CAPSULE_FMP_HEADER
+   bool "Capsule uses FMP header"
+   depends on EFI_CAPSULE_FIRMWARE_MANAGEMENT
+   help
+ Select this option if the capsule is built using the
+ scripts in edk2.
+
 config EFI_CAPSULE_FIRMWARE_FIT
bool "FMP driver for FIT image"
depends on EFI_CAPSULE_FIRMWARE_MANAGEMENT
diff --git a/lib/efi_loader/efi_firmware.c b/lib/efi_loader/efi_firmware.c
index 7e56077383..6c97604d8b 100644
--- a/lib/efi_loader/efi_firmware.c
+++ b/lib/efi_loader/efi_firmware.c
@@ -385,10 +385,22 @@ efi_status_t EFIAPI efi_firmware_raw_set_image(
if (!image)
return EFI_EXIT(EFI_INVALID_PARAMETER);
 
+   if (CONFIG_IS_ENABLED(EFI_CAPSULE_FMP_HEADER)) {
+   /*
+* When building the capsule with the scripts in
+* edk2, a FMP header is inserted above the capsule
+* payload. Compensate for this header to get the
+* actual payload that is to be updated.
+*/
+   image += 0x10;
+   image_size -= 0x10;
+   }
+
if (dfu_write_by_alt(image_index - 1, (void *)image, image_size,
 NULL, NULL))
return EFI_EXIT(EFI_DEVICE_ERROR);
 
+   printf("%s: Capsule update complete!\n", __func__);
return EFI_EXIT(EFI_SUCCESS);
 }
 
-- 
2.17.1



[PATCH 06/14] qemu: arm64: Set dfu_alt_info variable for the platform

2020-11-26 Thread Sughosh Ganu
The dfu framework uses the dfu_alt_info environment variable to get
information that is needed for performing the firmware update. Set the
dfu_alt_info for the platform to reflect the two mtd partitions
created for the u-boot env and the firmware image.

Signed-off-by: Sughosh Ganu 
---
 board/emulation/qemu-arm/qemu-arm.c | 55 +
 include/configs/qemu-arm.h  |  1 +
 2 files changed, 56 insertions(+)

diff --git a/board/emulation/qemu-arm/qemu-arm.c 
b/board/emulation/qemu-arm/qemu-arm.c
index d5ed3eebaf..8cad54c76f 100644
--- a/board/emulation/qemu-arm/qemu-arm.c
+++ b/board/emulation/qemu-arm/qemu-arm.c
@@ -200,8 +200,63 @@ void flash_write32(u32 value, void *addr)
 
 #if defined(CONFIG_EFI_CAPSULE_FIRMWARE_MANAGEMENT)
 
+#include 
 #include 
 
+#define MTDPARTS_LEN   256
+#define MTDIDS_LEN 128
+
+#define DFU_ALT_BUF_LENSZ_1K
+
+static void board_get_alt_info(struct mtd_info *mtd, char *buf)
+{
+   struct mtd_info *part;
+   bool first = true;
+   const char *name;
+   int len, partnum = 0;
+
+   name = mtd->name;
+   len = strlen(buf);
+
+   if (buf[0] != '\0')
+   len += snprintf(buf + len, DFU_ALT_BUF_LEN - len, "&");
+   len += snprintf(buf + len, DFU_ALT_BUF_LEN - len,
+   "mtd %s=", name);
+
+   list_for_each_entry(part, &mtd->partitions, node) {
+   partnum++;
+   if (!first)
+   len += snprintf(buf + len, DFU_ALT_BUF_LEN - len, ";");
+   first = false;
+
+   len += snprintf(buf + len, DFU_ALT_BUF_LEN - len,
+   "%s part %d",
+   part->name, partnum);
+   }
+}
+
+void set_dfu_alt_info(char *interface, char *devstr)
+{
+   struct mtd_info *mtd;
+
+   ALLOC_CACHE_ALIGN_BUFFER(char, buf, DFU_ALT_BUF_LEN);
+
+   if (env_get("dfu_alt_info"))
+   return;
+
+   memset(buf, 0, sizeof(buf));
+
+   /* probe all MTD devices */
+   mtd_probe_devices();
+
+   mtd = get_mtd_device_nm("nor0");
+   if (!IS_ERR_OR_NULL(mtd))
+   board_get_alt_info(mtd, buf);
+
+   env_set("dfu_alt_info", buf);
+   printf("dfu_alt_info set\n");
+}
+
 static void board_get_mtdparts(const char *dev, const char *partition,
   char *mtdids, char *mtdparts)
 {
diff --git a/include/configs/qemu-arm.h b/include/configs/qemu-arm.h
index 69ff329434..726f985d35 100644
--- a/include/configs/qemu-arm.h
+++ b/include/configs/qemu-arm.h
@@ -33,6 +33,7 @@
 #include 
 
 #if defined(CONFIG_EFI_CAPSULE_FIRMWARE_MANAGEMENT)
+#define CONFIG_SET_DFU_ALT_INFO
 #define CONFIG_SYS_MTDPARTS_RUNTIME
 #endif
 
-- 
2.17.1



[PATCH 05/14] qemu: arm64: Add support for dynamic mtdparts for the platform

2020-11-26 Thread Sughosh Ganu
Add support for setting the default values for mtd partitions on the
platform for the nor flash. This would be used for updating the
firmware image using uefi capsule update with the dfu mtd backend
driver.

Signed-off-by: Sughosh Ganu 
---
 board/emulation/qemu-arm/qemu-arm.c | 70 +
 include/configs/qemu-arm.h  |  7 +++
 2 files changed, 77 insertions(+)

diff --git a/board/emulation/qemu-arm/qemu-arm.c 
b/board/emulation/qemu-arm/qemu-arm.c
index b3d5b3d5c2..d5ed3eebaf 100644
--- a/board/emulation/qemu-arm/qemu-arm.c
+++ b/board/emulation/qemu-arm/qemu-arm.c
@@ -197,3 +197,73 @@ void flash_write32(u32 value, void *addr)
 {
asm("str %" __W "1, %0" : "=m"(*(u32 *)addr) : "r"(value));
 }
+
+#if defined(CONFIG_EFI_CAPSULE_FIRMWARE_MANAGEMENT)
+
+#include 
+
+static void board_get_mtdparts(const char *dev, const char *partition,
+  char *mtdids, char *mtdparts)
+{
+   /* mtdids: "=, " */
+   if (mtdids[0] != '\0')
+   strcat(mtdids, ",");
+   strcat(mtdids, dev);
+   strcat(mtdids, "=");
+   strcat(mtdids, dev);
+
+   /* mtdparts: "mtdparts=:>;..." */
+   if (mtdparts[0] != '\0')
+   strncat(mtdparts, ";", MTDPARTS_LEN);
+   else
+   strcat(mtdparts, "mtdparts=");
+
+   strncat(mtdparts, dev, MTDPARTS_LEN);
+   strncat(mtdparts, ":", MTDPARTS_LEN);
+   strncat(mtdparts, partition, MTDPARTS_LEN);
+}
+
+void board_mtdparts_default(const char **mtdids, const char **mtdparts)
+{
+   struct mtd_info *mtd;
+   struct udevice *dev;
+   const char *mtd_partition;
+   static char parts[3 * MTDPARTS_LEN + 1];
+   static char ids[MTDIDS_LEN + 1];
+   static bool mtd_initialized;
+
+   if (mtd_initialized) {
+   *mtdids = ids;
+   *mtdparts = parts;
+   return;
+   }
+
+   memset(parts, 0, sizeof(parts));
+   memset(ids, 0, sizeof(ids));
+
+   /* probe all MTD devices */
+   for (uclass_first_device(UCLASS_MTD, &dev); dev;
+uclass_next_device(&dev)) {
+   debug("mtd device = %s\n", dev->name);
+   }
+
+   mtd = get_mtd_device_nm("nor0");
+   if (!IS_ERR_OR_NULL(mtd)) {
+   mtd_partition = MTDPARTS_NOR0;
+   board_get_mtdparts("nor0", mtd_partition, ids, parts);
+   put_mtd_device(mtd);
+   }
+
+   mtd = get_mtd_device_nm("nor1");
+   if (!IS_ERR_OR_NULL(mtd)) {
+   mtd_partition = MTDPARTS_NOR1;
+   board_get_mtdparts("nor1", mtd_partition, ids, parts);
+   put_mtd_device(mtd);
+   }
+
+   mtd_initialized = true;
+   *mtdids = ids;
+   *mtdparts = parts;
+   debug("%s:mtdids=%s & mtdparts=%s\n", __func__, ids, parts);
+}
+#endif /* CONFIG_EFI_CAPSULE_FIRMWARE_MANAGEMENT */
diff --git a/include/configs/qemu-arm.h b/include/configs/qemu-arm.h
index 273fa1a7d7..69ff329434 100644
--- a/include/configs/qemu-arm.h
+++ b/include/configs/qemu-arm.h
@@ -32,6 +32,13 @@
 
 #include 
 
+#if defined(CONFIG_EFI_CAPSULE_FIRMWARE_MANAGEMENT)
+#define CONFIG_SYS_MTDPARTS_RUNTIME
+#endif
+
+#define MTDPARTS_NOR0  "64m(u-boot)\0"
+#define MTDPARTS_NOR1  "64m(u-boot-env)\0"
+
 #define CONFIG_EXTRA_ENV_SETTINGS \
"fdt_high=0x\0" \
"initrd_high=0x\0" \
-- 
2.17.1



[PATCH 04/14] crypto: Fix the logic to calculate hash with authattributes set

2020-11-26 Thread Sughosh Ganu
RFC 2315 Section 9.3 describes the message digesting process. The
digest calculated depends on whether the authenticated attributes are
present. In case of a scenario where the authenticated attributes are
present, the message digest that gets signed and is part of the pkcs7
message is computed from the auth attributes rather than the contents
field.

Check if the auth attributes are present, and if set, use the auth
attributes to compute the hash that would be compared with the
encrypted hash on the pkcs7 message.

Signed-off-by: Sughosh Ganu 
---
 lib/crypto/pkcs7_verify.c | 37 ++---
 1 file changed, 26 insertions(+), 11 deletions(-)

diff --git a/lib/crypto/pkcs7_verify.c b/lib/crypto/pkcs7_verify.c
index 320ba49f79..58683ef614 100644
--- a/lib/crypto/pkcs7_verify.c
+++ b/lib/crypto/pkcs7_verify.c
@@ -50,8 +50,15 @@ static int pkcs7_digest(struct pkcs7_message *pkcs7,
struct image_region regions[2];
int ret = 0;
 
-   /* The digest was calculated already. */
-   if (sig->digest)
+   /*
+* [RFC2315 9.3]
+* If the authenticated attributes are present,
+* the message-digest is calculated on the
+* attributes present in the
+* authenticatedAttributes field and not just
+* the contents field
+*/
+   if (!sinfo->authattrs && sig->digest)
return 0;
 
if (!sinfo->sig->hash_algo)
@@ -63,17 +70,25 @@ static int pkcs7_digest(struct pkcs7_message *pkcs7,
else
return -ENOPKG;
 
-   sig->digest = calloc(1, sig->digest_size);
-   if (!sig->digest) {
-   pr_warn("Sig %u: Out of memory\n", sinfo->index);
-   return -ENOMEM;
-   }
+   /*
+* Calculate the hash only if the data is present.
+* In case of authenticated variable and capsule,
+* the hash has already been calculated on the
+* efi_image_regions and populated
+*/
+   if (pkcs7->data) {
+   sig->digest = calloc(1, sig->digest_size);
+   if (!sig->digest) {
+   pr_warn("Sig %u: Out of memory\n", sinfo->index);
+   return -ENOMEM;
+   }
 
-   regions[0].data = pkcs7->data;
-   regions[0].size = pkcs7->data_len;
+   regions[0].data = pkcs7->data;
+   regions[0].size = pkcs7->data_len;
 
-   /* Digest the message [RFC2315 9.3] */
-   hash_calculate(sinfo->sig->hash_algo, regions, 1, sig->digest);
+   /* Digest the message [RFC2315 9.3] */
+   hash_calculate(sinfo->sig->hash_algo, regions, 1, sig->digest);
+   }
 
/* However, if there are authenticated attributes, there must be a
 * message digest attribute amongst them which corresponds to the
-- 
2.17.1



[PATCH 03/14] qemu: arm: Scan the pci bus in board_init

2020-11-26 Thread Sughosh Ganu
Scan the pci bus in board_init routine before scanning the virtio
devices. This enumerates all the virtio devices, including devices
found on the pci bus.

Signed-off-by: Sughosh Ganu 
---
 board/emulation/qemu-arm/qemu-arm.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/board/emulation/qemu-arm/qemu-arm.c 
b/board/emulation/qemu-arm/qemu-arm.c
index e146d1cc50..b3d5b3d5c2 100644
--- a/board/emulation/qemu-arm/qemu-arm.c
+++ b/board/emulation/qemu-arm/qemu-arm.c
@@ -65,6 +65,14 @@ struct mm_region *mem_map = qemu_arm64_mem_map;
 
 int board_init(void)
 {
+
+   /*
+* Scan the pci bus before calling virtio_init. This
+* enumerates all virtio devices, including devices
+* on the pci bus.
+*/
+   pci_init();
+
/*
 * Make sure virtio bus is enumerated so that peripherals
 * on the virtio bus can be discovered by their drivers
-- 
2.17.1



[PATCH 02/14] mkeficapsule: Add support for embedding public key in a dtb

2020-11-26 Thread Sughosh Ganu
Add options for embedding the public key esl(efi signature list) file
to the platform's dtb. The esl file is then retrieved and used for
authenticating the capsule to be used for updating firmare components
on the platform.

The esl file can now be embedded in the dtb by invoking the following
command
mkeficapsule -K  -D 

This will create a node named 'signature' in the dtb, and the esl file
will be stored as 'capsule-key'

Signed-off-by: Sughosh Ganu 
---
 tools/Makefile   |   1 +
 tools/mkeficapsule.c | 198 ---
 2 files changed, 186 insertions(+), 13 deletions(-)

diff --git a/tools/Makefile b/tools/Makefile
index 66d9376803..6d7b48fb57 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -218,6 +218,7 @@ hostprogs-$(CONFIG_MIPS) += mips-relocs
 hostprogs-$(CONFIG_ASN1_COMPILER)  += asn1_compiler
 HOSTCFLAGS_asn1_compiler.o = -idirafter $(srctree)/include
 
+mkeficapsule-objs  := mkeficapsule.o $(LIBFDT_OBJS)
 hostprogs-$(CONFIG_EFI_HAVE_CAPSULE_SUPPORT) += mkeficapsule
 
 # We build some files with extra pedantic flags to try to minimize things
diff --git a/tools/mkeficapsule.c b/tools/mkeficapsule.c
index 45e27d74a5..ce05da12d6 100644
--- a/tools/mkeficapsule.c
+++ b/tools/mkeficapsule.c
@@ -4,16 +4,22 @@
  * Author: AKASHI Takahiro
  */
 
+#include 
 #include 
 #include 
 #include 
 #include 
 #include 
 #include 
+#include 
 #include 
+
+#include 
 #include 
 #include 
 
+#include "fdt_host.h"
+
 typedef __u8 u8;
 typedef __u16 u16;
 typedef __u32 u32;
@@ -23,6 +29,8 @@ typedef __s32 s32;
 
 #define aligned_u64 __aligned_u64
 
+#define SIGNATURE_NODENAME "signature"
+
 #ifndef __packed
 #define __packed __attribute__((packed))
 #endif
@@ -43,6 +51,8 @@ static struct option options[] = {
{"raw", required_argument, NULL, 'r'},
{"index", required_argument, NULL, 'i'},
{"instance", required_argument, NULL, 'I'},
+   {"dtb", required_argument, NULL, 'D'},
+   {"public key", required_argument, NULL, 'K'},
{"version", required_argument, NULL, 'v'},
{"help", no_argument, NULL, 'h'},
{NULL, 0, NULL, 0},
@@ -52,15 +62,154 @@ static void print_usage(void)
 {
printf("Usage: %s [options] \n"
   "Options:\n"
-  "\t--fit   new FIT image file\n"
-  "\t--raw   new raw image file\n"
-  "\t--index update image index\n"
-  "\t--instance   update hardware instance\n"
-  "\t--version firmware version\n"
-  "\t--help print a help message\n",
+  "\t--fitnew FIT image file\n"
+  "\t--rawnew raw image file\n"
+  "\t--index  update image index\n"
+  "\t--instanceupdate hardware instance\n"
+  "\t--version  firmware version\n"
+  "\t--public-key  public key esl file\n"
+  "\t--dtb dtb file\n"
+  "\t--help  print a help message\n",
   tool_name);
 }
 
+static int fdt_add_pub_key_data(void *sptr, void *dptr, size_t key_size)
+{
+   int parent;
+   int ret = 0;
+
+   parent = fdt_subnode_offset(dptr, 0, SIGNATURE_NODENAME);
+   if (parent == -FDT_ERR_NOTFOUND) {
+   parent = fdt_add_subnode(dptr, 0, SIGNATURE_NODENAME);
+   if (parent < 0) {
+   ret = parent;
+   if (ret != -FDT_ERR_NOSPACE) {
+   fprintf(stderr,
+   "Couldn't create signature node: %s\n",
+   fdt_strerror(parent));
+   }
+   }
+   }
+   if (ret)
+   goto done;
+
+   /* Write the key to the FDT node */
+   ret = fdt_setprop(dptr, parent, "capsule-key",
+ sptr, key_size);
+
+done:
+   if (ret)
+   ret = ret == -FDT_ERR_NOSPACE ? -ENOSPC : -EIO;
+
+   return ret;
+}
+
+static int add_public_key(const char *pkey_file, const char *dtb_file)
+{
+   int ret;
+   int srcfd = 0;
+   int destfd = 0;
+   void *sptr = NULL;
+   void *dptr = NULL;
+   off_t src_size;
+   struct stat pub_key;
+   struct stat dtb;
+
+   /* Find out the size of the public key */
+   srcfd = open(pkey_file, O_RDONLY);
+   if (srcfd == -1) {
+   fprintf(stderr, "%s: Can't open %s: %s\n",
+   __func__, pkey_file, strerror(errno));
+   goto err;
+   }
+
+   ret = fstat(srcfd, &pub_key);
+   if (ret == -1) {
+   fprintf(stderr, "%s: Can't stat %s: %s\n",
+   __func__, pkey_file, strerror(errno));
+   goto err;
+   }
+
+   src_size = pub_key.st_size;
+
+   /* mmap the public key esl file */
+   sptr = mmap(0, src_size, PROT_READ, MAP_SHARED, srcfd, 0);
+

[PATCH 01/14] qemu: arm: Use the generated DTB only when CONGIG_OF_BOARD is defined

2020-11-26 Thread Sughosh Ganu
The Qemu platform emulator generates a device tree blob and places it
at the start of the dram, which is then used by u-boot. Use this dtb
only if CONFIG_OF_BOARD is defined. This allows using a different
device tree, using the CONFIG_OF_SEPARATE option. This dtb is attached
to the u-boot binary as a u-boot-fdt.bin file

Signed-off-by: Sughosh Ganu 
---
 board/emulation/qemu-arm/qemu-arm.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/board/emulation/qemu-arm/qemu-arm.c 
b/board/emulation/qemu-arm/qemu-arm.c
index f18f2ed7da..e146d1cc50 100644
--- a/board/emulation/qemu-arm/qemu-arm.c
+++ b/board/emulation/qemu-arm/qemu-arm.c
@@ -89,11 +89,13 @@ int dram_init_banksize(void)
return 0;
 }
 
+#if defined(CONFIG_OF_BOARD)
 void *board_fdt_blob_setup(void)
 {
/* QEMU loads a generated DTB for us at the start of RAM. */
return (void *)CONFIG_SYS_SDRAM_BASE;
 }
+#endif
 
 void enable_caches(void)
 {
-- 
2.17.1



[PATCH 00/14] qemu: arm64: Add support for uefi capsule update on qemu arm64 platform

2020-11-26 Thread Sughosh Ganu


The following series adds support for the uefi capsule update feature
on the qemu arm64 platform, along with adding support for the capsule
authentication feature.

The capsule update feature is supported on a platform configuration
booting in a non-secure mode, i.e with -machine virt,secure=off option
set. This results in the platform booting u-boot directly without
the presence of trusted firmware(tf-a). Steps that need to be followed
for using this feature have been provided as part of the documentation.

Support has also been added for enabling the capsule authentication
feature. Capsule authentication, as defined by the uefi
specification is very much on similar lines to the logic used for
variable authentication. As a result, most of the signature
verification code already in use for variable authentication has been
used for capsule authentication.

Storage of the public key certificate, needed for the signature
verification process is in form of the efi signature list(esl)
structure.  This public key is stored on the platform's device tree
blob. The public key esl file can be embedded into the dtb using the
mkeficapsule utility that has been added as part of the capsule update
support series[1]. Steps needed for enabling capsule authentication
have been provided as part of the documentation.

This patch series needs to be applied on top of the capsule update
support patch series from Takahiro Akashi[1]


[1] -
https://patchwork.ozlabs.org/project/uboot/cover/20201117002805.13902-1-takahiro.aka...@linaro.org/


Sughosh Ganu (14):
  qemu: arm: Use the generated DTB only when CONGIG_OF_BOARD is defined
  mkeficapsule: Add support for embedding public key in a dtb
  qemu: arm: Scan the pci bus in board_init
  crypto: Fix the logic to calculate hash with authattributes set
  qemu: arm64: Add support for dynamic mtdparts for the platform
  qemu: arm64: Set dfu_alt_info variable for the platform
  efi_loader: Add config option to indicate fmp header presence
  dfu_mtd: Add provision to unlock mtd device
  efi_loader: Make the pkcs7 header parsing function an extern
  efi_loader: Re-factor code to build the signature store from efi
signature list
  efi: capsule: Add support for uefi capsule authentication
  efi_loader: Enable uefi capsule authentication
  efidebug: capsule: Add a command to update capsule on disk
  qemu: arm64: Add documentation for capsule update

 board/emulation/qemu-arm/qemu-arm.c | 170 
 cmd/efidebug.c  |  14 ++
 doc/board/emulation/qemu-arm.rst| 157 ++
 drivers/dfu/dfu_mtd.c   |  20 ++-
 include/configs/qemu-arm.h  |   8 ++
 include/efi_api.h   |  18 +++
 include/efi_loader.h|  12 ++
 lib/crypto/pkcs7_verify.c   |  37 --
 lib/efi_loader/Kconfig  |  24 
 lib/efi_loader/efi_capsule.c| 122 +
 lib/efi_loader/efi_firmware.c   |  49 ++-
 lib/efi_loader/efi_signature.c  | 192 ---
 lib/efi_loader/efi_variable.c   |  93 +
 tools/Makefile  |   1 +
 tools/mkeficapsule.c| 198 ++--
 15 files changed, 954 insertions(+), 161 deletions(-)

-- 
2.17.1




Re: [BUG] mvebu pci auto config broken

2020-11-26 Thread Stefan Roese

Hi Ake,

On 25.11.20 11:47, Ake Rehnman wrote:

Hello all,

it seems since the transition to DM for pci marvell mvebu does not work...

autoconfig tries to configure the memory controller but it seems to
trash the configuration made by mvebu_pcie_probe().

Also pci enumeration command does not work.

Here are my patches:


Thanks for looking into this.

As already mentioned to you in a private mail, please send a proper
patch with a problem description and commit text and Signed-off-by
etc as explained here:

http://www.denx.de/wiki/view/U-Boot/Patches

Otherwise this patch can not be reviewed and after accepted pushed into
mainline U-Boot.

Thanks,
Stefan


diff --git a/drivers/pci/pci_auto.c b/drivers/pci/pci_auto.c
index 3f46b7697d..5724f9f707 100644
--- a/drivers/pci/pci_auto.c
+++ b/drivers/pci/pci_auto.c
@@ -360,6 +360,12 @@ int dm_pciauto_config_device(struct udevice *dev)

   break;

+#if defined(CONFIG_ARCH_MVEBU)
+ case 0x0580:
+ debug("akre: PCI Autoconfig: Found Marvell memory controller. Doing
nothing\n");
+ break;
+#endif
+
  #if defined(CONFIG_PCIAUTO_SKIP_HOST_BRIDGE)
   case PCI_CLASS_BRIDGE_OTHER:
   debug("PCI Autoconfig: Skipping bridge device %d\n",
diff --git a/drivers/pci/pci_mvebu.c b/drivers/pci/pci_mvebu.c
index c9afe75150..1ec3fd9bbe 100644
--- a/drivers/pci/pci_mvebu.c
+++ b/drivers/pci/pci_mvebu.c
@@ -484,6 +484,8 @@ static int mvebu_pcie_bind(struct udevice *parent)
   struct uclass_driver *drv;
   struct udevice *dev;
   ofnode subnode;
+ int ret;
+ int cnt=0;

   /* Lookup eth driver */
   drv = lists_uclass_lookup(UCLASS_PCI);
@@ -499,10 +501,18 @@ static int mvebu_pcie_bind(struct udevice *parent)
   pcie = calloc(1, sizeof(*pcie));
   if (!pcie)
   return -ENOMEM;
+ strncpy(pcie->name,ofnode_get_name(subnode),sizeof(pcie->name));

   /* Create child device UCLASS_PCI and bind it */
- device_bind_ofnode(parent, &pcie_mvebu_drv, pcie->name, pcie,
+ ret=device_bind_ofnode(parent, &pcie_mvebu_drv, pcie->name, pcie,
  subnode, &dev);
+ if (ret)
+ {
+ debug("akre: device_bind_ofnode failed ret=%d\n",ret);
+ return ret;
+ }
+
+ dev->req_seq = cnt++;
   }

   return 0;




Viele Grüße,
Stefan

--
DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: s...@denx.de


Re: [PATCH 0/2] *** Add support for Mediatek mt762x SoC ***

2020-11-26 Thread SkyLake Huang
HiJagan,

On Fri, 2020-11-13 at 11:02 +0800, SkyLake Huang wrote:
> From: "SkyLake.Huang" 
> 
> This patch adds support MTK's SPI NOR controller on
> mt7622 & mt7629. With this controller, you can access
> SPI NOR with better performance on mt762x platform.
> 
> SkyLake.Huang (2):
>   spi: mtk_snor: add support for MTK SPI NOR controller
>   arm: dts: enable MTK SPI NOR controller driver
> 
>  arch/arm/dts/mt7622-rfb.dts  |  14 +-
>  arch/arm/dts/mt7622.dtsi |   7 +
>  arch/arm/dts/mt7629-rfb.dts  |  14 +-
>  arch/arm/dts/mt7629.dtsi |   9 +
>  configs/mt7622_rfb_defconfig |   3 +-
>  configs/mt7629_rfb_defconfig |   3 +-
>  drivers/spi/Kconfig  |   7 +
>  drivers/spi/Makefile |   1 +
>  drivers/spi/mtk_snor.c   | 597 +++
>  9 files changed, 651 insertions(+), 4 deletions(-)
>  create mode 100644 drivers/spi/mtk_snor.c
> 
A gentle ping.


Re: [PATCH 3/3] patman: fix project-defaults not propagating into parsers

2020-11-26 Thread Philipp Tomsich
Simon,

On Wed, 25 Nov 2020 at 16:30, Simon Glass  wrote:
> Here is a pointer to the docs I saw:
>
>
https://docs.python.org/3/library/argparse.html#argparse.ArgumentParser.set_defaults
>
> "Parser-level defaults can be particularly useful when working with
> multiple parsers. See the add_subparsers() method for an example of
> this type."

I had looked at the same documentation and needed to carefully read the
example
to infer the original author's intended messaging...

The only mention of this in the subparser-docs was:

> One particularly effective way of handling sub-commands is to combine the
> use of the add_subparsers() method with calls to set_defaults() so that
> each subparser knows which Python function it should execute.

This example just demonstrated that two different subparsers could create a
different
default for the same argument name.  I couldn't find any example of a
set_defaults()
on a higher-level parser propagating and the argparse-source doesn't seem
to try to
propagate defaults either.

I am starting to think that the correct fix for this would be more along
the lines of:

> diff --git a/tools/patman/settings.py b/tools/patman/settings.py
> index bb3f868..525c69e 100644
> --- a/tools/patman/settings.py
> +++ b/tools/patman/settings.py
> @@ -266,7 +266,11 @@ def _UpdateDefaults(main_parser, config):
>  print("WARNING: Unknown setting %s" % name)
>
>  # Set all the defaults (this propagates through all subparsers)
> -main_parser.set_defaults(**defaults)
> +for parser in parsers:
> +for name, val in defaults.items():
> +if parser.get_default(name) and val:
> +parser.set_defaults(name=val)
>
>  def _ReadAliasFile(fname):
>  """Read in the U-Boot git alias file if it exists.
>
than of what I sent out earlier.

An interesting aside: it looks as if the double-parsing of the args leads
to 'defaults'
being installed for all arguments that are passed in the first cycle (e.g.
count,
project and patchwork_url suddenly have the values loaded from the config
files
and parsed from the args populated with 'default' values).

Philipp.


Re: [PATCH 3/3] patman: fix project-defaults not propagating into parsers

2020-11-26 Thread Philipp Tomsich
Simon,

On Wed, 25 Nov 2020 at 00:41, Simon Glass  wrote:
> According to the Python documentation and my testing, it should
> propagate. Do you know what is going wrong here? If there is a
> problem, we should update the comment.

I don't see any code for propagating this in the argparse module:
  
https://github.com/python/cpython/blob/85c84920f511d0d73a16daeaf715a022cd64/Lib/argparse.py#L1763
  
https://github.com/python/cpython/blob/85c84920f511d0d73a16daeaf715a022cd64/Lib/argparse.py#L1363

Philipp.


Re: [PATCH 3/3] patman: fix project-defaults not propagating into parsers

2020-11-26 Thread Philipp Tomsich
Simon,

On Wed, 25 Nov 2020 at 00:41, Simon Glass  wrote:
>
> > Project defaults (e.g. for linux and gcc) do not propagate into the
> > subparsers.  As both the processing of tags (e.g. in the defaults
> > for the linux project) and supressing the signoff (in the defaults
> > for the gcc project) are settings from subparsers, these would still
> > require an explicit commandline option mirroring the (ignored) default.
> >
> > This change ensures that defaults are updated in all parsers.
> >
> > Signed-off-by: Philipp Tomsich 
> > ---
> >
> >  tools/patman/settings.py | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/tools/patman/settings.py b/tools/patman/settings.py
> > index bb3f868..dc57b2f 100644
> > --- a/tools/patman/settings.py
> > +++ b/tools/patman/settings.py
> > @@ -266,7 +266,8 @@ def _UpdateDefaults(main_parser, config):
> >  print("WARNING: Unknown setting %s" % name)
> >
> >  # Set all the defaults (this propagates through all subparsers)
> > -main_parser.set_defaults(**defaults)
> > +for parser in parsers:
> > +parser.set_defaults(**defaults)
>
> According to the Python documentation and my testing, it should
> propagate. Do you know what is going wrong here? If there is a
> problem, we should update the comment.

I haven't dug down to find the root-cause, but I see the following behavior
both on Debian 10.6 and CentOS 7 when adding a print(args) in main.py
just before the __name__ == "__main__" check...

With this commit:
$ tools/patman/patman -p linux -c1 send -n
Namespace(add_maintainers=True, branch=None, cc_cmd=None,
check_patch=True, cmd='send', count=1, debug=False, dest_branch=None,
dry_run=True, end=0, force=False, full_help=False,
ignore_bad_tags=False, ignore_binary=False, ignore_errors=False,
in_reply_to=None, limit=None, patchfiles=['linux'],
patchwork_url='https://patchwork.ozlabs.org', process_tags=False,
project='linux', show_comments=False, smtp_server=None, start=0,
testname='linux', thread=False, verbose=False)

=> process_tags=False

Without this commit:
Namespace(add_maintainers=True, branch=None, cc_cmd=None,
check_patch=True, cmd='send', count=1, debug=False, dest_branch=None,
dry_run=True, end=0, force=False, full_help=False,
ignore_bad_tags=False, ignore_binary=False, ignore_errors=False,
in_reply_to=None, limit=None, patchfiles=[],
patchwork_url='https://patchwork.ozlabs.org', process_tags=True,
project='linux', show_comments=False, smtp_server=None, start=0,
testname='linux', thread=False, verbose=False)

=> process_tags=True

So in my testing, the problem reproduces reliably across distributions.

Regards,
Philipp


RE: [PATCH] added check for ignored CONFIG_ENV_EXT4_DEVICE_AND_PART definition

2020-11-26 Thread Manuel Reis

Hi,

thanks for the feedback.

Just sent a new corrected patch with fixed commit message title:
[PATCH] add check for ignored CONFIG_ENV_EXT4_DEVICE_AND_PART 
definition.


regards,
Manuel


On qua, 25 nov, 2020 at 08:45, Patrick DELAUNAY 
 wrote:

Hi,


 From: Manuel Reis 
 Sent: dimanche 22 novembre 2020 16:20

 Check whether user has explicitly defined device and partition 
where environment
 file will be located. Voids the need to set such partition as 
bootable to work with

 the 'dev:auto'

 Signed-off-by: Manuel Reis 
 Cc: Patrick Delaunay 
 Cc: Patrice Chotard 
 ---

  board/st/stm32mp1/stm32mp1.c | 5 +
  1 file changed, 5 insertions(+)

 diff --git a/board/st/stm32mp1/stm32mp1.c 
b/board/st/stm32mp1/stm32mp1.c

 index 4553329b25..4dda70740d 100644
 --- a/board/st/stm32mp1/stm32mp1.c
 +++ b/board/st/stm32mp1/stm32mp1.c
 @@ -868,6 +868,11 @@ const char *env_ext4_get_intf(void)

  const char *env_ext4_get_dev_part(void)  {
 +  static char *const env_dev_part =
 CONFIG_ENV_EXT4_DEVICE_AND_PART;
 +
 +  if (strlen(env_dev_part) > 0)
 +  return env_dev_part;
 +
static char *const dev_part[] = {"0:auto", "1:auto", "2:auto"};
u32 bootmode = get_bootmode();

 --
 2.27.0


Behavior seems ok, but patch mixes code and variables.
can you move the code part after the variables definitions ?

  const char *env_ext4_get_dev_part(void)  {
static char *const dev_part[] = {"0:auto", "1:auto", "2:auto"};
u32 bootmode = get_bootmode();
 +  static char *const env_dev_part =
 CONFIG_ENV_EXT4_DEVICE_AND_PART;
 +
 +  if (strlen(env_dev_part) > 0)
 +  return env_dev_part;
 +

Regards

PAtrick





[PATCH] add check for ignored CONFIG_ENV_EXT4_DEVICE_AND_PART definition

2020-11-26 Thread Manuel Reis
Check whether user has explicitly defined device and partition where
environment file will be located before using 'auto' i.e. bootable
partition

Voids the need to set such partition as bootable to work with the
'dev:auto' tuple

Signed-off-by: Manuel Reis 
Cc: Patrick Delaunay 
Cc: Patrice Chotard 
Tested-by: Michael Opdenacker 
---

 board/st/stm32mp1/stm32mp1.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/board/st/stm32mp1/stm32mp1.c b/board/st/stm32mp1/stm32mp1.c
index 03a19af930..09d9bbf07d 100644
--- a/board/st/stm32mp1/stm32mp1.c
+++ b/board/st/stm32mp1/stm32mp1.c
@@ -827,7 +827,12 @@ const char *env_ext4_get_intf(void)
 
 const char *env_ext4_get_dev_part(void)
 {
+   static char *const env_dev_part = CONFIG_ENV_EXT4_DEVICE_AND_PART;
static char *const dev_part[] = {"0:auto", "1:auto", "2:auto"};
+
+   if (strlen(env_dev_part) > 0)
+   return env_dev_part;
+
u32 bootmode = get_bootmode();
 
return dev_part[(bootmode & TAMP_BOOT_INSTANCE_MASK) - 1];
-- 
2.27.0



[no subject]

2020-11-26 Thread Manuel Reis


Hi,

thanks for feedback.

sending new squash commit with grouped variables and code, and
corrected git message for initial patch sent:

[PATCH] added check for ignored CONFIG_ENV_EXT4_DEVICE_AND_PART

hope this is better now.

regards,
manuel




[PATCH] arm: ls102xa: select USB PHY erratum's only if USB support is enabled

2020-11-26 Thread Aleksandar Gerasimovski
The USB support is not by default enabled on all designs, so it does not
make seance to have USB specific erratum's enabled on such a designs.

On our internal Hitachi-Powergrids design not using the USB controller
there is a crash when accessing those specific memory locations selected
by the erratum flags.

Signed-off-by: Aleksandar Gerasimovski 

---
 arch/arm/cpu/armv7/ls102xa/Kconfig | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/arch/arm/cpu/armv7/ls102xa/Kconfig 
b/arch/arm/cpu/armv7/ls102xa/Kconfig
index 937989b..747059b 100644
--- a/arch/arm/cpu/armv7/ls102xa/Kconfig
+++ b/arch/arm/cpu/armv7/ls102xa/Kconfig
@@ -5,11 +5,11 @@ config ARCH_LS1021A
select SYS_FSL_ERRATUM_A008378
select SYS_FSL_ERRATUM_A008407
select SYS_FSL_ERRATUM_A008850
-   select SYS_FSL_ERRATUM_A008997
-   select SYS_FSL_ERRATUM_A009007
-   select SYS_FSL_ERRATUM_A009008
+   select SYS_FSL_ERRATUM_A008997 if USB
+   select SYS_FSL_ERRATUM_A009007 if USB
+   select SYS_FSL_ERRATUM_A009008 if USB
select SYS_FSL_ERRATUM_A009663
-   select SYS_FSL_ERRATUM_A009798
+   select SYS_FSL_ERRATUM_A009798 if USB
select SYS_FSL_ERRATUM_A009942
select SYS_FSL_ERRATUM_A010315
select SYS_FSL_HAS_CCI400
-- 
1.8.3.1


[PATCH] drivers: ifc: add define for IFC_CSPRn TE bit

2020-11-26 Thread Aleksandar Gerasimovski
To drive TE pin high is supported IFC configuration that can be used on
some designs.

Signed-off-by: Aleksandar Gerasimovski 

---
 include/fsl_ifc.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/include/fsl_ifc.h b/include/fsl_ifc.h
index fd91533..e1e6214 100644
--- a/include/fsl_ifc.h
+++ b/include/fsl_ifc.h
@@ -52,6 +52,8 @@
 /* Machine Select */
 #define CSPR_MSEL  0x0006
 #define CSPR_MSEL_SHIFT1
+/* External Transceiver Enable */
+#define CSPR_TE0x0010
 /* NOR */
 #define CSPR_MSEL_NOR  0x
 /* NAND */
-- 
1.8.3.1


[BUG] mvebu pci auto config broken

2020-11-26 Thread Ake Rehnman
Hello all,

it seems since the transition to DM for pci marvell mvebu does not work...

autoconfig tries to configure the memory controller but it seems to
trash the configuration made by mvebu_pcie_probe().

Also pci enumeration command does not work.

Here are my patches:

diff --git a/drivers/pci/pci_auto.c b/drivers/pci/pci_auto.c
index 3f46b7697d..5724f9f707 100644
--- a/drivers/pci/pci_auto.c
+++ b/drivers/pci/pci_auto.c
@@ -360,6 +360,12 @@ int dm_pciauto_config_device(struct udevice *dev)

  break;

+#if defined(CONFIG_ARCH_MVEBU)
+ case 0x0580:
+ debug("akre: PCI Autoconfig: Found Marvell memory controller. Doing
nothing\n");
+ break;
+#endif
+
 #if defined(CONFIG_PCIAUTO_SKIP_HOST_BRIDGE)
  case PCI_CLASS_BRIDGE_OTHER:
  debug("PCI Autoconfig: Skipping bridge device %d\n",
diff --git a/drivers/pci/pci_mvebu.c b/drivers/pci/pci_mvebu.c
index c9afe75150..1ec3fd9bbe 100644
--- a/drivers/pci/pci_mvebu.c
+++ b/drivers/pci/pci_mvebu.c
@@ -484,6 +484,8 @@ static int mvebu_pcie_bind(struct udevice *parent)
  struct uclass_driver *drv;
  struct udevice *dev;
  ofnode subnode;
+ int ret;
+ int cnt=0;

  /* Lookup eth driver */
  drv = lists_uclass_lookup(UCLASS_PCI);
@@ -499,10 +501,18 @@ static int mvebu_pcie_bind(struct udevice *parent)
  pcie = calloc(1, sizeof(*pcie));
  if (!pcie)
  return -ENOMEM;
+ strncpy(pcie->name,ofnode_get_name(subnode),sizeof(pcie->name));

  /* Create child device UCLASS_PCI and bind it */
- device_bind_ofnode(parent, &pcie_mvebu_drv, pcie->name, pcie,
+ ret=device_bind_ofnode(parent, &pcie_mvebu_drv, pcie->name, pcie,
 subnode, &dev);
+ if (ret)
+ {
+ debug("akre: device_bind_ofnode failed ret=%d\n",ret);
+ return ret;
+ }
+
+ dev->req_seq = cnt++;
  }

  return 0;


Re: [BUG] U-boot does not detect emmc card in odroid-c2 for newer U-boot as 2020.04

2020-11-26 Thread Otto Meier



Hi,

I bisected it and this is the result:

dd5f2351e99aad8fcbedbc1305b8b51b09952336 is the first bad commit
commit dd5f2351e99aad8fcbedbc1305b8b51b09952336
Author: Jerome Brunet 
Date:   Thu Mar 5 12:12:38 2020 +0100

arm64: dts: meson: sync dt and bindings from v5.6-rc2

Sync the device tree and dt-bindings from Linux v5.6-rc2

11a48a5a18c6 ("Linux 5.6-rc2")

The only exception to this is the mmc pinctrl pin bias of gxl SoC family.

This is a fix which found its way to u-boot but not Linux yet.

Acked-by: Neil Armstrong 

Signed-off-by: Jerome Brunet 
Signed-off-by: Neil Armstrong 

 arch/arm/dts/meson-axg-s400.dts|  70 ++-
 arch/arm/dts/meson-axg.dtsi| 273 ++--
 arch/arm/dts/meson-g12-common.dtsi | 478 +++--
 arch/arm/dts/meson-g12.dtsi| 398 +
 arch/arm/dts/meson-g12a-sei510.dts |  64 +++
 arch/arm/dts/meson-g12a-u200.dts   |  54 +++
 arch/arm/dts/meson-g12a.dtsi   |  33 +-
 arch/arm/dts/meson-g12b-a311d-khadas-vim3.dts  |  25 ++
 arch/arm/dts/meson-g12b-odroid-n2.dts  |   2 +-
 arch/arm/dts/meson-g12b.dtsi   |  26 +-
 arch/arm/dts/meson-gx.dtsi |  87 +++-
 arch/arm/dts/meson-gxbb-nanopi-k2.dts  |  26 +-
 arch/arm/dts/meson-gxbb-odroidc2.dts   | 100 -
 arch/arm/dts/meson-gxbb-p200.dts   |   9 +-
 arch/arm/dts/meson-gxbb-p201.dts   |   2 +-
 arch/arm/dts/meson-gxbb-p20x.dtsi  |   9 +-
 arch/arm/dts/meson-gxbb.dtsi   | 118 -
 arch/arm/dts/meson-gxl-s805x-libretech-ac.dts  |   2 +-
 arch/arm/dts/meson-gxl-s905x-khadas-vim.dts|  20 +-
 arch/arm/dts/meson-gxl-s905x-libretech-cc.dts  |  26 +-
 arch/arm/dts/meson-gxl-s905x-p212.dtsi |  10 +-
 arch/arm/dts/meson-gxl.dtsi|  76 +++-
 arch/arm/dts/meson-gxm-khadas-vim2.dts |  71 +--
 arch/arm/dts/meson-gxm.dtsi|  39 +-
 arch/arm/dts/meson-khadas-vim3.dtsi|   7 +
 arch/arm/dts/meson-sm1-sei610.dts  | 236 +-
 arch/arm/dts/meson-sm1.dtsi| 356 +++
 include/dt-bindings/clock/axg-audio-clkc.h |  10 +
 include/dt-bindings/clock/gxbb-aoclkc.h|   7 +
 include/dt-bindings/clock/gxbb-clkc.h  |  21 +
 include/dt-bindings/gpio/meson-gxbb-gpio.h |   8 +-
 include/dt-bindings/gpio/meson-gxl-gpio.h  |   8 +-
 .../reset/amlogic,meson-axg-audio-arb.h|   2 +
 .../dt-bindings/reset/amlogic,meson-axg-reset.h|   3 +-
 .../reset/amlogic,meson-g12a-audio-reset.h |  15 +
 .../dt-bindings/reset/amlogic,meson-gxbb-reset.h   |  51 +--
 36 files changed, 2119 insertions(+), 623 deletions(-)
 create mode 100644 arch/arm/dts/meson-g12.dtsi

Hope this helps

Best Regards

Otto



Am 26.11.20 um 12:46 schrieb Jaehoon Chung:

Hi,

On 11/26/20 8:26 PM, Otto Meier wrote:

Hi Jaehoon,

no i did not run git bisect. I don't know how to
process this. Could you guide me?


You can see usage with "$git bisect --help"

You mentioned v2020.07 doesn't work fine. then checkout v2020.07

git checkout v2020.07
git bisect start
git bisect bad
git bisect good v2020.04

1) build odroid-c2
2) check whether it's working fine or not.
2-1) if not work, $git bisect bad
2-2) if work fine, $git bisect good

Repeat to do above sequence until find commit. (maybe you can find what commit 
is problem.)


Best Regards,
Jaehoon Chung



best regards Otto


Am 26.11.20 um 12:11 schrieb Jaehoon Chung:

Hi Otto,

Sorry for sending personally.
Did you try to run "git bisect" ?


Best Regards,
Jaehoon Chung



On 11/20/20 12:52 AM, Otto Meier wrote:

Hi,

I have extended the previous post.



with these modifications i get:

U-Boot 2021.01-rc2-00047-g9324c9a823-dirty (Nov 19 2020 - 15:33:00 +0100) 
odroid-c2

Model: Hardkernel ODROID-C2
SoC:   Amlogic Meson GXBB (S905) Revision 1f:c (0:1)
DRAM:  2 GiB
MMC:   mmc@72000: 0, mmc@74000: 1
In:    serial
Out:   serial
Err:   serial
Net:   Could not get PHY for ethernet@c941: addr -1
No ethernet found.

Hit any key to stop autoboot:  0
MESON EMMC status = c5ff
MESON EMMC status = 01ff2000
MESON EMMC status = c5ff
MESON EMMC status = cdff
MESON EMMC status = 01ff2800
meson_dm_mmc_send_cmd[226]
MESON EMMC status = c5ff
MESON EMMC status = 01ff2800
meson_dm_mmc_send_cmd[226]
MESON EMMC status = c5ff
MESON EMMC status = 01ff2000
MESON EMMC status = c5ff
MESON EMMC status = cdff
MESON EMMC status = 01ff2800
meson_dm_mmc_send_cmd[226]
Card did not respond to voltage select! : -110
MESON EMMC status = c5ff
MESON EMMC status = 01ff2000
MESON EMMC status = c5ff
MESON EMMC status = cdff
MESON EMMC status = 01ff2800
meson_dm_mmc_send_cmd[226]
MESON 

[PATCH] arm: at91: configs: Enable CONFIG_SYS_NAND_USE_FLASH_BBT on all boards

2020-11-26 Thread Eugen Hristev
From: Nicolas Ferre 

As highlighted by Stefan in the commit e074d0f79b2e ("arm: at91:
gardena-smart-gateway-at91sam: Enable CONFIG_SYS_NAND_USE_FLASH_BBT")
it's important to use BBT when Linux enables it. We use it for a long
time on all our boards.

Signed-off-by: Nicolas Ferre 
Cc: Stefan Roese 
Cc: Eugen Hristev 
Cc: Tom Rini 
---
 configs/at91sam9260ek_dataflash_cs0_defconfig  | 1 -
 configs/at91sam9260ek_dataflash_cs1_defconfig  | 1 -
 configs/at91sam9260ek_nandflash_defconfig  | 1 -
 configs/at91sam9261ek_dataflash_cs0_defconfig  | 1 -
 configs/at91sam9261ek_dataflash_cs3_defconfig  | 1 -
 configs/at91sam9261ek_nandflash_defconfig  | 1 -
 configs/at91sam9263ek_dataflash_cs0_defconfig  | 1 -
 configs/at91sam9263ek_dataflash_defconfig  | 1 -
 configs/at91sam9263ek_nandflash_defconfig  | 1 -
 configs/at91sam9263ek_norflash_boot_defconfig  | 1 -
 configs/at91sam9263ek_norflash_defconfig   | 1 -
 configs/at91sam9g10ek_dataflash_cs0_defconfig  | 1 -
 configs/at91sam9g10ek_dataflash_cs3_defconfig  | 1 -
 configs/at91sam9g10ek_nandflash_defconfig  | 1 -
 configs/at91sam9g20ek_2mmc_defconfig   | 1 -
 configs/at91sam9g20ek_2mmc_nandflash_defconfig | 1 -
 configs/at91sam9g20ek_dataflash_cs0_defconfig  | 1 -
 configs/at91sam9g20ek_dataflash_cs1_defconfig  | 1 -
 configs/at91sam9g20ek_nandflash_defconfig  | 1 -
 configs/at91sam9m10g45ek_mmc_defconfig | 1 -
 configs/at91sam9m10g45ek_nandflash_defconfig   | 1 -
 configs/at91sam9n12ek_mmc_defconfig| 1 -
 configs/at91sam9n12ek_nandflash_defconfig  | 1 -
 configs/at91sam9n12ek_spiflash_defconfig   | 1 -
 configs/at91sam9rlek_dataflash_defconfig   | 1 -
 configs/at91sam9rlek_mmc_defconfig | 1 -
 configs/at91sam9rlek_nandflash_defconfig   | 1 -
 configs/at91sam9x5ek_dataflash_defconfig   | 1 -
 configs/at91sam9x5ek_mmc_defconfig | 1 -
 configs/at91sam9x5ek_nandflash_defconfig   | 1 -
 configs/at91sam9x5ek_spiflash_defconfig| 1 -
 configs/at91sam9xeek_dataflash_cs0_defconfig   | 1 -
 configs/at91sam9xeek_dataflash_cs1_defconfig   | 1 -
 configs/at91sam9xeek_nandflash_defconfig   | 1 -
 configs/sama5d2_ptc_ek_mmc_defconfig   | 1 -
 configs/sama5d2_ptc_ek_nandflash_defconfig | 1 -
 configs/sama5d36ek_cmp_mmc_defconfig   | 1 -
 configs/sama5d36ek_cmp_nandflash_defconfig | 1 -
 configs/sama5d36ek_cmp_spiflash_defconfig  | 1 -
 configs/sama5d3_xplained_mmc_defconfig | 1 -
 configs/sama5d3_xplained_nandflash_defconfig   | 1 -
 configs/sama5d3xek_mmc_defconfig   | 1 -
 configs/sama5d3xek_nandflash_defconfig | 1 -
 configs/sama5d3xek_spiflash_defconfig  | 1 -
 configs/sama5d4_xplained_mmc_defconfig | 1 -
 configs/sama5d4_xplained_nandflash_defconfig   | 1 -
 configs/sama5d4_xplained_spiflash_defconfig| 1 -
 configs/sama5d4ek_mmc_defconfig| 1 -
 configs/sama5d4ek_nandflash_defconfig  | 1 -
 configs/sama5d4ek_spiflash_defconfig   | 1 -
 50 files changed, 50 deletions(-)

diff --git a/configs/at91sam9260ek_dataflash_cs0_defconfig 
b/configs/at91sam9260ek_dataflash_cs0_defconfig
index 0d9b69160a..89f5f2c959 100644
--- a/configs/at91sam9260ek_dataflash_cs0_defconfig
+++ b/configs/at91sam9260ek_dataflash_cs0_defconfig
@@ -43,7 +43,6 @@ CONFIG_AT91_GPIO=y
 # CONFIG_MMC is not set
 CONFIG_MTD=y
 CONFIG_MTD_RAW_NAND=y
-# CONFIG_SYS_NAND_USE_FLASH_BBT is not set
 CONFIG_NAND_ATMEL=y
 CONFIG_DM_SPI_FLASH=y
 CONFIG_SPI_FLASH_ATMEL=y
diff --git a/configs/at91sam9260ek_dataflash_cs1_defconfig 
b/configs/at91sam9260ek_dataflash_cs1_defconfig
index d0542ec60e..a7d0d2811b 100644
--- a/configs/at91sam9260ek_dataflash_cs1_defconfig
+++ b/configs/at91sam9260ek_dataflash_cs1_defconfig
@@ -43,7 +43,6 @@ CONFIG_AT91_GPIO=y
 # CONFIG_MMC is not set
 CONFIG_MTD=y
 CONFIG_MTD_RAW_NAND=y
-# CONFIG_SYS_NAND_USE_FLASH_BBT is not set
 CONFIG_NAND_ATMEL=y
 CONFIG_DM_SPI_FLASH=y
 CONFIG_SPI_FLASH_ATMEL=y
diff --git a/configs/at91sam9260ek_nandflash_defconfig 
b/configs/at91sam9260ek_nandflash_defconfig
index e68f0bd03d..a5eaba57bd 100644
--- a/configs/at91sam9260ek_nandflash_defconfig
+++ b/configs/at91sam9260ek_nandflash_defconfig
@@ -40,7 +40,6 @@ CONFIG_AT91_GPIO=y
 # CONFIG_MMC is not set
 CONFIG_MTD=y
 CONFIG_MTD_RAW_NAND=y
-# CONFIG_SYS_NAND_USE_FLASH_BBT is not set
 CONFIG_NAND_ATMEL=y
 CONFIG_DM_SPI_FLASH=y
 CONFIG_SPI_FLASH_ATMEL=y
diff --git a/configs/at91sam9261ek_dataflash_cs0_defconfig 
b/configs/at91sam9261ek_dataflash_cs0_defconfig
index e19b97b3b1..2172c7908d 100644
--- a/configs/at91sam9261ek_dataflash_cs0_defconfig
+++ b/configs/at91sam9261ek_dataflash_cs0_defconfig
@@ -42,7 +42,6 @@ CONFIG_AT91_GPIO=y
 # CONFIG_MMC is not set
 CONFIG_MTD=y
 CONFIG_MTD_RAW_NAND=y
-# CONFIG_SYS_NAND_USE_FLASH_BBT is not set
 CONFIG_NAND_ATMEL=y
 CONFIG_DM_SPI_FLASH=y
 CONFIG_SPI_FLASH_ATMEL=y
diff --git a/configs/at91sam9261ek_dataflash_cs3_defconfig 
b/configs/at91sam9261ek_dataflash_cs3_

Re: [PATCH] ARM: at91: armv7: sama7g5 uses CCF clock driver

2020-11-26 Thread Eugen.Hristev
On 11.11.2020 13:15, Eugen Hristev wrote:
> From: Nicolas Ferre 
> 
> SAMA7G5 uses CCF driver under drivers/clk/at91/ and not the custom older
> at91 clock.c driver. Remove it from the compilation list and adapt cpu.c
> arch_cpu_init() to avoid calling at91_clock_init() which is wrong
> anyway.
> 
> Signed-off-by: Nicolas Ferre 
> Reviewed-by: Claudiu Beznea 
> ---

Applied to u-boot-atmel/master, thanks !



Re: [PATCH] ARM: mach-at91: fix timer.o compile condition

2020-11-26 Thread Eugen.Hristev
On 11.11.2020 18:46, Eugen Hristev wrote:
> The AT91 architecture now has two possible timer blocks, the old PIT timer
> and the new PIT64B.
> The timer.c file has an old non DM driver that works for platforms
> that do not use the ATMEL_PIT_TIMER DM-based driver.
> Update the Makefile to select this old driver in case neither of the
> ATMEL_PIT_TIMER and the MCHP_PIT64B_TIMER are selected.
> 
> Suggested-by: Claudiu Beznea 
> Signed-off-by: Eugen Hristev 
> ---

Applied to u-boot-atmel/master


Re: [PATCH] ARM: dts: at91: sam9x60: enable slewrate/high drive for sdhci0 pinout

2020-11-26 Thread Eugen.Hristev
On 09.11.2020 17:35, Eugen Hristev wrote:
> Align the pin setup for sdhci0 with linux kernel.
> This means to have slew rate enable and high drive strength.
> 
> Signed-off-by: Eugen Hristev 
> ---

Applied to u-boot-atmel/master


Re: [PATCH v2] mmc: atmel-sdhci: fix the clk_enable call in case of no ops

2020-11-26 Thread Eugen.Hristev
On 09.11.2020 14:14, Jaehoon Chung wrote:
> On 11/9/20 8:02 PM, Eugen Hristev wrote:
>> If the clock driver does not offer a clk_enable ops, then the system will
>> return -ENOSYS.
>> The clk_enable works with CCF (common clock framework).
>> Some clocks in some cases (like the generic clock for some products: sama5d2)
>> do not have the clk_enable primitive, and in this case probing of the driver
>> will fail.
>> This patch changes the behavior to return an error in case there is really
>> an error, and not a missing primitive.
>> If the clock driver does not have an enable primitive, most likely clocks
>> are always enabled or enabled in the set_rate primitives.
>>
>> Fixes: 81f16438d4 ("mmc: atmel-sdhci: enable the required generic clock")
>> Signed-off-by: Eugen Hristev 
> 
> Reviewed-by: Jaehoon Chung 
> 
> Best Regards,
> Jaehoon Chung
> 
>> ---

Applied to u-boot-atmel/master



Re: [PATCH] arm: at91: configs: Enable CONFIG_SYS_NAND_USE_FLASH_BBT on all boards

2020-11-26 Thread Alexander Dahl
Hello,

Am Donnerstag, 26. November 2020, 09:21:35 CET schrieb Eugen Hristev:
> From: Nicolas Ferre 
> 
> As highlighted by Stefan in the commit e074d0f79b2e ("arm: at91:
> gardena-smart-gateway-at91sam: Enable CONFIG_SYS_NAND_USE_FLASH_BBT")
> it's important to use BBT when Linux enables it. We use it for a long
> time on all our boards.
> 
> Signed-off-by: Nicolas Ferre 
> Cc: Stefan Roese 
> Cc: Eugen Hristev 
> Cc: Tom Rini 

Acked-by: Alexander Dahl 

Greets
Alex

> ---
>  configs/at91sam9260ek_dataflash_cs0_defconfig  | 1 -
>  configs/at91sam9260ek_dataflash_cs1_defconfig  | 1 -
>  configs/at91sam9260ek_nandflash_defconfig  | 1 -
>  configs/at91sam9261ek_dataflash_cs0_defconfig  | 1 -
>  configs/at91sam9261ek_dataflash_cs3_defconfig  | 1 -
>  configs/at91sam9261ek_nandflash_defconfig  | 1 -
>  configs/at91sam9263ek_dataflash_cs0_defconfig  | 1 -
>  configs/at91sam9263ek_dataflash_defconfig  | 1 -
>  configs/at91sam9263ek_nandflash_defconfig  | 1 -
>  configs/at91sam9263ek_norflash_boot_defconfig  | 1 -
>  configs/at91sam9263ek_norflash_defconfig   | 1 -
>  configs/at91sam9g10ek_dataflash_cs0_defconfig  | 1 -
>  configs/at91sam9g10ek_dataflash_cs3_defconfig  | 1 -
>  configs/at91sam9g10ek_nandflash_defconfig  | 1 -
>  configs/at91sam9g20ek_2mmc_defconfig   | 1 -
>  configs/at91sam9g20ek_2mmc_nandflash_defconfig | 1 -
>  configs/at91sam9g20ek_dataflash_cs0_defconfig  | 1 -
>  configs/at91sam9g20ek_dataflash_cs1_defconfig  | 1 -
>  configs/at91sam9g20ek_nandflash_defconfig  | 1 -
>  configs/at91sam9m10g45ek_mmc_defconfig | 1 -
>  configs/at91sam9m10g45ek_nandflash_defconfig   | 1 -
>  configs/at91sam9n12ek_mmc_defconfig| 1 -
>  configs/at91sam9n12ek_nandflash_defconfig  | 1 -
>  configs/at91sam9n12ek_spiflash_defconfig   | 1 -
>  configs/at91sam9rlek_dataflash_defconfig   | 1 -
>  configs/at91sam9rlek_mmc_defconfig | 1 -
>  configs/at91sam9rlek_nandflash_defconfig   | 1 -
>  configs/at91sam9x5ek_dataflash_defconfig   | 1 -
>  configs/at91sam9x5ek_mmc_defconfig | 1 -
>  configs/at91sam9x5ek_nandflash_defconfig   | 1 -
>  configs/at91sam9x5ek_spiflash_defconfig| 1 -
>  configs/at91sam9xeek_dataflash_cs0_defconfig   | 1 -
>  configs/at91sam9xeek_dataflash_cs1_defconfig   | 1 -
>  configs/at91sam9xeek_nandflash_defconfig   | 1 -
>  configs/sama5d2_ptc_ek_mmc_defconfig   | 1 -
>  configs/sama5d2_ptc_ek_nandflash_defconfig | 1 -
>  configs/sama5d36ek_cmp_mmc_defconfig   | 1 -
>  configs/sama5d36ek_cmp_nandflash_defconfig | 1 -
>  configs/sama5d36ek_cmp_spiflash_defconfig  | 1 -
>  configs/sama5d3_xplained_mmc_defconfig | 1 -
>  configs/sama5d3_xplained_nandflash_defconfig   | 1 -
>  configs/sama5d3xek_mmc_defconfig   | 1 -
>  configs/sama5d3xek_nandflash_defconfig | 1 -
>  configs/sama5d3xek_spiflash_defconfig  | 1 -
>  configs/sama5d4_xplained_mmc_defconfig | 1 -
>  configs/sama5d4_xplained_nandflash_defconfig   | 1 -
>  configs/sama5d4_xplained_spiflash_defconfig| 1 -
>  configs/sama5d4ek_mmc_defconfig| 1 -
>  configs/sama5d4ek_nandflash_defconfig  | 1 -
>  configs/sama5d4ek_spiflash_defconfig   | 1 -
>  50 files changed, 50 deletions(-)
> 
> diff --git a/configs/at91sam9260ek_dataflash_cs0_defconfig
> b/configs/at91sam9260ek_dataflash_cs0_defconfig index
> 0d9b69160a..89f5f2c959 100644
> --- a/configs/at91sam9260ek_dataflash_cs0_defconfig
> +++ b/configs/at91sam9260ek_dataflash_cs0_defconfig
> @@ -43,7 +43,6 @@ CONFIG_AT91_GPIO=y
>  # CONFIG_MMC is not set
>  CONFIG_MTD=y
>  CONFIG_MTD_RAW_NAND=y
> -# CONFIG_SYS_NAND_USE_FLASH_BBT is not set
>  CONFIG_NAND_ATMEL=y
>  CONFIG_DM_SPI_FLASH=y
>  CONFIG_SPI_FLASH_ATMEL=y
> diff --git a/configs/at91sam9260ek_dataflash_cs1_defconfig
> b/configs/at91sam9260ek_dataflash_cs1_defconfig index
> d0542ec60e..a7d0d2811b 100644
> --- a/configs/at91sam9260ek_dataflash_cs1_defconfig
> +++ b/configs/at91sam9260ek_dataflash_cs1_defconfig
> @@ -43,7 +43,6 @@ CONFIG_AT91_GPIO=y
>  # CONFIG_MMC is not set
>  CONFIG_MTD=y
>  CONFIG_MTD_RAW_NAND=y
> -# CONFIG_SYS_NAND_USE_FLASH_BBT is not set
>  CONFIG_NAND_ATMEL=y
>  CONFIG_DM_SPI_FLASH=y
>  CONFIG_SPI_FLASH_ATMEL=y
> diff --git a/configs/at91sam9260ek_nandflash_defconfig
> b/configs/at91sam9260ek_nandflash_defconfig index e68f0bd03d..a5eaba57bd
> 100644
> --- a/configs/at91sam9260ek_nandflash_defconfig
> +++ b/configs/at91sam9260ek_nandflash_defconfig
> @@ -40,7 +40,6 @@ CONFIG_AT91_GPIO=y
>  # CONFIG_MMC is not set
>  CONFIG_MTD=y
>  CONFIG_MTD_RAW_NAND=y
> -# CONFIG_SYS_NAND_USE_FLASH_BBT is not set
>  CONFIG_NAND_ATMEL=y
>  CONFIG_DM_SPI_FLASH=y
>  CONFIG_SPI_FLASH_ATMEL=y
> diff --git a/configs/at91sam9261ek_dataflash_cs0_defconfig
> b/configs/at91sam9261ek_dataflash_cs0_defconfig index
> e19b97b3b1..2172c7908d 100644
> --- a/configs/at91sam9261ek_dataflash_cs0_defconfig
> +++ b/configs/at91sam9261ek_data

Re: [PATCH 1/5 v2] mips: start.S: Add Octeon boot header compatibility

2020-11-26 Thread Stefan Roese

Hi Daniel,

On 28.10.20 15:09, Stefan Roese wrote:

Octeon has a specific boot header, when booted via SPI NOR, NAND or MMC.
Here the only 2 instructions are allowed in the first few bytes of the
image. And these instructions need to be one branch and a nop. This
patch adds the necessary nop after the nop, to that the common MIPS
image is compatible with this Octeon header.

The tool to patch the Octeon boot header into the image will be send in
a follow-up patch.

Signed-off-by: Stefan Roese 
Cc: Aaron Williams 
Cc: Chandrakala Chavva 
Cc: Daniel Schwierzeck 
---
v2:
- Enhance comment
- Fix delay slot indentation


Do you have any comments on this patchset? What is your plan with it?
Could you integrate it in the upcoming release? It includes some fixes,
which would be really helpful in the release and does not touch
platforms other than Octeon (other than this small patch here).

Thanks,
Stefan


  arch/mips/cpu/start.S | 10 --
  1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/arch/mips/cpu/start.S b/arch/mips/cpu/start.S
index d0c412236d..335aafa6a8 100644
--- a/arch/mips/cpu/start.S
+++ b/arch/mips/cpu/start.S
@@ -74,9 +74,14 @@
.endm
  
  ENTRY(_start)

-   /* U-Boot entry point */
+   /*
+* U-Boot entry point.
+* Do not add instructions to the branch delay slot! Some SoC's
+* like Octeon might patch the final U-Boot binary at this location
+* with additional boot headers.
+*/
b   reset
-mtc0   zero, CP0_COUNT # clear cp0 count for most accurate boot timing
+nop
  
  #if defined(CONFIG_MIPS_INSERT_BOOT_CONFIG)

/*
@@ -123,6 +128,7 @@ ENTRY(_start)
  #endif
  
  reset:

+   mtc0zero, CP0_COUNT # clear cp0 count for most accurate boot timing
  #if __mips_isa_rev >= 6
mfc0t0, CP0_CONFIG, 5
and t0, t0, MIPS_CONF5_VP




Viele Grüße,
Stefan

--
DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: s...@denx.de


RE: [PATCH] riscv: timer: Add support for an early timer

2020-11-26 Thread Pragnesh Patel
Hi Rick,

>-Original Message-
>From: Rick Chen 
>Sent: 26 November 2020 14:44
>To: Pragnesh Patel 
>Cc: Simon Glass ; U-Boot Mailing List b...@lists.denx.de>; Atish Patra ; Bin Meng
>; Paul Walmsley ( Sifive) ;
>Anup Patel ; Sagar Kadam
>; Palmer Dabbelt ; rick
>; Alan Kao ; Leo Liang
>
>Subject: Re: [PATCH] riscv: timer: Add support for an early timer
>
>[External Email] Do not click links or attachments unless you recognize the
>sender and know the content is safe
>
>Hi Pragnesh
>
>> Hi Rick,
>>
>> >-Original Message-
>> >From: Rick Chen 
>> >Sent: 24 November 2020 13:08
>> >To: Pragnesh Patel 
>> >Cc: U-Boot Mailing List ; Atish Patra
>> >; Bin Meng ; Paul Walmsley (
>> >Sifive) ; Anup Patel ;
>> >Sagar Kadam ; Palmer Dabbelt
>> >; Simon Glass ; rick
>> >; Alan Kao ; Leo Liang
>> >
>> >Subject: Re: [PATCH] riscv: timer: Add support for an early timer
>> >
>> >[External Email] Do not click links or attachments unless you
>> >recognize the sender and know the content is safe
>> >
>> >Hi Pragnesh,
>> >
>> >> From: Pragnesh Patel [mailto:pragnesh.pa...@sifive.com]
>> >> Sent: Tuesday, November 17, 2020 7:05 PM
>> >> To: u-boot@lists.denx.de
>> >> Cc: atish.pa...@wdc.com; palmerdabb...@google.com;
>> >bmeng...@gmail.com;
>> >> paul.walms...@sifive.com; anup.pa...@wdc.com;
>> >> sagar.ka...@sifive.com; Rick Jian-Zhi Chen(陳建志); Pragnesh Patel;
>> >> Palmer Dabbelt; Sean Anderson; Simon Glass; Bin Meng
>> >> Subject: [PATCH] riscv: timer: Add support for an early timer
>> >>
>> >> Added support for timer_early_get_count() and
>> >> timer_early_get_rate() This is mostly useful in tracing.
>> >>
>> >> Signed-off-by: Pragnesh Patel 
>> >> ---
>> >>  drivers/timer/andes_plmt_timer.c   | 21 -
>> >>  drivers/timer/riscv_timer.c| 21 -
>> >>  drivers/timer/sifive_clint_timer.c | 21 -
>> >>  include/configs/ax25-ae350.h   |  5 +
>> >>  include/configs/sifive-fu540.h |  5 +
>> >>  5 files changed, 70 insertions(+), 3 deletions(-)
>> >>
>> >
>> >I verify with ae350_rv64_defconfig
>> >
>> >make FTRACE=1 ae350_rv64_defconfig
>> >make FTRACE=1
>> >
>> >and it boot fail as below:
>> >
>> >U-Boot 2021.01-rc2-00140-geb42715 (Nov 24 2020 - 15:02:18 +0800)
>> >
>> >DRAM:  1 GiB
>> >trace: enabled
>> >
>> >DO you have any suggestions ?
>>
>> Please enable CONFIG_TIMER_EARLY=y in ae350_rv64_defconfig
>>
>> Actually in v2, I will make TRACE to select TIMER_EARLY like below,
>>
>> --- a/lib/Kconfig
>> +++ b/lib/Kconfig
>> @@ -210,6 +210,7 @@ config BITREVERSE
>>  config TRACE
>> bool "Support for tracing of function calls and timing"
>> imply CMD_TRACE
>> +   select TIMER_EARLY
>>
>> Let me know if you have any suggestion.
>
>OK.
>
>After add CONFIG_TIMER_EARLY, U-Boot boots ok.
>But When I try to booting kernel with FTRACE=1, following are the test stats:
>
>ae350_rv64_spl_defconfig without FTRACE=1, kernel booting is ok.
>ae350_rv64_spl_defconfig with FTRACE=1, kernel booting fail.
>ae350_rv64_defconfig with FTRACE=1, kernel booting is ok
>
>The failure case seems not reasonable.
>Any suggestions ?

Strange, Can you please tell me which steps you follow and also send some debug 
logs  if possible.

>
>Thanks,
>Rick
>
>>
>> >
>> >Thanks,
>> >Rick
>> >
>> >> diff --git a/drivers/timer/andes_plmt_timer.c
>> >> b/drivers/timer/andes_plmt_timer.c
>> >> index cec86718c7..74b795c97a 100644
>> >> --- a/drivers/timer/andes_plmt_timer.c
>> >> +++ b/drivers/timer/andes_plmt_timer.c
>> >> @@ -17,11 +17,30 @@
>> >>  /* mtime register */
>> >>  #define MTIME_REG(base)((ulong)(base))
>> >>
>> >> -static u64 andes_plmt_get_count(struct udevice *dev)
>> >> +static u64 notrace andes_plmt_get_count(struct udevice *dev)
>> >>  {
>> >> return readq((void __iomem *)MTIME_REG(dev->priv));  }
>> >>
>> >> +#if CONFIG_IS_ENABLED(RISCV_MMODE)
>> >> +/**
>> >> + * timer_early_get_rate() - Get the timer rate before driver model
>> >> +*/ unsigned long notrace timer_early_get_rate(void) {
>> >> +   return RISCV_MMODE_TIMER_FREQ; }
>> >> +
>> >> +/**
>> >> + * timer_early_get_count() - Get the timer count before driver
>> >> +model
>> >> + *
>> >> + */
>> >> +u64 notrace timer_early_get_count(void) {
>> >> +   return readq((void __iomem
>> >> +*)MTIME_REG(RISCV_MMODE_TIMERBASE));
>> >> +}
>> >> +#endif
>> >> +
>> >>  static const struct timer_ops andes_plmt_ops = {
>> >> .get_count = andes_plmt_get_count,  }; diff --git
>> >> a/drivers/timer/riscv_timer.c b/drivers/timer/riscv_timer.c index
>> >> 21ae184057..a0f71ca897 100644
>> >> --- a/drivers/timer/riscv_timer.c
>> >> +++ b/drivers/timer/riscv_timer.c
>> >> @@ -16,7 +16,7 @@
>> >>  #include 
>> >>  #include 
>> >>
>> >> -static u64 riscv_timer_get_count(struct udevice *dev)
>> >> +static u64 notrace riscv_timer_get_count(struct udevice *dev)
>> >>  {
>> >> __maybe_unused u32 hi, lo;
>> >>
>> >> @@ -31,6 +31,25 @@ static u64 riscv_timer_

Re: [BUG] U-boot does not detect emmc card in odroid-c2 for newer U-boot as 2020.04

2020-11-26 Thread Otto Meier

Hi



Am 26.11.20 um 04:13 schrieb Jaehoon Chung:

Hi,

On 11/19/20 11:39 PM, Otto Meier wrote:

Hi,

with these modifications i get:

U-Boot 2021.01-rc2-00047-g9324c9a823-dirty (Nov 19 2020 - 15:33:00 +0100) 
odroid-c2

Model: Hardkernel ODROID-C2
SoC:   Amlogic Meson GXBB (S905) Revision 1f:c (0:1)
DRAM:  2 GiB
MMC:   mmc@72000: 0, mmc@74000: 1
In:serial
Out:   serial
Err:   serial
Net:   Could not get PHY for ethernet@c941: addr -1
No ethernet found.

Hit any key to stop autoboot:  0
MESON EMMC status = c5ff
MESON EMMC status = 01ff2000
MESON EMMC status = c5ff
MESON EMMC status = cdff
MESON EMMC status = 01ff2800
meson_dm_mmc_send_cmd[226]
MESON EMMC status = c5ff
MESON EMMC status = 01ff2800
meson_dm_mmc_send_cmd[226]
MESON EMMC status = c5ff
MESON EMMC status = 01ff2000
MESON EMMC status = c5ff
MESON EMMC status = cdff
MESON EMMC status = 01ff2800
meson_dm_mmc_send_cmd[226]
Card did not respond to voltage select! : -110
MESON EMMC status = c5ff
MESON EMMC status = 01ff2000
MESON EMMC status = c5ff
MESON EMMC status = cdff
MESON EMMC status = 01ff2800
meson_dm_mmc_send_cmd[226]
MESON EMMC status = c5ff
MESON EMMC status = 01ff2800
meson_dm_mmc_send_cmd[226]
MESON EMMC status = c5ff
MESON EMMC status = 01ff2000
MESON EMMC status = c5ff
MESON EMMC status = 00ff2000
MESON EMMC status = c5ff
MESON EMMC status = 01ff2800
meson_dm_mmc_send_cmd[226]
Card did not respond to voltage select! : -110
MMC Device 2 not found
no mmc device at slot 2
starting USB...

Hope this shed more light on the issue.


Sorry for late. Did you check more? or Is its status same?
If my understanding is correct, it seems that it's working fine with SD-card, 
right?
When i have checked its register value, resp timeout bit[11] is set. Adnd 
Bus_fsm is 1100.
I don't know what mean bus_fsm(0x1100)..
According to my understanding, resp_timeout value can be increased with cmd's 
argument.
Current u-boot is set to 4s. but maximum timeout value is 32.768s.

But i don't think that it's not affected with your target.. Because you 
mentioned that v2020.04 u-boot is working.
So i'm checking what is different to u-boot v2020.04.

Best Regards,
Jaehoon Chung



Best regards

Am 19.11.20 um 12:50 schrieb Jaehoon Chung:

Hi,




Yes i have tried different things: i have tried uboot-2020.07, 2020.10 all do 
not work. SO
it started with 2020.07. A diff between 2020.04 and 2020.07 in meson_gx_mmc.c 
gives
the following don´t know if it shows some point.

--- u-boot-2020.04/drivers/mmc/meson_gx_mmc.c   2020-11-21 20:42:01.768860866 
+0100
+++ u-boot-2020.07/drivers/mmc/meson_gx_mmc.c   2020-07-06 21:22:53.0 
+0200
@@ -4,6 +4,7 @@
  */
 
 #include 

+#include 
 #include 
 #include 
 #include 
@@ -13,6 +14,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 static inline void *get_regbase(const struct mmc *mmc)

@@ -198,7 +200,7 @@
status = meson_read(mmc, MESON_SD_EMMC_STATUS);
} while(!(status & STATUS_END_OF_CHAIN) && get_timer(start) < 1);
 
-   if (!(status & STATUS_END_OF_CHAIN))

+   if (!(status & STATUS_END_OF_CHAIN))
ret = -ETIMEDOUT;
else if (status & STATUS_RESP_TIMEOUT)
ret = -ETIMEDOUT;
@@ -241,12 +243,23 @@
struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
struct mmc *mmc = &pdata->mmc;
struct mmc_config *cfg = &pdata->cfg;
+   struct clk_bulk clocks;
uint32_t val;
+   int ret;
+
 #ifdef CONFIG_PWRSEQ
struct udevice *pwr_dev;
-   int ret;
 #endif
 
+   /* Enable the clocks feeding the MMC controller */

+   ret = clk_get_bulk(dev, &clocks);
+   if (ret)
+   return ret;
+
+   ret = clk_enable_bulk(&clocks);
+   if (ret)
+   return ret;
+
cfg->voltages = MMC_VDD_33_34 | MMC_VDD_32_33 |
MMC_VDD_31_32 | MMC_VDD_165_195;
cfg->host_caps = MMC_MODE_8BIT | MMC_MODE_4BIT |

-

SD Card is working, i can boot to u-boot command line , insert
an SD card and get with u-Boot git:

U-Boot 2021.01-rc2-00136-gd361eafe82-dirty (Nov 24 2020 - 16:23:10 +0100) 
odroid-c2

Model: Hardkernel ODROID-C2
SoC:   Amlogic Meson GXBB (S905) Revision 1f:c (0:1)
DRAM:  2 GiB
MMC:   mmc@72000: 0, mmc@74000: 1
In:serial
Out:   serial
Err:   serial
Net:   eth0: ethernet@c941
Hit any key to stop autoboot:  0

only with emmc i get :

=> mmc info
Card did not respond to voltage select!
=> mmc dev 1
Card did not respond to voltage select!

after inserting SD Card i get:

=> mmc info
Device: mmc@72000
Manufacturer ID: 74
OEM: 4a60
Name: USDU1
Bus Speed: 5000
Mode: SD High Speed (50MHz)
Rd Block Len: 512
SD version 3.0
High Capacity: Yes
Capacity: 119.1 GiB
Bus Width: 4-bit
Erase Group Size: 512 Bytes
=> mmc dev 1
Card did not respond to voltage select!
=> mmc list
mmc@72000: 0 (SD)
mmc@74000: 1
=>


Any Idea where i can help further?

Be

[PATCH v2] cmd: Add a pwm command

2020-11-26 Thread Pragnesh Patel
Add the command "pwm" for controlling the pwm channels. This
command provides pwm invert/config/enable/disable functionalities
via PWM uclass drivers

Signed-off-by: Pragnesh Patel 
---

Changes in v2:
- Add test for pwm command


 README|   1 +
 cmd/Kconfig   |   6 ++
 cmd/Makefile  |   1 +
 cmd/pwm.c | 120 ++
 configs/sandbox_defconfig |   1 +
 test/cmd/Makefile |   1 +
 test/cmd/pwm.c|  54 +
 7 files changed, 184 insertions(+)
 create mode 100644 cmd/pwm.c
 create mode 100644 test/cmd/pwm.c

diff --git a/README b/README
index cb49aa15da..dab291e0d0 100644
--- a/README
+++ b/README
@@ -3160,6 +3160,7 @@ i2c   - I2C sub-system
 sspi   - SPI utility commands
 base   - print or set address offset
 printenv- print environment variables
+pwm- control pwm channels
 setenv - set environment variables
 saveenv - save environment variables to persistent storage
 protect - enable or disable FLASH write protection
diff --git a/cmd/Kconfig b/cmd/Kconfig
index 1595de999b..0d085108f4 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -918,6 +918,12 @@ config CMD_GPIO
help
  GPIO support.
 
+config CMD_PWM
+   bool "pwm"
+   depends on DM_PWM
+   help
+ Control PWM channels, this allows invert/config/enable/disable PWM 
channels.
+
 config CMD_GPT
bool "GPT (GUID Partition Table) command"
select EFI_PARTITION
diff --git a/cmd/Makefile b/cmd/Makefile
index dd86675bf2..75df3c136c 100644
--- a/cmd/Makefile
+++ b/cmd/Makefile
@@ -120,6 +120,7 @@ endif
 obj-$(CONFIG_CMD_PINMUX) += pinmux.o
 obj-$(CONFIG_CMD_PMC) += pmc.o
 obj-$(CONFIG_CMD_PSTORE) += pstore.o
+obj-$(CONFIG_CMD_PWM) += pwm.o
 obj-$(CONFIG_CMD_PXE) += pxe.o pxe_utils.o
 obj-$(CONFIG_CMD_WOL) += wol.o
 obj-$(CONFIG_CMD_QFW) += qfw.o
diff --git a/cmd/pwm.c b/cmd/pwm.c
new file mode 100644
index 00..f704c7a755
--- /dev/null
+++ b/cmd/pwm.c
@@ -0,0 +1,120 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Control PWM channels
+ *
+ * Copyright (c) 2020 SiFive, Inc
+ * author: Pragnesh Patel 
+ */
+
+#include 
+#include 
+#include 
+
+enum pwm_cmd {
+   PWM_SET_INVERT,
+   PWM_SET_CONFIG,
+   PWM_SET_ENABLE,
+   PWM_SET_DISABLE,
+};
+
+static int do_pwm(struct cmd_tbl *cmdtp, int flag, int argc,
+ char *const argv[])
+{
+   const char *str_cmd, *str_channel = NULL, *str_enable = NULL;
+   const char *str_pwm = NULL, *str_period = NULL, *str_duty = NULL;
+   enum pwm_cmd sub_cmd;
+   struct udevice *dev;
+   u32 channel, pwm_enable, pwm_dev, period_ns = 0, duty_ns = 0;
+   int ret;
+
+   if (argc < 4)
+ show_usage:
+   return CMD_RET_USAGE;
+
+   str_cmd = argv[1];
+   argc -= 2;
+   argv += 2;
+
+   if (argc > 0) {
+   str_pwm = *argv;
+   argc--;
+   argv++;
+   }
+
+   if (!str_pwm)
+   goto show_usage;
+
+   switch (*str_cmd) {
+   case 'i':
+   sub_cmd = PWM_SET_INVERT;
+   break;
+   case 'c':
+   sub_cmd = PWM_SET_CONFIG;
+   break;
+   case 'e':
+   sub_cmd = PWM_SET_ENABLE;
+   break;
+   case 'd':
+   sub_cmd = PWM_SET_DISABLE;
+   break;
+   default:
+   goto show_usage;
+   }
+
+   if (IS_ENABLED(CONFIG_DM_PWM)) {
+   pwm_dev = simple_strtoul(str_pwm, NULL, 10);
+   ret = uclass_get_device(UCLASS_PWM, pwm_dev, &dev);
+   if (ret) {
+   printf("PWM: '%s' not found\n", str_pwm);
+   return cmd_process_error(cmdtp, ret);
+   }
+   }
+
+   if (argc > 0) {
+   str_channel = *argv;
+   channel = simple_strtoul(str_channel, NULL, 10);
+   argc--;
+   argv++;
+   } else {
+   goto show_usage;
+   }
+
+   if (sub_cmd == PWM_SET_INVERT && argc > 0) {
+   str_enable = *argv;
+   pwm_enable = simple_strtoul(str_enable, NULL, 10);
+   ret = pwm_set_invert(dev, channel, pwm_enable);
+   } else if (sub_cmd == PWM_SET_CONFIG && argc == 2) {
+   str_period = *argv;
+   argc--;
+   argv++;
+   period_ns = simple_strtoul(str_period, NULL, 10);
+
+   if (argc > 0) {
+   str_duty = *argv;
+   duty_ns = simple_strtoul(str_duty, NULL, 10);
+   }
+
+   ret = pwm_set_config(dev, channel, period_ns, duty_ns);
+   } else if (sub_cmd == PWM_SET_ENABLE) {
+   ret = pwm_set_enable(dev, channel, 1);
+   } else if (sub_cmd == PWM_SET_DISABLE) {
+   ret = pwm_set_enable(dev, channel, 0);
+   } else {
+   printf("PWM arguments missing\n");
+  

Re: [PATCH] Add fdtfile for Marvell Armada 37xx default environment

2020-11-26 Thread Andre Heider

On 26/11/2020 10:04, Matwey V. Kornilov wrote:



чт, 26 нояб. 2020 г. в 06:45, Andre Heider >:


On 25/11/2020 10:14, Matwey V. Kornilov wrote:
 > Signed-off-by: Matwey V. Kornilov mailto:matwey.korni...@gmail.com>>
 > ---
 >   configs/mvebu_db-88f3720_defconfig          | 1 +
 >   configs/mvebu_espressobin-88f3720_defconfig | 1 +
 >   include/configs/mvebu_armada-37xx.h         | 1 +
 >   3 files changed, 3 insertions(+)
 >
 > diff --git a/configs/mvebu_db-88f3720_defconfig
b/configs/mvebu_db-88f3720_defconfig
 > index a6bbe1a7af..1a3a267890 100644
 > --- a/configs/mvebu_db-88f3720_defconfig
 > +++ b/configs/mvebu_db-88f3720_defconfig
 > @@ -12,6 +12,7 @@ CONFIG_DM_GPIO=y
 >   CONFIG_DEBUG_UART_BASE=0xd0012000
 >   CONFIG_DEBUG_UART_CLOCK=25804800
 >   CONFIG_DEFAULT_DEVICE_TREE="armada-3720-db"
 > +CONFIG_DEFAULT_FDT_FILE="marvell/armada-3720-db.dtb"
 >   CONFIG_DEBUG_UART=y
 >   CONFIG_AHCI=y
 >   CONFIG_DISTRO_DEFAULTS=y
 > diff --git a/configs/mvebu_espressobin-88f3720_defconfig
b/configs/mvebu_espressobin-88f3720_defconfig
 > index 8a859cba2e..56ec482794 100644
 > --- a/configs/mvebu_espressobin-88f3720_defconfig
 > +++ b/configs/mvebu_espressobin-88f3720_defconfig
 > @@ -12,6 +12,7 @@ CONFIG_DM_GPIO=y
 >   CONFIG_DEBUG_UART_BASE=0xd0012000
 >   CONFIG_DEBUG_UART_CLOCK=25804800
 >   CONFIG_DEFAULT_DEVICE_TREE="armada-3720-espressobin"
 > +CONFIG_DEFAULT_FDT_FILE="marvell/armada-3720-espressobin.dtb"

No, that doesn't work for this board, see
68e32e344 "arm: mvebu: Espressobin: Set environment variable fdtfile"


Good point.
But why does this autodetection not work for me?


I guess that can only happen if:
- the commit isn't part of you tree
- you disabled CONFIG_BOARD_LATE_INIT or didn't refresh from the defconfig
- you already have the envvar set/saved



 >   CONFIG_DEBUG_UART=y
 >   CONFIG_AHCI=y
 >   CONFIG_DISTRO_DEFAULTS=y
 > diff --git a/include/configs/mvebu_armada-37xx.h
b/include/configs/mvebu_armada-37xx.h
 > index 0d585606a7..377ac60def 100644
 > --- a/include/configs/mvebu_armada-37xx.h
 > +++ b/include/configs/mvebu_armada-37xx.h
 > @@ -96,6 +96,7 @@
 >       "kernel_addr=0x700\0"       \
 >       "kernel_addr_r=0x700\0"     \
 >       "ramdisk_addr_r=0xa00\0"    \
 > +     "fdtfile=" CONFIG_DEFAULT_FDT_FILE "\0" \
 >       BOOTENV
 >
 >   #endif /* _CONFIG_MVEBU_ARMADA_37XX_H */
 >



--
With best regards,
Matwey V. Kornilov




Re: [PATCH] riscv: timer: Add support for an early timer

2020-11-26 Thread Rick Chen
Hi Pragnesh

> Hi Rick,
>
> >-Original Message-
> >From: Rick Chen 
> >Sent: 24 November 2020 13:08
> >To: Pragnesh Patel 
> >Cc: U-Boot Mailing List ; Atish Patra
> >; Bin Meng ; Paul Walmsley (
> >Sifive) ; Anup Patel ; Sagar
> >Kadam ; Palmer Dabbelt ;
> >Simon Glass ; rick ; Alan Kao
> >; Leo Liang 
> >Subject: Re: [PATCH] riscv: timer: Add support for an early timer
> >
> >[External Email] Do not click links or attachments unless you recognize the
> >sender and know the content is safe
> >
> >Hi Pragnesh,
> >
> >> From: Pragnesh Patel [mailto:pragnesh.pa...@sifive.com]
> >> Sent: Tuesday, November 17, 2020 7:05 PM
> >> To: u-boot@lists.denx.de
> >> Cc: atish.pa...@wdc.com; palmerdabb...@google.com;
> >bmeng...@gmail.com;
> >> paul.walms...@sifive.com; anup.pa...@wdc.com; sagar.ka...@sifive.com;
> >> Rick Jian-Zhi Chen(陳建志); Pragnesh Patel; Palmer Dabbelt; Sean
> >> Anderson; Simon Glass; Bin Meng
> >> Subject: [PATCH] riscv: timer: Add support for an early timer
> >>
> >> Added support for timer_early_get_count() and timer_early_get_rate()
> >> This is mostly useful in tracing.
> >>
> >> Signed-off-by: Pragnesh Patel 
> >> ---
> >>  drivers/timer/andes_plmt_timer.c   | 21 -
> >>  drivers/timer/riscv_timer.c| 21 -
> >>  drivers/timer/sifive_clint_timer.c | 21 -
> >>  include/configs/ax25-ae350.h   |  5 +
> >>  include/configs/sifive-fu540.h |  5 +
> >>  5 files changed, 70 insertions(+), 3 deletions(-)
> >>
> >
> >I verify with ae350_rv64_defconfig
> >
> >make FTRACE=1 ae350_rv64_defconfig
> >make FTRACE=1
> >
> >and it boot fail as below:
> >
> >U-Boot 2021.01-rc2-00140-geb42715 (Nov 24 2020 - 15:02:18 +0800)
> >
> >DRAM:  1 GiB
> >trace: enabled
> >
> >DO you have any suggestions ?
>
> Please enable CONFIG_TIMER_EARLY=y in ae350_rv64_defconfig
>
> Actually in v2, I will make TRACE to select TIMER_EARLY like below,
>
> --- a/lib/Kconfig
> +++ b/lib/Kconfig
> @@ -210,6 +210,7 @@ config BITREVERSE
>  config TRACE
> bool "Support for tracing of function calls and timing"
> imply CMD_TRACE
> +   select TIMER_EARLY
>
> Let me know if you have any suggestion.

OK.

After add CONFIG_TIMER_EARLY, U-Boot boots ok.
But When I try to booting kernel with FTRACE=1, following are the test stats:

ae350_rv64_spl_defconfig without FTRACE=1, kernel booting is ok.
ae350_rv64_spl_defconfig with FTRACE=1, kernel booting fail.
ae350_rv64_defconfig with FTRACE=1, kernel booting is ok

The failure case seems not reasonable.
Any suggestions ?

Thanks,
Rick

>
> >
> >Thanks,
> >Rick
> >
> >> diff --git a/drivers/timer/andes_plmt_timer.c
> >> b/drivers/timer/andes_plmt_timer.c
> >> index cec86718c7..74b795c97a 100644
> >> --- a/drivers/timer/andes_plmt_timer.c
> >> +++ b/drivers/timer/andes_plmt_timer.c
> >> @@ -17,11 +17,30 @@
> >>  /* mtime register */
> >>  #define MTIME_REG(base)((ulong)(base))
> >>
> >> -static u64 andes_plmt_get_count(struct udevice *dev)
> >> +static u64 notrace andes_plmt_get_count(struct udevice *dev)
> >>  {
> >> return readq((void __iomem *)MTIME_REG(dev->priv));  }
> >>
> >> +#if CONFIG_IS_ENABLED(RISCV_MMODE)
> >> +/**
> >> + * timer_early_get_rate() - Get the timer rate before driver model
> >> +*/ unsigned long notrace timer_early_get_rate(void) {
> >> +   return RISCV_MMODE_TIMER_FREQ; }
> >> +
> >> +/**
> >> + * timer_early_get_count() - Get the timer count before driver model
> >> + *
> >> + */
> >> +u64 notrace timer_early_get_count(void) {
> >> +   return readq((void __iomem
> >> +*)MTIME_REG(RISCV_MMODE_TIMERBASE));
> >> +}
> >> +#endif
> >> +
> >>  static const struct timer_ops andes_plmt_ops = {
> >> .get_count = andes_plmt_get_count,  }; diff --git
> >> a/drivers/timer/riscv_timer.c b/drivers/timer/riscv_timer.c index
> >> 21ae184057..a0f71ca897 100644
> >> --- a/drivers/timer/riscv_timer.c
> >> +++ b/drivers/timer/riscv_timer.c
> >> @@ -16,7 +16,7 @@
> >>  #include 
> >>  #include 
> >>
> >> -static u64 riscv_timer_get_count(struct udevice *dev)
> >> +static u64 notrace riscv_timer_get_count(struct udevice *dev)
> >>  {
> >> __maybe_unused u32 hi, lo;
> >>
> >> @@ -31,6 +31,25 @@ static u64 riscv_timer_get_count(struct udevice *dev)
> >> return ((u64)hi << 32) | lo;
> >>  }
> >>
> >> +#if CONFIG_IS_ENABLED(RISCV_SMODE)
> >> +/**
> >> + * timer_early_get_rate() - Get the timer rate before driver model
> >> +*/ unsigned long notrace timer_early_get_rate(void) {
> >> +   return RISCV_SMODE_TIMER_FREQ; }
> >> +
> >> +/**
> >> + * timer_early_get_count() - Get the timer count before driver model
> >> + *
> >> + */
> >> +u64 notrace timer_early_get_count(void) {
> >> +   return riscv_timer_get_count(NULL); } #endif
> >> +
> >>  static int riscv_timer_probe(struct udevice *dev)  {
> >> struct timer_dev_priv *uc_priv = dev_get_uclass_priv(dev);
> >> diff --git a/drivers/timer/sifive_clint_timer.c
> >> b/d

Re: [PATCH] Add fdtfile for Marvell Armada 37xx default environment

2020-11-26 Thread Matwey V. Kornilov
чт, 26 нояб. 2020 г. в 06:45, Andre Heider :

> On 25/11/2020 10:14, Matwey V. Kornilov wrote:
> > Signed-off-by: Matwey V. Kornilov 
> > ---
> >   configs/mvebu_db-88f3720_defconfig  | 1 +
> >   configs/mvebu_espressobin-88f3720_defconfig | 1 +
> >   include/configs/mvebu_armada-37xx.h | 1 +
> >   3 files changed, 3 insertions(+)
> >
> > diff --git a/configs/mvebu_db-88f3720_defconfig
> b/configs/mvebu_db-88f3720_defconfig
> > index a6bbe1a7af..1a3a267890 100644
> > --- a/configs/mvebu_db-88f3720_defconfig
> > +++ b/configs/mvebu_db-88f3720_defconfig
> > @@ -12,6 +12,7 @@ CONFIG_DM_GPIO=y
> >   CONFIG_DEBUG_UART_BASE=0xd0012000
> >   CONFIG_DEBUG_UART_CLOCK=25804800
> >   CONFIG_DEFAULT_DEVICE_TREE="armada-3720-db"
> > +CONFIG_DEFAULT_FDT_FILE="marvell/armada-3720-db.dtb"
> >   CONFIG_DEBUG_UART=y
> >   CONFIG_AHCI=y
> >   CONFIG_DISTRO_DEFAULTS=y
> > diff --git a/configs/mvebu_espressobin-88f3720_defconfig
> b/configs/mvebu_espressobin-88f3720_defconfig
> > index 8a859cba2e..56ec482794 100644
> > --- a/configs/mvebu_espressobin-88f3720_defconfig
> > +++ b/configs/mvebu_espressobin-88f3720_defconfig
> > @@ -12,6 +12,7 @@ CONFIG_DM_GPIO=y
> >   CONFIG_DEBUG_UART_BASE=0xd0012000
> >   CONFIG_DEBUG_UART_CLOCK=25804800
> >   CONFIG_DEFAULT_DEVICE_TREE="armada-3720-espressobin"
> > +CONFIG_DEFAULT_FDT_FILE="marvell/armada-3720-espressobin.dtb"
>
> No, that doesn't work for this board, see
> 68e32e344 "arm: mvebu: Espressobin: Set environment variable fdtfile"
>
>
Good point.
But why does this autodetection not work for me?



> >   CONFIG_DEBUG_UART=y
> >   CONFIG_AHCI=y
> >   CONFIG_DISTRO_DEFAULTS=y
> > diff --git a/include/configs/mvebu_armada-37xx.h
> b/include/configs/mvebu_armada-37xx.h
> > index 0d585606a7..377ac60def 100644
> > --- a/include/configs/mvebu_armada-37xx.h
> > +++ b/include/configs/mvebu_armada-37xx.h
> > @@ -96,6 +96,7 @@
> >   "kernel_addr=0x700\0"   \
> >   "kernel_addr_r=0x700\0" \
> >   "ramdisk_addr_r=0xa00\0"\
> > + "fdtfile=" CONFIG_DEFAULT_FDT_FILE "\0" \
> >   BOOTENV
> >
> >   #endif /* _CONFIG_MVEBU_ARMADA_37XX_H */
> >
>
>

-- 
With best regards,
Matwey V. Kornilov