[PATCH v3 4/4] mkeficapsule: add FMP Payload Header

2023-03-19 Thread Masahisa Kojima
Current mkeficapsule tool does not provide firmware
version management. EDK2 reference implementation inserts
the FMP Payload Header right before the payload.
It coutains the fw_version and lowest supported version.

This commit adds two new parameters required to generate
the FMP Payload Header for mkeficapsule tool.
 '-v' indicates the firmware version.
 '-l' indicates the lowest supported version.

When mkeficapsule tool is invoked with neither '-v' nor '-l' option,
FMP Payload Header is not inserted, the behavior is same as
current implementation.

Signed-off-by: Masahisa Kojima 
---
Changes in v3:
- remove '-f' option
- move some definitions into tools/eficapsule.h
- add dependency check of fw_version and lowest_supported_version
- remove unexpected modification of existing fprintf() call
- add documentation

Newly created in v2

 doc/mkeficapsule.1   | 16 ++
 tools/eficapsule.h   | 32 +++
 tools/mkeficapsule.c | 51 +++-
 3 files changed, 94 insertions(+), 5 deletions(-)

diff --git a/doc/mkeficapsule.1 b/doc/mkeficapsule.1
index 1ca245a10f..7c62b03c73 100644
--- a/doc/mkeficapsule.1
+++ b/doc/mkeficapsule.1
@@ -61,6 +61,22 @@ Specify an image index
 .BI "-I\fR,\fB --instance " instance
 Specify a hardware instance
 
+.PP
+FMP Payload Header is inserted right before the payload if
+.BR --fw-version
+or
+.BR --lsv
+are specified
+
+
+.TP
+.BI "-v\fR,\fB --fw-version " firmware-version
+Specify a firmware version, 0 if omitted
+
+.TP
+.BI "-l\fR,\fB --lsv " lowest-supported-version
+Specify a lowest supported version, 0 if omitted
+
 .PP
 For generation of firmware accept empty capsule
 .BR --guid
diff --git a/tools/eficapsule.h b/tools/eficapsule.h
index 072a4b5598..72500d1f84 100644
--- a/tools/eficapsule.h
+++ b/tools/eficapsule.h
@@ -113,4 +113,36 @@ struct efi_firmware_image_authentication {
struct win_certificate_uefi_guid auth_info;
 } __packed;
 
+
+/* fmp payload header */
+#define SIGNATURE_16(A, B) ((A) | ((B) << 8))
+#define SIGNATURE_32(A, B, C, D)   \
+   (SIGNATURE_16(A, B) | (SIGNATURE_16(C, D) << 16))
+
+#define FMP_PAYLOAD_HDR_SIGNATURE  SIGNATURE_32('M', 'S', 'S', '1')
+
+/**
+ * struct fmp_payload_header - EDK2 header for the FMP payload
+ *
+ * This structure describes the header which is preprended to the
+ * FMP payload by the edk2 capsule generation scripts.
+ *
+ * @signature: Header signature used to identify the header
+ * @header_size:   Size of the structure
+ * @fw_version:Firmware versions used
+ * @lowest_supported_version:  Lowest supported version
+ */
+struct fmp_payload_header {
+   uint32_t signature;
+   uint32_t header_size;
+   uint32_t fw_version;
+   uint32_t lowest_supported_version;
+};
+
+struct fmp_payload_header_params {
+   bool have_header;
+   uint32_t fw_version;
+   uint32_t lowest_supported_version;
+};
+
 #endif /* _EFI_CAPSULE_H */
diff --git a/tools/mkeficapsule.c b/tools/mkeficapsule.c
index b71537beee..e50e6a8ed7 100644
--- a/tools/mkeficapsule.c
+++ b/tools/mkeficapsule.c
@@ -29,7 +29,7 @@ static const char *tool_name = "mkeficapsule";
 efi_guid_t efi_guid_fm_capsule = EFI_FIRMWARE_MANAGEMENT_CAPSULE_ID_GUID;
 efi_guid_t efi_guid_cert_type_pkcs7 = EFI_CERT_TYPE_PKCS7_GUID;
 
-static const char *opts_short = "g:i:I:v:p:c:m:o:dhAR";
+static const char *opts_short = "g:i:I:v:l:p:c:m:o:dhAR";
 
 enum {
CAPSULE_NORMAL_BLOB = 0,
@@ -41,6 +41,8 @@ static struct option options[] = {
{"guid", required_argument, NULL, 'g'},
{"index", required_argument, NULL, 'i'},
{"instance", required_argument, NULL, 'I'},
+   {"fw-version", required_argument, NULL, 'v'},
+   {"lsv", required_argument, NULL, 'l'},
{"private-key", required_argument, NULL, 'p'},
{"certificate", required_argument, NULL, 'c'},
{"monotonic-count", required_argument, NULL, 'm'},
@@ -60,6 +62,8 @@ static void print_usage(void)
"\t-g, --guid guid for image blob type\n"
"\t-i, --index  update image index\n"
"\t-I, --instanceupdate hardware instance\n"
+   "\t-v, --fw-version   firmware version\n"
+   "\t-l, --lsv  lowest supported version\n"
"\t-p, --private-key   private key file\n"
"\t-c, --certificate  signer's certificate 
file\n"
"\t-m, --monotonic-count  monotonic count\n"
@@ -402,6 +406,7 @@ static void free_sig_data(struct auth_context *ctx)
  */
 static int create_fwbin(char *path, char *bin, efi_guid_t *guid,
unsigned long index, unsigned long instance,
+   struct fmp_payload_header_params *fmp_ph_params,
uint64_t mcount, char *privkey_file, char *cert_file,
uint16_t oemflags)
 {
@@ -410,10 +415,11 @@ 

[PATCH v3 3/4] efi_loader: check lowest supported version in capsule update

2023-03-19 Thread Masahisa Kojima
The FMP Payload Header which EDK2 capsule generation scripts
insert contains lowest supported version.
This commit reads the lowest supported version stored in the
"FmpState" EFI non-volatile variable, then check if the
firmware version of ongoing capsule is equal or greater than
the lowest supported version.

Signed-off-by: Masahisa Kojima 
---
No changes since v2

Changes in v2:
- add error message when the firmware version is lower than
  lowest supported version

 lib/efi_loader/efi_firmware.c | 50 ++-
 1 file changed, 49 insertions(+), 1 deletion(-)

diff --git a/lib/efi_loader/efi_firmware.c b/lib/efi_loader/efi_firmware.c
index 289456ecbb..8d6e32006d 100644
--- a/lib/efi_loader/efi_firmware.c
+++ b/lib/efi_loader/efi_firmware.c
@@ -391,6 +391,39 @@ void efi_firmware_parse_payload_header(const void 
**p_image,
*p_image_size = image_size;
 }
 
+/**
+ * efi_firmware_get_lowest_supported_version - get the lowest supported version
+ * @image_index:   image_index
+ *
+ * Get the lowest supported version from FmpState variable.
+ *
+ * Return: lowest supported version, return 0 if reading 
FmpState
+ * variable failed
+ */
+static
+u32 efi_firmware_get_lowest_supported_version(u8 image_index)
+{
+   u16 varname[13]; /* u"FmpState" */
+   efi_status_t ret;
+   efi_uintn_t size;
+   efi_guid_t *image_type_id;
+   struct fmp_state var_state = { 0 };
+
+   image_type_id = efi_firmware_get_image_type_id(image_index);
+   if (!image_type_id)
+   return 0;
+
+   efi_create_indexed_name(varname, sizeof(varname), "FmpState",
+   image_index);
+   size = sizeof(var_state);
+   ret = efi_get_variable_int(varname, image_type_id, NULL, ,
+  _state, NULL);
+   if (ret != EFI_SUCCESS)
+   return 0;
+
+   return var_state.lowest_supported_version;
+}
+
 /**
  * efi_firmware_verify_image - verify image
  * @p_image:   Pointer to new image
@@ -398,7 +431,8 @@ void efi_firmware_parse_payload_header(const void **p_image,
  * @image_indexImage index
  * @state  Pointer to fmp state
  *
- * Verify the capsule file
+ * Verify the capsule authentication and check if the fw_version
+ * is equal or greater than the lowest supported version.
  *
  * Return: status code
  */
@@ -409,10 +443,24 @@ efi_status_t efi_firmware_verify_image(const void 
**p_image,
   struct fmp_state *state)
 {
efi_status_t ret;
+   u32 lowest_supported_version;
 
ret = efi_firmware_capsule_authenticate(p_image, p_image_size, state);
efi_firmware_parse_payload_header(p_image, p_image_size, state);
 
+   /* check lowest_supported_version if capsule authentication passes */
+   if (ret == EFI_SUCCESS) {
+   lowest_supported_version =
+   efi_firmware_get_lowest_supported_version(image_index);
+   if (lowest_supported_version > state->fw_version) {
+   printf("fw_version(%u) is too low(expected >%u). 
Aborting update\n",
+  state->fw_version, lowest_supported_version);
+   state->last_attempt_status =
+   LAST_ATTEMPT_STATUS_ERROR_INCORRECT_VERSION;
+   ret = EFI_INVALID_PARAMETER;
+   }
+   }
+
return ret;
 }
 
-- 
2.17.1



[PATCH v3 2/4] efi_loader: versioning support in GetImageInfo

2023-03-19 Thread Masahisa Kojima
Current FMP->GetImageInfo() always return 0 for the firmware
version, user can not identify which firmware version is currently
running through the EFI interface.

This commit reads the "FmpState" EFI variable, then fills the
firmware version, lowest supported version, last attempt version
and last attempt status in FMP->GetImageInfo().

Now FMP->GetImageInfo() and ESRT have the meaningful version number.

Signed-off-by: Masahisa Kojima 
---
No update since v1

 lib/efi_loader/efi_firmware.c | 30 ++
 1 file changed, 26 insertions(+), 4 deletions(-)

diff --git a/lib/efi_loader/efi_firmware.c b/lib/efi_loader/efi_firmware.c
index d6f3741024..289456ecbb 100644
--- a/lib/efi_loader/efi_firmware.c
+++ b/lib/efi_loader/efi_firmware.c
@@ -190,13 +190,38 @@ static efi_status_t efi_fill_image_desc_array(
*package_version_name = NULL; /* not supported */
 
for (i = 0; i < num_image_type_guids; i++) {
+   u16 varname[13]; /* u"FmpState" */
+   efi_status_t ret;
+   efi_uintn_t size;
+   struct fmp_state var_state = { 0 };
+
image_info[i].image_index = fw_array[i].image_index;
image_info[i].image_type_id = fw_array[i].image_type_id;
image_info[i].image_id = fw_array[i].image_index;
 
image_info[i].image_id_name = fw_array[i].fw_name;
 
-   image_info[i].version = 0; /* not supported */
+   efi_create_indexed_name(varname, sizeof(varname), "FmpState",
+   fw_array[i].image_index);
+   size = sizeof(var_state);
+   ret = efi_get_variable_int(varname, _array[i].image_type_id,
+  NULL, , _state, NULL);
+   if (ret == EFI_SUCCESS) {
+   image_info[i].version = var_state.fw_version;
+   image_info[i].lowest_supported_image_version =
+   var_state.lowest_supported_version;
+   image_info[i].last_attempt_version =
+   var_state.last_attempt_version;
+   image_info[i].last_attempt_status =
+   var_state.last_attempt_status;
+   } else {
+   image_info[i].version = 0;
+   image_info[i].lowest_supported_image_version = 0;
+   image_info[i].last_attempt_version = 0;
+   image_info[i].last_attempt_status =
+   LAST_ATTEMPT_STATUS_SUCCESS;
+   }
+
image_info[i].version_name = NULL; /* not supported */
image_info[i].size = 0;
image_info[i].attributes_supported =
@@ -210,9 +235,6 @@ static efi_status_t efi_fill_image_desc_array(
image_info[0].attributes_setting |=
IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED;
 
-   image_info[i].lowest_supported_image_version = 0;
-   image_info[i].last_attempt_version = 0;
-   image_info[i].last_attempt_status = LAST_ATTEMPT_STATUS_SUCCESS;
image_info[i].hardware_instance = 1;
image_info[i].dependencies = NULL;
}
-- 
2.17.1



[PATCH v3 1/4] efi_loader: store firmware version into FmpState variable

2023-03-19 Thread Masahisa Kojima
Firmware version management is not implemented in the current
FMP protocol.
EDK2 reference implementation capsule generation script inserts
the FMP Payload Header right before the payload, it contains the
firmware version and lowest supported version.

This commit utilizes the FMP Payload Header, read the header and
stores the firmware version, lowest supported version,
last attempt version and last attempt status into "FmpState"
EFI non-volatile variable.  indicates the image index,
since FMP protocol handles multiple image indexes.

This change is compatible with the existing FMP implementation.
This change does not mandate the FMP Payload Header.
If no FMP Payload Header is found in the capsule file, fw_version,
lowest supported version, last attempt version and last attempt
status is 0 and this is the same behavior as existing FMP
implementation.

Signed-off-by: Masahisa Kojima 
---
Changes in v3:
- exclude CONFIG_FWU_MULTI_BANK_UPDATE case
- set image_type_id as a vendor field of FmpState variable
- set READ_ONLY flag for FmpState variable
- add error code for FIT image case

Changes in v2:
- modify indent

 lib/efi_loader/efi_firmware.c | 224 ++
 1 file changed, 201 insertions(+), 23 deletions(-)

diff --git a/lib/efi_loader/efi_firmware.c b/lib/efi_loader/efi_firmware.c
index 93e2b01c07..d6f3741024 100644
--- a/lib/efi_loader/efi_firmware.c
+++ b/lib/efi_loader/efi_firmware.c
@@ -10,6 +10,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -36,6 +37,24 @@ struct fmp_payload_header {
u32 lowest_supported_version;
 };
 
+/**
+ * struct fmp_state - fmp firmware update state
+ *
+ * This structure describes the state of the firmware update
+ * through FMP protocol.
+ *
+ * @fw_version:Firmware versions used
+ * @lowest_supported_version:  Lowest supported version
+ * @last_attempt_version:  Last attempt version
+ * @last_attempt_status:   Last attempt status
+ */
+struct fmp_state {
+   u32 fw_version;
+   u32 lowest_supported_version;
+   u32 last_attempt_version;
+   u32 last_attempt_status;
+};
+
 __weak void set_dfu_alt_info(char *interface, char *devstr)
 {
env_set("dfu_alt_info", update_info.dfu_string);
@@ -102,6 +121,29 @@ efi_status_t EFIAPI 
efi_firmware_set_package_info_unsupported(
return EFI_EXIT(EFI_UNSUPPORTED);
 }
 
+/**
+ * efi_firmware_get_image_type_id - get image_type_id
+ * @image_index:   image index
+ *
+ * Return the image_type_id identified by the image index.
+ *
+ * Return: pointer to the image_type_id, NULL if image_index is 
invalid
+ */
+static
+efi_guid_t *efi_firmware_get_image_type_id(u8 image_index)
+{
+   int i;
+   struct efi_fw_image *fw_array;
+
+   fw_array = update_info.images;
+   for (i = 0; i < num_image_type_guids; i++) {
+   if (fw_array[i].image_index == image_index)
+   return _array[i].image_type_id;
+   }
+
+   return NULL;
+}
+
 /**
  * efi_fill_image_desc_array - populate image descriptor array
  * @image_info_size:   Size of @image_info
@@ -182,6 +224,7 @@ static efi_status_t efi_fill_image_desc_array(
  * efi_firmware_capsule_authenticate - authenticate the capsule if enabled
  * @p_image:   Pointer to new image
  * @p_image_size:  Pointer to size of new image
+ * @state  Pointer to fmp state
  *
  * Authenticate the capsule if authentication is enabled.
  * The image pointer and the image size are updated in case of success.
@@ -190,12 +233,11 @@ static efi_status_t efi_fill_image_desc_array(
  */
 static
 efi_status_t efi_firmware_capsule_authenticate(const void **p_image,
-  efi_uintn_t *p_image_size)
+  efi_uintn_t *p_image_size,
+  struct fmp_state *state)
 {
const void *image = *p_image;
efi_uintn_t image_size = *p_image_size;
-   u32 fmp_hdr_signature;
-   struct fmp_payload_header *header;
void *capsule_payload;
efi_status_t status;
efi_uintn_t capsule_payload_size;
@@ -209,8 +251,12 @@ efi_status_t efi_firmware_capsule_authenticate(const void 
**p_image,
 
if (status == EFI_SECURITY_VIOLATION) {
printf("Capsule authentication check failed. Aborting 
update\n");
+   state->last_attempt_status =
+   LAST_ATTEMPT_STATUS_ERROR_AUTH_ERROR;
return status;
} else if (status != EFI_SUCCESS) {
+   state->last_attempt_status =
+   LAST_ATTEMPT_STATUS_ERROR_UNSUCCESSFUL;
return status;
}
 
@@ -222,24 +268,130 @@ efi_status_t efi_firmware_capsule_authenticate(const 
void **p_image,
debug("Updating 

[PATCH v3 0/4] FMP versioning support

2023-03-19 Thread Masahisa Kojima
Firmware version management is not implemented in the current
FMP implementation. This series aims to add the versioning support
in FMP.
Python based test will follow later.

EDK2 reference implementation utilizes the FMP Payload Header
inserted right before the capsule payload. With this series,
U-Boot also follows the EDK2 implementation.

Currently, there is no way to know the current running firmware
version through the EFI interface. FMP->GetImageInfo() returns
always 0 for the version number. So a user can not know that
expected firmware is running after the capsule update.

With this series applied, version number can be specified
in the capsule file generation with mkeficapsule tool, then
user can know the running firmware version through
FMP->GetImageInfo() and ESRT.

Note that this series does not mandate the FMP Payload Header,
compatible with boards that are already using the existing
U-Boot FMP implementation.
If no FMP Payload Header is found in the capsule file, fw_version,
lowest supported version, last attempt version and last attempt
status is set to 0 and this is the same behavior as existing FMP
implementation.

Changes in v3:
- exclude CONFIG_FWU_MULTI_BANK_UPDATE case

Masahisa Kojima (4):
  efi_loader: store firmware version into FmpState variable
  efi_loader: versioning support in GetImageInfo
  efi_loader: check lowest supported version in capsule update
  mkeficapsule: add FMP Payload Header

 doc/mkeficapsule.1|  16 ++
 lib/efi_loader/efi_firmware.c | 302 +++---
 tools/eficapsule.h|  32 
 tools/mkeficapsule.c  |  51 +-
 4 files changed, 369 insertions(+), 32 deletions(-)

-- 
2.17.1



[PATCH v3 9/9] bootstd: Relax the argument requirements for bootflow scan

2023-03-19 Thread Simon Glass
Currently this does not allow the -lb flags unless CMD_BOOTFLOW_FULL is
enabled, which means that we need two separate boot commands. Relax this
to make things easier. It is only a small amount of extra code.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 boot/Kconfig   |  3 +--
 cmd/bootflow.c | 14 --
 2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/boot/Kconfig b/boot/Kconfig
index 3bda7b5a793d..b8c1ebc4b345 100644
--- a/boot/Kconfig
+++ b/boot/Kconfig
@@ -1563,8 +1563,7 @@ config USE_BOOTCOMMAND
 config BOOTCOMMAND
string "bootcmd value"
depends on USE_BOOTCOMMAND && !USE_DEFAULT_ENV_FILE
-   default "bootflow scan -lb" if BOOTSTD_BOOTCOMMAND && CMD_BOOTFLOW_FULL
-   default "bootflow scan" if BOOTSTD_BOOTCOMMAND && !CMD_BOOTFLOW_FULL
+   default "bootflow scan -lb" if BOOTSTD_BOOTCOMMAND
default "run distro_bootcmd" if !BOOTSTD_BOOTCOMMAND && DISTRO_DEFAULTS
help
  This is the string of commands that will be used as bootcmd and if
diff --git a/cmd/bootflow.c b/cmd/bootflow.c
index 42f6e14a4370..c345b020070f 100644
--- a/cmd/bootflow.c
+++ b/cmd/bootflow.c
@@ -124,9 +124,19 @@ static int do_bootflow_scan(struct cmd_tbl *cmdtp, int 
flag, int argc,
if (!label)
dev = std->cur_bootdev;
} else {
+   /*
+* allow -b and -l (which is ignored) but complain about
+* anything else
+*/
if (has_args) {
-   printf("Flags not supported: enable 
CONFIG_BOOTFLOW_FULL\n");
-   return CMD_RET_USAGE;
+   char *p;
+
+   for (p = argv[1] + 1; *p; p++) {
+   if (*p != 'b' && *p != 'l') {
+   printf("Flags not supported: enable 
CONFIG_BOOTFLOW_FULL\n");
+   return CMD_RET_USAGE;
+   }
+   }
}
boot = true;
}
-- 
2.40.0.rc1.284.g88254d51c5-goog



[PATCH v3 8/9] rockchip: Move to standard boot

2023-03-19 Thread Simon Glass
Drop the distro-boot scripts and use standard boot instead.

Signed-off-by: Simon Glass 
---

Changes in v3:
- Update rk3588 boards too

Changes in v2:
- Add new patch to move rockchip to standard boot

 arch/arm/Kconfig  |  1 -
 include/configs/px30_common.h |  4 +--
 include/configs/rk3036_common.h   |  5 +--
 include/configs/rk3066_common.h   |  5 +--
 include/configs/rk3128_common.h   |  4 +--
 include/configs/rk3188_common.h   |  5 +--
 include/configs/rk322x_common.h   |  5 +--
 include/configs/rk3288_common.h   |  5 +--
 include/configs/rk3308_common.h   |  4 +--
 include/configs/rk3328_common.h   |  4 +--
 include/configs/rk3368_common.h   |  5 +--
 include/configs/rk3399_common.h   |  2 +-
 include/configs/rk3568_common.h   |  4 +--
 include/configs/rk3588_common.h   |  4 +--
 include/configs/rockchip-common.h | 58 ---
 include/configs/rv1108_common.h   |  3 +-
 16 files changed, 14 insertions(+), 104 deletions(-)

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index e324387ad057..5fe21413d6bc 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -1956,7 +1956,6 @@ config ARCH_ROCKCHIP
imply ADC
imply CMD_DM
imply DEBUG_UART_BOARD_INIT
-   imply DISTRO_DEFAULTS if !ROCKCHIP_RK3399
imply FAT_WRITE
imply SARADC_ROCKCHIP
imply SPL_SYSRESET
diff --git a/include/configs/px30_common.h b/include/configs/px30_common.h
index c0896e5f6281..a4c8bfebdf84 100644
--- a/include/configs/px30_common.h
+++ b/include/configs/px30_common.h
@@ -25,12 +25,10 @@
"kernel_addr_c=0x03e8\0" \
"ramdisk_addr_r=0x0a20\0"
 
-#include 
 #define CFG_EXTRA_ENV_SETTINGS \
ENV_MEM_LAYOUT_SETTINGS \
"fdtfile=" CONFIG_DEFAULT_FDT_FILE "\0" \
"partitions=" PARTS_DEFAULT \
-   ROCKCHIP_DEVICE_SETTINGS \
-   BOOTENV
+   ROCKCHIP_DEVICE_SETTINGS
 
 #endif
diff --git a/include/configs/rk3036_common.h b/include/configs/rk3036_common.h
index ea6073f29446..e056555276aa 100644
--- a/include/configs/rk3036_common.h
+++ b/include/configs/rk3036_common.h
@@ -21,15 +21,12 @@
"kernel_addr_r=0x6200\0" \
"ramdisk_addr_r=0x6400\0"
 
-#include 
-
 /* Linux fails to load the fdt if it's loaded above 512M on a evb-rk3036 board,
  * so limit the fdt reallocation to that */
 #define CFG_EXTRA_ENV_SETTINGS \
"fdt_file=" CONFIG_DEFAULT_FDT_FILE "\0" \
"fdt_high=0x7fff\0" \
"partitions=" PARTS_DEFAULT \
-   ENV_MEM_LAYOUT_SETTINGS \
-   BOOTENV
+   ENV_MEM_LAYOUT_SETTINGS
 
 #endif
diff --git a/include/configs/rk3066_common.h b/include/configs/rk3066_common.h
index 1a6d3678df3e..7f4d48c1ea95 100644
--- a/include/configs/rk3066_common.h
+++ b/include/configs/rk3066_common.h
@@ -22,14 +22,11 @@
"kernel_addr_r=0x6200\0" \
"ramdisk_addr_r=0x6400\0"
 
-#include 
-
 #define CFG_EXTRA_ENV_SETTINGS \
"fdt_high=0x6fff\0" \
"initrd_high=0x6fff\0" \
"partitions=" PARTS_DEFAULT \
ENV_MEM_LAYOUT_SETTINGS \
-   ROCKCHIP_DEVICE_SETTINGS \
-   BOOTENV
+   ROCKCHIP_DEVICE_SETTINGS
 
 #endif
diff --git a/include/configs/rk3128_common.h b/include/configs/rk3128_common.h
index 8aa17bfbd364..6d531f6bc812 100644
--- a/include/configs/rk3128_common.h
+++ b/include/configs/rk3128_common.h
@@ -26,11 +26,9 @@
"kernel_addr_r=0x6200\0" \
"ramdisk_addr_r=0x6400\0"
 
-#include 
 #define CFG_EXTRA_ENV_SETTINGS \
ENV_MEM_LAYOUT_SETTINGS \
"fdt_file=" CONFIG_DEFAULT_FDT_FILE "\0" \
-   "partitions=" PARTS_DEFAULT \
-   BOOTENV
+   "partitions=" PARTS_DEFAULT
 
 #endif
diff --git a/include/configs/rk3188_common.h b/include/configs/rk3188_common.h
index ac9195672fb7..80d2619fb78f 100644
--- a/include/configs/rk3188_common.h
+++ b/include/configs/rk3188_common.h
@@ -27,8 +27,6 @@
"kernel_addr_r=0x6200\0" \
"ramdisk_addr_r=0x6400\0"
 
-#include 
-
 /* Linux fails to load the fdt if it's loaded above 256M on a Rock board,
  * so limit the fdt reallocation to that */
 #define CFG_EXTRA_ENV_SETTINGS \
@@ -37,7 +35,6 @@
"initrd_high=0x6fff\0" \
"partitions=" PARTS_DEFAULT \
ENV_MEM_LAYOUT_SETTINGS \
-   ROCKCHIP_DEVICE_SETTINGS \
-   BOOTENV
+   ROCKCHIP_DEVICE_SETTINGS
 
 #endif
diff --git a/include/configs/rk322x_common.h b/include/configs/rk322x_common.h
index fcaf9c52c4be..fb6c1033499b 100644
--- a/include/configs/rk322x_common.h
+++ b/include/configs/rk322x_common.h
@@ -23,15 +23,12 @@
"kernel_addr_r=0x6200\0" \
"ramdisk_addr_r=0x6400\0"
 
-#include 
-
 /* Linux fails to load the fdt if it's loaded above 512M on a evb-rk3036 board,
  * so limit the fdt reallocation to that */
 #define CFG_EXTRA_ENV_SETTINGS \
"fdtfile=" CONFIG_DEFAULT_FDT_FILE "\0" \
"fdt_high=0x7fff\0" \
"partitions=" PARTS_DEFAULT \
-   

[PATCH v3 6/9] lmb: Enable LMB if SYS_BOOT_RAMDISK_HIGH

2023-03-19 Thread Simon Glass
Ramdisk relocation requires LMB, so enable it automatically to avoid
build errors.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 boot/Kconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/boot/Kconfig b/boot/Kconfig
index 7da084312d67..769a78e249c5 100644
--- a/boot/Kconfig
+++ b/boot/Kconfig
@@ -834,6 +834,7 @@ config SYS_BOOT_RAMDISK_HIGH
depends on CMD_BOOTM || CMD_BOOTI || CMD_BOOTZ
depends on !(NIOS2 || SANDBOX || SH || XTENSA)
def_bool y
+   select LMB
help
  Enable initrd_high functionality.  If defined then the initrd_high
  feature is enabled and the boot* ramdisk subcommand is enabled.
-- 
2.40.0.rc1.284.g88254d51c5-goog



[PATCH v3 5/9] Move DISTRO_DEFAULTS into boot/

2023-03-19 Thread Simon Glass
This relates to booting so move it in to that Kconfig file, before
changing it.

Signed-off-by: Simon Glass 
---

(no changes since v2)

Changes in v2:
- Add new patch to move DISTRO_DEFAULTS into boot/

 Kconfig  | 27 ---
 boot/Kconfig | 28 +++-
 2 files changed, 27 insertions(+), 28 deletions(-)

diff --git a/Kconfig b/Kconfig
index a75cce7e28fb..b8f65589f457 100644
--- a/Kconfig
+++ b/Kconfig
@@ -191,33 +191,6 @@ config XEN
 
  [1] - https://xenproject.org/
 
-config DISTRO_DEFAULTS
-   bool "Select defaults suitable for booting general purpose Linux 
distributions"
-   select AUTO_COMPLETE
-   select CMDLINE_EDITING
-   select CMD_BOOTI if ARM64
-   select CMD_BOOTZ if ARM && !ARM64
-   select CMD_DHCP if CMD_NET
-   select CMD_ENV_EXISTS
-   select CMD_EXT2
-   select CMD_EXT4
-   select CMD_FAT
-   select CMD_FS_GENERIC
-   select CMD_PART if PARTITIONS
-   select CMD_PING if CMD_NET
-   select CMD_PXE if NET
-   select CMD_SYSBOOT
-   select ENV_VARS_UBOOT_CONFIG
-   select HUSH_PARSER
-   select SUPPORT_RAW_INITRD
-   select SYS_LONGHELP
-   imply CMD_MII if NET
-   imply USB_STORAGE
-   imply USE_BOOTCOMMAND
-   help
- Select this to enable various options and commands which are suitable
- for building u-boot for booting general purpose Linux distributions.
-
 config ENV_VARS_UBOOT_CONFIG
bool "Add arch, board, vendor and soc variables to default environment"
help
diff --git a/boot/Kconfig b/boot/Kconfig
index 3e567a5547c3..7da084312d67 100644
--- a/boot/Kconfig
+++ b/boot/Kconfig
@@ -408,7 +408,6 @@ if BOOTSTD
 
 config BOOTSTD_DEFAULTS
bool "Select some common defaults for standard boot"
-   depends on BOOTSTD
default y
imply USE_BOOTCOMMAND
# Bring in some defaults which are generally needed. Boards can drop
@@ -841,6 +840,33 @@ config SYS_BOOT_RAMDISK_HIGH
 
 endmenu# Boot images
 
+config DISTRO_DEFAULTS
+   bool "Select defaults suitable for booting general purpose Linux 
distributions"
+   select AUTO_COMPLETE
+   select CMDLINE_EDITING
+   select CMD_BOOTI if ARM64
+   select CMD_BOOTZ if ARM && !ARM64
+   select CMD_DHCP if CMD_NET
+   select CMD_ENV_EXISTS
+   select CMD_EXT2
+   select CMD_EXT4
+   select CMD_FAT
+   select CMD_FS_GENERIC
+   select CMD_PART if PARTITIONS
+   select CMD_PING if CMD_NET
+   select CMD_PXE if NET
+   select CMD_SYSBOOT
+   select ENV_VARS_UBOOT_CONFIG
+   select HUSH_PARSER
+   select SUPPORT_RAW_INITRD
+   select SYS_LONGHELP
+   imply CMD_MII if NET
+   imply USB_STORAGE
+   imply USE_BOOTCOMMAND
+   help
+ Select this to enable various options and commands which are suitable
+ for building u-boot for booting general purpose Linux distributions.
+
 menu "Boot timing"
 
 config BOOTSTAGE
-- 
2.40.0.rc1.284.g88254d51c5-goog



[PATCH v3 4/9] bootstd: Enable BOOTSTD_DEFAULTS by default

2023-03-19 Thread Simon Glass
This is needed to enable the boot command used to start standard boot.
Enable it by default. This brings in quite a few features, mostly in
common with DISTRO_DEFAULTS

Disable this option for boards which don't have enough space.

Disable CONFIG_ENV_VARS_UBOOT_CONFIG for some zynq boards which have
a very small environment. Disable BOOTSTD_DEFAULTS for smartweb since
it is too close to its limit.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 boot/Kconfig | 1 +
 configs/bk4r1_defconfig  | 1 +
 configs/sama5d27_giantboard_defconfig| 1 +
 configs/sama5d27_som1_ek_mmc1_defconfig  | 1 +
 configs/sama5d27_som1_ek_mmc_defconfig   | 1 +
 configs/sama5d27_som1_ek_qspiflash_defconfig | 1 +
 configs/sama5d27_wlsom1_ek_mmc_defconfig | 1 +
 configs/sama5d2_icp_mmc_defconfig| 1 +
 configs/sama5d2_xplained_emmc_defconfig  | 1 +
 configs/sama5d2_xplained_mmc_defconfig   | 1 +
 configs/sama5d2_xplained_qspiflash_defconfig | 1 +
 configs/sheevaplug_defconfig | 1 +
 configs/smartweb_defconfig   | 1 +
 configs/taurus_defconfig | 1 +
 configs/tools-only_defconfig | 2 +-
 configs/xilinx_versal_mini_emmc0_defconfig   | 4 +---
 configs/xilinx_versal_mini_emmc1_defconfig   | 4 +---
 configs/xilinx_zynqmp_mini_emmc0_defconfig   | 4 +---
 configs/xilinx_zynqmp_mini_emmc1_defconfig   | 4 +---
 19 files changed, 19 insertions(+), 13 deletions(-)

diff --git a/boot/Kconfig b/boot/Kconfig
index d646369f55c3..3e567a5547c3 100644
--- a/boot/Kconfig
+++ b/boot/Kconfig
@@ -409,6 +409,7 @@ if BOOTSTD
 config BOOTSTD_DEFAULTS
bool "Select some common defaults for standard boot"
depends on BOOTSTD
+   default y
imply USE_BOOTCOMMAND
# Bring in some defaults which are generally needed. Boards can drop
# these as needed to save code space. Bootstd does not generally require
diff --git a/configs/bk4r1_defconfig b/configs/bk4r1_defconfig
index 66adeac725ce..298518e7ea59 100644
--- a/configs/bk4r1_defconfig
+++ b/configs/bk4r1_defconfig
@@ -21,6 +21,7 @@ CONFIG_SYS_MEMTEST_END=0x87c0
 CONFIG_HAS_BOARD_SIZE_LIMIT=y
 CONFIG_BOARD_SIZE_LIMIT=520192
 CONFIG_FIT=y
+# CONFIG_BOOTSTD_DEFAULTS is not set
 CONFIG_BOOTDELAY=3
 CONFIG_AUTOBOOT_KEYED=y
 CONFIG_AUTOBOOT_PROMPT="Enter passphrase to stop autoboot, booting in %d 
seconds\n"
diff --git a/configs/sama5d27_giantboard_defconfig 
b/configs/sama5d27_giantboard_defconfig
index 39d1dcdbb796..39680fcf69d7 100644
--- a/configs/sama5d27_giantboard_defconfig
+++ b/configs/sama5d27_giantboard_defconfig
@@ -29,6 +29,7 @@ CONFIG_DEBUG_UART=y
 CONFIG_ENV_VARS_UBOOT_CONFIG=y
 CONFIG_SYS_MONITOR_LEN=524288
 CONFIG_FIT=y
+# CONFIG_BOOTSTD_DEFAULTS is not set
 CONFIG_SD_BOOT=y
 CONFIG_BOOTDELAY=3
 CONFIG_AUTOBOOT_KEYED=y
diff --git a/configs/sama5d27_som1_ek_mmc1_defconfig 
b/configs/sama5d27_som1_ek_mmc1_defconfig
index cdb000fe1ebe..dd76c79b82e3 100644
--- a/configs/sama5d27_som1_ek_mmc1_defconfig
+++ b/configs/sama5d27_som1_ek_mmc1_defconfig
@@ -28,6 +28,7 @@ CONFIG_DEBUG_UART=y
 CONFIG_ENV_VARS_UBOOT_CONFIG=y
 CONFIG_SYS_MONITOR_LEN=524288
 CONFIG_FIT=y
+# CONFIG_BOOTSTD_DEFAULTS is not set
 CONFIG_SD_BOOT=y
 CONFIG_BOOTDELAY=3
 CONFIG_USE_BOOTARGS=y
diff --git a/configs/sama5d27_som1_ek_mmc_defconfig 
b/configs/sama5d27_som1_ek_mmc_defconfig
index 1471cebaf4d0..d5c3c01cf707 100644
--- a/configs/sama5d27_som1_ek_mmc_defconfig
+++ b/configs/sama5d27_som1_ek_mmc_defconfig
@@ -29,6 +29,7 @@ CONFIG_DEBUG_UART=y
 CONFIG_ENV_VARS_UBOOT_CONFIG=y
 CONFIG_SYS_MONITOR_LEN=524288
 CONFIG_FIT=y
+# CONFIG_BOOTSTD_DEFAULTS is not set
 CONFIG_SD_BOOT=y
 CONFIG_BOOTDELAY=3
 CONFIG_USE_BOOTARGS=y
diff --git a/configs/sama5d27_som1_ek_qspiflash_defconfig 
b/configs/sama5d27_som1_ek_qspiflash_defconfig
index 1c8adfbb7a31..f765379985f8 100644
--- a/configs/sama5d27_som1_ek_qspiflash_defconfig
+++ b/configs/sama5d27_som1_ek_qspiflash_defconfig
@@ -29,6 +29,7 @@ CONFIG_DEBUG_UART=y
 CONFIG_ENV_VARS_UBOOT_CONFIG=y
 CONFIG_SYS_MONITOR_LEN=524288
 CONFIG_FIT=y
+# CONFIG_BOOTSTD_DEFAULTS is not set
 CONFIG_QSPI_BOOT=y
 CONFIG_BOOTDELAY=3
 CONFIG_USE_BOOTARGS=y
diff --git a/configs/sama5d27_wlsom1_ek_mmc_defconfig 
b/configs/sama5d27_wlsom1_ek_mmc_defconfig
index eeb8d209f2b4..ec11575224ee 100644
--- a/configs/sama5d27_wlsom1_ek_mmc_defconfig
+++ b/configs/sama5d27_wlsom1_ek_mmc_defconfig
@@ -27,6 +27,7 @@ CONFIG_DEBUG_UART=y
 CONFIG_ENV_VARS_UBOOT_CONFIG=y
 CONFIG_SYS_MONITOR_LEN=524288
 CONFIG_FIT=y
+# CONFIG_BOOTSTD_DEFAULTS is not set
 CONFIG_SD_BOOT=y
 CONFIG_BOOTDELAY=3
 CONFIG_USE_BOOTARGS=y
diff --git a/configs/sama5d2_icp_mmc_defconfig 
b/configs/sama5d2_icp_mmc_defconfig
index e1b602d8e5ec..2abe775480c1 100644
--- a/configs/sama5d2_icp_mmc_defconfig
+++ b/configs/sama5d2_icp_mmc_defconfig
@@ -27,6 +27,7 @@ CONFIG_DEBUG_UART=y
 CONFIG_ENV_VARS_UBOOT_CONFIG=y
 CONFIG_SYS_MONITOR_LEN=524288
 CONFIG_FIT=y
+# 

[PATCH v3 3/9] rockchip: Disable DISTRO_DEFAULTS for rk3399 boards

2023-03-19 Thread Simon Glass
These board have moved to standard boot but the old 'distro_bootcmd'
command is still active. Disable DISTRO_DEFAULTS to fix this.

Signed-off-by: Simon Glass 
Tested-by: Vagrant Cascadian 
---

(no changes since v1)

 arch/arm/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index c51f15fcf465..e324387ad057 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -1956,7 +1956,7 @@ config ARCH_ROCKCHIP
imply ADC
imply CMD_DM
imply DEBUG_UART_BOARD_INIT
-   imply DISTRO_DEFAULTS
+   imply DISTRO_DEFAULTS if !ROCKCHIP_RK3399
imply FAT_WRITE
imply SARADC_ROCKCHIP
imply SPL_SYSRESET
-- 
2.40.0.rc1.284.g88254d51c5-goog



[PATCH v3 2/9] rockchip: Drop bootstage stash in TPL and SPL for rockpro64

2023-03-19 Thread Simon Glass
Unfortunately the IRAM used to stash the bootstage records in TPL
becomes inaccessible after SPL runs. Presumably this is because of ATF
taking it over.

We could move the stash to another address in SPL, before passing it to
U-Boot proper. But it seems easier to wait until we have support for
standard passage[1] which should not be too far away.

For now, disable it in TPL and SPL.

[1] https://patchwork.ozlabs.org/project/uboot/cover/
20220117150428.1580273-1-...@chromium.org/

Signed-off-by: Simon Glass 
Tested-by: Vagrant Cascadian 
---

(no changes since v2)

Changes in v2:
- Fix 'accessible' typo

 configs/rockpro64-rk3399_defconfig | 5 -
 1 file changed, 5 deletions(-)

diff --git a/configs/rockpro64-rk3399_defconfig 
b/configs/rockpro64-rk3399_defconfig
index dd67f9dff64b..496142368195 100644
--- a/configs/rockpro64-rk3399_defconfig
+++ b/configs/rockpro64-rk3399_defconfig
@@ -13,7 +13,6 @@ CONFIG_DM_RESET=y
 CONFIG_ROCKCHIP_RK3399=y
 CONFIG_TARGET_ROCKPRO64_RK3399=y
 CONFIG_SPL_STACK=0x40
-CONFIG_BOOTSTAGE_STASH_ADDR=0xff8e
 CONFIG_DEBUG_UART_BASE=0xFF1A
 CONFIG_DEBUG_UART_CLOCK=2400
 CONFIG_SPL_SPI_FLASH_SUPPORT=y
@@ -21,11 +20,7 @@ CONFIG_SPL_SPI=y
 CONFIG_SYS_LOAD_ADDR=0x800800
 CONFIG_DEBUG_UART=y
 CONFIG_BOOTSTAGE=y
-CONFIG_SPL_BOOTSTAGE=y
-CONFIG_TPL_BOOTSTAGE=y
 CONFIG_BOOTSTAGE_REPORT=y
-CONFIG_SPL_BOOTSTAGE_RECORD_COUNT=10
-CONFIG_BOOTSTAGE_STASH=y
 CONFIG_USE_PREBOOT=y
 CONFIG_DEFAULT_FDT_FILE="rockchip/rk3399-rockpro64.dtb"
 CONFIG_DISPLAY_BOARDINFO_LATE=y
-- 
2.40.0.rc1.284.g88254d51c5-goog



[PATCH v3 1/9] configs: Resync with savedefconfig

2023-03-19 Thread Simon Glass
Rsync all defconfig files using moveconfig.py

Signed-off-by: Simon Glass 
---

(no changes since v1)

 configs/clearfog_defconfig  |  2 --
 configs/clearfog_gt_8k_defconfig|  2 --
 configs/clearfog_sata_defconfig |  7 +++
 configs/db-88f6820-amc_nand_defconfig   |  6 +++---
 configs/eDPU_defconfig  |  2 --
 configs/evb-px5_defconfig   |  1 -
 configs/evb-rk3568_defconfig|  1 -
 configs/helios4_defconfig   |  2 --
 configs/lion-rk3368_defconfig   |  1 -
 configs/mvebu_ac5_rd_defconfig  |  2 --
 configs/mvebu_crb_cn9130_defconfig  |  2 --
 configs/mvebu_db-88f3720_defconfig  |  2 --
 configs/mvebu_db_armada8k_defconfig |  2 --
 configs/mvebu_db_cn9130_defconfig   |  2 --
 configs/mvebu_espressobin-88f3720_defconfig |  2 --
 configs/mvebu_mcbin-88f8040_defconfig   |  2 --
 configs/mvebu_puzzle-m801-88f8040_defconfig |  2 --
 configs/nanopi-r4s-rk3399_defconfig | 12 ++--
 configs/neu6a-io-rk3588_defconfig   |  3 +--
 configs/rock-3a-rk3568_defconfig| 17 -
 configs/rock-pi-s-rk3308_defconfig  |  8 
 configs/sandbox64_defconfig |  1 -
 configs/sandbox_defconfig   |  1 -
 configs/sandbox_flattree_defconfig  |  1 -
 configs/sandbox_noinst_defconfig|  1 -
 configs/sandbox_spl_defconfig   |  1 -
 configs/sandbox_vpl_defconfig   |  1 -
 configs/turris_mox_defconfig|  2 --
 configs/turris_omnia_defconfig  |  1 -
 configs/uDPU_defconfig  |  2 --
 configs/wandboard_defconfig |  1 -
 configs/xilinx_zynqmp_mini_defconfig|  1 -
 configs/xilinx_zynqmp_mini_emmc0_defconfig  |  1 -
 configs/xilinx_zynqmp_mini_emmc1_defconfig  |  1 -
 configs/xilinx_zynqmp_mini_nand_defconfig   |  1 -
 .../xilinx_zynqmp_mini_nand_single_defconfig|  1 -
 configs/xilinx_zynqmp_mini_qspi_defconfig   |  1 -
 configs/zynq_cse_qspi_defconfig |  1 -
 38 files changed, 25 insertions(+), 74 deletions(-)

diff --git a/configs/clearfog_defconfig b/configs/clearfog_defconfig
index 8cd35f9f1a41..f5263edf4e86 100644
--- a/configs/clearfog_defconfig
+++ b/configs/clearfog_defconfig
@@ -46,7 +46,6 @@ CONFIG_CMD_USB=y
 CONFIG_CMD_TFTPPUT=y
 CONFIG_CMD_CACHE=y
 CONFIG_CMD_TIME=y
-CONFIG_CMD_MVEBU_BUBT=y
 CONFIG_ENV_OVERWRITE=y
 CONFIG_ENV_MIN_ENTRIES=128
 CONFIG_ARP_TIMEOUT=200
@@ -59,7 +58,6 @@ CONFIG_DM_I2C=y
 CONFIG_SYS_I2C_MVTWSI=y
 CONFIG_I2C_EEPROM=y
 CONFIG_SPL_I2C_EEPROM=y
-CONFIG_SUPPORT_EMMC_BOOT=y
 CONFIG_MMC_SDHCI=y
 CONFIG_MMC_SDHCI_SDMA=y
 CONFIG_MMC_SDHCI_MV=y
diff --git a/configs/clearfog_gt_8k_defconfig b/configs/clearfog_gt_8k_defconfig
index f82025513c9c..8b7de182fbbb 100644
--- a/configs/clearfog_gt_8k_defconfig
+++ b/configs/clearfog_gt_8k_defconfig
@@ -23,7 +23,6 @@ CONFIG_SYS_CONSOLE_INFO_QUIET=y
 # CONFIG_DISPLAY_CPUINFO is not set
 # CONFIG_DISPLAY_BOARDINFO is not set
 CONFIG_DISPLAY_BOARDINFO_LATE=y
-CONFIG_ARCH_EARLY_INIT_R=y
 CONFIG_BOARD_EARLY_INIT_F=y
 CONFIG_SYS_MAXARGS=32
 CONFIG_SYS_BOOTM_LEN=0x80
@@ -37,7 +36,6 @@ CONFIG_CMD_USB=y
 CONFIG_CMD_TFTPPUT=y
 CONFIG_CMD_CACHE=y
 CONFIG_CMD_TIME=y
-CONFIG_CMD_MVEBU_BUBT=y
 CONFIG_CMD_REGULATOR=y
 CONFIG_CMD_EXT4_WRITE=y
 CONFIG_MAC_PARTITION=y
diff --git a/configs/clearfog_sata_defconfig b/configs/clearfog_sata_defconfig
index e9b36150eae9..53b5daec16a0 100644
--- a/configs/clearfog_sata_defconfig
+++ b/configs/clearfog_sata_defconfig
@@ -6,11 +6,14 @@ CONFIG_TEXT_BASE=0x0080
 CONFIG_SPL_LIBCOMMON_SUPPORT=y
 CONFIG_SPL_LIBGENERIC_SUPPORT=y
 CONFIG_NR_DRAM_BANKS=2
+CONFIG_HAS_CUSTOM_SYS_INIT_SP_ADDR=y
+CONFIG_CUSTOM_SYS_INIT_SP_ADDR=0xff
 CONFIG_TARGET_CLEARFOG=y
 CONFIG_MVEBU_SPL_BOOT_DEVICE_SATA=y
 CONFIG_DEFAULT_DEVICE_TREE="armada-388-clearfog"
 CONFIG_SPL_TEXT_BASE=0x4030
 CONFIG_SPL_SERIAL=y
+CONFIG_SPL_STACK=0x4002c000
 CONFIG_SPL=y
 CONFIG_DEBUG_UART_BASE=0xf1012000
 CONFIG_DEBUG_UART_CLOCK=25000
@@ -18,8 +21,6 @@ CONFIG_SYS_LOAD_ADDR=0x80
 CONFIG_DEBUG_UART=y
 CONFIG_AHCI=y
 CONFIG_DISTRO_DEFAULTS=y
-CONFIG_HAS_CUSTOM_SYS_INIT_SP_ADDR=y
-CONFIG_CUSTOM_SYS_INIT_SP_ADDR=0xff
 CONFIG_BOOTDELAY=3
 CONFIG_USE_PREBOOT=y
 CONFIG_SYS_CONSOLE_INFO_QUIET=y
@@ -31,7 +32,6 @@ CONFIG_SPL_BSS_START_ADDR=0x40023000
 CONFIG_SPL_BSS_MAX_SIZE=0x4000
 CONFIG_SPL_SYS_MALLOC_SIMPLE=y
 # CONFIG_SPL_SHARES_INIT_SP_ADDR is not set
-CONFIG_SPL_STACK=0x4002c000
 CONFIG_SPL_I2C=y
 CONFIG_SYS_MAXARGS=32
 CONFIG_CMD_TLV_EEPROM=y
@@ -46,7 +46,6 @@ CONFIG_CMD_USB=y
 CONFIG_CMD_TFTPPUT=y
 CONFIG_CMD_CACHE=y
 CONFIG_CMD_TIME=y
-CONFIG_CMD_MVEBU_BUBT=y
 CONFIG_ENV_OVERWRITE=y
 CONFIG_ENV_MIN_ENTRIES=128
 CONFIG_ARP_TIMEOUT=200
diff 

Re: [PATCH v1 2/5] net: dwc_eth_qos: Add StarFive ethernet driver glue layer

2023-03-19 Thread yanhong wang



On 2023/3/19 4:20, Simon Glass wrote:
> Hi Yanhong,
> 
> On Thu, 16 Mar 2023 at 19:07, Yanhong Wang
>  wrote:
>>
>> The StarFive ETHQOS hardware has its own clock and reset,so add a
>> corresponding glue driver to configure them.
>>
>> Signed-off-by: Yanhong Wang 
>> ---
>>  drivers/net/Kconfig|   7 +
>>  drivers/net/Makefile   |   1 +
>>  drivers/net/dwc_eth_qos.c  |   6 +
>>  drivers/net/dwc_eth_qos.h  |   2 +
>>  drivers/net/dwc_eth_qos_starfive.c | 306 +
>>  5 files changed, 322 insertions(+)
>>  create mode 100644 drivers/net/dwc_eth_qos_starfive.c
> 
>>[..]
> 
>> diff --git a/drivers/net/dwc_eth_qos_starfive.c 
>> b/drivers/net/dwc_eth_qos_starfive.c
>> new file mode 100644
>> index 00..eeb45981bd
>> --- /dev/null
>> +++ b/drivers/net/dwc_eth_qos_starfive.c
>> @@ -0,0 +1,306 @@
>> +// SPDX-License-Identifier: GPL-2.0+
>> +/*
>> + * Copyright (C) 2023 StarFive Technology Co., Ltd.
>> + * Author: Yanhong Wang
>> + */
>> +
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +
>> +#include "dwc_eth_qos.h"
>> +
>> +#define STARFIVE_DWMAC_PHY_INFT_RGMII  0x1
>> +#define STARFIVE_DWMAC_PHY_INFT_RMII   0x4
>> +#define STARFIVE_DWMAC_PHY_INFT_FIELD  0x7U
>> +
>> +static int eqos_interface_init_jh7110(struct udevice *dev,
>> + phy_interface_t interface_type)
>> +{
>> +   struct regmap *regmap;
>> +   struct ofnode_phandle_args args;
>> +   unsigned int mode;
>> +   int ret;
>> +
>> +   switch (interface_type) {
>> +   case PHY_INTERFACE_MODE_RMII:
>> +   mode = STARFIVE_DWMAC_PHY_INFT_RMII;
>> +   break;
>> +
>> +   case PHY_INTERFACE_MODE_RGMII:
>> +   case PHY_INTERFACE_MODE_RGMII_ID:
>> +   mode = STARFIVE_DWMAC_PHY_INFT_RGMII;
>> +   break;
>> +
>> +   default:
>> +   return -EINVAL;
>> +   }
>> +
>> +   ret = dev_read_phandle_with_args(dev, "starfive,syscon", NULL,
>> +2, 0, );
> 
> You must read the DT in an ofdata_to_plat() method (or probe() if that
> doesn't suit). Put it in a struct.
> 
> You must not read it constantly at runtime throughout your driver. It
> is slow and error-prone.
> [..]
> 

Thanks. I will define a platform data structure for saving device-related 
configurations in the next version.

>> +
>> +struct eqos_config __maybe_unused eqos_jh7110_config = {
>> +   .reg_access_always_ok = false,
>> +   .mdio_wait = 10,
>> +   .swr_wait = 50,
>> +   .config_mac = EQOS_MAC_RXQ_CTRL0_RXQ0EN_ENABLED_DCB,
>> +   .config_mac_mdio = EQOS_MAC_MDIO_ADDRESS_CR_250_300,
>> +   .axi_bus_width = EQOS_AXI_WIDTH_64,
>> +   .interface = dev_read_phy_mode,
>> +   .ops = _jh7110_ops
>> +};
>> --
>> 2.17.1
>>
> 
> What is that data for? Please add a comment.
> 

The definition of these parameters refers to IMX platform, I will double 
confirm whether the definition of 
these parameters is accurate, and add corresponding comments in the next 
version.

> Regards,
> SImom


Re: [PATCH v1 1/5] net: phy: Add driver for Motorcomm yt8531 gigabit ethernet phy

2023-03-19 Thread yanhong wang



On 2023/3/19 4:20, Simon Glass wrote:
> Hi Yanhong,
> 
> On Thu, 16 Mar 2023 at 19:06, Yanhong Wang
>  wrote:
>>
>> Add a driver for the motorcomm yt8531 gigabit ethernet phy. We have
>> verified the driver on StarFive VisionFive2 board.
>>
>> Signed-off-by: Yanhong Wang 
>> ---
>>  drivers/net/phy/Kconfig |   6 +
>>  drivers/net/phy/Makefile|   1 +
>>  drivers/net/phy/motorcomm.c | 409 
>>  drivers/net/phy/phy.c   |   4 +-
>>  include/phy.h   |   1 +
>>  5 files changed, 420 insertions(+), 1 deletion(-)
>>  create mode 100644 drivers/net/phy/motorcomm.c
>>
>> diff --git a/drivers/net/phy/Kconfig b/drivers/net/phy/Kconfig
>> index 5eaff053a0..aba718566a 100644
>> --- a/drivers/net/phy/Kconfig
>> +++ b/drivers/net/phy/Kconfig
>> @@ -212,6 +212,12 @@ config PHY_MICREL_KSZ8XXX
>>
>>  endif # PHY_MICREL
>>
>> +config PHY_MOTORCOMM
>> +   tristate "Motorcomm PHYs"
>> +   help
>> + Enables support for Motorcomm network PHYs.
>> + Currently supports the YT8531 Gigabit Ethernet PHYs.
>> +
>>  config PHY_MSCC
>> bool "Microsemi Corp Ethernet PHYs support"
>>
>> diff --git a/drivers/net/phy/Makefile b/drivers/net/phy/Makefile
>> index d38e99e717..e9523fed2e 100644
>> --- a/drivers/net/phy/Makefile
>> +++ b/drivers/net/phy/Makefile
>> @@ -23,6 +23,7 @@ obj-$(CONFIG_PHY_MARVELL) += marvell.o
>>  obj-$(CONFIG_PHY_MICREL_KSZ8XXX) += micrel_ksz8xxx.o
>>  obj-$(CONFIG_PHY_MICREL_KSZ90X1) += micrel_ksz90x1.o
>>  obj-$(CONFIG_PHY_MESON_GXL) += meson-gxl.o
>> +obj-$(CONFIG_PHY_MOTORCOMM) += motorcomm.o
>>  obj-$(CONFIG_PHY_NATSEMI) += natsemi.o
>>  obj-$(CONFIG_PHY_NXP_C45_TJA11XX) += nxp-c45-tja11xx.o
>>  obj-$(CONFIG_PHY_NXP_TJA11XX) += nxp-tja11xx.o
>> diff --git a/drivers/net/phy/motorcomm.c b/drivers/net/phy/motorcomm.c
>> new file mode 100644
>> index 00..c7e44cfb63
>> --- /dev/null
>> +++ b/drivers/net/phy/motorcomm.c
>> @@ -0,0 +1,409 @@
>> +// SPDX-License-Identifier: GPL-2.0+
>> +/*
> 
> [..]
> 
>> +static u32 ytphy_get_delay_reg_value(struct phy_device *phydev,
>> +const char *prop_name,
>> +const struct ytphy_cfg_reg_map *tbl,
>> +int tb_size,
>> +u16 *rxc_dly_en,
>> +u32 dflt)
>> +{
>> +   int tb_size_half = tb_size / 2;
>> +   u32 val;
>> +   int i;
>> +
>> +   if (ofnode_read_u32(phydev->node, prop_name, ))
>> +   goto err_dts_val;
> 
> Please move to your ofdata_to_plat() method.
> 
> Also, use dev_read_u32() when you have a device.
> 
> [.]
> 

Thanks. I will define a platform data structure for saving device-related 
configurations in the next version.

>> +static int yt8531_startup(struct phy_device *phydev)
>> +{
>> +   bool tx_clk_adj_enabled = false;
>> +   bool tx_clk_1000_inverted = false;
>> +   bool tx_clk_100_inverted = false;
>> +   bool tx_clk_10_inverted = false;
>> +   u16 val = 0;
>> +   int ret;
>> +
>> +   ret = genphy_update_link(phydev);
>> +   if (ret)
>> +   return ret;
>> +
>> +   ret = yt8531_parse_status(phydev);
>> +   if (ret)
>> +   return ret;
>> +
>> +   if (ofnode_read_bool(phydev->node, "motorcomm,tx-clk-adj-enabled"))
>> +   tx_clk_adj_enabled = true;
> 
> priv->tx_clk_adj_enabled = ofnode_read_bool(...)
> 
> Please fix globally
> 

Ok. I will fixed.

> Regards,
> Simon


Re: [PATCH 4/4] CI: Add m68k target

2023-03-19 Thread Marek Vasut

On 3/19/23 20:27, Angelo Dureghello wrote:

Hi,

[...]


+qemu_m68k test.py:
+  variables:
+    TEST_PY_BD: "M5208EVBE"
+    TEST_PY_TEST_SPEC: "not sleep and not efi"
+    TEST_PY_ID: "--id qemu"
+    OVERRIDE: "-a CONFIG_M68K_QEMU=y -a CONFIG_MCFTMR=n"
+  <<: *buildman_and_testpy_dfn
+
  qemu_malta test.py:
    variables:
  TEST_PY_BD: "malta"


i tested the patchset in u-boot-coldfire, i see also a pipeline error:

https://source.denx.de/u-boot/custodians/u-boot-coldfire/-/pipelines/15651/failures


That should be fixed here:

https://source.denx.de/u-boot/custodians/u-boot-sh/-/tree/m68k/wip

But I still suspect the qemu run will fail due to missing m68k qemu in 
the current docker image. Tom ?


Re: [PATCH v1 1/6] rockchip: gpio: rk_gpio: use ROCKCHIP_GPIOS_PER_BANK as divider

2023-03-19 Thread Kever Yang

Hi Johan,

On 2023/3/19 19:34, Johan Jonker wrote:


On 3/18/23 21:20, Simon Glass wrote:

Hi Johan,

On Thu, 16 Mar 2023 at 10:46, Johan Jonker  wrote:

The current divider to calculate the bank ID can change.
Use a constant ROCKCHIP_GPIOS_PER_BANK as fixed divider.

What is the motivation for this patch?

The gpio-ranges property format:

gpio-ranges = <[pin controller phandle], [GPIO controller offset],
 [pin controller offset], [number of pins]>;

1: Given the Rockchip TRM not all gpio-banks have 32 pins per bank.


Could you share which TRM did you find gpio-banks is not 32 pins?

The design should be 32 pins per bank for all the SoCs, although some 
banks may not have full 32 pins,


but all the pin ID should follow the rules with 32pin per bank.


Thanks,

- Kever


2: The "gpio-ranges" syntax allows multiple items with variable number of pins.

===

Theoretical example:

gpio-ranges = < 0 32 32>; // 32/32 => bank 1

vs.

gpio-ranges = < 16 48 16>, // 48/16 => bank 3 vs. 48/32 => bank 1
   < 0 32 16>; // 32/16  => bank 2 vs. 32/32 => bank 1

Both descriptions are valid.
The number of pins in the second example is reduced to 16 per item.
Using that as divider will give a wrong bank number.
Use a constant instead.
For the Rockchip situation simple parsing the first item is enough the know 
it's bank number for now.
To do it correct one could parse a list of gpio-range items, but that makes it 
more complicated.

>From gpio.txt:
Each offset runs from 0 to N. It is perfectly fine to pile any number of
ranges with just one pin-to-GPIO line mapping if the ranges are concocted, but
in practice these ranges are often lumped in discrete sets.


Signed-off-by: Johan Jonker 
---
  drivers/gpio/rk_gpio.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Simon Glass 


diff --git a/drivers/gpio/rk_gpio.c b/drivers/gpio/rk_gpio.c
index f7ad4d68..0a2acf18 100644
--- a/drivers/gpio/rk_gpio.c
+++ b/drivers/gpio/rk_gpio.c
@@ -160,7 +160,7 @@ static int rockchip_gpio_probe(struct udevice *dev)
  0, );
 if (!ret || ret != -ENOENT) {
 uc_priv->gpio_count = args.args[2];
-   priv->bank = args.args[1] / args.args[2];
+   priv->bank = args.args[1] / ROCKCHIP_GPIOS_PER_BANK;
 } else {
 uc_priv->gpio_count = ROCKCHIP_GPIOS_PER_BANK;
 end = strrchr(dev->name, '@');
--
2.20.1


Regards,
SImon


[PATCH v4] test_vboot.py: include test of fdt_add_pubkey tool

2023-03-19 Thread Ivan Mikhaylov
From: Roman Kopytin 

Add test_fdt_add_pubkey test which provides simple functionality test
which contains such steps:
 create DTB and FIT files
 add keys with fdt_add_pubkey to DTB
 sign FIT image
 check with fit_check_sign that keys properly added to DTB file

Signed-off-by: Roman Kopytin 
Signed-off-by: Ivan Mikhaylov 
Cc: Rasmus Villemoes 
---
 test/py/tests/test_vboot.py | 200 ++--
 1 file changed, 166 insertions(+), 34 deletions(-)

diff --git a/test/py/tests/test_vboot.py b/test/py/tests/test_vboot.py
index e3e7ca4b21..5d69a8c70e 100644
--- a/test/py/tests/test_vboot.py
+++ b/test/py/tests/test_vboot.py
@@ -30,6 +30,12 @@ For pre-load header verification:
 - Check that image verification fails
 
 Tests run with both SHA1 and SHA256 hashing.
+
+This also tests fdt_add_pubkey utility in the simple way:
+- Create DTB and FIT files
+- Add keys with fdt_add_pubkey to DTB
+- Sign FIT image
+- Check with fit_check_sign that keys properly added to DTB file
 """
 
 import os
@@ -40,6 +46,41 @@ import u_boot_utils as util
 import vboot_forge
 import vboot_evil
 
+# Common helper functions
+def dtc(dts, cons, dtc_args, datadir, tmpdir, dtb):
+"""Run the device tree compiler to compile a .dts file
+
+The output file will be the same as the input file but with a .dtb
+extension.
+
+Args:
+dts: Device tree file to compile.
+cons: U-Boot console.
+dtc_args: DTC arguments.
+datadir: Path to data directory.
+tmpdir: Path to temp directory.
+dtb: Resulting DTB file.
+"""
+dtb = dts.replace('.dts', '.dtb')
+util.run_and_log(cons, 'dtc %s %s%s -O dtb '
+ '-o %s%s' % (dtc_args, datadir, dts, tmpdir, dtb))
+
+def make_fit(its, cons, mkimage, dtc_args, datadir, fit):
+"""Make a new FIT from the .its source file.
+
+This runs 'mkimage -f' to create a new FIT.
+
+Args:
+its: Filename containing .its source.
+cons: U-Boot console.
+mkimage: Path to mkimage utility.
+dtc_args: DTC arguments.
+datadir: Path to data directory.
+fit: Resulting FIT file.
+"""
+util.run_and_log(cons, [mkimage, '-D', dtc_args, '-f',
+'%s%s' % (datadir, its), fit])
+
 # Only run the full suite on a few combinations, since it doesn't add any more
 # test coverage.
 TESTDATA_IN = [
@@ -82,19 +123,6 @@ def test_vboot(u_boot_console, name, sha_algo, padding, 
sign_options, required,
 The SHA1 and SHA256 tests are combined into a single test since the
 key-generation process is quite slow and we want to avoid doing it twice.
 """
-def dtc(dts):
-"""Run the device tree compiler to compile a .dts file
-
-The output file will be the same as the input file but with a .dtb
-extension.
-
-Args:
-dts: Device tree file to compile.
-"""
-dtb = dts.replace('.dts', '.dtb')
-util.run_and_log(cons, 'dtc %s %s%s -O dtb '
- '-o %s%s' % (dtc_args, datadir, dts, tmpdir, dtb))
-
 def dtc_options(dts, options):
 """Run the device tree compiler to compile a .dts file
 
@@ -152,16 +180,27 @@ def test_vboot(u_boot_console, name, sha_algo, padding, 
sign_options, required,
 assert('sandbox: continuing, as we cannot run'
not in ''.join(output))
 
-def make_fit(its):
-"""Make a new FIT from the .its source file.
-
-This runs 'mkimage -f' to create a new FIT.
+def create_rsa_pair(name):
+"""Generate a new RSA key paid and certificate
 
 Args:
-its: Filename containing .its source.
+name: Name of of the key (e.g. 'dev')
 """
-util.run_and_log(cons, [mkimage, '-D', dtc_args, '-f',
-'%s%s' % (datadir, its), fit])
+public_exponent = 65537
+
+if sha_algo == "sha384":
+rsa_keygen_bits = 3072
+else:
+rsa_keygen_bits = 2048
+
+util.run_and_log(cons, 'openssl genpkey -algorithm RSA -out %s%s.key '
+ '-pkeyopt rsa_keygen_bits:%d '
+ '-pkeyopt rsa_keygen_pubexp:%d' %
+ (tmpdir, name, rsa_keygen_bits, public_exponent))
+
+# Create a certificate containing the public key
+util.run_and_log(cons, 'openssl req -batch -new -x509 -key %s%s.key '
+ '-out %s%s.crt' % (tmpdir, name, tmpdir, name))
 
 def sign_fit(sha_algo, options):
 """Sign the FIT
@@ -286,12 +325,12 @@ def test_vboot(u_boot_console, name, sha_algo, padding, 
sign_options, required,
 # Compile our device tree files for kernel and U-Boot. These are
 # regenerated here since mkimage will modify them (by adding a
 # public key) below.
-dtc('sandbox-kernel.dts')
-dtc('sandbox-u-boot.dts')
+dtc('sandbox-kernel.dts', cons, dtc_args, datadir, 

Re: [PATCH] netconsole: various improvements

2023-03-19 Thread Tony Dinh
Hi Pali,

On Sun, Mar 19, 2023 at 12:36 PM Pali Rohár  wrote:
>
> On Saturday 18 March 2023 14:46:25 Tony Dinh wrote:
> > - When Netconsole is running, stdin/stdout/stderr are set to nc. Reset
> > stdin/stdout/stderr to serial (a sane deffault) before booting kernel.
>
> This can be a problematic. serial output does not have to be available
> for all devices. For example on Nokia N900 phone is available only
> lcd/vga display device.

Here is a shortcoming of the current implementation of netconsole.
When it starts, the user sets the stdin/stdout/stderr envs to nc, and
we lose the previous state of the console. Especially with the
CONSOLE_MUX is not enabled. There is no way to set them back by
setting the envs in booting logic.

It sounds like we need to implement internal envs to save the previous
state, and then restore it before shutting down the network and
booting the kernel.
I recall in previous Linux kernel versions many years ago Linux still
booted OK, but recently it can no longer boot with the stdio set to nc
(I've tested this failure case). Perhaps nc should _not_ be set
explicitly by the user. We might need a u-boot command to start
netconsole, and that would include checking if the serverip is
running?

>
> Also this can break CONSOLE_MUX support when more devices are specified
> in stdin/stdout/stderr env variables. With CONSOLE_MUX, output is send
> to more than one device. User may set it to both serial and nc or also
> to other output (e.g. to lcd like on Nokia N900).
>
> So in my opinion, if "nc" is is going to be turned off then just "nc"
> string should be removed from env variable and let all other devices
> stay in env variables.
>
> Maybe you can use something like this? (taken from common/usb_kbd.c)
>
> #if CONFIG_IS_ENABLED(CONSOLE_MUX)
> if (iomux_replace_device(stdin, "nc", "nulldev"))
> return 1;
> #endif

Thanks for pointing out that fact about CONSOLE_MUX. Yes I will
incorporate that as part of the logic.

All the best,
Tony

>
> > - Enable net_timeout when netconsole starts will give a better user
> > experience if netconsole server is not running.
> >
> > Signed-off-by: Tony Dinh 
> > ---
> >
> >  boot/bootm.c | 16 +++-
> >  drivers/net/netconsole.c |  2 +-
> >  2 files changed, 16 insertions(+), 2 deletions(-)
> >
> > diff --git a/boot/bootm.c b/boot/bootm.c
> > index 2eec60ec7b..c4a3aaf1bd 100644
> > --- a/boot/bootm.c
> > +++ b/boot/bootm.c
> > @@ -473,7 +473,21 @@ ulong bootm_disable_interrupts(void)
> >*/
> >   iflag = disable_interrupts();
> >  #ifdef CONFIG_NETCONSOLE
> > - /* Stop the ethernet stack if NetConsole could have left it up */
> > + /*
> > +  * Make sure that the starting kernel message printed out.
> > +  * Reset stdin/out/err back to serial and stop the ethernet
> > +  * stack if NetConsole could have left it up
> > +  */
> > + char *s;
> > + int ret;
> > +
> > + s = env_get("stdout");
> > + if (strcmp(s, "nc") == 0) {
> > + printf("\n\nStarting kernel ...\n");
> > + ret = env_set("stdin", "serial");
> > + ret = env_set("stdout", "serial");
> > + ret = env_set("stderr", "serial");
> > + }
> >   eth_halt();
> >  #endif
> >
> > diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c
> > index 151bc55e07..2091014918 100644
> > --- a/drivers/net/netconsole.c
> > +++ b/drivers/net/netconsole.c
> > @@ -20,7 +20,7 @@ static int input_size; /* char count in input buffer */
> >  static int input_offset; /* offset to valid chars in input buffer */
> >  static int input_recursion;
> >  static int output_recursion;
> > -static int net_timeout;
> > +static int net_timeout = 1;
> >  static uchar nc_ether[6]; /* server enet address */
> >  static struct in_addr nc_ip; /* server ip */
> >  static short nc_out_port; /* target output port */
> > --
> > 2.30.2
> >


Re: [PATCH] netconsole: various improvements

2023-03-19 Thread Tony Dinh
Hi Simon,

On Sun, Mar 19, 2023 at 12:30 PM Simon Glass  wrote:
>
> Hi Tony,
>
> On Sun, 19 Mar 2023 at 10:46, Tony Dinh  wrote:
> >
> > - When Netconsole is running, stdin/stdout/stderr are set to nc. Reset
> > stdin/stdout/stderr to serial (a sane deffault) before booting kernel.
>
> spelling

OK.
>
> > - Enable net_timeout when netconsole starts will give a better user
> > experience if netconsole server is not running.
> >
> > Signed-off-by: Tony Dinh 
> > ---
> >
> >  boot/bootm.c | 16 +++-
> >  drivers/net/netconsole.c |  2 +-
> >  2 files changed, 16 insertions(+), 2 deletions(-)
> >
> > diff --git a/boot/bootm.c b/boot/bootm.c
> > index 2eec60ec7b..c4a3aaf1bd 100644
> > --- a/boot/bootm.c
> > +++ b/boot/bootm.c
> > @@ -473,7 +473,21 @@ ulong bootm_disable_interrupts(void)
> >  */
> > iflag = disable_interrupts();
> >  #ifdef CONFIG_NETCONSOLE
>
> Can you convert this to 'if IS_ENABLED(...)' at the same time?

Sure I will.
>
> > -   /* Stop the ethernet stack if NetConsole could have left it up */
> > +   /*
> > +* Make sure that the starting kernel message printed out.
> > +* Reset stdin/out/err back to serial and stop the ethernet
> > +* stack if NetConsole could have left it up
> > +*/
> > +   char *s;
> > +   int ret;
> > +
> > +   s = env_get("stdout");
> > +   if (strcmp(s, "nc") == 0) {
> > +   printf("\n\nStarting kernel ...\n");
> > +   ret = env_set("stdin", "serial");
> > +   ret = env_set("stdout", "serial");
> > +   ret = env_set("stderr", "serial");
> > +   }
> > eth_halt();
> >  #endif
> >
> > diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c
> > index 151bc55e07..2091014918 100644
> > --- a/drivers/net/netconsole.c
> > +++ b/drivers/net/netconsole.c
> > @@ -20,7 +20,7 @@ static int input_size; /* char count in input buffer */
> >  static int input_offset; /* offset to valid chars in input buffer */
> >  static int input_recursion;
> >  static int output_recursion;
> > -static int net_timeout;
> > +static int net_timeout = 1;
>
> What is this change?

I've been carrying this one-line patch out-of-tree for a few years.
Back when I saw that the netconsole started transitioning faster from
the serial console (I tested with 2 consoles running) . But I can no
longer prove that anymore! code change... I think it does not hurt to
set it to timeout initially anyway, since netconsole is polling for
chars. But I will remove this part of the patch if others think it is
not necessary.

>
> >  static uchar nc_ether[6]; /* server enet address */
> >  static struct in_addr nc_ip; /* server ip */
> >  static short nc_out_port; /* target output port */
> > --
> > 2.30.2
> >
>
> Could you take a look at converting netconsole to driver model? It
> should be a child of the eth device probably. I think this patch is OK
> for, but it would be better if the driver could deregister itself from
> stdio in its remove() method, perhaps installing serial at that point.

Agreed. It would be nice to have netconsole as a driver model. It will
get more attention that it deserves. I'm a bit short for free time
atm, though. I will make it a task to work on it.

Thanks,
Tony

> Regards,
> SImon


Re: [PATCH v3] Let the EQoS in imx8mp handle fixed-phy too.

2023-03-19 Thread Marek Vasut

On 3/19/23 21:02, Elmar Psilog wrote:


Am 19.03.23 um 18:21 schrieb Marek Vasut:

On 3/19/23 11:43, Elmar Psilog wrote:

Without that patch it lost track to the node to scan
speed and duplex.
Patch was created by Marek Vasut, just tested by me.

Signed-off-by: Elmar Psilog 
Reviewed-by: Marek Vasut 
---
   changes v2: fix format issues
   changes v3: remove {} around single if, add reviewd..

  drivers/net/dwc_eth_qos.c | 18 +++---
  1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/drivers/net/dwc_eth_qos.c b/drivers/net/dwc_eth_qos.c
index 112deb546d..b9de205b8a 100644
--- a/drivers/net/dwc_eth_qos.c
+++ b/drivers/net/dwc_eth_qos.c
@@ -788,9 +788,21 @@ static int eqos_start(struct udevice *dev)
   */
  if (!eqos->phy) {
  int addr = -1;
-    addr = eqos_get_phy_addr(eqos, dev);
-    eqos->phy = phy_connect(eqos->mii, addr, dev,
-    eqos->config->interface(dev));
+    ofnode fixed_node;
+
+    if (IS_ENABLED(CONFIG_PHY_FIXED)) {
+    fixed_node = ofnode_find_subnode(dev_ofnode(dev),
+ "fixed-link");
+    if (ofnode_valid(fixed_node))
+    eqos->phy = fixed_phy_create(dev_ofnode(dev));
+    }
+
+    if (!eqos->phy) {
+    addr = eqos_get_phy_addr(eqos, dev);
+    eqos->phy = phy_connect(eqos->mii, addr, dev,
+    eqos->config->interface(dev));
+    }
+
  if (!eqos->phy) {
  pr_err("phy_connect() failed");
  goto err_stop_resets;
--
2.34.1



I would give a short reminder about the patch. Reviewed by Marek, ok for
Ramon. Would be glad to see it in 2023.04.


We're already in 2023.04-rc4 , this is material for v2023.07 , i.e. 
for u-boot/next branch .


Ok, but does it change anything for the patch itself?


No, it will be applied to u-boot-net / next and then proceed via PR to 
u-boot / next .


As source isn't 
touched in last weeks it is still needed. Other way asked: Any action 
(from my side) needed?


No, it is up to Ramon now.

I just afraid your (@Marek) and my work gets 
lost. I would expect either an "accepted" or "rejected" (for a reason).


It's just overloaded/busy maintainers problem, sadly, this does happen 
from time to time. The patch is tracked by patchwork, so it shouldn't be 
lost.


[PATCH v2 2/2] drivers: rtc: add max313xx series rtc driver

2023-03-19 Thread Chris Packham
Adding support for Analog Devices MAX313XX series RTCs.

This is ported from the Linux driver and adapted for use in u-boot.
Notable differences are
- handling of tm_year and tm_mon differ
- clock source support is omitted
- hwmon support for the MAX31328 and MAX31343 is omitted
- rtc_ops->reset is added

Signed-off-by: Chris Packham 
Reviewed-by: Simon Glass 
---

Changes in v2:
- Enable in sandbox for compile testing
- Note feature omissions in Kconfig
- Incorporate review comments from Simon
- Collect r-by from Simon

 configs/sandbox_defconfig |   1 +
 drivers/rtc/Kconfig   |  13 ++
 drivers/rtc/Makefile  |   1 +
 drivers/rtc/max313xx.c| 459 ++
 4 files changed, 474 insertions(+)
 create mode 100644 drivers/rtc/max313xx.c

diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig
index 77ade1f1d873..0c898df44672 100644
--- a/configs/sandbox_defconfig
+++ b/configs/sandbox_defconfig
@@ -267,6 +267,7 @@ CONFIG_SANDBOX_RESET=y
 CONFIG_RESET_SYSCON=y
 CONFIG_RESET_SCMI=y
 CONFIG_DM_RTC=y
+CONFIG_RTC_MAX313XX=y
 CONFIG_RTC_RV8803=y
 CONFIG_RTC_HT1380=y
 CONFIG_SCSI=y
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index 35b6ed4d7c72..aae2ae61ba36 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -134,6 +134,19 @@ config RTC_ISL1208
  This driver supports reading and writing the RTC/calendar and detects
  total power failures.
 
+config RTC_MAX313XX
+   bool "Analog Devices MAX313XX RTC driver"
+   depends on DM_RTC
+   depends on DM_I2C
+   help
+ If you say yes here you will get support for the
+ Analog Devices MAX313XX series RTC family.
+
+ Chip features not currently supported:
+ - Timestamp registers as SRAM
+ - Temperature sensor
+ - CLKOUT generation
+
 config RTC_PCF8563
tristate "Philips PCF8563"
help
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index 447551e15aa2..adfa23f66702 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -19,6 +19,7 @@ obj-$(CONFIG_RTC_HT1380) += ht1380.o
 obj-$(CONFIG_SANDBOX) += i2c_rtc_emul.o
 obj-$(CONFIG_RTC_ISL1208) += isl1208.o
 obj-$(CONFIG_RTC_M41T62) += m41t62.o
+obj-$(CONFIG_RTC_MAX313XX) += max313xx.o
 obj-$(CONFIG_RTC_MC13XXX) += mc13xxx-rtc.o
 obj-$(CONFIG_RTC_MC146818) += mc146818.o
 obj-$(CONFIG_MCFRTC) += mcfrtc.o
diff --git a/drivers/rtc/max313xx.c b/drivers/rtc/max313xx.c
new file mode 100644
index ..748f3c42c30e
--- /dev/null
+++ b/drivers/rtc/max313xx.c
@@ -0,0 +1,459 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Analog Devices MAX313XX series I2C RTC driver
+ *
+ * Copyright 2022 Analog Devices Inc.
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* common registers */
+#define MAX313XX_INT_ALARM1BIT(0)
+#define MAX313XX_INT_ALARM2BIT(1)
+#define MAX313XX_HRS_F_12_24   BIT(6)
+#define MAX313XX_HRS_F_AM_PM   BIT(5)
+#define MAX313XX_MONTH_CENTURY BIT(7)
+
+#define MAX313XX_TMR_CFG_ENABLEBIT(4)
+#define MAX313XX_TMR_CFG_FREQ_MASK GENMASK(1, 0)
+#define MAX313XX_TMR_CFG_FREQ_16HZ 0x03
+
+#define MAX313XX_REG_MINUTE0x01
+#define MAX313XX_REG_HOUR  0x02
+
+#define MAX313XX_TIME_SIZE 0x07
+
+/* device specific registers */
+#define MAX3134X_CFG2_REG  0x01
+#define MAX3134X_CFG2_SET_RTC  BIT(1)
+
+#define MAX31341_TRICKLE_RES_MASK  GENMASK(1, 0)
+#define MAX31341_TRICKLE_DIODE_EN  BIT(2)
+#define MAX31341_TRICKLE_ENABLE_BITBIT(3)
+#define MAX31341_POWER_MGMT_REG0x56
+#define MAX31341_POWER_MGMT_TRICKLE_BITBIT(0)
+
+#define MAX3133X_TRICKLE_RES_MASK  GENMASK(2, 1)
+#define MAX3133X_TRICKLE_DIODE_EN  BIT(3)
+#define MAX3133X_TRICKLE_ENABLE_BITBIT(0)
+
+#define MAX31329_TRICKLE_ENABLE_BITBIT(7)
+#define MAX31343_TRICKLE_ENABLE_MASK   GENMASK(7, 4)
+#define MAX31343_TRICKLE_ENABLE_CODE   5
+#define MAX31329_43_TRICKLE_RES_MASK   GENMASK(1, 0)
+#define MAX31329_43_TRICKLE_DIODE_EN   BIT(2)
+
+#define MAX31329_CONFIG2_REG   0x04
+#define MAX31329_CONFIG2_CLKIN_EN  BIT(2)
+#define MAX31329_CONFIG2_CLKIN_FREQGENMASK(1, 0)
+
+#define MAX31341_42_CONFIG1_REG0x00
+#define MAX31341_42_CONFIG1_CLKIN_EN   BIT(7)
+#define MAX31341_42_CONFIG1_CLKIN_FREQ GENMASK(5, 4)
+#define MAX31341_42_CONFIG1_OSC_DISABLEBIT(3)
+#define MAX31341_42_CONFIG1_SWRST  BIT(0)
+
+enum max313xx_ids {
+   ID_MAX31328,
+   ID_MAX31329,
+   ID_MAX31331,
+   ID_MAX31334,
+   ID_MAX31341,
+   ID_MAX31342,
+   ID_MAX31343,
+   MAX313XX_ID_NR
+};
+
+/**
+ * struct chip_desc - descriptor for MAX313xx variants
+ * @sec_reg: Offset to seconds register. Used to denote the start of the
+ *   current time registers.
+ * @alarm1_sec_reg: Offset to Alarm1 seconds register. Used to denote the
+ 

[PATCH v2 1/2] include: kernel.h: port find_closest() from Linux

2023-03-19 Thread Chris Packham
The find_closest() macro can be used to find an element in a sorted
array that is closest to an input value. Bring in this macro from
Linux v6.3-rc1-2-g8ca09d5fa354.

Signed-off-by: Chris Packham 
Reviewed-by: Simon Glass 
---

Changes in v2:
- Add note on which Linux version this came from
- Collect review from Simon

 include/linux/kernel.h | 24 
 1 file changed, 24 insertions(+)

diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 3e71d61074b6..5cd6c9dc8219 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -284,4 +284,28 @@
offsetof(struct structure, member) == (offset), \
"`struct " #structure "` offset for `" #member "` is not " #offset)
 
+#define __find_closest(x, a, as, op)   \
+({ \
+   typeof(as) __fc_i, __fc_as = (as) - 1;  \
+   typeof(x) __fc_x = (x); \
+   typeof(*a) const *__fc_a = (a); \
+   for (__fc_i = 0; __fc_i < __fc_as; __fc_i++) {  \
+   if (__fc_x op DIV_ROUND_CLOSEST(__fc_a[__fc_i] +\
+   __fc_a[__fc_i + 1], 2)) \
+   break;  \
+   }   \
+   (__fc_i);   \
+})
+
+/**
+ * find_closest - locate the closest element in a sorted array
+ * @x: The reference value.
+ * @a: The array in which to look for the closest element. Must be sorted
+ *  in ascending order.
+ * @as: Size of 'a'.
+ *
+ * Returns the index of the element closest to 'x'.
+ */
+#define find_closest(x, a, as) __find_closest(x, a, as, <=)
+
 #endif
-- 
2.40.0



[PATCH v2 0/2] max313xx RTC driver

2023-03-19 Thread Chris Packham
This series is based on the in-flight linux patch that is adding support
for this family of RTCs to linux[1]. The u-boot driver is a bit
different due to some of the differences between Linux and u-boot and
I've dropped the support for hwmon and clock source functions. Where
possible I've tried to keep things such that the U-Boot and Linux
versions can be compared and kept in sync.

For reference the datasheets are all available at

https://www.analog.com/media/en/technical-documentation/data-sheets/MAX31328.pdf
https://www.analog.com/media/en/technical-documentation/data-sheets/MAX31329.pdf
https://www.analog.com/media/en/technical-documentation/data-sheets/MAX31331.pdf
https://www.analog.com/media/en/technical-documentation/data-sheets/MAX31334.pdf
https://www.analog.com/media/en/technical-documentation/data-sheets/MAX31341B-MAX31341C.pdf
https://www.analog.com/media/en/technical-documentation/data-sheets/MAX31342.pdf
https://www.analog.com/media/en/technical-documentation/data-sheets/MAX31343.pdf

[1] - 
https://lore.kernel.org/all/20221108122254.1185-2-ibrahim.ti...@analog.com/

Changes in v2:
- Add note on which Linux version this came from
- Collect review from Simon
- Enable in sandbox for compile testing
- Note feature omissions in Kconfig
- Incorporate review comments from Simon
- Collect r-by from Simon

Chris Packham (2):
  include: kernel.h: port find_closest() from Linux
  drivers: rtc: add max313xx series rtc driver

 configs/sandbox_defconfig |   1 +
 drivers/rtc/Kconfig   |  13 ++
 drivers/rtc/Makefile  |   1 +
 drivers/rtc/max313xx.c| 459 ++
 include/linux/kernel.h|  24 ++
 5 files changed, 498 insertions(+)
 create mode 100644 drivers/rtc/max313xx.c

-- 
2.40.0



Re: [PATCH 2/2] efi_loader: fix device-path for USB devices

2023-03-19 Thread Heinrich Schuchardt




On 3/19/23 20:29, Simon Glass wrote:

Hi Heinrich,

On Mon, 20 Mar 2023 at 04:25, Heinrich Schuchardt
 wrote:


EFI device paths for block devices must be unique. If a non-unique device
path is discovered, probing of the block device fails.

Currently we use UsbClass() device path nodes. As multiple devices may
have the same vendor and product id these are non-unique. Instead we
should use Usb() device path nodes. They include the USB port on the
parent hub. Hence they are unique.

A USB storage device may contain multiple logical units. These can be
modeled as Ctrl() nodes.

Reported-by: Patrick Delaunay 
Signed-off-by: Heinrich Schuchardt 
---
  lib/efi_loader/efi_device_path.c | 45 +++-
  1 file changed, 33 insertions(+), 12 deletions(-)


Reviewed-by: Simon Glass 

[..]



diff --git a/lib/efi_loader/efi_device_path.c b/lib/efi_loader/efi_device_path.c
index 3b267b713e..b6dd575b13 100644
--- a/lib/efi_loader/efi_device_path.c
+++ b/lib/efi_loader/efi_device_path.c
@@ -147,7 +147,7 @@ struct efi_device_path *efi_dp_shorten(struct 
efi_device_path *dp)
  * in practice fallback.efi just uses MEDIA:HARD_DRIVE
  * so not sure when we would see these other cases.
  */
-   if (EFI_DP_TYPE(dp, MESSAGING_DEVICE, MSG_USB_CLASS) ||
+   if (EFI_DP_TYPE(dp, MESSAGING_DEVICE, MSG_USB) ||
 EFI_DP_TYPE(dp, MEDIA_DEVICE, HARD_DRIVE_PATH) ||
 EFI_DP_TYPE(dp, MEDIA_DEVICE, FILE_PATH))
 return dp;
@@ -564,6 +564,11 @@ __maybe_unused static unsigned int dp_size(struct udevice 
*dev)
 return dp_size(dev->parent)
 + sizeof(struct efi_device_path_vendor) + 1;
  #endif
+#ifdef CONFIG_USB
+   case UCLASS_MASS_STORAGE:


Can we do:

case UCLASS_MASS_STORAGE:
   if (IS_ENABLED(CONFIG_USB)) {
...
   }

?


That should be possible too. Didn't you want to get rid of IS_ENABLED()? 
CONFIG_IS_ENABLED() would work here too.


The whole way that we create device paths is not consistent. We should 
have a device path node for each DM device.


With v2023.07 I want to add

struct efi_device_path *(*get_dp_node)(struct udevice *dev);

to struct uclass_driver and move the generation of device path nodes to 
the individual uclass drivers.


Best regards

Heinrich



and below too


+   return dp_size(dev->parent)
+   + sizeof(struct efi_device_path_controller);
+#endif
  #ifdef CONFIG_VIRTIO_BLK
 case UCLASS_VIRTIO:
  /*
@@ -585,7 +590,7 @@ __maybe_unused static unsigned int dp_size(struct udevice 
*dev)
 case UCLASS_MASS_STORAGE:
 case UCLASS_USB_HUB:
 return dp_size(dev->parent) +
-   sizeof(struct efi_device_path_usb_class);
+   sizeof(struct efi_device_path_usb);
 default:
 /* just skip over unknown classes: */
 return dp_size(dev->parent);
@@ -741,6 +746,19 @@ __maybe_unused static void *dp_fill(void *buf, struct 
udevice *dev)
 memcpy(>ns_id, _id, sizeof(ns_id));
 return [1];
 }
+#endif
+#if defined(CONFIG_USB)
+   case UCLASS_MASS_STORAGE: {
+   struct blk_desc *desc = desc = dev_get_uclass_plat(dev);
+   struct efi_device_path_controller *dp =
+   dp_fill(buf, dev->parent);
+
+   dp->dp.type = DEVICE_PATH_TYPE_HARDWARE_DEVICE;
+   dp->dp.sub_type = DEVICE_PATH_SUB_TYPE_CONTROLLER;
+   dp->dp.length   = sizeof(*dp);
+   dp->controller_number = desc->lun;
+   return [1];
+   }
  #endif


[..]

Regards,
SImon


Re: [PATCH v3] Let the EQoS in imx8mp handle fixed-phy too.

2023-03-19 Thread Elmar Psilog


Am 19.03.23 um 18:21 schrieb Marek Vasut:

On 3/19/23 11:43, Elmar Psilog wrote:

Without that patch it lost track to the node to scan
speed and duplex.
Patch was created by Marek Vasut, just tested by me.

Signed-off-by: Elmar Psilog 
Reviewed-by: Marek Vasut 
---
   changes v2: fix format issues
   changes v3: remove {} around single if, add reviewd..

  drivers/net/dwc_eth_qos.c | 18 +++---
  1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/drivers/net/dwc_eth_qos.c b/drivers/net/dwc_eth_qos.c
index 112deb546d..b9de205b8a 100644
--- a/drivers/net/dwc_eth_qos.c
+++ b/drivers/net/dwc_eth_qos.c
@@ -788,9 +788,21 @@ static int eqos_start(struct udevice *dev)
   */
  if (!eqos->phy) {
  int addr = -1;
-    addr = eqos_get_phy_addr(eqos, dev);
-    eqos->phy = phy_connect(eqos->mii, addr, dev,
-    eqos->config->interface(dev));
+    ofnode fixed_node;
+
+    if (IS_ENABLED(CONFIG_PHY_FIXED)) {
+    fixed_node = ofnode_find_subnode(dev_ofnode(dev),
+ "fixed-link");
+    if (ofnode_valid(fixed_node))
+    eqos->phy = fixed_phy_create(dev_ofnode(dev));
+    }
+
+    if (!eqos->phy) {
+    addr = eqos_get_phy_addr(eqos, dev);
+    eqos->phy = phy_connect(eqos->mii, addr, dev,
+    eqos->config->interface(dev));
+    }
+
  if (!eqos->phy) {
  pr_err("phy_connect() failed");
  goto err_stop_resets;
--
2.34.1



I would give a short reminder about the patch. Reviewed by Marek, ok for
Ramon. Would be glad to see it in 2023.04.


We're already in 2023.04-rc4 , this is material for v2023.07 , i.e. 
for u-boot/next branch .


Ok, but does it change anything for the patch itself? As source isn't 
touched in last weeks it is still needed. Other way asked: Any action 
(from my side) needed? I just afraid your (@Marek) and my work gets 
lost. I would expect either an "accepted" or "rejected" (for a reason).




Re: [PATCH 1/3] net: mvpp2: Replace PHY_INTERFACE_MODE_SGMII_2500 with SGMII and speed

2023-03-19 Thread Marek Behún
On Sun, 19 Mar 2023 18:06:45 +0100
Marek Vasut  wrote:

> Replace PHY_INTERFACE_MODE_SGMII_2500 with PHY_INTERFACE_MODE_SGMII and
> phydev->speed check where applicable. The PHY_INTERFACE_MODE_SGMII_2500
> does not exist in Linux, so remove it from U-Boot too.
> 
> Signed-off-by: Marek Vasut 

SGMII cannot operate on 2500mbps. As I explained to the author who added
PHY_INTERFACE_MODE_SGMII_2500 to U-Boot (and the conversation didn't lead
anywhere then), what I think happened here is that for some reason
Marvell sometimes calls 2500base-x mode SGMII_2500. Meaning that they
incorrectly interchange the names 2500base-x and sgmii_2500 as if they
were the same thing. This is probably due to how 1000base-x and SGMII
are similar and they do the same with those.

The thing is, 1000base-x and SGMII are different protocols / interface
modes. The difference is that they have different autonegotiation. SGMII
allows also for speed autonegotiation, whilst 1000base-x only for flow
control. The bits in the clause 37 link ability advertisement word have
different meaning for 1000base-x than for sgmii.

When SGMII negotiates lower speed, the actual serdes frequency does not
change. The lower speed of 100mbps or 10mbps is achieved by repeating
the word 10 or 100 times.

The 2500base-x mode works the same way as 1000base-x mode, but at 2.5x
the frequency. Calling it sgmii-2500 is wrong because it would mean that
it also allows for lower speeds by repeating the words. In reality it
is possible, on many controllers you can set SGMII mode at 2.5x normal
frequency and then instead of 1000/100/10mbps speeds achieve
2500/250/25mbps. But this is not standardized anyway.

Marek, your patch does a good thing getting rid of the sgmii-2500
constant, but you are still leaving the possibility of 2500mbps speed
in SGMII mode...

Marek


[PATCH v3 09/12] doc: Add help for the efi command

2023-03-19 Thread Simon Glass
This command currently has no help. Add some.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 doc/usage/cmd/efi.rst | 197 ++
 doc/usage/index.rst   |   1 +
 2 files changed, 198 insertions(+)
 create mode 100644 doc/usage/cmd/efi.rst

diff --git a/doc/usage/cmd/efi.rst b/doc/usage/cmd/efi.rst
new file mode 100644
index ..c029c423879f
--- /dev/null
+++ b/doc/usage/cmd/efi.rst
@@ -0,0 +1,197 @@
+.. SPDX-License-Identifier: GPL-2.0+
+.. Copyright 2020, Heinrich Schuchardt 
+
+efi command
+===
+
+Synopsis
+
+
+::
+
+efi mem [all]
+
+Description
+---
+
+The *efi* command provides information about the EFI environment U-Boot is
+running in, when it is started from EFI.
+
+When running as an EFI app, this command queries EFI boot services for the
+information. When running as an EFI payload, EFI boot services have been
+stopped, so it uses the information collected by the boot stub before that
+happened.
+
+efi mem
+~~~
+
+This shows the EFI memory map, sorted in order of physical address.
+
+This is normally a very large table. To help reduce the amount of detritus,
+boot-time memory is normally merged with conventional memory. Use the 'all'
+argument to show everything.
+
+The fields are as follows:
+
+#
+Entry number (sequentially from 0)
+
+Type
+Memory type. EFI has a large number of memory types. The type is shown in
+the format : where in is the format number in hex and  is 
the
+name.
+
+Physical
+Physical address
+
+Virtual
+Virtual address
+
+Size
+Size of memory area in bytes
+
+Attributes
+Shows a code for memory attributes. The key for this is shown below the
+table.
+
+Example
+---
+
+::
+
+=> efi mem
+EFI table at 0, memory map 1ad38b60, size 1260, key a79, version 
1, descr. size 0x30
+ #  Type  Physical VirtualSize  Attributes
+ 0  7:conv  00  00  0a  f
+   0a  06
+ 1  7:conv  10  00  70  f
+ 2  a:acpi_nvs  80  00  008000  f
+ 3  7:conv  808000  00  008000  f
+ 4  a:acpi_nvs  81  00  0f  f
+ 5  7:conv  90  00  001efef000  f
+ 6  6:rt_data   001f8ef000  00  10  rf
+ 7  5:rt_code   001f9ef000  00  10  rf
+ 8  0:reserved  001faef000  00  08  f
+ 9  9:acpi_reclaim  001fb6f000  00  01  f
+10  a:acpi_nvs  001fb7f000  00  08  f
+11  7:conv  001fbff000  00  359000  f
+12  6:rt_data   001ff58000  00  02  rf
+13  a:acpi_nvs  001ff78000  00  088000  f
+   002000  009000
+14  0:reserved  00b000  00  001000  1
+
+Attributes key:
+ f: uncached, write-coalescing, write-through, write-back
+rf: uncached, write-coalescing, write-through, write-back, needs runtime 
mapping
+ 1: uncached
+*Some areas are merged (use 'all' to see)
+
+
+=> efi mem  all
+EFI table at 0, memory map 1ad38bb0, size 1260, key a79, version 
1, descr. size 0x30
+ #  Type  Physical VirtualSize  Attributes
+ 0  3:bs_code   00  00  001000  f
+ 1  7:conv  001000  00  09f000  f
+   0a  06
+ 2  7:conv  10  00  70  f
+ 3  a:acpi_nvs  80  00  008000  f
+ 4  7:conv  808000  00  008000  f
+ 5  a:acpi_nvs  81  00  0f  f
+ 6  4:bs_data   90  00  c0  f
+ 7  7:conv  000150  00  000aa36000  f
+ 8  2:loader_data   000bf36000  00  001000  f
+ 9  4:bs_data   001bf36000  00  02  f
+10  7:conv  001bf56000  00  00021e1000  f
+11  1:loader_code   001e137000  00  0c4000  f
+12  7:conv  001e1fb000  00  09b000  f
+13  1:loader_code   001e296000  00  0e2000  f
+14  7:conv  001e378000  00  05b000  f
+15  4:bs_data   001e3d3000  00  01e000  f
+16  7:conv  001e3f1000  00  016000  f
+17  4:bs_data   001e407000  00  016000  f
+18  2:loader_data   001e41d000  00  002000  f
+19  4:bs_data   001e41f000  00  828000  f
+20  3:bs_code   001ec47000  00  045000  f
+21  4:bs_data   001ec8c000  00  001000  f
+22  3:bs_code   001ec8d000  00  00e000  f
+23  4:bs_data   001ec9b000  00  

Re: [PATCH u-boot] cmd: mmc: Return CMD_RET_* from commands

2023-03-19 Thread Pali Rohár
On Monday 20 March 2023 08:29:04 Simon Glass wrote:
> Hi Pali,
> 
> On Mon, 20 Mar 2023 at 05:34, Pali Rohár  wrote:
> >
> > Numeric return values may cause strange errors line:
> > exit not allowed from main input shell.
> >
> > Signed-off-by: Pali Rohár 
> > ---
> >  cmd/mmc.c | 18 +-
> >  1 file changed, 13 insertions(+), 5 deletions(-)
> >
> > diff --git a/cmd/mmc.c b/cmd/mmc.c
> > index c79d9407986d..0b8fc903e1f6 100644
> > --- a/cmd/mmc.c
> > +++ b/cmd/mmc.c
> > @@ -175,7 +175,7 @@ static int do_mmcinfo(struct cmd_tbl *cmdtp, int flag, 
> > int argc,
> > curr_device = 0;
> > else {
> > puts("No MMC device available\n");
> > -   return 1;
> > +   return CMD_RET_FAILURE;
> > }
> > }
> >
> > @@ -927,7 +927,7 @@ static int mmc_partconf_print(struct mmc *mmc, const 
> > char *varname)
> >  static int do_mmc_partconf(struct cmd_tbl *cmdtp, int flag,
> >int argc, char *const argv[])
> >  {
> > -   int dev;
> > +   int r, dev;
> > struct mmc *mmc;
> > u8 ack, part_num, access;
> >
> > @@ -953,13 +953,17 @@ static int do_mmc_partconf(struct cmd_tbl *cmdtp, int 
> > flag,
> > access = dectoul(argv[4], NULL);
> >
> > /* acknowledge to be sent during boot operation */
> > -   return mmc_set_part_conf(mmc, ack, part_num, access);
> > +   r = mmc_set_part_conf(mmc, ack, part_num, access);
> > +   if (r != 0)
> > +   return CMD_RET_FAILURE;
> > +
> > +   return CMD_RET_SUCCESS;
> >  }
> >
> >  static int do_mmc_rst_func(struct cmd_tbl *cmdtp, int flag,
> >int argc, char *const argv[])
> >  {
> > -   int dev;
> > +   int r, dev;
> 
> Please use 'ret' as that is what we normally do with driver model.

Ok.

> > struct mmc *mmc;
> > u8 enable;
> >
> > @@ -988,7 +992,11 @@ static int do_mmc_rst_func(struct cmd_tbl *cmdtp, int 
> > flag,
> > return CMD_RET_FAILURE;
> > }
> >
> > -   return mmc_set_rst_n_function(mmc, enable);
> > +   r = mmc_set_rst_n_function(mmc, enable);
> > +   if (r != 0)
> 
> if (ret)
> 
> > +   return CMD_RET_FAILURE;
> > +
> > +   return CMD_RET_SUCCESS;
> 
> 'return 0' is fine here as less verbose. Success is 0 in U-Boot.

On all other mmc.c places is used verbose CMD_RET_SUCCESS macro. So it
is better to have one common style.

> 
> >  }
> >  #endif
> >  static int do_mmc_setdsr(struct cmd_tbl *cmdtp, int flag,
> > --
> > 2.20.1
> >
> 
> Regards,
> Simon


Re: [PATCH] netconsole: various improvements

2023-03-19 Thread Pali Rohár
On Saturday 18 March 2023 14:46:25 Tony Dinh wrote:
> - When Netconsole is running, stdin/stdout/stderr are set to nc. Reset
> stdin/stdout/stderr to serial (a sane deffault) before booting kernel.

This can be a problematic. serial output does not have to be available
for all devices. For example on Nokia N900 phone is available only
lcd/vga display device.

Also this can break CONSOLE_MUX support when more devices are specified
in stdin/stdout/stderr env variables. With CONSOLE_MUX, output is send
to more than one device. User may set it to both serial and nc or also
to other output (e.g. to lcd like on Nokia N900).

So in my opinion, if "nc" is is going to be turned off then just "nc"
string should be removed from env variable and let all other devices
stay in env variables.

Maybe you can use something like this? (taken from common/usb_kbd.c)

#if CONFIG_IS_ENABLED(CONSOLE_MUX)
if (iomux_replace_device(stdin, "nc", "nulldev"))
return 1;
#endif

> - Enable net_timeout when netconsole starts will give a better user
> experience if netconsole server is not running.
> 
> Signed-off-by: Tony Dinh 
> ---
> 
>  boot/bootm.c | 16 +++-
>  drivers/net/netconsole.c |  2 +-
>  2 files changed, 16 insertions(+), 2 deletions(-)
> 
> diff --git a/boot/bootm.c b/boot/bootm.c
> index 2eec60ec7b..c4a3aaf1bd 100644
> --- a/boot/bootm.c
> +++ b/boot/bootm.c
> @@ -473,7 +473,21 @@ ulong bootm_disable_interrupts(void)
>*/
>   iflag = disable_interrupts();
>  #ifdef CONFIG_NETCONSOLE
> - /* Stop the ethernet stack if NetConsole could have left it up */
> + /*
> +  * Make sure that the starting kernel message printed out.
> +  * Reset stdin/out/err back to serial and stop the ethernet
> +  * stack if NetConsole could have left it up
> +  */
> + char *s;
> + int ret;
> +
> + s = env_get("stdout");
> + if (strcmp(s, "nc") == 0) {
> + printf("\n\nStarting kernel ...\n");
> + ret = env_set("stdin", "serial");
> + ret = env_set("stdout", "serial");
> + ret = env_set("stderr", "serial");
> + }
>   eth_halt();
>  #endif
>  
> diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c
> index 151bc55e07..2091014918 100644
> --- a/drivers/net/netconsole.c
> +++ b/drivers/net/netconsole.c
> @@ -20,7 +20,7 @@ static int input_size; /* char count in input buffer */
>  static int input_offset; /* offset to valid chars in input buffer */
>  static int input_recursion;
>  static int output_recursion;
> -static int net_timeout;
> +static int net_timeout = 1;
>  static uchar nc_ether[6]; /* server enet address */
>  static struct in_addr nc_ip; /* server ip */
>  static short nc_out_port; /* target output port */
> -- 
> 2.30.2
> 


[PATCH v3 12/12] efI: Allow packaging a kernel in the debugging script

2023-03-19 Thread Simon Glass
Add an option to package a kernel into the debugging script used for
EFI.

The name of the kernel must be added to the script. By default it is
assumed that the kernel is built in the /tmp/kernel directory.

Signed-off-by: Simon Glass 
---

(no changes since v2)

Changes in v2:
- Fix typos in commit message

 scripts/build-efi.sh | 14 +-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/scripts/build-efi.sh b/scripts/build-efi.sh
index 46c28807ef1f..6b7df2e9bfe8 100755
--- a/scripts/build-efi.sh
+++ b/scripts/build-efi.sh
@@ -18,12 +18,15 @@
 # OVMF-pure-efi.x64.fd at
 # 
https://drive.google.com/file/d/1c39YI9QtpByGQ4V0UNNQtGqttEzS-eFV/view?usp=sharing
 
+bzimage_fname=/tmp/kernel/arch/x86/boot/bzImage
+
 set -e
 
 usage() {
echo "Usage: $0 [-a | -p] [other opts]" 1>&2
echo 1>&2
echo "   -a   - Package up the app" 1>&2
+   echo "   -k   - Add a kernel" 1>&2
echo "   -o   - Use old EFI app build (before 32/64 split)" 1>&2
echo "   -p   - Package up the payload" 1>&2
echo "   -P   - Create a partition table" 1>&2
@@ -52,11 +55,14 @@ serial=
 # before the 32/64 split of the app
 old=
 
+# package up a kernel as well
+kernel=
+
 # Set ubdir to the build directory where you build U-Boot out-of-tree
 # We avoid in-tree build because it gets confusing trying different builds
 ubdir=/tmp/b/
 
-while getopts "aopPrsw" opt; do
+while getopts "akopPrsw" opt; do
case "${opt}" in
a)
type=app
@@ -64,6 +70,9 @@ while getopts "aopPrsw" opt; do
p)
type=payload
;;
+   k)
+   kernel=1
+   ;;
r)
run=1
;;
@@ -124,6 +133,9 @@ EOF
 # Copy files into the filesystem
 copy_files() {
sudo cp $TMP/* $MNT
+   if [[ -n "${kernel}" ]]; then
+   sudo cp ${bzimage_fname} $MNT/vmlinuz
+   fi
 }
 
 # Create a filesystem on a raw device and copy in the files
-- 
2.40.0.rc1.284.g88254d51c5-goog



[PATCH v3 11/12] efi: Support showing tables

2023-03-19 Thread Simon Glass
Add a command (for the app and payload) to display the tables provided
by EFI. Note that for the payload the tables should always be present, so
an error message is unnecessary and would bloat the code.

Signed-off-by: Simon Glass 
---

Changes in v3:
- Drop unnecessary error message for some that shoudn't happen.

Changes in v2:
- Make use of common code

 cmd/Makefile  |  2 +-
 cmd/efi.c | 31 ++-
 doc/usage/cmd/efi.rst | 22 ++
 3 files changed, 53 insertions(+), 2 deletions(-)

diff --git a/cmd/Makefile b/cmd/Makefile
index 1c5c6f3c00cb..a0bfa2acefe6 100644
--- a/cmd/Makefile
+++ b/cmd/Makefile
@@ -62,7 +62,7 @@ obj-$(CONFIG_CMD_EXTENSION) += extension_board.o
 obj-$(CONFIG_CMD_ECHO) += echo.o
 obj-$(CONFIG_ENV_IS_IN_EEPROM) += eeprom.o
 obj-$(CONFIG_CMD_EEPROM) += eeprom.o
-obj-$(CONFIG_EFI) += efi.o
+obj-$(CONFIG_EFI) += efi.o efi_common.o
 obj-$(CONFIG_CMD_EFIDEBUG) += efidebug.o efi_common.o
 obj-$(CONFIG_CMD_EFICONFIG) += eficonfig.o
 ifdef CONFIG_CMD_EFICONFIG
diff --git a/cmd/efi.c b/cmd/efi.c
index c0384e0db287..6cd5361aca59 100644
--- a/cmd/efi.c
+++ b/cmd/efi.c
@@ -7,10 +7,12 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
 #include 
+#include 
 #include 
 
 DECLARE_GLOBAL_DATA_PTR;
@@ -273,8 +275,34 @@ done:
return ret ? CMD_RET_FAILURE : 0;
 }
 
+static int do_efi_tables(struct cmd_tbl *cmdtp, int flag, int argc,
+char *const argv[])
+{
+   struct efi_system_table *systab;
+
+   if (IS_ENABLED(CONFIG_EFI_APP)) {
+   systab = efi_get_sys_table();
+   if (!systab) {
+   printf("Cannot read system table\n");
+   return CMD_RET_FAILURE;
+   }
+   } else {
+   int size;
+   int ret;
+
+   ret = efi_info_get(EFIET_SYS_TABLE, (void **), );
+   if (ret)  /* this should not happen */
+   return CMD_RET_FAILURE;
+   }
+
+   efi_show_tables(systab);
+
+   return 0;
+}
+
 static struct cmd_tbl efi_commands[] = {
U_BOOT_CMD_MKENT(mem, 1, 1, do_efi_mem, "", ""),
+   U_BOOT_CMD_MKENT(tables, 1, 1, do_efi_tables, "", ""),
 };
 
 static int do_efi(struct cmd_tbl *cmdtp, int flag, int argc, char *const 
argv[])
@@ -298,5 +326,6 @@ static int do_efi(struct cmd_tbl *cmdtp, int flag, int 
argc, char *const argv[])
 U_BOOT_CMD(
efi, 3,  1,  do_efi,
"EFI access",
-   "mem [all]Dump memory information [include boot services]"
+   "mem [all]Dump memory information [include boot services]\n"
+   "tables   Dump tables"
 );
diff --git a/doc/usage/cmd/efi.rst b/doc/usage/cmd/efi.rst
index c029c423879f..ef37ff2f4c1d 100644
--- a/doc/usage/cmd/efi.rst
+++ b/doc/usage/cmd/efi.rst
@@ -10,6 +10,7 @@ Synopsis
 ::
 
 efi mem [all]
+efi tables
 
 Description
 ---
@@ -54,6 +55,14 @@ Attributes
 Shows a code for memory attributes. The key for this is shown below the
 table.
 
+efi tables
+~~
+
+This shows a list of the EFI tables provided in the system table. These use
+GUIDs so it is not possible in general to show the name of a table. But some
+effort is made to provide a useful table, where the GUID is known by U-Boot.
+
+
 Example
 ---
 
@@ -195,3 +204,16 @@ Example
  f: uncached, write-coalescing, write-through, write-back
 rf: uncached, write-coalescing, write-through, write-back, needs runtime 
mapping
  1: uncached
+
+
+=> efi tables
+1f8edf98  ee4e5898-3914-4259-9d6e-dc7bd79403cf  EFI_LZMA_COMPRESSED
+1ff2ace0  05ad34ba-6f02-4214-952e-4da0398e2bb9  EFI_DXE_SERVICES
+1f8ea018  7739f24c-93d7-11d4-9a3a-0090273fc14d  EFI_HOB_LIST
+1ff2bac0  4c19049f-4137-4dd3-9c10-8b97a83ffdfa  EFI_MEMORY_TYPE
+1ff2cb10  49152e77-1ada-4764-b7a2-7afefed95e8b  (unknown)
+1f9ac018  060cc026-4c0d-4dda-8f41-595fef00a502  
EFI_MEM_STATUS_CODE_REC
+1f9ab000  eb9d2d31-2d88-11d3-9a16-0090273fc14d  SMBIOS table
+1fb7e000  eb9d2d30-2d88-11d3-9a16-0090273fc14d  EFI_GUID_EFI_ACPI1
+1fb7e014  8868e871-e4f1-11d3-bc22-0080c73c8881  ACPI table
+1e654018  dcfa911d-26eb-469f-a220-38b7dc461220  (unknown)
-- 
2.40.0.rc1.284.g88254d51c5-goog



[PATCH v3 10/12] efi: Split out table-listing code into a new file

2023-03-19 Thread Simon Glass
This code is used with EFI_LOADER but is also useful (with some
modifications) for the EFI app and payload. Move it into a shared
file.

Show the address of the table so it can be examined if needed. Also show
the table name as unknown if necessary. Our list of GUIDs is fairly
small.

Signed-off-by: Simon Glass 
---

Changes in v3:
- Use %pUl to print the UUID

Changes in v2:
- Add new patch to split out table-listing code into a new file

 cmd/Makefile |  2 +-
 cmd/efi_common.c | 26 ++
 cmd/efidebug.c   |  6 +-
 include/efi.h|  9 +
 4 files changed, 37 insertions(+), 6 deletions(-)
 create mode 100644 cmd/efi_common.c

diff --git a/cmd/Makefile b/cmd/Makefile
index 2d8bb4fc0529..1c5c6f3c00cb 100644
--- a/cmd/Makefile
+++ b/cmd/Makefile
@@ -63,7 +63,7 @@ obj-$(CONFIG_CMD_ECHO) += echo.o
 obj-$(CONFIG_ENV_IS_IN_EEPROM) += eeprom.o
 obj-$(CONFIG_CMD_EEPROM) += eeprom.o
 obj-$(CONFIG_EFI) += efi.o
-obj-$(CONFIG_CMD_EFIDEBUG) += efidebug.o
+obj-$(CONFIG_CMD_EFIDEBUG) += efidebug.o efi_common.o
 obj-$(CONFIG_CMD_EFICONFIG) += eficonfig.o
 ifdef CONFIG_CMD_EFICONFIG
 ifdef CONFIG_EFI_MM_COMM_TEE
diff --git a/cmd/efi_common.c b/cmd/efi_common.c
new file mode 100644
index ..f4056096cd3f
--- /dev/null
+++ b/cmd/efi_common.c
@@ -0,0 +1,26 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Common code for EFI commands
+ *
+ * Copyright 2023 Google LLC
+ * Written by Simon Glass 
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+void efi_show_tables(struct efi_system_table *systab)
+{
+   int i;
+
+   for (i = 0; i < systab->nr_tables; i++) {
+   struct efi_configuration_table *tab = >tables[i];
+   char guid_str[37];
+
+   uuid_bin_to_str(tab->guid.b, guid_str, 1);
+   printf("%p  %pUl  %s\n", tab->table, guid_str,
+  uuid_guid_get_str(tab->guid.b) ?: "(unknown)");
+   }
+}
diff --git a/cmd/efidebug.c b/cmd/efidebug.c
index e6959ede930f..9622430c475e 100644
--- a/cmd/efidebug.c
+++ b/cmd/efidebug.c
@@ -649,11 +649,7 @@ static int do_efi_show_memmap(struct cmd_tbl *cmdtp, int 
flag,
 static int do_efi_show_tables(struct cmd_tbl *cmdtp, int flag,
  int argc, char *const argv[])
 {
-   efi_uintn_t i;
-
-   for (i = 0; i < systab.nr_tables; ++i)
-   printf("%pUl (%pUs)\n",
-  [i].guid, [i].guid);
+   efi_show_tables();
 
return CMD_RET_SUCCESS;
 }
diff --git a/include/efi.h b/include/efi.h
index c3087d3da28e..342dd52fed9f 100644
--- a/include/efi.h
+++ b/include/efi.h
@@ -637,4 +637,13 @@ int efi_call_exit_boot_services(void);
 int efi_get_mmap(struct efi_mem_desc **descp, int *sizep, uint *keyp,
 int *desc_sizep, uint *versionp);
 
+/**
+ * efi_show_tables() - Show a list of available tables
+ *
+ * Shows the address, GUID (and name where known) for each table
+ *
+ * @systab: System table containing the list of tables
+ */
+void efi_show_tables(struct efi_system_table *systab);
+
 #endif /* _LINUX_EFI_H */
-- 
2.40.0.rc1.284.g88254d51c5-goog



[PATCH v3 07/12] efi: Add another tranch of GUIDs

2023-03-19 Thread Simon Glass
Provide information about the GUIDs supplied by QEMU, so far as it is
known.

These values are used in the 'efi table' command as well as the printf
format string %sU

Signed-off-by: Simon Glass 
---

Changes in v3:
- Make this depend on CONFIG_EFI so that EFI_LOADER doesn't get it
- Really drop SMBIOS

Changes in v2:
- Update commit message to explain why these are needed
- Drop EFI_SMBIOS which exists as SMBIOS_TABLE_GUID
- Drop unwanted EFI_GUID_SNBIOS
- Drop EFI_GUID_EFI_ACPI2 which exists as EFI_ACPI_TABLE_GUID

 include/efi_api.h | 19 +++
 lib/uuid.c|  8 
 2 files changed, 27 insertions(+)

diff --git a/include/efi_api.h b/include/efi_api.h
index 2d18d25a7137..89762553d66e 100644
--- a/include/efi_api.h
+++ b/include/efi_api.h
@@ -1909,6 +1909,25 @@ struct efi_system_resource_table {
EFI_GUID(0x4aafd29d, 0x68df, 0x49ee, 0x8a, 0xa9, \
 0x34, 0x7d, 0x37, 0x56, 0x65, 0xa7)
 
+#define EFI_LZMA_COMPRESSED \
+   EFI_GUID(0xee4e5898, 0x3914, 0x4259, 0x9d, 0x6e, \
+0xdc, 0x7b, 0xd7, 0x94, 0x03, 0xcf)
+#define EFI_DXE_SERVICES \
+   EFI_GUID(0x05ad34ba, 0x6f02, 0x4214, 0x95, 0x2e, \
+0x4d, 0xa0, 0x39, 0x8e, 0x2b, 0xb9)
+#define EFI_HOB_LIST \
+   EFI_GUID(0x7739f24c, 0x93d7, 0x11d4, 0x9a, 0x3a,  \
+0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
+#define EFI_MEMORY_TYPE \
+   EFI_GUID(0x4c19049f, 0x4137, 0x4dd3, 0x9c, 0x10, \
+0x8b, 0x97, 0xa8, 0x3f, 0xfd, 0xfa)
+#define EFI_MEM_STATUS_CODE_REC \
+   EFI_GUID(0x060cc026, 0x4c0d, 0x4dda, 0x8f, 0x41, \
+0x59, 0x5f, 0xef, 0x00, 0xa5, 0x02)
+#define EFI_GUID_EFI_ACPI1 \
+   EFI_GUID(0xeb9d2d30, 0x2d88, 0x11d3,  0x9a, 0x16, \
+0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
+
 /**
  * struct win_certificate_uefi_guid - A certificate that encapsulates
  * a GUID-specific signature
diff --git a/lib/uuid.c b/lib/uuid.c
index 465e1ac38f57..5ea30a66f5d0 100644
--- a/lib/uuid.c
+++ b/lib/uuid.c
@@ -255,6 +255,14 @@ static const struct {
EFI_CERT_TYPE_PKCS7_GUID,
},
 #endif
+#ifdef CONFIG_EFI
+   { "EFI_LZMA_COMPRESSED", EFI_LZMA_COMPRESSED },
+   { "EFI_DXE_SERVICES", EFI_DXE_SERVICES },
+   { "EFI_HOB_LIST", EFI_HOB_LIST },
+   { "EFI_MEMORY_TYPE", EFI_MEMORY_TYPE },
+   { "EFI_MEM_STATUS_CODE_REC", EFI_MEM_STATUS_CODE_REC },
+   { "EFI_GUID_EFI_ACPI1", EFI_GUID_EFI_ACPI1 },
+#endif
 };
 
 /*
-- 
2.40.0.rc1.284.g88254d51c5-goog



[PATCH v3 08/12] efi: Include GUID names with EFI app and payload

2023-03-19 Thread Simon Glass
These are currently only available when running with EFI_LOADER.
Expand this to include the app and payload, since it is useful to be
able to decode things there.

Signed-off-by: Simon Glass 
---

(no changes since v2)

Changes in v2:
- Add new patch to enable GUID names with EFI app and payload

 lib/uuid.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/uuid.c b/lib/uuid.c
index 5ea30a66f5d0..96e1af3c8b00 100644
--- a/lib/uuid.c
+++ b/lib/uuid.c
@@ -102,7 +102,7 @@ static const struct {
{"lvm", PARTITION_LINUX_LVM_GUID},
{"u-boot-env",  PARTITION_U_BOOT_ENVIRONMENT},
 #endif
-#ifdef CONFIG_CMD_EFIDEBUG
+#if defined(CONFIG_CMD_EFIDEBUG) || defined(CONFIG_EFI)
{
"Device Path",
EFI_DEVICE_PATH_PROTOCOL_GUID,
-- 
2.40.0.rc1.284.g88254d51c5-goog



[PATCH v3 06/12] x86: Support zboot and bootm in the EFI app

2023-03-19 Thread Simon Glass
These have been disabled due to the rudimentary support available. It is
a little better now, so enable these options.

Signed-off-by: Simon Glass 
Reviewed-by: Heinrich Schuchardt 
---

(no changes since v1)

 configs/efi-x86_app32_defconfig | 2 +-
 configs/efi-x86_app64_defconfig | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/configs/efi-x86_app32_defconfig b/configs/efi-x86_app32_defconfig
index 905f375a3efe..50975dbfaafc 100644
--- a/configs/efi-x86_app32_defconfig
+++ b/configs/efi-x86_app32_defconfig
@@ -19,7 +19,7 @@ CONFIG_DISPLAY_BOARDINFO_LATE=y
 CONFIG_LAST_STAGE_INIT=y
 CONFIG_HUSH_PARSER=y
 CONFIG_SYS_PBSIZE=532
-# CONFIG_CMD_BOOTM is not set
+CONFIG_CMD_BOOTZ=y
 CONFIG_CMD_PART=y
 # CONFIG_CMD_NET is not set
 CONFIG_CMD_TIME=y
diff --git a/configs/efi-x86_app64_defconfig b/configs/efi-x86_app64_defconfig
index f1cf43c1ef66..0fc358ddcdfb 100644
--- a/configs/efi-x86_app64_defconfig
+++ b/configs/efi-x86_app64_defconfig
@@ -20,7 +20,7 @@ CONFIG_DISPLAY_BOARDINFO_LATE=y
 CONFIG_LAST_STAGE_INIT=y
 CONFIG_HUSH_PARSER=y
 CONFIG_SYS_PBSIZE=532
-# CONFIG_CMD_BOOTM is not set
+CONFIG_CMD_BOOTZ=y
 CONFIG_CMD_PART=y
 # CONFIG_CMD_NET is not set
 CONFIG_CMD_CACHE=y
-- 
2.40.0.rc1.284.g88254d51c5-goog



[PATCH v3 05/12] x86: Exit EFI boot services before starting kernel

2023-03-19 Thread Simon Glass
When running the EFI app, we need to exit boot services before jumping
to Linux.

At some point it may be possible to jump to Linux and pass on the system
table, and:

  * install the device-tree as configuration table
  * use LoadImage() to load the kernel image (e.g. from memory)
  * start the image with StartImage()

This should allow the Linux efistub to be used. For now, this is not
implemented.

Signed-off-by: Simon Glass 
---

Changes in v3:
- Update commit message based on Heinrich's comments

 arch/x86/lib/bootm.c | 18 ++
 1 file changed, 18 insertions(+)

diff --git a/arch/x86/lib/bootm.c b/arch/x86/lib/bootm.c
index 9beb376bb9c2..61cb7bc61168 100644
--- a/arch/x86/lib/bootm.c
+++ b/arch/x86/lib/bootm.c
@@ -10,6 +10,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -156,6 +157,23 @@ int boot_linux_kernel(ulong setup_base, ulong entry, bool 
image_64bit)
 #ifdef CONFIG_SYS_COREBOOT
timestamp_add_now(TS_U_BOOT_START_KERNEL);
 #endif
+
+   /*
+* Exit EFI boot services just before jumping, after all console
+* output, since the console won't be available afterwards.
+*/
+   if (IS_ENABLED(CONFIG_EFI_APP)) {
+   int ret;
+
+   ret = efi_store_memory_map(efi_get_priv());
+   if (ret)
+   return ret;
+   printf("Exiting EFI boot services\n");
+   ret = efi_call_exit_boot_services();
+   if (ret)
+   return ret;
+   }
+
if (image_64bit) {
if (!cpu_has_64bit()) {
puts("Cannot boot 64-bit kernel on 32-bit machine\n");
-- 
2.40.0.rc1.284.g88254d51c5-goog



[PATCH v3 02/12] x86: Adjust bootparam.h to be more like linux

2023-03-19 Thread Simon Glass
This likely came from Linux originally, so update it to match v6.2 more.
This has no functional change.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 arch/x86/include/asm/bootparam.h | 70 +---
 arch/x86/lib/zimage.c|  2 +-
 2 files changed, 47 insertions(+), 25 deletions(-)

diff --git a/arch/x86/include/asm/bootparam.h b/arch/x86/include/asm/bootparam.h
index 7a3c1f515544..ea816ca74698 100644
--- a/arch/x86/include/asm/bootparam.h
+++ b/arch/x86/include/asm/bootparam.h
@@ -9,19 +9,54 @@
 #include 
 #include 
 
-/* setup data types */
-enum {
-   SETUP_NONE = 0,
-   SETUP_E820_EXT,
-   SETUP_DTB,
-};
+/* setup_data/setup_indirect types */
+#define SETUP_NONE 0
+#define SETUP_E820_EXT 1
+#define SETUP_DTB  2
+#define SETUP_PCI  3
+#define SETUP_EFI  4
+#define SETUP_APPLE_PROPERTIES 5
+#define SETUP_JAILHOUSE6
+#define SETUP_CC_BLOB  7
+#define SETUP_IMA  8
+#define SETUP_RNG_SEED 9
+#define SETUP_ENUM_MAX SETUP_RNG_SEED
+
+#define SETUP_INDIRECT BIT(31)
+#define SETUP_TYPE_MAX (SETUP_ENUM_MAX | SETUP_INDIRECT)
+
+/* ram_size flags */
+#define RAMDISK_IMAGE_START_MASK   0x07FF
+#define RAMDISK_PROMPT_FLAG0x8000
+#define RAMDISK_LOAD_FLAG  0x4000
+
+/* loadflags */
+#define LOADED_HIGHBIT(0)
+#define KASLR_FLAG BIT(1)
+#define QUIET_FLAG BIT(5)
+#define KEEP_SEGMENTS  BIT(6)
+#define CAN_USE_HEAP   BIT(7)
+
+#define XLF_KERNEL_64  BIT(0)
+#define XLF_CAN_BE_LOADED_ABOVE_4G BIT(1)
+#define XLF_EFI_HANDOVER_32BIT(2)
+#define XLF_EFI_HANDOVER_64BIT(3)
+#define XLF_EFI_KEXEC  BIT(4)
 
 /* extensible setup data list node */
 struct setup_data {
__u64 next;
__u32 type;
__u32 len;
-   __u8 data[0];
+   __u8 data[];
+};
+
+/* extensible setup indirect data node */
+struct setup_indirect {
+   __u32 type;
+   __u32 reserved;  /* Reserved, must be set to zero. */
+   __u64 len;
+   __u64 addr;
 };
 
 /**
@@ -34,9 +69,6 @@ struct setup_header {
__u16   root_flags;
__u32   syssize;
__u16   ram_size;
-#define RAMDISK_IMAGE_START_MASK   0x07FF
-#define RAMDISK_PROMPT_FLAG0x8000
-#define RAMDISK_LOAD_FLAG  0x4000
__u16   vid_mode;
__u16   root_dev;
__u16   boot_flag;
@@ -44,15 +76,10 @@ struct setup_header {
__u32   header;
__u16   version;
__u32   realmode_swtch;
-   __u16   start_sys;
+   __u16   start_sys_seg;
__u16   kernel_version;
__u8type_of_loader;
__u8loadflags;
-#define LOADED_HIGHBIT(0)
-#define KASLR_FLAG BIT(1)
-#define QUIET_FLAG BIT(5)
-#define KEEP_SEGMENTS  BIT(6)  /* Obsolete */
-#define CAN_USE_HEAP   BIT(7)
__u16   setup_move_size;
__u32   code32_start;
__u32   ramdisk_image;
@@ -65,13 +92,8 @@ struct setup_header {
__u32   initrd_addr_max;
__u32   kernel_alignment;
__u8relocatable_kernel;
-   u8  min_alignment;
-#define XLF_KERNEL_64  BIT(0)
-#define XLF_CAN_BE_LOADED_ABOVE_4G BIT(1)
-#define XLF_EFI_HANDOVER_32BIT(2)
-#define XLF_EFI_HANDOVER_64BIT(3)
-#define XLF_EFI_KEXEC  BIT(4)
-   u16 xloadflags;
+   __u8min_alignment;
+   __u16   xloadflags;
__u32   cmdline_size;
__u32   hardware_subarch;
__u64   hardware_subarch_data;
@@ -81,7 +103,7 @@ struct setup_header {
__u64   pref_address;
__u32   init_size;
__u32   handover_offset;
-   u32 kernel_info_offset;
+   __u32   kernel_info_offset;
 } __attribute__((packed));
 
 struct sys_desc_table {
diff --git a/arch/x86/lib/zimage.c b/arch/x86/lib/zimage.c
index 9cc04490307c..a6d9151c3240 100644
--- a/arch/x86/lib/zimage.c
+++ b/arch/x86/lib/zimage.c
@@ -655,7 +655,7 @@ void zimage_dump(struct boot_params *base_ptr)
printf("%-20s  %s\n", "", "Ancient kernel, using version 100");
print_num("Version", hdr->version);
print_num("Real mode switch", hdr->realmode_swtch);
-   print_num("Start sys", hdr->start_sys);
+   print_num("Start sys seg", hdr->start_sys_seg);
print_num("Kernel version", hdr->kernel_version);
version = get_kernel_version(base_ptr, (void *)state.bzimage_addr);
if (version)
-- 
2.40.0.rc1.284.g88254d51c5-goog



[PATCH v3 04/12] x86: Support booting a 64-bit kernel from 64-bit U-Boot

2023-03-19 Thread Simon Glass
Add the missing code to handle this. For a 64-bit kernel the entry
address is 0x200 bytes after the normal entry.

Rename the parameter to boot_linux_kernel() accordingly. Update the
comments to indicate that these are addresses, not pointers.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 arch/x86/include/asm/bootm.h | 12 ++--
 arch/x86/lib/bootm.c | 25 +
 arch/x86/lib/zimage.c| 15 +--
 3 files changed, 36 insertions(+), 16 deletions(-)

diff --git a/arch/x86/include/asm/bootm.h b/arch/x86/include/asm/bootm.h
index 109f686f7403..3b641783b9cd 100644
--- a/arch/x86/include/asm/bootm.h
+++ b/arch/x86/include/asm/bootm.h
@@ -14,14 +14,14 @@ void bootm_announce_and_cleanup(void);
  * This boots a kernel image, either 32-bit or 64-bit. It will also work with
  * a self-extracting kernel, if you set @image_64bit to false.
  *
- * @setup_base:Pointer to the setup.bin information for the 
kernel
- * @load_address:  Pointer to the start of the kernel image
- * @image_64bit:   true if the image is a raw 64-bit kernel, false if it
- * is raw 32-bit or any type of self-extracting kernel
- * such as a bzImage.
+ * @setup_base:Address of the setup.bin information for the 
kernel
+ * @entry: Address of the kernel entry point
+ * @image_64bit:   true if the image is a raw 64-bit kernel, or a kernel
+ * which supports booting in 64-bit mode; false if it is raw 32-bit or any type
+ * of self-extracting kernel such as a bzImage.
  * Return: -ve error code. This function does not return if the kernel was
  * booted successfully.
  */
-int boot_linux_kernel(ulong setup_base, ulong load_address, bool image_64bit);
+int boot_linux_kernel(ulong setup_base, ulong entry, bool image_64bit);
 
 #endif
diff --git a/arch/x86/lib/bootm.c b/arch/x86/lib/bootm.c
index 873e2bc176f3..9beb376bb9c2 100644
--- a/arch/x86/lib/bootm.c
+++ b/arch/x86/lib/bootm.c
@@ -149,7 +149,7 @@ error:
return 1;
 }
 
-int boot_linux_kernel(ulong setup_base, ulong load_address, bool image_64bit)
+int boot_linux_kernel(ulong setup_base, ulong entry, bool image_64bit)
 {
bootm_announce_and_cleanup();
 
@@ -161,14 +161,23 @@ int boot_linux_kernel(ulong setup_base, ulong 
load_address, bool image_64bit)
puts("Cannot boot 64-bit kernel on 32-bit machine\n");
return -EFAULT;
}
-   /* At present 64-bit U-Boot does not support booting a
+   /*
+* At present 64-bit U-Boot only supports booting a 64-bit
 * kernel.
-* TODO(s...@chromium.org): Support booting both 32-bit and
-* 64-bit kernels from 64-bit U-Boot.
+*
+* TODO(s...@chromium.org): Support booting 32-bit kernels from
+* 64-bit U-Boot
 */
-#if !CONFIG_IS_ENABLED(X86_64)
-   return cpu_jump_to_64bit(setup_base, load_address);
-#endif
+   if (CONFIG_IS_ENABLED(X86_64)) {
+   typedef void (*h_func)(ulong zero, ulong setup);
+   h_func func;
+
+   /* jump to Linux with rdi=0, rsi=setup_base */
+   func = (h_func)entry;
+   func(0, setup_base);
+   } else {
+   return cpu_jump_to_64bit(setup_base, entry);
+   }
} else {
/*
* Set %ebx, %ebp, and %edi to 0, %esi to point to the
@@ -190,7 +199,7 @@ int boot_linux_kernel(ulong setup_base, ulong load_address, 
bool image_64bit)
"movl $0, %%ebp\n"
"cli\n"
"jmp *%[kernel_entry]\n"
-   :: [kernel_entry]"a"(load_address),
+   :: [kernel_entry]"a"(entry),
[boot_params] "S"(setup_base),
"b"(0), "D"(0)
);
diff --git a/arch/x86/lib/zimage.c b/arch/x86/lib/zimage.c
index a6d9151c3240..e5ea5129c1e9 100644
--- a/arch/x86/lib/zimage.c
+++ b/arch/x86/lib/zimage.c
@@ -504,13 +504,24 @@ static int do_zboot_info(struct cmd_tbl *cmdtp, int flag, 
int argc,
 static int do_zboot_go(struct cmd_tbl *cmdtp, int flag, int argc,
   char *const argv[])
 {
+   struct boot_params *params = state.base_ptr;
+   struct setup_header *hdr = >hdr;
+   bool image_64bit;
+   ulong entry;
int ret;
 
disable_interrupts();
 
+   entry = state.load_address;
+   image_64bit = false;
+   if (IS_ENABLED(CONFIG_X86_RUN_64BIT) &&
+   (hdr->xloadflags & XLF_KERNEL_64)) {
+   entry += 0x200;
+   image_64bit = true;
+   }
+
/* we assume that the kernel is in place */
-   ret = boot_linux_kernel((ulong)state.base_ptr, state.load_address,
-   false);
+   ret = 

[PATCH v3 03/12] x86: Add return-value comment to cpu_jump_to_64bit()

2023-03-19 Thread Simon Glass
This does not mention what it returns. Add the missing documentation.

Signed-off-by: Simon Glass 
---

Changes in v3:
- Use Return instead of Returns

 arch/x86/include/asm/cpu.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/x86/include/asm/cpu.h b/arch/x86/include/asm/cpu.h
index 3346012d335c..073f80b07f10 100644
--- a/arch/x86/include/asm/cpu.h
+++ b/arch/x86/include/asm/cpu.h
@@ -262,6 +262,7 @@ void cpu_call32(ulong code_seg32, ulong target, ulong 
table);
  *
  * @setup_base:Pointer to the setup.bin information for the kernel
  * @target:Pointer to the start of the kernel image
+ * Return: -EFAULT if the kernel returned; otherwise does not return
  */
 int cpu_jump_to_64bit(ulong setup_base, ulong target);
 
-- 
2.40.0.rc1.284.g88254d51c5-goog



[PATCH v3 00/12] efi: Improvements to booting and debugging

2023-03-19 Thread Simon Glass
This series provides support for booting a kernel from the EFI app. So
far this is pretty basic, since it only supports the actual booting, not
providing ACPI tables, etc. But it is a start.

It also includes an enhancement to the 'efi' command and a few other
clean-ups.


Changes in v3:
- Use Return instead of Returns
- Update commit message based on Heinrich's comments
- Make this depend on CONFIG_EFI so that EFI_LOADER doesn't get it
- Really drop SMBIOS
- Use %pUl to print the UUID
- Drop unnecessary error message for some that shoudn't happen.

Changes in v2:
- Update commit message to explain why these are needed
- Drop EFI_SMBIOS which exists as SMBIOS_TABLE_GUID
- Drop unwanted EFI_GUID_SNBIOS
- Drop EFI_GUID_EFI_ACPI2 which exists as EFI_ACPI_TABLE_GUID
- Add new patch to enable GUID names with EFI app and payload
- Add new patch to split out table-listing code into a new file
- Make use of common code
- Fix typos in commit message

Simon Glass (12):
  efi: Set RUN_64BIT correctly for the EFI app
  x86: Adjust bootparam.h to be more like linux
  x86: Add return-value comment to cpu_jump_to_64bit()
  x86: Support booting a 64-bit kernel from 64-bit U-Boot
  x86: Exit EFI boot services before starting kernel
  x86: Support zboot and bootm in the EFI app
  efi: Add another tranch of GUIDs
  efi: Include GUID names with EFI app and payload
  doc: Add help for the efi command
  efi: Split out table-listing code into a new file
  efi: Support showing tables
  efI: Allow packaging a kernel in the debugging script

 arch/x86/Kconfig |   4 +-
 arch/x86/include/asm/bootm.h |  12 +-
 arch/x86/include/asm/bootparam.h |  70 ++
 arch/x86/include/asm/cpu.h   |   1 +
 arch/x86/lib/bootm.c |  43 --
 arch/x86/lib/zimage.c|  17 ++-
 cmd/Makefile |   4 +-
 cmd/efi.c|  31 -
 cmd/efi_common.c |  26 
 cmd/efidebug.c   |   6 +-
 configs/efi-x86_app32_defconfig  |   2 +-
 configs/efi-x86_app64_defconfig  |   3 +-
 doc/usage/cmd/efi.rst| 219 +++
 doc/usage/index.rst  |   1 +
 include/efi.h|   9 ++
 include/efi_api.h|  19 +++
 lib/uuid.c   |  10 +-
 scripts/build-efi.sh |  14 +-
 18 files changed, 436 insertions(+), 55 deletions(-)
 create mode 100644 cmd/efi_common.c
 create mode 100644 doc/usage/cmd/efi.rst

-- 
2.40.0.rc1.284.g88254d51c5-goog



[PATCH v3 01/12] efi: Set RUN_64BIT correctly for the EFI app

2023-03-19 Thread Simon Glass
The U-Boot EFI app can run as a 64-bit program, so set the Kconfig
correctly in that case. Make sure it doesn't build SPL, since there is
no need to switch from 32 to 64 bit when running.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 arch/x86/Kconfig| 4 ++--
 configs/efi-x86_app64_defconfig | 1 +
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 07be5cd05ec0..99e59d94c606 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -32,8 +32,8 @@ config X86_RUN_32BIT
 config X86_RUN_64BIT
bool "64-bit"
select X86_64
-   select SPL
-   select SPL_SEPARATE_BSS
+   select SPL if !EFI_APP
+   select SPL_SEPARATE_BSS if !EFI_APP
help
  Build U-Boot as a 64-bit binary with a 32-bit SPL. This is
  experimental and many features are missing. U-Boot SPL starts up,
diff --git a/configs/efi-x86_app64_defconfig b/configs/efi-x86_app64_defconfig
index dae488404935..f1cf43c1ef66 100644
--- a/configs/efi-x86_app64_defconfig
+++ b/configs/efi-x86_app64_defconfig
@@ -4,6 +4,7 @@ CONFIG_ENV_SIZE=0x1000
 CONFIG_DEFAULT_DEVICE_TREE="efi-x86_app"
 CONFIG_DEBUG_UART_BASE=0
 CONFIG_DEBUG_UART_CLOCK=0
+CONFIG_X86_RUN_64BIT=y
 CONFIG_VENDOR_EFI=y
 CONFIG_TARGET_EFI_APP64=y
 CONFIG_DEBUG_UART=y
-- 
2.40.0.rc1.284.g88254d51c5-goog



Re: [PATCH 2/3] gpio: rockchip: Use gpio alias id as gpio bank id

2023-03-19 Thread Simon Glass
On Sun, 19 Mar 2023 at 12:57, Jonas Karlman  wrote:
>
> Use the gpio alias id as the gpio bank id, same as in the linux driver.
>
> This reverts the recent change to base bank id on the gpio-ranges prop
> and apply the same logic used when nodes was named gpio0@ to the alias.
>
> With missing gpio aliases added to u-boot.dtsi files this should restore
> gpio function for SoCs that have synced gpio0@ to gpio@ node name
> changes from linux.
>
> Fixes: 904b8700f81c ("gpio: gpio-rockchip: parse gpio-ranges for bank id")
> Signed-off-by: Jonas Karlman 
> ---
>  drivers/gpio/rk_gpio.c | 17 -
>  1 file changed, 4 insertions(+), 13 deletions(-)
>

Reviewed-by: Simon Glass 


Re: [PATCH] netconsole: various improvements

2023-03-19 Thread Simon Glass
Hi Tony,

On Sun, 19 Mar 2023 at 10:46, Tony Dinh  wrote:
>
> - When Netconsole is running, stdin/stdout/stderr are set to nc. Reset
> stdin/stdout/stderr to serial (a sane deffault) before booting kernel.

spelling

> - Enable net_timeout when netconsole starts will give a better user
> experience if netconsole server is not running.
>
> Signed-off-by: Tony Dinh 
> ---
>
>  boot/bootm.c | 16 +++-
>  drivers/net/netconsole.c |  2 +-
>  2 files changed, 16 insertions(+), 2 deletions(-)
>
> diff --git a/boot/bootm.c b/boot/bootm.c
> index 2eec60ec7b..c4a3aaf1bd 100644
> --- a/boot/bootm.c
> +++ b/boot/bootm.c
> @@ -473,7 +473,21 @@ ulong bootm_disable_interrupts(void)
>  */
> iflag = disable_interrupts();
>  #ifdef CONFIG_NETCONSOLE

Can you convert this to 'if IS_ENABLED(...)' at the same time?

> -   /* Stop the ethernet stack if NetConsole could have left it up */
> +   /*
> +* Make sure that the starting kernel message printed out.
> +* Reset stdin/out/err back to serial and stop the ethernet
> +* stack if NetConsole could have left it up
> +*/
> +   char *s;
> +   int ret;
> +
> +   s = env_get("stdout");
> +   if (strcmp(s, "nc") == 0) {
> +   printf("\n\nStarting kernel ...\n");
> +   ret = env_set("stdin", "serial");
> +   ret = env_set("stdout", "serial");
> +   ret = env_set("stderr", "serial");
> +   }
> eth_halt();
>  #endif
>
> diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c
> index 151bc55e07..2091014918 100644
> --- a/drivers/net/netconsole.c
> +++ b/drivers/net/netconsole.c
> @@ -20,7 +20,7 @@ static int input_size; /* char count in input buffer */
>  static int input_offset; /* offset to valid chars in input buffer */
>  static int input_recursion;
>  static int output_recursion;
> -static int net_timeout;
> +static int net_timeout = 1;

What is this change?

>  static uchar nc_ether[6]; /* server enet address */
>  static struct in_addr nc_ip; /* server ip */
>  static short nc_out_port; /* target output port */
> --
> 2.30.2
>

Could you take a look at converting netconsole to driver model? It
should be a child of the eth device probably. I think this patch is OK
for, but it would be better if the driver could deregister itself from
stdio in its remove() method, perhaps installing serial at that point.

Regards,
SImon


[PATCH v2] disk: Use a helper function to reduce duplication

2023-03-19 Thread Simon Glass
Reduce the duplicated code slightly by using a helper function to handle
the common code.

This reduces the code size very slightly.

Signed-off-by: Simon Glass 
---

Changes in v2:
- Rebase to -next

 disk/disk-uclass.c | 46 +-
 1 file changed, 25 insertions(+), 21 deletions(-)

diff --git a/disk/disk-uclass.c b/disk/disk-uclass.c
index d32747e2242d..7f1fd80b2248 100644
--- a/disk/disk-uclass.c
+++ b/disk/disk-uclass.c
@@ -65,26 +65,38 @@ int part_create_block_devices(struct udevice *blk_dev)
return 0;
 }
 
+static int blk_part_setup(struct udevice *dev, lbaint_t *startp,
+ lbaint_t blkcnt)
+{
+   struct disk_part *part;
+
+   part = dev_get_uclass_plat(dev);
+   if (*startp >= part->gpt_part_info.size)
+   return -E2BIG;
+
+   if (*startp + blkcnt > part->gpt_part_info.size)
+   blkcnt = part->gpt_part_info.size - *startp;
+   *startp += part->gpt_part_info.start;
+
+   return 0;
+}
+
 static ulong part_blk_read(struct udevice *dev, lbaint_t start,
   lbaint_t blkcnt, void *buffer)
 {
struct udevice *parent;
-   struct disk_part *part;
const struct blk_ops *ops;
+   int ret;
 
parent = dev_get_parent(dev);
ops = blk_get_ops(parent);
if (!ops->read)
return -ENOSYS;
 
-   part = dev_get_uclass_plat(dev);
-   if (start >= part->gpt_part_info.size)
+   ret = blk_part_setup(dev, , blkcnt);
+   if (ret)
return 0;
 
-   if ((start + blkcnt) > part->gpt_part_info.size)
-   blkcnt = part->gpt_part_info.size - start;
-   start += part->gpt_part_info.start;
-
return ops->read(parent, start, blkcnt, buffer);
 }
 
@@ -92,22 +104,18 @@ static ulong part_blk_write(struct udevice *dev, lbaint_t 
start,
lbaint_t blkcnt, const void *buffer)
 {
struct udevice *parent;
-   struct disk_part *part;
const struct blk_ops *ops;
+   int ret;
 
parent = dev_get_parent(dev);
ops = blk_get_ops(parent);
if (!ops->write)
return -ENOSYS;
 
-   part = dev_get_uclass_plat(dev);
-   if (start >= part->gpt_part_info.size)
+   ret = blk_part_setup(dev, , blkcnt);
+   if (ret)
return 0;
 
-   if ((start + blkcnt) > part->gpt_part_info.size)
-   blkcnt = part->gpt_part_info.size - start;
-   start += part->gpt_part_info.start;
-
return ops->write(parent, start, blkcnt, buffer);
 }
 
@@ -115,22 +123,18 @@ static ulong part_blk_erase(struct udevice *dev, lbaint_t 
start,
lbaint_t blkcnt)
 {
struct udevice *parent;
-   struct disk_part *part;
const struct blk_ops *ops;
+   int ret;
 
parent = dev_get_parent(dev);
ops = blk_get_ops(parent);
if (!ops->erase)
return -ENOSYS;
 
-   part = dev_get_uclass_plat(dev);
-   if (start >= part->gpt_part_info.size)
+   ret = blk_part_setup(dev, , blkcnt);
+   if (ret)
return 0;
 
-   if ((start + blkcnt) > part->gpt_part_info.size)
-   blkcnt = part->gpt_part_info.size - start;
-   start += part->gpt_part_info.start;
-
return ops->erase(parent, start, blkcnt);
 }
 
-- 
2.40.0.rc1.284.g88254d51c5-goog



Re: [PATCH v3] test_vboot.py: include test of fdt_add_pubkey tool

2023-03-19 Thread Simon Glass
Hi Ivan,

On Sun, 19 Mar 2023 at 12:42, Ivan Mikhaylov  wrote:
>
> From: Roman Kopytin 

Please add a commit message.

>
> Signed-off-by: Roman Kopytin 
> Signed-off-by: Ivan Mikhaylov 
> Cc: Rasmus Villemoes 
> ---
>  test/py/tests/test_vboot.py | 33 +
>  1 file changed, 33 insertions(+)
>
> diff --git a/test/py/tests/test_vboot.py b/test/py/tests/test_vboot.py
> index e3e7ca4b21..5ae622fe21 100644
> --- a/test/py/tests/test_vboot.py
> +++ b/test/py/tests/test_vboot.py
> @@ -491,6 +491,37 @@ def test_vboot(u_boot_console, name, sha_algo, padding, 
> sign_options, required,
>  # Check that the boot fails if the global signature is not provided
>  run_bootm(sha_algo, 'global image signature', 'signature is 
> mandatory', False)
>
> +def test_fdt_add_pubkey(sha_algo, padding, sign_options):
> +"""Test fdt_add_pubkey utility with given hash algorithm and padding.
> +
> +This function tests if fdt_add_pubkey utility may add public keys 
> into dtb.
> +
> +Args:
> +sha_algo: Either 'sha1' or 'sha256', to select the algorithm to 
> use
> +padding: Either '' or '-pss', to select the padding to use for 
> the
> +rsa signature algorithm.
> +sign_options: Options to mkimage when signing a fit image.
> +"""
> +
> +# Create a fresh .dtb without the public keys
> +dtc('sandbox-u-boot.dts')
> +make_fit('sign-configs-%s%s.its' % (sha_algo, padding))
> +
> +# Sign images with our dev keys
> +sign_fit(sha_algo, sign_options)
> +
> +# Create a fresh .dtb without the public keys
> +dtc('sandbox-u-boot.dts')
> +
> +cons.log.action('%s: Test fdt_add_pubkey with signed configuration' 
> % sha_algo)
> +# Then add the dev key via the fdt_add_pubkey tool
> +util.run_and_log(cons, [fdt_add_pubkey, '-a', '%s,%s' % ('sha256' if 
> algo_arg else sha_algo, \
> +'rsa3072' if sha_algo == 'sha384' else 
> 'rsa2048'),
> +'-k', tmpdir, '-n', 'dev', '-r', 'conf', 
> dtb])
> +
> +# Check with fit_check_sign that FIT is signed with key
> +util.run_and_log(cons, [fit_check_sign, '-f', fit, '-k', dtb])
> +
>  cons = u_boot_console
>  tmpdir = os.path.join(cons.config.result_dir, name) + '/'
>  if not os.path.exists(tmpdir):
> @@ -500,6 +531,7 @@ def test_vboot(u_boot_console, name, sha_algo, padding, 
> sign_options, required,
>  mkimage = cons.config.build_dir + '/tools/mkimage'
>  binman = cons.config.source_dir + '/tools/binman/binman'
>  fit_check_sign = cons.config.build_dir + '/tools/fit_check_sign'
> +fdt_add_pubkey = cons.config.build_dir + '/tools/fdt_add_pubkey'
>  dtc_args = '-I dts -O dtb -i %s' % tmpdir
>  dtb = '%ssandbox-u-boot.dtb' % tmpdir
>  sig_node = '/configurations/conf-1/signature'
> @@ -516,6 +548,7 @@ def test_vboot(u_boot_console, name, sha_algo, padding, 
> sign_options, required,
>  with open(evil_kernel, 'wb') as fd:
>  fd.write(500 * b'\x01')
>
> +test_fdt_add_pubkey(sha_algo, padding, sign_options)
>  try:
>  # We need to use our own device tree file. Remember to restore it
>  # afterwards.
> --
> 2.39.1
>

I'm not sure how you are testing this, but it fails for me:

+openssl req -batch -new -x509 -key
/tmp/b/sandbox/sha256-global-sign-pss/prod.key -out
/tmp/b/sandbox/sha256-global-sign-pss/prod.crt
+dtc -I dts -O dtb -i /tmp/b/sandbox/sha256-global-sign-pss/
/home/sjg/c/src/third_party/u-boot/files/test/py/tests/vboot/sandbox-u-boot.dts
-O dtb -o /tmp/b/sandbox/sha256-global-sign-pss/sandbox-u-boot.dtb
/home/sjg/c/src/third_party/u-boot/files/test/py/tests/vboot/sandbox-u-boot.dts:10.10-12.4:
Warning (unit_address_vs_reg): /reset@0: node has a unit name, but no
reg or ranges property
+/tmp/b/sandbox/tools/mkimage -D -I dts -O dtb -i
/tmp/b/sandbox/sha256-global-sign-pss/ -f
/home/sjg/c/src/third_party/u-boot/files/test/py/tests/vboot/sign-configs-sha256-pss.its
/tmp/b/sandbox/sha256-global-sign-pss/test.fit
FATAL ERROR: Couldn't open "sandbox-kernel.dtb": No such file or directory
/tmp/b/sandbox/tools/mkimage: Can't open
/tmp/b/sandbox/sha256-global-sign-pss/test.fit.tmp: No such file or
directory
Error: Bad parameters for FIT image type
Usage: /tmp/b/sandbox/tools/mkimage [-T type] -l image
  -l ==> list image header information
  -T ==> parse image file as 'type'
  -q ==> quiet
   /tmp/b/sandbox/tools/mkimage [-x] -A arch -O os -T type -C comp
-a addr -e ep -n name -d data_file[:data_file...] image
  -A ==> set architecture to 'arch'
  -O ==> set operating system to 'os'
  -T ==> set image type to 'type'
  -C ==> set compression type 'comp'
  -a ==> set load address to 'addr' (hex)
  -e ==> set entry point to 'ep' (hex)
  -n ==> set image name to 'name'
   

Re: [PATCH 1/1] efi_loader: move struct efi_device_path to efi.h

2023-03-19 Thread Simon Glass
On Sun, 19 Mar 2023 at 20:59, Heinrich Schuchardt
 wrote:
>
> Avoid forward declaration of struct efi_device_path.
>
> Signed-off-by: Heinrich Schuchardt 
> ---
>  include/efi.h | 13 -
>  include/efi_api.h |  6 --
>  2 files changed, 12 insertions(+), 7 deletions(-)
>

Reviewed-by: Simon Glass 

Missing motivation for patch.


Re: [PATCH] scripts/Makefile.lib: also consider $(CONFIG_SYS_BOARD)-u-boot.dtsi

2023-03-19 Thread Simon Glass
Hi Rasmus,

On Sun, 19 Mar 2023 at 13:34, Rasmus Villemoes
 wrote:
>
> On 18/03/2023 21.20, Simon Glass wrote:
>
> >>
> >> Now, the only way to be really sure is to build the world
> >> with/without this patch and check if any .dtb file changes, but I
> >> don't have the means to do that. But I do notice that
> >>
> >>
> >>  doc/develop/devicetree/control.rst | 1 +
> >>  scripts/Makefile.lib   | 2 ++
> >>  2 files changed, 3 insertions(+)
> >
> > Reviewed-by: Simon Glass 
> >
> > There is something missing at the end of your note.
>
> Ah, sorry. I meant to say something about that it seems some existing
> in-tree cases could make use of this and thus be simplified, e.g. all
> the t8103-*-u-boot.dtsi just include t8103-u-boot.dtsi, but then I
> wasn't really sure if that was a proper example, so decided to edit that
> part out (but left that small fragment in).
>
> > What U-Boot-specific things are you using?
>
> Just the u-boot,dm-spl kind of stuff.

With the new bindings, we can put those tags (bootph-...) in the kernel DTs.

Regards,
Simon


Re: [PATCH v2 09/12] doc: Add help for the efi command

2023-03-19 Thread Simon Glass
Hi Heinrich,

On Mon, 20 Mar 2023 at 05:38, Heinrich Schuchardt  wrote:
>
> On 3/10/23 21:48, Simon Glass wrote:
> > This command currently has no help. Add some.
> >
> > Signed-off-by: Simon Glass 
> > ---
> >
> > (no changes since v1)
> >
> >   doc/usage/cmd/efi.rst | 197 ++
> >   doc/usage/index.rst   |   1 +
> >   2 files changed, 198 insertions(+)
> >   create mode 100644 doc/usage/cmd/efi.rst
> >
> > diff --git a/doc/usage/cmd/efi.rst b/doc/usage/cmd/efi.rst
> > new file mode 100644
> > index 000..c029c423879
> > --- /dev/null
> > +++ b/doc/usage/cmd/efi.rst
> > @@ -0,0 +1,197 @@
> > +.. SPDX-License-Identifier: GPL-2.0+
> > +.. Copyright 2020, Heinrich Schuchardt 
> > +
> > +efi command
> > +===
> > +
> > +Synopsis
> > +
> > +
> > +::
> > +
> > +efi mem [all]
> > +
> > +Description
> > +---
> > +
> > +The *efi* command provides information about the EFI environment U-Boot is
> > +running in, when it is started from EFI.
> > +
> > +When running as an EFI app, this command queries EFI boot services for the
> > +information. When running as an EFI payload, EFI boot services have been
> > +stopped, so it uses the information collected by the boot stub before that
> > +happened.
> > +
> > +efi mem
> > +~~~
> > +
> > +This shows the EFI memory map, sorted in order of physical address.
> > +
> > +This is normally a very large table. To help reduce the amount of detritus,
> > +boot-time memory is normally merged with conventional memory. Use the 'all'
> > +argument to show everything.
> > +
> > +The fields are as follows:
> > +
> > +#
> > +Entry number (sequentially from 0)
> > +
> > +Type
> > +Memory type. EFI has a large number of memory types. The type is shown 
> > in
> > +the format : where in is the format number in hex and  
> > is the
> > +name.
> > +
> > +Physical
> > +Physical address
> > +
> > +Virtual
> > +Virtual address
> > +
> > +Size
> > +Size of memory area in bytes
> > +
> > +Attributes
> > +Shows a code for memory attributes. The key for this is shown below the
> > +table.
> > +
> > +Example
> > +---
> > +
> > +::
> > +
> > +=> efi mem
> > +EFI table at 0, memory map 1ad38b60, size 1260, key a79, 
> > version 1, descr. size 0x30
> > + #  Type  Physical VirtualSize  Attributes
> > + 0  7:conv  00  00  0a  f
> > +   0a  06
> > + 1  7:conv  10  00  70  f
> > + 2  a:acpi_nvs  80  00  008000  f
> > + 3  7:conv  808000  00  008000  f
> > + 4  a:acpi_nvs  81  00  0f  f
> > + 5  7:conv  90  00  001efef000  f
> > + 6  6:rt_data   001f8ef000  00  10  rf
> > + 7  5:rt_code   001f9ef000  00  10  rf
> > + 8  0:reserved  001faef000  00  08  f
> > + 9  9:acpi_reclaim  001fb6f000  00  01  f
> > +10  a:acpi_nvs  001fb7f000  00  08  f
> > +11  7:conv  001fbff000  00  359000  f
> > +12  6:rt_data   001ff58000  00  02  rf
> > +13  a:acpi_nvs  001ff78000  00  088000  f
> > +   002000  009000
> > +14  0:reserved  00b000  00  001000  1
> > +
> > +Attributes key:
> > + f: uncached, write-coalescing, write-through, write-back
> > +rf: uncached, write-coalescing, write-through, write-back, needs 
> > runtime mapping
> > + 1: uncached
> > +*Some areas are merged (use 'all' to see)
> > +
> > +
> > +=> efi mem  all
> > +EFI table at 0, memory map 1ad38bb0, size 1260, key a79, 
> > version 1, descr. size 0x30
> > + #  Type  Physical VirtualSize  Attributes
> > + 0  3:bs_code   00  00  001000  f
> > + 1  7:conv  001000  00  09f000  f
> > +   0a  06
> > + 2  7:conv  10  00  70  f
> > + 3  a:acpi_nvs  80  00  008000  f
> > + 4  7:conv  808000  00  008000  f
> > + 5  a:acpi_nvs  81  00  0f  f
> > + 6  4:bs_data   90  00  c0  f
> > + 7  7:conv  000150  00  000aa36000  f
> > + 8  2:loader_data   000bf36000  00  001000  f
> > + 9  4:bs_data   001bf36000  00  02  f
> > +10  7:conv  001bf56000  00  00021e1000  f
> > +11  1:loader_code   001e137000  00  0c4000  f
> > +12  7:conv  001e1fb000  00  09b000  f
> > +13  1:loader_code   001e296000  00  

Re: [PATCH v2 03/12] x86: Add return-value comment to cpu_jump_to_64bit()

2023-03-19 Thread Simon Glass
Hi Heinrich,

On Mon, 20 Mar 2023 at 05:19, Heinrich Schuchardt  wrote:
>
> On 3/10/23 21:48, Simon Glass wrote:
> > This does not mention what it returns. Add the missing documentation.
> >
> > Signed-off-by: Simon Glass 
> > ---
> >
> > (no changes since v1)
> >
> >   arch/x86/include/asm/cpu.h | 1 +
> >   1 file changed, 1 insertion(+)
> >
> > diff --git a/arch/x86/include/asm/cpu.h b/arch/x86/include/asm/cpu.h
> > index 3346012d335..aa03ef598e1 100644
> > --- a/arch/x86/include/asm/cpu.h
> > +++ b/arch/x86/include/asm/cpu.h
> > @@ -262,6 +262,7 @@ void cpu_call32(ulong code_seg32, ulong target, ulong 
> > table);
> >*
> >* @setup_base: Pointer to the setup.bin information for the kernel
> >* @target: Pointer to the start of the kernel image
> > + * Returns: -EFAULT if the kernel returned; otherwise does not return
>
> %s/Returns:/Return:/
>
> See https://docs.kernel.org/doc-guide/kernel-doc.html#function-documentation

Returns is more natural I think, in many contexts. It seems to support
both from my testing.

Regards,
Simon


Re: [PATCH] gpio: allow passing NULL to gpio_request_by_line_name() to search all gpio controllers

2023-03-19 Thread Simon Glass
Hi Rasmus,

On Sun, 19 Mar 2023 at 13:38, Rasmus Villemoes
 wrote:
>
> On 18/03/2023 21.20, Simon Glass wrote:
> > Hi Rasmus,
> >
> > On Fri, 17 Mar 2023 at 14:13, Rasmus Villemoes
> >  wrote:
> >>
> >> The API is more convenient to use if one doesn't have to know upfront
> >> which gpio controller has a line with the name one is searching for,
> >> and arrange to look that device up somehow. Or implement this loop
> >> oneself.
> >>
> >> Signed-off-by: Rasmus Villemoes 
> >> ---
> >>  drivers/gpio/gpio-uclass.c | 7 +++
> >>  include/asm-generic/gpio.h | 3 ++-
> >>  2 files changed, 9 insertions(+), 1 deletion(-)
> >
> > Reviewed-by: Simon Glass 
> >
> > What is a line name? I don't see any mention of its purpose in the
> > binding doc[1].
>
> Nah, those yaml-files are usually completely useless to gain some
> understanding of what stuff is for, I much preferred the free-form prose.
>
> https://www.kernel.org/doc/Documentation/devicetree/bindings/gpio/gpio.txt
> has this text:
>
> Optionally, a GPIO controller may have a "gpio-line-names" property. This is
> an array of strings defining the names of the GPIO lines going out of the
> GPIO controller. This name should be the most meaningful producer name
> for the system, such as a rail name indicating the usage. Package names
> such as pin name are discouraged: such lines have opaque names (since they
> are by definition generic purpose) and such names are usually not very
> helpful. For example "MMC-CD", "Red LED Vdd" and "ethernet reset" are
> reasonable line names as they describe what the line is used for.

OK thank you. I wonder why that is not included in the yaml? There is
a description field, I think.

+Rob Herring who may know

Regards,
Simon


Re: [PATCH 2/2] efi_loader: simplify efi_str_to_u16()

2023-03-19 Thread Simon Glass
On Sun, 19 Mar 2023 at 21:21, Heinrich Schuchardt
 wrote:
>
> Use efi_alloc() to allocate memory.
>
> Signed-off-by: Heinrich Schuchardt 
> ---
>  lib/efi_loader/efi_device_path_to_text.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)

Reviewed-by: Simon Glass 


Re: [PATCH 1/2] efi_loader: support for Ctrl() device path node

2023-03-19 Thread Simon Glass
On Mon, 20 Mar 2023 at 04:18, Heinrich Schuchardt
 wrote:
>
> * Add the definitions for Ctrl() device path nodes.
> * Implement Ctrl() nodes in the device path to text protocol.
>
> Signed-off-by: Heinrich Schuchardt 
> ---
>  include/efi_api.h| 6 ++
>  lib/efi_loader/efi_device_path_to_text.c | 7 +++
>  2 files changed, 13 insertions(+)
>

Reviewed-by: Simon Glass 


Re: [PATCH 2/2] efi_loader: fix device-path for USB devices

2023-03-19 Thread Simon Glass
Hi Heinrich,

On Mon, 20 Mar 2023 at 04:25, Heinrich Schuchardt
 wrote:
>
> EFI device paths for block devices must be unique. If a non-unique device
> path is discovered, probing of the block device fails.
>
> Currently we use UsbClass() device path nodes. As multiple devices may
> have the same vendor and product id these are non-unique. Instead we
> should use Usb() device path nodes. They include the USB port on the
> parent hub. Hence they are unique.
>
> A USB storage device may contain multiple logical units. These can be
> modeled as Ctrl() nodes.
>
> Reported-by: Patrick Delaunay 
> Signed-off-by: Heinrich Schuchardt 
> ---
>  lib/efi_loader/efi_device_path.c | 45 +++-
>  1 file changed, 33 insertions(+), 12 deletions(-)

Reviewed-by: Simon Glass 

[..]

>
> diff --git a/lib/efi_loader/efi_device_path.c 
> b/lib/efi_loader/efi_device_path.c
> index 3b267b713e..b6dd575b13 100644
> --- a/lib/efi_loader/efi_device_path.c
> +++ b/lib/efi_loader/efi_device_path.c
> @@ -147,7 +147,7 @@ struct efi_device_path *efi_dp_shorten(struct 
> efi_device_path *dp)
>  * in practice fallback.efi just uses MEDIA:HARD_DRIVE
>  * so not sure when we would see these other cases.
>  */
> -   if (EFI_DP_TYPE(dp, MESSAGING_DEVICE, MSG_USB_CLASS) ||
> +   if (EFI_DP_TYPE(dp, MESSAGING_DEVICE, MSG_USB) ||
> EFI_DP_TYPE(dp, MEDIA_DEVICE, HARD_DRIVE_PATH) ||
> EFI_DP_TYPE(dp, MEDIA_DEVICE, FILE_PATH))
> return dp;
> @@ -564,6 +564,11 @@ __maybe_unused static unsigned int dp_size(struct 
> udevice *dev)
> return dp_size(dev->parent)
> + sizeof(struct efi_device_path_vendor) + 1;
>  #endif
> +#ifdef CONFIG_USB
> +   case UCLASS_MASS_STORAGE:

Can we do:

   case UCLASS_MASS_STORAGE:
  if (IS_ENABLED(CONFIG_USB)) {
   ...
  }

?

and below too

> +   return dp_size(dev->parent)
> +   + sizeof(struct efi_device_path_controller);
> +#endif
>  #ifdef CONFIG_VIRTIO_BLK
> case UCLASS_VIRTIO:
>  /*
> @@ -585,7 +590,7 @@ __maybe_unused static unsigned int dp_size(struct udevice 
> *dev)
> case UCLASS_MASS_STORAGE:
> case UCLASS_USB_HUB:
> return dp_size(dev->parent) +
> -   sizeof(struct efi_device_path_usb_class);
> +   sizeof(struct efi_device_path_usb);
> default:
> /* just skip over unknown classes: */
> return dp_size(dev->parent);
> @@ -741,6 +746,19 @@ __maybe_unused static void *dp_fill(void *buf, struct 
> udevice *dev)
> memcpy(>ns_id, _id, sizeof(ns_id));
> return [1];
> }
> +#endif
> +#if defined(CONFIG_USB)
> +   case UCLASS_MASS_STORAGE: {
> +   struct blk_desc *desc = desc = 
> dev_get_uclass_plat(dev);
> +   struct efi_device_path_controller *dp =
> +   dp_fill(buf, dev->parent);
> +
> +   dp->dp.type = DEVICE_PATH_TYPE_HARDWARE_DEVICE;
> +   dp->dp.sub_type = DEVICE_PATH_SUB_TYPE_CONTROLLER;
> +   dp->dp.length   = sizeof(*dp);
> +   dp->controller_number = desc->lun;
> +   return [1];
> +   }
>  #endif

[..]

Regards,
SImon


Re: [PATCH v2 11/12] efi: Support showing tables

2023-03-19 Thread Simon Glass
Hi Heinrich,

On Mon, 20 Mar 2023 at 05:43, Heinrich Schuchardt  wrote:
>
> On 3/10/23 21:49, Simon Glass wrote:
> > Add a command (for the app and payload) to display the tables provided
> > by EFI.
> >
> > Signed-off-by: Simon Glass 
> > ---
> >
> > Changes in v2:
> > - Make use of common code
> >
> >   cmd/Makefile  |  2 +-
> >   cmd/efi.c | 33 -
> >   doc/usage/cmd/efi.rst | 22 ++
> >   3 files changed, 55 insertions(+), 2 deletions(-)
> >
> > diff --git a/cmd/Makefile b/cmd/Makefile
> > index 1c5c6f3c00c..a0bfa2acefe 100644
> > --- a/cmd/Makefile
> > +++ b/cmd/Makefile
> > @@ -62,7 +62,7 @@ obj-$(CONFIG_CMD_EXTENSION) += extension_board.o
> >   obj-$(CONFIG_CMD_ECHO) += echo.o
> >   obj-$(CONFIG_ENV_IS_IN_EEPROM) += eeprom.o
> >   obj-$(CONFIG_CMD_EEPROM) += eeprom.o
> > -obj-$(CONFIG_EFI) += efi.o
> > +obj-$(CONFIG_EFI) += efi.o efi_common.o
> >   obj-$(CONFIG_CMD_EFIDEBUG) += efidebug.o efi_common.o
> >   obj-$(CONFIG_CMD_EFICONFIG) += eficonfig.o
> >   ifdef CONFIG_CMD_EFICONFIG
> > diff --git a/cmd/efi.c b/cmd/efi.c
> > index c0384e0db28..4d0edfa7f27 100644
> > --- a/cmd/efi.c
> > +++ b/cmd/efi.c
> > @@ -7,10 +7,12 @@
> >   #include 
> >   #include 
> >   #include 
> > +#include 
> >   #include 
> >   #include 
> >   #include 
> >   #include 
> > +#include 
> >   #include 
> >
> >   DECLARE_GLOBAL_DATA_PTR;
> > @@ -273,8 +275,36 @@ done:
> >   return ret ? CMD_RET_FAILURE : 0;
> >   }
> >
> > +static int do_efi_tables(struct cmd_tbl *cmdtp, int flag, int argc,
> > +  char *const argv[])
> > +{
> > + struct efi_system_table *systab;
> > +
> > + if (IS_ENABLED(CONFIG_EFI_APP)) {
> > + systab = efi_get_sys_table();
> > + if (!systab) {
> > + printf("Cannot read system table\n");
> > + return CMD_RET_FAILURE;
> > + }
> > + } else {
> > + int size;
> > + int ret;
> > +
> > + ret = efi_info_get(EFIET_SYS_TABLE, (void **), );
> > + if (ret) {
> > + printf("Cannot find EFI system table (err=%d)\n", 
> > ret);
> > + return CMD_RET_FAILURE;
>
> Wouldn't U-Boot have failed earlier if there is no system table?

This is catching the case where we didn't add it to the list by
calling add_entry_addr() in the stub. I agree it can't happen with the
current code. How about I just drop the message, but still return
failure?

Regards,
Simon


Re: [PATCH u-boot] cmd: mmc: Return CMD_RET_* from commands

2023-03-19 Thread Simon Glass
Hi Pali,

On Mon, 20 Mar 2023 at 05:34, Pali Rohár  wrote:
>
> Numeric return values may cause strange errors line:
> exit not allowed from main input shell.
>
> Signed-off-by: Pali Rohár 
> ---
>  cmd/mmc.c | 18 +-
>  1 file changed, 13 insertions(+), 5 deletions(-)
>
> diff --git a/cmd/mmc.c b/cmd/mmc.c
> index c79d9407986d..0b8fc903e1f6 100644
> --- a/cmd/mmc.c
> +++ b/cmd/mmc.c
> @@ -175,7 +175,7 @@ static int do_mmcinfo(struct cmd_tbl *cmdtp, int flag, 
> int argc,
> curr_device = 0;
> else {
> puts("No MMC device available\n");
> -   return 1;
> +   return CMD_RET_FAILURE;
> }
> }
>
> @@ -927,7 +927,7 @@ static int mmc_partconf_print(struct mmc *mmc, const char 
> *varname)
>  static int do_mmc_partconf(struct cmd_tbl *cmdtp, int flag,
>int argc, char *const argv[])
>  {
> -   int dev;
> +   int r, dev;
> struct mmc *mmc;
> u8 ack, part_num, access;
>
> @@ -953,13 +953,17 @@ static int do_mmc_partconf(struct cmd_tbl *cmdtp, int 
> flag,
> access = dectoul(argv[4], NULL);
>
> /* acknowledge to be sent during boot operation */
> -   return mmc_set_part_conf(mmc, ack, part_num, access);
> +   r = mmc_set_part_conf(mmc, ack, part_num, access);
> +   if (r != 0)
> +   return CMD_RET_FAILURE;
> +
> +   return CMD_RET_SUCCESS;
>  }
>
>  static int do_mmc_rst_func(struct cmd_tbl *cmdtp, int flag,
>int argc, char *const argv[])
>  {
> -   int dev;
> +   int r, dev;

Please use 'ret' as that is what we normally do with driver model.

> struct mmc *mmc;
> u8 enable;
>
> @@ -988,7 +992,11 @@ static int do_mmc_rst_func(struct cmd_tbl *cmdtp, int 
> flag,
> return CMD_RET_FAILURE;
> }
>
> -   return mmc_set_rst_n_function(mmc, enable);
> +   r = mmc_set_rst_n_function(mmc, enable);
> +   if (r != 0)

if (ret)

> +   return CMD_RET_FAILURE;
> +
> +   return CMD_RET_SUCCESS;

'return 0' is fine here as less verbose. Success is 0 in U-Boot.

>  }
>  #endif
>  static int do_mmc_setdsr(struct cmd_tbl *cmdtp, int flag,
> --
> 2.20.1
>

Regards,
Simon


Re: [PATCH v2 08/12] efi: Include GUID names with EFI app and payload

2023-03-19 Thread Simon Glass
Hi Heinrich,

On Mon, 20 Mar 2023 at 05:36, Heinrich Schuchardt  wrote:
>
> On 3/10/23 21:48, Simon Glass wrote:
> > These are currently only available when running with EFI_LOADER.
> > Expand this to include the app and payload, since it is useful to be
> > able to decode things there.
> >
> > Signed-off-by: Simon Glass 
> > ---
> >
> > Changes in v2:
> > - Add new patch to enable GUID names with EFI app and payload
> >
> >   lib/uuid.c | 2 +-
> >   1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/lib/uuid.c b/lib/uuid.c
> > index d86fab72626..09793fb62bc 100644
> > --- a/lib/uuid.c
> > +++ b/lib/uuid.c
> > @@ -102,7 +102,7 @@ static const struct {
> >   {"lvm", PARTITION_LINUX_LVM_GUID},
> >   {"u-boot-env",  PARTITION_U_BOOT_ENVIRONMENT},
> >   #endif
> > -#ifdef CONFIG_CMD_EFIDEBUG
> > +#if defined(CONFIG_CMD_EFIDEBUG) || defined(CONFIG_EFI)
>
> %s/CONFIG_EFI/CONFIG_EFI_APP)/
>
> We don't need these when running EFI_STUB=y without EFI_LOADER).

Actually in that case they are needed, so that the 'efi tables'
command can work. Otherwise it just shows thes hex values.

Regards,
Simon


Re: [PATCH 1/3] rockchip: dts: Add missing alias for gpio controllers

2023-03-19 Thread Simon Glass
On Sun, 19 Mar 2023 at 12:57, Jonas Karlman  wrote:
>
> This adds any missing gpio alias for gpio controllers in rockchip
> u-boot.dtsi files. They are needed to determin what gpio bank id to use
> in the rockchip gpio driver.
>
> Signed-off-by: Jonas Karlman 
> ---
>  arch/arm/dts/px30-u-boot.dtsi|  4 
>  arch/arm/dts/rk3066a-u-boot.dtsi | 11 +++
>  arch/arm/dts/rk3188-u-boot.dtsi  |  9 +
>  arch/arm/dts/rk322x-u-boot.dtsi  |  7 +++
>  arch/arm/dts/rk3308-u-boot.dtsi  |  5 +
>  arch/arm/dts/rk3328-u-boot.dtsi  |  4 
>  arch/arm/dts/rk3368-u-boot.dtsi  |  7 +++
>  arch/arm/dts/rk3399-u-boot.dtsi  |  5 +
>  arch/arm/dts/rk3588s-u-boot.dtsi |  8 
>  arch/arm/dts/rv1108-u-boot.dtsi  |  9 +
>  arch/arm/dts/rv1126-u-boot.dtsi  |  8 
>  11 files changed, 77 insertions(+)

Reviewed-by: Simon Glass 


Re: [PATCH 4/4] CI: Add m68k target

2023-03-19 Thread Angelo Dureghello

Hi Marek,

On 19/03/23 4:14 AM, Marek Vasut wrote:

Add M5208EVBE board to CI. This does not use default config due to
limitations of QEMU emulation, instead the timer is switched from
DMA timer to PIT timer and RAMBAR accesses are inhibited.

Local QEMU launch command is as follows:
$ qemu-system-m68k -nographic -machine mcf5208evb -cpu m5208 -bios u-boot.bin

Signed-off-by: Marek Vasut 
---
Cc: Angelo Dureghello 
Cc: Huan Wang 
Cc: Marek Vasut 
Cc: Simon Glass 
Cc: Stefan Roese 
Cc: Tom Rini 
---
  .azure-pipelines.yml | 5 +
  .gitlab-ci.yml   | 8 
  2 files changed, 13 insertions(+)

diff --git a/.azure-pipelines.yml b/.azure-pipelines.yml
index 947c400f8d3..e4e0c4c4d0d 100644
--- a/.azure-pipelines.yml
+++ b/.azure-pipelines.yml
@@ -268,6 +268,11 @@ stages:
  qemu_arm64:
TEST_PY_BD: "qemu_arm64"
TEST_PY_TEST_SPEC: "not sleep"
+qemu_m68k:
+  TEST_PY_BD: "M5208EVBE"
+  TEST_PY_ID: "--id qemu"
+  TEST_PY_TEST_SPEC: "not sleep and not efi"
+  OVERRIDE: "-a CONFIG_M68K_QEMU=y -a CONFIG_MCFTMR=n"
  qemu_malta:
TEST_PY_BD: "malta"
TEST_PY_ID: "--id qemu"
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 272d69e2206..4c144ab938a 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -322,6 +322,14 @@ qemu_arm64 test.py:
  TEST_PY_TEST_SPEC: "not sleep"
<<: *buildman_and_testpy_dfn
  
+qemu_m68k test.py:

+  variables:
+TEST_PY_BD: "M5208EVBE"
+TEST_PY_TEST_SPEC: "not sleep and not efi"
+TEST_PY_ID: "--id qemu"
+OVERRIDE: "-a CONFIG_M68K_QEMU=y -a CONFIG_MCFTMR=n"
+  <<: *buildman_and_testpy_dfn
+
  qemu_malta test.py:
variables:
  TEST_PY_BD: "malta"


i tested the patchset in u-boot-coldfire, i see also a pipeline error:

https://source.denx.de/u-boot/custodians/u-boot-coldfire/-/pipelines/15651/failures

regards,
angelo



Re: [PATCH 2/4] arch: m68k: Introduce trivial PIT based timer

2023-03-19 Thread Angelo Dureghello

Hi Marek,

On 19/03/23 4:14 AM, Marek Vasut wrote:

The QEMU emulation of m68k does not support DMA timer, the only
timer that is supported is the PIT timer. Implement trivial PIT
timer support for m68k.

Signed-off-by: Marek Vasut 
---
Cc: Angelo Dureghello 
Cc: Huan Wang 
Cc: Marek Vasut 
Cc: Simon Glass 
Cc: Stefan Roese 
Cc: Tom Rini 
---
  arch/m68k/include/asm/immap.h | 24 +++
  arch/m68k/lib/time.c  | 36 +--
  common/board_f.c  |  2 +-
  3 files changed, 59 insertions(+), 3 deletions(-)

diff --git a/arch/m68k/include/asm/immap.h b/arch/m68k/include/asm/immap.h
index 3b515fe2c65..aafa4f40cb3 100644
--- a/arch/m68k/include/asm/immap.h
+++ b/arch/m68k/include/asm/immap.h
@@ -25,6 +25,8 @@
  #define CFG_SYS_TMRINTR_PEND  (CFG_SYS_TMRINTR_MASK)
  #define CFG_SYS_TMRINTR_PRI   (6)
  #define CFG_SYS_TIMER_PRESCALER   (((gd->bus_clk / 100) - 1) << 8)
+#else
+#define CFG_SYS_UDELAY_BASE(MMAP_PIT0)
  #endif
  
  #define CFG_SYS_INTR_BASE		(MMAP_INTC0)

@@ -47,6 +49,8 @@
  #define CFG_SYS_TMRINTR_PEND  (CFG_SYS_TMRINTR_MASK)
  #define CFG_SYS_TMRINTR_PRI   (0x1E)  /* Level must include 
inorder to work */
  #define CFG_SYS_TIMER_PRESCALER   (((gd->bus_clk / 100) - 1) << 8)
+#else
+#define CFG_SYS_UDELAY_BASE(MMAP_PIT0)
  #endif
  
  #define CFG_SYS_INTR_BASE		(MMAP_INTC0)

@@ -72,6 +76,8 @@
  #define CFG_SYS_TMRINTR_PEND  (CFG_SYS_TMRINTR_MASK)
  #define CFG_SYS_TMRINTR_PRI   (MCFSIM_ICR_AUTOVEC | MCFSIM_ICR_LEVEL7 
| MCFSIM_ICR_PRI3)
  #define CFG_SYS_TIMER_PRESCALER   (((gd->bus_clk / 200) - 1) << 8)
+#else
+#define CFG_SYS_UDELAY_BASE(MMAP_PIT0)
  #endif
  #endif/* CONFIG_M5249 */
  
@@ -95,6 +101,8 @@

  #define CFG_SYS_TMRINTR_PEND  (CFG_SYS_TMRINTR_MASK)
  #define CFG_SYS_TMRINTR_PRI   (MCFSIM_ICR_AUTOVEC | MCFSIM_ICR_LEVEL3 
| MCFSIM_ICR_PRI3)
  #define CFG_SYS_TIMER_PRESCALER   (((gd->bus_clk / 200) - 1) << 8)
+#else
+#define CFG_SYS_UDELAY_BASE(MMAP_PIT0)
  #endif
  #endif/* CONFIG_M5253 */
  
@@ -114,6 +122,8 @@

  #define CFG_SYS_TMRINTR_PEND  (CFG_SYS_TMRINTR_MASK)
  #define CFG_SYS_TMRINTR_PRI   (0x1E) /* Interrupt level 3, priority 6 
*/
  #define CFG_SYS_TIMER_PRESCALER   (((gd->bus_clk / 100) - 1) << 8)
+#else
+#define CFG_SYS_UDELAY_BASE(MMAP_PIT0)
  #endif
  
  #define CFG_SYS_INTR_BASE		(MMAP_INTC0)

@@ -139,6 +149,8 @@
  #define CFG_SYS_TMRINTR_PEND  (0)
  #define CFG_SYS_TMRINTR_PRI   (INT_ICR1_TMR3PI | INT_ICR1_TMR3IPL(5))
  #define CFG_SYS_TIMER_PRESCALER   (((gd->bus_clk / 100) - 1) << 8)
+#else
+#define CFG_SYS_UDELAY_BASE(MMAP_PIT0)
  #endif
  #endif/* CONFIG_M5272 */
  
@@ -161,6 +173,8 @@

  #define CFG_SYS_TMRINTR_PEND  (CFG_SYS_TMRINTR_MASK)
  #define CFG_SYS_TMRINTR_PRI   (0x1E)
  #define CFG_SYS_TIMER_PRESCALER   (((gd->bus_clk / 100) - 1) << 8)
+#else
+#define CFG_SYS_UDELAY_BASE(MMAP_PIT0)
  #endif
  #endif/* CONFIG_M5275 */
  
@@ -183,6 +197,8 @@

  #define CFG_SYS_TMRINTR_PEND  (CFG_SYS_TMRINTR_MASK)
  #define CFG_SYS_TMRINTR_PRI   (0x1E)  /* Level must include 
inorder to work */
  #define CFG_SYS_TIMER_PRESCALER   (((gd->bus_clk / 100) - 1) << 8)
+#else
+#define CFG_SYS_UDELAY_BASE(MMAP_PIT0)
  #endif
  #endif/* CONFIG_M5282 */
  
@@ -207,6 +223,8 @@

  #define CFG_SYS_TMRINTR_PRI  (MCFSIM_ICR_AUTOVEC | \
MCFSIM_ICR_LEVEL7 | MCFSIM_ICR_PRI3)
  #define CFG_SYS_TIMER_PRESCALER  (((gd->bus_clk / 100) - 1) << 8)
+#else
+#define CFG_SYS_UDELAY_BASE(MMAP_PIT0)
  #endif
  #endif  /* CONFIG_M5307 */
  
@@ -226,6 +244,8 @@

  #define CFG_SYS_TMRINTR_PEND  (CFG_SYS_TMRINTR_MASK)
  #define CFG_SYS_TMRINTR_PRI   (6)
  #define CFG_SYS_TIMER_PRESCALER   (((gd->bus_clk / 100) - 1) << 8)
+#else
+#define CFG_SYS_UDELAY_BASE(MMAP_PIT0)
  #endif
  
  #define CFG_SYS_INTR_BASE		(MMAP_INTC0)

@@ -248,6 +268,8 @@
  #define CFG_SYS_TMRINTR_PEND  (CFG_SYS_TMRINTR_MASK)
  #define CFG_SYS_TMRINTR_PRI   (6)
  #define CFG_SYS_TIMER_PRESCALER   (((gd->bus_clk / 100) - 1) << 8)
+#else
+#define CFG_SYS_UDELAY_BASE(MMAP_PIT0)
  #endif
  
  #define CFG_SYS_INTR_BASE		(MMAP_INTC0)

@@ -278,6 +300,8 @@
  #define CFG_SYS_TMRINTR_PEND  (CFG_SYS_TMRINTR_MASK)
  #define CFG_SYS_TMRINTR_PRI   (6)
  #define CFG_SYS_TIMER_PRESCALER   (((gd->bus_clk / 100) - 1) << 8)
+#else
+#define CFG_SYS_UDELAY_BASE(MMAP_PIT0)
  #endif
  
  #define CFG_SYS_INTR_BASE		(MMAP_INTC0)

diff --git a/arch/m68k/lib/time.c b/arch/m68k/lib/time.c
index 500e4dbbba2..61db1e6c500 

Re: [PATCH 1/4] arch: m68k: Use existing CONFIG_MCFTMR instead of CFG_MCFTMR

2023-03-19 Thread Angelo Dureghello

Hi Marek,

On 19/03/23 4:14 AM, Marek Vasut wrote:

There is an existing CONFIG_MCFTMR Kconfig symbol,
use it and drop all other instances of CFG_MCFTMR.
This duality is likely a result of bogus conversion
to Kconfig.



Thanks, my fault here, introduced in commit
7ff7b46e6ce44b2ee09647a928ce1021c3c8a66e

i mainly misunderstood the CI error, moving this to
CFG namespace. Thanks for fixing it.


Signed-off-by: Marek Vasut 
---
Cc: Angelo Dureghello 
Cc: Huan Wang 
Cc: Marek Vasut 
Cc: Simon Glass 
Cc: Stefan Roese 
Cc: Tom Rini 
---
  arch/m68k/Kconfig   |  1 +
  arch/m68k/cpu/mcf523x/interrupts.c  |  2 +-
  arch/m68k/cpu/mcf52x2/interrupts.c  | 12 ++--
  arch/m68k/cpu/mcf532x/interrupts.c  |  2 +-
  arch/m68k/cpu/mcf5445x/interrupts.c |  2 +-
  arch/m68k/include/asm/immap.h   | 24 
  arch/m68k/lib/time.c|  4 ++--
  board/freescale/m53017evb/README|  2 +-
  board/freescale/m5373evb/README |  2 +-
  include/configs/M5208EVBE.h |  1 -
  include/configs/M5235EVB.h  |  1 -
  include/configs/M5249EVB.h  |  1 -
  include/configs/M5253DEMO.h |  1 -
  include/configs/M5272C3.h   |  1 -
  include/configs/M5275EVB.h  |  1 -
  include/configs/M5282EVB.h  |  1 -
  include/configs/M53017EVB.h |  1 -
  include/configs/M5329EVB.h  |  1 -
  include/configs/M5373EVB.h  |  1 -
  include/configs/amcore.h|  1 -
  include/configs/astro_mcf5373l.h|  1 -
  include/configs/cobra5272.h |  1 -
  include/configs/eb_cpu5282.h|  1 -
  include/configs/stmark2.h   |  1 -
  24 files changed, 26 insertions(+), 40 deletions(-)

diff --git a/arch/m68k/Kconfig b/arch/m68k/Kconfig
index 76233ef563f..32759cde47d 100644
--- a/arch/m68k/Kconfig
+++ b/arch/m68k/Kconfig
@@ -200,5 +200,6 @@ source "board/sysam/stmark2/Kconfig"
  
  config MCFTMR

bool "Use DMA timer"
+   default y
  
  endmenu

diff --git a/arch/m68k/cpu/mcf523x/interrupts.c 
b/arch/m68k/cpu/mcf523x/interrupts.c
index b02ea29f635..09c7f9e67cc 100644
--- a/arch/m68k/cpu/mcf523x/interrupts.c
+++ b/arch/m68k/cpu/mcf523x/interrupts.c
@@ -22,7 +22,7 @@ int interrupt_init(void)
return 0;
  }
  
-#if defined(CFG_MCFTMR)

+#if CONFIG_IS_ENABLED(MCFTMR)
  void dtimer_intr_setup(void)
  {
int0_t *intp = (int0_t *) (CFG_SYS_INTR_BASE);
diff --git a/arch/m68k/cpu/mcf52x2/interrupts.c 
b/arch/m68k/cpu/mcf52x2/interrupts.c
index e787c7605f8..c5ed0600736 100644
--- a/arch/m68k/cpu/mcf52x2/interrupts.c
+++ b/arch/m68k/cpu/mcf52x2/interrupts.c
@@ -34,7 +34,7 @@ int interrupt_init(void)
return 0;
  }
  
-#if defined(CFG_MCFTMR)

+#if CONFIG_IS_ENABLED(MCFTMR)
  void dtimer_intr_setup(void)
  {
intctrl_t *intp = (intctrl_t *) (CFG_SYS_INTR_BASE);
@@ -42,7 +42,7 @@ void dtimer_intr_setup(void)
clrbits_be32(>int_icr1, INT_ICR1_TMR3MASK);
setbits_be32(>int_icr1, CFG_SYS_TMRINTR_PRI);
  }
-#endif /* CFG_MCFTMR */
+#endif /* CONFIG_MCFTMR */
  #endif/* CONFIG_M5272 */
  
  #if defined(CONFIG_M5208) || defined(CONFIG_M5282) || \

@@ -63,7 +63,7 @@ int interrupt_init(void)
return 0;
  }
  
-#if defined(CFG_MCFTMR)

+#if CONFIG_IS_ENABLED(MCFTMR)
  void dtimer_intr_setup(void)
  {
int0_t *intp = (int0_t *) (CFG_SYS_INTR_BASE);
@@ -72,7 +72,7 @@ void dtimer_intr_setup(void)
clrbits_be32(>imrl0, 0x0001);
clrbits_be32(>imrl0, CFG_SYS_TMRINTR_MASK);
  }
-#endif /* CFG_MCFTMR */
+#endif /* CONFIG_MCFTMR */
  #endif/* CONFIG_M5282 | CONFIG_M5271 | 
CONFIG_M5275 */
  
  #if defined(CONFIG_M5249) || defined(CONFIG_M5253)

@@ -83,11 +83,11 @@ int interrupt_init(void)
return 0;
  }
  
-#if defined(CFG_MCFTMR)

+#if CONFIG_IS_ENABLED(MCFTMR)
  void dtimer_intr_setup(void)
  {
mbar_writeLong(MCFSIM_IMR, mbar_readLong(MCFSIM_IMR) & ~0x0400);
mbar_writeByte(MCFSIM_TIMER2ICR, CFG_SYS_TMRINTR_PRI);
  }
-#endif /* CFG_MCFTMR */
+#endif /* CONFIG_MCFTMR */
  #endif/* CONFIG_M5249 || CONFIG_M5253 */
diff --git a/arch/m68k/cpu/mcf532x/interrupts.c 
b/arch/m68k/cpu/mcf532x/interrupts.c
index bbe823c0cf7..4f72fa88e58 100644
--- a/arch/m68k/cpu/mcf532x/interrupts.c
+++ b/arch/m68k/cpu/mcf532x/interrupts.c
@@ -23,7 +23,7 @@ int interrupt_init(void)
return 0;
  }
  
-#if defined(CFG_MCFTMR)

+#if CONFIG_IS_ENABLED(MCFTMR)
  void dtimer_intr_setup(void)
  {
int0_t *intp = (int0_t *) (CFG_SYS_INTR_BASE);
diff --git a/arch/m68k/cpu/mcf5445x/interrupts.c 
b/arch/m68k/cpu/mcf5445x/interrupts.c
index fb80a879c7e..400f3dee879 100644
--- a/arch/m68k/cpu/mcf5445x/interrupts.c
+++ b/arch/m68k/cpu/mcf5445x/interrupts.c
@@ -26,7 +26,7 @@ int interrupt_init(void)
return 

[PATCH v2] gpio: rockchip: Add support for RK3568 and RK3588 banks

2023-03-19 Thread Jonas Karlman
The GPIO V2 controller on RK3568 and RK3588 works very similar to
prior generation, main difference is the use of a write mask in the
upper 16 bits and register address offset have changed.

GPIO_VER_ID is a new register at 0x0078 that is used to determine when
the driver should use new or old register offsets and values. Earlier
generation return 0x0 from this offset.

Refactor code and add support for the GPIO V2 controller used in RK3568
and RK3588.

Signed-off-by: Jonas Karlman 
---
Changes in v2:
- Drop two patches related to gpio alias id

 drivers/gpio/rk_gpio.c | 112 -
 1 file changed, 76 insertions(+), 36 deletions(-)

diff --git a/drivers/gpio/rk_gpio.c b/drivers/gpio/rk_gpio.c
index f7ad4d68b452..d9bde8f4f034 100644
--- a/drivers/gpio/rk_gpio.c
+++ b/drivers/gpio/rk_gpio.c
@@ -13,83 +13,118 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
-#include 
+#include 
+#include 
+
+#define SWPORT_DR  0x
+#define SWPORT_DDR 0x0004
+#define EXT_PORT   0x0050
+#define SWPORT_DR_L0x
+#define SWPORT_DR_H0x0004
+#define SWPORT_DDR_L   0x0008
+#define SWPORT_DDR_H   0x000C
+#define EXT_PORT_V20x0070
+#define VER_ID_V2  0x0078
 
 enum {
ROCKCHIP_GPIOS_PER_BANK = 32,
 };
 
-#define OFFSET_TO_BIT(bit) (1UL << (bit))
-
 struct rockchip_gpio_priv {
-   struct rockchip_gpio_regs *regs;
+   void __iomem *regs;
struct udevice *pinctrl;
int bank;
char name[2];
+   u32 version;
 };
 
-static int rockchip_gpio_direction_input(struct udevice *dev, unsigned offset)
+static int rockchip_gpio_get_value(struct udevice *dev, unsigned offset)
 {
struct rockchip_gpio_priv *priv = dev_get_priv(dev);
-   struct rockchip_gpio_regs *regs = priv->regs;
+   u32 mask = BIT(offset), data;
 
-   clrbits_le32(>swport_ddr, OFFSET_TO_BIT(offset));
+   if (priv->version)
+   data = readl(priv->regs + EXT_PORT_V2);
+   else
+   data = readl(priv->regs + EXT_PORT);
 
-   return 0;
+   return (data & mask) ? 1 : 0;
 }
 
-static int rockchip_gpio_direction_output(struct udevice *dev, unsigned offset,
- int value)
+static int rockchip_gpio_set_value(struct udevice *dev, unsigned offset,
+  int value)
 {
struct rockchip_gpio_priv *priv = dev_get_priv(dev);
-   struct rockchip_gpio_regs *regs = priv->regs;
-   int mask = OFFSET_TO_BIT(offset);
+   u32 mask = BIT(offset), data = value ? mask : 0;
 
-   clrsetbits_le32(>swport_dr, mask, value ? mask : 0);
-   setbits_le32(>swport_ddr, mask);
+   if (priv->version && offset >= 16)
+   rk_clrsetreg(priv->regs + SWPORT_DR_H, mask >> 16, data >> 16);
+   else if (priv->version)
+   rk_clrsetreg(priv->regs + SWPORT_DR_L, mask, data);
+   else
+   clrsetbits_le32(priv->regs + SWPORT_DR, mask, data);
 
return 0;
 }
 
-static int rockchip_gpio_get_value(struct udevice *dev, unsigned offset)
+static int rockchip_gpio_direction_input(struct udevice *dev, unsigned offset)
 {
struct rockchip_gpio_priv *priv = dev_get_priv(dev);
-   struct rockchip_gpio_regs *regs = priv->regs;
+   u32 mask = BIT(offset);
+
+   if (priv->version && offset >= 16)
+   rk_clrreg(priv->regs + SWPORT_DDR_H, mask >> 16);
+   else if (priv->version)
+   rk_clrreg(priv->regs + SWPORT_DDR_L, mask);
+   else
+   clrbits_le32(priv->regs + SWPORT_DDR, mask);
 
-   return readl(>ext_port) & OFFSET_TO_BIT(offset) ? 1 : 0;
+   return 0;
 }
 
-static int rockchip_gpio_set_value(struct udevice *dev, unsigned offset,
-  int value)
+static int rockchip_gpio_direction_output(struct udevice *dev, unsigned offset,
+ int value)
 {
struct rockchip_gpio_priv *priv = dev_get_priv(dev);
-   struct rockchip_gpio_regs *regs = priv->regs;
-   int mask = OFFSET_TO_BIT(offset);
+   u32 mask = BIT(offset);
+
+   rockchip_gpio_set_value(dev, offset, value);
 
-   clrsetbits_le32(>swport_dr, mask, value ? mask : 0);
+   if (priv->version && offset >= 16)
+   rk_setreg(priv->regs + SWPORT_DDR_H, mask >> 16);
+   else if (priv->version)
+   rk_setreg(priv->regs + SWPORT_DDR_L, mask);
+   else
+   setbits_le32(priv->regs + SWPORT_DDR, mask);
 
return 0;
 }
 
 static int rockchip_gpio_get_function(struct udevice *dev, unsigned offset)
 {
-#ifdef CONFIG_SPL_BUILD
-   return -ENODATA;
-#else
struct rockchip_gpio_priv *priv = dev_get_priv(dev);
-   struct rockchip_gpio_regs *regs = priv->regs;
-   bool is_output;
+   u32 mask = BIT(offset), data;
int ret;
 
-   ret = 

Re: [PATCH RFC u-boot-mvebu 0/6] arm: mvebu: Fix boot mode detection

2023-03-19 Thread Pali Rohár
On Sunday 19 March 2023 17:47:57 Pali Rohár wrote:
> On Sunday 19 March 2023 03:30:33 Martin Rowe wrote:
> > On Sun, 5 Mar 2023 at 11:55, Pali Rohár  wrote:
> > 
> > > On Sunday 05 March 2023 04:21:42 Martin Rowe wrote:
> > > > On Sat, 4 Mar 2023 at 10:51, Pali Rohár  wrote:
> > > >
> > > > > Improve code for checking strapping pins which specifies boot mode
> > > source.
> > > > >
> > > > > Martin, could you test if Clearfog can be still configured into UART
> > > > > booting mode via HW switches and if it still works correctly? First
> > > > > patch is reverting UART related commit for Clearfog which I think it
> > > not
> > > > > needed anymore.
> > > > >
> > > >
> > > > On Clearfog the logic in the CONFIG_ARMADA_38X ifdef before the switch
> > > that
> > > > you refactored in cpu.c/get_boot_device is all that gets processed. It
> > > > decides there is an error and returns BOOT_DEVICE_UART, probably because
> > > of
> > > > the invalid boot workaround for broken UART selection that you
> > > identified.
> > >
> > > Ok, so I figured out correctly how this invalid mode works.
> > >
> > > > UART only works if I use the clearfog_spi_defconfig or if I select
> > > > CONFIG_MVEBU_SPL_BOOT_DEVICE_UART=y. It does not work with the MMC or
> > > SATA
> > > > defconfigs. I get the same result without this patch series applied,
> > > though.
> > > >
> > > > The failed cases have the same output (other than kwboot header patching
> > > > output) until after sending boot image data is complete. The output 
> > > > stops
> > > > after:
> > > > 
> > > >  98 % [.
> > > >   ]
> > > > Done
> > > > Finishing transfer
> > > > [Type Ctrl-\ + c to quit]
> > > > 
> > >
> > > This is very strange because CONFIG_MVEBU_SPL_BOOT_DEVICE_UART just
> > > instruct mkimage what to put into kwbimage header.
> > >
> > > If I'm looking at the output correctly then SPL was booted, it correctly
> > > trained DDR RAM, returned back to bootrom, kwboot continued sending main
> > > u-boot and bootrom confirmed that transfer of both SPL and main u-boot
> > > is complete. But then there is no output from main u-boot.
> > >
> > > > It looks like an unrelated issue with kwboot.c, which I was sure was
> > > > working after the last patches but I can no longer reproduce a 
> > > > successful
> > > > boot.
> > >
> > > Can you check that you are using _both_ mkimage and kwboot from version
> > > with applying _all_ my patches recently sent to ML? Because both mkimage
> > > and kwboot have fixes for SATA and SDIO images.
> > >
> > 
> > I tested using the latest next branch which has those changes in it. Steps:
> > - Set UART boot mode on device
> > - make clean
> > - make clearfog_defconfig
> > - make
> > - ./tools/kwboot -b u-boot-with-spl.kwb -t /dev/ttyUSB0
> > 
> > For me it looks like that either mkimage generated incorrect image size
> > > for SATA or SDIO image. Or kwboot incorrectly parsed that image size
> > > from kwbimage header and sent smaller image.
> > >
> > 
> > 
> > ./tools/kwboot -b u-boot-with-spl.kwb -t /dev/ttyUSB0
> > kwboot version 2023.04-rc4-00339-gcefd0449d6
> > Detected kwbimage v1 with SDIO boot signature
> > Patching image boot signature to UART
> > Aligning image header to Xmodem block size
> > Sending boot message. Please reboot the target...\
> > Sending boot image header (113408 bytes)...
> >   0 %
> > [..]
> > 
> >  94 % [..
> >  ]
> > Done
> > 
> > U-Boot SPL 2023.04-rc4-00339-gcefd0449d6 (Mar 19 2023 - 12:57:31 +1000)
> > High speed PHY - Version: 2.0
> > EEPROM TLV detection failed: Using static config for Clearfog Pro.
> > Detected Device ID 6828
> > board SerDes lanes topology details:
> >  | Lane # | Speed |  Type   |
> >  
> >  |   0|   3   | SATA0 |
> >  |   1|   0   | SGMII1 |
> >  |   2|   5   | PCIe1 |
> >  |   3|   5   | USB3 HOST1 |
> >  |   4|   5   | PCIe2 |
> >  |   5|   0   | SGMII2 |
> >  
> > High speed PHY - Ended Successfully
> > mv_ddr: 14.0.0
> > DDR3 Training Sequence - Switching XBAR Window to FastPath Window
> > mv_ddr: completed successfully
> > Trying to boot from BOOTROM
> > Returning to BootROM (return address 0x05c4)...
> > 
> > Sending boot image data (474564 bytes)...
> >   0 %
> > [..]
> > 
> >  98 % [
> >  ]
> > Done
> > Finishing transfer
> > [Type Ctrl-\ + c to quit]
> > 
> > 
> > 
> > du -b u-boot*
> > 4996828 u-boot
> > 474304 u-boot.bin
> > 15155 u-boot.cfg
> > 19496 u-boot.dtb
> > 474304 u-boot-dtb.bin
> > 474368 u-boot-dtb.img
> > 474368 u-boot.img
> > 1721 u-boot.lds
> > 1069982 u-boot.map
> > 454808 

Re: [PATCH v3] Let the EQoS in imx8mp handle fixed-phy too.

2023-03-19 Thread Marek Vasut

On 3/19/23 11:43, Elmar Psilog wrote:

Without that patch it lost track to the node to scan
speed and duplex.
Patch was created by Marek Vasut, just tested by me.

Signed-off-by: Elmar Psilog 
Reviewed-by: Marek Vasut 
---
   changes v2: fix format issues
   changes v3: remove {} around single if, add reviewd..

  drivers/net/dwc_eth_qos.c | 18 +++---
  1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/drivers/net/dwc_eth_qos.c b/drivers/net/dwc_eth_qos.c
index 112deb546d..b9de205b8a 100644
--- a/drivers/net/dwc_eth_qos.c
+++ b/drivers/net/dwc_eth_qos.c
@@ -788,9 +788,21 @@ static int eqos_start(struct udevice *dev)
   */
  if (!eqos->phy) {
  int addr = -1;
-    addr = eqos_get_phy_addr(eqos, dev);
-    eqos->phy = phy_connect(eqos->mii, addr, dev,
-    eqos->config->interface(dev));
+    ofnode fixed_node;
+
+    if (IS_ENABLED(CONFIG_PHY_FIXED)) {
+    fixed_node = ofnode_find_subnode(dev_ofnode(dev),
+ "fixed-link");
+    if (ofnode_valid(fixed_node))
+    eqos->phy = fixed_phy_create(dev_ofnode(dev));
+    }
+
+    if (!eqos->phy) {
+    addr = eqos_get_phy_addr(eqos, dev);
+    eqos->phy = phy_connect(eqos->mii, addr, dev,
+    eqos->config->interface(dev));
+    }
+
  if (!eqos->phy) {
  pr_err("phy_connect() failed");
  goto err_stop_resets;
--
2.34.1



I would give a short reminder about the patch. Reviewed by Marek, ok for
Ramon. Would be glad to see it in 2023.04.


We're already in 2023.04-rc4 , this is material for v2023.07 , i.e. for 
u-boot/next branch .


Re: [PATCH] fdt: Make fdt addr -q quieter

2023-03-19 Thread Marek Vasut

On 3/17/23 18:27, Peter Hoyes wrote:

On 17/03/2023 12:17, Marek Vasut wrote:

On 3/16/23 17:34, Peter Hoyes wrote:

From: Peter Hoyes 

64597346 "fdt: Add -q option to fdt addr for distro_bootcmd" introduced
the -q option for fdt addr, which sets the current working fdt address
without printing any output.

baf41410 "fdt: Show a message when the working FDT changes" made the
utility function set_working_fdt_addr (in cmd/fdt.c) output a message
on each invocation, even if called via fdt addr -q, in which case its
output is now slightly noisier.

To fix this, move the printf outside of set_working_fdt_addr to three
call sites:
  * bootm_find_images (the use case for which the additional output was
    added in baf41410).
  * fdt addr, but only if the 'quiet' argument is not set.
  * fdt move.

This also has the advantage of printing the specified address instead of
the translated address when using the sandbox.

Remove assertions from the fdt addr test case when:
  * Calling set_working_fdt_addr directly.
  * Calling fdt addr with the -q argument.


Why not just pass the 'quiet' flag to set_working_fdt_addr() to avoid 
duplication ?


I considered this too, but there are other machine-specific call sites 
and I was trying to avoid adding an extra argument everywhere just for 
logging.


I'll send a v2 with a 'quiet' argument on Monday.


H, what about creating a wrapper with the extra logging ? That way, 
you can have the logging in one place, without introducing the extra 
parameter.


int set_working_fdt_addr_verbose(...) {
 ret = set_working_fdt_addr();
 printf(...);
 return ret;
}


[PATCH 4/5] net: phy: Add MDIO PCS 2.5G and 5G speed macros from Linux

2023-03-19 Thread Marek Vasut
Add MDIO PCS 2.5G and 5G speed macros from Linux 5.1.y as of commit
7fd8afa8933a0 ("net: phy: Add generic support for 2.5GBaseT and 5GBaseT")
This is used by the upcoming Marvell 10G PHY driver.

Signed-off-by: Marek Vasut 
---
Cc: "Ariel D'Alessandro" 
Cc: "Marek Behún" 
Cc: Joe Hershberger 
Cc: Marek Vasut 
Cc: Michael Trimarchi 
Cc: Nate Drude 
Cc: Ramon Fried 
Cc: Simon Glass 
Cc: Stefan Roese 
Cc: Tim Harvey 
Cc: Vladimir Oltean 
---
 include/linux/mdio.h | 18 ++
 1 file changed, 18 insertions(+)

diff --git a/include/linux/mdio.h b/include/linux/mdio.h
index 6e821d906fb..b7c845155e4 100644
--- a/include/linux/mdio.h
+++ b/include/linux/mdio.h
@@ -44,6 +44,7 @@
 #define MDIO_AN_ADVERTISE  16  /* AN advertising (base page) */
 #define MDIO_AN_LPA19  /* AN LP abilities (base page) */
 #define MDIO_PCS_EEE_ABLE  20  /* EEE Capability register */
+#define MDIO_PMA_NG_EXTABLE21  /* 2.5G/5G PMA/PMD extended ability */
 #define MDIO_PCS_EEE_WK_ERR22  /* EEE wake error counter */
 #define MDIO_PHYXS_LNSTAT  24  /* PHY XGXS lane state */
 #define MDIO_AN_EEE_ADV60  /* EEE advertisement */
@@ -91,6 +92,10 @@
 #define MDIO_CTRL1_SPEED10G(MDIO_CTRL1_SPEEDSELEXT | 0x00)
 /* 10PASS-TS/2BASE-TL */
 #define MDIO_CTRL1_SPEED10P2B  (MDIO_CTRL1_SPEEDSELEXT | 0x04)
+/* 2.5 Gb/s */
+#define MDIO_CTRL1_SPEED2_5G   (MDIO_CTRL1_SPEEDSELEXT | 0x18)
+/* 5 Gb/s */
+#define MDIO_CTRL1_SPEED5G (MDIO_CTRL1_SPEEDSELEXT | 0x1c)
 
 /* Status register 1. */
 #define MDIO_STAT1_LPOWERABLE  0x0002  /* Low-power ability */
@@ -111,6 +116,8 @@
 #define MDIO_PMA_SPEED_100 0x0020  /* 100M capable */
 #define MDIO_PMA_SPEED_10  0x0040  /* 10M capable */
 #define MDIO_PCS_SPEED_10P2B   0x0002  /* 10PASS-TS/2BASE-TL capable */
+#define MDIO_PCS_SPEED_2_5G0x0040  /* 2.5G capable */
+#define MDIO_PCS_SPEED_5G  0x0080  /* 5G capable */
 
 /* Device present registers. */
 #define MDIO_DEVS_PRESENT(devad)   (1 << (devad))
@@ -150,6 +157,8 @@
 #define MDIO_PMA_CTRL2_1000BKX 0x000d  /* 1000BASE-KX type */
 #define MDIO_PMA_CTRL2_100BTX  0x000e  /* 100BASE-TX type */
 #define MDIO_PMA_CTRL2_10BT0x000f  /* 10BASE-T type */
+#define MDIO_PMA_CTRL2_2_5GBT  0x0030  /* 2.5GBaseT type */
+#define MDIO_PMA_CTRL2_5GBT0x0031  /* 5GBaseT type */
 #define MDIO_PCS_CTRL2_TYPE0x0003  /* PCS type selection */
 #define MDIO_PCS_CTRL2_10GBR   0x  /* 10GBASE-R type */
 #define MDIO_PCS_CTRL2_10GBX   0x0001  /* 10GBASE-X type */
@@ -203,6 +212,7 @@
 #define MDIO_PMA_EXTABLE_1000BKX   0x0040  /* 1000BASE-KX ability */
 #define MDIO_PMA_EXTABLE_100BTX0x0080  /* 100BASE-TX ability */
 #define MDIO_PMA_EXTABLE_10BT  0x0100  /* 10BASE-T ability */
+#define MDIO_PMA_EXTABLE_NBT   0x4000  /* 2.5/5GBASE-T ability */
 
 /* PHY XGXS lane state register. */
 #define MDIO_PHYXS_LNSTAT_SYNC00x0001
@@ -239,9 +249,13 @@
 #define MDIO_PCS_10GBRT_STAT2_BER  0x3f00
 
 /* AN 10GBASE-T control register. */
+#define MDIO_AN_10GBT_CTRL_ADV2_5G 0x0080  /* Advertise 2.5GBASE-T */
+#define MDIO_AN_10GBT_CTRL_ADV5G   0x0100  /* Advertise 5GBASE-T */
 #define MDIO_AN_10GBT_CTRL_ADV10G  0x1000  /* Advertise 10GBASE-T */
 
 /* AN 10GBASE-T status register. */
+#define MDIO_AN_10GBT_STAT_LP2_5G  0x0020  /* LP is 2.5GBT capable */
+#define MDIO_AN_10GBT_STAT_LP5G0x0040  /* LP is 5GBT capable */
 #define MDIO_AN_10GBT_STAT_LPTRR   0x0200  /* LP training reset req. */
 #define MDIO_AN_10GBT_STAT_LPLTABLE0x0400  /* LP loop timing ability */
 #define MDIO_AN_10GBT_STAT_LP10G   0x0800  /* LP is 10GBT capable */
@@ -270,6 +284,10 @@
 #define MDIO_EEE_10GKX40x0020  /* 10G KX4 EEE cap */
 #define MDIO_EEE_10GKR 0x0040  /* 10G KR EEE cap */
 
+/* 2.5G/5G Extended abilities register. */
+#define MDIO_PMA_NG_EXTABLE_2_5GBT 0x0001  /* 2.5GBASET ability */
+#define MDIO_PMA_NG_EXTABLE_5GBT   0x0002  /* 5GBASET ability */
+
 /* LASI RX_ALARM control/status registers. */
 #define MDIO_PMA_LASI_RX_PHYXSLFLT 0x0001  /* PHY XS RX local fault */
 #define MDIO_PMA_LASI_RX_PCSLFLT   0x0008  /* PCS RX local fault */
-- 
2.39.2



[PATCH 5/5] net: phy: marvell10g: Adapt Marvell 10G PHY driver from Linux

2023-03-19 Thread Marek Vasut
Pull Marvell 10G PHY driver from Linux 6.1.y as of commit
d6d29292640d3 ("net: phy: marvell10g: select host interface configuration")
and heavily adapt to match U-Boot PHY framework. Support for
hwmon is removed as is much other functionality which could
not be tested, this results in much simpler driver which can
only bring the PHY up and set MAC type.

Signed-off-by: Marek Vasut 
---
Cc: "Ariel D'Alessandro" 
Cc: "Marek Behún" 
Cc: Joe Hershberger 
Cc: Marek Vasut 
Cc: Michael Trimarchi 
Cc: Nate Drude 
Cc: Ramon Fried 
Cc: Simon Glass 
Cc: Stefan Roese 
Cc: Tim Harvey 
Cc: Vladimir Oltean 
---
 drivers/net/phy/Kconfig  |   5 +
 drivers/net/phy/Makefile |   1 +
 drivers/net/phy/marvell10g.c | 605 +++
 3 files changed, 611 insertions(+)
 create mode 100644 drivers/net/phy/marvell10g.c

diff --git a/drivers/net/phy/Kconfig b/drivers/net/phy/Kconfig
index 6806e3c0903..24158776f52 100644
--- a/drivers/net/phy/Kconfig
+++ b/drivers/net/phy/Kconfig
@@ -174,6 +174,11 @@ config PHY_LXT
 config PHY_MARVELL
bool "Marvell Ethernet PHYs support"
 
+config PHY_MARVELL_10G
+   bool "Marvell Alaska 10Gbit PHYs"
+   help
+ Support for the Marvell Alaska MV88X3310 and compatible PHYs.
+
 config PHY_MESON_GXL
bool "Amlogic Meson GXL Internal PHY support"
 
diff --git a/drivers/net/phy/Makefile b/drivers/net/phy/Makefile
index 963d96e2bcb..85d17f109cd 100644
--- a/drivers/net/phy/Makefile
+++ b/drivers/net/phy/Makefile
@@ -20,6 +20,7 @@ obj-$(CONFIG_PHY_DAVICOM) += davicom.o
 obj-$(CONFIG_PHY_ET1011C) += et1011c.o
 obj-$(CONFIG_PHY_LXT) += lxt.o
 obj-$(CONFIG_PHY_MARVELL) += marvell.o
+obj-$(CONFIG_PHY_MARVELL_10G) += marvell10g.o
 obj-$(CONFIG_PHY_MICREL_KSZ8XXX) += micrel_ksz8xxx.o
 obj-$(CONFIG_PHY_MICREL_KSZ90X1) += micrel_ksz90x1.o
 obj-$(CONFIG_PHY_MESON_GXL) += meson-gxl.o
diff --git a/drivers/net/phy/marvell10g.c b/drivers/net/phy/marvell10g.c
new file mode 100644
index 000..9e64672f5ca
--- /dev/null
+++ b/drivers/net/phy/marvell10g.c
@@ -0,0 +1,605 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Marvell 10G 88x3310 PHY driver
+ *
+ * Based upon the ID registers, this PHY appears to be a mixture of IPs
+ * from two different companies.
+ *
+ * There appears to be several different data paths through the PHY which
+ * are automatically managed by the PHY.  The following has been determined
+ * via observation and experimentation for a setup using single-lane Serdes:
+ *
+ *   SGMII PHYXS -- BASE-T PCS -- 10G PMA -- AN -- Copper (for <= 1G)
+ *  10GBASE-KR PHYXS -- BASE-T PCS -- 10G PMA -- AN -- Copper (for 10G)
+ *  10GBASE-KR PHYXS -- BASE-R PCS -- Fiber
+ *
+ * With XAUI, observation shows:
+ *
+ *XAUI PHYXS -- 
+ *
+ * and no switching of the host interface mode occurs.
+ *
+ * If both the fiber and copper ports are connected, the first to gain
+ * link takes priority and the other port is completely locked out.
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define MV_PHY_ALASKA_NBT_QUIRK_MASK   0xfffe
+#define MV_PHY_ALASKA_NBT_QUIRK_REV(MARVELL_PHY_ID_88X3310 | 0xa)
+
+#define MV_VERSION(a, b, c, d) ((a) << 24 | (b) << 16 | (c) << 8 | (d))
+
+enum {
+   MV_PMA_FW_VER0  = 0xc011,
+   MV_PMA_FW_VER1  = 0xc012,
+   MV_PMA_21X0_PORT_CTRL   = 0xc04a,
+   MV_PMA_21X0_PORT_CTRL_SWRST = BIT(15),
+   MV_PMA_21X0_PORT_CTRL_MACTYPE_MASK  = 0x7,
+   MV_PMA_21X0_PORT_CTRL_MACTYPE_USXGMII   = 0x0,
+   MV_PMA_2180_PORT_CTRL_MACTYPE_DXGMII= 0x1,
+   MV_PMA_2180_PORT_CTRL_MACTYPE_QXGMII= 0x2,
+   MV_PMA_21X0_PORT_CTRL_MACTYPE_5GBASER   = 0x4,
+   MV_PMA_21X0_PORT_CTRL_MACTYPE_5GBASER_NO_SGMII_AN   = 0x5,
+   MV_PMA_21X0_PORT_CTRL_MACTYPE_10GBASER_RATE_MATCH   = 0x6,
+   MV_PMA_BOOT = 0xc050,
+   MV_PMA_BOOT_FATAL   = BIT(0),
+
+   MV_PCS_BASE_T   = 0x,
+   MV_PCS_BASE_R   = 0x1000,
+   MV_PCS_1000BASEX= 0x2000,
+
+   MV_PCS_CSCR1= 0x8000,
+   MV_PCS_CSCR1_ED_MASK= 0x0300,
+   MV_PCS_CSCR1_ED_OFF = 0x,
+   MV_PCS_CSCR1_ED_RX  = 0x0200,
+   MV_PCS_CSCR1_ED_NLP = 0x0300,
+   MV_PCS_CSCR1_MDIX_MASK  = 0x0060,
+   MV_PCS_CSCR1_MDIX_MDI   = 0x,
+   MV_PCS_CSCR1_MDIX_MDIX  = 0x0020,
+   MV_PCS_CSCR1_MDIX_AUTO  = 0x0060,
+
+   MV_PCS_DSC1 = 0x8003,
+   MV_PCS_DSC1_ENABLE  = BIT(9),
+   MV_PCS_DSC1_10GBT   = 0x01c0,
+   MV_PCS_DSC1_1GBR= 0x0038,
+   MV_PCS_DSC1_100BTX  = 0x0007,
+   MV_PCS_DSC2 = 0x8004,
+   MV_PCS_DSC2_2P5G= 0xf000,
+   MV_PCS_DSC2_5G  = 0x0f00,
+
+   MV_PCS_CSSR1= 0x8008,
+   MV_PCS_CSSR1_SPD1_MASK 

[PATCH 4/4] phy: renesas: Add Renesas Ethernet SERDES driver for R-Car S4-8

2023-03-19 Thread Marek Vasut
Add Renesas Ethernet SERDES driver for R-Car S4-8 (r8a779f0).
The datasheet describes initialization procedure without any information
about registers' name/bits. So, this is all black magic to initialize
the hardware. Especially, all channels should be initialized at once.

This driver is imported and adjusted from Linux 6.3-rc1 commit:
50133cd3e8dd1 ("phy: renesas: r8a779f0-eth-serdes: Remove retry code in 
.init()")

Signed-off-by: Marek Vasut 
---
Cc: Jim Liu 
Cc: Neil Armstrong 
Cc: Patrice Chotard 
Cc: Samuel Holland 
Cc: Sumit Garg 
Cc: Weijie Gao 
---
 drivers/phy/Kconfig |   1 +
 drivers/phy/Makefile|   1 +
 drivers/phy/renesas/Kconfig |   9 +
 drivers/phy/renesas/Makefile|   1 +
 drivers/phy/renesas/r8a779f0-ether-serdes.c | 384 
 5 files changed, 396 insertions(+)
 create mode 100644 drivers/phy/renesas/Kconfig
 create mode 100644 drivers/phy/renesas/Makefile
 create mode 100644 drivers/phy/renesas/r8a779f0-ether-serdes.c

diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
index cf4d5908d73..7a2d54f71d2 100644
--- a/drivers/phy/Kconfig
+++ b/drivers/phy/Kconfig
@@ -285,5 +285,6 @@ source "drivers/phy/rockchip/Kconfig"
 source "drivers/phy/cadence/Kconfig"
 source "drivers/phy/ti/Kconfig"
 source "drivers/phy/qcom/Kconfig"
+source "drivers/phy/renesas/Kconfig"
 
 endmenu
diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile
index a3b9f3c5b18..aca365d219c 100644
--- a/drivers/phy/Makefile
+++ b/drivers/phy/Makefile
@@ -41,3 +41,4 @@ obj-$(CONFIG_PHY_XILINX_ZYNQMP) += phy-zynqmp.o
 obj-y += cadence/
 obj-y += ti/
 obj-y += qcom/
+obj-y += renesas/
diff --git a/drivers/phy/renesas/Kconfig b/drivers/phy/renesas/Kconfig
new file mode 100644
index 000..0efb0f8f337
--- /dev/null
+++ b/drivers/phy/renesas/Kconfig
@@ -0,0 +1,9 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# Phy drivers for Renesas platforms
+
+config PHY_R8A779F0_ETHERNET_SERDES
+   tristate "Renesas R-Car S4-8 Ethernet SERDES driver"
+   depends on RCAR_64 && PHY
+   help
+ Support for Ethernet SERDES found on Renesas R-Car S4-8 SoCs.
diff --git a/drivers/phy/renesas/Makefile b/drivers/phy/renesas/Makefile
new file mode 100644
index 000..fd6b8d964e5
--- /dev/null
+++ b/drivers/phy/renesas/Makefile
@@ -0,0 +1 @@
+obj-$(CONFIG_PHY_R8A779F0_ETHERNET_SERDES) += r8a779f0-ether-serdes.o
diff --git a/drivers/phy/renesas/r8a779f0-ether-serdes.c 
b/drivers/phy/renesas/r8a779f0-ether-serdes.c
new file mode 100644
index 000..bd1fdd3a667
--- /dev/null
+++ b/drivers/phy/renesas/r8a779f0-ether-serdes.c
@@ -0,0 +1,384 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Renesas Ethernet SERDES device driver
+ *
+ * Copyright (C) 2022 Renesas Electronics Corporation
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define R8A779F0_ETH_SERDES_NUM3
+#define R8A779F0_ETH_SERDES_OFFSET 0x0400
+#define R8A779F0_ETH_SERDES_BANK_SELECT0x03fc
+#define R8A779F0_ETH_SERDES_TIMEOUT_US 10
+#define R8A779F0_ETH_SERDES_NUM_RETRY_LINKUP   3
+
+struct r8a779f0_eth_serdes_drv_data;
+struct r8a779f0_eth_serdes_channel {
+   struct r8a779f0_eth_serdes_drv_data *dd;
+   struct phy *phy;
+   void __iomem *addr;
+   phy_interface_t phy_interface;
+   int speed;
+   int index;
+};
+
+struct r8a779f0_eth_serdes_drv_data {
+   void __iomem *addr;
+   struct reset_ctl *reset;
+   struct r8a779f0_eth_serdes_channel channel[R8A779F0_ETH_SERDES_NUM];
+   bool initialized;
+};
+
+/*
+ * The datasheet describes initialization procedure without any information
+ * about registers' name/bits. So, this is all black magic to initialize
+ * the hardware.
+ */
+static void r8a779f0_eth_serdes_write32(void __iomem *addr, u32 offs, u32 
bank, u32 data)
+{
+   writel(bank, addr + R8A779F0_ETH_SERDES_BANK_SELECT);
+   writel(data, addr + offs);
+}
+
+static int
+r8a779f0_eth_serdes_reg_wait(struct r8a779f0_eth_serdes_channel *channel,
+u32 offs, u32 bank, u32 mask, u32 expected)
+{
+   u32 val = 0;
+   int ret;
+
+   writel(bank, channel->addr + R8A779F0_ETH_SERDES_BANK_SELECT);
+
+   ret = readl_poll_timeout(channel->addr + offs, val,
+(val & mask) == expected,
+R8A779F0_ETH_SERDES_TIMEOUT_US);
+   if (ret)
+   dev_dbg(channel->phy->dev,
+   "%s: index %d, offs %x, bank %x, mask %x, expected 
%x\n",
+__func__, channel->index, offs, bank, mask, expected);
+
+   return ret;
+}
+
+static int
+r8a779f0_eth_serdes_common_init_ram(struct r8a779f0_eth_serdes_drv_data *dd)
+{
+   struct r8a779f0_eth_serdes_channel *channel;
+   

[PATCH 3/4] phy: Add .set_mode and .set_speed callbacks

2023-03-19 Thread Marek Vasut
Add two new callbacks matching the Linux ones. The .set_mode is used to set
PHY mode and submode, where mode is either USB, Ethernet, and so on, while
submode is e.g. for Ethernet case RGMII, RMII, and so on. The .set_speed is
used to configure link speed into the PHY. Unlike the existing configure
callback, which is used to pass arbitrary custom information to the PHY,
these two callbacks are used to pass standardized set of information to
the PHY.

Signed-off-by: Marek Vasut 
---
Cc: Jim Liu 
Cc: Neil Armstrong 
Cc: Patrice Chotard 
Cc: Samuel Holland 
Cc: Sumit Garg 
Cc: Weijie Gao 
---
 drivers/phy/phy-uclass.c | 22 
 include/generic-phy.h| 77 
 2 files changed, 99 insertions(+)

diff --git a/drivers/phy/phy-uclass.c b/drivers/phy/phy-uclass.c
index 3fef5135a9c..83e4b63079d 100644
--- a/drivers/phy/phy-uclass.c
+++ b/drivers/phy/phy-uclass.c
@@ -351,6 +351,28 @@ int generic_phy_configure(struct phy *phy, void *params)
return ops->configure ? ops->configure(phy, params) : 0;
 }
 
+int generic_phy_set_mode(struct phy *phy, enum phy_mode mode, int submode)
+{
+   struct phy_ops const *ops;
+
+   if (!generic_phy_valid(phy))
+   return 0;
+   ops = phy_dev_ops(phy->dev);
+
+   return ops->set_mode ? ops->set_mode(phy, mode, submode) : 0;
+}
+
+int generic_phy_set_speed(struct phy *phy, int speed)
+{
+   struct phy_ops const *ops;
+
+   if (!generic_phy_valid(phy))
+   return 0;
+   ops = phy_dev_ops(phy->dev);
+
+   return ops->set_speed ? ops->set_speed(phy, speed) : 0;
+}
+
 int generic_phy_get_bulk(struct udevice *dev, struct phy_bulk *bulk)
 {
int i, ret, count;
diff --git a/include/generic-phy.h b/include/generic-phy.h
index 8dca21b1283..bee4de8a0ba 100644
--- a/include/generic-phy.h
+++ b/include/generic-phy.h
@@ -11,6 +11,29 @@
 
 struct ofnode_phandle_args;
 
+enum phy_mode {
+   PHY_MODE_INVALID,
+   PHY_MODE_USB_HOST,
+   PHY_MODE_USB_HOST_LS,
+   PHY_MODE_USB_HOST_FS,
+   PHY_MODE_USB_HOST_HS,
+   PHY_MODE_USB_HOST_SS,
+   PHY_MODE_USB_DEVICE,
+   PHY_MODE_USB_DEVICE_LS,
+   PHY_MODE_USB_DEVICE_FS,
+   PHY_MODE_USB_DEVICE_HS,
+   PHY_MODE_USB_DEVICE_SS,
+   PHY_MODE_USB_OTG,
+   PHY_MODE_UFS_HS_A,
+   PHY_MODE_UFS_HS_B,
+   PHY_MODE_PCIE,
+   PHY_MODE_ETHERNET,
+   PHY_MODE_MIPI_DPHY,
+   PHY_MODE_SATA,
+   PHY_MODE_LVDS,
+   PHY_MODE_DP
+};
+
 /**
  * struct phy - A handle to (allowing control of) a single phy port.
  *
@@ -136,6 +159,32 @@ struct phy_ops {
 * Return: 0 if OK, or a negative error code
 */
int (*configure)(struct phy *phy, void *params);
+
+   /**
+* set_mode - set PHY device mode
+*
+* @phy:PHY port to be configured
+* @mode: PHY mode
+* @submode: PHY submode
+*
+* Configure PHY mode (e.g. USB, Ethernet, ...) and submode
+* (e.g. for Ethernet this can be RGMII).
+*
+* Return: 0 if OK, or a negative error code
+*/
+   int (*set_mode)(struct phy *phy, enum phy_mode mode, int submode);
+
+   /**
+* set_speed - set PHY device speed
+*
+* @phy:PHY port to be configured
+* @speed: PHY speed
+*
+* Configure PHY speed (e.g. for Ethernet, this could be 10 or 100 ...).
+*
+* Return: 0 if OK, or a negative error code
+*/
+   int (*set_speed)(struct phy *phy, int speed);
 };
 
 /**
@@ -206,6 +255,24 @@ int generic_phy_power_off(struct phy *phy);
  */
 int generic_phy_configure(struct phy *phy, void *params);
 
+/**
+ * generic_phy_set_mode() - set PHY device mode
+ *
+ * @phy:   PHY port to be configured
+ * @mode: PHY mode
+ * @submode: PHY submode
+ * Return: 0 if OK, or a negative error code
+ */
+int generic_phy_set_mode(struct phy *phy, enum phy_mode mode, int submode);
+
+/**
+ * generic_phy_set_speed() - set PHY device speed
+ *
+ * @phy:   PHY port to be configured
+ * @speed: PHY speed
+ * Return: 0 if OK, or a negative error code
+ */
+int generic_phy_set_speed(struct phy *phy, int speed);
 
 /**
  * generic_phy_get_by_index() - Get a PHY device by integer index.
@@ -394,6 +461,16 @@ static inline int generic_phy_configure(struct phy *phy, 
void *params)
return 0;
 }
 
+static inline int generic_phy_set_mode(struct phy *phy, enum phy_mode mode, 
int submode)
+{
+   return 0;
+}
+
+static inline int generic_phy_set_speed(struct phy *phy, int speed)
+{
+   return 0;
+}
+
 static inline int generic_phy_get_by_index(struct udevice *user, int index,
 struct phy *phy)
 {
-- 
2.39.2



[PATCH 1/4] phy: Add empty generic_phy_configure() implementation for PHY disabled case

2023-03-19 Thread Marek Vasut
In case PHY is not enabled, the generic_phy_configure() implementation is
missing. Add an empty one so that the list of empty functions is complete.

Fixes: f8da8a82c57 ("generic-phy: add configure op")
Signed-off-by: Marek Vasut 
---
Cc: Jim Liu 
Cc: Neil Armstrong 
Cc: Patrice Chotard 
Cc: Samuel Holland 
Cc: Sumit Garg 
Cc: Weijie Gao 
---
 include/generic-phy.h | 5 +
 1 file changed, 5 insertions(+)

diff --git a/include/generic-phy.h b/include/generic-phy.h
index f8eddeff67a..fa5f6fa3636 100644
--- a/include/generic-phy.h
+++ b/include/generic-phy.h
@@ -389,6 +389,11 @@ static inline int generic_phy_power_off(struct phy *phy)
return 0;
 }
 
+static inline int generic_phy_configure(struct phy *phy, void *params)
+{
+   return 0;
+}
+
 static inline int generic_phy_get_by_index(struct udevice *user, int index,
 struct phy *phy)
 {
-- 
2.39.2



[PATCH 2/4] phy: Fix kerneldoc alignment

2023-03-19 Thread Marek Vasut
Insert missing space in front of asterisk to avoid checkpatch warning.
Replace 'beeing' with 'being' as well, to fix another checkpatch warning.

Signed-off-by: Marek Vasut 
---
Cc: Jim Liu 
Cc: Neil Armstrong 
Cc: Patrice Chotard 
Cc: Samuel Holland 
Cc: Sumit Garg 
Cc: Weijie Gao 
---
 include/generic-phy.h | 108 +-
 1 file changed, 54 insertions(+), 54 deletions(-)

diff --git a/include/generic-phy.h b/include/generic-phy.h
index fa5f6fa3636..8dca21b1283 100644
--- a/include/generic-phy.h
+++ b/include/generic-phy.h
@@ -69,72 +69,72 @@ struct phy_ops {
int (*init)(struct phy *phy);
 
/**
-   * exit - de-initialize the PHY device
-   *
-   * Hardware de-intialization should be done here. Every step done in
-   * init() should be undone here.
-   * This could be used to suspend the phy to reduce power consumption or
-   * to put the phy in a known condition before booting the OS (though it
-   * is NOT called automatically before booting the OS)
-   * If power_off() is not implemented, it must power down the phy.
-   *
-   * @phy: PHY port to be de-initialized
-   * Return: 0 if OK, or a negative error code
-   */
+* exit - de-initialize the PHY device
+*
+* Hardware de-intialization should be done here. Every step done in
+* init() should be undone here.
+* This could be used to suspend the phy to reduce power consumption or
+* to put the phy in a known condition before booting the OS (though it
+* is NOT called automatically before booting the OS)
+* If power_off() is not implemented, it must power down the phy.
+*
+* @phy:PHY port to be de-initialized
+* Return: 0 if OK, or a negative error code
+*/
int (*exit)(struct phy *phy);
 
/**
-   * reset - resets a PHY device without shutting down
-   *
-   * @phy: PHY port to be reset
-   *
-   * During runtime, the PHY may need to be reset in order to
-   * re-establish connection etc without being shut down or exit.
-   *
-   * Return: 0 if OK, or a negative error code
-   */
+* reset - resets a PHY device without shutting down
+*
+* @phy:PHY port to be reset
+*
+* During runtime, the PHY may need to be reset in order to
+* re-establish connection etc without being shut down or exit.
+*
+* Return: 0 if OK, or a negative error code
+*/
int (*reset)(struct phy *phy);
 
/**
-   * power_on - power on a PHY device
-   *
-   * @phy: PHY port to be powered on
-   *
-   * During runtime, the PHY may need to be powered on or off several
-   * times. This function is used to power on the PHY. It relies on the
-   * setup done in init(). If init() is not implemented, it must take care
-   * of setting up the context (PLLs, ...)
-   *
-   * Return: 0 if OK, or a negative error code
-   */
+* power_on - power on a PHY device
+*
+* @phy:PHY port to be powered on
+*
+* During runtime, the PHY may need to be powered on or off several
+* times. This function is used to power on the PHY. It relies on the
+* setup done in init(). If init() is not implemented, it must take care
+* of setting up the context (PLLs, ...)
+*
+* Return: 0 if OK, or a negative error code
+*/
int (*power_on)(struct phy *phy);
 
/**
-   * power_off - power off a PHY device
-   *
-   * @phy: PHY port to be powered off
-   *
-   * During runtime, the PHY may need to be powered on or off several
-   * times. This function is used to power off the PHY. Except if
-   * init()/deinit() are not implemented, it must not de-initialize
-   * everything.
-   *
-   * Return: 0 if OK, or a negative error code
-   */
+* power_off - power off a PHY device
+*
+* @phy:PHY port to be powered off
+*
+* During runtime, the PHY may need to be powered on or off several
+* times. This function is used to power off the PHY. Except if
+* init()/deinit() are not implemented, it must not de-initialize
+* everything.
+*
+* Return: 0 if OK, or a negative error code
+*/
int (*power_off)(struct phy *phy);
 
/**
-   * configure - configure a PHY device
-   *
-   * @phy: PHY port to be configured
-   * @params: PHY Parameters, underlying data is specific to the PHY 
function
-   *
-   * During runtime, the PHY may need to be configured for it's main 
function.
-   * This function configures the PHY for it's main function following
-   * power_on/off() after beeing initialized.
-   *
-   * Return: 0 if OK, or a negative 

[PATCH 1/5] net: phy: marvell: Import and use marvell_phy.h from Linux

2023-03-19 Thread Marek Vasut
Import marvell_phy.h from Linux 5.14.y as of commit
a5de4be06 ("net: phy: marvell10g: fix differentiation of 88X3310 from 
88X3340")
and use it in marvell PHY driver instead of current ad-hoc macros.
Two of the PHY IDs are unknown to Linux, 88E1149S and 88E1680, for
those two, only sync the length of the hexadecimal number to 8 digits.

No functional change.

Signed-off-by: Marek Vasut 
---
Cc: "Ariel D'Alessandro" 
Cc: "Marek Behún" 
Cc: Joe Hershberger 
Cc: Marek Vasut 
Cc: Michael Trimarchi 
Cc: Nate Drude 
Cc: Ramon Fried 
Cc: Simon Glass 
Cc: Stefan Roese 
Cc: Tim Harvey 
Cc: Vladimir Oltean 
---
 drivers/net/phy/marvell.c | 45 +++--
 include/marvell_phy.h | 47 +++
 2 files changed, 70 insertions(+), 22 deletions(-)
 create mode 100644 include/marvell_phy.h

diff --git a/drivers/net/phy/marvell.c b/drivers/net/phy/marvell.c
index 8992be6e89e..0a90f710dfe 100644
--- a/drivers/net/phy/marvell.c
+++ b/drivers/net/phy/marvell.c
@@ -7,6 +7,7 @@
  */
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -695,8 +696,8 @@ static int m88e1680_config(struct phy_device *phydev)
 
 U_BOOT_PHY_DRIVER(m88e1011s) = {
.name = "Marvell 88E1011S",
-   .uid = 0x1410c60,
-   .mask = 0xff0,
+   .uid = MARVELL_PHY_ID_88E1101,
+   .mask = MARVELL_PHY_ID_MASK,
.features = PHY_GBIT_FEATURES,
.config = _config,
.startup = _startup,
@@ -705,8 +706,8 @@ U_BOOT_PHY_DRIVER(m88e1011s) = {
 
 U_BOOT_PHY_DRIVER(m88es) = {
.name = "Marvell 88ES",
-   .uid = 0x1410cc0,
-   .mask = 0xff0,
+   .uid = MARVELL_PHY_ID_88E,
+   .mask = MARVELL_PHY_ID_MASK,
.features = PHY_GBIT_FEATURES,
.config = _config,
.startup = _startup,
@@ -715,8 +716,8 @@ U_BOOT_PHY_DRIVER(m88es) = {
 
 U_BOOT_PHY_DRIVER(m88e1118) = {
.name = "Marvell 88E1118",
-   .uid = 0x1410e10,
-   .mask = 0xff0,
+   .uid = MARVELL_PHY_ID_88E1118,
+   .mask = MARVELL_PHY_ID_MASK,
.features = PHY_GBIT_FEATURES,
.config = _config,
.startup = _startup,
@@ -725,8 +726,8 @@ U_BOOT_PHY_DRIVER(m88e1118) = {
 
 U_BOOT_PHY_DRIVER(m88e1118r) = {
.name = "Marvell 88E1118R",
-   .uid = 0x1410e40,
-   .mask = 0xff0,
+   .uid = MARVELL_PHY_ID_88E1116R,
+   .mask = MARVELL_PHY_ID_MASK,
.features = PHY_GBIT_FEATURES,
.config = _config,
.startup = _startup,
@@ -735,8 +736,8 @@ U_BOOT_PHY_DRIVER(m88e1118r) = {
 
 U_BOOT_PHY_DRIVER(m88e1121r) = {
.name = "Marvell 88E1121R",
-   .uid = 0x1410cb0,
-   .mask = 0xff0,
+   .uid = MARVELL_PHY_ID_88E1121R,
+   .mask = MARVELL_PHY_ID_MASK,
.features = PHY_GBIT_FEATURES,
.config = _config,
.startup = _startup,
@@ -745,8 +746,8 @@ U_BOOT_PHY_DRIVER(m88e1121r) = {
 
 U_BOOT_PHY_DRIVER(m88e1145) = {
.name = "Marvell 88E1145",
-   .uid = 0x1410cd0,
-   .mask = 0xff0,
+   .uid = MARVELL_PHY_ID_88E1145,
+   .mask = MARVELL_PHY_ID_MASK,
.features = PHY_GBIT_FEATURES,
.config = _config,
.startup = _startup,
@@ -755,8 +756,8 @@ U_BOOT_PHY_DRIVER(m88e1145) = {
 
 U_BOOT_PHY_DRIVER(m88e1149s) = {
.name = "Marvell 88E1149S",
-   .uid = 0x1410ca0,
-   .mask = 0xff0,
+   .uid = 0x01410ca0,
+   .mask = MARVELL_PHY_ID_MASK,
.features = PHY_GBIT_FEATURES,
.config = _config,
.startup = _startup,
@@ -765,8 +766,8 @@ U_BOOT_PHY_DRIVER(m88e1149s) = {
 
 U_BOOT_PHY_DRIVER(m88e1240) = {
.name = "Marvell 88E1240",
-   .uid = 0x1410e30,
-   .mask = 0xff0,
+   .uid = MARVELL_PHY_ID_88E1240,
+   .mask = MARVELL_PHY_ID_MASK,
.features = PHY_GBIT_FEATURES,
.config = _config,
.startup = _startup,
@@ -775,8 +776,8 @@ U_BOOT_PHY_DRIVER(m88e1240) = {
 
 U_BOOT_PHY_DRIVER(m88e151x) = {
.name = "Marvell 88E151x",
-   .uid = 0x1410dd0,
-   .mask = 0xff0,
+   .uid = MARVELL_PHY_ID_88E1510,
+   .mask = MARVELL_PHY_ID_MASK,
.features = PHY_GBIT_FEATURES,
.config = _config,
.startup = _startup,
@@ -787,8 +788,8 @@ U_BOOT_PHY_DRIVER(m88e151x) = {
 
 U_BOOT_PHY_DRIVER(m88e1310) = {
.name = "Marvell 88E1310",
-   .uid = 0x01410e90,
-   .mask = 0xff0,
+   .uid = MARVELL_PHY_ID_88E1318S,
+   .mask = MARVELL_PHY_ID_MASK,
.features = PHY_GBIT_FEATURES,
.config = _config,
.startup = _startup,
@@ -797,8 +798,8 @@ U_BOOT_PHY_DRIVER(m88e1310) = {
 
 U_BOOT_PHY_DRIVER(m88e1680) = {
.name = "Marvell 88E1680",
-   .uid = 0x1410ed0,
-   .mask = 0xff0,
+   .uid = 0x01410ed0,
+   .mask = MARVELL_PHY_ID_MASK,
.features = PHY_GBIT_FEATURES,
.config = _config,
.startup = _startup,
diff --git a/include/marvell_phy.h b/include/marvell_phy.h
new file 

[PATCH 2/5] net: phy: Add phy_modify_mmd() and phy_modify_mmd_changed() from Linux

2023-03-19 Thread Marek Vasut
Add phy_modify_mmd()/phy_modify_mmd_changed() from Linux 5.1.y as of commit
b8554d4f7288f ("net: phy: add register modifying helpers returning 1 on change")
This is used by the upcoming Marvell 10G PHY driver.

Signed-off-by: Marek Vasut 
---
Cc: "Ariel D'Alessandro" 
Cc: "Marek Behún" 
Cc: Joe Hershberger 
Cc: Marek Vasut 
Cc: Michael Trimarchi 
Cc: Nate Drude 
Cc: Ramon Fried 
Cc: Simon Glass 
Cc: Stefan Roese 
Cc: Tim Harvey 
Cc: Vladimir Oltean 
---
 drivers/net/phy/phy.c | 54 +++
 include/phy.h |  4 
 2 files changed, 58 insertions(+)

diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index f720d0a7920..0eeb0cb3a85 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -1158,6 +1158,60 @@ int phy_clear_bits_mmd(struct phy_device *phydev, int 
devad, u32 regnum, u16 val
return 0;
 }
 
+/**
+ * phy_modify_mmd_changed - Function for modifying a register on MMD
+ * @phydev: the phy_device struct
+ * @devad: the MMD containing register to modify
+ * @regnum: register number to modify
+ * @mask: bit mask of bits to clear
+ * @set: new value of bits set in mask to write to @regnum
+ *
+ * NOTE: MUST NOT be called from interrupt context,
+ * because the bus read/write functions may wait for an interrupt
+ * to conclude the operation.
+ *
+ * Returns negative errno, 0 if there was no change, and 1 in case of change
+ */
+int phy_modify_mmd_changed(struct phy_device *phydev, int devad, u32 regnum,
+  u16 mask, u16 set)
+{
+   int new, ret;
+
+   ret = phy_read_mmd(phydev, devad, regnum);
+   if (ret < 0)
+   return ret;
+
+   new = (ret & ~mask) | set;
+   if (new == ret)
+   return 0;
+
+   ret = phy_write_mmd(phydev, devad, regnum, new);
+
+   return ret < 0 ? ret : 1;
+}
+
+/**
+ * phy_modify_mmd - Convenience function for modifying a register on MMD
+ * @phydev: the phy_device struct
+ * @devad: the MMD containing register to modify
+ * @regnum: register number to modify
+ * @mask: bit mask of bits to clear
+ * @set: new value of bits set in mask to write to @regnum
+ *
+ * NOTE: MUST NOT be called from interrupt context,
+ * because the bus read/write functions may wait for an interrupt
+ * to conclude the operation.
+ */
+int phy_modify_mmd(struct phy_device *phydev, int devad, u32 regnum,
+  u16 mask, u16 set)
+{
+   int ret;
+
+   ret = phy_modify_mmd_changed(phydev, devad, regnum, mask, set);
+
+   return ret < 0 ? ret : 0;
+}
+
 bool phy_interface_is_ncsi(void)
 {
 #ifdef CONFIG_PHY_NCSI
diff --git a/include/phy.h b/include/phy.h
index 4a9de461152..34675b2c9c0 100644
--- a/include/phy.h
+++ b/include/phy.h
@@ -289,6 +289,10 @@ int phy_read_mmd(struct phy_device *phydev, int devad, int 
regnum);
 int phy_write_mmd(struct phy_device *phydev, int devad, int regnum, u16 val);
 int phy_set_bits_mmd(struct phy_device *phydev, int devad, u32 regnum, u16 
val);
 int phy_clear_bits_mmd(struct phy_device *phydev, int devad, u32 regnum, u16 
val);
+int phy_modify_mmd_changed(struct phy_device *phydev, int devad, u32 regnum,
+  u16 mask, u16 set);
+int phy_modify_mmd(struct phy_device *phydev, int devad, u32 regnum,
+  u16 mask, u16 set);
 
 int phy_startup(struct phy_device *phydev);
 int phy_config(struct phy_device *phydev);
-- 
2.39.2



[PATCH 3/5] net: phy: Add phy_read_mmd_poll_timeout() from Linux

2023-03-19 Thread Marek Vasut
Add phy_read_mmd_poll_timeout() from Linux 5.7.y as of commit
bd971ff0b7392 ("net: phy: introduce phy_read_mmd_poll_timeout macro")
This is used by the upcoming Marvell 10G PHY driver.

Signed-off-by: Marek Vasut 
---
Cc: "Ariel D'Alessandro" 
Cc: "Marek Behún" 
Cc: Joe Hershberger 
Cc: Marek Vasut 
Cc: Michael Trimarchi 
Cc: Nate Drude 
Cc: Ramon Fried 
Cc: Simon Glass 
Cc: Stefan Roese 
Cc: Tim Harvey 
Cc: Vladimir Oltean 
---
 include/phy.h | 31 +++
 1 file changed, 31 insertions(+)

diff --git a/include/phy.h b/include/phy.h
index 34675b2c9c0..a837fed7235 100644
--- a/include/phy.h
+++ b/include/phy.h
@@ -282,6 +282,37 @@ static inline ofnode phy_get_ofnode(struct phy_device 
*phydev)
return dev_ofnode(phydev->dev);
 }
 
+/**
+ * phy_read_mmd_poll_timeout - Periodically poll a PHY register until a
+ * condition is met or a timeout occurs
+ *
+ * @phydev: The phy_device struct
+ * @devaddr: The MMD to read from
+ * @regnum: The register on the MMD to read
+ * @val: Variable to read the register into
+ * @cond: Break condition (usually involving @val)
+ * @sleep_us: Maximum time to sleep between reads in us (0
+ *tight-loops).  Should be less than ~20ms since usleep_range
+ *is used (see Documentation/timers/timers-howto.rst).
+ * @timeout_us: Timeout in us, 0 means never timeout
+ * @sleep_before_read: if it is true, sleep @sleep_us before read.
+ * Returns 0 on success and -ETIMEDOUT upon a timeout. In either
+ * case, the last read value at @args is stored in @val. Must not
+ * be called from atomic context if sleep_us or timeout_us are used.
+ */
+#define phy_read_mmd_poll_timeout(phydev, devaddr, regnum, val, cond, \
+ sleep_us, timeout_us, sleep_before_read) \
+({ \
+   int __ret = read_poll_timeout(phy_read_mmd, val, (cond) || val < 0, \
+ sleep_us, timeout_us, \
+ phydev, devaddr, regnum); \
+   if (val <  0) \
+   __ret = val; \
+   if (__ret) \
+   dev_err(phydev->dev, "%s failed: %d\n", __func__, __ret); \
+   __ret; \
+})
+
 int phy_read(struct phy_device *phydev, int devad, int regnum);
 int phy_write(struct phy_device *phydev, int devad, int regnum, u16 val);
 void phy_mmd_start_indirect(struct phy_device *phydev, int devad, int regnum);
-- 
2.39.2



[PATCH 14/41] net: phy: davicom: Convert to U_BOOT_PHY_DRIVER()

2023-03-19 Thread Marek Vasut
Convert PHY driver to U_BOOT_PHY_DRIVER() macro and drop phy_register() init 
call.

Converted using sed
"s@^static struct phy_driver \(.*\)_driver = \+{@U_BOOT_PHY_DRIVER(\L\1) = {"

Signed-off-by: Marek Vasut 
---
Cc: "Ariel D'Alessandro" 
Cc: "Cédric Le Goater" 
Cc: "Marek Behún" 
Cc: Alex Nemirovsky 
Cc: Haolin Li 
Cc: Heinrich Schuchardt 
Cc: Joe Hershberger 
Cc: Joel Stanley 
Cc: Josua Mayer 
Cc: Marek Vasut 
Cc: Michael Trimarchi 
Cc: Michal Simek 
Cc: Nate Drude 
Cc: Neil Armstrong 
Cc: Radu Pirea 
Cc: Ramon Fried 
Cc: Samuel Mendoza-Jonas 
Cc: Stefan Roese 
Cc: T Karthik Reddy 
Cc: Tim Harvey 
Cc: Vladimir Oltean 
Cc: u-boot-amlo...@groups.io
---
 drivers/net/phy/davicom.c | 9 +
 drivers/net/phy/phy.c | 3 ---
 include/phy.h | 1 -
 3 files changed, 1 insertion(+), 12 deletions(-)

diff --git a/drivers/net/phy/davicom.c b/drivers/net/phy/davicom.c
index 4666497d44f..31ffa1ac7a9 100644
--- a/drivers/net/phy/davicom.c
+++ b/drivers/net/phy/davicom.c
@@ -69,7 +69,7 @@ static int dm9161_startup(struct phy_device *phydev)
return dm9161_parse_status(phydev);
 }
 
-static struct phy_driver DM9161_driver = {
+U_BOOT_PHY_DRIVER(dm9161) = {
.name = "Davicom DM9161E",
.uid = 0x181b880,
.mask = 0xff0,
@@ -78,10 +78,3 @@ static struct phy_driver DM9161_driver = {
.startup = _startup,
.shutdown = _shutdown,
 };
-
-int phy_davicom_init(void)
-{
-   phy_register(_driver);
-
-   return 0;
-}
diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index d595290dd4b..6d7e07c25a5 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -517,9 +517,6 @@ int phy_init(void)
 #ifdef CONFIG_MV88E61XX_SWITCH
phy_mv88e61xx_init();
 #endif
-#ifdef CONFIG_PHY_DAVICOM
-   phy_davicom_init();
-#endif
 #ifdef CONFIG_PHY_ET1011C
phy_et1011c_init();
 #endif
diff --git a/include/phy.h b/include/phy.h
index 797139bf681..51c2ddb7e4e 100644
--- a/include/phy.h
+++ b/include/phy.h
@@ -316,7 +316,6 @@ int gen10g_shutdown(struct phy_device *phydev);
 int gen10g_discover_mmds(struct phy_device *phydev);
 
 int phy_mv88e61xx_init(void);
-int phy_davicom_init(void);
 int phy_et1011c_init(void);
 int phy_lxt_init(void);
 int phy_marvell_init(void);
-- 
2.39.2



[PATCH 37/41] net: phy: gen10g: Convert to U_BOOT_PHY_DRIVER()

2023-03-19 Thread Marek Vasut
Convert PHY driver to U_BOOT_PHY_DRIVER() macro and drop phy_register() init 
call.

Converted using sed
"s@^static struct phy_driver \(.*\)_driver = \+{@U_BOOT_PHY_DRIVER(\L\1) = {"

Signed-off-by: Marek Vasut 
---
Cc: "Ariel D'Alessandro" 
Cc: "Cédric Le Goater" 
Cc: "Marek Behún" 
Cc: Alex Nemirovsky 
Cc: Haolin Li 
Cc: Heinrich Schuchardt 
Cc: Joe Hershberger 
Cc: Joel Stanley 
Cc: Josua Mayer 
Cc: Marek Vasut 
Cc: Michael Trimarchi 
Cc: Michal Simek 
Cc: Nate Drude 
Cc: Neil Armstrong 
Cc: Radu Pirea 
Cc: Ramon Fried 
Cc: Samuel Mendoza-Jonas 
Cc: Stefan Roese 
Cc: T Karthik Reddy 
Cc: Tim Harvey 
Cc: Vladimir Oltean 
Cc: u-boot-amlo...@groups.io
---
 drivers/net/phy/generic_10g.c | 2 +-
 drivers/net/phy/phy.c | 2 +-
 include/phy.h | 4 
 3 files changed, 2 insertions(+), 6 deletions(-)

diff --git a/drivers/net/phy/generic_10g.c b/drivers/net/phy/generic_10g.c
index b4384e1f781..34ac51ea070 100644
--- a/drivers/net/phy/generic_10g.c
+++ b/drivers/net/phy/generic_10g.c
@@ -80,7 +80,7 @@ int gen10g_config(struct phy_device *phydev)
return gen10g_discover_mmds(phydev);
 }
 
-struct phy_driver gen10g_driver = {
+U_BOOT_PHY_DRIVER(gen10g) = {
.uid= 0x,
.mask   = 0x,
.name   = "Generic 10G PHY",
diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index b1e9861c6f3..bd9c576f459 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -566,7 +566,7 @@ static struct phy_driver *generic_for_phy(struct phy_device 
*phydev)
 {
 #ifdef CONFIG_PHYLIB_10G
if (phydev->is_c45)
-   return _driver;
+   return ll_entry_get(struct phy_driver, gen10g, phy_driver);
 #endif
 
return ll_entry_get(struct phy_driver, genphy, phy_driver);
diff --git a/include/phy.h b/include/phy.h
index df2586f89ea..5f4967cb150 100644
--- a/include/phy.h
+++ b/include/phy.h
@@ -173,10 +173,6 @@ struct fixed_link {
int asym_pause;
 };
 
-#ifdef CONFIG_PHYLIB_10G
-extern struct phy_driver gen10g_driver;
-#endif
-
 /**
  * phy_init() - Initializes the PHY drivers
  * This function registers all available PHY drivers
-- 
2.39.2



[PATCH 3/3] net: phy: Synchronize PHY interface modes with Linux

2023-03-19 Thread Marek Vasut
Synchronize PHY interface modes with Linux next 6.2.y commit:
0194b64578e90 ("net: phy: improve phy_read_poll_timeout")

Retain LX2160A/LX2162A PHY modes as those are not yet supported
by the Linux kernel, but isolate those with ifdeffery.

Isolate NCSI which are also not supported by Linux kernel. Note
that the ifdeffery cannot be avoided with IS_ENABLED() here due
to compilation of the entire conditional, which would fail in
case NCSI symbols are not available.

Signed-off-by: Marek Vasut 
---
Cc: "Ariel D'Alessandro" 
Cc: "Marek Behún" 
Cc: Joe Hershberger 
Cc: Marek Vasut 
Cc: Ramon Fried 
Cc: Stefan Roese 
Cc: Tim Harvey 
Cc: Vladimir Oltean 
---
 drivers/net/phy/phy.c   |  4 +++
 include/phy_interface.h | 68 +
 2 files changed, 53 insertions(+), 19 deletions(-)

diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index 9b0e497f223..f720d0a7920 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -1160,7 +1160,11 @@ int phy_clear_bits_mmd(struct phy_device *phydev, int 
devad, u32 regnum, u16 val
 
 bool phy_interface_is_ncsi(void)
 {
+#ifdef CONFIG_PHY_NCSI
struct eth_pdata *pdata = dev_get_plat(eth_get_dev());
 
return pdata->phy_interface == PHY_INTERFACE_MODE_NCSI;
+#else
+   return 0;
+#endif
 }
diff --git a/include/phy_interface.h b/include/phy_interface.h
index 52af7e612b6..31be3228c7c 100644
--- a/include/phy_interface.h
+++ b/include/phy_interface.h
@@ -14,65 +14,95 @@
 
 typedef enum {
PHY_INTERFACE_MODE_NA, /* don't touch */
+   PHY_INTERFACE_MODE_INTERNAL,
PHY_INTERFACE_MODE_MII,
PHY_INTERFACE_MODE_GMII,
PHY_INTERFACE_MODE_SGMII,
-   PHY_INTERFACE_MODE_SGMII_2500,
-   PHY_INTERFACE_MODE_QSGMII,
PHY_INTERFACE_MODE_TBI,
+   PHY_INTERFACE_MODE_REVMII,
PHY_INTERFACE_MODE_RMII,
+   PHY_INTERFACE_MODE_REVRMII,
PHY_INTERFACE_MODE_RGMII,
PHY_INTERFACE_MODE_RGMII_ID,
PHY_INTERFACE_MODE_RGMII_RXID,
PHY_INTERFACE_MODE_RGMII_TXID,
PHY_INTERFACE_MODE_RTBI,
+   PHY_INTERFACE_MODE_SMII,
+   PHY_INTERFACE_MODE_XGMII,
+   PHY_INTERFACE_MODE_XLGMII,
+   PHY_INTERFACE_MODE_MOCA,
+   PHY_INTERFACE_MODE_QSGMII,
+   PHY_INTERFACE_MODE_TRGMII,
+   PHY_INTERFACE_MODE_100BASEX,
PHY_INTERFACE_MODE_1000BASEX,
PHY_INTERFACE_MODE_2500BASEX,
-   PHY_INTERFACE_MODE_XGMII,
-   PHY_INTERFACE_MODE_XAUI,
-   PHY_INTERFACE_MODE_RXAUI,
PHY_INTERFACE_MODE_5GBASER,
-   PHY_INTERFACE_MODE_SFI,
-   PHY_INTERFACE_MODE_INTERNAL,
+   PHY_INTERFACE_MODE_RXAUI,
+   PHY_INTERFACE_MODE_XAUI,
+   /* 10GBASE-R, XFI, SFI - single lane 10G Serdes */
+   PHY_INTERFACE_MODE_10GBASER,
+   PHY_INTERFACE_MODE_25GBASER,
+   PHY_INTERFACE_MODE_USXGMII,
+   /* 10GBASE-KR - with Clause 73 AN */
+   PHY_INTERFACE_MODE_10GKR,
+   PHY_INTERFACE_MODE_QUSGMII,
+   PHY_INTERFACE_MODE_1000BASEKX,
+#if defined(CONFIG_ARCH_LX2160A) || defined(CONFIG_ARCH_LX2162A)
+   /* LX2160A SERDES modes */
PHY_INTERFACE_MODE_25G_AUI,
PHY_INTERFACE_MODE_XLAUI,
PHY_INTERFACE_MODE_CAUI2,
PHY_INTERFACE_MODE_CAUI4,
+#endif
+#if defined(CONFIG_PHY_NCSI)
PHY_INTERFACE_MODE_NCSI,
-   PHY_INTERFACE_MODE_10GBASER,
-   PHY_INTERFACE_MODE_USXGMII,
+#endif
PHY_INTERFACE_MODE_MAX,
 } phy_interface_t;
 
 static const char * const phy_interface_strings[] = {
-   [PHY_INTERFACE_MODE_NA] = "",
+   [PHY_INTERFACE_MODE_NA] = "",
+   [PHY_INTERFACE_MODE_INTERNAL]   = "internal",
[PHY_INTERFACE_MODE_MII]= "mii",
[PHY_INTERFACE_MODE_GMII]   = "gmii",
[PHY_INTERFACE_MODE_SGMII]  = "sgmii",
-   [PHY_INTERFACE_MODE_SGMII_2500] = "sgmii-2500",
-   [PHY_INTERFACE_MODE_QSGMII] = "qsgmii",
[PHY_INTERFACE_MODE_TBI]= "tbi",
+   [PHY_INTERFACE_MODE_REVMII] = "rev-mii",
[PHY_INTERFACE_MODE_RMII]   = "rmii",
+   [PHY_INTERFACE_MODE_REVRMII]= "rev-rmii",
[PHY_INTERFACE_MODE_RGMII]  = "rgmii",
[PHY_INTERFACE_MODE_RGMII_ID]   = "rgmii-id",
[PHY_INTERFACE_MODE_RGMII_RXID] = "rgmii-rxid",
[PHY_INTERFACE_MODE_RGMII_TXID] = "rgmii-txid",
[PHY_INTERFACE_MODE_RTBI]   = "rtbi",
+   [PHY_INTERFACE_MODE_SMII]   = "smii",
+   [PHY_INTERFACE_MODE_XGMII]  = "xgmii",
+   [PHY_INTERFACE_MODE_XLGMII] = "xlgmii",
+   [PHY_INTERFACE_MODE_MOCA]   = "moca",
+   [PHY_INTERFACE_MODE_QSGMII] = "qsgmii",
+   [PHY_INTERFACE_MODE_TRGMII] = "trgmii",
[PHY_INTERFACE_MODE_1000BASEX]  = "1000base-x",
+   [PHY_INTERFACE_MODE_1000BASEKX] = "1000base-kx",

[PATCH 35/41] net: phy: xilinx-gmii2rgmii: Convert to U_BOOT_PHY_DRIVER()

2023-03-19 Thread Marek Vasut
Convert PHY driver to U_BOOT_PHY_DRIVER() macro and drop phy_register() init 
call.

Converted using sed
"s@^static struct phy_driver \(.*\)_driver = \+{@U_BOOT_PHY_DRIVER(\L\1) = {"

Signed-off-by: Marek Vasut 
---
Cc: "Ariel D'Alessandro" 
Cc: "Cédric Le Goater" 
Cc: "Marek Behún" 
Cc: Alex Nemirovsky 
Cc: Haolin Li 
Cc: Heinrich Schuchardt 
Cc: Joe Hershberger 
Cc: Joel Stanley 
Cc: Josua Mayer 
Cc: Marek Vasut 
Cc: Michael Trimarchi 
Cc: Michal Simek 
Cc: Nate Drude 
Cc: Neil Armstrong 
Cc: Radu Pirea 
Cc: Ramon Fried 
Cc: Samuel Mendoza-Jonas 
Cc: Stefan Roese 
Cc: T Karthik Reddy 
Cc: Tim Harvey 
Cc: Vladimir Oltean 
Cc: u-boot-amlo...@groups.io
---
 drivers/net/phy/phy.c   | 3 ---
 drivers/net/phy/xilinx_gmii2rgmii.c | 9 +
 include/phy.h   | 2 --
 3 files changed, 1 insertion(+), 13 deletions(-)

diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index 69db79f79e0..9d5d1494616 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -514,9 +514,6 @@ int phy_init(void)
phy_drv_reloc(drv);
 #endif
 
-#ifdef CONFIG_PHY_XILINX_GMII2RGMII
-   phy_xilinx_gmii2rgmii_init();
-#endif
genphy_init();
 
return 0;
diff --git a/drivers/net/phy/xilinx_gmii2rgmii.c 
b/drivers/net/phy/xilinx_gmii2rgmii.c
index 73762839565..0b7436a7e1e 100644
--- a/drivers/net/phy/xilinx_gmii2rgmii.c
+++ b/drivers/net/phy/xilinx_gmii2rgmii.c
@@ -124,7 +124,7 @@ static int xilinxgmiitorgmii_probe(struct phy_device 
*phydev)
return 0;
 }
 
-static struct phy_driver gmii2rgmii_driver = {
+U_BOOT_PHY_DRIVER(gmii2rgmii) = {
.name = "XILINX GMII2RGMII",
.uid = PHY_GMII2RGMII_ID,
.mask = 0x,
@@ -135,10 +135,3 @@ static struct phy_driver gmii2rgmii_driver = {
.writeext = xilinxgmiitorgmii_extwrite,
.readext = xilinxgmiitorgmii_extread,
 };
-
-int phy_xilinx_gmii2rgmii_init(void)
-{
-   phy_register(_driver);
-
-   return 0;
-}
diff --git a/include/phy.h b/include/phy.h
index 001c998db47..df2586f89ea 100644
--- a/include/phy.h
+++ b/include/phy.h
@@ -315,8 +315,6 @@ int gen10g_startup(struct phy_device *phydev);
 int gen10g_shutdown(struct phy_device *phydev);
 int gen10g_discover_mmds(struct phy_device *phydev);
 
-int phy_xilinx_gmii2rgmii_init(void);
-
 /**
  * U_BOOT_PHY_DRIVER() - Declare a new U-Boot driver
  * @__name: name of the driver
-- 
2.39.2



[PATCH 2/3] net: mvpp2: Replace PHY_INTERFACE_MODE_SFI with 5GBASER/10GBASER/XAUI

2023-03-19 Thread Marek Vasut
Replace PHY_INTERFACE_MODE_SFI with PHY_INTERFACE_MODE_5GBASER,
PHY_INTERFACE_MODE_10GBASER and PHY_INTERFACE_MODE_XAUI to match
Linux PHY interface modes.

Signed-off-by: Marek Vasut 
---
Cc: "Ariel D'Alessandro" 
Cc: "Marek Behún" 
Cc: Joe Hershberger 
Cc: Marek Vasut 
Cc: Ramon Fried 
Cc: Stefan Roese 
Cc: Tim Harvey 
Cc: Vladimir Oltean 
---
 drivers/net/mvpp2.c | 8 ++--
 include/phy_interface.h | 2 ++
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/net/mvpp2.c b/drivers/net/mvpp2.c
index 71347b7e69c..096b8a35853 100644
--- a/drivers/net/mvpp2.c
+++ b/drivers/net/mvpp2.c
@@ -3438,7 +3438,9 @@ static int gop_port_init(struct mvpp2_port *port)
gop_gmac_reset(port, 0);
break;
 
-   case PHY_INTERFACE_MODE_SFI:
+   case PHY_INTERFACE_MODE_10GBASER:
+   case PHY_INTERFACE_MODE_5GBASER:
+   case PHY_INTERFACE_MODE_XAUI:
num_of_act_lanes = 2;
mac_num = 0;
/* configure PCS */
@@ -3489,7 +3491,9 @@ static void gop_port_enable(struct mvpp2_port *port, int 
enable)
mvpp2_port_disable(port);
break;
 
-   case PHY_INTERFACE_MODE_SFI:
+   case PHY_INTERFACE_MODE_10GBASER:
+   case PHY_INTERFACE_MODE_5GBASER:
+   case PHY_INTERFACE_MODE_XAUI:
gop_xlg_mac_port_enable(port, enable);
 
break;
diff --git a/include/phy_interface.h b/include/phy_interface.h
index fed3357b9a2..52af7e612b6 100644
--- a/include/phy_interface.h
+++ b/include/phy_interface.h
@@ -31,6 +31,7 @@ typedef enum {
PHY_INTERFACE_MODE_XGMII,
PHY_INTERFACE_MODE_XAUI,
PHY_INTERFACE_MODE_RXAUI,
+   PHY_INTERFACE_MODE_5GBASER,
PHY_INTERFACE_MODE_SFI,
PHY_INTERFACE_MODE_INTERNAL,
PHY_INTERFACE_MODE_25G_AUI,
@@ -62,6 +63,7 @@ static const char * const phy_interface_strings[] = {
[PHY_INTERFACE_MODE_XGMII]  = "xgmii",
[PHY_INTERFACE_MODE_XAUI]   = "xaui",
[PHY_INTERFACE_MODE_RXAUI]  = "rxaui",
+   [PHY_INTERFACE_MODE_5GBASER]= "5gbase-r",
[PHY_INTERFACE_MODE_SFI]= "sfi",
[PHY_INTERFACE_MODE_INTERNAL]   = "internal",
[PHY_INTERFACE_MODE_25G_AUI]= "25g-aui",
-- 
2.39.2



[PATCH 40/41] net: phy: Re-inline phy_drv_reloc()

2023-03-19 Thread Marek Vasut
Wrap phy_drv_reloc() back into phy_init() to reduce ifdeffery,
since phy_drv_reloc() is now called only from one call site.
No functional change.

Signed-off-by: Marek Vasut 
---
Cc: "Ariel D'Alessandro" 
Cc: "Cédric Le Goater" 
Cc: "Marek Behún" 
Cc: Alex Nemirovsky 
Cc: Haolin Li 
Cc: Heinrich Schuchardt 
Cc: Joe Hershberger 
Cc: Joel Stanley 
Cc: Josua Mayer 
Cc: Marek Vasut 
Cc: Michael Trimarchi 
Cc: Michal Simek 
Cc: Nate Drude 
Cc: Neil Armstrong 
Cc: Radu Pirea 
Cc: Ramon Fried 
Cc: Samuel Mendoza-Jonas 
Cc: Stefan Roese 
Cc: T Karthik Reddy 
Cc: Tim Harvey 
Cc: Vladimir Oltean 
Cc: u-boot-amlo...@groups.io
---
 drivers/net/phy/phy.c | 42 ++
 1 file changed, 18 insertions(+), 24 deletions(-)

diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index 15da9a80de2..61603f28179 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -463,28 +463,6 @@ U_BOOT_PHY_DRIVER(genphy) = {
.shutdown   = genphy_shutdown,
 };
 
-#ifdef CONFIG_NEEDS_MANUAL_RELOC
-static void phy_drv_reloc(struct phy_driver *drv)
-{
-   if (drv->probe)
-   drv->probe += gd->reloc_off;
-   if (drv->config)
-   drv->config += gd->reloc_off;
-   if (drv->startup)
-   drv->startup += gd->reloc_off;
-   if (drv->shutdown)
-   drv->shutdown += gd->reloc_off;
-   if (drv->readext)
-   drv->readext += gd->reloc_off;
-   if (drv->writeext)
-   drv->writeext += gd->reloc_off;
-   if (drv->read_mmd)
-   drv->read_mmd += gd->reloc_off;
-   if (drv->write_mmd)
-   drv->write_mmd += gd->reloc_off;
-}
-#endif
-
 int phy_init(void)
 {
 #ifdef CONFIG_NEEDS_MANUAL_RELOC
@@ -493,8 +471,24 @@ int phy_init(void)
 
/* Perform manual relocation on linker list based PHY drivers */
ll_entry = ll_entry_start(struct phy_driver, phy_driver);
-   for (drv = ll_entry; drv != ll_entry + ll_n_ents; drv++)
-   phy_drv_reloc(drv);
+   for (drv = ll_entry; drv != ll_entry + ll_n_ents; drv++) {
+   if (drv->probe)
+   drv->probe += gd->reloc_off;
+   if (drv->config)
+   drv->config += gd->reloc_off;
+   if (drv->startup)
+   drv->startup += gd->reloc_off;
+   if (drv->shutdown)
+   drv->shutdown += gd->reloc_off;
+   if (drv->readext)
+   drv->readext += gd->reloc_off;
+   if (drv->writeext)
+   drv->writeext += gd->reloc_off;
+   if (drv->read_mmd)
+   drv->read_mmd += gd->reloc_off;
+   if (drv->write_mmd)
+   drv->write_mmd += gd->reloc_off;
+   }
 #endif
 
return 0;
-- 
2.39.2



[PATCH 23/41] net: phy: nxp-c45-tja11xx: Convert to U_BOOT_PHY_DRIVER()

2023-03-19 Thread Marek Vasut
Convert PHY driver to U_BOOT_PHY_DRIVER() macro and drop phy_register() init 
call.

Converted using sed
"s@^static struct phy_driver \(.*\)_driver = \+{@U_BOOT_PHY_DRIVER(\L\1) = {"

Signed-off-by: Marek Vasut 
---
Cc: "Ariel D'Alessandro" 
Cc: "Cédric Le Goater" 
Cc: "Marek Behún" 
Cc: Alex Nemirovsky 
Cc: Haolin Li 
Cc: Heinrich Schuchardt 
Cc: Joe Hershberger 
Cc: Joel Stanley 
Cc: Josua Mayer 
Cc: Marek Vasut 
Cc: Michael Trimarchi 
Cc: Michal Simek 
Cc: Nate Drude 
Cc: Neil Armstrong 
Cc: Radu Pirea 
Cc: Ramon Fried 
Cc: Samuel Mendoza-Jonas 
Cc: Stefan Roese 
Cc: T Karthik Reddy 
Cc: Tim Harvey 
Cc: Vladimir Oltean 
Cc: u-boot-amlo...@groups.io
---
 drivers/net/phy/nxp-c45-tja11xx.c | 8 +---
 drivers/net/phy/phy.c | 3 ---
 include/phy.h | 1 -
 3 files changed, 1 insertion(+), 11 deletions(-)

diff --git a/drivers/net/phy/nxp-c45-tja11xx.c 
b/drivers/net/phy/nxp-c45-tja11xx.c
index a0f41fab698..f701790194c 100644
--- a/drivers/net/phy/nxp-c45-tja11xx.c
+++ b/drivers/net/phy/nxp-c45-tja11xx.c
@@ -330,7 +330,7 @@ static int nxp_c45_probe(struct phy_device *phydev)
return 0;
 }
 
-static struct phy_driver nxp_c45_tja11xx = {
+U_BOOT_PHY_DRIVER(nxp_c45_tja11xx) = {
.name = "NXP C45 TJA1103",
.uid  = PHY_ID_TJA_1103,
.mask = 0xf0,
@@ -340,9 +340,3 @@ static struct phy_driver nxp_c45_tja11xx = {
.startup = _c45_startup,
.shutdown = _shutdown,
 };
-
-int phy_nxp_c45_tja11xx_init(void)
-{
-   phy_register(_c45_tja11xx);
-   return 0;
-}
diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index 3d6fc8080e5..706b9505d6e 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -514,9 +514,6 @@ int phy_init(void)
phy_drv_reloc(drv);
 #endif
 
-#ifdef CONFIG_NXP_C45_TJA11XX_PHY
-   phy_nxp_c45_tja11xx_init();
-#endif
 #ifdef CONFIG_PHY_NXP_TJA11XX
phy_nxp_tja11xx_init();
 #endif
diff --git a/include/phy.h b/include/phy.h
index 647d23595d1..aa65ae16f68 100644
--- a/include/phy.h
+++ b/include/phy.h
@@ -315,7 +315,6 @@ int gen10g_startup(struct phy_device *phydev);
 int gen10g_shutdown(struct phy_device *phydev);
 int gen10g_discover_mmds(struct phy_device *phydev);
 
-int phy_nxp_c45_tja11xx_init(void);
 int phy_nxp_tja11xx_init(void);
 int phy_realtek_init(void);
 int phy_smsc_init(void);
-- 
2.39.2



[PATCH 1/3] net: mvpp2: Replace PHY_INTERFACE_MODE_SGMII_2500 with SGMII and speed

2023-03-19 Thread Marek Vasut
Replace PHY_INTERFACE_MODE_SGMII_2500 with PHY_INTERFACE_MODE_SGMII and
phydev->speed check where applicable. The PHY_INTERFACE_MODE_SGMII_2500
does not exist in Linux, so remove it from U-Boot too.

Signed-off-by: Marek Vasut 
---
Cc: "Ariel D'Alessandro" 
Cc: "Marek Behún" 
Cc: Joe Hershberger 
Cc: Marek Vasut 
Cc: Ramon Fried 
Cc: Stefan Roese 
Cc: Tim Harvey 
Cc: Vladimir Oltean 
---
 drivers/net/mvpp2.c | 18 ++
 1 file changed, 6 insertions(+), 12 deletions(-)

diff --git a/drivers/net/mvpp2.c b/drivers/net/mvpp2.c
index 1bad50d344c..71347b7e69c 100644
--- a/drivers/net/mvpp2.c
+++ b/drivers/net/mvpp2.c
@@ -2871,7 +2871,6 @@ static void mvpp2_port_mii_set(struct mvpp2_port *port)
 
switch (port->phy_interface) {
case PHY_INTERFACE_MODE_SGMII:
-   case PHY_INTERFACE_MODE_SGMII_2500:
val |= MVPP2_GMAC_INBAND_AN_MASK;
break;
case PHY_INTERFACE_MODE_1000BASEX:
@@ -2939,7 +2938,6 @@ static void mvpp2_port_loopback_set(struct mvpp2_port 
*port)
val &= ~MVPP2_GMAC_GMII_LB_EN_MASK;
 
if (port->phy_interface == PHY_INTERFACE_MODE_SGMII ||
-   port->phy_interface == PHY_INTERFACE_MODE_SGMII_2500 ||
port->phy_interface == PHY_INTERFACE_MODE_1000BASEX ||
port->phy_interface == PHY_INTERFACE_MODE_2500BASEX)
val |= MVPP2_GMAC_PCS_LB_EN_MASK;
@@ -3237,10 +3235,12 @@ static int gop_gmac_mode_cfg(struct mvpp2_port *port)
/* Set TX FIFO thresholds */
switch (port->phy_interface) {
case PHY_INTERFACE_MODE_SGMII:
-   gop_gmac_sgmii_cfg(port);
-   break;
-   case PHY_INTERFACE_MODE_SGMII_2500:
-   gop_gmac_sgmii2_5_cfg(port);
+   if (port->speed == SPEED_1000)
+   gop_gmac_sgmii_cfg(port);
+   else if (port->speed == 2500)
+   gop_gmac_sgmii2_5_cfg(port);
+   else
+   return -1;
break;
case PHY_INTERFACE_MODE_1000BASEX:
gop_gmac_1000basex_cfg(port);
@@ -3422,7 +3422,6 @@ static int gop_port_init(struct mvpp2_port *port)
break;
 
case PHY_INTERFACE_MODE_SGMII:
-   case PHY_INTERFACE_MODE_SGMII_2500:
case PHY_INTERFACE_MODE_1000BASEX:
case PHY_INTERFACE_MODE_2500BASEX:
/* configure PCS */
@@ -3482,7 +3481,6 @@ static void gop_port_enable(struct mvpp2_port *port, int 
enable)
case PHY_INTERFACE_MODE_RGMII:
case PHY_INTERFACE_MODE_RGMII_ID:
case PHY_INTERFACE_MODE_SGMII:
-   case PHY_INTERFACE_MODE_SGMII_2500:
case PHY_INTERFACE_MODE_1000BASEX:
case PHY_INTERFACE_MODE_2500BASEX:
if (enable)
@@ -3519,7 +3517,6 @@ static u32 mvpp2_netc_cfg_create(int gop_id, 
phy_interface_t phy_type)
 
if (gop_id == 2) {
if (phy_type == PHY_INTERFACE_MODE_SGMII ||
-   phy_type == PHY_INTERFACE_MODE_SGMII_2500 ||
phy_type == PHY_INTERFACE_MODE_1000BASEX ||
phy_type == PHY_INTERFACE_MODE_2500BASEX)
val |= MV_NETC_GE_MAC2_SGMII;
@@ -3530,7 +3527,6 @@ static u32 mvpp2_netc_cfg_create(int gop_id, 
phy_interface_t phy_type)
 
if (gop_id == 3) {
if (phy_type == PHY_INTERFACE_MODE_SGMII ||
-   phy_type == PHY_INTERFACE_MODE_SGMII_2500 ||
phy_type == PHY_INTERFACE_MODE_1000BASEX ||
phy_type == PHY_INTERFACE_MODE_2500BASEX)
val |= MV_NETC_GE_MAC3_SGMII;
@@ -4529,7 +4525,6 @@ static void mvpp2_start_dev(struct mvpp2_port *port)
case PHY_INTERFACE_MODE_RGMII:
case PHY_INTERFACE_MODE_RGMII_ID:
case PHY_INTERFACE_MODE_SGMII:
-   case PHY_INTERFACE_MODE_SGMII_2500:
case PHY_INTERFACE_MODE_1000BASEX:
case PHY_INTERFACE_MODE_2500BASEX:
mvpp2_gmac_max_rx_size_set(port);
@@ -5263,7 +5258,6 @@ static int mvpp2_start(struct udevice *dev)
case PHY_INTERFACE_MODE_RGMII:
case PHY_INTERFACE_MODE_RGMII_ID:
case PHY_INTERFACE_MODE_SGMII:
-   case PHY_INTERFACE_MODE_SGMII_2500:
case PHY_INTERFACE_MODE_1000BASEX:
case PHY_INTERFACE_MODE_2500BASEX:
mvpp2_port_power_up(port);
-- 
2.39.2



[PATCH 27/41] net: phy: teranetics: Convert to U_BOOT_PHY_DRIVER()

2023-03-19 Thread Marek Vasut
Convert PHY driver to U_BOOT_PHY_DRIVER() macro and drop phy_register() init 
call.

Converted using sed
"s@^static struct phy_driver \(.*\)_driver = \+{@U_BOOT_PHY_DRIVER(\L\1) = {"

Signed-off-by: Marek Vasut 
---
Cc: "Ariel D'Alessandro" 
Cc: "Cédric Le Goater" 
Cc: "Marek Behún" 
Cc: Alex Nemirovsky 
Cc: Haolin Li 
Cc: Heinrich Schuchardt 
Cc: Joe Hershberger 
Cc: Joel Stanley 
Cc: Josua Mayer 
Cc: Marek Vasut 
Cc: Michael Trimarchi 
Cc: Michal Simek 
Cc: Nate Drude 
Cc: Neil Armstrong 
Cc: Radu Pirea 
Cc: Ramon Fried 
Cc: Samuel Mendoza-Jonas 
Cc: Stefan Roese 
Cc: T Karthik Reddy 
Cc: Tim Harvey 
Cc: Vladimir Oltean 
Cc: u-boot-amlo...@groups.io
---
 drivers/net/phy/phy.c| 3 ---
 drivers/net/phy/teranetics.c | 9 +
 include/phy.h| 1 -
 3 files changed, 1 insertion(+), 12 deletions(-)

diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index d4a50fb76ac..b76cc51cbfb 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -514,9 +514,6 @@ int phy_init(void)
phy_drv_reloc(drv);
 #endif
 
-#ifdef CONFIG_PHY_TERANETICS
-   phy_teranetics_init();
-#endif
 #ifdef CONFIG_PHY_TI
phy_ti_init();
 #endif
diff --git a/drivers/net/phy/teranetics.c b/drivers/net/phy/teranetics.c
index c402bad88c6..15f2c12ed83 100644
--- a/drivers/net/phy/teranetics.c
+++ b/drivers/net/phy/teranetics.c
@@ -90,7 +90,7 @@ int tn2020_startup(struct phy_device *phydev)
return 0;
 }
 
-static struct phy_driver tn2020_driver = {
+U_BOOT_PHY_DRIVER(tn2020) = {
.name = "Teranetics TN2020",
.uid = PHY_UID_TN2020,
.mask = 0xfff0,
@@ -102,10 +102,3 @@ static struct phy_driver tn2020_driver = {
.startup = _startup,
.shutdown = _shutdown,
 };
-
-int phy_teranetics_init(void)
-{
-   phy_register(_driver);
-
-   return 0;
-}
diff --git a/include/phy.h b/include/phy.h
index 4326ef223e0..2c6e167f26e 100644
--- a/include/phy.h
+++ b/include/phy.h
@@ -315,7 +315,6 @@ int gen10g_startup(struct phy_device *phydev);
 int gen10g_shutdown(struct phy_device *phydev);
 int gen10g_discover_mmds(struct phy_device *phydev);
 
-int phy_teranetics_init(void);
 int phy_ti_init(void);
 int phy_vitesse_init(void);
 int phy_xilinx_init(void);
-- 
2.39.2



[PATCH 24/41] net: phy: nxp-tja11xx: Convert to U_BOOT_PHY_DRIVER()

2023-03-19 Thread Marek Vasut
Convert PHY driver to U_BOOT_PHY_DRIVER() macro and drop phy_register() init 
call.

Converted using sed
"s@^static struct phy_driver \(.*\)_driver = \+{@U_BOOT_PHY_DRIVER(\L\1) = {"

Signed-off-by: Marek Vasut 
---
Cc: "Ariel D'Alessandro" 
Cc: "Cédric Le Goater" 
Cc: "Marek Behún" 
Cc: Alex Nemirovsky 
Cc: Haolin Li 
Cc: Heinrich Schuchardt 
Cc: Joe Hershberger 
Cc: Joel Stanley 
Cc: Josua Mayer 
Cc: Marek Vasut 
Cc: Michael Trimarchi 
Cc: Michal Simek 
Cc: Nate Drude 
Cc: Neil Armstrong 
Cc: Radu Pirea 
Cc: Ramon Fried 
Cc: Samuel Mendoza-Jonas 
Cc: Stefan Roese 
Cc: T Karthik Reddy 
Cc: Tim Harvey 
Cc: Vladimir Oltean 
Cc: u-boot-amlo...@groups.io
---
 drivers/net/phy/nxp-tja11xx.c | 12 ++--
 drivers/net/phy/phy.c |  3 ---
 include/phy.h |  1 -
 3 files changed, 2 insertions(+), 14 deletions(-)

diff --git a/drivers/net/phy/nxp-tja11xx.c b/drivers/net/phy/nxp-tja11xx.c
index 30dec5e605b..471b0e322b5 100644
--- a/drivers/net/phy/nxp-tja11xx.c
+++ b/drivers/net/phy/nxp-tja11xx.c
@@ -248,7 +248,7 @@ static int tja11xx_startup(struct phy_device *phydev)
return 0;
 }
 
-static struct phy_driver TJA1100_driver = {
+U_BOOT_PHY_DRIVER(tja1100) = {
.name = "NXP TJA1100",
.uid = PHY_ID_TJA1100,
.mask = PHY_ID_MASK,
@@ -258,7 +258,7 @@ static struct phy_driver TJA1100_driver = {
.shutdown = _shutdown,
 };
 
-static struct phy_driver TJA1101_driver = {
+U_BOOT_PHY_DRIVER(tja1101) = {
.name = "NXP TJA1101",
.uid = PHY_ID_TJA1101,
.mask = PHY_ID_MASK,
@@ -267,11 +267,3 @@ static struct phy_driver TJA1101_driver = {
.startup = _startup,
.shutdown = _shutdown,
 };
-
-int phy_nxp_tja11xx_init(void)
-{
-   phy_register(_driver);
-   phy_register(_driver);
-
-   return 0;
-}
diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index 706b9505d6e..03d221f216d 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -514,9 +514,6 @@ int phy_init(void)
phy_drv_reloc(drv);
 #endif
 
-#ifdef CONFIG_PHY_NXP_TJA11XX
-   phy_nxp_tja11xx_init();
-#endif
 #ifdef CONFIG_PHY_REALTEK
phy_realtek_init();
 #endif
diff --git a/include/phy.h b/include/phy.h
index aa65ae16f68..bc42a522ea6 100644
--- a/include/phy.h
+++ b/include/phy.h
@@ -315,7 +315,6 @@ int gen10g_startup(struct phy_device *phydev);
 int gen10g_shutdown(struct phy_device *phydev);
 int gen10g_discover_mmds(struct phy_device *phydev);
 
-int phy_nxp_tja11xx_init(void);
 int phy_realtek_init(void);
 int phy_smsc_init(void);
 int phy_teranetics_init(void);
-- 
2.39.2



[PATCH 34/41] net: phy: ncsi: Convert to U_BOOT_PHY_DRIVER()

2023-03-19 Thread Marek Vasut
Convert PHY driver to U_BOOT_PHY_DRIVER() macro and drop phy_register() init 
call.

Converted using sed
"s@^static struct phy_driver \(.*\)_driver = \+{@U_BOOT_PHY_DRIVER(\L\1) = {"

Signed-off-by: Marek Vasut 
---
Cc: "Ariel D'Alessandro" 
Cc: "Cédric Le Goater" 
Cc: "Marek Behún" 
Cc: Alex Nemirovsky 
Cc: Haolin Li 
Cc: Heinrich Schuchardt 
Cc: Joe Hershberger 
Cc: Joel Stanley 
Cc: Josua Mayer 
Cc: Marek Vasut 
Cc: Michael Trimarchi 
Cc: Michal Simek 
Cc: Nate Drude 
Cc: Neil Armstrong 
Cc: Radu Pirea 
Cc: Ramon Fried 
Cc: Samuel Mendoza-Jonas 
Cc: Stefan Roese 
Cc: T Karthik Reddy 
Cc: Tim Harvey 
Cc: Vladimir Oltean 
Cc: u-boot-amlo...@groups.io
---
 drivers/net/phy/ncsi.c | 8 +---
 drivers/net/phy/phy.c  | 3 ---
 include/phy.h  | 1 -
 3 files changed, 1 insertion(+), 11 deletions(-)

diff --git a/drivers/net/phy/ncsi.c b/drivers/net/phy/ncsi.c
index bb7ecebed38..eb3fd65bb47 100644
--- a/drivers/net/phy/ncsi.c
+++ b/drivers/net/phy/ncsi.c
@@ -881,7 +881,7 @@ int ncsi_shutdown(struct phy_device *phydev)
return 0;
 }
 
-static struct phy_driver ncsi_driver = {
+U_BOOT_PHY_DRIVER(ncsi) = {
.uid= PHY_NCSI_ID,
.mask   = 0x,
.name   = "NC-SI",
@@ -891,9 +891,3 @@ static struct phy_driver ncsi_driver = {
.startup= ncsi_startup,
.shutdown   = ncsi_shutdown,
 };
-
-int phy_ncsi_init(void)
-{
-   phy_register(_driver);
-   return 0;
-}
diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index 245357c31dc..69db79f79e0 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -514,9 +514,6 @@ int phy_init(void)
phy_drv_reloc(drv);
 #endif
 
-#ifdef CONFIG_PHY_NCSI
-   phy_ncsi_init();
-#endif
 #ifdef CONFIG_PHY_XILINX_GMII2RGMII
phy_xilinx_gmii2rgmii_init();
 #endif
diff --git a/include/phy.h b/include/phy.h
index 9cabfeedec8..001c998db47 100644
--- a/include/phy.h
+++ b/include/phy.h
@@ -315,7 +315,6 @@ int gen10g_startup(struct phy_device *phydev);
 int gen10g_shutdown(struct phy_device *phydev);
 int gen10g_discover_mmds(struct phy_device *phydev);
 
-int phy_ncsi_init(void);
 int phy_xilinx_gmii2rgmii_init(void);
 
 /**
-- 
2.39.2



[PATCH 26/41] net: phy: smsc: Convert to U_BOOT_PHY_DRIVER()

2023-03-19 Thread Marek Vasut
Convert PHY driver to U_BOOT_PHY_DRIVER() macro and drop phy_register() init 
call.

Converted using sed
"s@^static struct phy_driver \(.*\)_driver = \+{@U_BOOT_PHY_DRIVER(\L\1) = {"

Signed-off-by: Marek Vasut 
---
Cc: "Ariel D'Alessandro" 
Cc: "Cédric Le Goater" 
Cc: "Marek Behún" 
Cc: Alex Nemirovsky 
Cc: Haolin Li 
Cc: Heinrich Schuchardt 
Cc: Joe Hershberger 
Cc: Joel Stanley 
Cc: Josua Mayer 
Cc: Marek Vasut 
Cc: Michael Trimarchi 
Cc: Michal Simek 
Cc: Nate Drude 
Cc: Neil Armstrong 
Cc: Radu Pirea 
Cc: Ramon Fried 
Cc: Samuel Mendoza-Jonas 
Cc: Stefan Roese 
Cc: T Karthik Reddy 
Cc: Tim Harvey 
Cc: Vladimir Oltean 
Cc: u-boot-amlo...@groups.io
---
 drivers/net/phy/phy.c  |  3 ---
 drivers/net/phy/smsc.c | 24 ++--
 include/phy.h  |  1 -
 3 files changed, 6 insertions(+), 22 deletions(-)

diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index e821a3f37cb..d4a50fb76ac 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -514,9 +514,6 @@ int phy_init(void)
phy_drv_reloc(drv);
 #endif
 
-#ifdef CONFIG_PHY_SMSC
-   phy_smsc_init();
-#endif
 #ifdef CONFIG_PHY_TERANETICS
phy_teranetics_init();
 #endif
diff --git a/drivers/net/phy/smsc.c b/drivers/net/phy/smsc.c
index 7740a2510d2..056b607e0b8 100644
--- a/drivers/net/phy/smsc.c
+++ b/drivers/net/phy/smsc.c
@@ -43,7 +43,7 @@ static int smsc_startup(struct phy_device *phydev)
return smsc_parse_status(phydev);
 }
 
-static struct phy_driver lan8700_driver = {
+U_BOOT_PHY_DRIVER(lan8700) = {
.name = "SMSC LAN8700",
.uid = 0x0007c0c0,
.mask = 0x0,
@@ -53,7 +53,7 @@ static struct phy_driver lan8700_driver = {
.shutdown = _shutdown,
 };
 
-static struct phy_driver lan911x_driver = {
+U_BOOT_PHY_DRIVER(lan911x) = {
.name = "SMSC LAN911x Internal PHY",
.uid = 0x0007c0d0,
.mask = 0x0,
@@ -63,7 +63,7 @@ static struct phy_driver lan911x_driver = {
.shutdown = _shutdown,
 };
 
-static struct phy_driver lan8710_driver = {
+U_BOOT_PHY_DRIVER(lan8710) = {
.name = "SMSC LAN8710/LAN8720",
.uid = 0x0007c0f0,
.mask = 0x0,
@@ -73,7 +73,7 @@ static struct phy_driver lan8710_driver = {
.shutdown = _shutdown,
 };
 
-static struct phy_driver lan8740_driver = {
+U_BOOT_PHY_DRIVER(lan8740) = {
.name = "SMSC LAN8740",
.uid = 0x0007c110,
.mask = 0x0,
@@ -83,7 +83,7 @@ static struct phy_driver lan8740_driver = {
.shutdown = _shutdown,
 };
 
-static struct phy_driver lan8741_driver = {
+U_BOOT_PHY_DRIVER(lan8741) = {
.name = "SMSC LAN8741",
.uid = 0x0007c120,
.mask = 0x0,
@@ -93,7 +93,7 @@ static struct phy_driver lan8741_driver = {
.shutdown = _shutdown,
 };
 
-static struct phy_driver lan8742_driver = {
+U_BOOT_PHY_DRIVER(lan8742) = {
.name = "SMSC LAN8742",
.uid = 0x0007c130,
.mask = 0x0,
@@ -102,15 +102,3 @@ static struct phy_driver lan8742_driver = {
.startup = _startup,
.shutdown = _shutdown,
 };
-
-int phy_smsc_init(void)
-{
-   phy_register(_driver);
-   phy_register(_driver);
-   phy_register(_driver);
-   phy_register(_driver);
-   phy_register(_driver);
-   phy_register(_driver);
-
-   return 0;
-}
diff --git a/include/phy.h b/include/phy.h
index 24a880ed2fb..4326ef223e0 100644
--- a/include/phy.h
+++ b/include/phy.h
@@ -315,7 +315,6 @@ int gen10g_startup(struct phy_device *phydev);
 int gen10g_shutdown(struct phy_device *phydev);
 int gen10g_discover_mmds(struct phy_device *phydev);
 
-int phy_smsc_init(void);
 int phy_teranetics_init(void);
 int phy_ti_init(void);
 int phy_vitesse_init(void);
-- 
2.39.2



[PATCH 28/41] net: phy: ti: Convert to U_BOOT_PHY_DRIVER()

2023-03-19 Thread Marek Vasut
Convert PHY driver to U_BOOT_PHY_DRIVER() macro and drop phy_register() init 
call.

Converted using sed
"s@^static struct phy_driver \(.*\)_driver = \+{@U_BOOT_PHY_DRIVER(\L\1) = {"

This particular PHY driver is slightly more spread out across additional
source files. Since the phy_register() calls are no longer necessary, all
the registration calls across those source files is dropped. Furthermore,
the Makefile can now be updated to only compile generic TI PHY support if
matching Kconfig symbol is enabled and the ifdeffery in the generic TI PHY
driver can be dropped.

Signed-off-by: Marek Vasut 
---
Cc: "Ariel D'Alessandro" 
Cc: "Cédric Le Goater" 
Cc: "Marek Behún" 
Cc: Alex Nemirovsky 
Cc: Haolin Li 
Cc: Heinrich Schuchardt 
Cc: Joe Hershberger 
Cc: Joel Stanley 
Cc: Josua Mayer 
Cc: Marek Vasut 
Cc: Michael Trimarchi 
Cc: Michal Simek 
Cc: Nate Drude 
Cc: Neil Armstrong 
Cc: Radu Pirea 
Cc: Ramon Fried 
Cc: Samuel Mendoza-Jonas 
Cc: Stefan Roese 
Cc: T Karthik Reddy 
Cc: Tim Harvey 
Cc: Vladimir Oltean 
Cc: u-boot-amlo...@groups.io
---
 drivers/net/phy/Makefile  |  2 +-
 drivers/net/phy/dp83867.c |  8 +---
 drivers/net/phy/dp83869.c |  8 +---
 drivers/net/phy/phy.c |  3 ---
 drivers/net/phy/ti_phy_init.c | 38 +++
 include/phy.h |  1 -
 6 files changed, 10 insertions(+), 50 deletions(-)

diff --git a/drivers/net/phy/Makefile b/drivers/net/phy/Makefile
index d38e99e7171..963d96e2bcb 100644
--- a/drivers/net/phy/Makefile
+++ b/drivers/net/phy/Makefile
@@ -29,7 +29,7 @@ obj-$(CONFIG_PHY_NXP_TJA11XX) += nxp-tja11xx.o
 obj-$(CONFIG_PHY_REALTEK) += realtek.o
 obj-$(CONFIG_PHY_SMSC) += smsc.o
 obj-$(CONFIG_PHY_TERANETICS) += teranetics.o
-obj-$(CONFIG_PHY_TI) += ti_phy_init.o
+obj-$(CONFIG_PHY_TI_GENERIC) += ti_phy_init.o
 obj-$(CONFIG_PHY_TI_DP83867) += dp83867.o
 obj-$(CONFIG_PHY_TI_DP83869) += dp83869.o
 obj-$(CONFIG_PHY_XILINX) += xilinx_phy.o
diff --git a/drivers/net/phy/dp83867.c b/drivers/net/phy/dp83867.c
index a45152bddc9..b861bf7cef3 100644
--- a/drivers/net/phy/dp83867.c
+++ b/drivers/net/phy/dp83867.c
@@ -409,7 +409,7 @@ static int dp83867_probe(struct phy_device *phydev)
return 0;
 }
 
-static struct phy_driver DP83867_driver = {
+U_BOOT_PHY_DRIVER(dp83867) = {
.name = "TI DP83867",
.uid = 0x2000a231,
.mask = 0xfff0,
@@ -419,9 +419,3 @@ static struct phy_driver DP83867_driver = {
.startup = _startup,
.shutdown = _shutdown,
 };
-
-int phy_dp83867_init(void)
-{
-   phy_register(_driver);
-   return 0;
-}
diff --git a/drivers/net/phy/dp83869.c b/drivers/net/phy/dp83869.c
index 23dbf42b68c..8d32d73b07f 100644
--- a/drivers/net/phy/dp83869.c
+++ b/drivers/net/phy/dp83869.c
@@ -473,7 +473,7 @@ static int dp83869_probe(struct phy_device *phydev)
return 0;
 }
 
-static struct phy_driver DP83869_driver = {
+U_BOOT_PHY_DRIVER(dp83869) = {
.name = "TI DP83869",
.uid = 0x2000a0f1,
.mask = 0xfff0,
@@ -485,9 +485,3 @@ static struct phy_driver DP83869_driver = {
.readext = dp83869_readext,
.writeext = dp83869_writeext
 };
-
-int phy_dp83869_init(void)
-{
-   phy_register(_driver);
-   return 0;
-}
diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index b76cc51cbfb..404d61c5ab3 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -514,9 +514,6 @@ int phy_init(void)
phy_drv_reloc(drv);
 #endif
 
-#ifdef CONFIG_PHY_TI
-   phy_ti_init();
-#endif
 #ifdef CONFIG_PHY_VITESSE
phy_vitesse_init();
 #endif
diff --git a/drivers/net/phy/ti_phy_init.c b/drivers/net/phy/ti_phy_init.c
index 075b19a39f0..a0878193ac0 100644
--- a/drivers/net/phy/ti_phy_init.c
+++ b/drivers/net/phy/ti_phy_init.c
@@ -10,8 +10,7 @@
 #include 
 #include "ti_phy_init.h"
 
-#ifdef CONFIG_PHY_TI_GENERIC
-static struct phy_driver dp83822_driver = {
+U_BOOT_PHY_DRIVER(dp83822) = {
.name = "TI DP83822",
.uid = 0x2000a240,
.mask = 0xfff0,
@@ -21,7 +20,7 @@ static struct phy_driver dp83822_driver = {
.shutdown = _shutdown,
 };
 
-static struct phy_driver dp83826nc_driver = {
+U_BOOT_PHY_DRIVER(dp83826nc) = {
.name = "TI DP83826NC",
.uid = 0x2000a110,
.mask = 0xfff0,
@@ -31,7 +30,7 @@ static struct phy_driver dp83826nc_driver = {
.shutdown = _shutdown,
 };
 
-static struct phy_driver dp83826c_driver = {
+U_BOOT_PHY_DRIVER(dp83826c) = {
.name = "TI DP83826C",
.uid = 0x2000a130,
.mask = 0xfff0,
@@ -41,7 +40,7 @@ static struct phy_driver dp83826c_driver = {
.shutdown = _shutdown,
 };
 
-static struct phy_driver dp83825s_driver = {
+U_BOOT_PHY_DRIVER(dp83825s) = {
.name = "TI DP83825S",
.uid = 0x2000a140,
.mask = 0xfff0,
@@ -51,7 +50,7 @@ static struct phy_driver dp83825s_driver = {
.shutdown = _shutdown,
 };
 
-static struct phy_driver dp83825i_driver = {

[PATCH 25/41] net: phy: realtek: Convert to U_BOOT_PHY_DRIVER()

2023-03-19 Thread Marek Vasut
Convert PHY driver to U_BOOT_PHY_DRIVER() macro and drop phy_register() init 
call.

Converted using sed
"s@^static struct phy_driver \(.*\)_driver = \+{@U_BOOT_PHY_DRIVER(\L\1) = {"

Signed-off-by: Marek Vasut 
---
Cc: "Ariel D'Alessandro" 
Cc: "Cédric Le Goater" 
Cc: "Marek Behún" 
Cc: Alex Nemirovsky 
Cc: Haolin Li 
Cc: Heinrich Schuchardt 
Cc: Joe Hershberger 
Cc: Joel Stanley 
Cc: Josua Mayer 
Cc: Marek Vasut 
Cc: Michael Trimarchi 
Cc: Michal Simek 
Cc: Nate Drude 
Cc: Neil Armstrong 
Cc: Radu Pirea 
Cc: Ramon Fried 
Cc: Samuel Mendoza-Jonas 
Cc: Stefan Roese 
Cc: T Karthik Reddy 
Cc: Tim Harvey 
Cc: Vladimir Oltean 
Cc: u-boot-amlo...@groups.io
---
 drivers/net/phy/phy.c |  3 ---
 drivers/net/phy/realtek.c | 21 +
 include/phy.h |  1 -
 3 files changed, 5 insertions(+), 20 deletions(-)

diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index 03d221f216d..e821a3f37cb 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -514,9 +514,6 @@ int phy_init(void)
phy_drv_reloc(drv);
 #endif
 
-#ifdef CONFIG_PHY_REALTEK
-   phy_realtek_init();
-#endif
 #ifdef CONFIG_PHY_SMSC
phy_smsc_init();
 #endif
diff --git a/drivers/net/phy/realtek.c b/drivers/net/phy/realtek.c
index 24c3ea59bbb..247d9753a88 100644
--- a/drivers/net/phy/realtek.c
+++ b/drivers/net/phy/realtek.c
@@ -409,7 +409,7 @@ static int rtl8211f_startup(struct phy_device *phydev)
 }
 
 /* Support for RTL8211B PHY */
-static struct phy_driver RTL8211B_driver = {
+U_BOOT_PHY_DRIVER(rtl8211b) = {
.name = "RealTek RTL8211B",
.uid = 0x1cc912,
.mask = 0xff,
@@ -421,7 +421,7 @@ static struct phy_driver RTL8211B_driver = {
 };
 
 /* Support for RTL8211E-VB-CG, RTL8211E-VL-CG and RTL8211EG-VB-CG PHYs */
-static struct phy_driver RTL8211E_driver = {
+U_BOOT_PHY_DRIVER(rtl8211e) = {
.name = "RealTek RTL8211E",
.uid = 0x1cc915,
.mask = 0xff,
@@ -433,7 +433,7 @@ static struct phy_driver RTL8211E_driver = {
 };
 
 /* Support for RTL8211DN PHY */
-static struct phy_driver RTL8211DN_driver = {
+U_BOOT_PHY_DRIVER(rtl8211dn) = {
.name = "RealTek RTL8211DN",
.uid = 0x1cc914,
.mask = 0xff,
@@ -444,7 +444,7 @@ static struct phy_driver RTL8211DN_driver = {
 };
 
 /* Support for RTL8211F PHY */
-static struct phy_driver RTL8211F_driver = {
+U_BOOT_PHY_DRIVER(rtl8211f) = {
.name = "RealTek RTL8211F",
.uid = 0x1cc916,
.mask = 0xff,
@@ -458,7 +458,7 @@ static struct phy_driver RTL8211F_driver = {
 };
 
 /* Support for RTL8201F PHY */
-static struct phy_driver RTL8201F_driver = {
+U_BOOT_PHY_DRIVER(rtl8201f) = {
.name = "RealTek RTL8201F 10/100Mbps Ethernet",
.uid = 0x1cc816,
.mask = 0xff,
@@ -468,14 +468,3 @@ static struct phy_driver RTL8201F_driver = {
.startup = _startup,
.shutdown = _shutdown,
 };
-
-int phy_realtek_init(void)
-{
-   phy_register(_driver);
-   phy_register(_driver);
-   phy_register(_driver);
-   phy_register(_driver);
-   phy_register(_driver);
-
-   return 0;
-}
diff --git a/include/phy.h b/include/phy.h
index bc42a522ea6..24a880ed2fb 100644
--- a/include/phy.h
+++ b/include/phy.h
@@ -315,7 +315,6 @@ int gen10g_startup(struct phy_device *phydev);
 int gen10g_shutdown(struct phy_device *phydev);
 int gen10g_discover_mmds(struct phy_device *phydev);
 
-int phy_realtek_init(void);
 int phy_smsc_init(void);
 int phy_teranetics_init(void);
 int phy_ti_init(void);
-- 
2.39.2



[PATCH 41/41] net: phy: Only call phy_init() on systems needing manual relocation

2023-03-19 Thread Marek Vasut
The phy_init() is now used only to perform manual relocation of PHY
driver callbacks. Wrap it in ifdeffery and only call it on systems
which still require manual relocation, i.e. m68k .

Signed-off-by: Marek Vasut 
---
Cc: "Ariel D'Alessandro" 
Cc: "Cédric Le Goater" 
Cc: "Marek Behún" 
Cc: Alex Nemirovsky 
Cc: Haolin Li 
Cc: Heinrich Schuchardt 
Cc: Joe Hershberger 
Cc: Joel Stanley 
Cc: Josua Mayer 
Cc: Marek Vasut 
Cc: Michael Trimarchi 
Cc: Michal Simek 
Cc: Nate Drude 
Cc: Neil Armstrong 
Cc: Radu Pirea 
Cc: Ramon Fried 
Cc: Samuel Mendoza-Jonas 
Cc: Stefan Roese 
Cc: T Karthik Reddy 
Cc: Tim Harvey 
Cc: Vladimir Oltean 
Cc: u-boot-amlo...@groups.io
---
 drivers/net/phy/phy.c | 4 ++--
 net/eth_common.c  | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index 61603f28179..9b0e497f223 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -463,9 +463,9 @@ U_BOOT_PHY_DRIVER(genphy) = {
.shutdown   = genphy_shutdown,
 };
 
+#ifdef CONFIG_NEEDS_MANUAL_RELOC
 int phy_init(void)
 {
-#ifdef CONFIG_NEEDS_MANUAL_RELOC
const int ll_n_ents = ll_entry_count(struct phy_driver, phy_driver);
struct phy_driver *drv, *ll_entry;
 
@@ -489,10 +489,10 @@ int phy_init(void)
if (drv->write_mmd)
drv->write_mmd += gd->reloc_off;
}
-#endif
 
return 0;
 }
+#endif
 
 int phy_set_supported(struct phy_device *phydev, u32 max_speed)
 {
diff --git a/net/eth_common.c b/net/eth_common.c
index 82d527abba6..c94a7ba6ae7 100644
--- a/net/eth_common.c
+++ b/net/eth_common.c
@@ -37,7 +37,7 @@ void eth_common_init(void)
miiphy_init();
 #endif
 
-#ifdef CONFIG_PHYLIB
+#if defined(CONFIG_NEEDS_MANUAL_RELOC) && defined(CONFIG_PHYLIB)
phy_init();
 #endif
 #endif
-- 
2.39.2



[PATCH 17/41] net: phy: lxt: Convert to U_BOOT_PHY_DRIVER()

2023-03-19 Thread Marek Vasut
Convert PHY driver to U_BOOT_PHY_DRIVER() macro and drop phy_register() init 
call.

Converted using sed
"s@^static struct phy_driver \(.*\)_driver = \+{@U_BOOT_PHY_DRIVER(\L\1) = {"

Signed-off-by: Marek Vasut 
---
Cc: "Ariel D'Alessandro" 
Cc: "Cédric Le Goater" 
Cc: "Marek Behún" 
Cc: Alex Nemirovsky 
Cc: Haolin Li 
Cc: Heinrich Schuchardt 
Cc: Joe Hershberger 
Cc: Joel Stanley 
Cc: Josua Mayer 
Cc: Marek Vasut 
Cc: Michael Trimarchi 
Cc: Michal Simek 
Cc: Nate Drude 
Cc: Neil Armstrong 
Cc: Radu Pirea 
Cc: Ramon Fried 
Cc: Samuel Mendoza-Jonas 
Cc: Stefan Roese 
Cc: T Karthik Reddy 
Cc: Tim Harvey 
Cc: Vladimir Oltean 
Cc: u-boot-amlo...@groups.io
---
 drivers/net/phy/lxt.c | 9 +
 drivers/net/phy/phy.c | 3 ---
 include/phy.h | 1 -
 3 files changed, 1 insertion(+), 12 deletions(-)

diff --git a/drivers/net/phy/lxt.c b/drivers/net/phy/lxt.c
index 2618deb0096..20940033a38 100644
--- a/drivers/net/phy/lxt.c
+++ b/drivers/net/phy/lxt.c
@@ -58,7 +58,7 @@ static int lxt971_startup(struct phy_device *phydev)
return lxt971_parse_status(phydev);
 }
 
-static struct phy_driver LXT971_driver = {
+U_BOOT_PHY_DRIVER(lxt971) = {
.name = "LXT971",
.uid = 0x1378e0,
.mask = 0xf0,
@@ -67,10 +67,3 @@ static struct phy_driver LXT971_driver = {
.startup = _startup,
.shutdown = _shutdown,
 };
-
-int phy_lxt_init(void)
-{
-   phy_register(_driver);
-
-   return 0;
-}
diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index 5b6e6294377..e2e31773f6a 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -514,9 +514,6 @@ int phy_init(void)
phy_drv_reloc(drv);
 #endif
 
-#ifdef CONFIG_PHY_LXT
-   phy_lxt_init();
-#endif
 #ifdef CONFIG_PHY_MARVELL
phy_marvell_init();
 #endif
diff --git a/include/phy.h b/include/phy.h
index 3bc4a0de724..a309056ce77 100644
--- a/include/phy.h
+++ b/include/phy.h
@@ -315,7 +315,6 @@ int gen10g_startup(struct phy_device *phydev);
 int gen10g_shutdown(struct phy_device *phydev);
 int gen10g_discover_mmds(struct phy_device *phydev);
 
-int phy_lxt_init(void);
 int phy_marvell_init(void);
 int phy_micrel_ksz8xxx_init(void);
 int phy_micrel_ksz90x1_init(void);
-- 
2.39.2



[PATCH 21/41] net: phy: meson-gxl: Convert to U_BOOT_PHY_DRIVER()

2023-03-19 Thread Marek Vasut
Convert PHY driver to U_BOOT_PHY_DRIVER() macro and drop phy_register() init 
call.

Converted using sed
"s@^static struct phy_driver \(.*\)_driver = \+{@U_BOOT_PHY_DRIVER(\L\1) = {"

Signed-off-by: Marek Vasut 
---
Cc: "Ariel D'Alessandro" 
Cc: "Cédric Le Goater" 
Cc: "Marek Behún" 
Cc: Alex Nemirovsky 
Cc: Haolin Li 
Cc: Heinrich Schuchardt 
Cc: Joe Hershberger 
Cc: Joel Stanley 
Cc: Josua Mayer 
Cc: Marek Vasut 
Cc: Michael Trimarchi 
Cc: Michal Simek 
Cc: Nate Drude 
Cc: Neil Armstrong 
Cc: Radu Pirea 
Cc: Ramon Fried 
Cc: Samuel Mendoza-Jonas 
Cc: Stefan Roese 
Cc: T Karthik Reddy 
Cc: Tim Harvey 
Cc: Vladimir Oltean 
Cc: u-boot-amlo...@groups.io
---
 drivers/net/phy/meson-gxl.c | 9 +
 drivers/net/phy/phy.c   | 3 ---
 include/phy.h   | 1 -
 3 files changed, 1 insertion(+), 12 deletions(-)

diff --git a/drivers/net/phy/meson-gxl.c b/drivers/net/phy/meson-gxl.c
index 753ca727686..b49c9b5f495 100644
--- a/drivers/net/phy/meson-gxl.c
+++ b/drivers/net/phy/meson-gxl.c
@@ -124,7 +124,7 @@ static int meson_gxl_phy_config(struct phy_device *phydev)
return genphy_config(phydev);
 }
 
-static struct phy_driver meson_gxl_phy_driver = {
+U_BOOT_PHY_DRIVER(meson_gxl_phy) = {
.name = "Meson GXL Internal PHY",
.uid = 0x01814400,
.mask = 0xfff0,
@@ -133,10 +133,3 @@ static struct phy_driver meson_gxl_phy_driver = {
.startup = _gxl_startup,
.shutdown = _shutdown,
 };
-
-int phy_meson_gxl_init(void)
-{
-   phy_register(_gxl_phy_driver);
-
-   return 0;
-}
diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index 4747011cda2..27cc9f5ec60 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -514,9 +514,6 @@ int phy_init(void)
phy_drv_reloc(drv);
 #endif
 
-#ifdef CONFIG_PHY_MESON_GXL
-   phy_meson_gxl_init();
-#endif
 #ifdef CONFIG_PHY_NATSEMI
phy_natsemi_init();
 #endif
diff --git a/include/phy.h b/include/phy.h
index 570524a21f5..f69f379fc2b 100644
--- a/include/phy.h
+++ b/include/phy.h
@@ -315,7 +315,6 @@ int gen10g_startup(struct phy_device *phydev);
 int gen10g_shutdown(struct phy_device *phydev);
 int gen10g_discover_mmds(struct phy_device *phydev);
 
-int phy_meson_gxl_init(void);
 int phy_natsemi_init(void);
 int phy_nxp_c45_tja11xx_init(void);
 int phy_nxp_tja11xx_init(void);
-- 
2.39.2



[PATCH 38/41] net: phy: Drop static phy_drivers list

2023-03-19 Thread Marek Vasut
The static phy_drivers list is superseded by linker list of struct phy_drivers
now that all drivers have been converted to the later. Drop the phy_drivers
list as well as list_head from struct phy_driver.

Signed-off-by: Marek Vasut 
---
Cc: "Ariel D'Alessandro" 
Cc: "Cédric Le Goater" 
Cc: "Marek Behún" 
Cc: Alex Nemirovsky 
Cc: Haolin Li 
Cc: Heinrich Schuchardt 
Cc: Joe Hershberger 
Cc: Joel Stanley 
Cc: Josua Mayer 
Cc: Marek Vasut 
Cc: Michael Trimarchi 
Cc: Michal Simek 
Cc: Nate Drude 
Cc: Neil Armstrong 
Cc: Radu Pirea 
Cc: Ramon Fried 
Cc: Samuel Mendoza-Jonas 
Cc: Stefan Roese 
Cc: T Karthik Reddy 
Cc: Tim Harvey 
Cc: Vladimir Oltean 
Cc: u-boot-amlo...@groups.io
---
 drivers/net/phy/phy.c | 26 ++
 include/phy.h |  2 --
 2 files changed, 2 insertions(+), 26 deletions(-)

diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index bd9c576f459..f4aa1f664cb 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -463,8 +463,6 @@ U_BOOT_PHY_DRIVER(genphy) = {
.shutdown   = genphy_shutdown,
 };
 
-static LIST_HEAD(phy_drivers);
-
 #ifdef CONFIG_NEEDS_MANUAL_RELOC
 static void phy_drv_reloc(struct phy_driver *drv)
 {
@@ -493,16 +491,6 @@ int phy_init(void)
const int ll_n_ents = ll_entry_count(struct phy_driver, phy_driver);
struct phy_driver *drv, *ll_entry;
 
-   /*
-* The pointers inside phy_drivers also needs to be updated incase of
-* manual reloc, without which these points to some invalid
-* pre reloc address and leads to invalid accesses, hangs.
-*/
-   struct list_head *head = _drivers;
-
-   head->next = (void *)head->next + gd->reloc_off;
-   head->prev = (void *)head->prev + gd->reloc_off;
-
/* Perform manual relocation on linker list based PHY drivers */
ll_entry = ll_entry_start(struct phy_driver, phy_driver);
for (drv = ll_entry; drv != ll_entry + ll_n_ents; drv++)
@@ -514,9 +502,6 @@ int phy_init(void)
 
 int phy_register(struct phy_driver *drv)
 {
-   INIT_LIST_HEAD(>list);
-   list_add_tail(>list, _drivers);
-
 #ifdef CONFIG_NEEDS_MANUAL_RELOC
phy_drv_reloc(drv);
 #endif
@@ -575,16 +560,9 @@ static struct phy_driver *generic_for_phy(struct 
phy_device *phydev)
 static struct phy_driver *get_phy_driver(struct phy_device *phydev)
 {
const int ll_n_ents = ll_entry_count(struct phy_driver, phy_driver);
-   struct phy_driver *ll_entry;
-   struct list_head *entry;
int phy_id = phydev->phy_id;
-   struct phy_driver *drv = NULL;
-
-   list_for_each(entry, _drivers) {
-   drv = list_entry(entry, struct phy_driver, list);
-   if ((drv->uid & drv->mask) == (phy_id & drv->mask))
-   return drv;
-   }
+   struct phy_driver *ll_entry;
+   struct phy_driver *drv;
 
ll_entry = ll_entry_start(struct phy_driver, phy_driver);
for (drv = ll_entry; drv != ll_entry + ll_n_ents; drv++)
diff --git a/include/phy.h b/include/phy.h
index 5f4967cb150..5e8ae5e29aa 100644
--- a/include/phy.h
+++ b/include/phy.h
@@ -125,8 +125,6 @@ struct phy_driver {
int (*write_mmd)(struct phy_device *phydev, int devad, int reg,
 u16 val);
 
-   struct list_head list;
-
/* driver private data */
ulong data;
 };
-- 
2.39.2



[PATCH 19/41] net: phy: ksz8xxx: Convert to U_BOOT_PHY_DRIVER()

2023-03-19 Thread Marek Vasut
Convert PHY driver to U_BOOT_PHY_DRIVER() macro and drop phy_register() init 
call.

Converted using sed
"s@^static struct phy_driver \(.*\)_driver = \+{@U_BOOT_PHY_DRIVER(\L\1) = {"

Signed-off-by: Marek Vasut 
---
Cc: "Ariel D'Alessandro" 
Cc: "Cédric Le Goater" 
Cc: "Marek Behún" 
Cc: Alex Nemirovsky 
Cc: Haolin Li 
Cc: Heinrich Schuchardt 
Cc: Joe Hershberger 
Cc: Joel Stanley 
Cc: Josua Mayer 
Cc: Marek Vasut 
Cc: Michael Trimarchi 
Cc: Michal Simek 
Cc: Nate Drude 
Cc: Neil Armstrong 
Cc: Radu Pirea 
Cc: Ramon Fried 
Cc: Samuel Mendoza-Jonas 
Cc: Stefan Roese 
Cc: T Karthik Reddy 
Cc: Tim Harvey 
Cc: Vladimir Oltean 
Cc: u-boot-amlo...@groups.io
---
 drivers/net/phy/micrel_ksz8xxx.c | 29 -
 drivers/net/phy/phy.c|  3 ---
 include/phy.h|  1 -
 3 files changed, 8 insertions(+), 25 deletions(-)

diff --git a/drivers/net/phy/micrel_ksz8xxx.c b/drivers/net/phy/micrel_ksz8xxx.c
index 60d42fe9840..b0f3abcb037 100644
--- a/drivers/net/phy/micrel_ksz8xxx.c
+++ b/drivers/net/phy/micrel_ksz8xxx.c
@@ -14,7 +14,7 @@
 #include 
 #include 
 
-static struct phy_driver KSZ804_driver = {
+U_BOOT_PHY_DRIVER(ksz804) = {
.name = "Micrel KSZ804",
.uid = 0x221510,
.mask = 0xf0,
@@ -44,7 +44,7 @@ static int ksz_genconfig_bcastoff(struct phy_device *phydev)
return genphy_config(phydev);
 }
 
-static struct phy_driver KSZ8031_driver = {
+U_BOOT_PHY_DRIVER(ksz8031) = {
.name = "Micrel KSZ8021/KSZ8031",
.uid = 0x221550,
.mask = 0xf0,
@@ -72,7 +72,7 @@ static int ksz8051_config(struct phy_device *phydev)
return genphy_config(phydev);
 }
 
-static struct phy_driver KSZ8051_driver = {
+U_BOOT_PHY_DRIVER(ksz8051) = {
.name = "Micrel KSZ8051",
.uid = 0x221550,
.mask = 0xf0,
@@ -87,7 +87,7 @@ static int ksz8061_config(struct phy_device *phydev)
return phy_write(phydev, MDIO_MMD_PMAPMD, MDIO_DEVID1, 0xB61A);
 }
 
-static struct phy_driver KSZ8061_driver = {
+U_BOOT_PHY_DRIVER(ksz8061) = {
.name = "Micrel KSZ8061",
.uid = 0x00221570,
.mask = 0xf0,
@@ -115,7 +115,7 @@ static int ksz8081_config(struct phy_device *phydev)
return genphy_config(phydev);
 }
 
-static struct phy_driver KSZ8081_driver = {
+U_BOOT_PHY_DRIVER(ksz8081) = {
.name = "Micrel KSZ8081",
.uid = 0x221560,
.mask = 0xf0,
@@ -172,7 +172,7 @@ static int ksz8895_startup(struct phy_device *phydev)
return 0;
 }
 
-static struct phy_driver ksz8895_driver = {
+U_BOOT_PHY_DRIVER(ksz8895) = {
.name = "Micrel KSZ8895/KSZ8864",
.uid  = 0x221450,
.mask = 0xe1,
@@ -185,7 +185,7 @@ static struct phy_driver ksz8895_driver = {
 /* Micrel used the exact same model number for the KSZ9021,
  * so the revision number is used to distinguish them.
  */
-static struct phy_driver KS8721_driver = {
+U_BOOT_PHY_DRIVER(ks8721) = {
.name = "Micrel KS8721BL",
.uid = 0x221618,
.mask = 0xfc,
@@ -210,7 +210,7 @@ static int ksz886x_startup(struct phy_device *phydev)
return 0;
 }
 
-static struct phy_driver ksz886x_driver = {
+U_BOOT_PHY_DRIVER(ksz886x) = {
.name = "Micrel KSZ886x Switch",
.uid  = 0x00221430,
.mask = 0xf0,
@@ -219,16 +219,3 @@ static struct phy_driver ksz886x_driver = {
.startup = _startup,
.shutdown = _shutdown,
 };
-
-int phy_micrel_ksz8xxx_init(void)
-{
-   phy_register(_driver);
-   phy_register(_driver);
-   phy_register(_driver);
-   phy_register(_driver);
-   phy_register(_driver);
-   phy_register(_driver);
-   phy_register(_driver);
-   phy_register(_driver);
-   return 0;
-}
diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index efc75808ead..b2b2d6edfa7 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -514,9 +514,6 @@ int phy_init(void)
phy_drv_reloc(drv);
 #endif
 
-#ifdef CONFIG_PHY_MICREL_KSZ8XXX
-   phy_micrel_ksz8xxx_init();
-#endif
 #ifdef CONFIG_PHY_MICREL_KSZ90X1
phy_micrel_ksz90x1_init();
 #endif
diff --git a/include/phy.h b/include/phy.h
index 77e46ebac83..27d9742c6c4 100644
--- a/include/phy.h
+++ b/include/phy.h
@@ -315,7 +315,6 @@ int gen10g_startup(struct phy_device *phydev);
 int gen10g_shutdown(struct phy_device *phydev);
 int gen10g_discover_mmds(struct phy_device *phydev);
 
-int phy_micrel_ksz8xxx_init(void);
 int phy_micrel_ksz90x1_init(void);
 int phy_meson_gxl_init(void);
 int phy_natsemi_init(void);
-- 
2.39.2



[PATCH 30/41] net: phy: xilinx: Convert to U_BOOT_PHY_DRIVER()

2023-03-19 Thread Marek Vasut
Convert PHY driver to U_BOOT_PHY_DRIVER() macro and drop phy_register() init 
call.

Converted using sed
"s@^static struct phy_driver \(.*\)_driver = \+{@U_BOOT_PHY_DRIVER(\L\1) = {"

Signed-off-by: Marek Vasut 
---
Cc: "Ariel D'Alessandro" 
Cc: "Cédric Le Goater" 
Cc: "Marek Behún" 
Cc: Alex Nemirovsky 
Cc: Haolin Li 
Cc: Heinrich Schuchardt 
Cc: Joe Hershberger 
Cc: Joel Stanley 
Cc: Josua Mayer 
Cc: Marek Vasut 
Cc: Michael Trimarchi 
Cc: Michal Simek 
Cc: Nate Drude 
Cc: Neil Armstrong 
Cc: Radu Pirea 
Cc: Ramon Fried 
Cc: Samuel Mendoza-Jonas 
Cc: Stefan Roese 
Cc: T Karthik Reddy 
Cc: Tim Harvey 
Cc: Vladimir Oltean 
Cc: u-boot-amlo...@groups.io
---
 drivers/net/phy/phy.c|  3 ---
 drivers/net/phy/xilinx_phy.c | 10 +-
 include/phy.h|  1 -
 3 files changed, 1 insertion(+), 13 deletions(-)

diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index fff1d669fcd..b85d5c4566d 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -514,9 +514,6 @@ int phy_init(void)
phy_drv_reloc(drv);
 #endif
 
-#ifdef CONFIG_PHY_XILINX
-   phy_xilinx_init();
-#endif
 #ifdef CONFIG_PHY_XWAY
phy_xway_init();
 #endif
diff --git a/drivers/net/phy/xilinx_phy.c b/drivers/net/phy/xilinx_phy.c
index 39dbfdb7da8..1df639d6f44 100644
--- a/drivers/net/phy/xilinx_phy.c
+++ b/drivers/net/phy/xilinx_phy.c
@@ -127,7 +127,7 @@ static int xilinxphy_config(struct phy_device *phydev)
return 0;
 }
 
-static struct phy_driver xilinxphy_driver = {
+U_BOOT_PHY_DRIVER(xilinxphy) = {
.uid = XILINX_PHY_ID,
.mask = XILINX_PHY_ID_MASK,
.name = "Xilinx PCS/PMA PHY",
@@ -136,11 +136,3 @@ static struct phy_driver xilinxphy_driver = {
.startup = _startup,
.shutdown = _shutdown,
 };
-
-int phy_xilinx_init(void)
-{
-   debug("%s\n", __func__);
-   phy_register(_driver);
-
-   return 0;
-}
diff --git a/include/phy.h b/include/phy.h
index 74f3ada2491..e128ddf0037 100644
--- a/include/phy.h
+++ b/include/phy.h
@@ -315,7 +315,6 @@ int gen10g_startup(struct phy_device *phydev);
 int gen10g_shutdown(struct phy_device *phydev);
 int gen10g_discover_mmds(struct phy_device *phydev);
 
-int phy_xilinx_init(void);
 int phy_xway_init(void);
 int phy_mscc_init(void);
 int phy_fixed_init(void);
-- 
2.39.2



[PATCH 16/41] net: phy: et1011c: Convert to U_BOOT_PHY_DRIVER()

2023-03-19 Thread Marek Vasut
Convert PHY driver to U_BOOT_PHY_DRIVER() macro and drop phy_register() init 
call.

Converted using sed
"s@^static struct phy_driver \(.*\)_driver = \+{@U_BOOT_PHY_DRIVER(\L\1) = {"

Signed-off-by: Marek Vasut 
---
Cc: "Ariel D'Alessandro" 
Cc: "Cédric Le Goater" 
Cc: "Marek Behún" 
Cc: Alex Nemirovsky 
Cc: Haolin Li 
Cc: Heinrich Schuchardt 
Cc: Joe Hershberger 
Cc: Joel Stanley 
Cc: Josua Mayer 
Cc: Marek Vasut 
Cc: Michael Trimarchi 
Cc: Michal Simek 
Cc: Nate Drude 
Cc: Neil Armstrong 
Cc: Radu Pirea 
Cc: Ramon Fried 
Cc: Samuel Mendoza-Jonas 
Cc: Stefan Roese 
Cc: T Karthik Reddy 
Cc: Tim Harvey 
Cc: Vladimir Oltean 
Cc: u-boot-amlo...@groups.io
---
 drivers/net/phy/et1011c.c | 9 +
 drivers/net/phy/phy.c | 3 ---
 include/phy.h | 1 -
 3 files changed, 1 insertion(+), 12 deletions(-)

diff --git a/drivers/net/phy/et1011c.c b/drivers/net/phy/et1011c.c
index 7eff5ec7cac..fa4831427d5 100644
--- a/drivers/net/phy/et1011c.c
+++ b/drivers/net/phy/et1011c.c
@@ -87,7 +87,7 @@ static int et1011c_startup(struct phy_device *phydev)
return et1011c_parse_status(phydev);
 }
 
-static struct phy_driver et1011c_driver = {
+U_BOOT_PHY_DRIVER(et1011c) = {
.name   = "ET1011C",
.uid= 0x0282f014,
.mask   = 0xfff0,
@@ -95,10 +95,3 @@ static struct phy_driver et1011c_driver = {
.config = _config,
.startup= _startup,
 };
-
-int phy_et1011c_init(void)
-{
-   phy_register(_driver);
-
-   return 0;
-}
diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index 7312719cdbb..5b6e6294377 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -514,9 +514,6 @@ int phy_init(void)
phy_drv_reloc(drv);
 #endif
 
-#ifdef CONFIG_PHY_ET1011C
-   phy_et1011c_init();
-#endif
 #ifdef CONFIG_PHY_LXT
phy_lxt_init();
 #endif
diff --git a/include/phy.h b/include/phy.h
index 9e5a9196cbd..3bc4a0de724 100644
--- a/include/phy.h
+++ b/include/phy.h
@@ -315,7 +315,6 @@ int gen10g_startup(struct phy_device *phydev);
 int gen10g_shutdown(struct phy_device *phydev);
 int gen10g_discover_mmds(struct phy_device *phydev);
 
-int phy_et1011c_init(void);
 int phy_lxt_init(void);
 int phy_marvell_init(void);
 int phy_micrel_ksz8xxx_init(void);
-- 
2.39.2



[PATCH 33/41] net: phy: fixed: Convert to U_BOOT_PHY_DRIVER()

2023-03-19 Thread Marek Vasut
Convert PHY driver to U_BOOT_PHY_DRIVER() macro and drop phy_register() init 
call.

Converted using sed
"s@^static struct phy_driver \(.*\)_driver = \+{@U_BOOT_PHY_DRIVER(\L\1) = {"

Signed-off-by: Marek Vasut 
---
Cc: "Ariel D'Alessandro" 
Cc: "Cédric Le Goater" 
Cc: "Marek Behún" 
Cc: Alex Nemirovsky 
Cc: Haolin Li 
Cc: Heinrich Schuchardt 
Cc: Joe Hershberger 
Cc: Joel Stanley 
Cc: Josua Mayer 
Cc: Marek Vasut 
Cc: Michael Trimarchi 
Cc: Michal Simek 
Cc: Nate Drude 
Cc: Neil Armstrong 
Cc: Radu Pirea 
Cc: Ramon Fried 
Cc: Samuel Mendoza-Jonas 
Cc: Stefan Roese 
Cc: T Karthik Reddy 
Cc: Tim Harvey 
Cc: Vladimir Oltean 
Cc: u-boot-amlo...@groups.io
---
 drivers/net/phy/fixed.c | 8 +---
 drivers/net/phy/phy.c   | 3 ---
 include/phy.h   | 1 -
 3 files changed, 1 insertion(+), 11 deletions(-)

diff --git a/drivers/net/phy/fixed.c b/drivers/net/phy/fixed.c
index 1192915ee52..2f0823b8365 100644
--- a/drivers/net/phy/fixed.c
+++ b/drivers/net/phy/fixed.c
@@ -93,7 +93,7 @@ static int fixedphy_shutdown(struct phy_device *phydev)
return 0;
 }
 
-static struct phy_driver fixedphy_driver = {
+U_BOOT_PHY_DRIVER(fixedphy) = {
.uid= PHY_FIXED_ID,
.mask   = 0x,
.name   = "Fixed PHY",
@@ -103,9 +103,3 @@ static struct phy_driver fixedphy_driver = {
.startup= fixedphy_startup,
.shutdown   = fixedphy_shutdown,
 };
-
-int phy_fixed_init(void)
-{
-   phy_register(_driver);
-   return 0;
-}
diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index c20e750aa16..245357c31dc 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -514,9 +514,6 @@ int phy_init(void)
phy_drv_reloc(drv);
 #endif
 
-#ifdef CONFIG_PHY_FIXED
-   phy_fixed_init();
-#endif
 #ifdef CONFIG_PHY_NCSI
phy_ncsi_init();
 #endif
diff --git a/include/phy.h b/include/phy.h
index e4a3e10c48b..9cabfeedec8 100644
--- a/include/phy.h
+++ b/include/phy.h
@@ -315,7 +315,6 @@ int gen10g_startup(struct phy_device *phydev);
 int gen10g_shutdown(struct phy_device *phydev);
 int gen10g_discover_mmds(struct phy_device *phydev);
 
-int phy_fixed_init(void);
 int phy_ncsi_init(void);
 int phy_xilinx_gmii2rgmii_init(void);
 
-- 
2.39.2



[PATCH 22/41] net: phy: natsemi: Convert to U_BOOT_PHY_DRIVER()

2023-03-19 Thread Marek Vasut
Convert PHY driver to U_BOOT_PHY_DRIVER() macro and drop phy_register() init 
call.

Converted using sed
"s@^static struct phy_driver \(.*\)_driver = \+{@U_BOOT_PHY_DRIVER(\L\1) = {"

Signed-off-by: Marek Vasut 
---
Cc: "Ariel D'Alessandro" 
Cc: "Cédric Le Goater" 
Cc: "Marek Behún" 
Cc: Alex Nemirovsky 
Cc: Haolin Li 
Cc: Heinrich Schuchardt 
Cc: Joe Hershberger 
Cc: Joel Stanley 
Cc: Josua Mayer 
Cc: Marek Vasut 
Cc: Michael Trimarchi 
Cc: Michal Simek 
Cc: Nate Drude 
Cc: Neil Armstrong 
Cc: Radu Pirea 
Cc: Ramon Fried 
Cc: Samuel Mendoza-Jonas 
Cc: Stefan Roese 
Cc: T Karthik Reddy 
Cc: Tim Harvey 
Cc: Vladimir Oltean 
Cc: u-boot-amlo...@groups.io
---
 drivers/net/phy/natsemi.c | 15 +++
 drivers/net/phy/phy.c |  3 ---
 include/phy.h |  1 -
 3 files changed, 3 insertions(+), 16 deletions(-)

diff --git a/drivers/net/phy/natsemi.c b/drivers/net/phy/natsemi.c
index efde4574deb..6b9e99ea115 100644
--- a/drivers/net/phy/natsemi.c
+++ b/drivers/net/phy/natsemi.c
@@ -33,7 +33,7 @@ static int dp83630_config(struct phy_device *phydev)
return 0;
 }
 
-static struct phy_driver DP83630_driver = {
+U_BOOT_PHY_DRIVER(dp83630) = {
.name = "NatSemi DP83630",
.uid = 0x20005ce1,
.mask = 0xfff0,
@@ -103,7 +103,7 @@ static int dp83865_startup(struct phy_device *phydev)
 }
 
 
-static struct phy_driver DP83865_driver = {
+U_BOOT_PHY_DRIVER(dp83865) = {
.name = "NatSemi DP83865",
.uid = 0x20005c70,
.mask = 0xfff0,
@@ -146,7 +146,7 @@ static int dp83848_startup(struct phy_device *phydev)
return dp83848_parse_status(phydev);
 }
 
-static struct phy_driver DP83848_driver = {
+U_BOOT_PHY_DRIVER(dp83848) = {
.name = "NatSemi DP83848",
.uid = 0x20005c90,
.mask = 0x2000ff90,
@@ -155,12 +155,3 @@ static struct phy_driver DP83848_driver = {
.startup = _startup,
.shutdown = _shutdown,
 };
-
-int phy_natsemi_init(void)
-{
-   phy_register(_driver);
-   phy_register(_driver);
-   phy_register(_driver);
-
-   return 0;
-}
diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index 27cc9f5ec60..3d6fc8080e5 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -514,9 +514,6 @@ int phy_init(void)
phy_drv_reloc(drv);
 #endif
 
-#ifdef CONFIG_PHY_NATSEMI
-   phy_natsemi_init();
-#endif
 #ifdef CONFIG_NXP_C45_TJA11XX_PHY
phy_nxp_c45_tja11xx_init();
 #endif
diff --git a/include/phy.h b/include/phy.h
index f69f379fc2b..647d23595d1 100644
--- a/include/phy.h
+++ b/include/phy.h
@@ -315,7 +315,6 @@ int gen10g_startup(struct phy_device *phydev);
 int gen10g_shutdown(struct phy_device *phydev);
 int gen10g_discover_mmds(struct phy_device *phydev);
 
-int phy_natsemi_init(void);
 int phy_nxp_c45_tja11xx_init(void);
 int phy_nxp_tja11xx_init(void);
 int phy_realtek_init(void);
-- 
2.39.2



[PATCH 13/41] net: phy: cortina: Convert to U_BOOT_PHY_DRIVER()

2023-03-19 Thread Marek Vasut
Convert PHY driver to U_BOOT_PHY_DRIVER() macro and drop phy_register() init 
call.

Converted using sed
"s@^static struct phy_driver \(.*\)_driver = \+{@U_BOOT_PHY_DRIVER(\L\1) = {"

Signed-off-by: Marek Vasut 
---
Cc: "Ariel D'Alessandro" 
Cc: "Cédric Le Goater" 
Cc: "Marek Behún" 
Cc: Alex Nemirovsky 
Cc: Haolin Li 
Cc: Heinrich Schuchardt 
Cc: Joe Hershberger 
Cc: Joel Stanley 
Cc: Josua Mayer 
Cc: Marek Vasut 
Cc: Michael Trimarchi 
Cc: Michal Simek 
Cc: Nate Drude 
Cc: Neil Armstrong 
Cc: Radu Pirea 
Cc: Ramon Fried 
Cc: Samuel Mendoza-Jonas 
Cc: Stefan Roese 
Cc: T Karthik Reddy 
Cc: Tim Harvey 
Cc: Vladimir Oltean 
Cc: u-boot-amlo...@groups.io
---
 drivers/net/phy/cortina.c | 11 ++-
 drivers/net/phy/phy.c |  3 ---
 include/phy.h |  1 -
 3 files changed, 2 insertions(+), 13 deletions(-)

diff --git a/drivers/net/phy/cortina.c b/drivers/net/phy/cortina.c
index df5a73d6112..1cf8b28f582 100644
--- a/drivers/net/phy/cortina.c
+++ b/drivers/net/phy/cortina.c
@@ -382,7 +382,7 @@ int cs4223_startup(struct phy_device *phydev)
return 0;
 }
 
-static struct phy_driver cs4340_driver = {
+U_BOOT_PHY_DRIVER(cs4340) = {
.name = "Cortina CS4315/CS4340",
.uid = PHY_UID_CS4340,
.mask = 0xfff0,
@@ -396,7 +396,7 @@ static struct phy_driver cs4340_driver = {
.shutdown = _shutdown,
 };
 
-static struct phy_driver cs4223_driver = {
+U_BOOT_PHY_DRIVER(cs4223) = {
.name = "Cortina CS4223",
.uid = PHY_UID_CS4223,
.mask = 0x000f,
@@ -409,13 +409,6 @@ static struct phy_driver cs4223_driver = {
.shutdown = _shutdown,
 };
 
-int phy_cortina_init(void)
-{
-   phy_register(_driver);
-   phy_register(_driver);
-   return 0;
-}
-
 int get_phy_id(struct mii_dev *bus, int addr, int devad, u32 *phy_id)
 {
int phy_reg;
diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index 4446902ab63..d595290dd4b 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -517,9 +517,6 @@ int phy_init(void)
 #ifdef CONFIG_MV88E61XX_SWITCH
phy_mv88e61xx_init();
 #endif
-#ifdef CONFIG_PHY_CORTINA
-   phy_cortina_init();
-#endif
 #ifdef CONFIG_PHY_DAVICOM
phy_davicom_init();
 #endif
diff --git a/include/phy.h b/include/phy.h
index 50a53982810..797139bf681 100644
--- a/include/phy.h
+++ b/include/phy.h
@@ -316,7 +316,6 @@ int gen10g_shutdown(struct phy_device *phydev);
 int gen10g_discover_mmds(struct phy_device *phydev);
 
 int phy_mv88e61xx_init(void);
-int phy_cortina_init(void);
 int phy_davicom_init(void);
 int phy_et1011c_init(void);
 int phy_lxt_init(void);
-- 
2.39.2



[PATCH 39/41] net: phy: Drop unused phy_register()

2023-03-19 Thread Marek Vasut
This function is no longer used, drop it.

Signed-off-by: Marek Vasut 
---
Cc: "Ariel D'Alessandro" 
Cc: "Cédric Le Goater" 
Cc: "Marek Behún" 
Cc: Alex Nemirovsky 
Cc: Haolin Li 
Cc: Heinrich Schuchardt 
Cc: Joe Hershberger 
Cc: Joel Stanley 
Cc: Josua Mayer 
Cc: Marek Vasut 
Cc: Michael Trimarchi 
Cc: Michal Simek 
Cc: Nate Drude 
Cc: Neil Armstrong 
Cc: Radu Pirea 
Cc: Ramon Fried 
Cc: Samuel Mendoza-Jonas 
Cc: Stefan Roese 
Cc: T Karthik Reddy 
Cc: Tim Harvey 
Cc: Vladimir Oltean 
Cc: u-boot-amlo...@groups.io
---
 drivers/net/phy/phy.c | 8 
 include/phy.h | 1 -
 2 files changed, 9 deletions(-)

diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index f4aa1f664cb..15da9a80de2 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -500,14 +500,6 @@ int phy_init(void)
return 0;
 }
 
-int phy_register(struct phy_driver *drv)
-{
-#ifdef CONFIG_NEEDS_MANUAL_RELOC
-   phy_drv_reloc(drv);
-#endif
-   return 0;
-}
-
 int phy_set_supported(struct phy_device *phydev, u32 max_speed)
 {
/* The default values for phydev->supported are provided by the PHY
diff --git a/include/phy.h b/include/phy.h
index 5e8ae5e29aa..4a9de461152 100644
--- a/include/phy.h
+++ b/include/phy.h
@@ -293,7 +293,6 @@ int phy_clear_bits_mmd(struct phy_device *phydev, int 
devad, u32 regnum, u16 val
 int phy_startup(struct phy_device *phydev);
 int phy_config(struct phy_device *phydev);
 int phy_shutdown(struct phy_device *phydev);
-int phy_register(struct phy_driver *drv);
 int phy_set_supported(struct phy_device *phydev, u32 max_speed);
 int phy_modify(struct phy_device *phydev, int devad, int regnum, u16 mask,
   u16 set);
-- 
2.39.2



[PATCH 29/41] net: phy: vitesse: Convert to U_BOOT_PHY_DRIVER()

2023-03-19 Thread Marek Vasut
Convert PHY driver to U_BOOT_PHY_DRIVER() macro and drop phy_register() init 
call.

Converted using sed
"s@^static struct phy_driver \(.*\)_driver = \+{@U_BOOT_PHY_DRIVER(\L\1) = {"

Signed-off-by: Marek Vasut 
---
Cc: "Ariel D'Alessandro" 
Cc: "Cédric Le Goater" 
Cc: "Marek Behún" 
Cc: Alex Nemirovsky 
Cc: Haolin Li 
Cc: Heinrich Schuchardt 
Cc: Joe Hershberger 
Cc: Joel Stanley 
Cc: Josua Mayer 
Cc: Marek Vasut 
Cc: Michael Trimarchi 
Cc: Michal Simek 
Cc: Nate Drude 
Cc: Neil Armstrong 
Cc: Radu Pirea 
Cc: Ramon Fried 
Cc: Samuel Mendoza-Jonas 
Cc: Stefan Roese 
Cc: T Karthik Reddy 
Cc: Tim Harvey 
Cc: Vladimir Oltean 
Cc: u-boot-amlo...@groups.io
---
 drivers/net/phy/phy.c |  3 ---
 drivers/net/phy/vitesse.c | 45 +++
 include/phy.h |  1 -
 3 files changed, 13 insertions(+), 36 deletions(-)

diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index 404d61c5ab3..fff1d669fcd 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -514,9 +514,6 @@ int phy_init(void)
phy_drv_reloc(drv);
 #endif
 
-#ifdef CONFIG_PHY_VITESSE
-   phy_vitesse_init();
-#endif
 #ifdef CONFIG_PHY_XILINX
phy_xilinx_init();
 #endif
diff --git a/drivers/net/phy/vitesse.c b/drivers/net/phy/vitesse.c
index eca26c98938..c5cf0d7dfbd 100644
--- a/drivers/net/phy/vitesse.c
+++ b/drivers/net/phy/vitesse.c
@@ -293,7 +293,7 @@ static int vsc8664_config(struct phy_device *phydev)
return 0;
 }
 
-static struct phy_driver VSC8211_driver = {
+U_BOOT_PHY_DRIVER(vsc8211) = {
.name   = "Vitesse VSC8211",
.uid= 0xfc4b0,
.mask   = 0x0,
@@ -303,7 +303,7 @@ static struct phy_driver VSC8211_driver = {
.shutdown = _shutdown,
 };
 
-static struct phy_driver VSC8221_driver = {
+U_BOOT_PHY_DRIVER(vsc8221) = {
.name = "Vitesse VSC8221",
.uid = 0xfc550,
.mask = 0x0,
@@ -313,7 +313,7 @@ static struct phy_driver VSC8221_driver = {
.shutdown = _shutdown,
 };
 
-static struct phy_driver VSC8244_driver = {
+U_BOOT_PHY_DRIVER(vsc8244) = {
.name = "Vitesse VSC8244",
.uid = 0xfc6c0,
.mask = 0x0,
@@ -323,7 +323,7 @@ static struct phy_driver VSC8244_driver = {
.shutdown = _shutdown,
 };
 
-static struct phy_driver VSC8234_driver = {
+U_BOOT_PHY_DRIVER(vsc8234) = {
.name = "Vitesse VSC8234",
.uid = 0xfc620,
.mask = 0x0,
@@ -333,7 +333,7 @@ static struct phy_driver VSC8234_driver = {
.shutdown = _shutdown,
 };
 
-static struct phy_driver VSC8574_driver = {
+U_BOOT_PHY_DRIVER(vsc8574) = {
.name = "Vitesse VSC8574",
.uid = 0x704a0,
.mask = 0x0,
@@ -343,7 +343,7 @@ static struct phy_driver VSC8574_driver = {
.shutdown = _shutdown,
 };
 
-static struct phy_driver VSC8514_driver = {
+U_BOOT_PHY_DRIVER(vsc8514) = {
.name = "Vitesse VSC8514",
.uid = 0x70670,
.mask = 0x0,
@@ -353,7 +353,7 @@ static struct phy_driver VSC8514_driver = {
.shutdown = _shutdown,
 };
 
-static struct phy_driver VSC8584_driver = {
+U_BOOT_PHY_DRIVER(vsc8584) = {
.name = "Vitesse VSC8584",
.uid = 0x707c0,
.mask = 0x0,
@@ -363,7 +363,7 @@ static struct phy_driver VSC8584_driver = {
.shutdown = _shutdown,
 };
 
-static struct phy_driver VSC8601_driver = {
+U_BOOT_PHY_DRIVER(vsc8601) = {
.name = "Vitesse VSC8601",
.uid = 0x70420,
.mask = 0x0,
@@ -373,7 +373,7 @@ static struct phy_driver VSC8601_driver = {
.shutdown = _shutdown,
 };
 
-static struct phy_driver VSC8641_driver = {
+U_BOOT_PHY_DRIVER(vsc8641) = {
.name = "Vitesse VSC8641",
.uid = 0x70430,
.mask = 0x0,
@@ -383,7 +383,7 @@ static struct phy_driver VSC8641_driver = {
.shutdown = _shutdown,
 };
 
-static struct phy_driver VSC8662_driver = {
+U_BOOT_PHY_DRIVER(vsc8662) = {
.name = "Vitesse VSC8662",
.uid = 0x70660,
.mask = 0x0,
@@ -393,7 +393,7 @@ static struct phy_driver VSC8662_driver = {
.shutdown = _shutdown,
 };
 
-static struct phy_driver VSC8664_driver = {
+U_BOOT_PHY_DRIVER(vsc8664) = {
.name = "Vitesse VSC8664",
.uid = 0x70660,
.mask = 0x0,
@@ -404,7 +404,7 @@ static struct phy_driver VSC8664_driver = {
 };
 
 /* Vitesse bought Cicada, so we'll put these here */
-static struct phy_driver cis8201_driver = {
+U_BOOT_PHY_DRIVER(cis8201) = {
.name = "CIS8201",
.uid = 0xfc410,
.mask = 0x0,
@@ -414,7 +414,7 @@ static struct phy_driver cis8201_driver = {
.shutdown = _shutdown,
 };
 
-static struct phy_driver cis8204_driver = {
+U_BOOT_PHY_DRIVER(cis8204) = {
.name = "Cicada Cis8204",
.uid = 0xfc440,
.mask = 0x0,
@@ -423,22 +423,3 @@ static struct phy_driver cis8204_driver = {
.startup = _startup,
.shutdown = _shutdown,
 };
-
-int phy_vitesse_init(void)
-{
-   

  1   2   >