Re: Pull request for UEFI sub-system for efi-2020-10-rc1 (2)

2020-07-11 Thread Heinrich Schuchardt
On 7/10/20 8:09 PM, Tom Rini wrote:
> On Thu, Jul 09, 2020 at 06:12:02PM +0200, Heinrich Schuchardt wrote:
>
>> The following changes since commit 61608f395e7dcb2be6060407a72a1149b046430a:
>>
>>   Merge branch '2020-07-08-misc-features-and-fixes' (2020-07-08 20:20:24
>> -0400)
>>
>> are available in the Git repository at:
>>
>>   https://gitlab.denx.de/u-boot/custodians/u-boot-efi.git efi-2020-10-rc1-2
>>
>> for you to fetch changes up to f4cef8e7585c268f05a8c39e368ca115c25e40d5:
>>
>>   efi_selftest: adjust runtime test for variables (2020-07-09 12:08:41
>> +0200)
>>
>
> NAK.  This is reliably failing here:
> https://gitlab.denx.de/u-boot/u-boot/-/jobs/122018
>
> I see it passed Azure, and hasn't run through Travis yet.  Maybe it
> needs to be run repeatedly to fail and we just got "lucky" ?
>

Hello Tom,

you saw unreproducible results with multiple runs failing and one run
succeeding. The reason is that when signing with sign-efi-sig-list in
out Python tests without passing a timestamp two signatures may be in
the same second or not.

When using the signed files to set UEFI variables a variable can only be
overwritten by a file with a newer timestamp. But without setting
timestamps explicitly using parameter -t passed to sign-efi-sig-list we
have no control.

I already fixed this for some elder tests but missed to fix this for the
merged patches from Takahiro.

Best regards

Heinrich


[PATCH v4 02/12] efi_loader: image_loader: retrieve authenticode only if it exists

2020-07-11 Thread Heinrich Schuchardt
From: AKASHI Takahiro 

Since the certificate table, which is indexed by
IMAGE_DIRECTORY_ENTRY_SECURITY and contains authenticode in PE image,
doesn't always exist, we should make sure that we will retrieve its pointer
only if it exists.

Signed-off-by: AKASHI Takahiro 
---
 lib/efi_loader/efi_image_loader.c | 29 +
 1 file changed, 21 insertions(+), 8 deletions(-)

diff --git a/lib/efi_loader/efi_image_loader.c 
b/lib/efi_loader/efi_image_loader.c
index 9b01e1ec90..de230409e3 100644
--- a/lib/efi_loader/efi_image_loader.c
+++ b/lib/efi_loader/efi_image_loader.c
@@ -267,6 +267,8 @@ bool efi_image_parse(void *efi, size_t len, struct 
efi_image_regions **regp,

dos = (void *)efi;
nt = (void *)(efi + dos->e_lfanew);
+   authoff = 0;
+   authsz = 0;

/*
 * Count maximum number of regions to be digested.
@@ -305,25 +307,36 @@ bool efi_image_parse(void *efi, size_t len, struct 
efi_image_regions **regp,
efi_image_region_add(regs,
 &opt->DataDirectory[ctidx] + 1,
 efi + opt->SizeOfHeaders, 0);
+
+   authoff = opt->DataDirectory[ctidx].VirtualAddress;
+   authsz = opt->DataDirectory[ctidx].Size;
}

bytes_hashed = opt->SizeOfHeaders;
align = opt->FileAlignment;
-   authoff = opt->DataDirectory[ctidx].VirtualAddress;
-   authsz = opt->DataDirectory[ctidx].Size;
} else if (nt->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
IMAGE_OPTIONAL_HEADER32 *opt = &nt->OptionalHeader;

+   /* Skip CheckSum */
efi_image_region_add(regs, efi, &opt->CheckSum, 0);
-   efi_image_region_add(regs, &opt->Subsystem,
-&opt->DataDirectory[ctidx], 0);
-   efi_image_region_add(regs, &opt->DataDirectory[ctidx] + 1,
-efi + opt->SizeOfHeaders, 0);
+   if (nt->OptionalHeader.NumberOfRvaAndSizes <= ctidx) {
+   efi_image_region_add(regs,
+&opt->Subsystem,
+efi + opt->SizeOfHeaders, 0);
+   } else {
+   /* Skip Certificates Table */
+   efi_image_region_add(regs, &opt->Subsystem,
+&opt->DataDirectory[ctidx], 0);
+   efi_image_region_add(regs,
+&opt->DataDirectory[ctidx] + 1,
+efi + opt->SizeOfHeaders, 0);
+
+   authoff = opt->DataDirectory[ctidx].VirtualAddress;
+   authsz = opt->DataDirectory[ctidx].Size;
+   }

bytes_hashed = opt->SizeOfHeaders;
align = opt->FileAlignment;
-   authoff = opt->DataDirectory[ctidx].VirtualAddress;
-   authsz = opt->DataDirectory[ctidx].Size;
} else {
EFI_PRINT("%s: Invalid optional header magic %x\n", __func__,
  nt->OptionalHeader.Magic);
--
2.27.0



[PATCH v4 00/12] efi_loader: rework/improve UEFI secure boot code

2020-07-11 Thread Heinrich Schuchardt
This is a respin of Takahiro's patch series adding a defined time stamp
for time authenticated variables by calling sign-efi-sig-list with -t in
patches 10 - 12.

The original patch 01 of version 3 has been obsoleted by

lib/crypto: use qualified path for x509_parser.h
https://lists.denx.de/pipermail/u-boot/2020-July/419214.html

v4 (Jul 11th, 2020)
* remove obsolete patch 01/13 of v3
* call sign-efi-sig-list with -t

v3 (Jul 8, 2020)
* rebased to Heinrich's (current) efi-2020-10-rc1
* removed already-merged commits
* include pylint fixes (patch#8, #9 and #10-#13)
* print time64_t in "0x%llx" format (patch#4)
* make a small change on a description about efi_hash_regions() (patch#5)

v2 (Jun 9, 2020)
* on top of v2020.07-rc4
* add patch#1,#2 to remove unnecessary hacks in pytest
* use EFI_PRINT() instead of debug() everywhere (patch#3-#5)
* fix a verification logic so that we should reject an image if, at least,
  one of signaures be verified by dbx. New efi_signature_verify_one() has
  a main role. (patch#10)
* use "llu" format instead of "llx" to print out the revocation time
  (patch#10)
* add some description about verification logic against multiple signatures
  (patch#11)

v1 (May 29, 2020)

* initial release

*** BLURB HERE ***

AKASHI Takahiro (12):
  efi_loader: image_loader: add a check against certificate type of
authenticode
  efi_loader: image_loader: retrieve authenticode only if it exists
  efi_loader: signature: fix a size check against revocation list
  efi_loader: signature: make efi_hash_regions more generic
  efi_loader: image_loader: verification for all signatures should pass
  efi_loader: image_loader: add digest-based verification for signed
image
  test/py: efi_secboot: apply autopep8
  test/py: efi_secboot: more fixes against pylint
  test/py: efi_secboot: split "signed image" test case-1 into two cases
  test/py: efi_secboot: add a test against certificate revocation
  test/py: efi_secboot: add a test for multiple signatures
  test/py: efi_secboot: add a test for verifying with digest of signed
image

 include/efi_loader.h  |  15 +-
 lib/efi_loader/efi_image_loader.c | 162 +--
 lib/efi_loader/efi_signature.c| 435 +-
 test/py/tests/test_efi_secboot/conftest.py| 104 +++--
 test/py/tests/test_efi_secboot/defs.py|  14 +-
 .../py/tests/test_efi_secboot/test_authvar.py |  92 ++--
 test/py/tests/test_efi_secboot/test_signed.py | 206 +++--
 .../tests/test_efi_secboot/test_unsigned.py   |  66 +--
 8 files changed, 677 insertions(+), 417 deletions(-)

--
2.27.0



[PATCH v4 01/12] efi_loader: image_loader: add a check against certificate type of authenticode

2020-07-11 Thread Heinrich Schuchardt
From: AKASHI Takahiro 

UEFI specification requires that we shall support three type of
certificates of authenticode in PE image:
  WIN_CERT_TYPE_EFI_GUID with the guid, EFI_CERT_TYPE_PCKS7_GUID
  WIN_CERT_TYPE_PKCS_SIGNED_DATA
  WIN_CERT_TYPE_EFI_PKCS1_15

As EDK2 does, we will support the first two that are pkcs7 SignedData.

Signed-off-by: AKASHI Takahiro 
---
 lib/efi_loader/efi_image_loader.c | 56 ---
 1 file changed, 44 insertions(+), 12 deletions(-)

diff --git a/lib/efi_loader/efi_image_loader.c 
b/lib/efi_loader/efi_image_loader.c
index 06a2ebdb90..9b01e1ec90 100644
--- a/lib/efi_loader/efi_image_loader.c
+++ b/lib/efi_loader/efi_image_loader.c
@@ -483,7 +483,8 @@ static bool efi_image_authenticate(void *efi, size_t 
efi_size)
struct efi_signature_store *db = NULL, *dbx = NULL;
struct x509_certificate *cert = NULL;
void *new_efi = NULL;
-   size_t new_efi_size;
+   u8 *auth, *wincerts_end;
+   size_t new_efi_size, auth_size;
bool ret = false;

if (!efi_secure_boot_enabled())
@@ -532,21 +533,52 @@ static bool efi_image_authenticate(void *efi, size_t 
efi_size)
}

/* go through WIN_CERTIFICATE list */
-   for (wincert = wincerts;
-(void *)wincert < (void *)wincerts + wincerts_len;
-wincert = (void *)wincert + ALIGN(wincert->dwLength, 8)) {
-   if (wincert->dwLength < sizeof(*wincert)) {
-   EFI_PRINT("%s: dwLength too small: %u < %zu\n",
- __func__, wincert->dwLength,
- sizeof(*wincert));
-   goto err;
+   for (wincert = wincerts, wincerts_end = (u8 *)wincerts + wincerts_len;
+(u8 *)wincert < wincerts_end;
+wincert = (WIN_CERTIFICATE *)
+   ((u8 *)wincert + ALIGN(wincert->dwLength, 8))) {
+   if ((u8 *)wincert + sizeof(*wincert) >= wincerts_end)
+   break;
+
+   if (wincert->dwLength <= sizeof(*wincert)) {
+   EFI_PRINT("dwLength too small: %u < %zu\n",
+ wincert->dwLength, sizeof(*wincert));
+   continue;
+   }
+
+   EFI_PRINT("WIN_CERTIFICATE_TYPE: 0x%x\n",
+ wincert->wCertificateType);
+
+   auth = (u8 *)wincert + sizeof(*wincert);
+   auth_size = wincert->dwLength - sizeof(*wincert);
+   if (wincert->wCertificateType == WIN_CERT_TYPE_EFI_GUID) {
+   if (auth + sizeof(efi_guid_t) >= wincerts_end)
+   break;
+
+   if (auth_size <= sizeof(efi_guid_t)) {
+   EFI_PRINT("dwLength too small: %u < %zu\n",
+ wincert->dwLength, sizeof(*wincert));
+   continue;
+   }
+   if (guidcmp(auth, &efi_guid_cert_type_pkcs7)) {
+   EFI_PRINT("Certificate type not supported: 
%pUl\n",
+ auth);
+   continue;
+   }
+
+   auth += sizeof(efi_guid_t);
+   auth_size -= sizeof(efi_guid_t);
+   } else if (wincert->wCertificateType
+   != WIN_CERT_TYPE_PKCS_SIGNED_DATA) {
+   EFI_PRINT("Certificate type not supported\n");
+   continue;
}
-   msg = pkcs7_parse_message((void *)wincert + sizeof(*wincert),
- wincert->dwLength - sizeof(*wincert));
+
+   msg = pkcs7_parse_message(auth, auth_size);
if (IS_ERR(msg)) {
EFI_PRINT("Parsing image's signature failed\n");
msg = NULL;
-   goto err;
+   continue;
}

/* try black-list first */
--
2.27.0



[PATCH v4 03/12] efi_loader: signature: fix a size check against revocation list

2020-07-11 Thread Heinrich Schuchardt
From: AKASHI Takahiro 

Since the size check against an entry in efi_search_siglist() is
incorrect, this function will never find out a to-be-matched certificate
and its associated revocation time in the signature list.

Signed-off-by: AKASHI Takahiro 
---
 lib/efi_loader/efi_signature.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/lib/efi_loader/efi_signature.c b/lib/efi_loader/efi_signature.c
index e05c471c61..cd2df46264 100644
--- a/lib/efi_loader/efi_signature.c
+++ b/lib/efi_loader/efi_signature.c
@@ -433,10 +433,11 @@ static bool efi_search_siglist(struct x509_certificate 
*cert,
 *  time64_t revocation_time;
 * };
 */
-   if ((sig_data->size == SHA256_SUM_LEN) &&
-   !memcmp(sig_data->data, hash, SHA256_SUM_LEN)) {
+   if ((sig_data->size >= SHA256_SUM_LEN + sizeof(time64_t)) &&
+   !memcmp(sig_data->data, msg, SHA256_SUM_LEN)) {
memcpy(revoc_time, sig_data->data + SHA256_SUM_LEN,
   sizeof(*revoc_time));
+   EFI_PRINT("revocation time: 0x%llx\n", *revoc_time);
found = true;
goto out;
}
--
2.27.0



[PATCH v4 05/12] efi_loader: image_loader: verification for all signatures should pass

2020-07-11 Thread Heinrich Schuchardt
From: AKASHI Takahiro 

A signed image may have multiple signatures in
  - each WIN_CERTIFICATE in authenticode, and/or
  - each SignerInfo in pkcs7 SignedData (of WIN_CERTIFICATE)

In the initial implementation of efi_image_authenticate(), the criteria
of verification check for multiple signatures case is a bit ambiguous
and it may cause inconsistent result.

With this patch, we will make sure that verification check in
efi_image_authenticate() should pass against all the signatures.
The only exception would be
  - the case where a digest algorithm used in signature is not supported by
U-Boot, or
  - the case where parsing some portion of authenticode has failed
In those cases, we don't know how the signature be handled and should
just ignore them.

Please note that, due to this change, efi_signature_verify_with_sigdb()'s
function prototype will be modified, taking "dbx" as well as "db"
instead of outputing a "certificate." If "dbx" is null, the behavior would
be the exact same as before.
The function's name will be changed to efi_signature_verify() once
current efi_signature_verify() has gone due to further improvement
in intermediate certificates support.

Signed-off-by: AKASHI Takahiro 
---
 include/efi_loader.h  |  13 +-
 lib/efi_loader/efi_image_loader.c |  43 ++---
 lib/efi_loader/efi_signature.c| 298 +-
 3 files changed, 198 insertions(+), 156 deletions(-)

diff --git a/include/efi_loader.h b/include/efi_loader.h
index fc9344c742..2f9fb112b3 100644
--- a/include/efi_loader.h
+++ b/include/efi_loader.h
@@ -765,14 +765,15 @@ struct efi_signature_store {
 struct x509_certificate;
 struct pkcs7_message;

-bool efi_signature_verify_cert(struct x509_certificate *cert,
-  struct efi_signature_store *dbx);
-bool efi_signature_verify_signers(struct pkcs7_message *msg,
- struct efi_signature_store *dbx);
+bool efi_signature_verify_one(struct efi_image_regions *regs,
+ struct pkcs7_message *msg,
+ struct efi_signature_store *db);
 bool efi_signature_verify_with_sigdb(struct efi_image_regions *regs,
 struct pkcs7_message *msg,
- struct efi_signature_store *db,
- struct x509_certificate **cert);
+struct efi_signature_store *db,
+struct efi_signature_store *dbx);
+bool efi_signature_check_signers(struct pkcs7_message *msg,
+struct efi_signature_store *dbx);

 efi_status_t efi_image_region_add(struct efi_image_regions *regs,
  const void *start, const void *end,
diff --git a/lib/efi_loader/efi_image_loader.c 
b/lib/efi_loader/efi_image_loader.c
index de230409e3..058359fc25 100644
--- a/lib/efi_loader/efi_image_loader.c
+++ b/lib/efi_loader/efi_image_loader.c
@@ -448,13 +448,13 @@ static bool efi_image_unsigned_authenticate(struct 
efi_image_regions *regs)
}

/* try black-list first */
-   if (efi_signature_verify_with_sigdb(regs, NULL, dbx, NULL)) {
+   if (efi_signature_verify_one(regs, NULL, dbx)) {
EFI_PRINT("Image is not signed and rejected by \"dbx\"\n");
goto out;
}

/* try white-list */
-   if (efi_signature_verify_with_sigdb(regs, NULL, db, NULL))
+   if (efi_signature_verify_one(regs, NULL, db))
ret = true;
else
EFI_PRINT("Image is not signed and not found in \"db\" or 
\"dbx\"\n");
@@ -494,12 +494,13 @@ static bool efi_image_authenticate(void *efi, size_t 
efi_size)
size_t wincerts_len;
struct pkcs7_message *msg = NULL;
struct efi_signature_store *db = NULL, *dbx = NULL;
-   struct x509_certificate *cert = NULL;
void *new_efi = NULL;
u8 *auth, *wincerts_end;
size_t new_efi_size, auth_size;
bool ret = false;

+   debug("%s: Enter, %d\n", __func__, ret);
+
if (!efi_secure_boot_enabled())
return true;

@@ -545,7 +546,17 @@ static bool efi_image_authenticate(void *efi, size_t 
efi_size)
goto err;
}

-   /* go through WIN_CERTIFICATE list */
+   /*
+* go through WIN_CERTIFICATE list
+* NOTE:
+* We may have multiple signatures either as WIN_CERTIFICATE's
+* in PE header, or as pkcs7 SignerInfo's in SignedData.
+* So the verification policy here is:
+*   - Success if, at least, one of signatures is verified
+*   - unless
+*   any of signatures is rejected explicitly, or
+*   none of digest algorithms are supported
+*/
for (wincert = wincerts, wincerts_end = (u8 *)wincerts + wincerts_len;
 (u8 *)wincert < wincerts_end;
 wincert = (WIN_CERTIFICATE *)
@@ -595,42 +606,

[PATCH v4 06/12] efi_loader: image_loader: add digest-based verification for signed image

2020-07-11 Thread Heinrich Schuchardt
From: AKASHI Takahiro 

In case that a type of certificate in "db" or "dbx" is
EFI_CERT_X509_SHA256_GUID, it is actually not a certificate which contains
a public key for RSA decryption, but a digest of image to be loaded.
If the value matches to a value calculated from a given binary image, it is
granted for loading.

With this patch, common digest check code, which used to be used for
unsigned image verification, will be extracted from
efi_signature_verify_with_sigdb() into efi_signature_lookup_digest(), and
extra step for digest check will be added to efi_image_authenticate().

Signed-off-by: AKASHI Takahiro 
---
 include/efi_loader.h  |   2 +
 lib/efi_loader/efi_image_loader.c |  44 --
 lib/efi_loader/efi_signature.c| 128 ++
 3 files changed, 99 insertions(+), 75 deletions(-)

diff --git a/include/efi_loader.h b/include/efi_loader.h
index 2f9fb112b3..ceabbaadd0 100644
--- a/include/efi_loader.h
+++ b/include/efi_loader.h
@@ -765,6 +765,8 @@ struct efi_signature_store {
 struct x509_certificate;
 struct pkcs7_message;

+bool efi_signature_lookup_digest(struct efi_image_regions *regs,
+struct efi_signature_store *db);
 bool efi_signature_verify_one(struct efi_image_regions *regs,
  struct pkcs7_message *msg,
  struct efi_signature_store *db);
diff --git a/lib/efi_loader/efi_image_loader.c 
b/lib/efi_loader/efi_image_loader.c
index 058359fc25..b7cf26046e 100644
--- a/lib/efi_loader/efi_image_loader.c
+++ b/lib/efi_loader/efi_image_loader.c
@@ -448,16 +448,16 @@ static bool efi_image_unsigned_authenticate(struct 
efi_image_regions *regs)
}

/* try black-list first */
-   if (efi_signature_verify_one(regs, NULL, dbx)) {
-   EFI_PRINT("Image is not signed and rejected by \"dbx\"\n");
+   if (efi_signature_lookup_digest(regs, dbx)) {
+   EFI_PRINT("Image is not signed and its digest found in 
\"dbx\"\n");
goto out;
}

/* try white-list */
-   if (efi_signature_verify_one(regs, NULL, db))
+   if (efi_signature_lookup_digest(regs, db))
ret = true;
else
-   EFI_PRINT("Image is not signed and not found in \"db\" or 
\"dbx\"\n");
+   EFI_PRINT("Image is not signed and its digest not found in 
\"db\" or \"dbx\"\n");

 out:
efi_sigstore_free(db);
@@ -605,6 +605,25 @@ static bool efi_image_authenticate(void *efi, size_t 
efi_size)
continue;
}

+   /*
+* NOTE:
+* UEFI specification defines two signature types possible
+* in signature database:
+* a. x509 certificate, where a signature in image is
+*a message digest encrypted by RSA public key
+*(EFI_CERT_X509_GUID)
+* b. bare hash value of message digest
+*(EFI_CERT_SHAxxx_GUID)
+*
+* efi_signature_verify() handles case (a), while
+* efi_signature_lookup_digest() handles case (b).
+*
+* There is a third type:
+* c. message digest of a certificate
+*(EFI_CERT_X509_SHAAxxx_GUID)
+* This type of signature is used only in revocation list
+* (dbx) and handled as part of efi_signatgure_verify().
+*/
/* try black-list first */
if (efi_signature_verify_one(regs, msg, dbx)) {
EFI_PRINT("Signature was rejected by \"dbx\"\n");
@@ -616,11 +635,22 @@ static bool efi_image_authenticate(void *efi, size_t 
efi_size)
goto err;
}

-   /* try white-list */
-   if (!efi_signature_verify_with_sigdb(regs, msg, db, dbx)) {
-   EFI_PRINT("Signature was not verified by \"db\"\n");
+   if (efi_signature_lookup_digest(regs, dbx)) {
+   EFI_PRINT("Image's digest was found in \"dbx\"\n");
goto err;
}
+
+   /* try white-list */
+   if (efi_signature_verify_with_sigdb(regs, msg, db, dbx))
+   continue;
+
+   debug("Signature was not verified by \"db\"\n");
+
+   if (efi_signature_lookup_digest(regs, db))
+   continue;
+
+   debug("Image's digest was not found in \"db\" or \"dbx\"\n");
+   goto err;
}
ret = true;

diff --git a/lib/efi_loader/efi_signature.c b/lib/efi_loader/efi_signature.c
index 52392d139a..fc0314e6d4 100644
--- a/lib/efi_loader/efi_signature.c
+++ b/lib/efi_loader/efi_signature.c
@@ -198,55 +198,43 @@ out:
 }

 /**
- * efi_signature_verify_with_list - verify a signature with signature list
- * @regs:  List of

[PATCH v4 09/12] test/py: efi_secboot: split "signed image" test case-1 into two cases

2020-07-11 Thread Heinrich Schuchardt
From: AKASHI Takahiro 

Split the existing test case-1 into case1 and a new case-2:
case-1 for non-SecureBoot mode; case-2 for SecureBoot mode.

In addition, one corner case is added to case-2; a image is signed
but a corresponding certificate is not yet installed in "db."

Signed-off-by: AKASHI Takahiro 
---
 test/py/tests/test_efi_secboot/test_signed.py | 66 +++
 1 file changed, 38 insertions(+), 28 deletions(-)

diff --git a/test/py/tests/test_efi_secboot/test_signed.py 
b/test/py/tests/test_efi_secboot/test_signed.py
index 4e6f129b7f..8ea45c8486 100644
--- a/test/py/tests/test_efi_secboot/test_signed.py
+++ b/test/py/tests/test_efi_secboot/test_signed.py
@@ -20,12 +20,12 @@ import pytest
 class TestEfiSignedImage(object):
 def test_efi_signed_image_auth1(self, u_boot_console, efi_boot_env):
 """
-Test Case 1 - authenticated by db
+Test Case 1 - Secure boot is not in force
 """
 u_boot_console.restart_uboot()
 disk_img = efi_boot_env
 with u_boot_console.log.section('Test Case 1a'):
-# Test Case 1a, run signed image if no db/dbx
+# Test Case 1a, run signed image if no PK
 output = u_boot_console.run_command_list([
 'host bind 0 %s' % disk_img,
 'efidebug boot add 1 HELLO1 host 0:1 /helloworld.efi.signed 
""',
@@ -34,48 +34,66 @@ class TestEfiSignedImage(object):
 assert 'Hello, world!' in ''.join(output)

 with u_boot_console.log.section('Test Case 1b'):
-# Test Case 1b, run unsigned image if no db/dbx
+# Test Case 1b, run unsigned image if no PK
 output = u_boot_console.run_command_list([
 'efidebug boot add 2 HELLO2 host 0:1 /helloworld.efi ""',
 'efidebug boot next 2',
 'bootefi bootmgr'])
 assert 'Hello, world!' in ''.join(output)

-with u_boot_console.log.section('Test Case 1c'):
-# Test Case 1c, not authenticated by db
+def test_efi_signed_image_auth2(self, u_boot_console, efi_boot_env):
+"""
+Test Case 2 - Secure boot is in force,
+  authenticated by db (TEST_db certificate in db)
+"""
+u_boot_console.restart_uboot()
+disk_img = efi_boot_env
+with u_boot_console.log.section('Test Case 2a'):
+# Test Case 2a, db is not yet installed
 output = u_boot_console.run_command_list([
-'fatload host 0:1 400 db.auth',
-'setenv -e -nv -bs -rt -at -i 400,$filesize db',
+'host bind 0 %s' % disk_img,
 'fatload host 0:1 400 KEK.auth',
 'setenv -e -nv -bs -rt -at -i 400,$filesize KEK',
 'fatload host 0:1 400 PK.auth',
 'setenv -e -nv -bs -rt -at -i 400,$filesize PK'])
 assert 'Failed to set EFI variable' not in ''.join(output)
 output = u_boot_console.run_command_list([
+'efidebug boot add 1 HELLO1 host 0:1 /helloworld.efi.signed 
""',
+'efidebug boot next 1',
+'efidebug test bootmgr'])
+assert('\'HELLO1\' failed' in ''.join(output))
+assert('efi_start_image() returned: 26' in ''.join(output))
+output = u_boot_console.run_command_list([
+'efidebug boot add 2 HELLO2 host 0:1 /helloworld.efi ""',
 'efidebug boot next 2',
-'bootefi bootmgr'])
+'efidebug test bootmgr'])
 assert '\'HELLO2\' failed' in ''.join(output)
+assert 'efi_start_image() returned: 26' in ''.join(output)
+
+with u_boot_console.log.section('Test Case 2b'):
+# Test Case 2b, authenticated by db
+output = u_boot_console.run_command_list([
+'fatload host 0:1 400 db.auth',
+'setenv -e -nv -bs -rt -at -i 400,$filesize db'])
+assert 'Failed to set EFI variable' not in ''.join(output)
 output = u_boot_console.run_command_list([
 'efidebug boot next 2',
 'efidebug test bootmgr'])
+assert '\'HELLO2\' failed' in ''.join(output)
 assert 'efi_start_image() returned: 26' in ''.join(output)
-assert 'Hello, world!' not in ''.join(output)
-
-with u_boot_console.log.section('Test Case 1d'):
-# Test Case 1d, authenticated by db
 output = u_boot_console.run_command_list([
 'efidebug boot next 1',
 'bootefi bootmgr'])
 assert 'Hello, world!' in ''.join(output)

-def test_efi_signed_image_auth2(self, u_boot_console, efi_boot_env):
+def test_efi_signed_image_auth3(self, u_boot_console, efi_boot_env):
 """
-Test Case 2 - rejected by dbx
+Test Case 3 - rejected by dbx (TEST_db certificate in dbx)
 """
  

[PATCH v4 11/12] test/py: efi_secboot: add a test for multiple signatures

2020-07-11 Thread Heinrich Schuchardt
From: AKASHI Takahiro 

In this test case, an image is signed multiple times with different
keys. If any of signatures contained is not verified, the whole
authentication check should fail.

Signed-off-by: AKASHI Takahiro 

Provide a defined time stamp for dbx_hash1.auth.
Signed-off-by: Heinrich Schuchardt 
---
v4:
call sign-efi-sig-list with -t
---
 test/py/tests/test_efi_secboot/conftest.py|  9 +++-
 test/py/tests/test_efi_secboot/test_signed.py | 51 +++
 2 files changed, 59 insertions(+), 1 deletion(-)

diff --git a/test/py/tests/test_efi_secboot/conftest.py 
b/test/py/tests/test_efi_secboot/conftest.py
index c3d56622a2..7bb2e1d765 100644
--- a/test/py/tests/test_efi_secboot/conftest.py
+++ b/test/py/tests/test_efi_secboot/conftest.py
@@ -116,6 +116,10 @@ def efi_boot_env(request, u_boot_config):
 check_call('cd %s; %scert-to-efi-hash-list -g %s -t 0 -s 256 db.crt 
dbx_hash.crl; %ssign-efi-sig-list -t "2020-04-05" -c KEK.crt -k KEK.key dbx 
dbx_hash.crl dbx_hash.auth'
% (mnt_point, EFITOOLS_PATH, GUID, EFITOOLS_PATH),
shell=True)
+## dbx_hash1 (digest of TEST_db1 certificate)
+check_call('cd %s; %scert-to-efi-hash-list -g %s -t 0 -s 256 db1.crt 
dbx_hash1.crl; %ssign-efi-sig-list -t "2020-04-05" -c KEK.crt -k KEK.key dbx 
dbx_hash1.crl dbx_hash1.auth'
+   % (mnt_point, EFITOOLS_PATH, GUID, EFITOOLS_PATH),
+   shell=True)

 # Copy image
 check_call('cp %s %s' % (HELLO_PATH, mnt_point), shell=True)
@@ -123,7 +127,10 @@ def efi_boot_env(request, u_boot_config):
 # Sign image
 check_call('cd %s; sbsign --key db.key --cert db.crt helloworld.efi'
% mnt_point, shell=True)
-# Digest image
+## Sign already-signed image with another key
+check_call('cd %s; sbsign --key db1.key --cert db1.crt --output 
helloworld.efi.signed_2sigs helloworld.efi.signed'
+   % mnt_point, shell=True)
+## Digest image
 check_call('cd %s; %shash-to-efi-sig-list helloworld.efi 
db_hello.hash; %ssign-efi-sig-list -t "2020-04-07" -c KEK.crt -k KEK.key db 
db_hello.hash db_hello.auth'
% (mnt_point, EFITOOLS_PATH, EFITOOLS_PATH),
shell=True)
diff --git a/test/py/tests/test_efi_secboot/test_signed.py 
b/test/py/tests/test_efi_secboot/test_signed.py
index 6dabecb669..1a31a57e12 100644
--- a/test/py/tests/test_efi_secboot/test_signed.py
+++ b/test/py/tests/test_efi_secboot/test_signed.py
@@ -147,3 +147,54 @@ class TestEfiSignedImage(object):
 'efidebug test bootmgr'])
 assert '\'HELLO\' failed' in ''.join(output)
 assert 'efi_start_image() returned: 26' in ''.join(output)
+
+def test_efi_signed_image_auth5(self, u_boot_console, efi_boot_env):
+"""
+Test Case 5 - multiple signatures
+one signed with TEST_db, and
+one signed with TEST_db1
+"""
+u_boot_console.restart_uboot()
+disk_img = efi_boot_env
+with u_boot_console.log.section('Test Case 5a'):
+# Test Case 5a, rejected if any of signatures is not verified
+output = u_boot_console.run_command_list([
+'host bind 0 %s' % disk_img,
+'fatload host 0:1 400 db.auth',
+'setenv -e -nv -bs -rt -at -i 400,$filesize db',
+'fatload host 0:1 400 KEK.auth',
+'setenv -e -nv -bs -rt -at -i 400,$filesize KEK',
+'fatload host 0:1 400 PK.auth',
+'setenv -e -nv -bs -rt -at -i 400,$filesize PK'])
+assert 'Failed to set EFI variable' not in ''.join(output)
+output = u_boot_console.run_command_list([
+'efidebug boot add 1 HELLO host 0:1 
/helloworld.efi.signed_2sigs ""',
+'efidebug boot next 1',
+'efidebug test bootmgr'])
+assert '\'HELLO\' failed' in ''.join(output)
+assert 'efi_start_image() returned: 26' in ''.join(output)
+
+with u_boot_console.log.section('Test Case 5b'):
+# Test Case 5b, authenticated if both signatures are verified
+output = u_boot_console.run_command_list([
+'fatload host 0:1 400 db1.auth',
+'setenv -e -nv -bs -rt -at -a -i 400,$filesize db'])
+assert 'Failed to set EFI variable' not in ''.join(output)
+output = u_boot_console.run_command_list([
+'efidebug boot add 1 HELLO host 0:1 
/helloworld.efi.signed_2sigs ""',
+'efidebug boot next 1',
+'bootefi bootmgr'])
+assert 'Hello, world!' in ''.join(output)
+
+with u_boot_console.log.section('Test Case 5c'):
+# Test Case 5c, rejected if any of signatures is revoked
+output = u_boot_console.run_command_li

[PATCH v4 07/12] test/py: efi_secboot: apply autopep8

2020-07-11 Thread Heinrich Schuchardt
From: AKASHI Takahiro 

Python's autopep8 can automatically correct some of warnings from pylint
and rewrite the code in a pretty print format. So just do it.

Suggested-by: Heinrich Schuchardt 
Signed-off-by: AKASHI Takahiro 
---
 test/py/tests/test_efi_secboot/conftest.py| 74 ++-
 test/py/tests/test_efi_secboot/defs.py| 14 ++--
 .../py/tests/test_efi_secboot/test_authvar.py |  1 +
 test/py/tests/test_efi_secboot/test_signed.py |  1 +
 .../tests/test_efi_secboot/test_unsigned.py   | 37 +-
 5 files changed, 67 insertions(+), 60 deletions(-)

diff --git a/test/py/tests/test_efi_secboot/conftest.py 
b/test/py/tests/test_efi_secboot/conftest.py
index ac5a780fdb..82bc8886c4 100644
--- a/test/py/tests/test_efi_secboot/conftest.py
+++ b/test/py/tests/test_efi_secboot/conftest.py
@@ -10,6 +10,8 @@ from subprocess import call, check_call, check_output, 
CalledProcessError
 from defs import *

 # from test/py/conftest.py
+
+
 def tool_is_in_path(tool):
 for path in os.environ["PATH"].split(os.pathsep):
 fn = os.path.join(path, tool)
@@ -20,13 +22,15 @@ def tool_is_in_path(tool):
 #
 # Fixture for UEFI secure boot test
 #
+
+
 @pytest.fixture(scope='session')
 def efi_boot_env(request, u_boot_config):
 """Set up a file system to be used in UEFI secure boot test.

 Args:
 request: Pytest request object.
-   u_boot_config: U-boot configuration.
+u_boot_config: U-boot configuration.

 Return:
 A path to disk image to be used for testing
@@ -48,20 +52,20 @@ def efi_boot_env(request, u_boot_config):

 # create a disk/partition
 check_call('dd if=/dev/zero of=%s bs=1MiB count=%d'
-% (image_path, image_size), shell=True)
+   % (image_path, image_size), shell=True)
 check_call('sgdisk %s -n 1:0:+%dMiB'
-% (image_path, part_size), shell=True)
+   % (image_path, part_size), shell=True)
 # create a file system
 check_call('dd if=/dev/zero of=%s.tmp bs=1MiB count=%d'
-% (image_path, part_size), shell=True)
+   % (image_path, part_size), shell=True)
 check_call('mkfs -t %s %s.tmp' % (fs_type, image_path), shell=True)
 check_call('dd if=%s.tmp of=%s bs=1MiB seek=1 count=%d conv=notrunc'
-% (image_path, image_path, 1), shell=True)
+   % (image_path, image_path, 1), shell=True)
 check_call('rm %s.tmp' % image_path, shell=True)
 loop_dev = check_output('sudo losetup -o 1MiB --sizelimit %dMiB --show 
-f %s | tr -d "\n"'
 % (part_size, image_path), shell=True).decode()
 check_output('sudo mount -t %s -o umask=000 %s %s'
-% (fs_type, loop_dev, mnt_point), shell=True)
+ % (fs_type, loop_dev, mnt_point), shell=True)

 # suffix
 # *.key: RSA private key in PEM
@@ -73,53 +77,53 @@ def efi_boot_env(request, u_boot_config):
 # *.efi.signed: signed UEFI image

 # Create signature database
-## PK
+# PK
 check_call('cd %s; openssl req -x509 -sha256 -newkey rsa:2048 -subj 
/CN=TEST_PK/ -keyout PK.key -out PK.crt -nodes -days 365'
-% mnt_point, shell=True)
+   % mnt_point, shell=True)
 check_call('cd %s; %scert-to-efi-sig-list -g %s PK.crt PK.esl; 
%ssign-efi-sig-list -t "2020-04-01" -c PK.crt -k PK.key PK PK.esl PK.auth'
-% (mnt_point, EFITOOLS_PATH, GUID, EFITOOLS_PATH),
-shell=True)
-## PK_null for deletion
+   % (mnt_point, EFITOOLS_PATH, GUID, EFITOOLS_PATH),
+   shell=True)
+# PK_null for deletion
 check_call('cd %s; touch PK_null.esl; %ssign-efi-sig-list -t 
"2020-04-02" -c PK.crt -k PK.key PK PK_null.esl PK_null.auth'
-% (mnt_point, EFITOOLS_PATH), shell=True)
-## KEK
+   % (mnt_point, EFITOOLS_PATH), shell=True)
+# KEK
 check_call('cd %s; openssl req -x509 -sha256 -newkey rsa:2048 -subj 
/CN=TEST_KEK/ -keyout KEK.key -out KEK.crt -nodes -days 365'
-% mnt_point, shell=True)
+   % mnt_point, shell=True)
 check_call('cd %s; %scert-to-efi-sig-list -g %s KEK.crt KEK.esl; 
%ssign-efi-sig-list -t "2020-04-03" -c PK.crt -k PK.key KEK KEK.esl KEK.auth'
-% (mnt_point, EFITOOLS_PATH, GUID, EFITOOLS_PATH),
-shell=True)
-## db
+   % (mnt_point, EFITOOLS_PATH, GUID, EFITOOLS_PATH),
+   shell=True)
+# db
 check_call('cd %s; openssl req -x509 -sha256 -newkey rsa:2048 -subj 
/CN=TEST_db/ -keyout db.key -out db.crt -nodes -days 365'
-% mnt_point, shell=True)
+ 

[PATCH v4 04/12] efi_loader: signature: make efi_hash_regions more generic

2020-07-11 Thread Heinrich Schuchardt
From: AKASHI Takahiro 

There are a couple of occurrences of hash calculations in which a new
efi_hash_regions will be commonly used.

Signed-off-by: AKASHI Takahiro 
---
 lib/efi_loader/efi_signature.c | 46 +-
 1 file changed, 17 insertions(+), 29 deletions(-)

diff --git a/lib/efi_loader/efi_signature.c b/lib/efi_loader/efi_signature.c
index cd2df46264..b14d104094 100644
--- a/lib/efi_loader/efi_signature.c
+++ b/lib/efi_loader/efi_signature.c
@@ -28,7 +28,8 @@ const efi_guid_t efi_guid_cert_type_pkcs7 = 
EFI_CERT_TYPE_PKCS7_GUID;

 /**
  * efi_hash_regions - calculate a hash value
- * @regs:  List of regions
+ * @regs:  Array of regions
+ * @count: Number of regions
  * @hash:  Pointer to a pointer to buffer holding a hash value
  * @size:  Size of buffer to be returned
  *
@@ -36,18 +37,20 @@ const efi_guid_t efi_guid_cert_type_pkcs7 = 
EFI_CERT_TYPE_PKCS7_GUID;
  *
  * Return: true on success, false on error
  */
-static bool efi_hash_regions(struct efi_image_regions *regs, void **hash,
-size_t *size)
+static bool efi_hash_regions(struct image_region *regs, int count,
+void **hash, size_t *size)
 {
-   *size = 0;
-   *hash = calloc(1, SHA256_SUM_LEN);
if (!*hash) {
-   EFI_PRINT("Out of memory\n");
-   return false;
+   *hash = calloc(1, SHA256_SUM_LEN);
+   if (!*hash) {
+   EFI_PRINT("Out of memory\n");
+   return false;
+   }
}
-   *size = SHA256_SUM_LEN;
+   if (size)
+   *size = SHA256_SUM_LEN;

-   hash_calculate("sha256", regs->reg, regs->num, *hash);
+   hash_calculate("sha256", regs, count, *hash);
 #ifdef DEBUG
EFI_PRINT("hash calculated:\n");
print_hex_dump("", DUMP_PREFIX_OFFSET, 16, 1,
@@ -72,26 +75,10 @@ static bool efi_hash_msg_content(struct pkcs7_message *msg, 
void **hash,
 {
struct image_region regtmp;

-   *size = 0;
-   *hash = calloc(1, SHA256_SUM_LEN);
-   if (!*hash) {
-   EFI_PRINT("Out of memory\n");
-   free(msg);
-   return false;
-   }
-   *size = SHA256_SUM_LEN;
-
regtmp.data = msg->data;
regtmp.size = msg->data_len;

-   hash_calculate("sha256", ®tmp, 1, *hash);
-#ifdef DEBUG
-   EFI_PRINT("hash calculated based on contentInfo:\n");
-   print_hex_dump("", DUMP_PREFIX_OFFSET, 16, 1,
-  *hash, SHA256_SUM_LEN, false);
-#endif
-
-   return true;
+   return efi_hash_regions(®tmp, 1, hash, size);
 }

 /**
@@ -169,9 +156,10 @@ static bool efi_signature_verify(struct efi_image_regions 
*regs,
   false);
 #endif
/* against contentInfo first */
+   hash = NULL;
if ((msg->data && efi_hash_msg_content(msg, &hash, &size)) ||
/* for signed image */
-   efi_hash_regions(regs, &hash, &size)) {
+   efi_hash_regions(regs->reg, regs->num, &hash, &size)) {
/* for authenticated variable */
if (ps_info->msgdigest_len != size ||
memcmp(hash, ps_info->msgdigest, size)) {
@@ -239,7 +227,7 @@ bool efi_signature_verify_with_list(struct 
efi_image_regions *regs,
  regs, signed_info, siglist, valid_cert);

if (!signed_info) {
-   void *hash;
+   void *hash = NULL;
size_t size;

EFI_PRINT("%s: unsigned image\n", __func__);
@@ -253,7 +241,7 @@ bool efi_signature_verify_with_list(struct 
efi_image_regions *regs,
goto out;
}

-   if (!efi_hash_regions(regs, &hash, &size)) {
+   if (!efi_hash_regions(regs->reg, regs->num, &hash, &size)) {
EFI_PRINT("Digesting unsigned image failed\n");
goto out;
}
--
2.27.0



[PATCH v4 10/12] test/py: efi_secboot: add a test against certificate revocation

2020-07-11 Thread Heinrich Schuchardt
From: AKASHI Takahiro 

Revocation database (dbx) may have not only certificates, but also
message digests of certificates with revocation time
(EFI_CERT_X509_SHA256_GUILD).

In this test case, if the database has such a digest and if the value
matches to a certificate that created a given image's signature,
authentication should fail.

Signed-off-by: AKASHI Takahiro 

Set defined time stamp for dbx_hash.auth.
Signed-off-by: Heinrich Schuchardt 
---
v4:
call sign-efi-sig-list with -t
---
 test/py/tests/test_efi_secboot/conftest.py|  6 -
 test/py/tests/test_efi_secboot/test_signed.py | 26 +++
 2 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/test/py/tests/test_efi_secboot/conftest.py 
b/test/py/tests/test_efi_secboot/conftest.py
index c0ee8be9f7..c3d56622a2 100644
--- a/test/py/tests/test_efi_secboot/conftest.py
+++ b/test/py/tests/test_efi_secboot/conftest.py
@@ -106,12 +106,16 @@ def efi_boot_env(request, u_boot_config):
 # db1-update
 check_call('cd %s; %ssign-efi-sig-list -t "2020-04-06" -a -c KEK.crt 
-k KEK.key db db1.esl db1-update.auth'
% (mnt_point, EFITOOLS_PATH), shell=True)
-# dbx
+## dbx (TEST_dbx certificate)
 check_call('cd %s; openssl req -x509 -sha256 -newkey rsa:2048 -subj 
/CN=TEST_dbx/ -keyout dbx.key -out dbx.crt -nodes -days 365'
% mnt_point, shell=True)
 check_call('cd %s; %scert-to-efi-sig-list -g %s dbx.crt dbx.esl; 
%ssign-efi-sig-list -t "2020-04-05" -c KEK.crt -k KEK.key dbx dbx.esl dbx.auth'
% (mnt_point, EFITOOLS_PATH, GUID, EFITOOLS_PATH),
shell=True)
+## dbx_hash (digest of TEST_db certificate)
+check_call('cd %s; %scert-to-efi-hash-list -g %s -t 0 -s 256 db.crt 
dbx_hash.crl; %ssign-efi-sig-list -t "2020-04-05" -c KEK.crt -k KEK.key dbx 
dbx_hash.crl dbx_hash.auth'
+   % (mnt_point, EFITOOLS_PATH, GUID, EFITOOLS_PATH),
+   shell=True)

 # Copy image
 check_call('cp %s %s' % (HELLO_PATH, mnt_point), shell=True)
diff --git a/test/py/tests/test_efi_secboot/test_signed.py 
b/test/py/tests/test_efi_secboot/test_signed.py
index 8ea45c8486..6dabecb669 100644
--- a/test/py/tests/test_efi_secboot/test_signed.py
+++ b/test/py/tests/test_efi_secboot/test_signed.py
@@ -121,3 +121,29 @@ class TestEfiSignedImage(object):
 'efidebug test bootmgr'])
 assert '\'HELLO\' failed' in ''.join(output)
 assert 'efi_start_image() returned: 26' in ''.join(output)
+
+def test_efi_signed_image_auth4(self, u_boot_console, efi_boot_env):
+"""
+Test Case 4 - revoked by dbx (digest of TEST_db certificate in dbx)
+"""
+u_boot_console.restart_uboot()
+disk_img = efi_boot_env
+with u_boot_console.log.section('Test Case 4'):
+# Test Case 4, rejected by dbx
+output = u_boot_console.run_command_list([
+'host bind 0 %s' % disk_img,
+'fatload host 0:1 400 dbx_hash.auth',
+'setenv -e -nv -bs -rt -at -i 400,$filesize dbx',
+'fatload host 0:1 400 db.auth',
+'setenv -e -nv -bs -rt -at -i 400,$filesize db',
+'fatload host 0:1 400 KEK.auth',
+'setenv -e -nv -bs -rt -at -i 400,$filesize KEK',
+'fatload host 0:1 400 PK.auth',
+'setenv -e -nv -bs -rt -at -i 400,$filesize PK'])
+assert 'Failed to set EFI variable' not in ''.join(output)
+output = u_boot_console.run_command_list([
+'efidebug boot add 1 HELLO host 0:1 /helloworld.efi.signed ""',
+'efidebug boot next 1',
+'efidebug test bootmgr'])
+assert '\'HELLO\' failed' in ''.join(output)
+assert 'efi_start_image() returned: 26' in ''.join(output)
--
2.27.0



[PATCH v4 12/12] test/py: efi_secboot: add a test for verifying with digest of signed image

2020-07-11 Thread Heinrich Schuchardt
From: AKASHI Takahiro 

Signature database (db or dbx) may have not only certificates that contain
a public key for RSA decryption, but also digests of signed images.

In this test case, if database has an image's digest (EFI_CERT_SHA256_GUID)
and if the value matches to a hash value calculated from image's binary,
authentication should pass in case of db, and fail in case of dbx.

Signed-off-by: AKASHI Takahiro 

Use defined time stamps for sign-efi-sig-list.
Signed-off-by: Heinrich Schuchardt 
---
v4:
call sign-efi-sig-list with -t
---
 test/py/tests/test_efi_secboot/conftest.py| 10 
 test/py/tests/test_efi_secboot/test_signed.py | 49 +++
 2 files changed, 59 insertions(+)

diff --git a/test/py/tests/test_efi_secboot/conftest.py 
b/test/py/tests/test_efi_secboot/conftest.py
index 7bb2e1d765..71ef723e59 100644
--- a/test/py/tests/test_efi_secboot/conftest.py
+++ b/test/py/tests/test_efi_secboot/conftest.py
@@ -120,6 +120,10 @@ def efi_boot_env(request, u_boot_config):
 check_call('cd %s; %scert-to-efi-hash-list -g %s -t 0 -s 256 db1.crt 
dbx_hash1.crl; %ssign-efi-sig-list -t "2020-04-05" -c KEK.crt -k KEK.key dbx 
dbx_hash1.crl dbx_hash1.auth'
% (mnt_point, EFITOOLS_PATH, GUID, EFITOOLS_PATH),
shell=True)
+## dbx_db (with TEST_db certificate)
+check_call('cd %s; %ssign-efi-sig-list -t "2020-04-05" -c KEK.crt -k 
KEK.key dbx db.esl dbx_db.auth'
+   % (mnt_point, EFITOOLS_PATH),
+   shell=True)

 # Copy image
 check_call('cp %s %s' % (HELLO_PATH, mnt_point), shell=True)
@@ -134,6 +138,12 @@ def efi_boot_env(request, u_boot_config):
 check_call('cd %s; %shash-to-efi-sig-list helloworld.efi 
db_hello.hash; %ssign-efi-sig-list -t "2020-04-07" -c KEK.crt -k KEK.key db 
db_hello.hash db_hello.auth'
% (mnt_point, EFITOOLS_PATH, EFITOOLS_PATH),
shell=True)
+check_call('cd %s; %shash-to-efi-sig-list helloworld.efi.signed 
db_hello_signed.hash; %ssign-efi-sig-list -t "2020-04-03" -c KEK.crt -k KEK.key 
db db_hello_signed.hash db_hello_signed.auth'
+   % (mnt_point, EFITOOLS_PATH, EFITOOLS_PATH),
+   shell=True)
+check_call('cd %s; %ssign-efi-sig-list -t "2020-04-07" -c KEK.crt -k 
KEK.key dbx db_hello_signed.hash dbx_hello_signed.auth'
+   % (mnt_point, EFITOOLS_PATH),
+   shell=True)

 check_call('sudo umount %s' % loop_dev, shell=True)
 check_call('sudo losetup -d %s' % loop_dev, shell=True)
diff --git a/test/py/tests/test_efi_secboot/test_signed.py 
b/test/py/tests/test_efi_secboot/test_signed.py
index 1a31a57e12..7531bbac6a 100644
--- a/test/py/tests/test_efi_secboot/test_signed.py
+++ b/test/py/tests/test_efi_secboot/test_signed.py
@@ -198,3 +198,52 @@ class TestEfiSignedImage(object):
 'efidebug test bootmgr'])
 assert '\'HELLO\' failed' in ''.join(output)
 assert 'efi_start_image() returned: 26' in ''.join(output)
+
+def test_efi_signed_image_auth6(self, u_boot_console, efi_boot_env):
+"""
+Test Case 6 - using digest of signed image in database
+"""
+u_boot_console.restart_uboot()
+disk_img = efi_boot_env
+with u_boot_console.log.section('Test Case 6a'):
+# Test Case 6a, verified by image's digest in db
+output = u_boot_console.run_command_list([
+'host bind 0 %s' % disk_img,
+'fatload host 0:1 400 db_hello_signed.auth',
+'setenv -e -nv -bs -rt -at -i 400,$filesize db',
+'fatload host 0:1 400 KEK.auth',
+'setenv -e -nv -bs -rt -at -i 400,$filesize KEK',
+'fatload host 0:1 400 PK.auth',
+'setenv -e -nv -bs -rt -at -i 400,$filesize PK'])
+assert 'Failed to set EFI variable' not in ''.join(output)
+output = u_boot_console.run_command_list([
+'efidebug boot add 1 HELLO host 0:1 /helloworld.efi.signed ""',
+'efidebug boot next 1',
+'bootefi bootmgr'])
+assert 'Hello, world!' in ''.join(output)
+
+with u_boot_console.log.section('Test Case 6b'):
+# Test Case 6b, rejected by TEST_db certificate in dbx
+output = u_boot_console.run_command_list([
+'fatload host 0:1 400 dbx_db.auth',
+'setenv -e -nv -bs -rt -at -i 400,$filesize dbx'])
+assert 'Failed to set EFI variable' not in ''.join(output)
+output = u_boot_console.run_command_list([
+'efidebug boot next 1',
+'efidebug test bootmgr'])
+assert '\'HELLO\' failed' in ''.join(output)
+assert 'efi_start_image() returned: 26' in ''.join(output)
+
+with u_boot_console.log.section('Test Case 6c'):
+  

[PATCH v4 08/12] test/py: efi_secboot: more fixes against pylint

2020-07-11 Thread Heinrich Schuchardt
From: AKASHI Takahiro 

More fixes against pylint warnings that autopep8 didn't handle
in the previous commit.

Signed-off-by: AKASHI Takahiro 
---
 test/py/tests/test_efi_secboot/conftest.py| 11 +--
 .../py/tests/test_efi_secboot/test_authvar.py | 91 +--
 test/py/tests/test_efi_secboot/test_signed.py | 31 +++
 .../tests/test_efi_secboot/test_unsigned.py   | 29 +++---
 4 files changed, 79 insertions(+), 83 deletions(-)

diff --git a/test/py/tests/test_efi_secboot/conftest.py 
b/test/py/tests/test_efi_secboot/conftest.py
index 82bc8886c4..c0ee8be9f7 100644
--- a/test/py/tests/test_efi_secboot/conftest.py
+++ b/test/py/tests/test_efi_secboot/conftest.py
@@ -4,9 +4,8 @@

 import os
 import os.path
-import pytest
-import re
 from subprocess import call, check_call, check_output, CalledProcessError
+import pytest
 from defs import *

 # from test/py/conftest.py
@@ -14,8 +13,8 @@ from defs import *

 def tool_is_in_path(tool):
 for path in os.environ["PATH"].split(os.pathsep):
-fn = os.path.join(path, tool)
-if os.path.isfile(fn) and os.access(fn, os.X_OK):
+full_path = os.path.join(path, tool)
+if os.path.isfile(full_path) and os.access(full_path, os.X_OK):
 return True
 return False

@@ -128,8 +127,8 @@ def efi_boot_env(request, u_boot_config):
 check_call('sudo umount %s' % loop_dev, shell=True)
 check_call('sudo losetup -d %s' % loop_dev, shell=True)

-except CalledProcessError as e:
-pytest.skip('Setup failed: %s' % e.cmd)
+except CalledProcessError as exception:
+pytest.skip('Setup failed: %s' % exception.cmd)
 return
 else:
 yield image_path
diff --git a/test/py/tests/test_efi_secboot/test_authvar.py 
b/test/py/tests/test_efi_secboot/test_authvar.py
index 359adba4b4..d0c6b9035b 100644
--- a/test/py/tests/test_efi_secboot/test_authvar.py
+++ b/test/py/tests/test_efi_secboot/test_authvar.py
@@ -9,7 +9,6 @@ This test verifies variable authentication
 """

 import pytest
-from defs import *


 @pytest.mark.boardspec('sandbox')
@@ -29,18 +28,18 @@ class TestEfiAuthVar(object):
 output = u_boot_console.run_command_list([
 'host bind 0 %s' % disk_img,
 'printenv -e SecureBoot'])
-assert(': 00' in ''.join(output))
+assert ': 00' in ''.join(output)

 output = u_boot_console.run_command(
 'printenv -e SetupMode')
-assert(': 01' in output)
+assert ': 01' in output

 with u_boot_console.log.section('Test Case 1b'):
 # Test Case 1b, PK without AUTHENTICATED_WRITE_ACCESS
 output = u_boot_console.run_command_list([
 'fatload host 0:1 400 PK.auth',
 'setenv -e -nv -bs -rt -i 400,$filesize PK'])
-assert('Failed to set EFI variable' in ''.join(output))
+assert 'Failed to set EFI variable' in ''.join(output)

 with u_boot_console.log.section('Test Case 1c'):
 # Test Case 1c, install PK
@@ -48,79 +47,79 @@ class TestEfiAuthVar(object):
 'fatload host 0:1 400 PK.auth',
 'setenv -e -nv -bs -rt -at -i 400,$filesize PK',
 'printenv -e -n PK'])
-assert('PK:' in ''.join(output))
+assert 'PK:' in ''.join(output)

 output = u_boot_console.run_command(
 'printenv -e SecureBoot')
-assert(': 01' in output)
+assert ': 01' in output
 output = u_boot_console.run_command(
 'printenv -e SetupMode')
-assert(': 00' in output)
+assert ': 00' in output

 with u_boot_console.log.section('Test Case 1d'):
 # Test Case 1d, db/dbx without KEK
 output = u_boot_console.run_command_list([
 'fatload host 0:1 400 db.auth',
 'setenv -e -nv -bs -rt -at -i 400,$filesize db'])
-assert('Failed to set EFI variable' in ''.join(output))
+assert 'Failed to set EFI variable' in ''.join(output)

 output = u_boot_console.run_command_list([
 'fatload host 0:1 400 db.auth',
 'setenv -e -nv -bs -rt -at -i 400,$filesize dbx'])
-assert('Failed to set EFI variable' in ''.join(output))
+assert 'Failed to set EFI variable' in ''.join(output)

 with u_boot_console.log.section('Test Case 1e'):
 # Test Case 1e, install KEK
 output = u_boot_console.run_command_list([
 'fatload host 0:1 400 KEK.auth',
 'setenv -e -nv -bs -rt -i 400,$filesize KEK'])
-assert('Failed to set EFI variable' in ''.join(output))
+assert 'Failed to set EFI variable' in ''.join(output)

 output = u_boot_console.run_command

Re: [PATCH 2/2] mtd: make spinand driver usable without CONFIG_DM

2020-07-11 Thread Jagan Teki
On Mon, Jun 22, 2020 at 9:25 PM Mikhail Kshevetskiy
 wrote:
>
> From: Mikhail Kshevetskiy 
>
> Here is an example of spinand driver initialization without CONFIG_DM
> enabled:
>
> void board_nand_init(void)
> {
> static struct spinand_devicespinand;
> static struct mtd_info  mtd;
> static struct spi_slave *slave;
> int ret;
>
> memset(&spinand, 0, sizeof(spinand));
> memset(&mtd, 0, sizeof(mtd));
>
> slave = spi_setup_slave(BUS, CS, MAX_HZ, MODE);
> if (!slave) {
> printf("SPI-NAND: Failed to set up SPI slave\n");
> return;
> }
>
> slave->mode |= (SPI_TX_BYTE | SPI_RX_SLOW);
> slave->max_read_size = SPI_MAX_READ_SIZE;
> slave->max_write_size = SPI_MAX_WRITE_SIZE;
>
> ret = spinand_probe_no_dm(&spinand, slave, &mtd);
> if (!ret)
> nand_register(0, &mtd);
> }
>
> Using of dual and quad wire transfer modes requires:
> * dual/quad speed capable hardware (both controller and flash)
> * physical presence of 4 data wires (quad mode only)
> * spi controller driver MUST supports slave->mem_ops.exec_op() operations
>   (spi_xfer() interface will suits for single speed data transfer mode
>   only)
>
> Signed-off-by: Mikhail Kshevetskiy 
> ---

Now it's time for dm only code, better not come up with nondm anymore
as possible, please.

Jagan.


Re: [PATCH 4/4] common: Add LX TestBox checks

2020-07-11 Thread Jagan Teki
On Fri, May 29, 2020 at 11:08 PM Benedikt Spranger
 wrote:
>
> The TestBox board is an open hardware enhancement for the Lamobo R1 router
> board. The Testbox board is used in the CI-RT project to manage devices
> under test (https://ci-rt.linutronix.de).
>
> The hardware project is located at https://github.com/ci-rt/testbox-shield
> Check if the hardware is present and use the appropriate device tree file.
>
> Signed-off-by: Benedikt Spranger 
> Reviewed-by: Kurt Kanzenbach 
> ---
>  arch/arm/mach-sunxi/Kconfig | 15 
>  board/sunxi/board.c | 47 +
>  configs/Lamobo_R1_defconfig |  1 +
>  3 files changed, 63 insertions(+)
>
> diff --git a/arch/arm/mach-sunxi/Kconfig b/arch/arm/mach-sunxi/Kconfig
> index be0822bfb7..970fa0fae2 100644
> --- a/arch/arm/mach-sunxi/Kconfig
> +++ b/arch/arm/mach-sunxi/Kconfig
> @@ -1010,4 +1010,19 @@ config PINE64_DT_SELECTION
>   option, the device tree selection code specific to Pine64 which
>   utilizes the DRAM size will be enabled.
>
> +config LXTESTBOX
> +   bool "Support for LX TestBox"
> +   depends on MACH_SUN7I
> +   select I2C2_ENABLE
> +   select DM_I2C
> +   help
> + The LX TestBox board is an open hardware enhancement for the
> + Lamobo R1 router board. The TestBox board is used in the CI-RT
> + project to manage devices under test (https://ci-rt.linutronix.de).
> +
> +config LXTESTBOX_DEVICE_TREE
> +   string "LX TestBox default device tree"
> +   default "sun7i-a20-linutronix-testbox-v2.dtb"
> +   help
> + LX TestBox default device tree name.
>  endif
> diff --git a/board/sunxi/board.c b/board/sunxi/board.c
> index f32e8f582f..4645798bcd 100644
> --- a/board/sunxi/board.c
> +++ b/board/sunxi/board.c
> @@ -43,6 +43,17 @@
>  #include 
>  #include 
>  #include 
> +#include 
> +#include 
> +
> +struct lxtestbox_eeprom {
> +   u32 magic;
> +   u8 version;
> +   char serial[7];
> +   u32 crc;
> +} __packed;
> +
> +#define LXTESTBOX_I2C_EEPROM_MAGIC 0x6274584c
>
>  #if defined CONFIG_VIDEO_LCD_PANEL_I2C && !(defined CONFIG_SPL_BUILD)
>  /* So that we can use pin names in Kconfig and sunxi_name_to_gpio() */
> @@ -839,6 +850,42 @@ static void setup_environment(const void *fdt)
> env_set("serial#", serial_string);
> }
> }
> +
> +#ifdef CONFIG_LXTESTBOX
> +   debug("Check for LX TestBox...");
> +   if (!strcmp(env_get("fdtfile"), CONFIG_DEFAULT_DEVICE_TREE ".dtb")) {
> +   struct lxtestbox_eeprom moep;
> +   struct udevice *bus, *dev;
> +   int ret;
> +
> +   ret = uclass_get_device_by_name(UCLASS_I2C,
> +   "i2c@1c2b400", &bus);
> +   if (ret) {
> +   printf("Cannot get I2C bus: %i\n", ret);
> +   return;
> +   }
> +
> +   ret = i2c_get_chip(bus, 0x50, 1, &dev);
> +   if (ret) {
> +   printf("Cannot get I2C chip: %i\n", ret);
> +   return;
> +   }
> +
> +   ret = dm_i2c_read(dev, 0, (u8 *)&moep, sizeof(moep));
> +   if (ret) {
> +   printf("cannot read EEPROM: %i\n", ret);
> +   return;
> +   }
> +
> +   if (moep.magic != LXTESTBOX_I2C_EEPROM_MAGIC) {
> +   printf("bad EEPROM magic number (%08x, should be 
> %08x)\n",
> +  moep.magic, LXTESTBOX_I2C_EEPROM_MAGIC);
> +   return;
> +   }
> +   debug("found.\n");
> +   env_set("fdtfile", CONFIG_LXTESTBOX_DEVICE_TREE);
> +   }

We have a board driver to do board-specific functionalities, try to
add that and get the board during _r instead of adding ifdef code in
the common board.


Re: [PATCH] sunxi: Add Drejo DS167 board

2020-07-11 Thread Jagan Teki
On Sun, May 31, 2020 at 3:25 PM  wrote:
>
> From: Sertac TULLUK 
>
> drejo ds167 is an allwinner a20 based custom board
> with twin LVDS LCD and TouchScreen, 7inch and 10.1inch.
> The board has 1G RAM, 8G eMMC, AXP209 PMIC, 10/100 EMAC
> SATA, 2x USB2.0, 1x USB OTG, 3x dry-contact input
> 3x relay output, builtin KNX transceiver, HDMI,
> Audio Amplifier, external UART3, SPI0, etc.
>
> Signed-off-by: Sertac TULLUK 
> ---
>  arch/arm/dts/Makefile   |   2 +
>  arch/arm/dts/sun7i-a20-drejo-ds167-emmc.dts |  69 +
>  arch/arm/dts/sun7i-a20-drejo-ds167.dts  | 305 

Hope these DST files are already in Mainline (or list). If yes, could
you add respective kernel commit id in the commit message?


Re: [PATCH] power: axp209: Limit inrush current for A20-OLinuXino_MICRO

2020-07-11 Thread Jagan Teki
On Tue, Jun 16, 2020 at 9:46 PM Cédric Félizard  wrote:
>
> This commit enables the work done in commit ef52605e for the
> A20-OLinuXino_MICRO{,-eMMC} boards. It was previously used only for the
> A20-OLinuXino-Lime2{,-eMMC} boards but is also needed for the MICRO
> boards. Without this, the board consistently hangs upon reboot. Note
> that a cold boot works fine though.
>
> I don't have -eMMC board variant to double check but the quirk is most
> likely present as well so I patched
> configs/A20-OLinuXino_MICRO-eMMC_defconfig too.
>
> The issue occurs with revision G of the board and most likely previous
> revisions as well since the faulty capacitance on LDO3's output hasn't
> been modified since the initial release of the board.
>
> Many thanks to Marex in #u-boot @ irc.freenode.net for helping me
> debugging this.

Signed-by-off missing? please resend.


Re: microSD Breakout Port

2020-07-11 Thread Jagan Teki
On Fri, Jun 26, 2020 at 5:28 AM Faruk Kılavuz  wrote:
>
> Hello
>
> This is my first mail. I tried running uart-0 with microsd breakout method. I 
> have added the following codes to open the F port.
>
> diff --git a/arch/arm/include/asm/arch-sunxi/gpio.h 
> b/arch/arm/include/asm/arch-sunxi/gpio.h
> index 40a3f845d0..9140b35450 100644
> --- a/arch/arm/include/asm/arch-sunxi/gpio.h
> +++ b/arch/arm/include/asm/arch-sunxi/gpio.h
> @@ -181,6 +181,7 @@ enum sunxi_gpio_number {
>  #define SUNXI_GPF_SDC0 2
>  #define SUNXI_GPF_UART0  4
>  #define SUN8I_GPF_UART03
> +#define SUN50I_GPF_UART0   3
>
>  #define SUN4I_GPG_SDC1 4
>  #define SUN5I_GPG_SDC1 2
> diff --git a/arch/arm/mach-sunxi/board.c b/arch/arm/mach-sunxi/board.c
> index b74eaf2a0e..019c9b9296 100644
> --- a/arch/arm/mach-sunxi/board.c
> +++ b/arch/arm/mach-sunxi/board.c
> @@ -76,6 +76,9 @@ static int gpio_init(void)
>  #if defined(CONFIG_MACH_SUN8I) && !defined(CONFIG_MACH_SUN8I_R40)
> sunxi_gpio_set_cfgpin(SUNXI_GPF(2), SUN8I_GPF_UART0);
> sunxi_gpio_set_cfgpin(SUNXI_GPF(4), SUN8I_GPF_UART0);
> +#elif defined(CONFIG_MACH_SUN50I)
> +   sunxi_gpio_set_cfgpin(SUNXI_GPF(2), SUN50I_GPF_UART0);
> +   sunxi_gpio_set_cfgpin(SUNXI_GPF(4), SUN50I_GPF_UART0);
>  #else
> sunxi_gpio_set_cfgpin(SUNXI_GPF(2), SUNXI_GPF_UART0);
> sunxi_gpio_set_cfgpin(SUNXI_GPF(4), SUNXI_GPF_UART0);
>
>
> Should I send this code as a u-boot patch? Thanks

Yes, please.


Re: [PATCH 14/15] net: sun8i-emac: Lower MDIO frequency

2020-07-11 Thread Jagan Teki
On Mon, Jul 6, 2020 at 6:12 AM Andre Przywara  wrote:
>
> When sending a command via the MDIO bus, the Designware MAC expects some
> bits in the CMD register to describe the clock divider value between
> the main clock and the MDIO clock.
> So far we were omitting these bits, resulting in setting "00", which
> means "/ 16", so ending up with an MDIO frequency of either 18.75 or
> 12.5 MHz.
> All the internal PHYs in the H3/H5/H6 SoCs as well as the Gbit Realtek
> PHYs seem to be fine with that - although it looks like to be severly
> overclocked (the MDIO spec limits the frequency to 2.5 MHz).
> However the external 100Mbit PHY on the Pine64 (non-plus) board is
> not happy with that, Ethernet was actually never working there, as the
> PHY didn't probe.

How come the existing divider cannot work with 100Mbit external
PHY(assuming external regulator pin as properly enabled) since it
works with 1Gbit already?

Jagan.


Re: [RFC PATCH v2] sunxi: Add UART4 console support for A64

2020-07-11 Thread Jagan Teki
On Wed, Jul 8, 2020 at 5:41 PM Nazım Gediz Aydındoğmuş
 wrote:
>
> UART4 port of A64 was in conflict with R_UART of older SoCs, like A23.
>
> This commit adds necessary definitions to use UART4 port on A64.
>
> Signed-off-by: Nazım Gediz Aydındoğmuş 
> Tested-by: Faruk Kılavuz 
> ---

I think this cannot be RFC, otherwise

Acked-by: Jagan Teki 


Re: [PATCH 2/2] mtd: make spinand driver usable without CONFIG_DM

2020-07-11 Thread Jagan Teki
On Sat, Jul 11, 2020 at 3:06 PM Mikhail Kshevetskiy
 wrote:
>
> On Sat, 11 Jul 2020 14:16:23 +0530
> Jagan Teki  wrote:
>
> > On Mon, Jun 22, 2020 at 9:25 PM Mikhail Kshevetskiy
> >  wrote:
> > >
> > > From: Mikhail Kshevetskiy 
> > >
> > > Here is an example of spinand driver initialization without CONFIG_DM
> > > enabled:
> > >
> > > void board_nand_init(void)
> > > {
> > > static struct spinand_devicespinand;
> > > static struct mtd_info  mtd;
> > > static struct spi_slave *slave;
> > > int ret;
> > >
> > > memset(&spinand, 0, sizeof(spinand));
> > > memset(&mtd, 0, sizeof(mtd));
> > >
> > > slave = spi_setup_slave(BUS, CS, MAX_HZ, MODE);
> > > if (!slave) {
> > > printf("SPI-NAND: Failed to set up SPI slave\n");
> > > return;
> > > }
> > >
> > > slave->mode |= (SPI_TX_BYTE | SPI_RX_SLOW);
> > > slave->max_read_size = SPI_MAX_READ_SIZE;
> > > slave->max_write_size = SPI_MAX_WRITE_SIZE;
> > >
> > > ret = spinand_probe_no_dm(&spinand, slave, &mtd);
> > > if (!ret)
> > > nand_register(0, &mtd);
> > > }
> > >
> > > Using of dual and quad wire transfer modes requires:
> > > * dual/quad speed capable hardware (both controller and flash)
> > > * physical presence of 4 data wires (quad mode only)
> > > * spi controller driver MUST supports slave->mem_ops.exec_op() operations
> > >   (spi_xfer() interface will suits for single speed data transfer mode
> > >   only)
> > >
> > > Signed-off-by: Mikhail Kshevetskiy 
> > > ---
> >
> > Now it's time for dm only code, better not come up with nondm anymore
> > as possible, please.
> >
> > Jagan.
>
> I know about it. These patches were in the queue for upstreaming from the new
> year :-(
>
> We are using 2010 and 2016 year based u-boot in our projects and due to some
> reasons it's not easy to switch it to DM build. This two patches helps us with
> backporting of spinand driver from upsteam u-boot. I think we are not an only
> users of old u-boot in the world, so it maybe helpful for other people as 
> well.

Yes, I agree with this point in terms of MTD code is a concern.
However, supporting nondm at this point look traversing in the reverse
direction as per as U-Boot development is a concern. I can guarantee
that the community is always helping to improve code if you wish to
use/migrate the mainline at any point.

>
> Just ignore these two patches if you think that NODM era is completely over.

Thanks.

Jagan.


[PATCH 0/1] fw_setenv always locks flash whenever it tries to write

2020-07-11 Thread Ivan Mikhaylov
fw_setenv usage always locks u-boot-env mtd device without questions.
Locking of flash can be disruptive and may affect not only u-boot-env
region due to different problems with chips and lock callbacks on kernel
side. I'm not sure if my fix is right, but also I thought about possible option
in fw_env config about locking/unlocking or even option into
fw_setenv/printenv. Any ideas?

Ivan Mikhaylov (1):
  fw_setenv: lock the flash only if it was locked before

 tools/env/fw_env.c | 24 +++-
 1 file changed, 19 insertions(+), 5 deletions(-)

-- 
2.21.1



[PATCH 1/1] fw_setenv: lock the flash only if it was locked before

2020-07-11 Thread Ivan Mikhaylov
u-boot-env flash region lock/unlock may affect other regions than
u-boot-env, fw_setenv does this in a way 'Lock it in any cases'.
Change this to 'lock it if it was locked before'.

Signed-off-by: Ivan Mikhaylov 
---
 tools/env/fw_env.c | 24 +++-
 1 file changed, 19 insertions(+), 5 deletions(-)

diff --git a/tools/env/fw_env.c b/tools/env/fw_env.c
index 381739d28d..3c01f52f3b 100644
--- a/tools/env/fw_env.c
+++ b/tools/env/fw_env.c
@@ -989,6 +989,7 @@ static int flash_write_buf(int dev, int fd, void *buf, 
size_t count)
   of the data */
loff_t blockstart;  /* running start of the current block -
   MEMGETBADBLOCK needs 64 bits */
+   int was_locked; /* flash lock flag */
int rc;
 
/*
@@ -1074,6 +1075,12 @@ static int flash_write_buf(int dev, int fd, void *buf, 
size_t count)
}
 
erase.length = erasesize;
+   if (DEVTYPE(dev) != MTD_ABSENT) {
+   was_locked = ioctl(fd, MEMISLOCKED, &erase);
+   /* treat any errors as unlocked flash */
+   if (was_locked < 0)
+   was_locked = 0;
+   }
 
/* This only runs once on NOR flash and SPI-dataflash */
while (processed < write_total) {
@@ -1093,7 +1100,8 @@ static int flash_write_buf(int dev, int fd, void *buf, 
size_t count)
 
if (DEVTYPE(dev) != MTD_ABSENT) {
erase.start = blockstart;
-   ioctl(fd, MEMUNLOCK, &erase);
+   if (was_locked)
+   ioctl(fd, MEMUNLOCK, &erase);
/* These do not need an explicit erase cycle */
if (DEVTYPE(dev) != MTD_DATAFLASH)
if (ioctl(fd, MEMERASE, &erase) != 0) {
@@ -1121,8 +1129,10 @@ static int flash_write_buf(int dev, int fd, void *buf, 
size_t count)
return -1;
}
 
-   if (DEVTYPE(dev) != MTD_ABSENT)
-   ioctl(fd, MEMLOCK, &erase);
+   if (DEVTYPE(dev) != MTD_ABSENT) {
+   if (was_locked)
+   ioctl(fd, MEMLOCK, &erase);
+   }
 
processed += erasesize;
block_seek = 0;
@@ -1143,7 +1153,9 @@ static int flash_flag_obsolete(int dev, int fd, off_t 
offset)
int rc;
struct erase_info_user erase;
char tmp = ENV_REDUND_OBSOLETE;
+   int was_locked; /* flash lock flag */
 
+   was_locked = ioctl(fd, MEMISLOCKED, &erase);
erase.start = DEVOFFSET(dev);
erase.length = DEVESIZE(dev);
/* This relies on the fact, that ENV_REDUND_OBSOLETE == 0 */
@@ -1153,9 +1165,11 @@ static int flash_flag_obsolete(int dev, int fd, off_t 
offset)
DEVNAME(dev));
return rc;
}
-   ioctl(fd, MEMUNLOCK, &erase);
+   if (was_locked)
+   ioctl(fd, MEMUNLOCK, &erase);
rc = write(fd, &tmp, sizeof(tmp));
-   ioctl(fd, MEMLOCK, &erase);
+   if (was_locked)
+   ioctl(fd, MEMLOCK, &erase);
if (rc < 0)
perror("Could not set obsolete flag");
 
-- 
2.21.1



Re: [PATCH 2/2] mtd: make spinand driver usable without CONFIG_DM

2020-07-11 Thread Mikhail Kshevetskiy
On Sat, 11 Jul 2020 14:16:23 +0530
Jagan Teki  wrote:

> On Mon, Jun 22, 2020 at 9:25 PM Mikhail Kshevetskiy
>  wrote:
> >
> > From: Mikhail Kshevetskiy 
> >
> > Here is an example of spinand driver initialization without CONFIG_DM
> > enabled:
> >
> > void board_nand_init(void)
> > {
> > static struct spinand_devicespinand;
> > static struct mtd_info  mtd;
> > static struct spi_slave *slave;
> > int ret;
> >
> > memset(&spinand, 0, sizeof(spinand));
> > memset(&mtd, 0, sizeof(mtd));
> >
> > slave = spi_setup_slave(BUS, CS, MAX_HZ, MODE);
> > if (!slave) {
> > printf("SPI-NAND: Failed to set up SPI slave\n");
> > return;
> > }
> >
> > slave->mode |= (SPI_TX_BYTE | SPI_RX_SLOW);
> > slave->max_read_size = SPI_MAX_READ_SIZE;
> > slave->max_write_size = SPI_MAX_WRITE_SIZE;
> >
> > ret = spinand_probe_no_dm(&spinand, slave, &mtd);
> > if (!ret)
> > nand_register(0, &mtd);
> > }
> >
> > Using of dual and quad wire transfer modes requires:
> > * dual/quad speed capable hardware (both controller and flash)
> > * physical presence of 4 data wires (quad mode only)
> > * spi controller driver MUST supports slave->mem_ops.exec_op() operations
> >   (spi_xfer() interface will suits for single speed data transfer mode
> >   only)
> >
> > Signed-off-by: Mikhail Kshevetskiy 
> > ---
> 
> Now it's time for dm only code, better not come up with nondm anymore
> as possible, please.
> 
> Jagan.

I know about it. These patches were in the queue for upstreaming from the new
year :-(

We are using 2010 and 2016 year based u-boot in our projects and due to some
reasons it's not easy to switch it to DM build. This two patches helps us with
backporting of spinand driver from upsteam u-boot. I think we are not an only
users of old u-boot in the world, so it maybe helpful for other people as well.

Just ignore these two patches if you think that NODM era is completely over.


Mikhail.



 


Re: Pull request for UEFI sub-system for efi-2020-10-rc1 (2)

2020-07-11 Thread Tom Rini
On Sat, Jul 11, 2020 at 09:00:16AM +0200, Heinrich Schuchardt wrote:
> On 7/10/20 8:09 PM, Tom Rini wrote:
> > On Thu, Jul 09, 2020 at 06:12:02PM +0200, Heinrich Schuchardt wrote:
> >
> >> The following changes since commit 
> >> 61608f395e7dcb2be6060407a72a1149b046430a:
> >>
> >>   Merge branch '2020-07-08-misc-features-and-fixes' (2020-07-08 20:20:24
> >> -0400)
> >>
> >> are available in the Git repository at:
> >>
> >>   https://gitlab.denx.de/u-boot/custodians/u-boot-efi.git efi-2020-10-rc1-2
> >>
> >> for you to fetch changes up to f4cef8e7585c268f05a8c39e368ca115c25e40d5:
> >>
> >>   efi_selftest: adjust runtime test for variables (2020-07-09 12:08:41
> >> +0200)
> >>
> >
> > NAK.  This is reliably failing here:
> > https://gitlab.denx.de/u-boot/u-boot/-/jobs/122018
> >
> > I see it passed Azure, and hasn't run through Travis yet.  Maybe it
> > needs to be run repeatedly to fail and we just got "lucky" ?
> >
> 
> Hello Tom,
> 
> you saw unreproducible results with multiple runs failing and one run
> succeeding. The reason is that when signing with sign-efi-sig-list in
> out Python tests without passing a timestamp two signatures may be in
> the same second or not.
> 
> When using the signed files to set UEFI variables a variable can only be
> overwritten by a file with a newer timestamp. But without setting
> timestamps explicitly using parameter -t passed to sign-efi-sig-list we
> have no control.
> 
> I already fixed this for some elder tests but missed to fix this for the
> merged patches from Takahiro.

Ah, thanks for the explanation.

-- 
Tom


signature.asc
Description: PGP signature


[PATCH 01/12] net: dc2114x: Use PCI_DEVICE() to define PCI device compat list

2020-07-11 Thread Marek Vasut
Use this macro to fully fill the PCI device ID table. This is mandatory
for the DM PCI support, which checks all the fields.

Signed-off-by: Marek Vasut 
Cc: Joe Hershberger 
Cc: Ramon Fried 
---
 drivers/net/dc2114x.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/dc2114x.c b/drivers/net/dc2114x.c
index c55358ef83..e537b29f3d 100644
--- a/drivers/net/dc2114x.c
+++ b/drivers/net/dc2114x.c
@@ -568,8 +568,8 @@ static void read_hw_addr(struct eth_device *dev, bd_t *bis)
 }
 
 static struct pci_device_id supported[] = {
-   { PCI_VENDOR_ID_DEC, PCI_DEVICE_ID_DEC_TULIP_FAST },
-   { PCI_VENDOR_ID_DEC, PCI_DEVICE_ID_DEC_21142 },
+   { PCI_DEVICE(PCI_VENDOR_ID_DEC, PCI_DEVICE_ID_DEC_TULIP_FAST) },
+   { PCI_DEVICE(PCI_VENDOR_ID_DEC, PCI_DEVICE_ID_DEC_21142) },
{ }
 };
 
-- 
2.27.0



[PATCH 02/12] net: dc2114x: Support all DC2114x

2020-07-11 Thread Marek Vasut
For the usage in this driver, the chips are identical,
so support all of them.

Signed-off-by: Marek Vasut 
Cc: Joe Hershberger 
Cc: Ramon Fried 
---
 drivers/net/dc2114x.c | 9 -
 1 file changed, 9 deletions(-)

diff --git a/drivers/net/dc2114x.c b/drivers/net/dc2114x.c
index e537b29f3d..245218080e 100644
--- a/drivers/net/dc2114x.c
+++ b/drivers/net/dc2114x.c
@@ -581,7 +581,6 @@ int dc21x4x_initialize(bd_t *bis)
unsigned int iobase;
int card_number = 0;
pci_dev_t devbusfn;
-   unsigned int cfrv;
int idx = 0;
 
while (1) {
@@ -589,14 +588,6 @@ int dc21x4x_initialize(bd_t *bis)
if (devbusfn == -1)
break;
 
-   /* Get the chip configuration revision register. */
-   pci_read_config_dword(devbusfn, PCI_REVISION_ID, &cfrv);
-
-   if ((cfrv & CFRV_RN) < DC2114x_BRK) {
-   printf("Error: The chip is not DC21143.\n");
-   continue;
-   }
-
pci_read_config_word(devbusfn, PCI_COMMAND, &status);
status |= PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER;
pci_write_config_word(devbusfn, PCI_COMMAND, status);
-- 
2.27.0



[PATCH 04/12] net: dc2114x: Drop update_srom()

2020-07-11 Thread Marek Vasut
This code is never used, remove it.

Signed-off-by: Marek Vasut 
Cc: Joe Hershberger 
Cc: Ramon Fried 
---
 drivers/net/dc2114x.c | 91 ---
 1 file changed, 91 deletions(-)

diff --git a/drivers/net/dc2114x.c b/drivers/net/dc2114x.c
index 245218080e..af582c5415 100644
--- a/drivers/net/dc2114x.c
+++ b/drivers/net/dc2114x.c
@@ -11,8 +11,6 @@
 
 #define SROM_DLEVEL0
 
-#undef UPDATE_SROM
-
 /* PCI Registers. */
 #define PCI_CFDA_PSM   0x43
 
@@ -270,92 +268,6 @@ static int read_srom(struct eth_device *dev, u_long 
ioaddr, int index)
 3 + ee_addr_size + 16);
 }
 
-#ifdef UPDATE_SROM
-static int write_srom(struct eth_device *dev, u_long ioaddr, int index,
- int new_value)
-{
-   unsigned short newval;
-   int ee_addr_size;
-   int i;
-
-   ee_addr_size = (do_read_eeprom(dev, ioaddr, 0xff, 8) & BIT(18)) ? 8 : 6;
-
-   udelay(10 * 1000); /* test-only */
-
-   debug_cond(SROM_DLEVEL >= 1, "ee_addr_size=%d.\n", ee_addr_size);
-   debug_cond(SROM_DLEVEL >= 1,
-  "Writing new entry 0x%4.4x to offset %d.\n",
-  new_value, index);
-
-   /* Enable programming modes. */
-   do_eeprom_cmd(dev, ioaddr, 0x4f << (ee_addr_size - 4),
- 3 + ee_addr_size);
-
-   /* Do the actual write. */
-   do_eeprom_cmd(dev, ioaddr, new_value |
- (((SROM_WRITE_CMD << ee_addr_size) | index) << 16),
- 3 + ee_addr_size + 16);
-
-   /* Poll for write finished. */
-   sendto_srom(dev, SROM_RD | SROM_SR | DT_CS, ioaddr);
-   for (i = 0; i < 1; i++) {   /* Typical 2000 ticks */
-   if (getfrom_srom(dev, ioaddr) & EE_DATA_READ)
-   break;
-   }
-
-   debug_cond(SROM_DLEVEL >= 1, " Write finished after %d ticks.\n", i);
-
-   /* Disable programming. */
-   do_eeprom_cmd(dev, ioaddr, (0x40 << (ee_addr_size - 4)),
- 3 + ee_addr_size);
-
-   /* And read the result. */
-   newval = do_eeprom_cmd(dev, ioaddr,
-  (((SROM_READ_CMD << ee_addr_size) | index) << 16)
-  | 0x, 3 + ee_addr_size + 16);
-
-   debug_cond(SROM_DLEVEL >= 1, "  New value at offset %d is %4.4x.\n",
-  index, newval);
-
-   return 1;
-}
-
-static void update_srom(struct eth_device *dev, bd_t *bis)
-{
-   static unsigned short eeprom[0x40] = {
-   0x140b, 0x6610, 0x, 0x, /* 00 */
-   0x, 0x, 0x, 0x, /* 04 */
-   0x00a3, 0x0103, 0x, 0x, /* 08 */
-   0x, 0x1f00, 0x, 0x, /* 0c */
-   0x0108, 0x038d, 0x, 0x, /* 10 */
-   0xe078, 0x0001, 0x0040, 0x0018, /* 14 */
-   0x, 0x, 0x, 0x, /* 18 */
-   0x, 0x, 0x, 0x, /* 1c */
-   0x, 0x, 0x, 0x, /* 20 */
-   0x, 0x, 0x, 0x, /* 24 */
-   0x, 0x, 0x, 0x, /* 28 */
-   0x, 0x, 0x, 0x, /* 2c */
-   0x, 0x, 0x, 0x, /* 30 */
-   0x, 0x, 0x, 0x, /* 34 */
-   0x, 0x, 0x, 0x, /* 38 */
-   0x, 0x, 0x, 0x4e07, /* 3c */
-   };
-   uchar enetaddr[6];
-   int i;
-
-   /* Ethernet Addr... */
-   if (!eth_env_get_enetaddr("ethaddr", enetaddr))
-   return;
-
-   eeprom[0x0a] = (enetaddr[1] << 8) | enetaddr[0];
-   eeprom[0x0b] = (enetaddr[3] << 8) | enetaddr[2];
-   eeprom[0x0c] = (enetaddr[5] << 8) | enetaddr[4];
-
-   for (i = 0; i < 0x40; i++)
-   write_srom(dev, DE4X5_APROM, i, eeprom[i]);
-}
-#endif /* UPDATE_SROM */
-
 static void send_setup_frame(struct eth_device *dev, bd_t *bis)
 {
char setup_frame[SETUP_FRAME_LEN];
@@ -561,9 +473,6 @@ static void read_hw_addr(struct eth_device *dev, bd_t *bis)
if (!j || j == 0x2fffd) {
memset(dev->enetaddr, 0, ETH_ALEN);
debug("Warning: can't read HW address from SROM.\n");
-#ifdef UPDATE_SROM
-   update_srom(dev, bis);
-#endif
}
 }
 
-- 
2.27.0



[PATCH 05/12] net: dc2114x: Use standard I/O accessors

2020-07-11 Thread Marek Vasut
The current dc21x4x driver accesses its memory mapped registers directly
instead of using the standard I/O accessors. This can cause problems on
some systems as the accesses can get out of order. So convert the direct
volatile dereferences to use the normal in/out macros.

Signed-off-by: Marek Vasut 
Cc: Joe Hershberger 
Cc: Ramon Fried 
---
 drivers/net/dc2114x.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/net/dc2114x.c b/drivers/net/dc2114x.c
index af582c5415..9dd36e74de 100644
--- a/drivers/net/dc2114x.c
+++ b/drivers/net/dc2114x.c
@@ -1,6 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0+
 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -104,12 +105,12 @@ static char tx_ring_size;
 
 static u32 dc2114x_inl(struct eth_device *dev, u32 addr)
 {
-   return le32_to_cpu(*(volatile u32 *)(addr + dev->iobase));
+   return le32_to_cpu(readl(dev->iobase + addr));
 }
 
 static void dc2114x_outl(struct eth_device *dev, u32 command, u32 addr)
 {
-   *(volatile u32 *)(addr + dev->iobase) = cpu_to_le32(command);
+   writel(cpu_to_le32(command), dev->iobase + addr);
 }
 
 static void reset_de4x5(struct eth_device *dev)
-- 
2.27.0



[PATCH 03/12] net: dc2114x: Add Kconfig entries

2020-07-11 Thread Marek Vasut
Add Kconfig entries for the dc2114x driver and convert various boards.

Signed-off-by: Marek Vasut 
Cc: Joe Hershberger 
Cc: Ramon Fried 
---
 README  | 3 ---
 configs/integratorap_cm720t_defconfig   | 1 +
 configs/integratorap_cm920t_defconfig   | 1 +
 configs/integratorap_cm926ejs_defconfig | 1 +
 configs/integratorap_cm946es_defconfig  | 1 +
 drivers/net/Kconfig | 6 ++
 include/configs/MPC8349EMDS.h   | 1 -
 include/configs/MPC8349EMDS_SDRAM.h | 1 -
 include/configs/MPC8540ADS.h| 1 -
 include/configs/MPC8541CDS.h| 1 -
 include/configs/MPC8544DS.h | 1 -
 include/configs/MPC8548CDS.h| 1 -
 include/configs/MPC8555CDS.h| 1 -
 include/configs/MPC8560ADS.h| 1 -
 include/configs/MPC8568MDS.h| 1 -
 include/configs/MPC8569MDS.h| 1 -
 include/configs/MPC8572DS.h | 1 -
 include/configs/MPC8641HPCN.h   | 1 -
 include/configs/TQM834x.h   | 1 -
 include/configs/caddy2.h| 1 -
 include/configs/integratorap.h  | 1 -
 include/configs/sbc8349.h   | 1 -
 include/configs/sbc8548.h   | 1 -
 include/configs/sbc8641d.h  | 1 -
 include/configs/vme8349.h   | 1 -
 scripts/config_whitelist.txt| 1 -
 26 files changed, 10 insertions(+), 23 deletions(-)

diff --git a/README b/README
index 020918a543..d3de7c41c9 100644
--- a/README
+++ b/README
@@ -871,9 +871,6 @@ The following options need to be configured:
Allow generic access to the SPI bus on the Intel 8257x, for
example with the "sspi" command.
 
-   CONFIG_TULIP
-   Support for Digital 2114x chips.
-
CONFIG_NATSEMI
Support for National dp83815 chips.
 
diff --git a/configs/integratorap_cm720t_defconfig 
b/configs/integratorap_cm720t_defconfig
index 1b7d672bcb..0d9746b485 100644
--- a/configs/integratorap_cm720t_defconfig
+++ b/configs/integratorap_cm720t_defconfig
@@ -25,6 +25,7 @@ CONFIG_FLASH_CFI_DRIVER=y
 CONFIG_SYS_FLASH_PROTECTION=y
 CONFIG_SYS_FLASH_CFI=y
 CONFIG_EEPRO100=y
+CONFIG_TULIP=y
 CONFIG_PCI=y
 CONFIG_BAUDRATE=38400
 CONFIG_OF_LIBFDT=y
diff --git a/configs/integratorap_cm920t_defconfig 
b/configs/integratorap_cm920t_defconfig
index 116ac015a0..7d71648a86 100644
--- a/configs/integratorap_cm920t_defconfig
+++ b/configs/integratorap_cm920t_defconfig
@@ -25,6 +25,7 @@ CONFIG_FLASH_CFI_DRIVER=y
 CONFIG_SYS_FLASH_PROTECTION=y
 CONFIG_SYS_FLASH_CFI=y
 CONFIG_EEPRO100=y
+CONFIG_TULIP=y
 CONFIG_PCI=y
 CONFIG_BAUDRATE=38400
 CONFIG_OF_LIBFDT=y
diff --git a/configs/integratorap_cm926ejs_defconfig 
b/configs/integratorap_cm926ejs_defconfig
index 9c1a3fa2f5..921a75e326 100644
--- a/configs/integratorap_cm926ejs_defconfig
+++ b/configs/integratorap_cm926ejs_defconfig
@@ -25,6 +25,7 @@ CONFIG_FLASH_CFI_DRIVER=y
 CONFIG_SYS_FLASH_PROTECTION=y
 CONFIG_SYS_FLASH_CFI=y
 CONFIG_EEPRO100=y
+CONFIG_TULIP=y
 CONFIG_PCI=y
 CONFIG_BAUDRATE=38400
 CONFIG_OF_LIBFDT=y
diff --git a/configs/integratorap_cm946es_defconfig 
b/configs/integratorap_cm946es_defconfig
index ee9c69bce0..4032da97b4 100644
--- a/configs/integratorap_cm946es_defconfig
+++ b/configs/integratorap_cm946es_defconfig
@@ -25,6 +25,7 @@ CONFIG_FLASH_CFI_DRIVER=y
 CONFIG_SYS_FLASH_PROTECTION=y
 CONFIG_SYS_FLASH_CFI=y
 CONFIG_EEPRO100=y
+CONFIG_TULIP=y
 CONFIG_PCI=y
 CONFIG_BAUDRATE=38400
 CONFIG_OF_LIBFDT=y
diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
index ec3fb49832..15030b8165 100644
--- a/drivers/net/Kconfig
+++ b/drivers/net/Kconfig
@@ -491,6 +491,12 @@ config SH_ETHER
 
 source "drivers/net/ti/Kconfig"
 
+config TULIP
+   bool "DEC Tulip DC2114x Ethernet support"
+   depends on (DM_ETH && DM_PCI) || !DM_ETH
+   help
+ This driver supports DEC DC2114x Fast ethernet chips.
+
 config XILINX_AXIEMAC
depends on DM_ETH && (MICROBLAZE || ARCH_ZYNQ || ARCH_ZYNQMP)
select PHYLIB
diff --git a/include/configs/MPC8349EMDS.h b/include/configs/MPC8349EMDS.h
index 41ef3d80e1..c2f44416b9 100644
--- a/include/configs/MPC8349EMDS.h
+++ b/include/configs/MPC8349EMDS.h
@@ -220,7 +220,6 @@
 
 #define CONFIG_83XX_PCI_STREAMING
 
-#undef CONFIG_TULIP
 
 #if !defined(CONFIG_PCI_PNP)
#define PCI_ENET0_IOADDR0xFIXME
diff --git a/include/configs/MPC8349EMDS_SDRAM.h 
b/include/configs/MPC8349EMDS_SDRAM.h
index 4b43ee1d44..618e210e4e 100644
--- a/include/configs/MPC8349EMDS_SDRAM.h
+++ b/include/configs/MPC8349EMDS_SDRAM.h
@@ -275,7 +275,6 @@
 
 #define CONFIG_83XX_PCI_STREAMING
 
-#undef CONFIG_TULIP
 
 #if !defined(CONFIG_PCI_PNP)
#define PCI_ENET0_IOADDR0xFIXME
diff --git a/include/configs/MPC8540ADS.h b/include/configs/MPC8540ADS.h
index d2a92619fb..8b7e0da9ca 100644
--- a/include/configs/MPC8540ADS.h
+++ b/include/configs/MPC8540ADS.h
@@ -234,7 +234,6 @@
 #define CONFIG_SYS_PCI1_IO_SIZE0x10

[PATCH 07/12] net: dc2114x: Pass private data around

2020-07-11 Thread Marek Vasut
This patch replaces the various uses of struct eth_device for accessing
device private data with struct dc2114x_priv, which is compatible both
with DM and non-DM operation.

Signed-off-by: Marek Vasut 
Cc: Joe Hershberger 
Cc: Ramon Fried 
---
 drivers/net/dc2114x.c | 135 ++
 1 file changed, 71 insertions(+), 64 deletions(-)

diff --git a/drivers/net/dc2114x.c b/drivers/net/dc2114x.c
index 9f16250fe6..0438cd3eda 100644
--- a/drivers/net/dc2114x.c
+++ b/drivers/net/dc2114x.c
@@ -110,78 +110,78 @@ static int tx_new;/* TX descriptor ring pointer */
 static char rx_ring_size;
 static char tx_ring_size;
 
-static u32 dc2114x_inl(struct eth_device *dev, u32 addr)
+static u32 dc2114x_inl(struct dc2114x_priv *priv, u32 addr)
 {
-   return le32_to_cpu(readl(dev->iobase + addr));
+   return le32_to_cpu(readl(priv->iobase + addr));
 }
 
-static void dc2114x_outl(struct eth_device *dev, u32 command, u32 addr)
+static void dc2114x_outl(struct dc2114x_priv *priv, u32 command, u32 addr)
 {
-   writel(cpu_to_le32(command), dev->iobase + addr);
+   writel(cpu_to_le32(command), priv->iobase + addr);
 }
 
-static void reset_de4x5(struct eth_device *dev)
+static void reset_de4x5(struct dc2114x_priv *priv)
 {
u32 i;
 
-   i = dc2114x_inl(dev, DE4X5_BMR);
+   i = dc2114x_inl(priv, DE4X5_BMR);
mdelay(1);
-   dc2114x_outl(dev, i | BMR_SWR, DE4X5_BMR);
+   dc2114x_outl(priv, i | BMR_SWR, DE4X5_BMR);
mdelay(1);
-   dc2114x_outl(dev, i, DE4X5_BMR);
+   dc2114x_outl(priv, i, DE4X5_BMR);
mdelay(1);
 
for (i = 0; i < 5; i++) {
-   dc2114x_inl(dev, DE4X5_BMR);
+   dc2114x_inl(priv, DE4X5_BMR);
mdelay(10);
}
 
mdelay(1);
 }
 
-static void start_de4x5(struct eth_device *dev)
+static void start_de4x5(struct dc2114x_priv *priv)
 {
u32 omr;
 
-   omr = dc2114x_inl(dev, DE4X5_OMR);
+   omr = dc2114x_inl(priv, DE4X5_OMR);
omr |= OMR_ST | OMR_SR;
-   dc2114x_outl(dev, omr, DE4X5_OMR);  /* Enable the TX and/or RX */
+   dc2114x_outl(priv, omr, DE4X5_OMR); /* Enable the TX and/or RX */
 }
 
-static void stop_de4x5(struct eth_device *dev)
+static void stop_de4x5(struct dc2114x_priv *priv)
 {
u32 omr;
 
-   omr = dc2114x_inl(dev, DE4X5_OMR);
+   omr = dc2114x_inl(priv, DE4X5_OMR);
omr &= ~(OMR_ST | OMR_SR);
-   dc2114x_outl(dev, omr, DE4X5_OMR);  /* Disable the TX and/or RX */
+   dc2114x_outl(priv, omr, DE4X5_OMR); /* Disable the TX and/or RX */
 }
 
 /* SROM Read and write routines. */
-static void sendto_srom(struct eth_device *dev, u_int command, u_long addr)
+static void sendto_srom(struct dc2114x_priv *priv, u_int command, u_long addr)
 {
-   dc2114x_outl(dev, command, addr);
+   dc2114x_outl(priv, command, addr);
udelay(1);
 }
 
-static int getfrom_srom(struct eth_device *dev, u_long addr)
+static int getfrom_srom(struct dc2114x_priv *priv, u_long addr)
 {
-   u32 tmp = dc2114x_inl(dev, addr);
+   u32 tmp = dc2114x_inl(priv, addr);
 
udelay(1);
return tmp;
 }
 
 /* Note: this routine returns extra data bits for size detection. */
-static int do_read_eeprom(struct eth_device *dev, u_long ioaddr, int location,
+static int do_read_eeprom(struct dc2114x_priv *priv, u_long ioaddr, int 
location,
  int addr_len)
 {
int read_cmd = location | (SROM_READ_CMD << addr_len);
unsigned int retval = 0;
int i;
 
-   sendto_srom(dev, SROM_RD | SROM_SR, ioaddr);
-   sendto_srom(dev, SROM_RD | SROM_SR | DT_CS, ioaddr);
+   sendto_srom(priv, SROM_RD | SROM_SR, ioaddr);
+   sendto_srom(priv, SROM_RD | SROM_SR | DT_CS, ioaddr);
 
debug_cond(SROM_DLEVEL >= 1, " EEPROM read at %d ", location);
 
@@ -189,35 +189,35 @@ static int do_read_eeprom(struct eth_device *dev, u_long 
ioaddr, int location,
for (i = 4 + addr_len; i >= 0; i--) {
short dataval = (read_cmd & (1 << i)) ? EE_DATA_WRITE : 0;
 
-   sendto_srom(dev, SROM_RD | SROM_SR | DT_CS | dataval,
+   sendto_srom(priv, SROM_RD | SROM_SR | DT_CS | dataval,
ioaddr);
udelay(10);
-   sendto_srom(dev, SROM_RD | SROM_SR | DT_CS | dataval | DT_CLK,
+   sendto_srom(priv, SROM_RD | SROM_SR | DT_CS | dataval | DT_CLK,
ioaddr);
udelay(10);
debug_cond(SROM_DLEVEL >= 2, "%X",
-  getfrom_srom(dev, ioaddr) & 15);
+  getfrom_srom(priv, ioaddr) & 15);
retval = (retval << 1) |
-!!(getfrom_srom(dev, ioaddr) & EE_DATA_READ);
+!!(getfrom_srom(priv, ioaddr) & EE_DATA_READ);
}
 
-   sendto_srom(dev, SROM_RD | SROM_SR | DT_CS, ioaddr);
+   sendto_srom(priv, SROM_RD | SR

[PATCH 06/12] net: dc2114x: Introduce private data

2020-07-11 Thread Marek Vasut
Introduce dc2114x_priv, which is a super-structure around eth_device
and tracks per-device state and the device IO address.

Signed-off-by: Marek Vasut 
Cc: Joe Hershberger 
Cc: Ramon Fried 
---
 drivers/net/dc2114x.c | 25 ++---
 1 file changed, 18 insertions(+), 7 deletions(-)

diff --git a/drivers/net/dc2114x.c b/drivers/net/dc2114x.c
index 9dd36e74de..9f16250fe6 100644
--- a/drivers/net/dc2114x.c
+++ b/drivers/net/dc2114x.c
@@ -94,6 +94,13 @@ struct de4x5_desc {
u32 next;
 };
 
+struct dc2114x_priv {
+   struct eth_device   dev;
+   char*name;
+   void __iomem*iobase;
+   u8  *enetaddr;
+};
+
 /* RX and TX descriptor ring */
 static struct de4x5_desc rx_ring[NUM_RX_DESC] __aligned(32);
 static struct de4x5_desc tx_ring[NUM_TX_DESC] __aligned(32);
@@ -460,9 +467,9 @@ static void dc21x4x_halt(struct eth_device *dev)
pci_write_config_byte(devbusfn, PCI_CFDA_PSM, SLEEP);
 }
 
-static void read_hw_addr(struct eth_device *dev, bd_t *bis)
+static void read_hw_addr(struct dc2114x_priv *priv)
 {
-   u_short tmp, *p = (u_short *)(&dev->enetaddr[0]);
+   u_short tmp, *p = (u_short *)(&priv->enetaddr[0]);
int i, j = 0;
 
for (i = 0; i < (ETH_ALEN >> 1); i++) {
@@ -472,7 +479,7 @@ static void read_hw_addr(struct eth_device *dev, bd_t *bis)
}
 
if (!j || j == 0x2fffd) {
-   memset(dev->enetaddr, 0, ETH_ALEN);
+   memset(priv->enetaddr, 0, ETH_ALEN);
debug("Warning: can't read HW address from SROM.\n");
}
 }
@@ -485,6 +492,7 @@ static struct pci_device_id supported[] = {
 
 int dc21x4x_initialize(bd_t *bis)
 {
+   struct dc2114x_priv *priv;
struct eth_device *dev;
unsigned short status;
unsigned char timer;
@@ -526,15 +534,18 @@ int dc21x4x_initialize(bd_t *bis)
iobase &= PCI_BASE_ADDRESS_MEM_MASK;
debug("dc21x4x: DEC 21142 PCI Device @0x%x\n", iobase);
 
-   dev = (struct eth_device *)malloc(sizeof(*dev));
-   if (!dev) {
+   priv = malloc(sizeof(*priv));
+   if (!priv) {
printf("Can not allocalte memory of dc21x4x\n");
break;
}
+   memset(priv, 0, sizeof(*priv));
 
-   memset(dev, 0, sizeof(*dev));
+   dev = &priv->dev;
 
sprintf(dev->name, "dc21x4x#%d", card_number);
+   priv->name = dev->name;
+   priv->enetaddr = dev->enetaddr;
 
dev->iobase = pci_mem_to_phys(devbusfn, iobase);
dev->priv = (void *)devbusfn;
@@ -548,7 +559,7 @@ int dc21x4x_initialize(bd_t *bis)
 
udelay(10 * 1000);
 
-   read_hw_addr(dev, bis);
+   read_hw_addr(priv);
 
eth_register(dev);
 
-- 
2.27.0



[PATCH 11/12] net: dc2114x: Split common parts of non-DM functions out

2020-07-11 Thread Marek Vasut
Split the common code from the non-DM code, so it can be reused by
the DM code later. As always, the recv() function had to be split
into the actual receiving part and free_pkt part to fit with the
DM.

Signed-off-by: Marek Vasut 
Cc: Joe Hershberger 
Cc: Ramon Fried 
---
 drivers/net/dc2114x.c | 117 --
 1 file changed, 67 insertions(+), 50 deletions(-)

diff --git a/drivers/net/dc2114x.c b/drivers/net/dc2114x.c
index e224d007de..dc202d81de 100644
--- a/drivers/net/dc2114x.c
+++ b/drivers/net/dc2114x.c
@@ -275,7 +275,7 @@ static int read_srom(struct dc2114x_priv *priv, u_long 
ioaddr, int index)
 3 + ee_addr_size + 16);
 }
 
-static void send_setup_frame(struct dc2114x_priv *priv, bd_t *bis)
+static void send_setup_frame(struct dc2114x_priv *priv)
 {
char setup_frame[SETUP_FRAME_LEN];
char *pa = &setup_frame[0];
@@ -320,10 +320,8 @@ static void send_setup_frame(struct dc2114x_priv *priv, 
bd_t *bis)
priv->tx_new = (priv->tx_new + 1) % NUM_TX_DESC;
 }
 
-static int dc21x4x_send(struct eth_device *dev, void *packet, int length)
+static int dc21x4x_send_common(struct dc2114x_priv *priv, void *packet, int 
length)
 {
-   struct dc2114x_priv *priv =
-   container_of(dev, struct dc2114x_priv, dev);
int status = -1;
int i;
 
@@ -395,48 +393,10 @@ static int dc21x4x_recv_check(struct dc2114x_priv *priv)
return -EAGAIN;
 }
 
-static int dc21x4x_recv(struct eth_device *dev)
-{
-   struct dc2114x_priv *priv =
-   container_of(dev, struct dc2114x_priv, dev);
-   int length = 0;
-   int ret;
-
-   while (true) {
-   ret = dc21x4x_recv_check(priv);
-   if (!ret)
-   break;
-
-   if (ret > 0) {
-   length = ret;
-   /* Pass the packet up to the protocol layers */
-   net_process_received_packet
-   (net_rx_packets[priv->rx_new], length - 4);
-   }
-
-   /*
-* Change buffer ownership for this frame,
-* back to the adapter.
-*/
-   if (ret != -EAGAIN)
-   priv->rx_ring[priv->rx_new].status = cpu_to_le32(R_OWN);
-
-   /* Update entry information. */
-   priv->rx_new = (priv->rx_new + 1) % priv->rx_ring_size;
-   }
-
-   return length;
-}
-
-static int dc21x4x_init(struct eth_device *dev, bd_t *bis)
+static int dc21x4x_init_common(struct dc2114x_priv *priv)
 {
-   struct dc2114x_priv *priv =
-   container_of(dev, struct dc2114x_priv, dev);
int i;
 
-   /* Ensure we're not sleeping. */
-   pci_write_config_byte(priv->devno, PCI_CFDA_PSM, WAKEUP);
-
reset_de4x5(priv);
 
if (dc2114x_inl(priv, DE4X5_STS) & (STS_TS | STS_RS)) {
@@ -479,20 +439,15 @@ static int dc21x4x_init(struct eth_device *dev, bd_t *bis)
priv->tx_new = 0;
priv->rx_new = 0;
 
-   send_setup_frame(priv, bis);
+   send_setup_frame(priv);
 
return 0;
 }
 
-static void dc21x4x_halt(struct eth_device *dev)
+static void dc21x4x_halt_common(struct dc2114x_priv *priv)
 {
-   struct dc2114x_priv *priv =
-   container_of(dev, struct dc2114x_priv, dev);
-
stop_de4x5(priv);
dc2114x_outl(priv, 0, DE4X5_SICR);
-
-   pci_write_config_byte(priv->devno, PCI_CFDA_PSM, SLEEP);
 }
 
 static void read_hw_addr(struct dc2114x_priv *priv)
@@ -518,6 +473,68 @@ static struct pci_device_id supported[] = {
{ }
 };
 
+static int dc21x4x_init(struct eth_device *dev, bd_t *bis)
+{
+   struct dc2114x_priv *priv =
+   container_of(dev, struct dc2114x_priv, dev);
+
+   /* Ensure we're not sleeping. */
+   pci_write_config_byte(priv->devno, PCI_CFDA_PSM, WAKEUP);
+
+   return dc21x4x_init_common(priv);
+}
+
+static void dc21x4x_halt(struct eth_device *dev)
+{
+   struct dc2114x_priv *priv =
+   container_of(dev, struct dc2114x_priv, dev);
+
+   dc21x4x_halt_common(priv);
+
+   pci_write_config_byte(priv->devno, PCI_CFDA_PSM, SLEEP);
+}
+
+static int dc21x4x_send(struct eth_device *dev, void *packet, int length)
+{
+   struct dc2114x_priv *priv =
+   container_of(dev, struct dc2114x_priv, dev);
+
+   return dc21x4x_send_common(priv, packet, length);
+}
+
+static int dc21x4x_recv(struct eth_device *dev)
+{
+   struct dc2114x_priv *priv =
+   container_of(dev, struct dc2114x_priv, dev);
+   int length = 0;
+   int ret;
+
+   while (true) {
+   ret = dc21x4x_recv_check(priv);
+   if (!ret)
+   break;
+
+   if (ret > 0) {
+   length = ret;
+   /* Pass the packet up to the protocol layers */
+   net_process_received_packet
+

[PATCH 10/12] net: dc2114x: Split RX path

2020-07-11 Thread Marek Vasut
Split the RX data check from the rest of the RX function, so that
the check can be performed separately from the processing of the
packet and the release of the received packet once the processing
is finished.

Signed-off-by: Marek Vasut 
Cc: Joe Hershberger 
Cc: Ramon Fried 
---
 drivers/net/dc2114x.c | 67 +++
 1 file changed, 43 insertions(+), 24 deletions(-)

diff --git a/drivers/net/dc2114x.c b/drivers/net/dc2114x.c
index a91749584f..e224d007de 100644
--- a/drivers/net/dc2114x.c
+++ b/drivers/net/dc2114x.c
@@ -367,41 +367,60 @@ done:
return status;
 }
 
+static int dc21x4x_recv_check(struct dc2114x_priv *priv)
+{
+   int length = 0;
+   u32 status;
+
+   status = le32_to_cpu(priv->rx_ring[priv->rx_new].status);
+
+   if (status & R_OWN)
+   return 0;
+
+   if (status & RD_LS) {
+   /* Valid frame status. */
+   if (status & RD_ES) {
+   /* There was an error. */
+   printf("RX error status = 0x%08X\n", status);
+   return -EINVAL;
+   } else {
+   /* A valid frame received. */
+   length = 
(le32_to_cpu(priv->rx_ring[priv->rx_new].status)
+ >> 16);
+
+   return length;
+   }
+   }
+
+   return -EAGAIN;
+}
+
 static int dc21x4x_recv(struct eth_device *dev)
 {
struct dc2114x_priv *priv =
container_of(dev, struct dc2114x_priv, dev);
int length = 0;
-   u32 status;
+   int ret;
 
while (true) {
-   status = le32_to_cpu(priv->rx_ring[priv->rx_new].status);
-
-   if (status & R_OWN)
+   ret = dc21x4x_recv_check(priv);
+   if (!ret)
break;
 
-   if (status & RD_LS) {
-   /* Valid frame status. */
-   if (status & RD_ES) {
-   /* There was an error. */
-   printf("RX error status = 0x%08X\n", status);
-   } else {
-   /* A valid frame received. */
-   length = 
(le32_to_cpu(priv->rx_ring[priv->rx_new].status)
- >> 16);
-
-   /* Pass the packet up to the protocol layers */
-   net_process_received_packet
-   (net_rx_packets[priv->rx_new], length - 
4);
-   }
-
-   /*
-* Change buffer ownership for this frame,
-* back to the adapter.
-*/
-   priv->rx_ring[priv->rx_new].status = cpu_to_le32(R_OWN);
+   if (ret > 0) {
+   length = ret;
+   /* Pass the packet up to the protocol layers */
+   net_process_received_packet
+   (net_rx_packets[priv->rx_new], length - 4);
}
 
+   /*
+* Change buffer ownership for this frame,
+* back to the adapter.
+*/
+   if (ret != -EAGAIN)
+   priv->rx_ring[priv->rx_new].status = cpu_to_le32(R_OWN);
+
/* Update entry information. */
priv->rx_new = (priv->rx_new + 1) % priv->rx_ring_size;
}
-- 
2.27.0



[PATCH 12/12] net: dc2114x: Add DM support

2020-07-11 Thread Marek Vasut
With all the changes in place, add support for DM into the
dc2114x driver.

Signed-off-by: Marek Vasut 
Cc: Joe Hershberger 
Cc: Ramon Fried 
---
 drivers/net/dc2114x.c | 147 +-
 1 file changed, 145 insertions(+), 2 deletions(-)

diff --git a/drivers/net/dc2114x.c b/drivers/net/dc2114x.c
index dc202d81de..26ca40e115 100644
--- a/drivers/net/dc2114x.c
+++ b/drivers/net/dc2114x.c
@@ -2,7 +2,7 @@
 
 #include 
 #include 
-#include 
+#include 
 #include 
 #include 
 #include 
@@ -73,7 +73,9 @@
 
 #define POLL_DEMAND1
 
-#if defined(CONFIG_E500)
+#if defined(CONFIG_DM_ETH)
+#define phys_to_bus(dev, a)dm_pci_phys_to_mem((dev), (a))
+#elif defined(CONFIG_E500)
 #define phys_to_bus(dev, a)(a)
 #else
 #define phys_to_bus(dev, a)pci_phys_to_mem((dev), (a))
@@ -101,8 +103,12 @@ struct dc2114x_priv {
int tx_new; /* TX descriptor ring pointer */
char rx_ring_size;
char tx_ring_size;
+#ifdef CONFIG_DM_ETH
+   struct udevice  *devno;
+#else
struct eth_device   dev;
pci_dev_t   devno;
+#endif
char*name;
void __iomem*iobase;
u8  *enetaddr;
@@ -473,6 +479,7 @@ static struct pci_device_id supported[] = {
{ }
 };
 
+#ifndef CONFIG_DM_ETH
 static int dc21x4x_init(struct eth_device *dev, bd_t *bis)
 {
struct dc2114x_priv *priv =
@@ -614,3 +621,139 @@ int dc21x4x_initialize(bd_t *bis)
 
return card_number;
 }
+
+#else  /* DM_ETH */
+static int dc2114x_start(struct udevice *dev)
+{
+   struct eth_pdata *plat = dev_get_platdata(dev);
+   struct dc2114x_priv *priv = dev_get_priv(dev);
+
+   memcpy(priv->enetaddr, plat->enetaddr, sizeof(plat->enetaddr));
+
+   /* Ensure we're not sleeping. */
+   dm_pci_write_config8(dev, PCI_CFDA_PSM, WAKEUP);
+
+   return dc21x4x_init_common(priv);
+}
+
+static void dc2114x_stop(struct udevice *dev)
+{
+   struct dc2114x_priv *priv = dev_get_priv(dev);
+
+   dc21x4x_halt_common(priv);
+
+   dm_pci_write_config8(dev, PCI_CFDA_PSM, SLEEP);
+}
+
+static int dc2114x_send(struct udevice *dev, void *packet, int length)
+{
+   struct dc2114x_priv *priv = dev_get_priv(dev);
+   int ret;
+
+   ret = dc21x4x_send_common(priv, packet, length);
+
+   return ret ? 0 : -ETIMEDOUT;
+}
+
+static int dc2114x_recv(struct udevice *dev, int flags, uchar **packetp)
+{
+   struct dc2114x_priv *priv = dev_get_priv(dev);
+   int ret;
+
+   ret = dc21x4x_recv_check(priv);
+
+   if (ret < 0) {
+   /* Update entry information. */
+   priv->rx_new = (priv->rx_new + 1) % priv->rx_ring_size;
+   ret = 0;
+   }
+
+   if (!ret)
+   return 0;
+
+   *packetp = net_rx_packets[priv->rx_new];
+
+   return ret - 4;
+}
+
+static int dc2114x_free_pkt(struct udevice *dev, uchar *packet, int length)
+{
+   struct dc2114x_priv *priv = dev_get_priv(dev);
+
+   priv->rx_ring[priv->rx_new].status = cpu_to_le32(R_OWN);
+
+   /* Update entry information. */
+   priv->rx_new = (priv->rx_new + 1) % priv->rx_ring_size;
+
+   return 0;
+}
+
+static int dc2114x_read_rom_hwaddr(struct udevice *dev)
+{
+   struct dc2114x_priv *priv = dev_get_priv(dev);
+
+   read_hw_addr(priv);
+
+   return 0;
+}
+
+static int dc2114x_bind(struct udevice *dev)
+{
+   static int card_number;
+   char name[16];
+
+   sprintf(name, "dc2114x#%u", card_number++);
+
+   return device_set_name(dev, name);
+}
+
+static int dc2114x_probe(struct udevice *dev)
+{
+   struct eth_pdata *plat = dev_get_platdata(dev);
+   struct dc2114x_priv *priv = dev_get_priv(dev);
+   u16 command, status;
+   u32 iobase;
+
+   dm_pci_read_config32(dev, PCI_BASE_ADDRESS_1, &iobase);
+   iobase &= ~0xf;
+
+   debug("dc2114x: DEC 2114x PCI Device @0x%x\n", iobase);
+
+   priv->devno = dev;
+   priv->enetaddr = plat->enetaddr;
+   priv->iobase = (void __iomem *)dm_pci_mem_to_phys(dev, iobase);
+
+   command = PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER;
+   dm_pci_write_config16(dev, PCI_COMMAND, command);
+   dm_pci_read_config16(dev, PCI_COMMAND, &status);
+   if ((status & command) != command) {
+   printf("dc2114x: Couldn't enable IO access or Bus Mastering\n");
+   return -EINVAL;
+   }
+
+   dm_pci_write_config8(dev, PCI_LATENCY_TIMER, 0x60);
+
+   return 0;
+}
+
+static const struct eth_ops dc2114x_ops = {
+   .start  = dc2114x_start,
+   .send   = dc2114x_send,
+   .recv   = dc2114x_recv,
+   .stop   = dc2114x_stop,
+   .free_pkt   = dc2114x_free_pkt,
+   .read_rom_hwaddr = dc2114x_read_rom_hwaddr,
+};
+
+U_BOOT_DRIVER(eth_dc2114x) = {
+   .name   = "eth_dc2114x",
+   .id = UCLASS_ETH,
+   .bind   = dc2114x_bind,
+   .probe  = 

[PATCH 09/12] net: dc2114x: Add RX/TX rings into the private data

2020-07-11 Thread Marek Vasut
The RX/TX DMA descriptor rings are per-device-instance private data,
so move them into the private data.

Signed-off-by: Marek Vasut 
Cc: Joe Hershberger 
Cc: Ramon Fried 
---
 drivers/net/dc2114x.c | 92 +--
 1 file changed, 46 insertions(+), 46 deletions(-)

diff --git a/drivers/net/dc2114x.c b/drivers/net/dc2114x.c
index 32d2034a05..a91749584f 100644
--- a/drivers/net/dc2114x.c
+++ b/drivers/net/dc2114x.c
@@ -95,6 +95,12 @@ struct de4x5_desc {
 };
 
 struct dc2114x_priv {
+   struct de4x5_desc rx_ring[NUM_RX_DESC] __aligned(32);
+   struct de4x5_desc tx_ring[NUM_TX_DESC] __aligned(32);
+   int rx_new; /* RX descriptor ring pointer */
+   int tx_new; /* TX descriptor ring pointer */
+   char rx_ring_size;
+   char tx_ring_size;
struct eth_device   dev;
pci_dev_t   devno;
char*name;
@@ -103,14 +109,6 @@ struct dc2114x_priv {
 };
 
 /* RX and TX descriptor ring */
-static struct de4x5_desc rx_ring[NUM_RX_DESC] __aligned(32);
-static struct de4x5_desc tx_ring[NUM_TX_DESC] __aligned(32);
-static int rx_new; /* RX descriptor ring pointer */
-static int tx_new; /* TX descriptor ring pointer */
-
-static char rx_ring_size;
-static char tx_ring_size;
-
 static u32 dc2114x_inl(struct dc2114x_priv *priv, u32 addr)
 {
return le32_to_cpu(readl(priv->iobase + addr));
@@ -291,7 +289,7 @@ static void send_setup_frame(struct dc2114x_priv *priv, 
bd_t *bis)
pa += 4;
}
 
-   for (i = 0; tx_ring[tx_new].status & cpu_to_le32(T_OWN); i++) {
+   for (i = 0; priv->tx_ring[priv->tx_new].status & cpu_to_le32(T_OWN); 
i++) {
if (i < TOUT_LOOP)
continue;
 
@@ -299,14 +297,14 @@ static void send_setup_frame(struct dc2114x_priv *priv, 
bd_t *bis)
return;
}
 
-   tx_ring[tx_new].buf = cpu_to_le32(phys_to_bus(priv->devno,
+   priv->tx_ring[priv->tx_new].buf = cpu_to_le32(phys_to_bus(priv->devno,
  (u32)&setup_frame[0]));
-   tx_ring[tx_new].des1 = cpu_to_le32(TD_TER | TD_SET | SETUP_FRAME_LEN);
-   tx_ring[tx_new].status = cpu_to_le32(T_OWN);
+   priv->tx_ring[priv->tx_new].des1 = cpu_to_le32(TD_TER | TD_SET | 
SETUP_FRAME_LEN);
+   priv->tx_ring[priv->tx_new].status = cpu_to_le32(T_OWN);
 
dc2114x_outl(priv, POLL_DEMAND, DE4X5_TPD);
 
-   for (i = 0; tx_ring[tx_new].status & cpu_to_le32(T_OWN); i++) {
+   for (i = 0; priv->tx_ring[priv->tx_new].status & cpu_to_le32(T_OWN); 
i++) {
if (i < TOUT_LOOP)
continue;
 
@@ -314,12 +312,12 @@ static void send_setup_frame(struct dc2114x_priv *priv, 
bd_t *bis)
return;
}
 
-   if (le32_to_cpu(tx_ring[tx_new].status) != 0x7FFF) {
+   if (le32_to_cpu(priv->tx_ring[priv->tx_new].status) != 0x7FFF) {
printf("TX error status2 = 0x%08X\n",
-  le32_to_cpu(tx_ring[tx_new].status));
+  le32_to_cpu(priv->tx_ring[priv->tx_new].status));
}
 
-   tx_new = (tx_new + 1) % NUM_TX_DESC;
+   priv->tx_new = (priv->tx_new + 1) % NUM_TX_DESC;
 }
 
 static int dc21x4x_send(struct eth_device *dev, void *packet, int length)
@@ -334,7 +332,7 @@ static int dc21x4x_send(struct eth_device *dev, void 
*packet, int length)
goto done;
}
 
-   for (i = 0; tx_ring[tx_new].status & cpu_to_le32(T_OWN); i++) {
+   for (i = 0; priv->tx_ring[priv->tx_new].status & cpu_to_le32(T_OWN); 
i++) {
if (i < TOUT_LOOP)
continue;
 
@@ -342,14 +340,14 @@ static int dc21x4x_send(struct eth_device *dev, void 
*packet, int length)
goto done;
}
 
-   tx_ring[tx_new].buf = cpu_to_le32(phys_to_bus(priv->devno,
+   priv->tx_ring[priv->tx_new].buf = cpu_to_le32(phys_to_bus(priv->devno,
  (u32)packet));
-   tx_ring[tx_new].des1 = cpu_to_le32(TD_TER | TD_LS | TD_FS | length);
-   tx_ring[tx_new].status = cpu_to_le32(T_OWN);
+   priv->tx_ring[priv->tx_new].des1 = cpu_to_le32(TD_TER | TD_LS | TD_FS | 
length);
+   priv->tx_ring[priv->tx_new].status = cpu_to_le32(T_OWN);
 
dc2114x_outl(priv, POLL_DEMAND, DE4X5_TPD);
 
-   for (i = 0; tx_ring[tx_new].status & cpu_to_le32(T_OWN); i++) {
+   for (i = 0; priv->tx_ring[priv->tx_new].status & cpu_to_le32(T_OWN); 
i++) {
if (i < TOUT_LOOP)
continue;
 
@@ -357,25 +355,27 @@ static int dc21x4x_send(struct eth_device *dev, void 
*packet, int length)
goto done;
}
 
-   if (le32_to_cpu(tx_ring[tx_new].status) & TD_ES) {
-   tx_ring[tx_new].status = 0x0;
+   if (le32_to_cpu(priv->tx_ring[priv->tx_new].status) & TD_ES) {
+   priv->tx_ring[priv->tx_new].sta

[PATCH 08/12] net: dc2114x: Pass PCI BDF into phys_to_bus()

2020-07-11 Thread Marek Vasut
This is a trick in preparation for adding DM support. By passing in
the PCI BDF into the phys_to_bus() macros and calling that dev, we
can substitute dev with udevice when DM support lands and do minor
adjustment to the macros to support both DM and non-DM operation.
No functional change.

Signed-off-by: Marek Vasut 
Cc: Joe Hershberger 
Cc: Ramon Fried 
---
 drivers/net/dc2114x.c | 29 -
 1 file changed, 16 insertions(+), 13 deletions(-)

diff --git a/drivers/net/dc2114x.c b/drivers/net/dc2114x.c
index 0438cd3eda..32d2034a05 100644
--- a/drivers/net/dc2114x.c
+++ b/drivers/net/dc2114x.c
@@ -74,9 +74,9 @@
 #define POLL_DEMAND1
 
 #if defined(CONFIG_E500)
-#define phys_to_bus(a) (a)
+#define phys_to_bus(dev, a)(a)
 #else
-#define phys_to_bus(a) pci_phys_to_mem((pci_dev_t)dev->priv, a)
+#define phys_to_bus(dev, a)pci_phys_to_mem((dev), (a))
 #endif
 
 #define NUM_RX_DESC PKTBUFSRX
@@ -96,6 +96,7 @@ struct de4x5_desc {
 
 struct dc2114x_priv {
struct eth_device   dev;
+   pci_dev_t   devno;
char*name;
void __iomem*iobase;
u8  *enetaddr;
@@ -278,7 +279,6 @@ static int read_srom(struct dc2114x_priv *priv, u_long 
ioaddr, int index)
 
 static void send_setup_frame(struct dc2114x_priv *priv, bd_t *bis)
 {
-   struct eth_device *dev = &priv->dev;
char setup_frame[SETUP_FRAME_LEN];
char *pa = &setup_frame[0];
int i;
@@ -299,7 +299,8 @@ static void send_setup_frame(struct dc2114x_priv *priv, 
bd_t *bis)
return;
}
 
-   tx_ring[tx_new].buf = cpu_to_le32(phys_to_bus((u32)&setup_frame[0]));
+   tx_ring[tx_new].buf = cpu_to_le32(phys_to_bus(priv->devno,
+ (u32)&setup_frame[0]));
tx_ring[tx_new].des1 = cpu_to_le32(TD_TER | TD_SET | SETUP_FRAME_LEN);
tx_ring[tx_new].status = cpu_to_le32(T_OWN);
 
@@ -341,7 +342,8 @@ static int dc21x4x_send(struct eth_device *dev, void 
*packet, int length)
goto done;
}
 
-   tx_ring[tx_new].buf = cpu_to_le32(phys_to_bus((u32)packet));
+   tx_ring[tx_new].buf = cpu_to_le32(phys_to_bus(priv->devno,
+ (u32)packet));
tx_ring[tx_new].des1 = cpu_to_le32(TD_TER | TD_LS | TD_FS | length);
tx_ring[tx_new].status = cpu_to_le32(T_OWN);
 
@@ -411,11 +413,10 @@ static int dc21x4x_init(struct eth_device *dev, bd_t *bis)
 {
struct dc2114x_priv *priv =
container_of(dev, struct dc2114x_priv, dev);
-   int devbusfn = (int)dev->priv;
int i;
 
/* Ensure we're not sleeping. */
-   pci_write_config_byte(devbusfn, PCI_CFDA_PSM, WAKEUP);
+   pci_write_config_byte(priv->devno, PCI_CFDA_PSM, WAKEUP);
 
reset_de4x5(priv);
 
@@ -429,8 +430,8 @@ static int dc21x4x_init(struct eth_device *dev, bd_t *bis)
for (i = 0; i < NUM_RX_DESC; i++) {
rx_ring[i].status = cpu_to_le32(R_OWN);
rx_ring[i].des1 = cpu_to_le32(RX_BUFF_SZ);
-   rx_ring[i].buf =
-   cpu_to_le32(phys_to_bus((u32)net_rx_packets[i]));
+   rx_ring[i].buf = cpu_to_le32(phys_to_bus(priv->devno,
+(u32)net_rx_packets[i]));
rx_ring[i].next = 0;
}
 
@@ -449,8 +450,10 @@ static int dc21x4x_init(struct eth_device *dev, bd_t *bis)
tx_ring[tx_ring_size - 1].des1 |= cpu_to_le32(TD_TER);
 
/* Tell the adapter where the TX/RX rings are located. */
-   dc2114x_outl(priv, phys_to_bus((u32)&rx_ring), DE4X5_RRBA);
-   dc2114x_outl(priv, phys_to_bus((u32)&tx_ring), DE4X5_TRBA);
+   dc2114x_outl(priv, phys_to_bus(priv->devno, (u32)&rx_ring),
+DE4X5_RRBA);
+   dc2114x_outl(priv, phys_to_bus(priv->devno, (u32)&tx_ring),
+DE4X5_TRBA);
 
start_de4x5(priv);
 
@@ -466,12 +469,11 @@ static void dc21x4x_halt(struct eth_device *dev)
 {
struct dc2114x_priv *priv =
container_of(dev, struct dc2114x_priv, dev);
-   int devbusfn = (int)dev->priv;
 
stop_de4x5(priv);
dc2114x_outl(priv, 0, DE4X5_SICR);
 
-   pci_write_config_byte(devbusfn, PCI_CFDA_PSM, SLEEP);
+   pci_write_config_byte(priv->devno, PCI_CFDA_PSM, SLEEP);
 }
 
 static void read_hw_addr(struct dc2114x_priv *priv)
@@ -551,6 +553,7 @@ int dc21x4x_initialize(bd_t *bis)
dev = &priv->dev;
 
sprintf(dev->name, "dc21x4x#%d", card_number);
+   priv->devno = devbusfn;
priv->name = dev->name;
priv->enetaddr = dev->enetaddr;
 
-- 
2.27.0



Re: Please pull u-boot-dm

2020-07-11 Thread Tom Rini
On Fri, Jul 10, 2020 at 11:07:38AM -0600, Simon Glass wrote:

> Hi Tom,
> 
> Results here:
> 
> https://gitlab.denx.de/u-boot/custodians/u-boot-dm/pipelines/3981
> 
> 
> The following changes since commit 506d52308a2f5de48c2b9a08229fee9a0ee2842a:
> 
>   Merge https://gitlab.denx.de/u-boot/custodians/u-boot-x86
> (2020-07-09 09:54:22 -0400)
> 
> are available in the Git repository at:
> 
>   git://git.denx.de/u-boot-dm.git tags/dm-pull-10jul20
> 
> for you to fetch changes up to 6c3fc50ee59366df62e8345ea9fd86c3ace0c3f1:
> 
>   dtoc: add test for cd-gpios (2020-07-09 22:00:29 -0600)
> 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH v2 1/1] CI: show skipped Python tests

2020-07-11 Thread Tom Rini
On Fri, Jul 10, 2020 at 10:04:40PM +0200, Heinrich Schuchardt wrote:

> Call pytest3 with argument -ra to display the reason why Python tests are
> skipped.
> 
> The -r flag displays a test summary info for each test. -ra eliminates
> this info for passed tests.
> 
> Pros an cons were discussed in:
> https://lists.denx.de/pipermail/u-boot/2020-June/417090.html
> 
> Signed-off-by: Heinrich Schuchardt 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH 01/10] Revert "ARM: uniphier: add weird workaround code for LD20"

2020-07-11 Thread Masahiro Yamada
On Thu, Jul 9, 2020 at 3:09 PM Masahiro Yamada
 wrote:
>
> This reverts commit 45f41c134baf5ff1bbf59d33027f6c79884fa4d9.
>
> This weird workaround was the best I came up with at that time
> to boot U-Boot from TF-A.
>
> I noticed U-Boot successfully boots on LD20 (i.e. CA72 CPU) by using
> the latest TF-A.
>
> Specifically, since the following TF-A commit, U-Boot runs at EL2
> instead of EL1, and this issue went away as a side-effect.
>
> |commit f998a052fd94ea082833109f25b94ed5bfa24e8b
> |Author: Masahiro Yamada 
> |Date:   Thu Jul 25 10:57:38 2019 +0900
> |
> |uniphier: run BL33 at EL2
> |
> |All the SoCs in 64-bit UniPhier SoC family support EL2.
> |
> |Just hard-code MODE_EL2 instead of using el_implemented() helper.
> |
> |Change-Id: I7ab48002c5205bc8c013e1b46313b57d6c431db0
> |Signed-off-by: Masahiro Yamada 
>
> However, if I reverted that, this problem would come back, presumably
> because some EL1 code in U-Boot triggers this issue.
>
> Now that commit f8ddd8cbb513 ("arm64: issue ISB after updating system
> registers") fixed this issue properly, this weird workaround is no
> longer needed irrespective of the exception level at which U-Boot runs.
>
> Signed-off-by: Masahiro Yamada 
> ---


Series, applied to u-boot-uniphier.



-- 
Best Regards
Masahiro Yamada


Re: [PATCH] ARM: uniphier: remove NAND reset code

2020-07-11 Thread Masahiro Yamada
On Fri, Jul 10, 2020 at 10:32 PM Masahiro Yamada
 wrote:
>
> Now that commit fceee65c878c ("mtd: nand: raw: denali: Assert reset
> before deassert") added the reset assertion, this code in the board
> file is unneeded.
>
> Signed-off-by: Masahiro Yamada 
> ---

Applied to u-boot-uniphier.


>  arch/arm/mach-uniphier/Makefile |  1 -
>  arch/arm/mach-uniphier/board_init.c |  4 ---
>  arch/arm/mach-uniphier/init.h   |  7 -
>  arch/arm/mach-uniphier/nand-reset.c | 43 -
>  4 files changed, 55 deletions(-)
>  delete mode 100644 arch/arm/mach-uniphier/nand-reset.c
>
> diff --git a/arch/arm/mach-uniphier/Makefile b/arch/arm/mach-uniphier/Makefile
> index e7eba75eed..38b6d904f4 100644
> --- a/arch/arm/mach-uniphier/Makefile
> +++ b/arch/arm/mach-uniphier/Makefile
> @@ -22,7 +22,6 @@ endif
>  obj-$(CONFIG_MICRO_SUPPORT_CARD) += micro-support-card.o
>  obj-y += pinctrl-glue.o
>  obj-$(CONFIG_MMC) += mmc-first-dev.o
> -obj-$(CONFIG_NAND_DENALI) += nand-reset.o
>  obj-y += fdt-fixup.o
>
>  endif
> diff --git a/arch/arm/mach-uniphier/board_init.c 
> b/arch/arm/mach-uniphier/board_init.c
> index 39df91982c..528074f547 100644
> --- a/arch/arm/mach-uniphier/board_init.c
> +++ b/arch/arm/mach-uniphier/board_init.c
> @@ -125,10 +125,6 @@ int board_init(void)
> if (initdata->misc_init)
> initdata->misc_init();
>
> -   led_puts("U3");
> -
> -   uniphier_nand_reset_assert();
> -
> led_puts("Uboo");
>
> return 0;
> diff --git a/arch/arm/mach-uniphier/init.h b/arch/arm/mach-uniphier/init.h
> index a20cafdfad..dd978c0208 100644
> --- a/arch/arm/mach-uniphier/init.h
> +++ b/arch/arm/mach-uniphier/init.h
> @@ -75,13 +75,6 @@ int uniphier_have_internal_stm(void);
>  int uniphier_boot_from_backend(void);
>  int uniphier_pin_init(const char *pinconfig_name);
>
> -#ifdef CONFIG_NAND_DENALI
> -void uniphier_nand_reset_assert(void);
> -#else
> -static inline void uniphier_nand_reset_assert(void)
> -{
> -}
> -#endif
>  #ifdef CONFIG_ARM64
>  void uniphier_mem_map_init(unsigned long dram_base, unsigned long dram_size);
>  #else
> diff --git a/arch/arm/mach-uniphier/nand-reset.c 
> b/arch/arm/mach-uniphier/nand-reset.c
> deleted file mode 100644
> index 11cadaabd8..00
> --- a/arch/arm/mach-uniphier/nand-reset.c
> +++ /dev/null
> @@ -1,43 +0,0 @@
> -// SPDX-License-Identifier: GPL-2.0 or later
> -/*
> - * Copyright (C) 2020 Socionext Inc.
> - *   Author: Masahiro Yamada 
> - */
> -
> -#include 
> -#include 
> -#include 
> -#include 
> -
> -#include "init.h"
> -
> -/*
> - * Assert the Denali NAND controller reset if found.
> - *
> - * On LD4, the bootstrap process starts running after power-on reset 
> regardless
> - * of the boot mode, here the pin-mux is not necessarily set up for NAND, 
> then
> - * the controller is stuck. Assert the controller reset here, and should be
> - * deasserted in the driver after the pin-mux is correctly handled. For other
> - * SoCs, the bootstrap runs only when the boot mode selects ONFi, but it is 
> yet
> - * effective when the boot swap is on. So, the reset should be asserted 
> anyway.
> - */
> -void uniphier_nand_reset_assert(void)
> -{
> -   struct udevice *dev;
> -   struct reset_ctl_bulk resets;
> -   int ret;
> -
> -   ret = uclass_find_first_device(UCLASS_MTD, &dev);
> -   if (ret || !dev)
> -   return;
> -
> -   /* make sure this is the Denali NAND controller */
> -   if (strcmp(dev->driver->name, "denali-nand-dt"))
> -   return;
> -
> -   ret = reset_get_bulk(dev, &resets);
> -   if (ret)
> -   return;
> -
> -   reset_assert_bulk(&resets);
> -}
> --
> 2.25.1
>


-- 
Best Regards
Masahiro Yamada


Re: [PATCH 1/3] serial: uniphier: use register macros instead of structure

2020-07-11 Thread Masahiro Yamada
On Fri, Jul 10, 2020 at 1:13 AM Masahiro Yamada
 wrote:
>
> After all, I am not a big fan of using a structure to represent the
> hardware register map.
>
> You do not need to know the entire register map.
>
> Add only necessary register macros.
>
> Use FIELD_PREP() instead of maintaining a pair of shift and mask.
>
> Signed-off-by: Masahiro Yamada 
> ---

Series, applied to u-boot-uniphier.



>  drivers/serial/serial_uniphier.c | 75 ++--
>  1 file changed, 32 insertions(+), 43 deletions(-)
>
> diff --git a/drivers/serial/serial_uniphier.c 
> b/drivers/serial/serial_uniphier.c
> index c7f46e5598..2ffab004bd 100644
> --- a/drivers/serial/serial_uniphier.c
> +++ b/drivers/serial/serial_uniphier.c
> @@ -7,6 +7,8 @@
>
>  #include 
>  #include 
> +#include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -15,77 +17,67 @@
>  #include 
>  #include 
>
> -/*
> - * Note: Register map is slightly different from that of 16550.
> - */
> -struct uniphier_serial {
> -   u32 rx; /* In:  Receive buffer */
> -#define tx rx  /* Out: Transmit buffer */
> -   u32 ier;/* Interrupt Enable Register */
> -   u32 iir;/* In: Interrupt ID Register */
> -   u32 char_fcr;   /* Charactor / FIFO Control Register */
> -   u32 lcr_mcr;/* Line/Modem Control Register */
> -#define LCR_SHIFT  8
> -#define LCR_MASK   (0xff << (LCR_SHIFT))
> -   u32 lsr;/* In: Line Status Register */
> -   u32 msr;/* In: Modem Status Register */
> -   u32 __rsv0;
> -   u32 __rsv1;
> -   u32 dlr;/* Divisor Latch Register */
> -};
> +#define UNIPHIER_UART_REGSHIFT 2
> +
> +#define UNIPHIER_UART_RX   (0 << (UNIPHIER_UART_REGSHIFT))
> +#define UNIPHIER_UART_TX   UNIPHIER_UART_RX
> +/* bit[15:8] = CHAR, bit[7:0] = FCR */
> +#define UNIPHIER_UART_CHAR_FCR (3 << (UNIPHIER_UART_REGSHIFT))
> +/* bit[15:8] = LCR, bit[7:0] = MCR */
> +#define UNIPHIER_UART_LCR_MCR  (4 << (UNIPHIER_UART_REGSHIFT))
> +#define   UNIPHIER_UART_LCR_MASK   GENMASK(15, 8)
> +#define UNIPHIER_UART_LSR  (5 << (UNIPHIER_UART_REGSHIFT))
> +/* Divisor Latch Register */
> +#define UNIPHIER_UART_DLR  (9 << (UNIPHIER_UART_REGSHIFT))
>
>  struct uniphier_serial_priv {
> -   struct uniphier_serial __iomem *membase;
> +   void __iomem *membase;
> unsigned int uartclk;
>  };
>
> -#define uniphier_serial_port(dev)  \
> -   ((struct uniphier_serial_priv *)dev_get_priv(dev))->membase
> -
>  static int uniphier_serial_setbrg(struct udevice *dev, int baudrate)
>  {
> struct uniphier_serial_priv *priv = dev_get_priv(dev);
> -   struct uniphier_serial __iomem *port = uniphier_serial_port(dev);
> -   const unsigned int mode_x_div = 16;
> +   static const unsigned int mode_x_div = 16;
> unsigned int divisor;
>
> divisor = DIV_ROUND_CLOSEST(priv->uartclk, mode_x_div * baudrate);
>
> -   writel(divisor, &port->dlr);
> +   writel(divisor, priv->membase + UNIPHIER_UART_DLR);
>
> return 0;
>  }
>
>  static int uniphier_serial_getc(struct udevice *dev)
>  {
> -   struct uniphier_serial __iomem *port = uniphier_serial_port(dev);
> +   struct uniphier_serial_priv *priv = dev_get_priv(dev);
>
> -   if (!(readl(&port->lsr) & UART_LSR_DR))
> +   if (!(readl(priv->membase + UNIPHIER_UART_LSR) & UART_LSR_DR))
> return -EAGAIN;
>
> -   return readl(&port->rx);
> +   return readl(priv->membase + UNIPHIER_UART_RX);
>  }
>
>  static int uniphier_serial_putc(struct udevice *dev, const char c)
>  {
> -   struct uniphier_serial __iomem *port = uniphier_serial_port(dev);
> +   struct uniphier_serial_priv *priv = dev_get_priv(dev);
>
> -   if (!(readl(&port->lsr) & UART_LSR_THRE))
> +   if (!(readl(priv->membase + UNIPHIER_UART_LSR) & UART_LSR_THRE))
> return -EAGAIN;
>
> -   writel(c, &port->tx);
> +   writel(c, priv->membase + UNIPHIER_UART_TX);
>
> return 0;
>  }
>
>  static int uniphier_serial_pending(struct udevice *dev, bool input)
>  {
> -   struct uniphier_serial __iomem *port = uniphier_serial_port(dev);
> +   struct uniphier_serial_priv *priv = dev_get_priv(dev);
>
> if (input)
> -   return readl(&port->lsr) & UART_LSR_DR;
> +   return readl(priv->membase + UNIPHIER_UART_LSR) & UART_LSR_DR;
> else
> -   return !(readl(&port->lsr) & UART_LSR_THRE);
> +   return !(readl(priv->membase + UNIPHIER_UART_LSR) & 
> UART_LSR_THRE);
>  }
>
>  /*
> @@ -113,7 +105,6 @@ static const struct uniphier_serial_clk_data 
> uniphier_serial_clk_data[] = {
>  static int uniphier_serial_probe(struct udevice *dev)
>  {
> struct uniphier_serial_priv *priv = dev_get_priv(dev);
> -   struct uniphier_serial __iomem 

[GIT PULL] UniPhier SoC updates for v2020.10

2020-07-11 Thread Masahiro Yamada
Hi Tom,

Please pull changes for v2020.10
Thanks.



The following changes since commit 3113c84ba25ec3ceae072cc5ad450c4238425939:

  Merge tag 'rpi-next-2020.10' of
https://gitlab.denx.de/u-boot/custodians/u-boot-raspberrypi
(2020-07-10 14:31:22 -0400)

are available in the Git repository at:

  https://gitlab.denx.de/u-boot/custodians/u-boot-uniphier.git
tags/uniphier-v2020.10

for you to fetch changes up to 5785950369cd68d4409bf4d0e34d4b1894e5d0e9:

  ARM: uniphier: remove NAND reset code (2020-07-11 21:56:51 +0900)


UniPhier SoC updates for v2020.10

 - remove workaround for Cortex-A72

 - increase U-Boot proper size to 2MB

 - sync DT with Linux

 - add system bus controller driver

 - improve serial driver

 - add reset assertion to Denali NAND driver


Ley Foon Tan (2):
  mtd: nand: raw: denali: Assert reset before deassert
  mtd: nand: raw: denali: Wait for reset completion status

Masahiro Yamada (14):
  Revert "ARM: uniphier: add weird workaround code for LD20"
  ARM: uniphier: increase CONFIG_SYS_MONITOR_LEN to 2MB
  ARM: uniphier: consolidate SoC select menu
  ARM: uniphier: sync with Linux 5.8-rc4
  ARM: uniphier: fix build error when CONFIG_MICRO_SUPPORT_CARD=n
  ARM: uniphier: remove unused uniphier_sbc_init_admulti()
  ARM: uniphier: remove support for NOR Flash on support card
  bus: uniphier-system-bus: add UniPhier System Bus driver
  bus: uniphier-system-bus: move hardware init from board files
  ARM: uniphier: remove sbc/ directory
  serial: uniphier: use register macros instead of structure
  serial: uniphier: flush transmitter before changing hardware settings
  serial: uniphier: enable FIFO
  ARM: uniphier: remove NAND reset code

 arch/arm/dts/uniphier-ld11-global.dts|   1 +
 arch/arm/dts/uniphier-ld11-ref.dts   |   1 +
 arch/arm/dts/uniphier-ld11.dtsi  |  16 ++-
 arch/arm/dts/uniphier-ld20-global.dts|   1 +
 arch/arm/dts/uniphier-ld20-ref.dts   |   1 +
 arch/arm/dts/uniphier-ld20.dtsi  |  28 +---
 arch/arm/dts/uniphier-ld4.dtsi   |   2 +
 arch/arm/dts/uniphier-ld6b-ref.dts   |   1 +
 arch/arm/dts/uniphier-pro4-ace.dts   |   1 +
 arch/arm/dts/uniphier-pro4-ref.dts   |   1 +
 arch/arm/dts/uniphier-pro4.dtsi  |  10 +
 arch/arm/dts/uniphier-pro5.dtsi  |  16 ++-
 arch/arm/dts/uniphier-pxs2-gentil.dts|   1 +
 arch/arm/dts/uniphier-pxs2-vodka.dts |   1 +
 arch/arm/dts/uniphier-pxs2.dtsi  |  16 ++-
 arch/arm/dts/uniphier-pxs3-ref.dts   |  28 
 arch/arm/dts/uniphier-pxs3.dtsi  |  59 +++-
 arch/arm/dts/uniphier-sld8.dtsi  |   2 +
 arch/arm/mach-uniphier/Kconfig   |  34 +++---
 arch/arm/mach-uniphier/Makefile  |   2 -
 arch/arm/mach-uniphier/arm64/Makefile|   1 -
 arch/arm/mach-uniphier/arm64/lowlevel_init.S |  13 --
 arch/arm/mach-uniphier/board_init.c  |  44 --
 arch/arm/mach-uniphier/boot-device/boot-device.c |   9 +++-
 arch/arm/mach-uniphier/init.h|  35 ---
 arch/arm/mach-uniphier/micro-support-card.c  | 110
+
 arch/arm/mach-uniphier/nand-reset.c  |  43 --
 arch/arm/mach-uniphier/sbc/Makefile  |  15 ---
 arch/arm/mach-uniphier/sbc/sbc-boot.c|  13 --
 arch/arm/mach-uniphier/sbc/sbc-ld11.c|  26 ---
 arch/arm/mach-uniphier/sbc/sbc-ld4.c |  25 ---
 arch/arm/mach-uniphier/sbc/sbc-pxs2.c|  23 --
 arch/arm/mach-uniphier/sbc/sbc-regs.h|  82
-
 arch/arm/mach-uniphier/sbc/sbc.c |  95
---
 configs/uniphier_ld4_sld8_defconfig  |   4 --
 configs/uniphier_v7_defconfig|   3 --
 configs/uniphier_v8_defconfig|   3 --
 drivers/Kconfig  |   2 +
 drivers/Makefile |   1 +
 drivers/bus/Kconfig  |  16 +++
 drivers/bus/Makefile |   6 +++
 drivers/bus/uniphier-system-bus.c| 100
+
 drivers/mtd/nand/raw/denali.c|  11 +
 drivers/mtd/nand/raw/denali.h|   1 +
 drivers/mtd/nand/raw/denali_dt.c |   8 +++-
 drivers/serial/serial_uniphier.c |  90
+++--
 include/configs/uniphier.h   |  24 +-
 47 f

Re: [PATCH v3 14/25] x86: mp: Park CPUs before running the OS

2020-07-11 Thread Simon Glass
Hi Bin,

On Tue, 7 Jul 2020 at 19:55, Simon Glass  wrote:
>
> Hi Bin,
>
> On Tue, 7 Jul 2020 at 02:26, Bin Meng  wrote:
> >
> > Hi Simon,
> >
> > On Mon, Jul 6, 2020 at 11:37 AM Simon Glass  wrote:
> > >
> > > With the new MP features the CPUs are no-longer parked when the OS is run.
> > > Fix this by calling a special function to park them, just before the OS is
> > > started.
> > >
> > > Signed-off-by: Simon Glass 
> > > Reviewed-by: Wolfgang Wallner 
> > > ---
> > >
> > > Changes in v3:
> > > - Update the comment for mp_park_aps()
> > >
> > >  arch/x86/cpu/cpu.c|  5 +
> > >  arch/x86/cpu/mp_init.c| 18 ++
> > >  arch/x86/include/asm/mp.h | 17 +
> > >  3 files changed, 40 insertions(+)
>
> OK. Sorry but I missed this.
>
> If there are no other comments I can just update this patch.
>

OK I sent a new version of that patch.

Regards,
Simon


[PATCH v5 14/25] x86: mp: Park CPUs before running the OS

2020-07-11 Thread Simon Glass
With the new MP features the CPUs are no-longer parked when the OS is run.
Fix this by calling a special function to park them, just before the OS is
started.

Signed-off-by: Simon Glass 
Reviewed-by: Wolfgang Wallner 
---

Changes in v5:
- Drop timing in mp_park_aps()

Changes in v3:
- Update the comment for mp_park_aps()

 arch/x86/cpu/cpu.c|  5 +
 arch/x86/cpu/mp_init.c| 16 
 arch/x86/include/asm/mp.h | 17 +
 3 files changed, 38 insertions(+)

diff --git a/arch/x86/cpu/cpu.c b/arch/x86/cpu/cpu.c
index d0720fb7fb..baa7dae172 100644
--- a/arch/x86/cpu/cpu.c
+++ b/arch/x86/cpu/cpu.c
@@ -66,6 +66,11 @@ static const char *const x86_vendor_name[] = {
 
 int __weak x86_cleanup_before_linux(void)
 {
+   int ret;
+
+   ret = mp_park_aps();
+   if (ret)
+   return log_msg_ret("park", ret);
bootstage_stash((void *)CONFIG_BOOTSTAGE_STASH_ADDR,
CONFIG_BOOTSTAGE_STASH_SIZE);
 
diff --git a/arch/x86/cpu/mp_init.c b/arch/x86/cpu/mp_init.c
index dd6d6bfab7..427ec8fc23 100644
--- a/arch/x86/cpu/mp_init.c
+++ b/arch/x86/cpu/mp_init.c
@@ -668,6 +668,22 @@ int mp_run_on_cpus(int cpu_select, mp_run_func func, void 
*arg)
return 0;
 }
 
+static void park_this_cpu(void *unused)
+{
+   stop_this_cpu();
+}
+
+int mp_park_aps(void)
+{
+   int ret;
+
+   ret = mp_run_on_cpus(MP_SELECT_APS, park_this_cpu, NULL);
+   if (ret)
+   return log_ret(ret);
+
+   return 0;
+}
+
 int mp_init(void)
 {
int num_aps, num_cpus;
diff --git a/arch/x86/include/asm/mp.h b/arch/x86/include/asm/mp.h
index eb49e690f2..f9d6c8e6bf 100644
--- a/arch/x86/include/asm/mp.h
+++ b/arch/x86/include/asm/mp.h
@@ -109,6 +109,15 @@ typedef void (*mp_run_func)(void *arg);
  * @return 0 on success, -ve on error
  */
 int mp_run_on_cpus(int cpu_select, mp_run_func func, void *arg);
+
+/**
+ * mp_park_aps() - Park the APs ready for the OS
+ *
+ * This halts all CPUs except the main one, ready for the OS to use them
+ *
+ * @return 0 if OK, -ve on error
+ */
+int mp_park_aps(void);
 #else
 static inline int mp_run_on_cpus(int cpu_select, mp_run_func func, void *arg)
 {
@@ -117,6 +126,14 @@ static inline int mp_run_on_cpus(int cpu_select, 
mp_run_func func, void *arg)
 
return 0;
 }
+
+static inline int mp_park_aps(void)
+{
+   /* No APs to park */
+
+   return 0;
+}
+
 #endif
 
 #endif /* _X86_MP_H_ */
-- 
2.27.0.389.gc38d7665816-goog



Re: [PATCH 00/16] spi: dm-conversion (part3)

2020-07-11 Thread Jagan Teki
On Wed, Jul 8, 2020 at 6:25 PM Stefano Babic  wrote:
>
> On 08.07.20 13:40, Jagan Teki wrote:
> > On Sat, Jun 13, 2020 at 9:11 PM Tom Rini  wrote:
> >>
> >> On Sat, Jun 13, 2020 at 07:24:39PM +0530, Jagan Teki wrote:
> >>
> >>> This series updated boards which are using mxc_spi
> >>> driver.
> >>>
> >>> Series has patches for
> >>> 1) DM_SPI/SPI_FLASH enablement for boards which
> >>>already support DM and OF_CONTROL.
> >>> 2) Drop the boards which doesn't support DM or OF_CONTROL.
> >>>
> >>> Now it's call for board maintainers to update their
> >>> board to use device tree and DM options to alive
> >>> on tree before MW.
>
> A couple of boards (pcm058, for example) were already updated. Some
> other boards are strongly maintained and I get patches for them (dh6 for
> example), so I guess it is enough to CC the board maintainers again
> asking to update. We can check later how many boards will still remain.

Thanks. I have marked the missing board maintainers. Hope to resolve
this before MW.

Jagan.


Pull request: u-boot-spi/master

2020-07-11 Thread Jagan Teki
Hi Tom,

This PR about dm migration and other SF fixes.

Summary:
- Enable DM_SPI on siemens omap boards (Jagan)
- Dropped some non-dm supported omap3 boards (Jagan) 
- Dropped non-dm code in omap3 spi driver (Jagan)
- Dropped non-dm code in kirkwood spi driver (Bhargav)

Travis CI:
https://travis-ci.org/github/openedev/u-boot-amarula/builds/707124445

Any inputs?
Jagan.

The following changes since commit d9107930af63d88c2d84560db19e65f1a51c4cbd:

  Merge tag 'for-v2020.10' of 
https://gitlab.denx.de/u-boot/custodians/u-boot-i2c (2020-07-09 08:22:44 -0400)

are available in the Git repository at:

  https://gitlab.denx.de/u-boot/custodians/u-boot-spi master

for you to fetch changes up to 18c56605c6cd45cb3e1ea39e2a9df46d4eade7ae:

  doc: driver-model: Update SPI migration status (2020-07-10 12:39:54 +0530)


Bhargav Shah (1):
  spi: kirkwood: Drop nondm code

Jagan Teki (19):
  am335x: igep003x: Enable DM_SPI
  siemens: draco: Enable DM_SPI, DM_SPI_FLASH
  siemens: etamin: Enable DM_SPI, DM_SPI_FLASH
  siemens: rastaban: Enable DM_SPI, DM_SPI_FLASH
  siemens: thuban: Enable DM_SPI, DM_SPI_FLASH
  siemens: pxm2: Enable DM_SPI, DM_SPI_FLASH
  siemens: rut: Enable DM_SPI, DM_SPI_FLASH
  arm: Remove cm_t54 board
  arm: Remove cm_t35 board
  arm: Remove overo board
  logicpd: Drop omap3 zoom1
  arm: Remove cairo board
  arm: Remove bav335x board
  arm: Remove pepper board
  arm: Remove pengwyn board
  db-88f6281-bp-nand: Enable DM_SPI/SPI_FLASH
  spi: omap3: Drop nondm code
  arm: Remove mx31pdk board
  doc: driver-model: Update SPI migration status

Johannes Holland (1):
  spi: add support for all spi modes with soft spi

Pragnesh Patel (1):
  mtd: spi-nor: Enable QE bit for ISSI flash in case of SFDP

 arch/arm/Kconfig |   3 -
 arch/arm/mach-imx/mx3/Kconfig|   1 -
 arch/arm/mach-omap2/am33xx/Kconfig   |  29 --
 arch/arm/mach-omap2/omap3/Kconfig|  18 --
 arch/arm/mach-omap2/omap4/Kconfig|   4 -
 arch/arm/mach-omap2/omap5/Kconfig|   1 -
 board/birdland/bav335x/Kconfig   |  23 --
 board/birdland/bav335x/Makefile  |  11 -
 board/birdland/bav335x/README|  31 --
 board/birdland/bav335x/board.c   | 432 --
 board/birdland/bav335x/board.h   |  58 
 board/birdland/bav335x/mux.c | 190 
 board/birdland/bav335x/u-boot.lds| 115 ---
 board/compulab/cm_t35/Kconfig|  12 -
 board/compulab/cm_t35/MAINTAINERS|   6 -
 board/compulab/cm_t35/Makefile   |   8 -
 board/compulab/cm_t35/cm_t35.c   | 513 ---
 board/compulab/cm_t54/Kconfig|  12 -
 board/compulab/cm_t54/MAINTAINERS|   6 -
 board/compulab/cm_t54/Makefile   |   8 -
 board/compulab/cm_t54/cm_t54.c   | 261 
 board/compulab/cm_t54/mux.c  |  94 --
 board/compulab/cm_t54/spl.c  |  65 
 board/freescale/mx31pdk/Kconfig  |  15 -
 board/freescale/mx31pdk/MAINTAINERS  |   6 -
 board/freescale/mx31pdk/Makefile |  11 -
 board/freescale/mx31pdk/lowlevel_init.S  |  76 -
 board/freescale/mx31pdk/mx31pdk.c| 119 ---
 board/gumstix/duovero/Kconfig|  12 -
 board/gumstix/duovero/MAINTAINERS|   6 -
 board/gumstix/duovero/Makefile   |   6 -
 board/gumstix/duovero/duovero.c  | 273 
 board/gumstix/duovero/duovero_mux_data.h | 198 
 board/gumstix/pepper/Kconfig |  15 -
 board/gumstix/pepper/MAINTAINERS |   6 -
 board/gumstix/pepper/Makefile|  11 -
 board/gumstix/pepper/board.c | 288 -
 board/gumstix/pepper/board.h |  31 --
 board/gumstix/pepper/mux.c   |  82 -
 board/logicpd/zoom1/Kconfig  |  12 -
 board/logicpd/zoom1/MAINTAINERS  |   6 -
 board/logicpd/zoom1/Makefile |   6 -
 board/logicpd/zoom1/config.mk|  14 -
 board/logicpd/zoom1/zoom1.c  | 148 -
 board/logicpd/zoom1/zoom1.h  | 122 
 board/overo/Kconfig  |   9 -
 board/overo/MAINTAINERS  |   6 -
 board/overo/Makefile |  10 -
 board/overo/common.c | 368 --
 board/overo/overo.c  | 411 -
 board/overo/overo.h  | 169 --
 board/overo/spl.c|  61 
 board/quipos/cairo/Kconfig   |  12 -
 board/quipos/cairo/MAINTAINERS   |   6 -
 board/quipos/cairo/Makefile  |   6 -
 board/quipos/cairo/cairo.c   |  98 --
 board/quipos/cairo/cairo.h   | 318 ---
 board/silica/

Re: [GIT PULL] UniPhier SoC updates for v2020.10

2020-07-11 Thread Tom Rini
On Sat, Jul 11, 2020 at 11:35:12PM +0900, Masahiro Yamada wrote:

> Hi Tom,
> 
> Please pull changes for v2020.10
> Thanks.
> 
> 
> 
> The following changes since commit 3113c84ba25ec3ceae072cc5ad450c4238425939:
> 
>   Merge tag 'rpi-next-2020.10' of
> https://gitlab.denx.de/u-boot/custodians/u-boot-raspberrypi
> (2020-07-10 14:31:22 -0400)
> 
> are available in the Git repository at:
> 
>   https://gitlab.denx.de/u-boot/custodians/u-boot-uniphier.git
> tags/uniphier-v2020.10
> 
> for you to fetch changes up to 5785950369cd68d4409bf4d0e34d4b1894e5d0e9:
> 
>   ARM: uniphier: remove NAND reset code (2020-07-11 21:56:51 +0900)
> 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: Pull request for UEFI sub-system for efi-2020-10-rc1 (2)

2020-07-11 Thread Heinrich Schuchardt
On 7/11/20 2:16 PM, Tom Rini wrote:
> On Sat, Jul 11, 2020 at 09:00:16AM +0200, Heinrich Schuchardt wrote:
>> On 7/10/20 8:09 PM, Tom Rini wrote:
>>> On Thu, Jul 09, 2020 at 06:12:02PM +0200, Heinrich Schuchardt wrote:
>>>
 The following changes since commit 
 61608f395e7dcb2be6060407a72a1149b046430a:

   Merge branch '2020-07-08-misc-features-and-fixes' (2020-07-08 20:20:24
 -0400)

 are available in the Git repository at:

   https://gitlab.denx.de/u-boot/custodians/u-boot-efi.git efi-2020-10-rc1-2

 for you to fetch changes up to f4cef8e7585c268f05a8c39e368ca115c25e40d5:

   efi_selftest: adjust runtime test for variables (2020-07-09 12:08:41
 +0200)

>>>
>>> NAK.  This is reliably failing here:
>>> https://gitlab.denx.de/u-boot/u-boot/-/jobs/122018
>>>
>>> I see it passed Azure, and hasn't run through Travis yet.  Maybe it
>>> needs to be run repeatedly to fail and we just got "lucky" ?
>>>
>>
>> Hello Tom,
>>
>> you saw unreproducible results with multiple runs failing and one run
>> succeeding. The reason is that when signing with sign-efi-sig-list in
>> out Python tests without passing a timestamp two signatures may be in
>> the same second or not.
>>
>> When using the signed files to set UEFI variables a variable can only be
>> overwritten by a file with a newer timestamp. But without setting
>> timestamps explicitly using parameter -t passed to sign-efi-sig-list we
>> have no control.
>>
>> I already fixed this for some elder tests but missed to fix this for the
>> merged patches from Takahiro.
>
> Ah, thanks for the explanation.
>

Hello Tom,

what I still do not understand why tests are sometimes skipped and
sometimes not for the same source code:

https://gitlab.denx.de/u-boot/u-boot/-/jobs/122018
Commit 7068e523

140 test/py/tests/test_efi_secboot/test_authvar.py .
141 test/py/tests/test_efi_secboot/test_signed.py .F
142 test/py/tests/test_efi_secboot/test_unsigned.py ...

https://gitlab.denx.de/u-boot/custodians/u-boot-efi/-/jobs/122155
Commit 7068e523

148 test/py/tests/test_efi_secboot/test_authvar.py s
149 test/py/tests/test_efi_secboot/test_signed.py ss
150 test/py/tests/test_efi_secboot/test_unsigned.py sss

Both runs used the same Docker image
trini/u-boot-gitlab-ci-runner:bionic-20200526-18Jun2020

What influence have different versions of the Gitlab runner?

gitlab-runner 13.1.1
gitlab-runner 12.2.0

Some of our tests create and delete files in /tmp. How are parallel jobs
separated in Gitlab?

Best regards

Heinrich


[PATCH v4 02/17] efi_loader: display RO attribute in printenv -e

2020-07-11 Thread Heinrich Schuchardt
Let the 'printenv -e' command display the read only flag.
If the variable is time authenticated write the time stamp.

Avoid EFI_CALL() when calling SetVariable() and GetVariable().

Signed-off-by: Heinrich Schuchardt 
---
 cmd/nvedit_efi.c | 24 
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/cmd/nvedit_efi.c b/cmd/nvedit_efi.c
index 29cad38e19..3f61d5d6cc 100644
--- a/cmd/nvedit_efi.c
+++ b/cmd/nvedit_efi.c
@@ -9,11 +9,13 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 

@@ -34,6 +36,7 @@ static const struct {
{EFI_VARIABLE_RUNTIME_ACCESS, "RT"},
{EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS, "AW"},
{EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS, "AT"},
+   {EFI_VARIABLE_READ_ONLY, "RO"},
 };

 static const struct {
@@ -87,20 +90,22 @@ static void efi_dump_single_var(u16 *name, const efi_guid_t 
*guid, bool verbose)
 {
u32 attributes;
u8 *data;
+   u64 time;
+   struct rtc_time tm;
efi_uintn_t size;
int count, i;
efi_status_t ret;

data = NULL;
size = 0;
-   ret = EFI_CALL(efi_get_variable(name, guid, &attributes, &size, data));
+   ret = efi_get_variable_int(name, guid, &attributes, &size, data, &time);
if (ret == EFI_BUFFER_TOO_SMALL) {
data = malloc(size);
if (!data)
goto out;

-   ret = EFI_CALL(efi_get_variable(name, guid, &attributes, &size,
-   data));
+   ret = efi_get_variable_int(name, guid, &attributes, &size,
+  data, &time);
}
if (ret == EFI_NOT_FOUND) {
printf("Error: \"%ls\" not defined\n", name);
@@ -109,13 +114,16 @@ static void efi_dump_single_var(u16 *name, const 
efi_guid_t *guid, bool verbose)
if (ret != EFI_SUCCESS)
goto out;

-   printf("%ls:\n%s:", name, efi_guid_to_str(guid));
+   rtc_to_tm(time, &tm);
+   printf("%ls:\n%s:\n", name, efi_guid_to_str(guid));
+   if (attributes & EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS)
+   printf("%04d-%02d-%02d %02d:%02d:%02d\n", tm.tm_year,
+  tm.tm_mon, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
+   printf("");
for (count = 0, i = 0; i < ARRAY_SIZE(efi_var_attrs); i++)
if (attributes & efi_var_attrs[i].mask) {
if (count)
putc('|');
-   else
-   putc(' ');
count++;
puts(efi_var_attrs[i].text);
}
@@ -592,8 +600,8 @@ int do_env_set_efi(struct cmd_tbl *cmdtp, int flag, int 
argc,
p = var_name16;
utf8_utf16_strncpy(&p, var_name, len + 1);

-   ret = EFI_CALL(efi_set_variable(var_name16, &guid, attributes,
-   size, value));
+   ret = efi_set_variable_int(var_name16, &guid, attributes, size, value,
+  true);
unmap_sysmem(value);
if (ret == EFI_SUCCESS) {
ret = CMD_RET_SUCCESS;
--
2.27.0



[PATCH v4 04/17] efi_loader: OsIndicationsSupported, PlatformLangCodes

2020-07-11 Thread Heinrich Schuchardt
UEFI variables OsIndicationsSupported, PlatformLangCodes should be read
only.

Avoid EFI_CALL() for SetVariable().

Signed-off-by: Heinrich Schuchardt 
---
 lib/efi_loader/efi_setup.c | 59 --
 1 file changed, 31 insertions(+), 28 deletions(-)

diff --git a/lib/efi_loader/efi_setup.c b/lib/efi_loader/efi_setup.c
index a3b05a4a9b..6196c0a06c 100644
--- a/lib/efi_loader/efi_setup.c
+++ b/lib/efi_loader/efi_setup.c
@@ -8,6 +8,7 @@
 #include 
 #include 
 #include 
+#include 

 #define OBJ_LIST_NOT_INITIALIZED 1

@@ -40,12 +41,13 @@ static efi_status_t efi_init_platform_lang(void)
 * Variable PlatformLangCodes defines the language codes that the
 * machine can support.
 */
-   ret = EFI_CALL(efi_set_variable(L"PlatformLangCodes",
-   &efi_global_variable_guid,
-   EFI_VARIABLE_BOOTSERVICE_ACCESS |
-   EFI_VARIABLE_RUNTIME_ACCESS,
-   sizeof(CONFIG_EFI_PLATFORM_LANG_CODES),
-   CONFIG_EFI_PLATFORM_LANG_CODES));
+   ret = efi_set_variable_int(L"PlatformLangCodes",
+  &efi_global_variable_guid,
+  EFI_VARIABLE_BOOTSERVICE_ACCESS |
+  EFI_VARIABLE_RUNTIME_ACCESS |
+  EFI_VARIABLE_READ_ONLY,
+  sizeof(CONFIG_EFI_PLATFORM_LANG_CODES),
+  CONFIG_EFI_PLATFORM_LANG_CODES, false);
if (ret != EFI_SUCCESS)
goto out;

@@ -53,9 +55,9 @@ static efi_status_t efi_init_platform_lang(void)
 * Variable PlatformLang defines the language that the machine has been
 * configured for.
 */
-   ret = EFI_CALL(efi_get_variable(L"PlatformLang",
-   &efi_global_variable_guid,
-   NULL, &data_size, &pos));
+   ret = efi_get_variable_int(L"PlatformLang",
+  &efi_global_variable_guid,
+  NULL, &data_size, &pos, NULL);
if (ret == EFI_BUFFER_TOO_SMALL) {
/* The variable is already set. Do not change it. */
ret = EFI_SUCCESS;
@@ -70,12 +72,12 @@ static efi_status_t efi_init_platform_lang(void)
if (pos)
*pos = 0;

-   ret = EFI_CALL(efi_set_variable(L"PlatformLang",
-   &efi_global_variable_guid,
-   EFI_VARIABLE_NON_VOLATILE |
-   EFI_VARIABLE_BOOTSERVICE_ACCESS |
-   EFI_VARIABLE_RUNTIME_ACCESS,
-   1 + strlen(lang), lang));
+   ret = efi_set_variable_int(L"PlatformLang",
+  &efi_global_variable_guid,
+  EFI_VARIABLE_NON_VOLATILE |
+  EFI_VARIABLE_BOOTSERVICE_ACCESS |
+  EFI_VARIABLE_RUNTIME_ACCESS,
+  1 + strlen(lang), lang, false);
 out:
if (ret != EFI_SUCCESS)
printf("EFI: cannot initialize platform language settings\n");
@@ -96,13 +98,13 @@ static efi_status_t efi_init_secure_boot(void)
};
efi_status_t ret;

-   /* TODO: read-only */
-   ret = EFI_CALL(efi_set_variable(L"SignatureSupport",
-   &efi_global_variable_guid,
-   EFI_VARIABLE_BOOTSERVICE_ACCESS
-| EFI_VARIABLE_RUNTIME_ACCESS,
-   sizeof(signature_types),
-   &signature_types));
+   ret = efi_set_variable_int(L"SignatureSupport",
+  &efi_global_variable_guid,
+  EFI_VARIABLE_BOOTSERVICE_ACCESS |
+  EFI_VARIABLE_RUNTIME_ACCESS |
+  EFI_VARIABLE_READ_ONLY,
+  sizeof(signature_types),
+  &signature_types, false);
if (ret != EFI_SUCCESS)
printf("EFI: cannot initialize SignatureSupport variable\n");

@@ -160,12 +162,13 @@ efi_status_t efi_init_obj_list(void)
goto out;

/* Indicate supported features */
-   ret = EFI_CALL(efi_set_variable(L"OsIndicationsSupported",
-   &efi_global_variable_guid,
-   EFI_VARIABLE_BOOTSERVICE_ACCESS |
-   EFI_VARIABLE_RUNTIME_ACCESS,
-   sizeof(os_indications_supported),
-   &os_indicat

[PATCH v4 00/17] efi_loader: non-volatile and runtime variables

2020-07-11 Thread Heinrich Schuchardt
With this patch series file ubootefi.var in the EFI system partition is
used for saving UEFI variables.

Furthermore the UEFI variables are exposed for reading at runtime.

v4:
Correct appending of variables when using the memory based store.
Performance enhancement for the memory based store.
v3:
Use efi_var_mem_ins() when restoring variables from file.
Remove EFI_VARIABLE_READ_ONLY attribute in runtime GetVariable().
Avoid setting efi_runtime_services.set_variable twice.
v2:
Rebase the series to consider OP-TEE based variables and
authenticated variables.
Do not enable SetVariable() at runtime as we cannot persist
non-volatile variables at runtime.
Display read-only attribute in printenv -e.

Heinrich Schuchardt (17):
  efi_loader: prepare for read only OP-TEE variables
  efi_loader: display RO attribute in printenv -e
  efi_loader: separate UEFI variable API from implemementation
  efi_loader: OsIndicationsSupported, PlatformLangCodes
  efi_loader: simplify boot manager
  efi_loader: keep attributes in efi_set_variable_int
  efi_loader: value of VendorKeys
  efi_loader: read-only AuditMode and DeployedMode
  efi_loader: secure boot flag
  efi_loader: UEFI variable persistence
  efi_loader: export efi_convert_pointer()
  efi_loader: optional pointer for ConvertPointer
  efi_loader: new function efi_memcpy_runtime()
  efi_loader: memory buffer for variables
  efi_loader: use memory based variable storage
  efi_loader: enable UEFI variables at runtime
  efi_selftest: adjust runtime test for variables

 cmd/nvedit_efi.c  |  24 +-
 doc/api/efi.rst   |   2 +
 include/efi_api.h |   2 +
 include/efi_loader.h  |   6 +
 include/efi_variable.h| 198 +
 lib/efi_loader/Kconfig|   8 +
 lib/efi_loader/Makefile   |   3 +
 lib/efi_loader/efi_bootmgr.c  |  28 +-
 lib/efi_loader/efi_runtime.c  |  35 +-
 lib/efi_loader/efi_setup.c|  59 +-
 lib/efi_loader/efi_var_common.c   | 140 +++
 lib/efi_loader/efi_var_file.c | 239 +
 lib/efi_loader/efi_var_mem.c  | 266 ++
 lib/efi_loader/efi_variable.c | 836 --
 lib/efi_loader/efi_variable_tee.c | 130 +--
 .../efi_selftest_variables_runtime.c  |  13 +-
 16 files changed, 1162 insertions(+), 827 deletions(-)
 create mode 100644 include/efi_variable.h
 create mode 100644 lib/efi_loader/efi_var_common.c
 create mode 100644 lib/efi_loader/efi_var_file.c
 create mode 100644 lib/efi_loader/efi_var_mem.c

--
2.27.0



[PATCH v4 05/17] efi_loader: simplify boot manager

2020-07-11 Thread Heinrich Schuchardt
Simplify the implementation of the UEFI boot manager:

* avoid EFI_CALL for SetVariable() and GetVariable()
* remove unnecessary type conversions

Signed-off-by: Heinrich Schuchardt 
---
 lib/efi_loader/efi_bootmgr.c | 28 
 1 file changed, 12 insertions(+), 16 deletions(-)

diff --git a/lib/efi_loader/efi_bootmgr.c b/lib/efi_loader/efi_bootmgr.c
index e268e9c4b8..e03198b57a 100644
--- a/lib/efi_loader/efi_bootmgr.c
+++ b/lib/efi_loader/efi_bootmgr.c
@@ -12,6 +12,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 

 static const struct efi_boot_services *bs;
@@ -147,15 +148,14 @@ unsigned long efi_serialize_load_option(struct 
efi_load_option *lo, u8 **data)
 static void *get_var(u16 *name, const efi_guid_t *vendor,
 efi_uintn_t *size)
 {
-   efi_guid_t *v = (efi_guid_t *)vendor;
efi_status_t ret;
void *buf = NULL;

*size = 0;
-   EFI_CALL(ret = rs->get_variable(name, v, NULL, size, buf));
+   ret = efi_get_variable_int(name, vendor, NULL, size, buf, NULL);
if (ret == EFI_BUFFER_TOO_SMALL) {
buf = malloc(*size);
-   EFI_CALL(ret = rs->get_variable(name, v, NULL, size, buf));
+   ret = efi_get_variable_int(name, vendor, NULL, size, buf, NULL);
}

if (ret != EFI_SUCCESS) {
@@ -219,10 +219,9 @@ static efi_status_t try_load_entry(u16 n, efi_handle_t 
*handle)
attributes = EFI_VARIABLE_BOOTSERVICE_ACCESS |
 EFI_VARIABLE_RUNTIME_ACCESS;
size = sizeof(n);
-   ret = EFI_CALL(efi_set_variable(
-   L"BootCurrent",
-   (efi_guid_t *)&efi_global_variable_guid,
-   attributes, size, &n));
+   ret = efi_set_variable_int(L"BootCurrent",
+  &efi_global_variable_guid,
+  attributes, size, &n, false);
if (ret != EFI_SUCCESS) {
if (EFI_CALL(efi_unload_image(*handle))
!= EFI_SUCCESS)
@@ -262,22 +261,19 @@ efi_status_t efi_bootmgr_load(efi_handle_t *handle)
rs = systab.runtime;

/* BootNext */
-   bootnext = 0;
size = sizeof(bootnext);
-   ret = EFI_CALL(efi_get_variable(L"BootNext",
-   (efi_guid_t *)&efi_global_variable_guid,
-   NULL, &size, &bootnext));
+   ret = efi_get_variable_int(L"BootNext",
+  &efi_global_variable_guid,
+  NULL, &size, &bootnext, NULL);
if (ret == EFI_SUCCESS || ret == EFI_BUFFER_TOO_SMALL) {
/* BootNext does exist here */
if (ret == EFI_BUFFER_TOO_SMALL || size != sizeof(u16))
log_err("BootNext must be 16-bit integer\n");

/* delete BootNext */
-   ret = EFI_CALL(efi_set_variable(
-   L"BootNext",
-   (efi_guid_t *)&efi_global_variable_guid,
-   EFI_VARIABLE_NON_VOLATILE, 0,
-   &bootnext));
+   ret = efi_set_variable_int(L"BootNext",
+  &efi_global_variable_guid,
+  0, 0, NULL, false);

/* load BootNext */
if (ret == EFI_SUCCESS) {
--
2.27.0



[PATCH v4 06/17] efi_loader: keep attributes in efi_set_variable_int

2020-07-11 Thread Heinrich Schuchardt
Do not change the value of parameter attributes in function
efi_set_variable_int(). This allows to use it later.

Do not use variable attr for different purposes but declare separate
variables (attr and old_attr).

Signed-off-by: Heinrich Schuchardt 
---
 lib/efi_loader/efi_variable.c | 24 
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/lib/efi_loader/efi_variable.c b/lib/efi_loader/efi_variable.c
index 36bac86702..c9980ca692 100644
--- a/lib/efi_loader/efi_variable.c
+++ b/lib/efi_loader/efi_variable.c
@@ -827,7 +827,7 @@ efi_status_t efi_set_variable_int(u16 *variable_name, const 
efi_guid_t *vendor,
efi_uintn_t old_size;
bool append, delete;
u64 time = 0;
-   u32 attr;
+   u32 old_attr;
efi_status_t ret = EFI_SUCCESS;

if (!variable_name || !*variable_name || !vendor ||
@@ -843,8 +843,8 @@ efi_status_t efi_set_variable_int(u16 *variable_name, const 
efi_guid_t *vendor,

/* check if a variable exists */
old_size = 0;
-   attr = 0;
-   ret = efi_get_variable_int(variable_name, vendor, &attr,
+   old_attr = 0;
+   ret = efi_get_variable_int(variable_name, vendor, &old_attr,
   &old_size, NULL, &time);
append = !!(attributes & EFI_VARIABLE_APPEND_WRITE);
attributes &= ~(u32)EFI_VARIABLE_APPEND_WRITE;
@@ -852,15 +852,15 @@ efi_status_t efi_set_variable_int(u16 *variable_name, 
const efi_guid_t *vendor,

/* check attributes */
if (old_size) {
-   if (ro_check && (attr & EFI_VARIABLE_READ_ONLY)) {
+   if (ro_check && (old_attr & EFI_VARIABLE_READ_ONLY)) {
ret = EFI_WRITE_PROTECTED;
goto err;
}

/* attributes won't be changed */
if (!delete &&
-   ((ro_check && attr != attributes) ||
-(!ro_check && ((attr & ~(u32)EFI_VARIABLE_READ_ONLY)
+   ((ro_check && old_attr != attributes) ||
+(!ro_check && ((old_attr & ~(u32)EFI_VARIABLE_READ_ONLY)
!= (attributes & 
~(u32)EFI_VARIABLE_READ_ONLY) {
ret = EFI_INVALID_PARAMETER;
goto err;
@@ -902,7 +902,7 @@ efi_status_t efi_set_variable_int(u16 *variable_name, const 
efi_guid_t *vendor,
EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS) {
ret = efi_variable_authenticate(variable_name, vendor,
&data_size, &data,
-   attributes, &attr,
+   attributes, &old_attr,
&time);
if (ret != EFI_SUCCESS)
goto err;
@@ -936,7 +936,7 @@ efi_status_t efi_set_variable_int(u16 *variable_name, const 
efi_guid_t *vendor,
goto err;
}
ret = efi_get_variable_int(variable_name, vendor,
-  &attr, &old_size, old_data, NULL);
+  &old_attr, &old_size, old_data, 
NULL);
if (ret != EFI_SUCCESS)
goto err;
} else {
@@ -962,8 +962,8 @@ efi_status_t efi_set_variable_int(u16 *variable_name, const 
efi_guid_t *vendor,
   EFI_VARIABLE_RUNTIME_ACCESS |
   EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS);
s += sprintf(s, "{");
-   while (attributes) {
-   attr = 1 << (ffs(attributes) - 1);
+   for (u32 attr_rem = attributes; attr_rem;) {
+   u32 attr = 1 << (ffs(attr_rem) - 1);

if (attr == EFI_VARIABLE_READ_ONLY) {
s += sprintf(s, "ro");
@@ -979,8 +979,8 @@ efi_status_t efi_set_variable_int(u16 *variable_name, const 
efi_guid_t *vendor,
s = bin2hex(s, (u8 *)&time, sizeof(time));
}

-   attributes &= ~attr;
-   if (attributes)
+   attr_rem &= ~attr;
+   if (attr_rem)
s += sprintf(s, ",");
}
s += sprintf(s, "}");
--
2.27.0



[PATCH v4 08/17] efi_loader: read-only AuditMode and DeployedMode

2020-07-11 Thread Heinrich Schuchardt
Set the read only property of the UEFI variables AuditMode and DeployedMode
conforming to the UEFI specification.

Signed-off-by: Heinrich Schuchardt 
---
 lib/efi_loader/efi_variable.c | 22 +-
 1 file changed, 13 insertions(+), 9 deletions(-)

diff --git a/lib/efi_loader/efi_variable.c b/lib/efi_loader/efi_variable.c
index 2f8005bd95..4bd976e44a 100644
--- a/lib/efi_loader/efi_variable.c
+++ b/lib/efi_loader/efi_variable.c
@@ -183,32 +183,36 @@ static const char *parse_attr(const char *str, u32 
*attrp, u64 *timep)
 static efi_status_t efi_set_secure_state(u8 secure_boot, u8 setup_mode,
 u8 audit_mode, u8 deployed_mode)
 {
-   u32 attributes;
efi_status_t ret;
+   const u32 attributes_ro = EFI_VARIABLE_BOOTSERVICE_ACCESS |
+ EFI_VARIABLE_RUNTIME_ACCESS |
+ EFI_VARIABLE_READ_ONLY;
+   const u32 attributes_rw = EFI_VARIABLE_BOOTSERVICE_ACCESS |
+ EFI_VARIABLE_RUNTIME_ACCESS;

-   attributes = EFI_VARIABLE_BOOTSERVICE_ACCESS |
-EFI_VARIABLE_RUNTIME_ACCESS |
-EFI_VARIABLE_READ_ONLY;
ret = efi_set_variable_int(L"SecureBoot", &efi_global_variable_guid,
-  attributes, sizeof(secure_boot),
+  attributes_ro, sizeof(secure_boot),
   &secure_boot, false);
if (ret != EFI_SUCCESS)
goto err;

ret = efi_set_variable_int(L"SetupMode", &efi_global_variable_guid,
-  attributes, sizeof(setup_mode),
+  attributes_ro, sizeof(setup_mode),
   &setup_mode, false);
if (ret != EFI_SUCCESS)
goto err;

ret = efi_set_variable_int(L"AuditMode", &efi_global_variable_guid,
-  attributes, sizeof(audit_mode),
-  &audit_mode, false);
+  audit_mode || setup_mode ?
+  attributes_ro : attributes_rw,
+  sizeof(audit_mode), &audit_mode, false);
if (ret != EFI_SUCCESS)
goto err;

ret = efi_set_variable_int(L"DeployedMode",
-  &efi_global_variable_guid, attributes,
+  &efi_global_variable_guid,
+  audit_mode || deployed_mode || setup_mode ?
+  attributes_ro : attributes_rw,
   sizeof(deployed_mode), &deployed_mode,
   false);
 err:
--
2.27.0



[PATCH v4 01/17] efi_loader: prepare for read only OP-TEE variables

2020-07-11 Thread Heinrich Schuchardt
We currently have two implementations of UEFI variables:

* variables provided via an OP-TEE module
* variables stored in the U-Boot environment

Read only variables are up to now only implemented in the U-Boot
environment implementation.

Provide a common interface for both implementations that allows handling
read-only variables.

As variable access is limited to very few source files put variable
related definitions into new include efi_variable.h instead of efi_loader.

Signed-off-by: Heinrich Schuchardt 
---
 doc/api/efi.rst   |   2 +
 include/efi_variable.h|  43 
 lib/efi_loader/Makefile   |   1 +
 lib/efi_loader/efi_var_common.c   |  78 +
 lib/efi_loader/efi_variable.c | 175 --
 lib/efi_loader/efi_variable_tee.c |  75 -
 6 files changed, 193 insertions(+), 181 deletions(-)
 create mode 100644 include/efi_variable.h
 create mode 100644 lib/efi_loader/efi_var_common.c

diff --git a/doc/api/efi.rst b/doc/api/efi.rst
index d5114f05b3..cb2a1c897e 100644
--- a/doc/api/efi.rst
+++ b/doc/api/efi.rst
@@ -93,6 +93,8 @@ Runtime services
 Variable services
 ~

+.. kernel-doc:: include/efi_variable.h
+   :internal:
 .. kernel-doc:: lib/efi_loader/efi_variable.c
:internal:

diff --git a/include/efi_variable.h b/include/efi_variable.h
new file mode 100644
index 00..6789118eba
--- /dev/null
+++ b/include/efi_variable.h
@@ -0,0 +1,43 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright (c) 2020, Heinrich Schuchardt 
+ */
+
+#ifndef _EFI_VARIABLE_H
+#define _EFI_VARIABLE_H
+
+#include 
+
+#define EFI_VARIABLE_READ_ONLY BIT(31)
+
+/**
+ * efi_get_variable() - retrieve value of a UEFI variable
+ *
+ * @variable_name: name of the variable
+ * @vendor:vendor GUID
+ * @attributes:attributes of the variable
+ * @data_size: size of the buffer to which the variable value is copied
+ * @data:  buffer to which the variable value is copied
+ * @timep: authentication time (seconds since start of epoch)
+ * Return: status code
+ */
+efi_status_t efi_get_variable_int(u16 *variable_name, const efi_guid_t *vendor,
+ u32 *attributes, efi_uintn_t *data_size,
+ void *data, u64 *timep);
+
+/**
+ * efi_set_variable() - set value of a UEFI variable
+ *
+ * @variable_name: name of the variable
+ * @vendor:vendor GUID
+ * @attributes:attributes of the variable
+ * @data_size: size of the buffer with the variable value
+ * @data:  buffer with the variable value
+ * @ro_check:  check the read only read only bit in attributes
+ * Return: status code
+ */
+efi_status_t efi_set_variable_int(u16 *variable_name, const efi_guid_t *vendor,
+ u32 attributes, efi_uintn_t data_size,
+ const void *data, bool ro_check);
+
+#endif
diff --git a/lib/efi_loader/Makefile b/lib/efi_loader/Makefile
index 57c7e66ea0..7eddd7ef37 100644
--- a/lib/efi_loader/Makefile
+++ b/lib/efi_loader/Makefile
@@ -35,6 +35,7 @@ obj-y += efi_root_node.o
 obj-y += efi_runtime.o
 obj-y += efi_setup.o
 obj-$(CONFIG_EFI_UNICODE_COLLATION_PROTOCOL2) += efi_unicode_collation.o
+obj-y += efi_var_common.o
 ifeq ($(CONFIG_EFI_MM_COMM_TEE),y)
 obj-y += efi_variable_tee.o
 else
diff --git a/lib/efi_loader/efi_var_common.c b/lib/efi_loader/efi_var_common.c
new file mode 100644
index 00..6a4efa3f27
--- /dev/null
+++ b/lib/efi_loader/efi_var_common.c
@@ -0,0 +1,78 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * UEFI runtime variable services
+ *
+ * Copyright (c) 2020, Heinrich Schuchardt 
+ */
+
+#include 
+#include 
+#include 
+
+/**
+ * efi_efi_get_variable() - retrieve value of a UEFI variable
+ *
+ * This function implements the GetVariable runtime service.
+ *
+ * See the Unified Extensible Firmware Interface (UEFI) specification for
+ * details.
+ *
+ * @variable_name: name of the variable
+ * @vendor:vendor GUID
+ * @attributes:attributes of the variable
+ * @data_size: size of the buffer to which the variable value is copied
+ * @data:  buffer to which the variable value is copied
+ * Return: status code
+ */
+efi_status_t EFIAPI efi_get_variable(u16 *variable_name,
+const efi_guid_t *vendor, u32 *attributes,
+efi_uintn_t *data_size, void *data)
+{
+   efi_status_t ret;
+
+   EFI_ENTRY("\"%ls\" %pUl %p %p %p", variable_name, vendor, attributes,
+ data_size, data);
+
+   ret = efi_get_variable_int(variable_name, vendor, attributes,
+  data_size, data, NULL);
+
+   /* Remove EFI_VARIABLE_READ_ONLY flag */
+   if (attributes)
+   *attributes &= EFI_VARIABLE_MASK

[PATCH v4 07/17] efi_loader: value of VendorKeys

2020-07-11 Thread Heinrich Schuchardt
According to the UEFI specification the variable VendorKeys is 1 if the
"system is configured to use only vendor-provided keys".

As we do not supply any vendor keys yet the variable VendorKeys must be
zero.

Signed-off-by: Heinrich Schuchardt 
---
 lib/efi_loader/efi_variable.c | 75 +++
 1 file changed, 15 insertions(+), 60 deletions(-)

diff --git a/lib/efi_loader/efi_variable.c b/lib/efi_loader/efi_variable.c
index c9980ca692..2f8005bd95 100644
--- a/lib/efi_loader/efi_variable.c
+++ b/lib/efi_loader/efi_variable.c
@@ -282,45 +282,29 @@ err:
  */
 static efi_status_t efi_init_secure_state(void)
 {
-   enum efi_secure_mode mode;
-   efi_uintn_t size;
+   enum efi_secure_mode mode = EFI_MODE_SETUP;
+   efi_uintn_t size = 0;
efi_status_t ret;

-   /*
-* TODO:
-* Since there is currently no "platform-specific" installation
-* method of Platform Key, we can't say if VendorKeys is 0 or 1
-* precisely.
-*/
-
-   size = 0;
ret = efi_get_variable_int(L"PK", &efi_global_variable_guid,
   NULL, &size, NULL, NULL);
if (ret == EFI_BUFFER_TOO_SMALL) {
if (IS_ENABLED(CONFIG_EFI_SECURE_BOOT))
mode = EFI_MODE_USER;
-   else
-   mode = EFI_MODE_SETUP;
-
-   efi_vendor_keys = 0;
-   } else if (ret == EFI_NOT_FOUND) {
-   mode = EFI_MODE_SETUP;
-   efi_vendor_keys = 1;
-   } else {
-   goto err;
}

ret = efi_transfer_secure_state(mode);
-   if (ret == EFI_SUCCESS)
-   ret = efi_set_variable_int(L"VendorKeys",
-  &efi_global_variable_guid,
-  EFI_VARIABLE_BOOTSERVICE_ACCESS |
-  EFI_VARIABLE_RUNTIME_ACCESS |
-  EFI_VARIABLE_READ_ONLY,
-  sizeof(efi_vendor_keys),
-  &efi_vendor_keys, false);
+   if (ret != EFI_SUCCESS)
+   return ret;

-err:
+   /* As we do not provide vendor keys this variable is always 0. */
+   ret = efi_set_variable_int(L"VendorKeys",
+  &efi_global_variable_guid,
+  EFI_VARIABLE_BOOTSERVICE_ACCESS |
+  EFI_VARIABLE_RUNTIME_ACCESS |
+  EFI_VARIABLE_READ_ONLY,
+  sizeof(efi_vendor_keys),
+  &efi_vendor_keys, false);
return ret;
 }

@@ -998,39 +982,10 @@ out:
if (env_set(native_name, val)) {
ret = EFI_DEVICE_ERROR;
} else {
-   bool vendor_keys_modified = false;
-
-   if ((u16_strcmp(variable_name, L"PK") == 0 &&
-guidcmp(vendor, &efi_global_variable_guid) == 0)) {
-   ret = efi_transfer_secure_state(
-   (delete ? EFI_MODE_SETUP :
- EFI_MODE_USER));
-   if (ret != EFI_SUCCESS)
-   goto err;
-
-   if (efi_secure_mode != EFI_MODE_SETUP)
-   vendor_keys_modified = true;
-   } else if ((u16_strcmp(variable_name, L"KEK") == 0 &&
-guidcmp(vendor, &efi_global_variable_guid) == 0)) {
-   if (efi_secure_mode != EFI_MODE_SETUP)
-   vendor_keys_modified = true;
-   }
-
-   /* update VendorKeys */
-   if (vendor_keys_modified & efi_vendor_keys) {
-   efi_vendor_keys = 0;
-   ret = efi_set_variable_int(
-   L"VendorKeys",
-   &efi_global_variable_guid,
-   EFI_VARIABLE_BOOTSERVICE_ACCESS
-| EFI_VARIABLE_RUNTIME_ACCESS
-| EFI_VARIABLE_READ_ONLY,
-   sizeof(efi_vendor_keys),
-   &efi_vendor_keys,
-   false);
-   } else {
+   if (!u16_strcmp(variable_name, L"PK"))
+   ret = efi_init_secure_state();
+   else
ret = EFI_SUCCESS;
-   }
}

 err:
--
2.27.0



[PATCH v4 03/17] efi_loader: separate UEFI variable API from implemementation

2020-07-11 Thread Heinrich Schuchardt
Separate the remaining UEFI variable API functions GetNextVariableName and
QueryVariableInfo() from internal functions implementing them.

Signed-off-by: Heinrich Schuchardt 
---
 include/efi_variable.h| 39 +++
 lib/efi_loader/efi_var_common.c   | 62 +++
 lib/efi_loader/efi_variable.c | 56 
 lib/efi_loader/efi_variable_tee.c | 55 +--
 4 files changed, 133 insertions(+), 79 deletions(-)

diff --git a/include/efi_variable.h b/include/efi_variable.h
index 6789118eba..3ba274fce1 100644
--- a/include/efi_variable.h
+++ b/include/efi_variable.h
@@ -40,4 +40,43 @@ efi_status_t efi_set_variable_int(u16 *variable_name, const 
efi_guid_t *vendor,
  u32 attributes, efi_uintn_t data_size,
  const void *data, bool ro_check);

+/**
+ * efi_get_next_variable_name_int() - enumerate the current variable names
+ *
+ * @variable_name_size:size of variable_name buffer in byte
+ * @variable_name: name of uefi variable's name in u16
+ * @vendor:vendor's guid
+ *
+ * See the Unified Extensible Firmware Interface (UEFI) specification for
+ * details.
+ *
+ * Return: status code
+ */
+efi_status_t efi_get_next_variable_name_int(efi_uintn_t *variable_name_size,
+   u16 *variable_name,
+   efi_guid_t *vendor);
+
+/**
+ * efi_query_variable_info_int() - get information about EFI variables
+ *
+ * This function implements the QueryVariableInfo() runtime service.
+ *
+ * See the Unified Extensible Firmware Interface (UEFI) specification for
+ * details.
+ *
+ * @attributes:bitmask to select variables to 
be
+ * queried
+ * @maximum_variable_storage_size: maximum size of storage area for the
+ * selected variable types
+ * @remaining_variable_storage_size:   remaining size of storage are for the
+ * selected variable types
+ * @maximum_variable_size: maximum size of a variable of the
+ * selected type
+ * Returns:status code
+ */
+efi_status_t efi_query_variable_info_int(u32 attributes,
+u64 *maximum_variable_storage_size,
+u64 *remaining_variable_storage_size,
+u64 *maximum_variable_size);
+
 #endif
diff --git a/lib/efi_loader/efi_var_common.c b/lib/efi_loader/efi_var_common.c
index 6a4efa3f27..1e2be1135b 100644
--- a/lib/efi_loader/efi_var_common.c
+++ b/lib/efi_loader/efi_var_common.c
@@ -76,3 +76,65 @@ efi_status_t EFIAPI efi_set_variable(u16 *variable_name,

return EFI_EXIT(ret);
 }
+
+/**
+ * efi_get_next_variable_name() - enumerate the current variable names
+ *
+ * @variable_name_size:size of variable_name buffer in byte
+ * @variable_name: name of uefi variable's name in u16
+ * @vendor:vendor's guid
+ *
+ * See the Unified Extensible Firmware Interface (UEFI) specification for
+ * details.
+ *
+ * Return: status code
+ */
+efi_status_t EFIAPI efi_get_next_variable_name(efi_uintn_t *variable_name_size,
+  u16 *variable_name,
+  efi_guid_t *vendor)
+{
+   efi_status_t ret;
+
+   EFI_ENTRY("%p \"%ls\" %pUl", variable_name_size, variable_name, vendor);
+
+   ret = efi_get_next_variable_name_int(variable_name_size, variable_name,
+vendor);
+
+   return EFI_EXIT(ret);
+}
+
+/**
+ * efi_query_variable_info() - get information about EFI variables
+ *
+ * This function implements the QueryVariableInfo() runtime service.
+ *
+ * See the Unified Extensible Firmware Interface (UEFI) specification for
+ * details.
+ *
+ * @attributes:bitmask to select variables to 
be
+ * queried
+ * @maximum_variable_storage_size: maximum size of storage area for the
+ * selected variable types
+ * @remaining_variable_storage_size:   remaining size of storage are for the
+ * selected variable types
+ * @maximum_variable_size: maximum size of a variable of the
+ * selected type
+ * Returns:status code
+ */
+efi_status_t EFIAPI efi_query_variable_info(
+   u32 attributes, u64 *maximum_variable_storage_size,
+   u64 *remaining_variable_storage_size,
+   u64 *maximum_variable_size)
+{
+   efi_status_t ret;
+
+   EFI_ENTRY("%x %p %p %p", attributes, maximum_variable_storage_size,
+

[PATCH v4 10/17] efi_loader: UEFI variable persistence

2020-07-11 Thread Heinrich Schuchardt
Persist non-volatile UEFI variables in a file on the EFI system partition.

The file is written whenever a non-volatile UEFI variable is changed after
initialization of the UEFI sub-system.

The file is read during the UEFI sub-system initialization to restore
non-volatile UEFI variables.

Signed-off-by: Heinrich Schuchardt 
---
 include/efi_variable.h|  62 +
 lib/efi_loader/Kconfig|   8 ++
 lib/efi_loader/Makefile   |   1 +
 lib/efi_loader/efi_var_file.c | 239 ++
 lib/efi_loader/efi_variable.c |  10 +-
 5 files changed, 319 insertions(+), 1 deletion(-)
 create mode 100644 lib/efi_loader/efi_var_file.c

diff --git a/include/efi_variable.h b/include/efi_variable.h
index 3ba274fce1..01054209c4 100644
--- a/include/efi_variable.h
+++ b/include/efi_variable.h
@@ -79,4 +79,66 @@ efi_status_t efi_query_variable_info_int(u32 attributes,
 u64 *remaining_variable_storage_size,
 u64 *maximum_variable_size);

+#define EFI_VAR_FILE_NAME "ubootefi.var"
+
+#define EFI_VAR_BUF_SIZE 0x4000
+
+#define EFI_VAR_FILE_MAGIC 0x0161566966456255 /* UbEfiVa, version 1 */
+
+/**
+ * struct efi_var_entry - UEFI variable file entry
+ *
+ * @length:length of enty, multiple of 8
+ * @attr:  variable attributes
+ * @time:  authentication time (seconds since start of epoch)
+ * @guid:  vendor GUID
+ * @name:  UTF16 variable name
+ */
+struct efi_var_entry {
+   u32 length;
+   u32 attr;
+   u64 time;
+   efi_guid_t guid;
+   u16 name[];
+};
+
+/**
+ * struct efi_var_file - file for storing UEFI variables
+ *
+ * @reserved:  unused, may be overwritten by memory probing
+ * @magic: identifies file format
+ * @length:length including header
+ * @crc32: CRC32 without header
+ * @var:   variables
+ */
+struct efi_var_file {
+   u64 reserved;
+   u64 magic;
+   u32 length;
+   u32 crc32;
+   struct efi_var_entry var[];
+};
+
+/**
+ * efi_var_to_file() - save non-volatile variables as file
+ *
+ * File ubootefi.var is created on the EFI system partion.
+ *
+ * Return: status code
+ */
+efi_status_t efi_var_to_file(void);
+
+/**
+ * efi_var_from_file() - read variables from file
+ *
+ * File ubootefi.var is read from the EFI system partitions and the variables
+ * stored in the file are created.
+ *
+ * In case the file does not exist yet or a variable cannot be set EFI_SUCCESS
+ * is returned.
+ *
+ * Return: status code
+ */
+efi_status_t efi_var_from_file(void);
+
 #endif
diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig
index 6c9df3a767..4324694d48 100644
--- a/lib/efi_loader/Kconfig
+++ b/lib/efi_loader/Kconfig
@@ -27,6 +27,14 @@ config EFI_LOADER

 if EFI_LOADER

+config EFI_VARIABLE_FILE_STORE
+   bool "Store non-volatile UEFI variables as file"
+   depends on FAT_WRITE
+   default y
+   help
+ Select tis option if you want non-volatile UEFI variables to be stored
+ as file /ubootefi.var on the EFI system partition.
+
 config EFI_GET_TIME
bool "GetTime() runtime service"
depends on DM_RTC
diff --git a/lib/efi_loader/Makefile b/lib/efi_loader/Makefile
index 7eddd7ef37..c87b82db32 100644
--- a/lib/efi_loader/Makefile
+++ b/lib/efi_loader/Makefile
@@ -40,6 +40,7 @@ ifeq ($(CONFIG_EFI_MM_COMM_TEE),y)
 obj-y += efi_variable_tee.o
 else
 obj-y += efi_variable.o
+obj-y += efi_var_file.o
 endif
 obj-y += efi_watchdog.o
 obj-$(CONFIG_LCD) += efi_gop.o
diff --git a/lib/efi_loader/efi_var_file.c b/lib/efi_loader/efi_var_file.c
new file mode 100644
index 00..b1b7532495
--- /dev/null
+++ b/lib/efi_loader/efi_var_file.c
@@ -0,0 +1,239 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * File interface for UEFI variables
+ *
+ * Copyright (c) 2020, Heinrich Schuchardt
+ */
+
+#define LOG_CATEGORY LOGC_EFI
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define PART_STR_LEN 10
+
+/**
+ * efi_set_blk_dev_to_system_partition() - select EFI system partition
+ *
+ * Set the EFI system partition as current block device.
+ *
+ * Return: status code
+ */
+static efi_status_t __maybe_unused efi_set_blk_dev_to_system_partition(void)
+{
+   char part_str[PART_STR_LEN];
+   int r;
+
+   if (!efi_system_partition.if_type) {
+   log_err("No EFI system partition\n");
+   return EFI_DEVICE_ERROR;
+   }
+   snprintf(part_str, PART_STR_LEN, "%u:%u",
+efi_system_partition.devnum, efi_system_partition.part);
+   r = fs_set_blk_dev(blk_get_if_type_name(efi_system_partition.if_type),
+  part_str, FS_TYPE_ANY);
+   if (r) {
+   log_err("Cannot read EFI system partition\n");
+   return EFI_DEVICE_ERROR;
+   }
+   return EFI_SUCCESS;
+}
+
+/**
+ * efi_var_collect() - collect non-volatile variables in buffer
+ *
+ * 

[PATCH v4 13/17] efi_loader: new function efi_memcpy_runtime()

2020-07-11 Thread Heinrich Schuchardt
Provide a memcpy() function that we can use at UEFI runtime.

Signed-off-by: Heinrich Schuchardt 
---
 include/efi_loader.h |  3 +++
 lib/efi_loader/efi_runtime.c | 19 +++
 2 files changed, 22 insertions(+)

diff --git a/include/efi_loader.h b/include/efi_loader.h
index be6cede92f..98944640be 100644
--- a/include/efi_loader.h
+++ b/include/efi_loader.h
@@ -792,6 +792,9 @@ 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);

+/* runtime implementation of memcpy() */
+void efi_memcpy_runtime(void *dest, const void *src, size_t n);
+
 #else /* CONFIG_IS_ENABLED(EFI_LOADER) */

 /* Without CONFIG_EFI_LOADER we don't have a runtime section, stub it out */
diff --git a/lib/efi_loader/efi_runtime.c b/lib/efi_loader/efi_runtime.c
index a4aa1d8b6c..5b6506fbdc 100644
--- a/lib/efi_loader/efi_runtime.c
+++ b/lib/efi_loader/efi_runtime.c
@@ -137,6 +137,25 @@ efi_status_t efi_init_runtime_supported(void)
return ret;
 }

+/**
+ * efi_memcpy_runtime() - copy memory area
+ *
+ * At runtime memcpy() is not available.
+ *
+ * @dest:  destination buffer
+ * @src:   source buffer
+ * @n: number of bytes to copy
+ * Return: pointer to destination buffer
+ */
+void __efi_runtime efi_memcpy_runtime(void *dest, const void *src, size_t n)
+{
+   u8 *d = dest;
+   const u8 *s = src;
+
+   for (; n; --n)
+   *d++ = *s++;
+}
+
 /**
  * efi_update_table_header_crc32() - Update crc32 in table header
  *
--
2.27.0



[PATCH v4 09/17] efi_loader: secure boot flag

2020-07-11 Thread Heinrich Schuchardt
In audit mode the UEFI variable SecureBoot is set to zero but the
efi_secure_boot flag is set to true.

The efi_secure_boot flag should match the UEFIvariable SecureBoot.

Signed-off-by: Heinrich Schuchardt 
---
 lib/efi_loader/efi_variable.c | 8 ++--
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/lib/efi_loader/efi_variable.c b/lib/efi_loader/efi_variable.c
index 4bd976e44a..0d6bafc76d 100644
--- a/lib/efi_loader/efi_variable.c
+++ b/lib/efi_loader/efi_variable.c
@@ -190,6 +190,8 @@ static efi_status_t efi_set_secure_state(u8 secure_boot, u8 
setup_mode,
const u32 attributes_rw = EFI_VARIABLE_BOOTSERVICE_ACCESS |
  EFI_VARIABLE_RUNTIME_ACCESS;

+   efi_secure_boot = secure_boot;
+
ret = efi_set_variable_int(L"SecureBoot", &efi_global_variable_guid,
   attributes_ro, sizeof(secure_boot),
   &secure_boot, false);
@@ -240,8 +242,6 @@ static efi_status_t efi_transfer_secure_state(enum 
efi_secure_mode mode)
ret = efi_set_secure_state(1, 0, 0, 1);
if (ret != EFI_SUCCESS)
goto err;
-
-   efi_secure_boot = true;
} else if (mode == EFI_MODE_AUDIT) {
ret = efi_set_variable_int(L"PK", &efi_global_variable_guid,
   EFI_VARIABLE_BOOTSERVICE_ACCESS |
@@ -253,14 +253,10 @@ static efi_status_t efi_transfer_secure_state(enum 
efi_secure_mode mode)
ret = efi_set_secure_state(0, 1, 1, 0);
if (ret != EFI_SUCCESS)
goto err;
-
-   efi_secure_boot = true;
} else if (mode == EFI_MODE_USER) {
ret = efi_set_secure_state(1, 0, 0, 0);
if (ret != EFI_SUCCESS)
goto err;
-
-   efi_secure_boot = true;
} else if (mode == EFI_MODE_SETUP) {
ret = efi_set_secure_state(0, 1, 0, 0);
if (ret != EFI_SUCCESS)
--
2.27.0



[PATCH v4 14/17] efi_loader: memory buffer for variables

2020-07-11 Thread Heinrich Schuchardt
Saving UEFI variable as encoded U-Boot environment variables does not allow
support at runtime.

Provide functions to manage a memory buffer with UEFI variables.

Signed-off-by: Heinrich Schuchardt 
---
v4:
Use memmove() instead of a loop for copying
Set efi_current_var in efi_var_mem_compare() to speed up finding
variables.
---
 include/efi_variable.h   |  54 +++
 lib/efi_loader/Makefile  |   1 +
 lib/efi_loader/efi_var_mem.c | 266 +++
 3 files changed, 321 insertions(+)
 create mode 100644 lib/efi_loader/efi_var_mem.c

diff --git a/include/efi_variable.h b/include/efi_variable.h
index 01054209c4..bc5985cfdb 100644
--- a/include/efi_variable.h
+++ b/include/efi_variable.h
@@ -141,4 +141,58 @@ efi_status_t efi_var_to_file(void);
  */
 efi_status_t efi_var_from_file(void);

+/**
+ * efi_var_mem_init() - set-up variable list
+ *
+ * Return: status code
+ */
+efi_status_t efi_var_mem_init(void);
+
+/**
+ * efi_var_mem_find() - find a variable in the list
+ *
+ * @guid:  GUID of the variable
+ * @name:  name of the variable
+ * @next:  on exit pointer to the next variable after the found one
+ * Return: found variable
+ */
+struct efi_var_entry *efi_var_mem_find(const efi_guid_t *guid, const u16 *name,
+  struct efi_var_entry **next);
+
+/**
+ * efi_var_mem_del() - delete a variable from the list of variables
+ *
+ * @var:   variable to delete
+ */
+void efi_var_mem_del(struct efi_var_entry *var);
+
+/**
+ * efi_var_mem_ins() - append a variable to the list of variables
+ *
+ * The variable is appended without checking if a variable of the same name
+ * already exists. The two data buffers are concatenated.
+ *
+ * @variable_name: variable name
+ * @vendor:GUID
+ * @attributes:variable attributes
+ * @size1: size of the first data buffer
+ * @data1: first data buffer
+ * @size2: size of the second data field
+ * @data2: second data buffer
+ * @time:  time of authentication (as seconds since start of epoch)
+ * Result: status code
+ */
+efi_status_t efi_var_mem_ins(u16 *variable_name,
+const efi_guid_t *vendor, u32 attributes,
+const efi_uintn_t size1, const void *data1,
+const efi_uintn_t size2, const void *data2,
+const u64 time);
+
+/**
+ * efi_var_mem_free() - determine free memory for variables
+ *
+ * Return: maximum data size plus variable name size
+ */
+u64 efi_var_mem_free(void);
+
 #endif
diff --git a/lib/efi_loader/Makefile b/lib/efi_loader/Makefile
index c87b82db32..f81ec8d277 100644
--- a/lib/efi_loader/Makefile
+++ b/lib/efi_loader/Makefile
@@ -36,6 +36,7 @@ obj-y += efi_runtime.o
 obj-y += efi_setup.o
 obj-$(CONFIG_EFI_UNICODE_COLLATION_PROTOCOL2) += efi_unicode_collation.o
 obj-y += efi_var_common.o
+obj-y += efi_var_mem.o
 ifeq ($(CONFIG_EFI_MM_COMM_TEE),y)
 obj-y += efi_variable_tee.o
 else
diff --git a/lib/efi_loader/efi_var_mem.c b/lib/efi_loader/efi_var_mem.c
new file mode 100644
index 00..7a2dba7dc2
--- /dev/null
+++ b/lib/efi_loader/efi_var_mem.c
@@ -0,0 +1,266 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * File interface for UEFI variables
+ *
+ * Copyright (c) 2020, Heinrich Schuchardt
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+static struct efi_var_file __efi_runtime_data *efi_var_buf;
+static struct efi_var_entry __efi_runtime_data *efi_current_var;
+
+/**
+ * efi_var_mem_compare() - compare GUID and name with a variable
+ *
+ * @var:   variable to compare
+ * @guid:  GUID to compare
+ * @name:  variable name to compare
+ * @next:  pointer to next variable
+ * Return: true if match
+ */
+static bool __efi_runtime
+efi_var_mem_compare(struct efi_var_entry *var, const efi_guid_t *guid,
+   const u16 *name, struct efi_var_entry **next)
+{
+   int i;
+   u8 *guid1, *guid2;
+   const u16 *data, *var_name;
+   bool match = true;
+
+   for (guid1 = (u8 *)&var->guid, guid2 = (u8 *)guid, i = 0;
+i < sizeof(efi_guid_t) && match; ++i)
+   match = (guid1[i] == guid2[i]);
+
+   for (data = var->name, var_name = name;; ++data, ++var_name) {
+   if (match)
+   match = (*data == *var_name);
+   if (!*data)
+   break;
+   }
+
+   ++data;
+
+   if (next)
+   *next = (struct efi_var_entry *)
+   ALIGN((uintptr_t)data + var->length, 8);
+
+   if (match)
+   efi_current_var = var;
+
+   return match;
+}
+
+struct efi_var_entry __efi_runtime
+*efi_var_mem_find(const efi_guid_t *guid, const u16 *name,
+ struct efi_var_entry **next)
+{
+   struct efi_var_entry *var, *last;
+
+   last = (struct efi_var_entry *)
+  

[PATCH v4 12/17] efi_loader: optional pointer for ConvertPointer

2020-07-11 Thread Heinrich Schuchardt
If the EFI_OPTIONAL_PTR is set in DebugDisposition, a NULL pointer does not
constitute an invalid parameter.

Signed-off-by: Heinrich Schuchardt 
---
 include/efi_api.h| 2 ++
 lib/efi_loader/efi_runtime.c | 6 ++
 2 files changed, 8 insertions(+)

diff --git a/include/efi_api.h b/include/efi_api.h
index 759d911875..5744f6aed8 100644
--- a/include/efi_api.h
+++ b/include/efi_api.h
@@ -251,6 +251,8 @@ struct efi_rt_properties_table {
u32 runtime_services_supported;
 };

+#define EFI_OPTIONAL_PTR   0x0001
+
 struct efi_runtime_services {
struct efi_table_hdr hdr;
efi_status_t (EFIAPI *get_time)(struct efi_time *time,
diff --git a/lib/efi_loader/efi_runtime.c b/lib/efi_loader/efi_runtime.c
index 45baa2fd3e..a4aa1d8b6c 100644
--- a/lib/efi_loader/efi_runtime.c
+++ b/lib/efi_loader/efi_runtime.c
@@ -512,6 +512,12 @@ efi_convert_pointer(efi_uintn_t debug_disposition, void 
**address)
ret = EFI_INVALID_PARAMETER;
goto out;
}
+   if (!*address) {
+   if (debug_disposition & EFI_OPTIONAL_PTR)
+   return EFI_SUCCESS;
+   else
+   return EFI_INVALID_PARAMETER;
+   }

addr = (uintptr_t)*address;
for (i = 0; i < efi_descriptor_count; i++) {
--
2.27.0



[PATCH v4 11/17] efi_loader: export efi_convert_pointer()

2020-07-11 Thread Heinrich Schuchardt
We need ConvertPointer() to adjust pointers when implementing  runtime
services within U-Boot.

After ExitBootServices() gd is not available anymore. So we should not use
EFI_ENTRY() and EFI_EXIT().

Signed-off-by: Heinrich Schuchardt 
---
 include/efi_loader.h | 3 +++
 lib/efi_loader/efi_runtime.c | 8 +++-
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/include/efi_loader.h b/include/efi_loader.h
index ceabbaadd0..be6cede92f 100644
--- a/include/efi_loader.h
+++ b/include/efi_loader.h
@@ -397,6 +397,9 @@ efi_status_t efi_root_node_register(void);
 efi_status_t efi_initialize_system_table(void);
 /* efi_runtime_detach() - detach unimplemented runtime functions */
 void efi_runtime_detach(void);
+/* efi_convert_pointer() - convert pointer to virtual address */
+efi_status_t EFIAPI efi_convert_pointer(efi_uintn_t debug_disposition,
+   void **address);
 /* Called by bootefi to make console interface available */
 efi_status_t efi_console_register(void);
 /* Called by bootefi to make all disk storage accessible as EFI objects */
diff --git a/lib/efi_loader/efi_runtime.c b/lib/efi_loader/efi_runtime.c
index 121e2f65c6..45baa2fd3e 100644
--- a/lib/efi_loader/efi_runtime.c
+++ b/lib/efi_loader/efi_runtime.c
@@ -496,15 +496,13 @@ static __efi_runtime efi_status_t EFIAPI 
efi_convert_pointer_runtime(
  * @address:   pointer to be converted
  * Return: status code
  */
-static __efi_runtime efi_status_t EFIAPI efi_convert_pointer(
-   efi_uintn_t debug_disposition, void **address)
+__efi_runtime efi_status_t EFIAPI
+efi_convert_pointer(efi_uintn_t debug_disposition, void **address)
 {
efi_physical_addr_t addr;
efi_uintn_t i;
efi_status_t ret = EFI_NOT_FOUND;

-   EFI_ENTRY("%zu %p", debug_disposition, address);
-
if (!efi_virtmap) {
ret = EFI_UNSUPPORTED;
goto out;
@@ -533,7 +531,7 @@ static __efi_runtime efi_status_t EFIAPI 
efi_convert_pointer(
}

 out:
-   return EFI_EXIT(ret);
+   return ret;
 }

 static __efi_runtime void efi_relocate_runtime_table(ulong offset)
--
2.27.0



[PATCH v4 16/17] efi_loader: enable UEFI variables at runtime

2020-07-11 Thread Heinrich Schuchardt
Enable UEFI variables at runtime.

Signed-off-by: Heinrich Schuchardt 
---
 lib/efi_loader/efi_runtime.c  |  2 ++
 lib/efi_loader/efi_var_file.c |  6 +++---
 lib/efi_loader/efi_variable.c | 14 --
 3 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/lib/efi_loader/efi_runtime.c b/lib/efi_loader/efi_runtime.c
index 5b6506fbdc..91a4551448 100644
--- a/lib/efi_loader/efi_runtime.c
+++ b/lib/efi_loader/efi_runtime.c
@@ -121,6 +121,8 @@ efi_status_t efi_init_runtime_supported(void)
rt_table->version = EFI_RT_PROPERTIES_TABLE_VERSION;
rt_table->length = sizeof(struct efi_rt_properties_table);
rt_table->runtime_services_supported =
+   EFI_RT_SUPPORTED_GET_VARIABLE |
+   EFI_RT_SUPPORTED_GET_NEXT_VARIABLE_NAME |
EFI_RT_SUPPORTED_SET_VIRTUAL_ADDRESS_MAP |
EFI_RT_SUPPORTED_CONVERT_POINTER;

diff --git a/lib/efi_loader/efi_var_file.c b/lib/efi_loader/efi_var_file.c
index b1b7532495..880c279aef 100644
--- a/lib/efi_loader/efi_var_file.c
+++ b/lib/efi_loader/efi_var_file.c
@@ -183,9 +183,9 @@ static efi_status_t __maybe_unused efi_var_restore(struct 
efi_var_file *buf)
u16 *data = var->name + u16_strlen(var->name) + 1;

if (var->attr & EFI_VARIABLE_NON_VOLATILE && var->length) {
-   ret = efi_set_variable_int(var->name, &var->guid,
-  var->attr, var->length,
-  data, true);
+   ret = efi_var_mem_ins(var->name, &var->guid, var->attr,
+ var->length, data, 0, NULL,
+ var->time);
if (ret != EFI_SUCCESS)
log_err("Failed to set EFI variable %ls\n",
var->name);
diff --git a/lib/efi_loader/efi_variable.c b/lib/efi_loader/efi_variable.c
index bbdc071126..eab5f005da 100644
--- a/lib/efi_loader/efi_variable.c
+++ b/lib/efi_loader/efi_variable.c
@@ -668,7 +668,16 @@ static efi_status_t __efi_runtime EFIAPI
 efi_get_variable_runtime(u16 *variable_name, const efi_guid_t *vendor,
 u32 *attributes, efi_uintn_t *data_size, void *data)
 {
-   return EFI_UNSUPPORTED;
+   efi_status_t ret;
+
+   ret = efi_get_variable_int(variable_name, vendor, attributes,
+  data_size, data, NULL);
+
+   /* Remove EFI_VARIABLE_READ_ONLY flag */
+   if (attributes)
+   *attributes &= EFI_VARIABLE_MASK;
+
+   return ret;
 }

 /**
@@ -684,7 +693,8 @@ static efi_status_t __efi_runtime EFIAPI
 efi_get_next_variable_name_runtime(efi_uintn_t *variable_name_size,
   u16 *variable_name, efi_guid_t *vendor)
 {
-   return EFI_UNSUPPORTED;
+   return efi_get_next_variable_name_int(variable_name_size, variable_name,
+ vendor);
 }

 /**
--
2.27.0



[PATCH v4 17/17] efi_selftest: adjust runtime test for variables

2020-07-11 Thread Heinrich Schuchardt
As variable services are available at runtime we have to expect EFI_SUCCESS
when calling the services.

Signed-off-by: Heinrich Schuchardt 
---
 lib/efi_selftest/efi_selftest_variables_runtime.c | 13 ++---
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/lib/efi_selftest/efi_selftest_variables_runtime.c 
b/lib/efi_selftest/efi_selftest_variables_runtime.c
index b3b40ad2cf..3226069c0b 100644
--- a/lib/efi_selftest/efi_selftest_variables_runtime.c
+++ b/lib/efi_selftest/efi_selftest_variables_runtime.c
@@ -16,9 +16,7 @@

 static struct efi_boot_services *boottime;
 static struct efi_runtime_services *runtime;
-static const efi_guid_t guid_vendor0 =
-   EFI_GUID(0x67029eb5, 0x0af2, 0xf6b1,
-0xda, 0x53, 0xfc, 0xb5, 0x66, 0xdd, 0x1c, 0xe6);
+static const efi_guid_t guid_vendor0 = EFI_GLOBAL_VARIABLE_GUID;

 /*
  * Setup unit test.
@@ -68,17 +66,18 @@ static int execute(void)
efi_st_error("SetVariable failed\n");
return EFI_ST_FAILURE;
}
-   len = 3;
-   ret = runtime->get_variable(L"efi_st_var0", &guid_vendor0,
+   len = EFI_ST_MAX_DATA_SIZE;
+   ret = runtime->get_variable(L"PlatformLangCodes", &guid_vendor0,
&attr, &len, data);
-   if (ret != EFI_UNSUPPORTED) {
+   if (ret != EFI_SUCCESS) {
efi_st_error("GetVariable failed\n");
return EFI_ST_FAILURE;
}
memset(&guid, 0, 16);
*varname = 0;
+   len = 2 * EFI_ST_MAX_VARNAME_SIZE;
ret = runtime->get_next_variable_name(&len, varname, &guid);
-   if (ret != EFI_UNSUPPORTED) {
+   if (ret != EFI_SUCCESS) {
efi_st_error("GetNextVariableName failed\n");
return EFI_ST_FAILURE;
}
--
2.27.0



[PATCH v4 15/17] efi_loader: use memory based variable storage

2020-07-11 Thread Heinrich Schuchardt
Saving UEFI variable as encoded U-Boot environment variables does not allow
implement run-time support.

Use a memory buffer for storing UEFI variables.

Signed-off-by: Heinrich Schuchardt 
---
v4:
correct appending of variables
---
 lib/efi_loader/efi_variable.c | 562 ++
 1 file changed, 94 insertions(+), 468 deletions(-)

diff --git a/lib/efi_loader/efi_variable.c b/lib/efi_loader/efi_variable.c
index 8ed4b0830b..bbdc071126 100644
--- a/lib/efi_loader/efi_variable.c
+++ b/lib/efi_loader/efi_variable.c
@@ -30,145 +30,6 @@ static bool efi_secure_boot;
 static enum efi_secure_mode efi_secure_mode;
 static u8 efi_vendor_keys;

-/*
- * Mapping between EFI variables and u-boot variables:
- *
- *   efi_$guid_$varname = {attributes}(type)value
- *
- * For example:
- *
- *   efi_8be4df61-93ca-11d2-aa0d-00e098032b8c_OsIndicationsSupported=
- *  "{ro,boot,run}(blob)"
- *   efi_8be4df61-93ca-11d2-aa0d-00e098032b8c_BootOrder=
- *  "(blob)0001"
- *
- * The attributes are a comma separated list of these possible
- * attributes:
- *
- *   + ro   - read-only
- *   + boot - boot-services access
- *   + run  - runtime access
- *
- * NOTE: with current implementation, no variables are available after
- * ExitBootServices, and all are persisted (if possible).
- *
- * If not specified, the attributes default to "{boot}".
- *
- * The required type is one of:
- *
- *   + utf8 - raw utf8 string
- *   + blob - arbitrary length hex string
- *
- * Maybe a utf16 type would be useful to for a string value to be auto
- * converted to utf16?
- */
-
-#define PREFIX_LEN (strlen("efi_----_"))
-
-/**
- * efi_to_native() - convert the UEFI variable name and vendor GUID to U-Boot
- *  variable name
- *
- * The U-Boot variable name is a concatenation of prefix 'efi', the hexstring
- * encoded vendor GUID, and the UTF-8 encoded UEFI variable name separated by
- * underscores, e.g. 'efi_8be4df61-93ca-11d2-aa0d-00e098032b8c_BootOrder'.
- *
- * @native:pointer to pointer to U-Boot variable name
- * @variable_name: UEFI variable name
- * @vendor:vendor GUID
- * Return: status code
- */
-static efi_status_t efi_to_native(char **native, const u16 *variable_name,
- const efi_guid_t *vendor)
-{
-   size_t len;
-   char *pos;
-
-   len = PREFIX_LEN + utf16_utf8_strlen(variable_name) + 1;
-   *native = malloc(len);
-   if (!*native)
-   return EFI_OUT_OF_RESOURCES;
-
-   pos = *native;
-   pos += sprintf(pos, "efi_%pUl_", vendor);
-   utf16_utf8_strcpy(&pos, variable_name);
-
-   return EFI_SUCCESS;
-}
-
-/**
- * prefix() - skip over prefix
- *
- * Skip over a prefix string.
- *
- * @str:   string with prefix
- * @prefix:prefix string
- * Return: string without prefix, or NULL if prefix not found
- */
-static const char *prefix(const char *str, const char *prefix)
-{
-   size_t n = strlen(prefix);
-   if (!strncmp(prefix, str, n))
-   return str + n;
-   return NULL;
-}
-
-/**
- * parse_attr() - decode attributes part of variable value
- *
- * Convert the string encoded attributes of a UEFI variable to a bit mask.
- * TODO: Several attributes are not supported.
- *
- * @str:   value of U-Boot variable
- * @attrp: pointer to UEFI attributes
- * @timep: pointer to time attribute
- * Return: pointer to remainder of U-Boot variable value
- */
-static const char *parse_attr(const char *str, u32 *attrp, u64 *timep)
-{
-   u32 attr = 0;
-   char sep = '{';
-
-   if (*str != '{') {
-   *attrp = EFI_VARIABLE_BOOTSERVICE_ACCESS;
-   return str;
-   }
-
-   while (*str == sep) {
-   const char *s;
-
-   str++;
-
-   if ((s = prefix(str, "ro"))) {
-   attr |= EFI_VARIABLE_READ_ONLY;
-   } else if ((s = prefix(str, "nv"))) {
-   attr |= EFI_VARIABLE_NON_VOLATILE;
-   } else if ((s = prefix(str, "boot"))) {
-   attr |= EFI_VARIABLE_BOOTSERVICE_ACCESS;
-   } else if ((s = prefix(str, "run"))) {
-   attr |= EFI_VARIABLE_RUNTIME_ACCESS;
-   } else if ((s = prefix(str, "time="))) {
-   attr |= 
EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS;
-   hex2bin((u8 *)timep, s, sizeof(*timep));
-   s += sizeof(*timep) * 2;
-   } else if (*str == '}') {
-   break;
-   } else {
-   printf("invalid attribute: %s\n", str);
-   break;
-   }
-
-   str = s;
-   sep = ',';
-   }
-
-   str++;
-
-   *attrp = attr;
-
-   return str;
-}
-
 /**
  * efi_set_secure_state - modify secure boot state variables
  * 

Re: [PATCH v2 4/5] mips: cache: Make invalidate_dcache_range() weak to enable overwrite

2020-07-11 Thread Daniel Schwierzeck
> This patch adds __weak to invalidate_dcache_range() in lib/cache.c. This
> makes it possible to overwrite this function by a platforms specific
> version, which will be done for Octeon.
> 
> Signed-off-by: Stefan Roese 
> ---
> 
> (no changes since v1)
> 
>  arch/mips/lib/cache.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> 

applied to u-boot-mips/next, thanks.


Stefan, I'll apply the two Octeon MIPS64 base support series after
I have applied my start.S refactoring and header sync series.

-- 
- Daniel



[PATCH 3/4] mips: refactor disabling of caches

2020-07-11 Thread Daniel Schwierzeck
Logically this code belongs to cache_init.S.

If a complex SoC needs to replace the generic cache init,
mips_cache_disable() can now be called from custom start.S files.

Signed-off-by: Daniel Schwierzeck 
---

 arch/mips/cpu/start.S  | 9 -
 arch/mips/lib/cache_init.S | 6 ++
 2 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/arch/mips/cpu/start.S b/arch/mips/cpu/start.S
index c3d1e64c1c..a9f8743717 100644
--- a/arch/mips/cpu/start.S
+++ b/arch/mips/cpu/start.S
@@ -196,11 +196,10 @@ wr_done:
mtc0zero, CP0_COMPARE
 
 #ifndef CONFIG_SKIP_LOWLEVEL_INIT
-   mfc0t0, CP0_CONFIG
-   and t0, t0, MIPS_CONF_IMPL
-   or  t0, t0, CONF_CM_UNCACHED
-   mtc0t0, CP0_CONFIG
-   ehb
+   /* Disable caches */
+   PTR_LA  t9, mips_cache_disable
+   jalrt9
+nop
 #endif
 
 #ifdef CONFIG_MIPS_CM
diff --git a/arch/mips/lib/cache_init.S b/arch/mips/lib/cache_init.S
index 2233d27137..602741c65d 100644
--- a/arch/mips/lib/cache_init.S
+++ b/arch/mips/lib/cache_init.S
@@ -418,6 +418,12 @@ return:
jr  R_RETURN
END(mips_cache_reset)
 
+LEAF(mips_cache_disable)
+   moveR_RETURN, ra
+   change_k0_cca_kseg1 CONF_CM_UNCACHED
+   jr  R_RETURN
+   END(mips_cache_disable)
+
 LEAF(change_k0_cca)
mfc0t0, CP0_CONFIG
 #if __mips_isa_rev >= 2
-- 
2.27.0



[PATCH 1/4] mips: start.S: remove dead code

2020-07-11 Thread Daniel Schwierzeck
Since commit 703ec9ddf965 ("MIPS: Stop building position independent code")
the relocation code was completely reworked and removed from start.S.
Remove some left-overs of the old code.

Signed-off-by: Daniel Schwierzeck 
---

 arch/mips/cpu/start.S | 9 -
 1 file changed, 9 deletions(-)

diff --git a/arch/mips/cpu/start.S b/arch/mips/cpu/start.S
index 6de9a2f362..c3d1e64c1c 100644
--- a/arch/mips/cpu/start.S
+++ b/arch/mips/cpu/start.S
@@ -17,19 +17,10 @@
 #endif
 
 #ifdef CONFIG_32BIT
-# define MIPS_RELOC3
 # define STATUS_SET0
 #endif
 
 #ifdef CONFIG_64BIT
-# ifdef CONFIG_SYS_LITTLE_ENDIAN
-#  define MIPS64_R_INFO(ssym, r_type3, r_type2, r_type) \
-   (((r_type) << 24) | ((r_type2) << 16) | ((r_type3) << 8) | (ssym))
-# else
-#  define MIPS64_R_INFO(ssym, r_type3, r_type2, r_type) \
-   ((r_type) | ((r_type2) << 8) | ((r_type3) << 16) | (ssym) << 24)
-# endif
-# define MIPS_RELOCMIPS64_R_INFO(0x00, 0x00, 0x12, 0x03)
 # define STATUS_SETST0_KX
 #endif
 
-- 
2.27.0



[PATCH 0/4] MIPS: refactor and cleanup start.S (part 1)

2020-07-11 Thread Daniel Schwierzeck


This is the first part of upcoming refactorings in start.S to
cleanup the multiple and hard-to-follow code flows as well as
adding more extension points required for modern and complex
multi-core SoC's. The first parts concentrates on caches.


Daniel Schwierzeck (4):
  mips: start.S: remove dead code
  mips: add KSEG1 wrapper for change_k0_cca
  mips: refactor disabling of caches
  mips: add config options for generic cache setup code

 arch/mips/Kconfig  | 24 
 arch/mips/cpu/start.S  | 24 +---
 arch/mips/lib/cache_init.S | 38 --
 3 files changed, 57 insertions(+), 29 deletions(-)

-- 
2.27.0



[PATCH 4/4] mips: add config options for generic cache setup code

2020-07-11 Thread Daniel Schwierzeck
Add an own Kconfig symbol for the initial disabling of caches
invoked from generic start code.

Also add an own Kconfig symbols for the initialization of caches
invoked from generic start code.

Until now both code paths could only be disabled with
CONFIG_SKIP_LOWLEVEL_INIT. But this is not flexible enough for
RAM boot scenarios like EJTAG or SPL payload or for machines
which don't require cache initialization or which want to
provide their own cache implementation.

Signed-off-by: Daniel Schwierzeck 

---

 arch/mips/Kconfig | 24 
 arch/mips/cpu/start.S |  6 +-
 2 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
index 48e754cc46..eb00ee71bc 100644
--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -270,6 +270,30 @@ config MIPS_CACHE_INDEX_BASE
  Normally this is CKSEG0. If the MIPS system needs to move this block
  to some SRAM or ScratchPad RAM, adapt this option accordingly.
 
+config MIPS_CACHE_SETUP
+   bool "Allow generic start code to initialize and setup caches"
+   default n if SKIP_LOWLEVEL_INIT
+   default y
+   help
+ This allows the generic start code to invoke the generic 
initialization
+ of the CPU caches. Disabling this can be useful for RAM boot scenarios
+ (EJTAG, SPL payload) or for machines which don't need cache 
initialization
+ or which want to provide their own cache implementation.
+
+ If unsure, say yes.
+
+config MIPS_CACHE_DISABLE
+   bool "Allow generic start code to initially disable caches"
+   default n if SKIP_LOWLEVEL_INIT
+   default y
+   help
+ This allows the generic start code to initially disable the CPU caches
+ and run uncached until the caches are initialized and enabled. 
Disabling
+ this can be useful on machines which don't need cache initialization 
or
+ which want to provide their own cache implementation.
+
+ If unsure, say yes.
+
 config MIPS_RELOCATION_TABLE_SIZE
hex "Relocation table size"
range 0x100 0x1
diff --git a/arch/mips/cpu/start.S b/arch/mips/cpu/start.S
index a9f8743717..0c303031ad 100644
--- a/arch/mips/cpu/start.S
+++ b/arch/mips/cpu/start.S
@@ -195,7 +195,7 @@ wr_done:
/* Clear timer interrupt (CP0_COUNT cleared on branch to 'reset') */
mtc0zero, CP0_COMPARE
 
-#ifndef CONFIG_SKIP_LOWLEVEL_INIT
+#ifdef CONFIG_MIPS_CACHE_DISABLE
/* Disable caches */
PTR_LA  t9, mips_cache_disable
jalrt9
@@ -234,12 +234,16 @@ wr_done:
jalrt9
 nop
 # endif
+#endif
 
+#ifdef CONFIG_MIPS_CACHE_SETUP
/* Initialize caches... */
PTR_LA  t9, mips_cache_reset
jalrt9
 nop
+#endif
 
+#ifndef CONFIG_SKIP_LOWLEVEL_INIT
 # ifndef CONFIG_SYS_MIPS_CACHE_INIT_RAM_LOAD
/* Initialize any external memory */
PTR_LA  t9, lowlevel_init
-- 
2.27.0



[PATCH 2/4] mips: add KSEG1 wrapper for change_k0_cca

2020-07-11 Thread Daniel Schwierzeck
change_k0_cca() is called multiple times. Move the code for
changing to KSEG1 to a macro to avoid code duplication.

Also fix missing change to KSEG1 when changing to CONF_CM_CACHABLE_COW.

Signed-off-by: Daniel Schwierzeck 
---

 arch/mips/lib/cache_init.S | 32 ++--
 1 file changed, 18 insertions(+), 14 deletions(-)

diff --git a/arch/mips/lib/cache_init.S b/arch/mips/lib/cache_init.S
index cfad1d9c8a..2233d27137 100644
--- a/arch/mips/lib/cache_init.S
+++ b/arch/mips/lib/cache_init.S
@@ -79,6 +79,21 @@
.setpop
.endm
 
+   /*
+* The changing of Kernel mode cacheability must be done from KSEG1.
+* If the code is executing from KSEG0, jump to KSEG1 during the 
execution
+* of change_k0_cca. change_k0_cca itself clears all hazards when 
returning.
+*/
+   .macro change_k0_cca_kseg1 mode
+   PTR_LA  t0, change_k0_cca
+   li  t1, CPHYSADDR(~0)
+   and t0, t0, t1
+   PTR_LI  t1, CKSEG1
+   or  t0, t0, t1
+   li  a0, \mode
+   jalrt0
+   .endm
+
 /*
  * mips_cache_reset - low level initialisation of the primary caches
  *
@@ -317,18 +332,9 @@ l1_init:
sync
 
/*
-* Enable use of the I-cache by setting Config.K0. The code for this
-* must be executed from KSEG1. Jump from KSEG0 to KSEG1 to do this.
-* Jump back to KSEG0 after caches are enabled and insert an
-* instruction hazard barrier.
+* Enable use of the I-cache by setting Config.K0.
 */
-   PTR_LA  t0, change_k0_cca
-   li  t1, CPHYSADDR(~0)
-   and t0, t0, t1
-   PTR_LI  t1, CKSEG1
-   or  t0, t0, t1
-   li  a0, CONF_CM_CACHABLE_NONCOHERENT
-   jalr.hb t0
+   change_k0_cca_kseg1 CONF_CM_CACHABLE_NONCOHERENT
 
/*
 * then initialize D-cache.
@@ -388,9 +394,7 @@ l2_unbypass:
beqzt0, 2f
 
/* Change Config.K0 to a coherent CCA */
-   PTR_LA  t0, change_k0_cca
-   li  a0, CONF_CM_CACHABLE_COW
-   jalrt0
+   change_k0_cca_kseg1 CONF_CM_CACHABLE_COW
 
/*
 * Join the coherent domain such that the caches of this core are kept
-- 
2.27.0



[PATCH 3/4] mips: sync asm/addrspace.h with Linux 5.7

2020-07-11 Thread Daniel Schwierzeck
Sync asm/addrspace.h with Linux 5.7

Signed-off-by: Daniel Schwierzeck 
---

 arch/mips/include/asm/addrspace.h | 14 ++
 1 file changed, 2 insertions(+), 12 deletions(-)

diff --git a/arch/mips/include/asm/addrspace.h 
b/arch/mips/include/asm/addrspace.h
index ae6f586f00..8112ab833e 100644
--- a/arch/mips/include/asm/addrspace.h
+++ b/arch/mips/include/asm/addrspace.h
@@ -42,7 +42,7 @@
 /*
  * Returns the kernel segment base of a given address
  */
-#define KSEGX(a)   ((_ACAST32_ (a)) & 0xe000)
+#define KSEGX(a)   ((_ACAST32_(a)) & _ACAST32_(0xe000))
 
 /*
  * Returns the physical address of a CKSEGx / XKPHYS address
@@ -123,8 +123,7 @@
 #define PHYS_TO_XKSEG_UNCACHED(p)  PHYS_TO_XKPHYS(K_CALG_UNCACHED, (p))
 #define PHYS_TO_XKSEG_CACHED(p)
PHYS_TO_XKPHYS(K_CALG_COH_SHAREABLE, (p))
 #define XKPHYS_TO_PHYS(p)  ((p) & TO_PHYS_MASK)
-#define PHYS_TO_XKPHYS(cm, a)  (_CONST64_(0x8000) | \
-(_CONST64_(cm) << 59) | (a))
+#define PHYS_TO_XKPHYS(cm, a)  (XKPHYS | (_ACAST64_(cm) << 59) | (a))
 
 /*
  * The ultimate limited of the 64-bit MIPS architecture:  2 bits for selecting
@@ -133,18 +132,9 @@
  */
 #define TO_PHYS_MASK   _CONST64_(0x07ff)   /* 2^^59 - 1 */
 
-#ifndef CONFIG_CPU_R8000
-
-/*
- * The R8000 doesn't have the 32-bit compat spaces so we don't define them
- * in order to catch bugs in the source code.
- */
-
 #define COMPAT_K1BASE32_CONST64_(0xa000)
 #define PHYS_TO_COMPATK1(x)((x) | COMPAT_K1BASE32) /* 32-bit compat k1 */
 
-#endif
-
 #define KDM_TO_PHYS(x) (_ACAST64_ (x) & TO_PHYS_MASK)
 #define PHYS_TO_K0(x)  (_ACAST64_ (x) | CAC_BASE)
 
-- 
2.27.0



[PATCH 0/4] MIPS: sync asm header files with Linux 5.7 (part 1)

2020-07-11 Thread Daniel Schwierzeck


This is the first part of syncing the MIPS asm header files with
Linux 5.7 to get the latest features for newer MIPS cores and
MIPS architectures. This also prepares for the upcoming Octeon
MIPS64 support.


Daniel Schwierzeck (4):
  mips: remove deprecated UNCACHED_SDRAM() macro
  mips: sync asm/asm.h with Linux 5.7
  mips: sync asm/addrspace.h with Linux 5.7
  mips: sync asm/mipsregs.h with Linux 5.7

 arch/mips/cpu/start.S |2 +-
 arch/mips/include/asm/addrspace.h |   27 +-
 arch/mips/include/asm/asm.h   |  130 +---
 arch/mips/include/asm/compiler.h  |   69 ++
 arch/mips/include/asm/isa-rev.h   |   24 +
 arch/mips/include/asm/mipsregs.h  | 1202 -
 arch/mips/lib/bootm.c |4 +-
 arch/mips/lib/traps.c |2 +-
 8 files changed, 1117 insertions(+), 343 deletions(-)
 create mode 100644 arch/mips/include/asm/compiler.h
 create mode 100644 arch/mips/include/asm/isa-rev.h

-- 
2.27.0



[PATCH 1/4] mips: remove deprecated UNCACHED_SDRAM() macro

2020-07-11 Thread Daniel Schwierzeck
This macro only served as a wrapper for CKSEG1ADDR() with an
exception for CONFIG_TB0229. CONFIG_TB0229 doesn't exist, thus
use CKSEG1ADDR() directly.

This also prepares for an upcoming asm header sync with Linux.

Signed-off-by: Daniel Schwierzeck 
---

 arch/mips/include/asm/addrspace.h | 13 -
 arch/mips/lib/bootm.c |  4 ++--
 2 files changed, 2 insertions(+), 15 deletions(-)

diff --git a/arch/mips/include/asm/addrspace.h 
b/arch/mips/include/asm/addrspace.h
index b6d387677e..ae6f586f00 100644
--- a/arch/mips/include/asm/addrspace.h
+++ b/arch/mips/include/asm/addrspace.h
@@ -126,19 +126,6 @@
 #define PHYS_TO_XKPHYS(cm, a)  (_CONST64_(0x8000) | \
 (_CONST64_(cm) << 59) | (a))
 
-/*
- * Returns the uncached address of a sdram address
- */
-#ifndef __ASSEMBLY__
-#if defined(CONFIG_TB0229)
-/* We use a 36 bit physical address map here and
-   cannot access physical memory directly from core */
-#define UNCACHED_SDRAM(a) (((unsigned long)(a)) | 0x2000)
-#else  /* !CONFIG_TB0229 */
-#define UNCACHED_SDRAM(a) CKSEG1ADDR(a)
-#endif /* CONFIG_TB0229 */
-#endif /* __ASSEMBLY__ */
-
 /*
  * The ultimate limited of the 64-bit MIPS architecture:  2 bits for selecting
  * the region, 3 bits for the CCA mode.  This leaves 59 bits of which the
diff --git a/arch/mips/lib/bootm.c b/arch/mips/lib/bootm.c
index 82f986cb81..0a13f6edb7 100644
--- a/arch/mips/lib/bootm.c
+++ b/arch/mips/lib/bootm.c
@@ -51,7 +51,7 @@ void arch_lmb_reserve(struct lmb *lmb)
 static void linux_cmdline_init(void)
 {
linux_argc = 1;
-   linux_argv = (char **)UNCACHED_SDRAM(gd->bd->bi_boot_params);
+   linux_argv = (char **)CKSEG1ADDR(gd->bd->bi_boot_params);
linux_argv[0] = 0;
linux_argp = (char *)(linux_argv + LINUX_MAX_ARGS);
 }
@@ -186,7 +186,7 @@ static void linux_env_legacy(bootm_headers_t *images)
  (ulong)(gd->ram_size >> 20));
}
 
-   rd_start = UNCACHED_SDRAM(images->initrd_start);
+   rd_start = CKSEG1ADDR(images->initrd_start);
rd_size = images->initrd_end - images->initrd_start;
 
linux_env_init();
-- 
2.27.0



[PATCH 2/4] mips: sync asm/asm.h with Linux 5.7

2020-07-11 Thread Daniel Schwierzeck
Sync asm/asm.h with Linux 5.7.

Signed-off-by: Daniel Schwierzeck 
---

 arch/mips/include/asm/asm.h | 130 +++-
 1 file changed, 10 insertions(+), 120 deletions(-)

diff --git a/arch/mips/include/asm/asm.h b/arch/mips/include/asm/asm.h
index 7abcf6df07..a6876e1b07 100644
--- a/arch/mips/include/asm/asm.h
+++ b/arch/mips/include/asm/asm.h
@@ -16,37 +16,12 @@
 
 #include 
 
-#ifndef CAT
-#ifdef __STDC__
-#define __CAT(str1, str2) str1##str2
-#else
-#define __CAT(str1, str2) str1/**/str2
-#endif
-#define CAT(str1, str2) __CAT(str1, str2)
-#endif
-
-/*
- * PIC specific declarations
- * Not used for the kernel but here seems to be the right place.
- */
-#ifdef __PIC__
-#define CPRESTORE(register)\
-   .cprestore register
-#define CPADD(register)\
-   .cpadd  register
-#define CPLOAD(register)   \
-   .cpload register
-#else
-#define CPRESTORE(register)
-#define CPADD(register)
-#define CPLOAD(register)
-#endif
-
 #define ENTRY(symbol)  \
.globl  symbol; \
.type   symbol, @function;  \
.entsymbol, 0;  \
-symbol:
+symbol:.cfi_startproc; \
+   .insn
 
 /*
  * LEAF - declare leaf routine
@@ -57,7 +32,9 @@ symbol:
.type   symbol, @function;  \
.entsymbol, 0;  \
.section .text.symbol, "x"; \
-symbol:.frame  sp, 0, ra
+symbol:.frame  sp, 0, ra;  \
+   .cfi_startproc; \
+   .insn
 
 /*
  * NESTED - declare nested routine entry point
@@ -68,12 +45,15 @@ symbol: .frame  sp, 0, ra
.type   symbol, @function;  \
.entsymbol, 0;  \
.section .text.symbol, "x"; \
-symbol:.frame  sp, framesize, rpc
+symbol:.frame  sp, framesize, rpc; \
+   .cfi_startproc; \
+   .insn
 
 /*
  * END - mark end of function
  */
 #define END(function)  \
+   .cfi_endproc;   \
.endfunction;   \
.size   function, .-function
 
@@ -90,7 +70,7 @@ symbol:
 #define FEXPORT(symbol)\
.globl  symbol; \
.type   symbol, @function;  \
-symbol:
+symbol:.insn
 
 /*
  * ABS - export absolute symbol
@@ -128,96 +108,6 @@ symbol =   value
 8: .asciiz msg;\
.popsection;
 
-/*
- * Build text tables
- */
-#define TTABLE(string) \
-   .pushsection .text; \
-   .word   1f; \
-   .popsection \
-   .pushsection .data; \
-1: .asciiz string; \
-   .popsection
-
-/*
- * MIPS IV pref instruction.
- * Use with .set noreorder only!
- *
- * MIPS IV implementations are free to treat this as a nop.  The R5000
- * is one of them.  So we should have an option not to use this instruction.
- */
-#ifdef CONFIG_CPU_HAS_PREFETCH
-
-#define PREF(hint, addr)   \
-   .setpush;   \
-   .setarch=r5000; \
-   prefhint, addr; \
-   .setpop
-
-#define PREFE(hint, addr)  \
-   .setpush;   \
-   .setmips0;  \
-   .seteva;\
-   prefe   hint, addr; \
-   .setpop
-
-#define PREFX(hint, addr)  \
-   .setpush;   \
-   .setarch=r5000; \
-   prefx   hint, addr; \
-   .setpop
-
-#else /* !CONFIG_CPU_HAS_PREFETCH */
-
-#define PREF(hint, addr)
-#define PREFE(hint, addr)
-#define PREFX(hint, addr)
-
-#endif /* !CONFIG_CPU_HAS_PREFETCH */
-
-/*
- * MIPS ISA IV/V movn/movz instructions and equivalents for older CPUs.
- */
-#if (_MIPS_ISA == _MIPS_ISA_MIPS1)
-#define MOVN(rd, rs, rt)   \
-   .setpush;   \
-   .setreorder;\
-  

[PATCH 4/4] mips: sync asm/mipsregs.h with Linux 5.7

2020-07-11 Thread Daniel Schwierzeck
Sync asm/mipsregs.h with Linux 5.7. Also replace the custom
symbols EBASE_CPUNUM and EBASE_WG with the according symbols
from Linux.

Signed-off-by: Daniel Schwierzeck 

---

 arch/mips/cpu/start.S|2 +-
 arch/mips/include/asm/compiler.h |   69 ++
 arch/mips/include/asm/isa-rev.h  |   24 +
 arch/mips/include/asm/mipsregs.h | 1202 +-
 arch/mips/lib/traps.c|2 +-
 5 files changed, 1103 insertions(+), 196 deletions(-)
 create mode 100644 arch/mips/include/asm/compiler.h
 create mode 100644 arch/mips/include/asm/isa-rev.h

diff --git a/arch/mips/cpu/start.S b/arch/mips/cpu/start.S
index 0c303031ad..e22771715c 100644
--- a/arch/mips/cpu/start.S
+++ b/arch/mips/cpu/start.S
@@ -138,7 +138,7 @@ reset:
and t0, t0, (1 << 31)
 #else
 1: mfc0t0, CP0_EBASE
-   and t0, t0, EBASE_CPUNUM
+   and t0, t0, MIPS_EBASE_CPUNUM
 #endif
 
/* Hang if this isn't the first CPU in the system */
diff --git a/arch/mips/include/asm/compiler.h b/arch/mips/include/asm/compiler.h
new file mode 100644
index 00..c498b42f1c
--- /dev/null
+++ b/arch/mips/include/asm/compiler.h
@@ -0,0 +1,69 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2004, 2007  Maciej W. Rozycki
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License.  See the file "COPYING" in the main directory of this archive
+ * for more details.
+ */
+#ifndef _ASM_COMPILER_H
+#define _ASM_COMPILER_H
+
+/*
+ * With GCC 4.5 onwards we can use __builtin_unreachable to indicate to the
+ * compiler that a particular code path will never be hit. This allows it to be
+ * optimised out of the generated binary.
+ *
+ * Unfortunately at least GCC 4.6.3 through 7.3.0 inclusive suffer from a bug
+ * that can lead to instructions from beyond an unreachable statement being
+ * incorrectly reordered into earlier delay slots if the unreachable statement
+ * is the only content of a case in a switch statement. This can lead to
+ * seemingly random behaviour, such as invalid memory accesses from incorrectly
+ * reordered loads or stores. See this potential GCC fix for details:
+ *
+ *   https://gcc.gnu.org/ml/gcc-patches/2015-09/msg00360.html
+ *
+ * It is unclear whether GCC 8 onwards suffer from the same issue - nothing
+ * relevant is mentioned in GCC 8 release notes and nothing obviously relevant
+ * stands out in GCC commit logs, but these newer GCC versions generate very
+ * different code for the testcase which doesn't exhibit the bug.
+ *
+ * GCC also handles stack allocation suboptimally when calling noreturn
+ * functions or calling __builtin_unreachable():
+ *
+ *   https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82365
+ *
+ * We work around both of these issues by placing a volatile asm statement,
+ * which GCC is prevented from reordering past, prior to __builtin_unreachable
+ * calls.
+ *
+ * The .insn statement is required to ensure that any branches to the
+ * statement, which sadly must be kept due to the asm statement, are known to
+ * be branches to code and satisfy linker requirements for microMIPS kernels.
+ */
+#undef barrier_before_unreachable
+#define barrier_before_unreachable() asm volatile(".insn")
+
+#if !defined(CONFIG_CC_IS_GCC) || \
+(__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 9)
+# define GCC_OFF_SMALL_ASM() "ZC"
+#elif defined(CONFIG_CPU_MICROMIPS)
+# error "microMIPS compilation unsupported with GCC older than 4.9"
+#else
+# define GCC_OFF_SMALL_ASM() "R"
+#endif
+
+#ifdef CONFIG_CPU_MIPSR6
+#define MIPS_ISA_LEVEL "mips64r6"
+#define MIPS_ISA_ARCH_LEVEL MIPS_ISA_LEVEL
+#define MIPS_ISA_LEVEL_RAW mips64r6
+#define MIPS_ISA_ARCH_LEVEL_RAW MIPS_ISA_LEVEL_RAW
+#else
+/* MIPS64 is a superset of MIPS32 */
+#define MIPS_ISA_LEVEL "mips64r2"
+#define MIPS_ISA_ARCH_LEVEL "arch=r4000"
+#define MIPS_ISA_LEVEL_RAW mips64r2
+#define MIPS_ISA_ARCH_LEVEL_RAW MIPS_ISA_LEVEL_RAW
+#endif /* CONFIG_CPU_MIPSR6 */
+
+#endif /* _ASM_COMPILER_H */
diff --git a/arch/mips/include/asm/isa-rev.h b/arch/mips/include/asm/isa-rev.h
new file mode 100644
index 00..683ea3454d
--- /dev/null
+++ b/arch/mips/include/asm/isa-rev.h
@@ -0,0 +1,24 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2018 MIPS Tech, LLC
+ * Author: Matt Redfearn 
+ */
+
+#ifndef __MIPS_ASM_ISA_REV_H__
+#define __MIPS_ASM_ISA_REV_H__
+
+/*
+ * The ISA revision level. This is 0 for MIPS I to V and N for
+ * MIPS{32,64}rN.
+ */
+
+/* If the compiler has defined __mips_isa_rev, believe it. */
+#ifdef __mips_isa_rev
+#define MIPS_ISA_REV __mips_isa_rev
+#else
+/* The compiler hasn't defined the isa rev so assume it's MIPS I - V (0) */
+#define MIPS_ISA_REV 0
+#endif
+
+
+#endif /* __MIPS_ASM_ISA_REV_H__ */
diff --git a/arch/mips/include/asm/mipsregs.h b/arch/mips/include/asm/mipsregs.h
index 17381301ec..e65485b4ff 100644
--- a/arch/mips/include/asm/mipsregs.h
+++ b/arch/mips/include/asm/mipsregs.h
@@ -10,6 +10,8 @@
 #ifndef _ASM_MIPSREG

Re: [PATCH 14/15] net: sun8i-emac: Lower MDIO frequency

2020-07-11 Thread André Przywara
On 11/07/2020 10:27, Jagan Teki wrote:

Hi,

> On Mon, Jul 6, 2020 at 6:12 AM Andre Przywara  wrote:
>>
>> When sending a command via the MDIO bus, the Designware MAC expects some
>> bits in the CMD register to describe the clock divider value between
>> the main clock and the MDIO clock.
>> So far we were omitting these bits, resulting in setting "00", which
>> means "/ 16", so ending up with an MDIO frequency of either 18.75 or
>> 12.5 MHz.
>> All the internal PHYs in the H3/H5/H6 SoCs as well as the Gbit Realtek
>> PHYs seem to be fine with that - although it looks like to be severly
>> overclocked (the MDIO spec limits the frequency to 2.5 MHz).
>> However the external 100Mbit PHY on the Pine64 (non-plus) board is
>> not happy with that, Ethernet was actually never working there, as the
>> PHY didn't probe.
> 
> How come the existing divider cannot work with 100Mbit external
> PHY(assuming external regulator pin as properly enabled) since it
> works with 1Gbit already?

Because it's far too high to be MDIO spec compliant. My guess is that
some PHYs (for instance the RTL8211 used on most boards with GBit
Ethernet) can cope with that, but apparently that's too much for the
RTL8201 on the Pine64. I would say that most boards have either an
external GBit PHY or use the internal PHY for 100MBit, so there are not
many boards using the sun8i EMAC with an 8201 PHY, that's why nobody
complained so far.

At least this is my best guess, based on the observation that this patch
makes the difference between Ethernet working or not on the Pine64
(non-plus).

Cheers,
Andre.


Re: [PATCH 2/3] msm_serial: Read bit rate register value from DT

2020-07-11 Thread Ramon Fried
On Mon, Jul 6, 2020 at 11:38 AM Robert Marko  wrote:
>
> IPQ40xx and currently supported Snapdragon boards don't use the same one
> so enable reading it from DT, if no DT property is found default value
> is the same as the previous define.
>
> Signed-off-by: Robert Marko 
> ---
>  doc/device-tree-bindings/serial/msm-serial.txt | 4 
>  drivers/serial/serial_msm.c| 6 +-
>  2 files changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/doc/device-tree-bindings/serial/msm-serial.txt 
> b/doc/device-tree-bindings/serial/msm-serial.txt
> index 48b8428aca..dca995798a 100644
> --- a/doc/device-tree-bindings/serial/msm-serial.txt
> +++ b/doc/device-tree-bindings/serial/msm-serial.txt
> @@ -4,3 +4,7 @@ Required properties:
>  - compatible: must be "qcom,msm-uartdm-v1.4"
>  - reg: start address and size of the registers
>  - clock: interface clock (must accept baudrate as a frequency)
> +
> +Optional properties:
> +- bit-rate: Data Mover bit rate register value
> +   (If not defined then 0xCC is used as default)
> diff --git a/drivers/serial/serial_msm.c b/drivers/serial/serial_msm.c
> index 0cc1aadce4..a32de373d7 100644
> --- a/drivers/serial/serial_msm.c
> +++ b/drivers/serial/serial_msm.c
> @@ -61,6 +61,7 @@ struct msm_serial_data {
> phys_addr_t base;
> unsigned chars_cnt; /* number of buffered chars */
> uint32_t chars_buf; /* buffered chars */
> +   uint32_t clk_bit_rate; /* data mover mode bit rate register value */
>  };
>
>  static int msm_serial_fetch(struct udevice *dev)
> @@ -190,7 +191,7 @@ static int msm_uart_clk_init(struct udevice *dev)
>
>  static void uart_dm_init(struct msm_serial_data *priv)
>  {
> -   writel(UART_DM_CLK_RX_TX_BIT_RATE, priv->base + UARTDM_CSR);
> +   writel(priv->clk_bit_rate, priv->base + UARTDM_CSR);
> writel(0x0, priv->base + UARTDM_MR1);
> writel(MSM_BOOT_UART_DM_8_N_1_MODE, priv->base + UARTDM_MR2);
> writel(MSM_BOOT_UART_DM_CMD_RESET_RX, priv->base + UARTDM_CR);
> @@ -223,6 +224,9 @@ static int msm_serial_ofdata_to_platdata(struct udevice 
> *dev)
> if (priv->base == FDT_ADDR_T_NONE)
> return -EINVAL;
>
> +   priv->clk_bit_rate = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev),
> +   "bit-rate", 
> UART_DM_CLK_RX_TX_BIT_RATE);
> +
> return 0;
>  }
>
> --
> 2.26.2
>

Reviewed-By: Ramon Fried 


Re: [PATCH 3/3] msm_gpio: Add support for Qualcomm IPQ40xx

2020-07-11 Thread Ramon Fried
On Mon, Jul 6, 2020 at 11:38 AM Robert Marko  wrote:
>
> Snapdragon SoCs and IPQ40xx use common TLMM IP,
> so existing driver supports IPQ40xx as well.
>
> So lets simply add a compatible for IPQ40xx.
>
> Signed-off-by: Robert Marko 
> ---
>  doc/device-tree-bindings/gpio/gpio-msm.txt | 3 ++-
>  drivers/gpio/msm_gpio.c| 1 +
>  2 files changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/doc/device-tree-bindings/gpio/gpio-msm.txt 
> b/doc/device-tree-bindings/gpio/gpio-msm.txt
> index 966ce0af09..70a2c7f0dd 100644
> --- a/doc/device-tree-bindings/gpio/gpio-msm.txt
> +++ b/doc/device-tree-bindings/gpio/gpio-msm.txt
> @@ -1,7 +1,8 @@
>  Qualcomm Snapdragon GPIO controller
>
>  Required properties:
> -- compatible : "qcom,msm8916-pinctrl" or "qcom,apq8016-pinctrl"
> +- compatible : "qcom,msm8916-pinctrl", "qcom,apq8016-pinctrl" or
> +   "qcom,ipq4019-pinctrl"
>  - reg : Physical base address and length of the controller's registers.
> This controller is called "Top Level Mode Multiplexing" in
> Qualcomm documentation.
> diff --git a/drivers/gpio/msm_gpio.c b/drivers/gpio/msm_gpio.c
> index ac5d20c1b9..868291eddb 100644
> --- a/drivers/gpio/msm_gpio.c
> +++ b/drivers/gpio/msm_gpio.c
> @@ -118,6 +118,7 @@ static int msm_gpio_ofdata_to_platdata(struct udevice 
> *dev)
>  static const struct udevice_id msm_gpio_ids[] = {
> { .compatible = "qcom,msm8916-pinctrl" },
> { .compatible = "qcom,apq8016-pinctrl" },
> +   { .compatible = "qcom,ipq4019-pinctrl" },
> { }
>  };
>
> --
> 2.26.2
>
Reviewed-By: Ramon Fried 


Re: Pull request for UEFI sub-system for efi-2020-10-rc1 (2)

2020-07-11 Thread Heinrich Schuchardt
On 7/12/20 12:05 AM, Heinrich Schuchardt wrote:
> On 7/11/20 2:16 PM, Tom Rini wrote:
>> On Sat, Jul 11, 2020 at 09:00:16AM +0200, Heinrich Schuchardt wrote:
>>> On 7/10/20 8:09 PM, Tom Rini wrote:
 On Thu, Jul 09, 2020 at 06:12:02PM +0200, Heinrich Schuchardt wrote:

> The following changes since commit 
> 61608f395e7dcb2be6060407a72a1149b046430a:
>
>   Merge branch '2020-07-08-misc-features-and-fixes' (2020-07-08 20:20:24
> -0400)
>
> are available in the Git repository at:
>
>   https://gitlab.denx.de/u-boot/custodians/u-boot-efi.git 
> efi-2020-10-rc1-2
>
> for you to fetch changes up to f4cef8e7585c268f05a8c39e368ca115c25e40d5:
>
>   efi_selftest: adjust runtime test for variables (2020-07-09 12:08:41
> +0200)
>

 NAK.  This is reliably failing here:
 https://gitlab.denx.de/u-boot/u-boot/-/jobs/122018

 I see it passed Azure, and hasn't run through Travis yet.  Maybe it
 needs to be run repeatedly to fail and we just got "lucky" ?

>>>
>>> Hello Tom,
>>>
>>> you saw unreproducible results with multiple runs failing and one run
>>> succeeding. The reason is that when signing with sign-efi-sig-list in
>>> out Python tests without passing a timestamp two signatures may be in
>>> the same second or not.
>>>
>>> When using the signed files to set UEFI variables a variable can only be
>>> overwritten by a file with a newer timestamp. But without setting
>>> timestamps explicitly using parameter -t passed to sign-efi-sig-list we
>>> have no control.
>>>
>>> I already fixed this for some elder tests but missed to fix this for the
>>> merged patches from Takahiro.
>>
>> Ah, thanks for the explanation.
>>
>
> Hello Tom,
>
> what I still do not understand why tests are sometimes skipped and
> sometimes not for the same source code:
>
> https://gitlab.denx.de/u-boot/u-boot/-/jobs/122018
> Commit 7068e523
>
> 140 test/py/tests/test_efi_secboot/test_authvar.py .
> 141 test/py/tests/test_efi_secboot/test_signed.py .F
> 142 test/py/tests/test_efi_secboot/test_unsigned.py ...
>
> https://gitlab.denx.de/u-boot/custodians/u-boot-efi/-/jobs/122155
> Commit 7068e523
>
> 148 test/py/tests/test_efi_secboot/test_authvar.py s
> 149 test/py/tests/test_efi_secboot/test_signed.py ss
> 150 test/py/tests/test_efi_secboot/test_unsigned.py sss
>
> Both runs used the same Docker image
> trini/u-boot-gitlab-ci-runner:bionic-20200526-18Jun2020
>
> What influence have different versions of the Gitlab runner?
>
> gitlab-runner 13.1.1
> gitlab-runner 12.2.0
>
> Some of our tests create and delete files in /tmp. How are parallel jobs
> separated in Gitlab?
>
> Best regards
>
> Heinrich
>

This information I received on the #gitlab IRC channel:

Q:
When using Gitlab CI for building the U-Boot project many jobs run in
parallel. Some results are irreproducible. How are parallel jobs
separated in Gitlab. E.g. if parallel jobs write and delete files in
/tmp are these in separate Docker containers or are they in the same
Docker container accessing the same directory?

A:
Yes, each job is a distinct docker container on a transient VM . Nothing
is shared unless you use the https://docs.gitlab.com/ee/ci/yaml/#cache
capability, but that wouldn't help for parallel jobs. At least: on
gitlab.com, that's how it's implemented. On self-managed: depends a
little on how you choose to operate your runners (e.g. shell-executor vs
docker etc).

Best regards

Heinrich


Signing a fit with no images

2020-07-11 Thread Ranran
Hello,

I am trying to sign a fit which contains no images.
But mkimage returns the following error message "mkimage Can't add
hashes to FIT blob: -1".
Is it not allowed to sign a fit which contains no images ?

Thanks