Re: [PATCH] Fix neighbor discovery ethernet address saving

2024-05-13 Thread Vyacheslav V. Mitrofanov
Hello, Sean. 
I see. You are right.

Reviewed-by: Viacheslav Mitrofanov 


On Tue, 2024-05-07 at 22:16 -0700, Sean Edmond wrote:
> 
> Hi Vyachesla,
> 
> Let's start by saying neighbour discovery protocol is definitely
> working
> properly.  I'm only suggesting that it isn't properly caching the MAC
> address.  During IPv6 TFTP I observe that neighbour discovery is
> performed before every packet sent from client(u-boot)->server.
> 
> Here's a snapshot of what the packets from client(u-boot)<->server
> look
> like during IPv6 TFTP:
> -> neighbour solicitation
> <- neighbour advertisement
> -> read request
> <- Block 0
> -> neighbour solicitation
> <- neighbour advertisement
> -> ACK block 0
> <- Block 1
> -> neighbour solicitation
> <- neighbour advertisement
> -> ACK block 1
> - ... (continues for entire file transfer)
> 
> The neighbour discovery on every TX TFTP packet isn't required and
> results in degraded performance.  Note, when performing the test with
> IPv4, ARP is not performed before every TX packet.
> 
> Here's a description of the code flow (including my proposal):
> - net.c defines "u8 net_server_ethaddr[6];"
> - tftp_send()-> net_send_udp_packet6(net_server_ethaddr, ...)
> - in net_send_udp_packet6(), "net_nd_packet_mac = ether;"  (now,
> net_nd_packet_mac is pointing to net_server_ethaddr)
> - in ndisc_receive(), when NA is received the mac becomes available
> in
> neigh_eth_addr
> - My proposal is, "if pointer net_nd_packet_mac isn't NULL, copy this
> contents of neigh_eth_addr into net_nd_packet_mac"
> - For TFTP, my fix allows the server's MAC to get copied into
> net_server_ethaddr
> - on the next tftp_send(), in net_send_udp_packet6() neighbour
> discovery
> is skipped because "ether" isn't all zeros
> 
> The memcpy isn't dangerous, because it's copying the discovered mac
> address into the already allocated net_server_ethaddr (and it's
> checking
> to make sure that net_nd_packet_mac isn't NULL before copying).
> 
> Also, the current code serves no purpose.  The current code is, "if
> net_nd_packet_mac is NULL, set it to stack variable neigh_eth_addr,
> then
> set net_nd_packet_mac to NULL when there is no ND pending (the mac
> address doesn't get saved in net_server_ethaddr).
> 
> Sean
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> On 2024-05-05 2:40 a.m., Vyacheslav V. Mitrofanov wrote:
> > On Mon, 2024-04-29 at 11:51 -0700, seanedm...@linux.microsoft.com
> > wrote:
> > > s...@yadro.com<mailto:s...@yadro.com>
> > > 
> > > From: Sean Edmond 
> > > 
> > > When a successful neighbor advertisement is received, the
> > > ethernet
> > > address should be saved for later use to avoid having to redo the
> > > neighbor discovery process.
> > > 
> > > For example, with TFTP the address should get saved into
> > > "net_server_ethaddr".  This is being done correctly with ARP for
> > > IPv4,
> > > but not for neighbor discovery with IPv6.
> > > 
> > > Signed-off-by: Sean Edmond 
> > > ---
> > >   net/ndisc.c | 4 ++--
> > >   1 file changed, 2 insertions(+), 2 deletions(-)
> > > 
> > > diff --git a/net/ndisc.c b/net/ndisc.c
> > > index d1cec0601c8..505515f2d95 100644
> > > --- a/net/ndisc.c
> > > +++ b/net/ndisc.c
> > > @@ -461,8 +461,8 @@ int ndisc_receive(struct ethernet_hdr *et,
> > > struct
> > > ip6_hdr *ip6, int len)
> > >  ndisc_extract_enetaddr(ndisc,
> > > neigh_eth_addr);
> > > 
> > >  /* save address for later use */
> > > -   if (!net_nd_packet_mac)
> > > -   net_nd_packet_mac =
> > > neigh_eth_addr;
> > > +   if (net_nd_packet_mac)
> > > +   memcpy(net_nd_packet_mac,
> > > neigh_eth_addr, 6);
> > > 
> > >  /* modify header, and transmit it */
> > >  memcpy(((struct ethernet_hdr
> > > *)net_nd_tx_packet)->et_dest,
> > > --
> > > 2.42.0
> > > 
> > Hello, Sean. Thanks for your notice. I see that net_nd_packet_mac
> > is
> > just a uchar pointer without memory allocation. It is dangerous to
> > do
> > memcpy and not necessary. All works as it has to be.



Re: [PATCH] Fix neighbor discovery ethernet address saving

2024-05-05 Thread Vyacheslav V. Mitrofanov
On Mon, 2024-04-29 at 11:51 -0700, seanedm...@linux.microsoft.com
wrote:
> s...@yadro.com
> 
> From: Sean Edmond 
> 
> When a successful neighbor advertisement is received, the ethernet
> address should be saved for later use to avoid having to redo the
> neighbor discovery process.
> 
> For example, with TFTP the address should get saved into
> "net_server_ethaddr".  This is being done correctly with ARP for
> IPv4,
> but not for neighbor discovery with IPv6.
> 
> Signed-off-by: Sean Edmond 
> ---
>  net/ndisc.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/net/ndisc.c b/net/ndisc.c
> index d1cec0601c8..505515f2d95 100644
> --- a/net/ndisc.c
> +++ b/net/ndisc.c
> @@ -461,8 +461,8 @@ int ndisc_receive(struct ethernet_hdr *et, struct
> ip6_hdr *ip6, int len)
>     ndisc_extract_enetaddr(ndisc,
> neigh_eth_addr);
> 
>     /* save address for later use */
> -   if (!net_nd_packet_mac)
> -   net_nd_packet_mac = neigh_eth_addr;
> +   if (net_nd_packet_mac)
> +   memcpy(net_nd_packet_mac,
> neigh_eth_addr, 6);
> 
>     /* modify header, and transmit it */
>     memcpy(((struct ethernet_hdr
> *)net_nd_tx_packet)->et_dest,
> --
> 2.42.0
> 
Hello, Sean. Thanks for your notice. I see that net_nd_packet_mac is
just a uchar pointer without memory allocation. It is dangerous to do 
memcpy and not necessary. All works as it has to be.


Re: [PATCH 2/2] net: ipv6: network protocol structures should be packed

2023-05-19 Thread Vyacheslav V. Mitrofanov
On Thu, 2023-05-18 at 11:24 -0700, emohand...@linux.microsoft.com
wrote:
> From: Ehsan Mohandesi 
> 
> The structure icmp6_ra_prefix_info needs to be packed because it is
> read
> from a network stream.
> 
> Signed-off-by: Ehsan Mohandesi 
> ---
>  include/net6.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/include/net6.h b/include/net6.h
> index beafc05..1e766aa 100644
> --- a/include/net6.h
> +++ b/include/net6.h
> @@ -204,7 +204,7 @@ struct icmp6_ra_prefix_info {
>  * be initialized to zero by the sender and ignored by the
> receiver.
>  */
> struct in6_addr prefix;
> -};
> +} __packed;
> 
>  extern struct in6_addr const net_null_addr_ip6;/* NULL IPv6
> address */
>  extern struct in6_addr net_gateway6;   /* Our gateways IPv6 address
> */
> --
> 1.8.3.1
> 
> 
Reviewed-by: Viacheslav Mitrofanov 


Re: [PATCH 1/2] net: ipv6: router advertisement message length should be within limits

2023-05-19 Thread Vyacheslav V. Mitrofanov
On Thu, 2023-05-18 at 11:24 -0700, emohand...@linux.microsoft.com
wrote:
> 
> From: Ehsan Mohandesi 
> 
> The argument len passed to function process_ra is the length of the
> IPv6
> router advertisement message and needs to be between 0 and MTU
> because
> it is assigned to remaining_option_len and used as a loop variable.
> 
> Addresses-Coverity-ID: 450971 ("TAINTED_SCALAR")
> Signed-off-by: Ehsan Mohandesi 
> ---
>  net/ndisc.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/net/ndisc.c b/net/ndisc.c
> index 0b27779..d1cec06 100644
> --- a/net/ndisc.c
> +++ b/net/ndisc.c
> @@ -382,6 +382,8 @@ int process_ra(struct ip6_hdr *ip6, int len)
> unsigned char type = 0;
> struct icmp6_ra_prefix_info *prefix = NULL;
> 
> +   if (len > ETH_MAX_MTU)
> +   return -EMSGSIZE;
> /* Ignore the packet if router lifetime is 0. */
> if (!icmp->icmp6_rt_lifetime)
> return -EOPNOTSUPP;
> --
> 1.8.3.1
> 
> 
Reviewed-by: Viacheslav Mitrofanov 


Re: [PATCH v4 1/3] net: ipv6: Add support for default gateway discovery.

2023-05-10 Thread Vyacheslav V. Mitrofanov
On Wed, 2023-05-10 at 13:05 +0300, Sergei Antonov wrote:
> 
> Hey! It was added without "__packed", see
> https://lists.denx.de/pipermail/u-boot/2023-May/517370.html
> 
Hello, Sergei. 

I see Ehsan hadn't sent v5 before v4 was applied.
I would make a patch with __packed attribute and post it.
Thanks


Re: [PATCH v4 1/3] net: ipv6: Add support for default gateway discovery.

2023-04-24 Thread Vyacheslav V. Mitrofanov
On Fri, 2023-04-21 at 17:08 -0700, emohand...@linux.microsoft.com
wrote:
> 
> From: Ehsan Mohandesi 
> 
> In IPv6, the default gateway and prefix length are determined by
> receiving
> a router advertisement as defined in -
> https://www.rfc-editor.org/rfc/rfc4861.
> 
> Add support for sending router solicitation (RS) and processing
> router
> advertisements (RA).
> 
> If the RA has prefix info option and following conditions are met,
> then
> gatewayip6 and net_prefix_length of ip6addr env variables are
> initialized.
> These are later consumed by IPv6 code for non-local destination IP.
> 
> - "Router Lifetime" != 0
> - Prefix is NOT link-local prefix (0xfe80::/10)
> - L flag is 1
> - "Valid Lifetime" != 0
> 
> Timing Parameters:
> - MAX_RTR_SOLICITATION_DELAY (0-1s)
> - RTR_SOLICITATION_INTERVAL (4s) (min retransmit delay)
> - MAX_RTR_SOLICITATIONS (3 RS transmissions)
> 
> The functionality is enabled by CONFIG_IPV6_ROUTER_DISCOVERY and
> invoked
> automatically from net_init_loop().
> 
> Signed-off-by: Ehsan Mohandesi 
> ---
>  cmd/Kconfig |   6 ++
>  include/ndisc.h |  35 
>  include/net.h   |   2 +-
>  include/net6.h  |  40 ++
>  net/ndisc.c | 243
> +---
>  net/net.c   |  23 +-
>  net/net6.c  |   1 +
>  7 files changed, 338 insertions(+), 12 deletions(-)
> 
> diff --git a/cmd/Kconfig b/cmd/Kconfig
> index e45b884..6919d31 100644
> --- a/cmd/Kconfig
> +++ b/cmd/Kconfig
> @@ -1916,6 +1916,12 @@ config CMD_NCSI
>   Normally this happens automatically before other network
>   operations.
> 
> +config IPV6_ROUTER_DISCOVERY
> +   bool "Do IPv6 router discovery"
> +   depends on IPV6
> +   help
> + Will automatically perform router solicitation on first
> IPv6
> + network operation
>  endif
> 
>  config CMD_ETHSW
> diff --git a/include/ndisc.h b/include/ndisc.h
> index f6f8eb6..12fa9e7 100644
> --- a/include/ndisc.h
> +++ b/include/ndisc.h
> @@ -19,6 +19,20 @@ struct nd_msg {
> __u8opt[0];
>  };
> 
> +/* struct rs_msg - ICMPv6 Router Solicitation message format */
> +struct rs_msg {
> +   struct icmp6hdr icmph;
> +   __u8opt[0];
> +};
> +
> +/* struct ra_msg - ICMPv6 Router Advertisement message format */
> +struct ra_msg {
> +   struct icmp6hdr icmph;
> +   __u32   reachable_time;
> +   __u32   retransmission_timer;
> +   __u8opt[0];
> +};
> +
>  /* struct echo_msg - ICMPv6 echo request/reply message format */
>  struct echo_msg {
> struct icmp6hdr icmph;
> @@ -57,6 +71,11 @@ extern int net_nd_try;
>   */
>  void ndisc_init(void);
> 
> +/*
> + * ip6_send_rs() - Send IPv6 Router Solicitation Message
> + */
> +void ip6_send_rs(void);
> +
>  /**
>   * ndisc_receive() - Handle ND packet
>   *
> @@ -78,6 +97,8 @@ void ndisc_request(void);
>   * Return: 0 if no timeout, -1 otherwise
>   */
>  int ndisc_timeout_check(void);
> +bool validate_ra(struct ip6_hdr *ip6);
> +int process_ra(struct ip6_hdr *ip6, int len);
>  #else
>  static inline void ndisc_init(void)
>  {
> @@ -97,6 +118,20 @@ static inline int ndisc_timeout_check(void)
>  {
> return 0;
>  }
> +
> +void ip6_send_rs(void)
> +{
> +}
> +
> +static inline bool validate_ra(struct ip6_hdr *ip6)
> +{
> +   return true;
> +}
> +
> +static inline int process_ra(struct ip6_hdr *ip6, int len)
> +{
> +   return 0;
> +}
>  #endif
> 
>  #endif /* __NDISC_H__ */
> diff --git a/include/net.h b/include/net.h
> index 399af5e..25c43b3 100644
> --- a/include/net.h
> +++ b/include/net.h
> @@ -505,7 +505,7 @@ extern int  net_restart_wrap;   /*
> Tried all network devices */
> 
>  enum proto_t {
> BOOTP, RARP, ARP, TFTPGET, DHCP, PING, PING6, DNS, NFS, CDP,
> NETCONS,
> -   SNTP, TFTPSRV, TFTPPUT, LINKLOCAL, FASTBOOT, WOL, UDP, NCSI,
> WGET
> +   SNTP, TFTPSRV, TFTPPUT, LINKLOCAL, FASTBOOT, WOL, UDP, NCSI,
> WGET, RS
>  };
> 
>  extern charnet_boot_file_name[1024];/* Boot File name */
> diff --git a/include/net6.h b/include/net6.h
> index 2d7c5a0..beafc05 100644
> --- a/include/net6.h
> +++ b/include/net6.h
> @@ -81,8 +81,17 @@ struct udp_hdr {
>   0x00, 0x00, 0x00, 0x00, \
>   0x00, 0x00, 0x00, 0x00, \
>   0x00, 0x00, 0x00, 0x00 } } }
> +/*
> + * All-routers multicast address is the link-local scope address to
> reach all
> + * routers.
> + */
> +#define ALL_ROUTERS_MULT_ADDR { { { 0xFF, 0x02, 0x00, 0x00, \
> + 0x00, 0x00, 0x00, 0x00, \
> + 0x00, 0x00, 0x00, 0x00, \
> + 0x00, 0x00, 0x00, 0x02 } } }
> 
>  #define IPV6_LINK_LOCAL_PREFIX 0xfe80
> +#define IPV6_LINK_LOCAL_MASK   0xffb0 /* The first 10-bit of address
> mask. */
> 
>  /* hop limit for neighbour discovery packets */
>  #define IPV6_NDISC_HOPLIMIT 255
> @@ -166,6 +175,37 @@ struct icmp6hdr {
>  

Re: [PATCH v4 3/3] test: eth: IPv6 network discovery unit test

2023-04-24 Thread Vyacheslav V. Mitrofanov
On Fri, 2023-04-21 at 17:08 -0700, emohand...@linux.microsoft.com
wrote:
> «Внимание! Данное письмо от внешнего адресата!»
> 
> From: Ehsan Mohandesi 
> 
> Test router advertisement validation and processing functions.
> 
> Signed-off-by: Ehsan Mohandesi 
> ---
>  test/dm/eth.c | 88
> +++
>  1 file changed, 88 insertions(+)
> 
> diff --git a/test/dm/eth.c b/test/dm/eth.c
> index ebf01d8..d05d2a9 100644
> --- a/test/dm/eth.c
> +++ b/test/dm/eth.c
> @@ -20,6 +20,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
> 
>  #define DM_TEST_ETH_NUM4
> 
> @@ -607,3 +608,90 @@ static int dm_test_eth_async_ping_reply(struct
> unit_test_state *uts)
>  }
> 
>  DM_TEST(dm_test_eth_async_ping_reply, UT_TESTF_SCAN_FDT);
> +
> +#if IS_ENABLED(CONFIG_IPV6_ROUTER_DISCOVERY)
> +
> +static u8 ip6_ra_buf[] = {0x60, 0xf, 0xc5, 0x4a, 0x0, 0x38, 0x3a,
> 0xff, 0xfe,
> + 0x80, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x6,
> 0x85, 0xe6,
> + 0x29, 0x77, 0xcb, 0xc8, 0x53, 0xff, 0x2,
> 0x0, 0x0,
> + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
> 0x0, 0x0, 0x0,
> + 0x1, 0x86, 0x0, 0xdc, 0x90, 0x40, 0x80,
> 0x15, 0x18,
> + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
> 0x3, 0x4,
> + 0x40, 0xc0, 0x0, 0x0, 0x37, 0xdc, 0x0, 0x0,
> 0x37,
> + 0x78, 0x0, 0x0, 0x0, 0x0, 0x20, 0x1, 0xca,
> 0xfe, 0xca,
> + 0xfe, 0xca, 0xfe, 0x0, 0x0, 0x0, 0x0, 0x0,
> 0x0, 0x0,
> + 0x0, 0x1, 0x1, 0x0, 0x15, 0x5d, 0xe2, 0x8a,
> 0x2};
> +
> +static int dm_test_validate_ra(struct unit_test_state *uts)
> +{
> +   struct ip6_hdr *ip6 = (struct ip6_hdr *)ip6_ra_buf;
> +   struct icmp6hdr *icmp = (struct icmp6hdr *)(ip6 + 1);
> +   __be16 temp = 0;
> +
> +   ut_assert(validate_ra(ip6) == true);
> +
> +   temp = ip6->payload_len;
> +   ip6->payload_len = 15;
> +   ut_assert(validate_ra(ip6) == false);
> +   ip6->payload_len = temp;
> +
> +   temp = ip6->saddr.s6_addr16[0];
> +   ip6->saddr.s6_addr16[0] = 0x2001;
> +   ut_assert(validate_ra(ip6) == false);
> +   ip6->saddr.s6_addr16[0] = temp;
> +
> +   temp = ip6->hop_limit;
> +   ip6->hop_limit = 15;
> +   ut_assert(validate_ra(ip6) == false);
> +   ip6->hop_limit = temp;
> +
> +   temp = icmp->icmp6_code;
> +   icmp->icmp6_code = 15;
> +   ut_assert(validate_ra(ip6) == false);
> +   icmp->icmp6_code = temp;
> +
> +   return 0;
> +}
> +
> +DM_TEST(dm_test_validate_ra, 0);
> +
> +static int dm_test_process_ra(struct unit_test_state *uts)
> +{
> +   int len = sizeof(ip6_ra_buf);
> +   struct ip6_hdr *ip6 = (struct ip6_hdr *)ip6_ra_buf;
> +   struct icmp6hdr *icmp = (struct icmp6hdr *)(ip6 + 1);
> +   struct ra_msg *msg = (struct ra_msg *)icmp;
> +   unsigned char *option = msg->opt;
> +   struct icmp6_ra_prefix_info *prefix =
> +   (struct icmp6_ra_prefix_info
> *)option;
> +   __be16 temp = 0;
> +   unsigned char option_len = option[1];
> +
> +   ut_assert(process_ra(ip6, len) == 0);
> +
> +   temp = icmp->icmp6_rt_lifetime;
> +   icmp->icmp6_rt_lifetime = 0;
> +   ut_assert(process_ra(ip6, len) != 0);
> +   icmp->icmp6_rt_lifetime = temp;
> +
> +   ut_assert(process_ra(ip6, 0) != 0);
> +
> +   option[1] = 0;
> +   ut_assert(process_ra(ip6, len) != 0);
> +   option[1] = option_len;
> +
> +   prefix->on_link = false;
> +   ut_assert(process_ra(ip6, len) != 0);
> +   prefix->on_link = true;
> +
> +   temp = prefix->prefix.s6_addr16[0];
> +   prefix->prefix.s6_addr16[0] = 0x80fe;
> +   ut_assert(process_ra(ip6, len) != 0);
> +   prefix->prefix.s6_addr16[0] = temp;
> +
> +   return 0;
> +}
> +
> +DM_TEST(dm_test_process_ra, 0);
> +
> +#endif
> --
> 1.8.3.1
> 
> 
Reviewed-by: Viacheslav Mitrofanov 


Re: [PATCH v4 2/3] test/py: IPv6 network discovery test

2023-04-24 Thread Vyacheslav V. Mitrofanov
On Fri, 2023-04-21 at 17:08 -0700, emohand...@linux.microsoft.com
wrote:
> «Внимание! Данное письмо от внешнего адресата!»
> 
> From: Ehsan Mohandesi 
> 
> Test the IPv6 network discovery feature if indicated by boardenv
> file.
> 
> Signed-off-by: Ehsan Mohandesi 
> ---
>  configs/sandbox64_defconfig|  2 ++
>  configs/sandbox_defconfig  |  2 ++
>  configs/sandbox_flattree_defconfig |  2 ++
>  test/py/tests/test_net.py  | 31
> ++-
>  4 files changed, 36 insertions(+), 1 deletion(-)
> 
> diff --git a/configs/sandbox64_defconfig
> b/configs/sandbox64_defconfig
> index af2c56a..be36ede 100644
> --- a/configs/sandbox64_defconfig
> +++ b/configs/sandbox64_defconfig
> @@ -260,3 +260,5 @@ CONFIG_FWU_MULTI_BANK_UPDATE=y
>  CONFIG_UNIT_TEST=y
>  CONFIG_UT_TIME=y
>  CONFIG_UT_DM=y
> +CONFIG_IPV6=y
> +CONFIG_IPV6_ROUTER_DISCOVERY=y
> diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig
> index ca95b2c..0673c69 100644
> --- a/configs/sandbox_defconfig
> +++ b/configs/sandbox_defconfig
> @@ -341,3 +341,5 @@ CONFIG_UNIT_TEST=y
>  CONFIG_UT_TIME=y
>  CONFIG_UT_DM=y
>  CONFIG_CMD_2048=y
> +CONFIG_IPV6=y
> +CONFIG_IPV6_ROUTER_DISCOVERY=y
> diff --git a/configs/sandbox_flattree_defconfig
> b/configs/sandbox_flattree_defconfig
> index e9fcc5b..d6c8dd2 100644
> --- a/configs/sandbox_flattree_defconfig
> +++ b/configs/sandbox_flattree_defconfig
> @@ -229,3 +229,5 @@ CONFIG_EFI_CAPSULE_FIRMWARE_FIT=y
>  CONFIG_UNIT_TEST=y
>  CONFIG_UT_TIME=y
>  CONFIG_UT_DM=y
> +CONFIG_IPV6=y
> +CONFIG_IPV6_ROUTER_DISCOVERY=y
> diff --git a/test/py/tests/test_net.py b/test/py/tests/test_net.py
> index 9ca6743..f85071d 100644
> --- a/test/py/tests/test_net.py
> +++ b/test/py/tests/test_net.py
> @@ -9,7 +9,7 @@ import u_boot_utils
> 
>  """
>  Note: This test relies on boardenv_* containing configuration values
> to define
> -which the network environment available for testing. Without this,
> this test
> +which network environment is available for testing. Without this,
> this test
>  will be automatically skipped.
> 
>  For example:
> @@ -55,6 +55,11 @@ env__net_nfs_readable_file = {
>  'size': 5058624,
>  'crc32': 'c2244b26',
>  }
> +
> +# True if a router advertisement service is connected to the
> network, and should
> +# be tested. If router advertisement testing is not possible or
> desired, this
> +variable may be omitted or set to False.
> +env__router_on_net = True
>  """
> 
>  net_set_up = False
> @@ -126,6 +131,30 @@ def test_net_ping(u_boot_console):
>  output = u_boot_console.run_command('ping $serverip')
>  assert 'is alive' in output
> 
> +@pytest.mark.buildconfigspec('IPV6_ROUTER_DISCOVERY')
> +def test_net_network_discovery(u_boot_console):
> +"""Test the network discovery feature of IPv6.
> +
> +An IPv6 network command (ping6 in this case) is run to make U-
> Boot send a
> +router solicitation packet, receive a router advertisement
> message, and
> +parse it.
> +A router advertisement service needs to be running for this test
> to succeed.
> +U-Boot receives the RA, processes it, and if successful, assigns
> the gateway
> +IP and prefix length.
> +The configuration is provided by the boardenv_* file; see the
> comment at
> +the beginning of this file.
> +"""
> +
> +router_on_net =
> u_boot_console.config.env.get('env__router_on_net', False)
> +if not router_on_net:
> +pytest.skip('No router on network')
> +
> +fake_host_ip = 'fe80::215:5dff:fef6:2ec6'
> +output = u_boot_console.run_command('ping6 ' + fake_host_ip)
> +assert 'ROUTER SOLICITATION 1' in output
> +assert 'Set gatewayip6:' in output
> +assert ':::::::' not in output
> +
>  @pytest.mark.buildconfigspec('cmd_net')
>  def test_net_tftpboot(u_boot_console):
>  """Test the tftpboot command.
> --
> 1.8.3.1
> 
> 

Reviewed-by: Viacheslav Mitrofanov 


Re: [PATCH v4 1/3] net: ipv6: Add support for default gateway discovery.

2023-04-24 Thread Vyacheslav V. Mitrofanov
On Fri, 2023-04-21 at 17:08 -0700, emohand...@linux.microsoft.com
wrote:
> 
> From: Ehsan Mohandesi 
> 
> In IPv6, the default gateway and prefix length are determined by
> receiving
> a router advertisement as defined in -
> https://www.rfc-editor.org/rfc/rfc4861.
> 
> Add support for sending router solicitation (RS) and processing
> router
> advertisements (RA).
> 
> If the RA has prefix info option and following conditions are met,
> then
> gatewayip6 and net_prefix_length of ip6addr env variables are
> initialized.
> These are later consumed by IPv6 code for non-local destination IP.
> 
> - "Router Lifetime" != 0
> - Prefix is NOT link-local prefix (0xfe80::/10)
> - L flag is 1
> - "Valid Lifetime" != 0
> 
> Timing Parameters:
> - MAX_RTR_SOLICITATION_DELAY (0-1s)
> - RTR_SOLICITATION_INTERVAL (4s) (min retransmit delay)
> - MAX_RTR_SOLICITATIONS (3 RS transmissions)
> 
> The functionality is enabled by CONFIG_IPV6_ROUTER_DISCOVERY and
> invoked
> automatically from net_init_loop().
> 
> Signed-off-by: Ehsan Mohandesi 
> ---
>  cmd/Kconfig |   6 ++
>  include/ndisc.h |  35 
>  include/net.h   |   2 +-
>  include/net6.h  |  40 ++
>  net/ndisc.c | 243
> +---
>  net/net.c   |  23 +-
>  net/net6.c  |   1 +
>  7 files changed, 338 insertions(+), 12 deletions(-)
> 
> diff --git a/cmd/Kconfig b/cmd/Kconfig
> index e45b884..6919d31 100644
> --- a/cmd/Kconfig
> +++ b/cmd/Kconfig
> @@ -1916,6 +1916,12 @@ config CMD_NCSI
>   Normally this happens automatically before other network
>   operations.
> 
> +config IPV6_ROUTER_DISCOVERY
> +   bool "Do IPv6 router discovery"
> +   depends on IPV6
> +   help
> + Will automatically perform router solicitation on first
> IPv6
> + network operation
>  endif
> 
>  config CMD_ETHSW
> diff --git a/include/ndisc.h b/include/ndisc.h
> index f6f8eb6..12fa9e7 100644
> --- a/include/ndisc.h
> +++ b/include/ndisc.h
> @@ -19,6 +19,20 @@ struct nd_msg {
> __u8opt[0];
>  };
> 
> +/* struct rs_msg - ICMPv6 Router Solicitation message format */
> +struct rs_msg {
> +   struct icmp6hdr icmph;
> +   __u8opt[0];
> +};
> +
> +/* struct ra_msg - ICMPv6 Router Advertisement message format */
> +struct ra_msg {
> +   struct icmp6hdr icmph;
> +   __u32   reachable_time;
> +   __u32   retransmission_timer;
> +   __u8opt[0];
> +};
> +
>  /* struct echo_msg - ICMPv6 echo request/reply message format */
>  struct echo_msg {
> struct icmp6hdr icmph;
> @@ -57,6 +71,11 @@ extern int net_nd_try;
>   */
>  void ndisc_init(void);
> 
> +/*
> + * ip6_send_rs() - Send IPv6 Router Solicitation Message
> + */
> +void ip6_send_rs(void);
> +
>  /**
>   * ndisc_receive() - Handle ND packet
>   *
> @@ -78,6 +97,8 @@ void ndisc_request(void);
>   * Return: 0 if no timeout, -1 otherwise
>   */
>  int ndisc_timeout_check(void);
> +bool validate_ra(struct ip6_hdr *ip6);
> +int process_ra(struct ip6_hdr *ip6, int len);
>  #else
>  static inline void ndisc_init(void)
>  {
> @@ -97,6 +118,20 @@ static inline int ndisc_timeout_check(void)
>  {
> return 0;
>  }
> +
> +void ip6_send_rs(void)
> +{
> +}
> +
> +static inline bool validate_ra(struct ip6_hdr *ip6)
> +{
> +   return true;
> +}
> +
> +static inline int process_ra(struct ip6_hdr *ip6, int len)
> +{
> +   return 0;
> +}
>  #endif
> 
>  #endif /* __NDISC_H__ */
> diff --git a/include/net.h b/include/net.h
> index 399af5e..25c43b3 100644
> --- a/include/net.h
> +++ b/include/net.h
> @@ -505,7 +505,7 @@ extern int  net_restart_wrap;   /*
> Tried all network devices */
> 
>  enum proto_t {
> BOOTP, RARP, ARP, TFTPGET, DHCP, PING, PING6, DNS, NFS, CDP,
> NETCONS,
> -   SNTP, TFTPSRV, TFTPPUT, LINKLOCAL, FASTBOOT, WOL, UDP, NCSI,
> WGET
> +   SNTP, TFTPSRV, TFTPPUT, LINKLOCAL, FASTBOOT, WOL, UDP, NCSI,
> WGET, RS
>  };
> 
>  extern charnet_boot_file_name[1024];/* Boot File name */
> diff --git a/include/net6.h b/include/net6.h
> index 2d7c5a0..beafc05 100644
> --- a/include/net6.h
> +++ b/include/net6.h
> @@ -81,8 +81,17 @@ struct udp_hdr {
>   0x00, 0x00, 0x00, 0x00, \
>   0x00, 0x00, 0x00, 0x00, \
>   0x00, 0x00, 0x00, 0x00 } } }
> +/*
> + * All-routers multicast address is the link-local scope address to
> reach all
> + * routers.
> + */
> +#define ALL_ROUTERS_MULT_ADDR { { { 0xFF, 0x02, 0x00, 0x00, \
> + 0x00, 0x00, 0x00, 0x00, \
> + 0x00, 0x00, 0x00, 0x00, \
> + 0x00, 0x00, 0x00, 0x02 } } }
> 
>  #define IPV6_LINK_LOCAL_PREFIX 0xfe80
> +#define IPV6_LINK_LOCAL_MASK   0xffb0 /* The first 10-bit of address
> mask. */
> 
>  /* hop limit for neighbour discovery packets */
>  #define IPV6_NDISC_HOPLIMIT 255
> @@ -166,6 +175,37 @@ struct icmp6hdr {
>  

Re: [PATCH v3 1/3] net: ipv6: Add support for default gateway discovery.

2023-04-20 Thread Vyacheslav V. Mitrofanov
Hello Ehsan! I tried to apply your patches and found out that there are some 
conflicts. I think you use your custom version. Check it please.

Thanks!

On Wed, 2023-04-12 at 09:10 -0700, emohand...@linux.microsoft.co
wrote:

From: Ehsan Mohandesi 
> 
> 
>  #endif /* __NDISC_H__ */
> diff --git a/include/net.h b/include/net.h
> index 8ba50a0..58774f6 100644
> --- a/include/net.h
> +++ b/include/net.h
> @@ -505,7 +505,8 @@ extern int  net_restart_wrap;   /*
> Tried all network devices */
> 
>  enum proto_t {
> BOOTP, RARP, ARP, TFTPGET, DHCP, DHCP6, PING, PING6, DNS,

Here DHCP6


>
> diff --git a/net/net.c b/net/net.c
> index d69bfb0..abdb7e4 100644
> --- a/net/net.c
> +++ b/net/net.c
> @@ -24,7 +24,7 @@
>   * - name of bootfile
>   * Next step:  ARP
>   *
> - * LINK_LOCAL:
> + * LINKLOCAL:
>   *
>   * Prerequisites:  - own ethernet address
>   * We want:- own IP address
> @@ -125,6 +125,7 @@
>  #if defined(CONFIG_CMD_DHCP6)
>  #include "dhcpv6.h"
> 
> 
Here DHCP6

And maybe somewhere else


Re: [PATCH v2 1/4] Revert "net: ipv6: Add support for default gateway discovery."

2023-04-11 Thread Vyacheslav V. Mitrofanov
On Mon, 2023-04-10 at 12:34 -0700, emohand...@linux.microsoft.com
wrote:
> 
> From: Ehsan Mohandesi 
> 
> This reverts commit 0af1035a55d9c1486b2db43ee70ff0a63affd4f4.
> 
> Signed-off-by: Ehsan Mohandesi 
> 
> Conflicts:
> cmd/Kconfig
> include/net.h
> include/net6.h
> net/net.c
> ---
>  include/net.h | 4 ++--
>  net/net.c | 3 +++
>  2 files changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/include/net.h b/include/net.h
> index 399af5e..8ba50a0 100644
> --- a/include/net.h
> +++ b/include/net.h
> @@ -504,8 +504,8 @@ extern
> ushort   net_native_vlan;/* Our Native VLAN */
>  extern int net_restart_wrap;   /* Tried all network
> devices */
> 
>  enum proto_t {
> -   BOOTP, RARP, ARP, TFTPGET, DHCP, PING, PING6, DNS, NFS, CDP,
> NETCONS,
> -   SNTP, TFTPSRV, TFTPPUT, LINKLOCAL, FASTBOOT, WOL, UDP, NCSI,
> WGET
> +   BOOTP, RARP, ARP, TFTPGET, DHCP, DHCP6, PING, PING6, DNS,
> NFS, CDP,
> +   NETCONS, SNTP, TFTPSRV, TFTPPUT, LINKLOCAL, FASTBOOT, WOL,
> UDP, NCSI, WGET
>  };
> 
>  extern charnet_boot_file_name[1024];/* Boot File name */
> diff --git a/net/net.c b/net/net.c
> index c9a749f..d69bfb0 100644
> --- a/net/net.c
> +++ b/net/net.c
> @@ -122,6 +122,9 @@
>  #endif
>  #include 
>  #include 
> +#if defined(CONFIG_CMD_DHCP6)
> +#include "dhcpv6.h"
> +#endif
> 
>  /** BOOTP EXTENTIONS **/
> 
> --
> 1.8.3.1
> 
> 
Hello, Ehsan!

Is everything ok with this patch set?
You reverted the commit that is absent in upstream.


Re: [PATCH] net: ipv6: Add support for default gateway discovery.

2023-03-23 Thread Vyacheslav V. Mitrofanov
On Thu, 2023-03-23 at 16:44 +, Ehsan Mohandesi wrote:
> 
> Hi Viacheslav,
> 
> > -Original Message-
> > From: Vyacheslav V. Mitrofanov 
> > Sent: Thursday, March 16, 2023 3:47 AM
> > To: u-boot@lists.denx.de; emohand...@linux.microsoft.com
> > Cc: joe.hershber...@ni.com; xypron.g...@gmx.de;
> > dpha...@linux.microsoft.com; sap...@gmail.com; rfried@gmail.com
> > ;
> > ilias.apalodi...@linaro.org; Ehsan Mohandesi <
> > emohand...@microsoft.com>;
> > j...@metanate.com; s...@chromium.org; masahisa.koj...@linaro.org
> > Subject: [EXTERNAL] Re: [PATCH] net: ipv6: Add support for default
> > gateway
> > discovery.
> > 
> > On Thu, 2023-03-02 at 08:58 -0800, emohand...@linux.microsoft.com
> > wrote:
> > > From: Ehsan Mohandesi 
> > > 
> > > In IPv6, the default gateway and prefix length are determined by
> > > receiving a router advertisement as defined in -
> > > 
> > https://www.rf/
> > c-
> > editor.org%2Frfc%2Frfc4861=05%7C01%7Cemohandesi%40microsoft.co
> > m%7C6dec635abc8c4861feb708db25fb05d6%7C72f988bf86f141af91ab2d7cd01
> > 1db47%7C1%7C0%7C638145532341238481%7CUnknown%7CTWFpbGZsb3d8ey
> > JWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C
> > 3000%7C%7C%7C=tAhREBvBgVQKOFqEQT2%2FKphGxYXUMo3UF5vvQpY
> > B%2Be0%3D=0.
> > > Add support for sending router solicitation (RS) and processing
> > > router
> > > advertisements (RA).
> > > 
> > > If the RA has prefix info option and following conditions are
> > > met,
> > > then
> > > gatewayip6 and net_prefix_length of ip6addr env variables are
> > > initialized.
> > > These are later consumed by IPv6 code for non-local destination
> > > IP.
> > > 
> > > - "Router Lifetime" != 0
> > > - Prefix is NOT link-local prefix (0xfe80::/10)
> > > - L flag is 1
> > > - "Valid Lifetime" != 0
> > > 
> > > Timing Parameters:
> > > - MAX_RTR_SOLICITATION_DELAY (0-1s)
> > > - RTR_SOLICITATION_INTERVAL (4s) (min retransmit delay)
> > > - MAX_RTR_SOLICITATIONS (3 RS transmissions)
> > > 
> > > The functionality is enabled by CONFIG_IPV6_ROUTER_DISCOVERY and
> > > invoked automatically from net_init_loop().
> > > 
> > > Signed-off-by: Ehsan Mohandesi 
> > > 
> > > Conflicts:
> > > cmd/Kconfig
> > > include/net.h
> > > net/net.c
> > > ---
> > >  cmd/Kconfig |   7 ++
> > >  include/ndisc.h |  23 ++
> > >  include/net.h   |   2 +-
> > >  include/net6.h  |  40 ++
> > >  net/ndisc.c | 243
> > > +---
> > >  net/net.c   |  23 +-
> > >  net/net6.c  |   1 +
> > >  7 files changed, 327 insertions(+), 12 deletions(-)
> > > 
> > 
> > I reviewed this patch and it looks good. I have no critical
> > remarks, only some
> > small notes.
> > 
> > I've tested it on SiFive Unmatched board.
> > 
> > 
> > > +config IPV6_ROUTER_DISCOVERY
> > > +   bool "Do router discovery"
> > > +   depends on IPV6
> > > +   help
> > > + Will automatically perform router solicitation on first
> > > IPv6
> > > + network operation
> > > +
> > >  endif
> > > 
> > I think it is better to write sth like Do IPv6 router discovery
> > because
> > IPv4 has also router discovery protocol and it could lead to
> > misunderstanding
> > 
> > 
> > > net_set_timeout_handler(0, 0);
> > > 
> > Maybe net_set_timeout_handler(0, NULL); is better
> > 
> > 
> > 
> > > +/*
> > > + * validate_ra() - Validate the router advertisement message.
> > > + *
> > > + * @ip6:
> > > + * @len: Length of the router advertisement packet
> > > + *
> > > + * Check if the router advertisement message is valid.
> > > Conditions
> > > are
> > > + * according to RFC 4861 section 6.1.2. Validation of Router
> > > Advertisement
> > > + * Messages.
> > > + *
> > > + * Return: true if the message is valid and false if it is
> > > invalid.
> > > + */
> > > +static bool validate_ra(struct ip6_hdr *ip6, int len) {
> > > +   struct icmp6hdr *icmp = (struct icmp6hdr *)(ip6 + 1);
> > > +
> > > +   /* ICMP length (

Re: [PATCH] net: ipv6: Add support for default gateway discovery.

2023-03-16 Thread Vyacheslav V. Mitrofanov
On Thu, 2023-03-02 at 08:58 -0800, emohand...@linux.microsoft.com
wrote:
> 
> From: Ehsan Mohandesi 
> 
> In IPv6, the default gateway and prefix length are determined by
> receiving
> a router advertisement as defined in -
> https://www.rfc-editor.org/rfc/rfc4861.
> 
> Add support for sending router solicitation (RS) and processing
> router
> advertisements (RA).
> 
> If the RA has prefix info option and following conditions are met,
> then
> gatewayip6 and net_prefix_length of ip6addr env variables are
> initialized.
> These are later consumed by IPv6 code for non-local destination IP.
> 
> - "Router Lifetime" != 0
> - Prefix is NOT link-local prefix (0xfe80::/10)
> - L flag is 1
> - "Valid Lifetime" != 0
> 
> Timing Parameters:
> - MAX_RTR_SOLICITATION_DELAY (0-1s)
> - RTR_SOLICITATION_INTERVAL (4s) (min retransmit delay)
> - MAX_RTR_SOLICITATIONS (3 RS transmissions)
> 
> The functionality is enabled by CONFIG_IPV6_ROUTER_DISCOVERY and
> invoked
> automatically from net_init_loop().
> 
> Signed-off-by: Ehsan Mohandesi 
> 
> Conflicts:
> cmd/Kconfig
> include/net.h
> net/net.c
> ---
>  cmd/Kconfig |   7 ++
>  include/ndisc.h |  23 ++
>  include/net.h   |   2 +-
>  include/net6.h  |  40 ++
>  net/ndisc.c | 243
> +---
>  net/net.c   |  23 +-
>  net/net6.c  |   1 +
>  7 files changed, 327 insertions(+), 12 deletions(-)
> 

I reviewed this patch and it looks good. I have no critical remarks,
only some small notes. 

I've tested it on SiFive Unmatched board.


> 
> +config IPV6_ROUTER_DISCOVERY
> +   bool "Do router discovery"
> +   depends on IPV6
> +   help
> + Will automatically perform router solicitation on first
> IPv6
> + network operation
> +
>  endif
> 
I think it is better to write sth like Do IPv6 router discovery because
IPv4 has also router discovery protocol and it could lead to
misunderstanding


> 
> net_set_timeout_handler(0, 0);
> 
Maybe net_set_timeout_handler(0, NULL); is better



> +/*
> + * validate_ra() - Validate the router advertisement message.
> + *
> + * @ip6:
> + * @len: Length of the router advertisement packet
> + *
> + * Check if the router advertisement message is valid. Conditions
> are
> + * according to RFC 4861 section 6.1.2. Validation of Router
> Advertisement
> + * Messages.
> + *
> + * Return: true if the message is valid and false if it is invalid.
> + */
> +static bool validate_ra(struct ip6_hdr *ip6, int len)
> +{
> +   struct icmp6hdr *icmp = (struct icmp6hdr *)(ip6 + 1);
> +
> +   /* ICMP length (derived from the IP length) should be 16 or
> more octets. */
> +   if (ip6->payload_len < 16)
> +   return false;
> +
> +   /* Source IP Address should be a valid link-local address. */
> +   if ((ntohs(ip6->saddr.s6_addr16[0]) & IPV6_LINK_LOCAL_MASK)
> !=
> +   IPV6_LINK_LOCAL_PREFIX)
> +   return false;
> +
> +   /*
> +* The IP Hop Limit field should have a value of 255, i.e.,
> the packet
> +* could not possibly have been forwarded by a router.
> +*/
> +   if (ip6->hop_limit != 255)
> +   return false;
> +
Unicast hop limit only?

> diff --git a/net/net.c b/net/net.c
> index c9a749f..39f0b81 100644
> --- a/net/net.c
> +++ b/net/net.c
> @@ -24,7 +24,7 @@
>   * - name of bootfile
>   * Next step:  ARP
>   *
> - * LINK_LOCAL:
> + * LINKLOCAL:
> 
Maybe it is better to move to other patch?!


Reviewed-by: Viacheslav Mitrofanov 
Tested-by: Viacheslav Mitrofanov 


Re: [PATCH 2/2] net: dhcp6: pxe: Add DHCP/PXE commands for IPv6

2023-03-05 Thread Vyacheslav V. Mitrofanov
> From: Sean Edmond 
> 
> Adds commands to support DHCP and PXE with IPv6.
> 
> New commands added (when IPv6 is enabled):
> - dhcp6
> - pxe get -ipv6
> - pxe boot -ipv6
> 
> Signed-off-by: Sean Edmond 
> ---
>  boot/bootmeth_distro.c |  2 +-
>  boot/bootmeth_pxe.c|  4 +-
>  boot/pxe_utils.c   |  3 +-
>  cmd/net.c  | 22 +++
>  cmd/pxe.c  | 86 +---
> --
>  cmd/sysboot.c  |  2 +-
>  include/net.h  |  2 +
>  include/net6.h |  2 -
>  include/pxe_utils.h| 10 -
>  9 files changed, 115 insertions(+), 18 deletions(-)
> 
> diff --git a/boot/bootmeth_distro.c b/boot/bootmeth_distro.c
> index 356929828b..b4b73ecbf5 100644
> --- a/boot/bootmeth_distro.c
> +++ b/boot/bootmeth_distro.c
> @@ -150,7 +150,7 @@ static int distro_boot(struct udevice *dev,
> struct bootflow *bflow)
> info.dev = dev;
> info.bflow = bflow;
> ret = pxe_setup_ctx(, , distro_getfile, ,
> true,
> -   bflow->subdir);
> +   bflow->subdir, false);
> if (ret)
> return log_msg_ret("ctx", -EINVAL);
> 
> diff --git a/boot/bootmeth_pxe.c b/boot/bootmeth_pxe.c
> index ecf8557af8..5a8af2bbd0 100644
> --- a/boot/bootmeth_pxe.c
> +++ b/boot/bootmeth_pxe.c
> @@ -70,7 +70,7 @@ static int distro_pxe_read_bootflow(struct udevice
> *dev, struct bootflow *bflow)
> addr = simple_strtoul(addr_str, NULL, 16);
> 
> log_debug("calling pxe_get()\n");
> -   ret = pxe_get(addr, , );
> +   ret = pxe_get(addr, , , false);
> log_debug("pxe_get() returned %d\n", ret);
> if (ret)
> return log_msg_ret("pxeb", ret);
> @@ -146,7 +146,7 @@ static int distro_pxe_boot(struct udevice *dev,
> struct bootflow *bflow)
> info.bflow = bflow;
> info.cmdtp = 
> ret = pxe_setup_ctx(ctx, , distro_pxe_getfile, ,
> false,
> -   bflow->subdir);
> +   bflow->subdir, false);
> if (ret)
> return log_msg_ret("ctx", -EINVAL);
> 
> diff --git a/boot/pxe_utils.c b/boot/pxe_utils.c
> index 3a1e50f2b1..d13c47dd94 100644
> --- a/boot/pxe_utils.c
> +++ b/boot/pxe_utils.c
> @@ -1578,7 +1578,7 @@ void handle_pxe_menu(struct pxe_context *ctx,
> struct pxe_menu *cfg)
> 
>  int pxe_setup_ctx(struct pxe_context *ctx, struct cmd_tbl *cmdtp,
>   pxe_getfile_func getfile, void *userdata,
> - bool allow_abs_path, const char *bootfile)
> + bool allow_abs_path, const char *bootfile, bool
> use_ipv6)
>  {
> const char *last_slash;
> size_t path_len = 0;
> @@ -1588,6 +1588,7 @@ int pxe_setup_ctx(struct pxe_context *ctx,
> struct cmd_tbl *cmdtp,
> ctx->getfile = getfile;
> ctx->userdata = userdata;
> ctx->allow_abs_path = allow_abs_path;
> +   ctx->use_ipv6 = use_ipv6;
> 
> /* figure out the boot directory, if there is one */
> if (bootfile && strlen(bootfile) >= MAX_TFTP_PATH_LEN)
> diff --git a/cmd/net.c b/cmd/net.c
> index 4227321871..88d53d14d5 100644
> --- a/cmd/net.c
> +++ b/cmd/net.c
> @@ -111,6 +111,28 @@ U_BOOT_CMD(
>  );
>  #endif
> 
> +#if defined(CONFIG_CMD_DHCP6)
> +static int do_dhcp6(struct cmd_tbl *cmdtp, int flag, int argc,
> +   char *const argv[])
> +{
> +   int i;
> +   int dhcp_argc;
> +   char *dhcp_argv[] = {NULL, NULL, NULL, NULL};
> +
> +   /* Add -ipv6 flag for autoload */
> +   for (i = 0; i < argc; i++)
> +   dhcp_argv[i] = argv[i];
> +   dhcp_argc = argc + 1;
> +   dhcp_argv[dhcp_argc - 1] =  USE_IP6_CMD_PARAM;
> +
> +   return netboot_common(DHCP6, cmdtp, dhcp_argc, dhcp_argv);
> +}
> +
> +U_BOOT_CMD(dhcp6,  3,  1,  do_dhcp6,
> +  "boot image via network using DHCPv6/TFTP protocol",
> +  "[loadAddress] [[hostIPaddr:]bootfilename]");
> +#endif
> +
>  #if defined(CONFIG_CMD_DHCP)
>  static int do_dhcp(struct cmd_tbl *cmdtp, int flag, int argc,
>char *const argv[])
> diff --git a/cmd/pxe.c b/cmd/pxe.c
> index db8e4697f2..ebc44fd661 100644
> --- a/cmd/pxe.c
> +++ b/cmd/pxe.c
> @@ -11,6 +11,10 @@
> 
>  #include "pxe_utils.h"
> 
> +#if IS_ENABLED(CONFIG_IPV6)
> +#include 
> +#endif
> +
>  #ifdef CONFIG_CMD_NET
>  const char *pxe_default_paths[] = {
>  #ifdef CONFIG_SYS_SOC
> @@ -29,12 +33,20 @@ static int do_get_tftp(struct pxe_context *ctx,
> const char *file_path,
>  {
> char *tftp_argv[] = {"tftp", NULL, NULL, NULL};
> int ret;
> +   int num_args;
> 
> tftp_argv[1] = file_addr;
> tftp_argv[2] = (void *)file_path;
> +   if (ctx->use_ipv6) {
> +   tftp_argv[3] = USE_IP6_CMD_PARAM;
> +   num_args = 4;
> +   } else {
> +   num_args = 3;
> +   }
> 
> -   if (do_tftpb(ctx->cmdtp, 0, 3, tftp_argv))
> +   if (do_tftpb(ctx->cmdtp, 0, num_args, 

Re: [PATCH 1/2] net: dhcp6: Add DHCPv6 (DHCP for IPv6)

2023-03-05 Thread Vyacheslav V. Mitrofanov
> From: Sean Edmond 
> 
> Adds DHCPv6 protocol to u-boot.
> 
> Allows for address assignement with DHCPv6 4-message exchange
> (SOLICIT->ADVERTISE->REQUEST->REPLY).  Includes DHCPv6 options
> required by RFC 8415.  Also adds DHCPv6 options required
> for PXE boot.
> 
> New configs added:
> - CMD_DHCP6
> - DHCP6_PXE_CLIENTARCH
> - DHCP6_PXE_DHCP_OPTION
> - DHCP6_ENTERPRISE_ID
> 
> Possible enhancements:
> - Duplicate address detection on DHCPv6 assigned address
> - IPv6 address assignement through SLAAC
> - Sending/parsing other DHCPv6 options (NTP, DNS, etc...)
> 
> Signed-off-by: Sean Edmond 
> ---
>  cmd/Kconfig   |  26 ++
>  include/net.h |   8 +-
>  net/Makefile  |   1 +
>  net/dhcpv6.c  | 741
> ++
>  net/dhcpv6.h  | 212 +++
>  net/net.c |  12 +
>  6 files changed, 998 insertions(+), 2 deletions(-)
>  create mode 100644 net/dhcpv6.c
>  create mode 100644 net/dhcpv6.h
> 
> diff --git a/cmd/Kconfig b/cmd/Kconfig
> index dc0446e02e..87813ddbb4 100644
> --- a/cmd/Kconfig
> +++ b/cmd/Kconfig
> @@ -1645,6 +1645,15 @@ config CMD_DHCP
> help
>   Boot image via network using DHCP/TFTP protocol
> 
> +config CMD_DHCP6
> +   bool "dhcp6"
> +   depends on IPV6
> +   help
> + Boot image via network using DHCPv6/TFTP protocol using
> IPv6.
> +
> + Will perform 4-message exchange with DHCPv6 server,
> requesting
> + the minimum required options to TFTP boot. Complies with
> RFC 8415.
> +
>  config BOOTP_MAY_FAIL
> bool "Allow for the BOOTP/DHCP server to not be found"
> depends on CMD_BOOTP
> @@ -1758,6 +1767,23 @@ config BOOTP_VCI_STRING
> default "U-Boot.arm" if ARM
> default "U-Boot"
> 
> +if CMD_DHCP6
> +
> +config DHCP6_PXE_CLIENTARCH
> +   hex
> +   default 0x16 if ARM64
> +   default 0x15 if ARM
> +   default 0xFF
> +
> +config DHCP6_PXE_DHCP_OPTION
> +   bool "Request & store 'pxe_configfile' from DHCP6 server"
> +
> +config DHCP6_ENTERPRISE_ID
> +   int "Enterprise ID to send in DHCPv6 Vendor Class Option"
> +   default 0
> +
> +endif
> +
>  config CMD_TFTPBOOT
> bool "tftpboot"
> default y
> diff --git a/include/net.h b/include/net.h
> index 399af5e064..cac818e292 100644
> --- a/include/net.h
> +++ b/include/net.h
> @@ -484,6 +484,10 @@ extern charnet_hostname[32];   /*
> Our hostname */
>  #ifdef CONFIG_NET
>  extern charnet_root_path[CONFIG_BOOTP_MAX_ROOT_PATH_LEN];  /*
> Our root path */
>  #endif
> +#if defined(CONFIG_DHCP6_PXE_DHCP_OPTION)
> +/* Indicates whether the pxe path prefix / config file was specified
> in dhcp option */
> +extern char *pxelinux_configfile;
> +#endif
>  /** END OF BOOTP EXTENTIONS **/
>  extern u8  net_ethaddr[ARP_HLEN];  /* Our
> ethernet address */
>  extern u8  net_server_ethaddr[ARP_HLEN];   /* Boot
> server enet address */
> @@ -504,8 +508,8 @@ extern
> ushort   net_native_vlan;/* Our Native VLAN */
>  extern int net_restart_wrap;   /* Tried all network
> devices */
> 
>  enum proto_t {
> -   BOOTP, RARP, ARP, TFTPGET, DHCP, PING, PING6, DNS, NFS, CDP,
> NETCONS,
> -   SNTP, TFTPSRV, TFTPPUT, LINKLOCAL, FASTBOOT, WOL, UDP, NCSI,
> WGET
> +   BOOTP, RARP, ARP, TFTPGET, DHCP, DHCP6, PING, PING6, DNS,
> NFS, CDP,
> +   NETCONS, SNTP, TFTPSRV, TFTPPUT, LINKLOCAL, FASTBOOT, WOL,
> UDP, NCSI, WGET
>  };
> 
>  extern charnet_boot_file_name[1024];/* Boot File name */
> diff --git a/net/Makefile b/net/Makefile
> index bea000b206..5968110170 100644
> --- a/net/Makefile
> +++ b/net/Makefile
> @@ -22,6 +22,7 @@ obj-$(CONFIG_IPV6) += net6.o
>  obj-$(CONFIG_CMD_NFS)  += nfs.o
>  obj-$(CONFIG_CMD_PING) += ping.o
>  obj-$(CONFIG_CMD_PING6) += ping6.o
> +obj-$(CONFIG_CMD_DHCP6) += dhcpv6.o
>  obj-$(CONFIG_CMD_PCAP) += pcap.o
>  obj-$(CONFIG_CMD_RARP) += rarp.o
>  obj-$(CONFIG_CMD_SNTP) += sntp.o
> diff --git a/net/dhcpv6.c b/net/dhcpv6.c
> new file mode 100644
> index 00..0f0fa291d3
> --- /dev/null
> +++ b/net/dhcpv6.c
> @@ -0,0 +1,741 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + * Copyright (C) Microsoft Corporation
> + * Author: Sean Edmond 
> + *
> + */
> +
> +/* Simple DHCP6 network layer implementation. */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include "dhcpv6.h"
> +#include 
> +#include 
> +#include "net_rand.h"
> +
> +/* Copied from bootp */
> +#ifndef CONFIG_NET_RETRY_COUNT
> +# define TIMEOUT_COUNT 5   /* # of timeouts before giving up */
> +#else
> +# define TIMEOUT_COUNT (CONFIG_NET_RETRY_COUNT)
> +#endif
> +
> +#define PORT_DHCP6_S   547 /* DHCP6 server UDP port */
> +#define PORT_DHCP6_C   546 /* DHCP6 client UDP port */
> +
> +//default timeout parameters (in ms)
> +#define SOL_MAX_DELAY_MS   1000
> +#define SOL_TIMEOUT_MS 1000
> 

Re: [PATCH 0/2] net: DHCPv6 protocol and commands

2023-03-05 Thread Vyacheslav V. Mitrofanov
> From: Sean Edmond 
> 
> The recently integrated IPv6 patch series relies on the link-local
> address,
> or a statically assigned IPv6 address for network operations.  This
> patch
> series adds IPv6 address assignment through DHCPv6.
> 
> The implementation meets the requirements in RFC 8415 for
> "Client/Server
> Exchanges Involving Four Messages":
> https://www.rfc-editor.org/rfc/rfc8415
> 
> The implementation sends/receives the minimum required DHCPv6 options
> to
> network boot.
> 
> A new command (dhcp6) will execute the protocol.  In addition, IPv6
> functionality has been extended to the existing pxe commands ("pxe
> get"
> and "pxe boot").
> 
> Sean Edmond (2):
>   net: dhcp6: Add DHCPv6 (DHCP for IPv6)
>   net: dhcp6: pxe: Add DHCP/PXE commands for IPv6
> 
>  boot/bootmeth_distro.c |   2 +-
>  boot/bootmeth_pxe.c|   4 +-
>  boot/pxe_utils.c   |   3 +-
>  cmd/Kconfig|  26 ++
>  cmd/net.c  |  22 ++
>  cmd/pxe.c  |  86 -
>  cmd/sysboot.c  |   2 +-
>  include/net.h  |  10 +-
>  include/net6.h |   2 -
>  include/pxe_utils.h|  10 +-
>  net/Makefile   |   1 +
>  net/dhcpv6.c   | 741
> +
>  net/dhcpv6.h   | 212 
>  net/net.c  |  12 +
>  14 files changed, 1113 insertions(+), 20 deletions(-)
>  create mode 100644 net/dhcpv6.c
>  create mode 100644 net/dhcpv6.h
> 
> --
> 2.39.0
> 
> 


Hello! Very sorry for the long response!
I checked your patches and in general it looks good. Anyway I have made
some notes. It is up to you and maintainers to improve the code or not.


Moreover I've briefly tested it and it works.
=> dhcp6
: PHY present at 0
: Starting autonegotiation...
: Autonegotiation complete
: link up, 100Mbps full-duplex (lpa: 0x41e1)
DHCP6 SOLICIT 0
DHCP6 REQUEST 0
DHCP6 client bound to fe80::::42f2:e9ff:fe6d:beef

Notes:
1. Some comments have //-style. Better to use /**/
//global variable to track any updates from DHCP6 server 

2. If you apply only the first patch you can add to config CMD_DHCP6
but when you run u-boot it won't be available. Looks like sth
incomplete. I think it would be much better to enable CMD_DHCP6 in the
second patch when you add do_dhcp6().

3. struct dhcp6_sm_params has invalid description. You copy-passed it
from the previous func.

4. Add CMD_DHCP6 to sandbox_*_defconfig

5. if CONFIG_DHCP6_PXE_DHCP_OPTION is not configured then you will get
"cmd/pxe.c:172:1: warning: label ‘error_exit’ defined but not used"
during a build

6. How to determine IPv6 address in dhcp6 command 
=> help dhcp6
dhcp6 [loadAddress] [[hostIPaddr:]bootfilename]

In tftpboot []-notation is used to specify IPv6

7. net_set_timeout_handler(); has prototype void
net_set_timeout_handler(ulong iv, thand_f *f). Maybe it is better to
use net_set_timeout_handler(0, NULL); than net_set_timeout_handler(0,
0); 

8. You moved #define USE_IP6_CMD_PARAM  "-ipv6" from include/net6.h
to include/net.h
I think it is better to leave IPv6 defines in net6 header.

Thanks!


Re: [PATCH] net: ipv6: fix alignment errors on ARM

2023-01-19 Thread Vyacheslav V. Mitrofanov
On Thu, 2023-01-19 at 14:05 +0300, Sergei Antonov wrote:
> 
> On Thu, 19 Jan 2023 at 11:18, Vyacheslav V. Mitrofanov
>  wrote:
> > On Wed, 2023-01-18 at 20:52 +0300, Sergei Antonov wrote:
> > > Commands "ping6" and "tftpboot ... -ipv6" did not work on ARM
> > > because
> > > machine code expects 4-byte alignment and some structures from
> > > net6.h
> > > are not aligned in memory.
> > > 
> > > Fix by adding __packed, since it is already used in this file.
> > > 
> > > Signed-off-by: Sergei Antonov 
> > > ---
> > >  include/net6.h | 6 +++---
> > >  1 file changed, 3 insertions(+), 3 deletions(-)
> > > 
> > > diff --git a/include/net6.h b/include/net6.h
> > > index 9b3de028e6dc..2d7c5a096046 100644
> > > --- a/include/net6.h
> > > +++ b/include/net6.h
> > > @@ -24,7 +24,7 @@ struct in6_addr {
> > >  #define s6_addrin6_u.u6_addr8
> > >  #define s6_addr16  in6_u.u6_addr16
> > >  #define s6_addr32  in6_u.u6_addr32
> > > -};
> > > +} __packed;
> > > 
> > >  #define IN6ADDRSZ  sizeof(struct in6_addr)
> > >  #define INETHADDRSZsizeof(net_ethaddr)
> > > @@ -62,7 +62,7 @@ struct ip6_hdr {
> > > u8  hop_limit;
> > > struct in6_addr saddr;
> > > struct in6_addr daddr;
> > > -};
> > > +} __packed;
> > >  #define IP6_HDR_SIZE (sizeof(struct ip6_hdr))
> > > 
> > >  /* struct udp_hdr - User Datagram Protocol header */
> > > @@ -164,7 +164,7 @@ struct icmp6hdr {
> > >  #define icmp6_addrconf_managed icmp6_dataun.u_nd_ra.managed
> > >  #define icmp6_addrconf_other   icmp6_dataun.u_nd_ra.other
> > >  #define icmp6_rt_lifetime  icmp6_dataun.u_nd_ra.rt_lifetime
> > > -};
> > > +} __packed;
> > > 
> > >  extern struct in6_addr const net_null_addr_ip6;/* NULL
> > > IPv6
> > > address */
> > >  extern struct in6_addr net_gateway6;   /* Our gateways IPv6
> > > address
> > > */
> > > --
> > > 2.34.1
> > > 
> > Hello, Sergei!
> > 
> > I didn't get you a little bit. You mean holes between fields of
> > structures or alignment of the beginning?
> 
> No, it is not about holes between fields. It is about the address at
> which a structure is placed in memory. In combination with store
> merging it leads to unaligned memory access. At least for struct
> ip6_hdr, which I studied using assembly listing files. The struct
> ip6_hdr is not placed at 4-byte aligned address because it is 14
> bytes
> off from the beginning of the Ethernet packet.
> 
> Also see how the corresponding IPv4 struct ip_hdr from net.h was
> fixed
> by commit 704f3acfcf553. I should have referred to it in my commit
> description.
> 
I got you. It makes sense.
Thanks!

Reviewed-by: Viacheslav Mitrofanov 


Re: [PATCH] net: ipv6: fix alignment errors on ARM

2023-01-19 Thread Vyacheslav V. Mitrofanov
On Wed, 2023-01-18 at 20:52 +0300, Sergei Antonov wrote:
> Commands "ping6" and "tftpboot ... -ipv6" did not work on ARM because
> machine code expects 4-byte alignment and some structures from net6.h
> are not aligned in memory.
> 
> Fix by adding __packed, since it is already used in this file.
> 
> Signed-off-by: Sergei Antonov 
> ---
>  include/net6.h | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/include/net6.h b/include/net6.h
> index 9b3de028e6dc..2d7c5a096046 100644
> --- a/include/net6.h
> +++ b/include/net6.h
> @@ -24,7 +24,7 @@ struct in6_addr {
>  #define s6_addrin6_u.u6_addr8
>  #define s6_addr16  in6_u.u6_addr16
>  #define s6_addr32  in6_u.u6_addr32
> -};
> +} __packed;
> 
>  #define IN6ADDRSZ  sizeof(struct in6_addr)
>  #define INETHADDRSZsizeof(net_ethaddr)
> @@ -62,7 +62,7 @@ struct ip6_hdr {
> u8  hop_limit;
> struct in6_addr saddr;
> struct in6_addr daddr;
> -};
> +} __packed;
>  #define IP6_HDR_SIZE (sizeof(struct ip6_hdr))
> 
>  /* struct udp_hdr - User Datagram Protocol header */
> @@ -164,7 +164,7 @@ struct icmp6hdr {
>  #define icmp6_addrconf_managed icmp6_dataun.u_nd_ra.managed
>  #define icmp6_addrconf_other   icmp6_dataun.u_nd_ra.other
>  #define icmp6_rt_lifetime  icmp6_dataun.u_nd_ra.rt_lifetime
> -};
> +} __packed;
> 
>  extern struct in6_addr const net_null_addr_ip6;/* NULL IPv6
> address */
>  extern struct in6_addr net_gateway6;   /* Our gateways IPv6 address
> */
> --
> 2.34.1
> 
Hello, Sergei!

I didn't get you a little bit. You mean holes between fields of
structures or alignment of the beginning?

Frankly speaking I always thought that in that kind of structure like
below it is not necessary. To be honest I disassembled the same code on
arm and there were no holes. There is no "pack" attribute in linux too.
https://elixir.bootlin.com/linux/latest/source/include/uapi/linux/in6.h#L33

May be it could be other kind of error? 
union
{
u8  u6_addr8[16];
__be16  u6_addr16[8];
__be32  u6_addr32[4];
};
If you don't mind I add Ramon and Simon...


Re: [PATCH] net: ipv6: Fixed IPv6 string to address conversion off-by-one error

2023-01-16 Thread Vyacheslav V. Mitrofanov
On Fri, 2023-01-13 at 09:27 -0800, emohand...@linux.microsoft.com
wrote:
> From: Ehsan Mohandesi 
> 
> One extra character was being checked in the IPv6 string which caused
> the
> last character of the address to be neither '\0' nor ':'. This raises
> an
> error condition and causes the function to always return an error.
> This
> issue was resolved by this fix.
> 
> Signed-off-by: Ehsan Mohandesi 
> ---
>  net/tftp.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/net/tftp.c b/net/tftp.c
> index c780c33..328fd90 100644
> --- a/net/tftp.c
> +++ b/net/tftp.c
> @@ -837,7 +837,7 @@ void tftp_start(enum proto_t protocol)
>   e = strchr(net_boot_file_name, ']');
>   len = e - s;
>   if (s && e) {
> - string_to_ip6(s + 1, len,
> _remote_ip6);
> + string_to_ip6(s + 1, len - 1,
> _remote_ip6);
>   strlcpy(tftp_filename, e + 2, MAX_LEN);
>   } else {
>   strlcpy(tftp_filename,
> net_boot_file_name, MAX_LEN);
Reviewed-by: Viacheslav Mitrofanov 


Re: [PATCH] net: ipv6: Fix IPv6 netmask parsing

2023-01-08 Thread Vyacheslav V. Mitrofanov
On Fri, 2023-01-06 at 14:22 -0800, seanedm...@linux.microsoft.com
wrote:
> From: Sean Edmond 
> 
> It should be possible to specify a netmask when
> setting a static IPv6 address.  For example:
> setenv ip6addr 2001:cafe:cafe:cafe::100/64
> 
> The net_prefix_length and net_ip6 should be updated
> properly.
> 
> Signed-off-by: Sean Edmond 
> ---
>  net/net6.c | 9 ++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/net/net6.c b/net/net6.c
> index fdea078788..75577bcea1 100644
> --- a/net/net6.c
> +++ b/net/net6.c
> @@ -47,10 +47,13 @@ static int on_ip6addr(const char *name, const
> char *value, enum env_op op,
> }
> 
> mask = strchr(value, '/');
> -   len = strlen(value);
> 
> -   if (mask)
> -   net_prefix_length = simple_strtoul(value + len, NULL,
> 10);
> +   if (mask) {
> +   net_prefix_length = simple_strtoul(mask + 1, NULL,
> 10);
> +   len = mask - value;
> +   } else {
> +   len = strlen(value);
> +   }
> 
> return string_to_ip6(value, len, _ip6);
>  }
> --
> 2.39.0
I do agree with your changes.Thanks

Reviewed-by: Viacheslav Mitrofanov 


[PATCH] board: amlogic: jethub j100: add rescue boot from microSD

2022-12-22 Thread Vyacheslav Bocharov
From: Viacheslav Bocharov 

The new JetHub D1+ has a microSD slot. Add rescue boot from microSD

Signed-off-by: Viacheslav Bocharov 
---
 include/configs/jethub.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/configs/jethub.h b/include/configs/jethub.h
index 35f85095ac..e22db4991d 100644
--- a/include/configs/jethub.h
+++ b/include/configs/jethub.h
@@ -12,6 +12,7 @@
 #define BOOTENV_DEV_RESCUE(devtypeu, devtypel, instance) \
"bootcmd_rescue=" \
"if gpio input 10; then " \
+   "run bootcmd_mmc0; " \
"run bootcmd_usb0;" \
"fi;\0"
 #else
-- 
2.34.1



Re: [PATCH 1/1] net: missing break after net_ip6_handler()

2022-12-21 Thread Mitrofanov Vyacheslav V .
On Mon, 2022-12-12 at 06:19 -0800, Heinrich Schuchardt wrote:
> «Внимание! Данное письмо от внешнего адресата!»
> 
> On 12/7/22 06:52, Vyacheslav Mitrofanov V wrote:
> > On Wed, 2022-12-07 at 09:42 -0500, Tom Rini wrote:
> > > On Wed, Dec 07, 2022 at 03:29:37PM +0100, Heinrich Schuchardt
> > > wrote:
> > > 
> > > > Don't fall through to handling an IPv6 header as IPv4.
> > > > 
> > > > Fixes: ffdbf3bad5f3 ("net: ipv6: Incorporate IPv6 support into
> > > > u-
> > > > boot net subsystem")
> > > > Addresses-Coverity-ID: 430975 ("Missing break in switch")
> > > > Signed-off-by: Heinrich Schuchardt <
> > > > heinrich.schucha...@canonical.com>
> > > > ---
> > > > Do we have a unit trest of IPv6?
> > > > I guess we should at least do a IPv6 ping.
> > > 
> > > There are a few tests, yes, but more would be good.
> > > 
> > Hello!
> > 
> > I have tested IPv6 (ping6 and tftpboot) with my own python scripts
> > before sending to pathwork. I'll do some test conversion to use
> > them with u-boot or add new tests for that soon!
> > Thanks!
> 
> Hello Vycheslav,
> 
> would you agree with that break being added? I didn't see a review
> response.
> 
> Best regards
> 
> Heinrich
> 
Hello, Heinrich. I'm sorry for the long response, your mail got to spam
folder.

Yes I do agree with you that missing break has to be there. I have
already sent reviewed sign to your patch. 

Many thanks for your work!

P.S. As I promised I'll add soon new tests but it is still in process.
Very heavy schedule by the end of the year...


Re: [PATCH 1/1] net: missing break after net_ip6_handler()

2022-12-21 Thread Mitrofanov Vyacheslav V .
On Wed, 2022-12-07 at 15:29 +0100, Heinrich Schuchardt wrote:
> 
> Don't fall through to handling an IPv6 header as IPv4.
> 
> Fixes: ffdbf3bad5f3 ("net: ipv6: Incorporate IPv6 support into u-boot 
> net subsystem")
> Addresses-Coverity-ID: 430975 ("Missing break in switch")
> Signed-off-by: Heinrich Schuchardt  >
> ---
> Do we have a unit trest of IPv6?
> I guess we should at least do a IPv6 ping.
> ---
>  net/net.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/net/net.c b/net/net.c
> index 1c39acc493..57da9bda85 100644
> --- a/net/net.c
> +++ b/net/net.c
> @@ -1269,6 +1269,7 @@ void net_process_received_packet(uchar
> *in_packet, int len)
>  #if IS_ENABLED(CONFIG_IPV6)
> case PROT_IP6:
> net_ip6_handler(et, (struct ip6_hdr *)ip, len);
> +   break;
>  #endif
> case PROT_IP:
> debug_cond(DEBUG_NET_PKT, "Got IP\n");
> --
> 2.37.2
> 
Reviewed-by: Viacheslav Mitrofanov 


Re: [PATCH 1/1] net: missing break after net_ip6_handler()

2022-12-07 Thread Vyacheslav Mitrofanov V
On Wed, 2022-12-07 at 09:42 -0500, Tom Rini wrote:
> On Wed, Dec 07, 2022 at 03:29:37PM +0100, Heinrich Schuchardt wrote:
> 
> > Don't fall through to handling an IPv6 header as IPv4.
> > 
> > Fixes: ffdbf3bad5f3 ("net: ipv6: Incorporate IPv6 support into u-
> > boot net subsystem")
> > Addresses-Coverity-ID: 430975 ("Missing break in switch")
> > Signed-off-by: Heinrich Schuchardt <
> > heinrich.schucha...@canonical.com>
> > ---
> > Do we have a unit trest of IPv6?
> > I guess we should at least do a IPv6 ping.
> 
> There are a few tests, yes, but more would be good.
> 
Hello!

I have tested IPv6 (ping6 and tftpboot) with my own python scripts before 
sending to pathwork. I'll do some test conversion to use them with u-boot or 
add new tests for that soon!
Thanks!


Re: [PATCH] net: ipv6: Fix link-partner MAC address assignment

2022-12-07 Thread Vyacheslav Mitrofanov V
On Tue, 2022-12-06 at 13:22 +0100, Daniel Schwierzeck wrote:
> «Внимание! Данное письмо от внешнего адресата!»
> 
> On 12/6/22 08:08, Viacheslav Mitrofanov wrote:
> > MAC address of a link-partner is not saved for future use because
> > of
> > bad condition of if statement. Moreover it can potentially cause to
> > NULL-pointer dereference.
> > 
> > Signed-off-by: Viacheslav Mitrofanov 
> > ---
> >   net/ndisc.c | 2 +-
> >   1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> 
> Reviewed-by: Daniel Schwierzeck 
> 
> > diff --git a/net/ndisc.c b/net/ndisc.c
> > index 3c0eeeaea3..56fc6390bc 100644
> > --- a/net/ndisc.c
> > +++ b/net/ndisc.c
> > @@ -264,7 +264,7 @@ int ndisc_receive(struct ethernet_hdr *et,
> > struct ip6_hdr *ip6, int len)
> >   ndisc_extract_enetaddr(ndisc,
> > neigh_eth_addr);
> > 
> >   /* save address for later use */
> > - if (!net_nd_packet_mac)
> > + if (net_nd_packet_mac)
> >   memcpy(net_nd_packet_mac,
> > neigh_eth_addr, 7);
> > 
> >   /* modify header, and transmit it */
> 
> --
> - Daniel
> 
This patch is not appropriate!net_nd_packet_mac is just a pointer,
moreover there is no memory allocation. It has just keep a pointer to
neigh_eth_addr.
So the solution must be sth. like net_nd_packet_mac = neigh_eth_addr;


Re: [PATCH 1/1] net: don't memcpy to NULL

2022-12-07 Thread Vyacheslav Mitrofanov V
On Wed, 2022-12-07 at 11:53 +0100, Heinrich Schuchardt wrote:
> «Внимание! Данное письмо от внешнего адресата!»
> 
> In ndisc_receive() 7 bytes are copied from a buffer of size 6 to
> NULL.
> 
> net_nd_packet_mac is a pointer. If it is NULL, we should set it to
> the
> address of the buffer with the MAC address.
> 
> Addresses-Coverity-ID: 430974 ("Out-of-bounds access")
> Fixes: c6610e1d90ea ("net: ipv6: Add Neighbor Discovery Protocol
> (NDP)")
> Signed-off-by: Heinrich Schuchardt  >
> ---
>  net/ndisc.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/net/ndisc.c b/net/ndisc.c
> index 3c0eeeaea3..367dae7676 100644
> --- a/net/ndisc.c
> +++ b/net/ndisc.c
> @@ -265,7 +265,7 @@ int ndisc_receive(struct ethernet_hdr *et, struct
> ip6_hdr *ip6, int len)
> 
> /* save address for later use */
> if (!net_nd_packet_mac)
> -   memcpy(net_nd_packet_mac,
> neigh_eth_addr, 7);
> +   net_nd_packet_mac = neigh_eth_addr;
> 
> /* modify header, and transmit it */
> memcpy(((struct ethernet_hdr
> *)net_nd_tx_packet)->et_dest,
> --
> 2.37.2
> 
> 
Reviewed-by: Viacheslav Mitrofanov 



Re: [PATCH v5 04/19] net: ipv6: Add Neighbor Discovery Protocol (NDP)

2022-12-05 Thread Vyacheslav Mitrofanov V
On Tue, 2022-12-06 at 03:14 +0100, Daniel Schwierzeck wrote:
> «Внимание! Данное письмо от внешнего адресата!»
> 
> On 12/2/22 10:18, Viacheslav Mitrofanov wrote:
> > Implement basic of NDP. It doesn't include such things as Router
> > Solicitation, Router Advertisement and Redirect. It just has
> > Neighbor
> > Solicitation and Neighbor Advertisement. Only these two features
> > are used
> > in u-boot IPv6. Implementation of some NDP functions uses API that
> > was
> > exposed in "net: ipv6: Add IPv6 basic primitives".
> > 
> > Also this patch inlcudes update in Makefile to build NDP.
> > 
> > Series-changes: 3
> > - Added structures and functions descriptions
> > - Fixed style problems
> > 
> > Series-changes: 4
> > - Fixed structures and functions description style
> > 
> > Signed-off-by: Viacheslav Mitrofanov 
> > Reviewed-by: Ramon Fried 
> > Reviewed-by: Simon Glass 
> > ---
> >   include/ndisc.h | 102 +
> >   net/Makefile|   1 +
> >   net/ndisc.c | 289
> > 
> >   3 files changed, 392 insertions(+)
> >   create mode 100644 include/ndisc.h
> >   create mode 100644 net/ndisc.c
> > 
> 
> ...
> 
> > +
> > +int ndisc_receive(struct ethernet_hdr *et, struct ip6_hdr *ip6,
> > int len)
> > +{
> > + struct icmp6hdr *icmp =
> > + (struct icmp6hdr *)(((uchar *)ip6) + IP6_HDR_SIZE);
> > + struct nd_msg *ndisc = (struct nd_msg *)icmp;
> > + uchar neigh_eth_addr[6];
> > +
> > + switch (icmp->icmp6_type) {
> > + case IPV6_NDISC_NEIGHBOUR_SOLICITATION:
> > + debug("received neighbor solicitation for %pI6c from
> > %pI6c\n",
> > +   >target, >saddr);
> > + if (ip6_is_our_addr(>target) &&
> > + ndisc_has_option(ip6, ND_OPT_SOURCE_LL_ADDR)) {
> > + ndisc_extract_enetaddr(ndisc,
> > neigh_eth_addr);
> > + ip6_send_na(neigh_eth_addr, >saddr,
> > + >target);
> > + }
> > + break;
> > +
> > + case IPV6_NDISC_NEIGHBOUR_ADVERTISEMENT:
> > + /* are we waiting for a reply ? */
> > + if (ip6_is_unspecified_addr(_nd_sol_packet_ip6))
> > + break;
> > +
> > + if ((memcmp(>target, _nd_rep_packet_ip6,
> > + sizeof(struct in6_addr)) == 0) &&
> > + ndisc_has_option(ip6, ND_OPT_TARGET_LL_ADDR)) {
> > + ndisc_extract_enetaddr(ndisc,
> > neigh_eth_addr);
> > +
> > + /* save address for later use */
> > + if (!net_nd_packet_mac)
> > + memcpy(net_nd_packet_mac,
> > neigh_eth_addr, 7);
> 
> Coverity reports the following:
> 
> CID 430977:  Null pointer dereferences  (FORWARD_NULL)
> Passing null pointer "net_nd_packet_mac" to "memcpy", which
> dereferences
> it. [Note: The source code implementation of the function has been
> overridden by a builtin model.]
> 
> CID 430974:  Memory - corruptions  (OVERRUN)
> Overrunning array "neigh_eth_addr" of 6 bytes by passing it to a
> function which accesses it at byte offset 6 using argument "7UL".
> [Note:
> The source code implementation of the function has been overridden by
> a
> builtin model.]
> 
> 
> Did you mean to write the following which would make more sense?
> 
> if (net_nd_packet_mac)
>  memcpy(net_nd_packet_mac, neigh_eth_addr, 7);
> 
> 
> > +
> > + /* modify header, and transmit it */
> > + memcpy(((struct ethernet_hdr
> > *)net_nd_tx_packet)->et_dest,
> > +neigh_eth_addr, 6);
> > +
> > + net_send_packet(net_nd_tx_packet,
> > + net_nd_tx_packet_size);
> > +
> > + /* no ND request pending now */
> > + net_nd_sol_packet_ip6 = net_null_addr_ip6;
> > + net_nd_tx_packet_size = 0;
> > + net_nd_packet_mac = NULL;
> > + }
> > + break;
> > + default:
> > + debug("Unexpected ICMPv6 type 0x%x\n", icmp-
> > >icmp6_type);
> > + return -1;
> > + }
> > +
> > + return 0;
> > +}
> 
> --
> - Daniel
> 
Hello Daniel! I do agree with your comments.
Will be fixed.Thank you!


Re: [PATCH v5 09/19] net: ipv6: Incorporate IPv6 support into u-boot net subsystem

2022-12-05 Thread Vyacheslav Mitrofanov V
On Tue, 2022-12-06 at 03:13 +0100, Daniel Schwierzeck wrote:
> «Внимание! Данное письмо от внешнего адресата!»
> 
> On 12/2/22 10:18, Viacheslav Mitrofanov wrote:
> > Add net_ip6_handler (an IPv6 packet handler) into net_loop. Add
> > neighbor discovery mechanism into network init process. That is the
> > main step to run IPv6 in u-boot. Now u-boot is capable to use NDP
> > and
> > handle IPv6 packets.
> > 
> > Signed-off-by: Viacheslav Mitrofanov 
> > Reviewed-by: Ramon Fried 
> > Reviewed-by: Simon Glass 
> > ---
> >   net/net.c | 23 ++-
> >   1 file changed, 22 insertions(+), 1 deletion(-)
> > 
> > diff --git a/net/net.c b/net/net.c
> > index aca20e43b0..63bf962b53 100644
> > --- a/net/net.c
> > +++ b/net/net.c
> > @@ -91,6 +91,8 @@
> >   #include 
> >   #include 
> >   #include 
> > +#include 
> > +#include 
> >   #include 
> >   #include 
> >   #include 
> > @@ -343,8 +345,17 @@ void net_auto_load(void)
> > 
> >   static int net_init_loop(void)
> >   {
> > - if (eth_get_dev())
> > + if (eth_get_dev()) {
> >   memcpy(net_ethaddr, eth_get_ethaddr(), 6);
> > +
> > + if (IS_ENABLED(CONFIG_IPV6)) {
> > + ip6_make_lladdr(_link_local_ip6,
> > net_ethaddr);
> > + if (!memcmp(_ip6, _null_addr_ip6,
> > + sizeof(struct in6_addr)))
> > + memcpy(_ip6, _link_local_ip6,
> > +sizeof(struct in6_addr));
> > + }
> > + }
> >   else
> >   /*
> >* Not ideal, but there's no way to get the actual
> > error, and I
> > @@ -385,6 +396,7 @@ int net_init(void)
> >   (i + 1) * PKTSIZE_ALIGN;
> >   }
> >   arp_init();
> > + ndisc_init();
> >   net_clear_handlers();
> > 
> >   /* Only need to setup buffer pointers once. */
> > @@ -589,6 +601,11 @@ restart:
> >   if (arp_timeout_check() > 0)
> >   time_start = get_timer(0);
> > 
> > + if (IS_ENABLED(CONFIG_IPV6)) {
> > + if (use_ip6 && (ndisc_timeout_check() > 0))
> > + time_start = get_timer(0);
> > + }
> > +
> >   /*
> >*  Check the ethernet for a new packet.  The
> > ethernet
> >*  receive routine will process it.
> > @@ -1243,6 +1260,10 @@ void net_process_received_packet(uchar
> > *in_packet, int len)
> >   case PROT_RARP:
> >   rarp_receive(ip, len);
> >   break;
> > +#endif
> > +#if IS_ENABLED(CONFIG_IPV6)
> > + case PROT_IP6:
> > + net_ip6_handler(et, (struct ip6_hdr *)ip, len);
> >   #endif
> 
> Coverity reports the following:
> 
> CID 430975:  Control flow issues  (MISSING_BREAK)
> The case for value "34525" is not terminated by a "break" statement.
> 
> 
> Either a 'break;' or a 'fallthrough;' is missing. It looks like
> net_ip6_handler() already handles ICMP and UDP so probably the
> PROT_IP
> case shouldn't be executed at all. Therefore you should add a
> 'break;'.
> 
> 
> >   case PROT_IP:
> >   debug_cond(DEBUG_NET_PKT, "Got IP\n");
> 
> --
> - Daniel
> 
Thanks Daniel! I do agree with you. It is missed break.


Re: [PATCH v4 00/17] IPv6 support

2022-12-01 Thread Vyacheslav Mitrofanov V
Hello, Peter!
I see your point and I think that you are right in some aspects. LwIP like 
other stacks can be used instead of built-in stack but it is necessary to make 
quite a big work to port it, write tests and so on. It is bigger than my tiny 
patches.

I'm not against the situation when someone do that work and port other stack. 
But I think it is better to give people IPv6 right now than wait it again.



От: Peter Robinson 
Отправлено: 1 декабря 2022 г. 16:03:46
Кому: Tom Rini
Копия: Vyacheslav Mitrofanov V; rfried@gmail.com; joe.hershber...@ni.com; 
w...@denx.de; u-boot@lists.denx.de; judge.pack...@gmail.com; li...@yadro.com; 
s...@chromium.org
Тема: Re: [PATCH v4 00/17] IPv6 support

«Внимание! Данное письмо от внешнего адресата!»

Hi Tom and others,

> > Tom, maybe it is better to change configs add ifdefs or do sth else to 
> > exclude them from the build if IPV6 is not configured?
>
> There's two parts to this, yes.  Sandbox needs to enable ipv6 so that
> the tests are run, and the tests need to be be appropriately ifdef'd so
> that they don't try and be run on platforms without ipv6.

I was wondering with the need to support IPv6, http and tls and the
various components whether we wouldn't just be better off using LwIP
[1][2]>, it gives us basically everything we need for IPv6, HTTP boot
and other things we need, and is used on microcontrollers (I came
across it recently when playing with micropython) so it's small. I
feel it would save a lot of time maintaining an independent IP stack
and being used a cross a bunch of different projects is quite widely
used/developed. Thoughts?

Peter

[1] https://savannah.nongnu.org/forum/forum.php?forum_id=9248
[2] https://en.wikipedia.org/wiki/LwIP



Re: [PATCH v4 00/17] IPv6 support

2022-11-29 Thread Vyacheslav Mitrofanov V
I'll fix it soon and send new patchset!

Thanks!


От: Tom Rini 
Отправлено: 29 ноября 2022 г. 16:49:48
Кому: Vyacheslav Mitrofanov V
Копия: rfried@gmail.com; joe.hershber...@ni.com; w...@denx.de; 
u-boot@lists.denx.de; judge.pack...@gmail.com; li...@yadro.com; 
s...@chromium.org
Тема: Re: [PATCH v4 00/17] IPv6 support

On Tue, Nov 29, 2022 at 08:39:36AM +, Vyacheslav Mitrofanov V wrote:

> Tom, maybe it is better to change configs add ifdefs or do sth else to 
> exclude them from the build if IPV6 is not configured?

There's two parts to this, yes.  Sandbox needs to enable ipv6 so that
the tests are run, and the tests need to be be appropriately ifdef'd so
that they don't try and be run on platforms without ipv6.

--
Tom


Re: [PATCH v4 00/17] IPv6 support

2022-11-29 Thread Vyacheslav Mitrofanov V
Tom, maybe it is better to change configs add ifdefs or do sth else to exclude 
them from the build if IPV6 is not configured?

Thanks!


От: Vyacheslav Mitrofanov V
Отправлено: 29 ноября 2022 г. 11:35:13
Кому: Tom Rini
Копия: rfried@gmail.com; joe.hershber...@ni.com; w...@denx.de; 
u-boot@lists.denx.de; judge.pack...@gmail.com; li...@yadro.com; 
s...@chromium.org
Тема: Re: [PATCH v4 00/17] IPv6 support


Hello Tom!
I tested this problem and I think it is necessary to set CONFIG_IPV6.
Without that option tests fail.

Thanks!


От: Tom Rini 
Отправлено: 28 ноября 2022 г. 18:34:58
Кому: Vyacheslav Mitrofanov V
Копия: rfried@gmail.com; joe.hershber...@ni.com; w...@denx.de; 
u-boot@lists.denx.de; judge.pack...@gmail.com; li...@yadro.com; 
s...@chromium.org
Тема: Re: [PATCH v4 00/17] IPv6 support

On Thu, Sep 08, 2022 at 02:58:48PM +0300, Viacheslav Mitrofanov wrote:

> This patch set adds basic IPv6 support to U-boot.
> It is based on Chris's Packham patches
> (https://lists.denx.de/pipermail/u-boot/2017-January/279366.html)
> Chris's patches were taken as base. There were efforts to launch it on
> HiFive SiFive Unmatched board but the board didn't work well. The code was
> refactored, fixed some bugs as CRC for little-endian, some parts were 
> implemented in
> our own way, something was taken from Linux. Finally we did manual tests and 
> the
> board worked well.
>
> Testing was done on HiFive SiFive Unmatched board (RISC-V)
>
> Signed-off-by: Viacheslav Mitrofanov 
> ---
> Changes in v2:
>  - Split big patches into smaller
>  - If an address in tftpboot is IPv6 than use IPv6 to boot
>  - Add tests
>
> Changes in v3:
>  - Added functions and structures description in whole patch-series
>  - Removed memory allocation in on_ip6addr()
>  - Some functions got return code from errno.h
>  - Add to string_to_ip6() length parameter to avoid obligatory null 
> termination
>  - Add a lot of small decorative cnages
>
> Changes in v4:
>  - Fixed funcs and structures style description
>  - Added omitted tags

Testing this locally in sandbox I see:
FAILED test/py/tests/test_ut.py::test_ut[ut_dm_dm_test_csum_ipv6_magic] - 
AssertionError: as...
FAILED test/py/tests/test_ut.py::test_ut[ut_dm_dm_test_ip6_addr_in_subnet] - 
AssertionError:...
FAILED test/py/tests/test_ut.py::test_ut[ut_dm_dm_test_ip6_make_lladdr] - 
assert False
FAILED test/py/tests/test_ut.py::test_ut[ut_dm_dm_test_ip6_make_snma] - assert 
False
FAILED test/py/tests/test_ut.py::test_ut[ut_dm_dm_test_string_to_ip6] - 
AssertionError: asse...
and this happens in CI as well:
https://source.denx.de/u-boot/u-boot/-/pipelines/14245
https://dev.azure.com/u-boot/u-boot/_build/results?buildId=5432=results

If you can't replicate the failures locally you should be able to
trigger CI:
https://u-boot.readthedocs.io/en/latest/develop/ci_testing.html

Thanks for pushing this along!

--
Tom


Re: [PATCH v4 00/17] IPv6 support

2022-11-29 Thread Vyacheslav Mitrofanov V
Hello Tom!
I tested this problem and I think it is necessary to set CONFIG_IPV6.
Without that option tests fail.

Thanks!


От: Tom Rini 
Отправлено: 28 ноября 2022 г. 18:34:58
Кому: Vyacheslav Mitrofanov V
Копия: rfried@gmail.com; joe.hershber...@ni.com; w...@denx.de; 
u-boot@lists.denx.de; judge.pack...@gmail.com; li...@yadro.com; 
s...@chromium.org
Тема: Re: [PATCH v4 00/17] IPv6 support

On Thu, Sep 08, 2022 at 02:58:48PM +0300, Viacheslav Mitrofanov wrote:

> This patch set adds basic IPv6 support to U-boot.
> It is based on Chris's Packham patches
> (https://lists.denx.de/pipermail/u-boot/2017-January/279366.html)
> Chris's patches were taken as base. There were efforts to launch it on
> HiFive SiFive Unmatched board but the board didn't work well. The code was
> refactored, fixed some bugs as CRC for little-endian, some parts were 
> implemented in
> our own way, something was taken from Linux. Finally we did manual tests and 
> the
> board worked well.
>
> Testing was done on HiFive SiFive Unmatched board (RISC-V)
>
> Signed-off-by: Viacheslav Mitrofanov 
> ---
> Changes in v2:
>  - Split big patches into smaller
>  - If an address in tftpboot is IPv6 than use IPv6 to boot
>  - Add tests
>
> Changes in v3:
>  - Added functions and structures description in whole patch-series
>  - Removed memory allocation in on_ip6addr()
>  - Some functions got return code from errno.h
>  - Add to string_to_ip6() length parameter to avoid obligatory null 
> termination
>  - Add a lot of small decorative cnages
>
> Changes in v4:
>  - Fixed funcs and structures style description
>  - Added omitted tags

Testing this locally in sandbox I see:
FAILED test/py/tests/test_ut.py::test_ut[ut_dm_dm_test_csum_ipv6_magic] - 
AssertionError: as...
FAILED test/py/tests/test_ut.py::test_ut[ut_dm_dm_test_ip6_addr_in_subnet] - 
AssertionError:...
FAILED test/py/tests/test_ut.py::test_ut[ut_dm_dm_test_ip6_make_lladdr] - 
assert False
FAILED test/py/tests/test_ut.py::test_ut[ut_dm_dm_test_ip6_make_snma] - assert 
False
FAILED test/py/tests/test_ut.py::test_ut[ut_dm_dm_test_string_to_ip6] - 
AssertionError: asse...
and this happens in CI as well:
https://source.denx.de/u-boot/u-boot/-/pipelines/14245
https://dev.azure.com/u-boot/u-boot/_build/results?buildId=5432=results

If you can't replicate the failures locally you should be able to
trigger CI:
https://u-boot.readthedocs.io/en/latest/develop/ci_testing.html

Thanks for pushing this along!

--
Tom


Re: [PATCH 01/17] net: ipv6: Add IPv6 basic primitives

2022-09-12 Thread Vyacheslav Mitrofanov V
On Mon, 2022-09-12 at 10:23 +0300, Ramon Fried wrote:
> «Внимание! Данное письмо от внешнего адресата!»
> 
> On Tue, Sep 6, 2022 at 6:10 PM Viacheslav Mitrofanov
>  wrote:
> > This patch is a collection of basic primitives that are
> > prerequisite for
> > further IPv6 implementation.
> > 
> > There are structures definition such as IPv6 header, UDP header
> > (for TFTP), ICMPv6 header. There are auxiliary defines such as
> > protocol
> > codes, padding, struct size and etc. Also here are functions
> > prototypes
> > and its empty implementation that will be used as API for further
> > patches.
> > Here are variables declaration such as IPv6 address of our host,
> > gateway, ipv6 server.
> > 
> > Signed-off-by: Viacheslav Mitrofanov 
> > ---
> >  include/net6.h | 369
> > +
> >  net/net6.c |  31 +
> >  2 files changed, 400 insertions(+)
> >  create mode 100644 include/net6.h
> >  create mode 100644 net/net6.c
> > 
> > diff --git a/include/net6.h b/include/net6.h
> > new file mode 100644
> > index 00..80236bd5ac
> > --- /dev/null
> > +++ b/include/net6.h
> > @@ -0,0 +1,369 @@
> > +/* SPDX-License-Identifier: GPL-2.0+ */
> > +/*
> > + * Copyright (C) 2013 Allied Telesis Labs NZ
> > + * Chris Packham, 
> > + *
> > + * Copyright (C) 2022 YADRO
> > + * Viacheslav Mitrofanov 
> > + */
> > +
> > +#ifndef __NET6_H__
> > +#define __NET6_H__
> > +
> > +#include 
> > +#include 
> > +
> > +/* struct in6_addr - 128 bits long IPv6 address */
> > +struct in6_addr {
> > +   union {
> > +   u8  u6_addr8[16];
> > +   __be16  u6_addr16[8];
> > +   __be32  u6_addr32[4];
> > +   } in6_u;
> > +
> > +#define s6_addrin6_u.u6_addr8
> > +#define s6_addr16  in6_u.u6_addr16
> > +#define s6_addr32  in6_u.u6_addr32
> > +};
> > +
> > +#define IN6ADDRSZ  sizeof(struct in6_addr)
> > +#define INETHADDRSZsizeof(net_ethaddr)
> > +
> > +#define PROT_IP6   0x86DD  /* IPv6 protocol */
> > +#define PROT_ICMPV658  /* ICMPv6 protocol*/
> > +
> > +#define IPV6_ADDRSCOPE_INTF0x01
> > +#define IPV6_ADDRSCOPE_LINK0x02
> > +#define IPV6_ADDRSCOPE_AMDIN   0x04
> > +#define IPV6_ADDRSCOPE_SITE0x05
> > +#define IPV6_ADDRSCOPE_ORG 0x08
> > +#define IPV6_ADDRSCOPE_GLOBAL  0x0E
> > +
> > +#define USE_IP6_CMD_PARAM  "-ipv6"
> > +
> > +/**
> > + * struct ipv6hdr - Internet Protocol V6 (IPv6) header.
> > + *
> > + * IPv6 packet header as defined in RFC 2460.
> > + */
> > +struct ip6_hdr {
> > +#if defined(__LITTLE_ENDIAN_BITFIELD)
> > +   u8  priority:4,
> > +   version:4;
> > +#elif defined(__BIG_ENDIAN_BITFIELD)
> > +   u8  version:4,
> > +   priority:4;
> > +#else
> > +#error  "Please fix "
> > +#endif
> > +   u8  flow_lbl[3];
> > +   __be16  payload_len;
> > +   u8  nexthdr;
> > +   u8  hop_limit;
> > +   struct in6_addr saddr;
> > +   struct in6_addr daddr;
> > +};
> > +#define IP6_HDR_SIZE (sizeof(struct ip6_hdr))
> > +
> > +/* struct udp_hdr - User Datagram Protocol header */
> > +struct udp_hdr {
> > +   u16 udp_src;/* UDP source
> > port  */
> > +   u16 udp_dst;/* UDP destination
> > port */
> > +   u16 udp_len;/* Length of UDP
> > packet */
> > +   u16 udp_xsum;   /*
> > Checksum */
> > +} __packed;
> > +
> > +/*
> > + * Handy for static initialisations of struct in6_addr, atlhough
> > the
> > + * c99 '= { 0 }' idiom might work depending on you compiler.
> > + */
> > +#define ZERO_IPV6_ADDR { { { 0x00, 0x00, 0x00, 0x00, \
> > + 0x00, 0x00, 0x00, 0x00, \
> > + 0x00, 0x00, 0x00, 0x00, \
> > + 0x00, 0x00, 0x00, 0x00 } } }
> > +
> > +#define IPV6_LINK_LOCAL_PREFIX 0xfe80
> > +
> > +/* hop limit for neighbour discovery packets */
> > +#define IPV6_NDISC_HOPLIMIT 255
> > +#define NDISC_TIMEOUT  5000UL
> > +#define NDISC_TIMEOUT_COUNT 3
> > +
> > +/* struct icmp6hdr - Internet Control Message Protocol header for
> > IPV6 */
> > +struct icmp6hdr {
> > +   u8  icmp6_type;
> > +#define IPV6_ICMP_ECHO_REQUEST 128
> > +#define IPV6_ICMP_ECHO_REPLY   129
> > +#define IPV6_NDISC_ROUTER_SOLICITATION 133
> > +#define IPV6_NDISC_ROUTER_ADVERTISEMENT134
> > +#define IPV6_NDISC_NEIGHBOUR_SOLICITATION  135
> > +#define IPV6_NDISC_NEIGHBOUR_ADVERTISEMENT 136
> > +#define IPV6_NDISC_REDIRECT137
> > +   u8  icmp6_code;
> > +   __be16  icmp6_cksum;
> > +
> > +   /* ICMPv6 data */
> > +   union {
> > +   __be32  un_data32[1];
> > +   __be16  un_data16[2];
> > +   u8  un_data8[4];
> > +
> > +   

Re: [PATCH 04/17] net: ipv6: Add Neighbor Discovery Protocol (NDP)

2022-09-11 Thread Vyacheslav Mitrofanov V
On Fri, 2022-09-09 at 08:44 -0600, Simon Glass wrote:
> «Внимание! Данное письмо от внешнего адресата!»
> 
> On Thu, 8 Sept 2022 at 05:59, Viacheslav Mitrofanov
>  wrote:
> > Implement basic of NDP. It doesn't include such things as Router
> > Solicitation, Router Advertisement and Redirect. It just has
> > Neighbor
> > Solicitation and Neighbor Advertisement. Only these two features
> > are used
> > in u-boot IPv6. Implementation of some NDP functions uses API that
> > was
> > exposed in "net: ipv6: Add IPv6 basic primitives".
> > 
> > Also this patch inlcudes update in Makefile to build NDP.
> > 
> > Series-changes: 3
> > - Added structures and functions descriptions
> > - Fixed style problems
> > 
> > Series-changes: 4
> > - Fixed structures and functions description style
> > 
> > Signed-off-by: Viacheslav Mitrofanov 
> > ---
> >  include/ndisc.h | 102 +
> >  net/Makefile|   1 +
> >  net/ndisc.c | 289
> > 
> >  3 files changed, 392 insertions(+)
> >  create mode 100644 include/ndisc.h
> >  create mode 100644 net/ndisc.c

Hello, Simon!
That is an empty message. I think you accidentally forgot to give a
response.

Thanks!


Re: [PATCH v4 00/17] IPv6 support

2022-09-11 Thread Vyacheslav Mitrofanov V
On Thu, 2022-09-08 at 14:58 +0300, Viacheslav Mitrofanov wrote:
> This patch set adds basic IPv6 support to U-boot.
> It is based on Chris's Packham patches
> (https://lists.denx.de/pipermail/u-boot/2017-January/279366.html)
> Chris's patches were taken as base. There were efforts to launch it
> on
> HiFive SiFive Unmatched board but the board didn't work well. The
> code was
> refactored, fixed some bugs as CRC for little-endian, some parts were
> implemented in
> our own way, something was taken from Linux. Finally we did manual
> tests and the
> board worked well.
> 
> Testing was done on HiFive SiFive Unmatched board (RISC-V)
> 
> Signed-off-by: Viacheslav Mitrofanov 
> 
> ---
> Changes in v2:
>  - Split big patches into smaller
>  - If an address in tftpboot is IPv6 than use IPv6 to boot
>  - Add tests
> 
> Changes in v3:
>  - Added functions and structures description in whole patch-series
>  - Removed memory allocation in on_ip6addr()
>  - Some functions got return code from errno.h
>  - Add to string_to_ip6() length parameter to avoid obligatory null
> termination
>  - Add a lot of small decorative cnages
> 
> Changes in v4:
>  - Fixed funcs and structures style description
>  - Added omitted tags 
> 
> Viacheslav Mitrofanov (17):
>   net: ipv6: Add IPv6 basic primitives
>   net: ipv6: Add IPv6 build options
>   net: ipv6: Add callbacks declarations to get access to IPv6
> variables
>   net: ipv6: Add Neighbor Discovery Protocol (NDP)
>   net: ipv6: Add string_to_ip6 converter
>   net: ipv6: Enable IPv6 typeconversion specifier
>   net: ipv6: Add ip6addr, gatewayip6, serverip6 variables callbacks
>   net: ipv6: Add implementation of main IPv6 functions
>   net: ipv6: Incorporate IPv6 support into u-boot net subsystem
>   net: tftp: Add IPv6 support for tftpboot
>   net: ping6: Add ping6 command
>   test: dm: eth: Add string_to_ip6 test
>   test: dm: eth: Add csum_ipv6_magic test
>   test: dm: eth: Add ip6_addr_in_subnet test
>   test: dm: eth: Add ip6_make_snma test
>   test: dm: eth: Add ip6_make_lladdr test
>   test/py: add a ping6 test
> 
>  cmd/Kconfig   |   7 +
>  cmd/net.c |  61 ++
>  include/env_callback.h|  10 +
>  include/env_flags.h   |  10 +
>  include/ndisc.h   | 102 +
>  include/net.h |   4 +-
>  include/net6.h| 432 
>  lib/net_utils.c   | 109 ++
>  lib/vsprintf.c|   7 +-
>  net/Kconfig   |  10 +
>  net/Makefile  |   3 +
>  net/ndisc.c   | 289 +
>  net/net.c |  53 -
>  net/net6.c| 445
> ++
>  net/ping6.c   | 118 ++
>  net/tftp.c|  63 +-
>  test/dm/eth.c | 146 +
>  test/py/tests/test_net.py |  15 ++
>  18 files changed, 1865 insertions(+), 19 deletions(-)
>  create mode 100644 include/ndisc.h
>  create mode 100644 include/net6.h
>  create mode 100644 net/ndisc.c
>  create mode 100644 net/net6.c
>  create mode 100644 net/ping6.c
> 

Many thanks, Simon, for your reviewing!
A really appreciate this!

Thanks, Viacheslav.


Re: [PATCH v2 00/17] IPv6 support

2022-09-03 Thread Vyacheslav Mitrofanov V
On Wed, 2022-08-31 at 20:27 -0600, Simon Glass wrote:
> «Внимание! Данное письмо от внешнего адресата!»
> 
> Hi Viacheslav,
> 
> On Tue, 30 Aug 2022 at 07:00, Viacheslav Mitrofanov
>  wrote:
> > This patch set adds basic IPv6 support to U-boot.
> > It is based on Chris's Packham patches
> > (https://lists.denx.de/pipermail/u-boot/2017-January/279366.html)
> > Chris's patches were taken as base. There were efforts to launch it
> > on HiFive
> > SiFive Unmatched board but the board didn't work well. The code was
> > refactored,
> > fixed some bugs as CRC for little-endian, some parts were
> > implemented in our own
> > way, something was taken from Linux. Finally we did manual tests
> > and the board
> > worked well.
> > 
> > Testing was done on HiFive SiFive Unmatched board (RISC-V)
> > 
> > Signed-off-by: Viacheslav Mitrofanov 
> > 
> > ---
> > Changes in v2:
> >  - Split big patches into smaller
> >  - If an address in tftpboot is IPv6 than use IPv6 to boot
> >  - Add tests
> > 
> > Viacheslav Mitrofanov (17):
> >   net: ipv6: Add IPv6 basic primitives
> >   net: ipv6: Add IPv6 build options
> >   net: ipv6: Add callbacks declarations to get access to IPv6
> > variables
> >   net: ipv6: Add Neighbor Discovery Protocol (NDP)
> >   net: ipv6: Add string_to_ip6 converter
> >   net: ipv6: Enable IPv6 typeconversion specifier
> >   net: ipv6: Add ip6addr, gatewayip6, serverip6 variables callbacks
> >   net: ipv6: Add implementation of main IPv6 functions
> >   net: ipv6: Incorporate IPv6 support into u-boot net subsystem
> >   net: tftp: Add IPv6 support for tftpboot
> >   net: ping6: Add ping6 command
> >   test: dm: eth: Add string_to_ip6 test
> >   test: dm: eth: Add csum_ipv6_magic test
> >   test: dm: eth: Add ip6_addr_in_subnet test
> >   test: dm: eth: Add ip6_make_snma test
> >   test: dm: eth: Add ip6_make_lladdr test
> >   test/py: add a ping6 test
> > 
> >  cmd/Kconfig   |   7 +
> >  cmd/net.c |  48 
> >  include/env_callback.h|  10 +
> >  include/env_flags.h   |  10 +
> >  include/ndisc.h   |  65 +
> >  include/net.h |   4 +-
> >  include/net6.h| 312 
> >  lib/net_utils.c   | 122 ++
> >  lib/vsprintf.c|  11 +-
> >  net/Kconfig   |   4 +
> >  net/Makefile  |   3 +
> >  net/ndisc.c   | 276 ++
> >  net/net.c |  70 +-
> >  net/net6.c| 484
> > ++
> >  net/ping6.c   | 117 +
> >  net/tftp.c|  62 -
> >  test/dm/eth.c | 140 +++
> >  test/py/tests/test_net.py |  15 ++
> >  18 files changed, 1741 insertions(+), 19 deletions(-)
> >  create mode 100644 include/ndisc.h
> >  create mode 100644 include/net6.h
> >  create mode 100644 net/ndisc.c
> >  create mode 100644 net/net6.c
> >  create mode 100644 net/ping6.c
> 
> This is very nicely put together. I added some comments about missing
> comments and other minor things.
> 
> I didn't try the ping6 test - does it need any special environment to
> work?
> 
> Regards,
> Simon

Hello, Simon!
Many thanks for your response! I do agree with your notes. I'm going to
follow them, so sooner I'll send new patch series.

Thanks!


Re: [PATCH 3/5] net: tftp: add IPv6 support for tftpboot

2022-09-02 Thread Vyacheslav Mitrofanov V
On Fri, 2022-09-02 at 17:48 +0300, Ramon Fried wrote:
> «Внимание! Данное письмо от внешнего адресата!»
> 
> On Mon, Aug 22, 2022 at 9:36 AM Vyacheslav Mitrofanov V
>  wrote:
> > On Fri, 2022-08-19 at 21:01 +0300, Ramon Fried wrote:
> > > On Fri, Aug 19, 2022 at 2:30 PM Vyacheslav Mitrofanov V
> > >  wrote:
> > > > On Fri, 2022-08-19 at 14:00 +0300, Ramon Fried wrote:
> > > > > On Fri, Aug 19, 2022 at 11:10 AM Viacheslav Mitrofanov
> > > > >  wrote:
> > > > > > The command tftpboot uses IPv4 by default, to use IPv6
> > > > > > instead
> > > > > > add
> > > > > > -ipv6
> > > > > > as the last argument. All other tftpboot features and
> > > > > > parameters
> > > > > > are left
> > > > > > the same.
> > > > > > 
> > > > > In my opinion, we should be able to detect if a user has
> > > > > provided
> > > > > or
> > > > > set an IPv6 server IP address and only use IPv6 then.
> > > > I tried to save tftboot semantics. I mean if we set -ipv6
> > > > option
> > > > the
> > > > command will check server address in args if it is empty check
> > > > environmental variable and if it is not set then terminate it.
> > > > It
> > > > works
> > > > the same way as it works now. If I didn't get you, please,
> > > > clarify
> > > > it a
> > > > little bit more.
> > > > Thanks!
> > > What I meant is that if you can distinguish IPv6 address from
> > > just
> > > parsing the address itself.
> > > Perhaps the -ipv6 is redundant.
> > It is not a problem to add a parser, I'll do that.
> > I thought that suffix can be useful if we use short command
> > notation as
> > an example just 'tftpboot'. In that case it uses IPv4 but if add
> > suffix
> > it will use IPv6. Or I can remove suffix at all and use an
> > environment
> > variable for example 'use_ip6' to determine protocol.
> > What do you think?!
> > Thanks!
> I think we can stay with the ipv6. I looked at some Linux command
> line
> utilities and they also require a parameter for Ipv6.
> Reviewed-by: Ramon Fried 

Hello Ramon!

I have already add the possibility to check if there is an IPv6
address. If so -ipv6 suffix is not obligatory. All this changes are
made in a new patchset that I sent 3 days ago. Simon Glass has already
reviewed some. 

Thanks!


Re: [PATCH v5 07/12] efi_loader: disk: a helper function to create efi_disk objects from udevice

2022-08-24 Thread Vyacheslav
Config for jethub_j100 did't contain any EFI* options. But build .config 
has these lines:

CONFIG_BOOTMETH_EFILOADER=y
CONFIG_CMD_BOOTEFI=y
CONFIG_CMD_BOOTEFI_HELLO_COMPILE=y
CONFIG_EFI_PARTITION=y
CONFIG_EFI_LOADER=y
CONFIG_CMD_BOOTEFI_BOOTMGR=y
CONFIG_EFI_SETUP_EARLY=y
CONFIG_EFI_VARIABLE_FILE_STORE=y
CONFIG_EFI_GET_TIME=y
CONFIG_EFI_DEVICE_PATH_TO_TEXT=y
CONFIG_EFI_DEVICE_PATH_UTIL=y
CONFIG_EFI_DT_FIXUP=y
CONFIG_EFI_LOADER_HII=y
CONFIG_EFI_UNICODE_COLLATION_PROTOCOL2=y
CONFIG_EFI_UNICODE_CAPITALIZATION=y
CONFIG_EFI_HAVE_RUNTIME_RESET=y
CONFIG_EFI_RNG_PROTOCOL=y
CONFIG_EFI_LOAD_FILE2_INITRD=y

If I set it all to "n" bug dissapears and board boots normally.

24.08.2022 12:00, Vyacheslav wrote:
I has similar problem on axg meson64. Seems problem exists at least on 
1Gb RAM devices, my device with 2 GB RAM did not hit this error.


--
Vyacheslav Bocharov


Re: [PATCH v5 07/12] efi_loader: disk: a helper function to create efi_disk objects from udevice

2022-08-24 Thread Vyacheslav
7dfbce48
x2 : 0010 x3 : 
x4 :  x5 : d55d507f5dacfff5
x6 : 7bf55bb0 x7 : 
x8 : 0007 x9 : 
x10: 0178 x11: 7bf4211c
x12: 00a4 x13: 7bf420d8
x14: 7965 x15: 0020
x16: 7df83454 x17: 
x18: 7bf4ddb0 x19: 7af42040
x20: 7df50b20 x21: 7dfbce48
x22: 1000 x23: 7bf55b00
x24: 7dfdb910 x25: 0100
x26: 0100 x27: 0100
x28: 1000 x29: 7bf420d0

Code: eb02009f 5461 5280 1406 (386468a3)


As far as my locally-built binary is concerned,
the faulted instruction is located in memcpy().

0106 :
  106:   aa0003e5mov x5, x0
  106:   d284mov x4, #0x0// #0
  106:   eb02009fcmp x4, x2
  106:   5461b.ne10653d4   // b.any
  106:   5280mov w0, #0x0// #0
  106:   1406b   10653e8 
  106:   386468a3ldrbw3, [x5, x4]

'x5' seems to be bogus.
The memory content might have been corrupted at this point.


Same place:

"Synchronous Abort" handler, esr 0x9604
elr: 0105ff48 lr : 010504d4 (reloc)
elr: 3ffa4f48 lr : 3ff954d4
x0 : 5695c9ebf0a7d8b1 x1 : 3ffac700
x2 : 0010 x3 : 
x4 :  x5 : 5695c9ebf0a7d8b1
x6 : 3df4e3b0 x7 : 0007
x8 :  x9 : 0008
x10: 8030 x11: 3df3496c
x12: 7fa8 x13: 3df34928
x14: 3ce18000 x15: 0020
x16: 3ff75d74 x17: 
x18: 3df42dc0 x19: 3cf34040
x20: 3ff45b20 x21: 3ffac700
x22: 0300 x23: 3df4e300
x24: 3ffca5e8 x25: 0530
x26: 0030 x27: 
x28: 0300 x29: 3df34930

Code: eb02009f 5461 5280 1406 (386468a3)
0105ff30 :
 105ff30:   aa0003e5mov x5, x0
 105ff34:   d284mov x4, #0x0 // #0
 105ff38:   eb02009fcmp x4, x2
 105ff3c:   5461b.ne105ff48   // b.any
 105ff40:   5280mov     w0, #0x0 // #0
 105ff44:   1406b   105ff5c 
*105ff48:   386468a3ldrbw3, [x5, x4]
 105ff4c:   38646820ldrbw0, [x1, x4]

I don't know how to get the call stack from this information.
What else can I do to investigate the problem?

--
Vyacheslav Bocharov


-Takahiro Akashi


Resetting CPU ...

using libretech-cc_defconfig and the followin boot.scr:
setenv autoload no
setenv initrd_high 0x
setenv fdt_high 0x
load mmc 0:1 0x1300 uImage
load mmc 0:1 0x600 ramdisk.cpio.gz.uboot
setenv initrd_size ${filesize}
load mmc 0:1 0x900 meson-gxl-s905x-libretech-cc.dtb
setenv bootargs 'console=ttyAML0,115200n8 root=/dev/ram0 
console_msg_format=syslog earlycon ip=dhcp'
bootm 0x1300 0x600 0x900

bisect log:
# bad: [c387e62614713d0cc9e3ed022b86c9f320b02853] Merge branch 
'2022-05-11-Kconfig-cleanups-etc'
# good: [e4b6ebd3de982ae7185dbf689a030e73fd06e0d2] Prepare v2022.04
git bisect start 'c387e62614' 'v2022.04'
# good: [4228023eff7e94500137ce9e30687c00ffb4dd4f] led: bcm6753: Drop duplicate OF 
"label" property parsing
git bisect good 4228023eff7e94500137ce9e30687c00ffb4dd4f
# bad: [3fbdd485fd87ce0d4e1b747aea3c433646f4ced2] ARM: dts: sam9x60: Add pit64b 
node
git bisect bad 3fbdd485fd87ce0d4e1b747aea3c433646f4ced2
# good: [e50f66e364be80e02dd0834b84b830f3aade82ea] Merge 
https://source.denx.de/u-boot/custodians/u-boot-marvell
git bisect good e50f66e364be80e02dd0834b84b830f3aade82ea
# good: [9de612ae4ded53f742f5f99929c06d0839471ced] cmd: adc: Add support for 
storing ADC result in env variable
git bisect good 9de612ae4ded53f742f5f99929c06d0839471ced
# bad: [bc9da9fb50ac3ba7603487a0366d4db60b984812] Merge branch 
'2022-04-23-binman-updates'
git bisect bad bc9da9fb50ac3ba7603487a0366d4db60b984812
# bad: [3c809dfed757c37b92ff543c8f1c941407bafc2e] efi_loader: disk: not create 
BLK device for BLK(IF_TYPE_EFI_LOADER) devices
git bisect bad 3c809dfed757c37b92ff543c8f1c941407bafc2e
# good: [38f255b96085d2e50558a16256c87ffd885f2f7e] efi_loader: disk: compile 
efi_disk when CONFIG_BLK
git bisect good 38f255b96085d2e50558a16256c87ffd885f2f7e
# good: [8ff50227befdc778eb2cb239b778ed1ed843bf33] test: dm: add tests for tag 
support
git bisect good 8ff50227befdc778eb2cb239b778ed1ed843bf33
# good: [bf76031d19fa82041ae5ddc17214ec71858b0097] dm: blk: add a device-probe 
hook for scanning disk partitions
git bisect good bf76031d19fa82041ae5ddc17214ec71858b0097
# bad: [a9bf024b2933bba0e23038892970a18b72dfaeb4] efi_loader: disk: 

Re: [PATCH 3/5] net: tftp: add IPv6 support for tftpboot

2022-08-22 Thread Vyacheslav Mitrofanov V
On Fri, 2022-08-19 at 21:01 +0300, Ramon Fried wrote:
> 
> On Fri, Aug 19, 2022 at 2:30 PM Vyacheslav Mitrofanov V
>  wrote:
> > On Fri, 2022-08-19 at 14:00 +0300, Ramon Fried wrote:
> > > On Fri, Aug 19, 2022 at 11:10 AM Viacheslav Mitrofanov
> > >  wrote:
> > > > The command tftpboot uses IPv4 by default, to use IPv6 instead
> > > > add
> > > > -ipv6
> > > > as the last argument. All other tftpboot features and
> > > > parameters
> > > > are left
> > > > the same.
> > > > 
> > > In my opinion, we should be able to detect if a user has provided
> > > or
> > > set an IPv6 server IP address and only use IPv6 then.
> > I tried to save tftboot semantics. I mean if we set -ipv6 option
> > the
> > command will check server address in args if it is empty check
> > environmental variable and if it is not set then terminate it. It
> > works
> > the same way as it works now. If I didn't get you, please, clarify
> > it a
> > little bit more.
> > Thanks!
> What I meant is that if you can distinguish IPv6 address from just
> parsing the address itself.
> Perhaps the -ipv6 is redundant.
It is not a problem to add a parser, I'll do that.
I thought that suffix can be useful if we use short command notation as
an example just 'tftpboot'. In that case it uses IPv4 but if add suffix
it will use IPv6. Or I can remove suffix at all and use an environment
variable for example 'use_ip6' to determine protocol.
What do you think?!
Thanks!


Re: [PATCH 3/5] net: tftp: add IPv6 support for tftpboot

2022-08-19 Thread Vyacheslav Mitrofanov V
On Fri, 2022-08-19 at 14:00 +0300, Ramon Fried wrote:
> On Fri, Aug 19, 2022 at 11:10 AM Viacheslav Mitrofanov
>  wrote:
> > The command tftpboot uses IPv4 by default, to use IPv6 instead add
> > -ipv6
> > as the last argument. All other tftpboot features and parameters
> > are left
> > the same.
> > 
> In my opinion, we should be able to detect if a user has provided or
> set an IPv6 server IP address and only use IPv6 then.
I tried to save tftboot semantics. I mean if we set -ipv6 option the
command will check server address in args if it is empty check
environmental variable and if it is not set then terminate it. It works
the same way as it works now. If I didn't get you, please, clarify it a
little bit more.
Thanks!


[PATCH] cmd: fix do_adc_single()

2022-07-03 Thread Vyacheslav Bocharov
The source code contains an error:
- argv[2] contains  arg, variable for env_set is in argv[3]
- number of args is 4

Revert 54d24d72601321f4470c4edf31c6b29adae424a7
  cmd: simplify do_adc_single()

Fixes 9de612ae4ded53f742f5f99929c06d0839471ced
  cmd: adc: Add support for storing ADC result in env variable
---
 cmd/adc.c | 9 +++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/cmd/adc.c b/cmd/adc.c
index 195efa8661..1c5d3e10a3 100644
--- a/cmd/adc.c
+++ b/cmd/adc.c
@@ -71,6 +71,7 @@ static int do_adc_info(struct cmd_tbl *cmdtp, int flag, int 
argc,
 static int do_adc_single(struct cmd_tbl *cmdtp, int flag, int argc,
 char *const argv[])
 {
+   char *varname = NULL;
struct udevice *dev;
unsigned int data;
int ret, uV, val;
@@ -78,6 +79,9 @@ static int do_adc_single(struct cmd_tbl *cmdtp, int flag, int 
argc,
if (argc < 3)
return CMD_RET_USAGE;
 
+   if (argc >= 4)
+   varname = argv[3];
+
ret = adc_channel_single_shot(argv[1], simple_strtol(argv[2], NULL, 0),
  );
if (ret) {
@@ -95,7 +99,8 @@ static int do_adc_single(struct cmd_tbl *cmdtp, int flag, int 
argc,
printf("%u\n", data);
}
 
-   env_set_ulong(argv[2], val);
+   if (varname)
+   env_set_ulong(varname, val);
 
return CMD_RET_SUCCESS;
 }
@@ -160,5 +165,5 @@ static char adc_help_text[] =
 U_BOOT_CMD_WITH_SUBCMDS(adc, "ADC sub-system", adc_help_text,
U_BOOT_SUBCMD_MKENT(list, 1, 1, do_adc_list),
U_BOOT_SUBCMD_MKENT(info, 2, 1, do_adc_info),
-   U_BOOT_SUBCMD_MKENT(single, 3, 1, do_adc_single),
+   U_BOOT_SUBCMD_MKENT(single, 4, 1, do_adc_single),
U_BOOT_SUBCMD_MKENT(scan, 3, 1, do_adc_scan));
-- 
2.30.2



[PATCH 2/2] doc: boards: amlogic: update jethub d1 specifications

2022-04-25 Thread Vyacheslav Bocharov
Signed-off-by: Vyacheslav Bocharov 
---
 doc/board/amlogic/jethub-j100.rst | 24 ++--
 1 file changed, 14 insertions(+), 10 deletions(-)

diff --git a/doc/board/amlogic/jethub-j100.rst 
b/doc/board/amlogic/jethub-j100.rst
index d54519aaef..8081569bba 100644
--- a/doc/board/amlogic/jethub-j100.rst
+++ b/doc/board/amlogic/jethub-j100.rst
@@ -3,27 +3,31 @@
 U-Boot for JetHub J100
 ===
 
-JetHome Jethub D1 (http://jethome.ru/jethub-d1) is a home automation
-controller manufactured by JetHome with the following specifications:
+JetHome Jethub D1 (http://jethome.ru/jethub-d1) is a series of home 
+automation controller manufactured by JetHome with the following 
+specifications:
 
  - Amlogic A113X (ARM Cortex-A53) quad-core up to 1.5GHz
  - no video out
- - 512Mb/1GB DDR3
- - 8/16GB eMMC flash
+ - 512MB/1GB DDR3 or 2GB DDR4 SDRAM
+ - 8/16/32GB eMMC flash
  - 1 x USB 2.0
  - 1 x 10/100Mbps ethernet
- - WiFi / Bluetooth AMPAK AP6255 (Broadcom BCM43455) IEEE
-   802.11a/b/g/n/ac, Bluetooth 4.2.
- - TI CC2538 + CC2592 Zigbee Wireless Module with up to 20dBm output
-   power and Zigbee 3.0 support.
+ - WiFi / Bluetooth one from:
+   - AMPAK AP6255 (Broadcom BCM43455) IEEE 802.11a/b/g/n/ac, Bluetooth 4.2
+   - RTL8822CS IEEE 802.11a/b/g/n/ac, Bluetooth 5.0
+   - Amlogic W155S1 WiFi5 IEEE 802.11a/b/g/n/ac, Bluetooth 5.2
  - 2 x gpio LEDS
  - GPIO user Button
+ - DC source with a voltage of 9 to 56 V / Passive POE
+ - DIN Rail Mounting case
+Basic version also has:
+ - TI CC2538 + CC2592 Zigbee Wireless Module with up to 20dBm output
+   power and Zigbee 3.0 support.
  - 1 x 1-Wire
  - 2 x RS-485
  - 4 x dry contact digital GPIO inputs
  - 3 x relay GPIO outputs
- - DC source with a voltage of 9 to 56 V / Passive POE
- - DIN Rail Mounting case
 
 U-Boot compilation
 --
-- 
2.30.2



[PATCH 1/2] doc: boards: amlogic: update documentation for ADC support for AXG

2022-04-25 Thread Vyacheslav Bocharov
Signed-off-by: Vyacheslav Bocharov 
---
 doc/board/amlogic/index.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/doc/board/amlogic/index.rst b/doc/board/amlogic/index.rst
index 9ef1440433..9c7fadf2c0 100644
--- a/doc/board/amlogic/index.rst
+++ b/doc/board/amlogic/index.rst
@@ -55,7 +55,7 @@ This matrix concerns the actual source code version.
 
+---+---+-+--+-++-+--+
 | NAND  | No| No  | No   | 
No  | No | No  | No   |
 
+---+---+-+--+-++-+--+
-| ADC   | **Yes**   | **Yes** | **Yes**  | 
No  | No | No  | No   |
+| ADC   | **Yes**   | **Yes** | **Yes**  | 
**Yes** | No | No  | No   |
 
+---+---+-+--+-++-+--+
 | CVBS Output   | **Yes**   | **Yes** | **Yes**  | 
*N/A*   | **Yes**| **Yes** | **Yes**  |
 
+---+---+-+--+-++-+--+
-- 
2.30.2



[PATCH v3 5/6] board: amlogic: jethub j100: enable saradc in dts

2022-04-24 Thread Vyacheslav Bocharov
Prepare to use ADC channel 1 to check the hardware revision of the board:
- add u-boot dts include with saradc node

Signed-off-by: Vyacheslav Bocharov 
---
 arch/arm/dts/meson-axg-jethome-jethub-j100-u-boot.dtsi | 10 ++
 1 file changed, 10 insertions(+)
 create mode 100644 arch/arm/dts/meson-axg-jethome-jethub-j100-u-boot.dtsi

diff --git a/arch/arm/dts/meson-axg-jethome-jethub-j100-u-boot.dtsi 
b/arch/arm/dts/meson-axg-jethome-jethub-j100-u-boot.dtsi
new file mode 100644
index 00..3ecb233f8e
--- /dev/null
+++ b/arch/arm/dts/meson-axg-jethome-jethub-j100-u-boot.dtsi
@@ -0,0 +1,10 @@
+// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
+/*
+ * Copyright (c) 2022 Vyacheslav Bocharov 
+ * Author: Vyacheslav Bocharov 
+ */
+
+ {
+   status = "okay";
+   vref-supply = <_ao18>;
+};
-- 
2.30.2



[PATCH v3 6/6] board: amlogic: jethub j100: enable saradc in config

2022-04-24 Thread Vyacheslav Bocharov
Enable ADC in board config file

Signed-off-by: Vyacheslav Bocharov 
Reviewed-by: Neil Armstrong 
---
 configs/jethub_j100_defconfig | 5 +
 1 file changed, 5 insertions(+)

diff --git a/configs/jethub_j100_defconfig b/configs/jethub_j100_defconfig
index 1c6db9f6a0..a30940bf1c 100644
--- a/configs/jethub_j100_defconfig
+++ b/configs/jethub_j100_defconfig
@@ -17,6 +17,7 @@ CONFIG_REMAKE_ELF=y
 CONFIG_OF_BOARD_SETUP=y
 # CONFIG_DISPLAY_CPUINFO is not set
 CONFIG_MISC_INIT_R=y
+CONFIG_CMD_ADC=y
 # CONFIG_CMD_BDI is not set
 # CONFIG_CMD_IMI is not set
 CONFIG_CMD_EEPROM=y
@@ -34,6 +35,10 @@ CONFIG_OF_CONTROL=y
 CONFIG_SYS_RELOC_GD_ENV_ADDR=y
 CONFIG_DM_I2C=y
 CONFIG_SYS_I2C_MESON=y
+CONFIG_ADC=y
+CONFIG_SARADC_MESON=y
+CONFIG_CLK=y
+CONFIG_CLK_MESON_AXG=y
 CONFIG_MMC_MESON_GX=y
 CONFIG_MTD_UBI=y
 CONFIG_PHY_REALTEK=y
-- 
2.30.2



[PATCH v3 4/6] adc: meson-saradc: add AXG variant

2022-04-24 Thread Vyacheslav Bocharov
Add support for the SARADC variant found on the AXG SoCs family.

Signed-off-by: Vyacheslav Bocharov 
Acked-by: Neil Armstrong 
---
 drivers/adc/meson-saradc.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/adc/meson-saradc.c b/drivers/adc/meson-saradc.c
index 1a45a3a265..37023512f0 100644
--- a/drivers/adc/meson-saradc.c
+++ b/drivers/adc/meson-saradc.c
@@ -737,6 +737,8 @@ static const struct udevice_id meson_saradc_ids[] = {
  .data = (ulong)_saradc_data },
{ .compatible = "amlogic,meson-g12a-saradc",
  .data = (ulong)_saradc_data },
+   { .compatible = "amlogic,meson-axg-saradc",
+ .data = (ulong)_saradc_data },
{ }
 };
 
-- 
2.30.2



[PATCH v3 3/6] clk: meson: update driver for g12a-ao clocks

2022-04-24 Thread Vyacheslav Bocharov
Update g12a-ao clk driver:
- move clk->id check to .request function
- remove unnecessary check (gate->reg == 0)

Signed-off-by: Vyacheslav Bocharov 
---
 drivers/clk/meson/g12a-ao.c | 15 +--
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/drivers/clk/meson/g12a-ao.c b/drivers/clk/meson/g12a-ao.c
index 17b11eb52a..1a855a6896 100644
--- a/drivers/clk/meson/g12a-ao.c
+++ b/drivers/clk/meson/g12a-ao.c
@@ -28,14 +28,8 @@ static int meson_set_gate(struct clk *clk, bool on)
struct meson_clk *priv = dev_get_priv(clk->dev);
struct meson_gate *gate;
 
-   if (clk->id >= ARRAY_SIZE(gates))
-   return -ENOENT;
-
gate = [clk->id];
 
-   if (gate->reg == 0)
-   return 0;
-
regmap_update_bits(priv->map, gate->reg,
   BIT(gate->bit), on ? BIT(gate->bit) : 0);
 
@@ -63,9 +57,18 @@ static int meson_clk_probe(struct udevice *dev)
return 0;
 }
 
+static int meson_clk_request(struct clk *clk)
+{
+   if (clk->id >= ARRAY_SIZE(gates))
+   return -ENOENT;
+
+   return 0;
+}
+
 static struct clk_ops meson_clk_ops = {
.disable= meson_clk_disable,
.enable = meson_clk_enable,
+   .request= meson_clk_request,
 };
 
 static const struct udevice_id meson_clk_ids[] = {
-- 
2.30.2



[PATCH v3 2/6] clk: meson: fix driver name for g12a-ao clocks

2022-04-24 Thread Vyacheslav Bocharov
Update the clk-g12a-ao driver from "axg" to "g12a"

Signed-off-by: Vyacheslav Bocharov 
Acked-by: Neil Armstrong 
---
 drivers/clk/meson/g12a-ao.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/clk/meson/g12a-ao.c b/drivers/clk/meson/g12a-ao.c
index 0148529e04..17b11eb52a 100644
--- a/drivers/clk/meson/g12a-ao.c
+++ b/drivers/clk/meson/g12a-ao.c
@@ -73,7 +73,7 @@ static const struct udevice_id meson_clk_ids[] = {
{ }
 };
 
-U_BOOT_DRIVER(meson_clk_axg) = {
+U_BOOT_DRIVER(meson_clk_g12a_ao) = {
.name   = "meson_clk_g12a_ao",
.id = UCLASS_CLK,
.of_match   = meson_clk_ids,
-- 
2.30.2



[PATCH v3 1/6] clk: meson: add minimal driver for axg-ao clocks

2022-04-24 Thread Vyacheslav Bocharov
Add minimal driver AO clocks on meson AXG family. Only ADC related clocks
are supported.

Signed-off-by: Vyacheslav Bocharov 
Reviewed-by: Sean Anderson 
Reviewed-by: Neil Armstrong 
---
 drivers/clk/meson/Makefile |  1 +
 drivers/clk/meson/axg-ao.c | 86 ++
 2 files changed, 87 insertions(+)
 create mode 100644 drivers/clk/meson/axg-ao.c

diff --git a/drivers/clk/meson/Makefile b/drivers/clk/meson/Makefile
index b9c6bd66cf..a486b13e9c 100644
--- a/drivers/clk/meson/Makefile
+++ b/drivers/clk/meson/Makefile
@@ -5,5 +5,6 @@
 
 obj-$(CONFIG_CLK_MESON_GX) += gxbb.o
 obj-$(CONFIG_CLK_MESON_AXG) += axg.o
+obj-$(CONFIG_CLK_MESON_AXG) += axg-ao.o
 obj-$(CONFIG_CLK_MESON_G12A) += g12a.o
 obj-$(CONFIG_CLK_MESON_G12A) += g12a-ao.o
diff --git a/drivers/clk/meson/axg-ao.c b/drivers/clk/meson/axg-ao.c
new file mode 100644
index 00..311ffc1cca
--- /dev/null
+++ b/drivers/clk/meson/axg-ao.c
@@ -0,0 +1,86 @@
+// SPDX-License-Identifier: GPL-2.0+
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "clk_meson.h"
+
+struct meson_clk {
+   struct regmap *map;
+};
+
+#define AO_CLK_GATE0   0x40
+#define AO_SAR_CLK 0x90
+
+static struct meson_gate gates[] = {
+   MESON_GATE(CLKID_AO_SAR_ADC, AO_CLK_GATE0, 7),
+   MESON_GATE(CLKID_AO_SAR_ADC_CLK, AO_SAR_CLK, 7),
+};
+
+static int meson_set_gate(struct clk *clk, bool on)
+{
+   struct meson_clk *priv = dev_get_priv(clk->dev);
+   struct meson_gate *gate;
+
+   gate = [clk->id];
+
+   regmap_update_bits(priv->map, gate->reg,
+  BIT(gate->bit), on ? BIT(gate->bit) : 0);
+
+   return 0;
+}
+
+static int meson_clk_enable(struct clk *clk)
+{
+   return meson_set_gate(clk, true);
+}
+
+static int meson_clk_disable(struct clk *clk)
+{
+   return meson_set_gate(clk, false);
+}
+
+static int meson_clk_probe(struct udevice *dev)
+{
+   struct meson_clk *priv = dev_get_priv(dev);
+
+   priv->map = syscon_node_to_regmap(dev_ofnode(dev_get_parent(dev)));
+   if (IS_ERR(priv->map))
+   return PTR_ERR(priv->map);
+
+   return 0;
+}
+
+static int meson_clk_request(struct clk *clk)
+{
+   if (clk->id >= ARRAY_SIZE(gates))
+   return -ENOENT;
+
+   return 0;
+}
+
+static struct clk_ops meson_clk_ops = {
+   .disable= meson_clk_disable,
+   .enable = meson_clk_enable,
+   .request= meson_clk_request,
+};
+
+static const struct udevice_id meson_clk_ids[] = {
+   { .compatible = "amlogic,meson-axg-aoclkc" },
+   { }
+};
+
+U_BOOT_DRIVER(meson_clk_axg_ao) = {
+   .name   = "meson_clk_axg_ao",
+   .id = UCLASS_CLK,
+   .of_match   = meson_clk_ids,
+   .priv_auto  = sizeof(struct meson_clk),
+   .ops= _clk_ops,
+   .probe  = meson_clk_probe,
+};
-- 
2.30.2



[PATCH v3 0/6] meson: add clk and adc support for JetHub D1 (j100)

2022-04-24 Thread Vyacheslav Bocharov
Prepare to use ADC channel 1 in JetHub D1 (j100) to check the hardware 
revision of the board.

- add support for AXG in saradc driver
- add simple clk-ao driver for AXG (base is taken from g12a)
- enable saradc in dts and board config file
- fix typo in the g12a-clk-ao driver name
- move clk->id check to .request function for g12a-clk-ao driver
- remove unnecessary check (gate->reg == 0) in g12a-clk-ao driver
- enable saradc in dts/board config for JetHub D1 (j100)

>From v2:
- remove unnecessary check (gate->reg == 0) in axg/g12a clk-ao drivers
- move j100 dts changes to -u-boot.dtsi
>From v1:
- move clk-id check to .request function for axg/g12a-ao clk driver


Vyacheslav Bocharov (6):
  clk: meson: add minimal driver for axg-ao clocks
  clk: meson: fix driver name for g12a-ao clocks
  clk: meson: update driver for g12a-ao clocks
  adc: meson-saradc: add AXG variant
  board: amlogic: jethub j100: enable saradc in dts
  board: amlogic: jethub j100: enable saradc in config

 .../meson-axg-jethome-jethub-j100-u-boot.dtsi | 10 +++
 configs/jethub_j100_defconfig |  5 ++
 drivers/adc/meson-saradc.c|  2 +
 drivers/clk/meson/Makefile|  1 +
 drivers/clk/meson/axg-ao.c| 86 +++
 drivers/clk/meson/g12a-ao.c   | 17 ++--
 6 files changed, 114 insertions(+), 7 deletions(-)
 create mode 100644 arch/arm/dts/meson-axg-jethome-jethub-j100-u-boot.dtsi
 create mode 100644 drivers/clk/meson/axg-ao.c

-- 
2.30.2



Re: [PATCH v2 5/6] board: amlogic: jethub j100: enable saradc in dts

2022-04-23 Thread Vyacheslav




22.04.2022 16:26, Neil Armstrong wrote:

On 22/04/2022 07:29, Vyacheslav Bocharov wrote:

Prepare to use ADC channel 1 to check the hardware revision of the board.

Signed-off-by: Vyacheslav Bocharov 
---
  arch/arm/dts/meson-axg-jethome-jethub-j100.dts | 5 +
  1 file changed, 5 insertions(+)

diff --git a/arch/arm/dts/meson-axg-jethome-jethub-j100.dts 
b/arch/arm/dts/meson-axg-jethome-jethub-j100.dts

index 5783732dc6..00a0b268af 100644
--- a/arch/arm/dts/meson-axg-jethome-jethub-j100.dts
+++ b/arch/arm/dts/meson-axg-jethome-jethub-j100.dts
@@ -359,3 +359,8 @@
   {
  #cooling-cells = <2>;
  };
+
+ {
+    status = "okay";
+    vref-supply = <_ao18>;
+};


Please move this in a -u-boot.dtsi file to keep the main DT in sync with 
Linux.


Thanks. Anyway, I will submit patch to the kernel later.


Neil


Re: [PATCH v2 1/6] clk: meson: add minimal driver for axg-ao clocks

2022-04-23 Thread Vyacheslav




23.04.2022 1:55, Sean Anderson wrote:

On 4/22/22 1:29 AM, Vyacheslav Bocharov wrote:

Add minimal driver AO clocks on meson AXG family. Only ADC related clocks
are supported.

Signed-off-by: Vyacheslav Bocharov 
---
  drivers/clk/meson/Makefile |  1 +
  drivers/clk/meson/axg-ao.c | 89 ++
  2 files changed, 90 insertions(+)
  create mode 100644 drivers/clk/meson/axg-ao.c

diff --git a/drivers/clk/meson/Makefile b/drivers/clk/meson/Makefile
index b9c6bd66cf..a486b13e9c 100644
--- a/drivers/clk/meson/Makefile
+++ b/drivers/clk/meson/Makefile
@@ -5,5 +5,6 @@
  obj-$(CONFIG_CLK_MESON_GX) += gxbb.o
  obj-$(CONFIG_CLK_MESON_AXG) += axg.o
+obj-$(CONFIG_CLK_MESON_AXG) += axg-ao.o
  obj-$(CONFIG_CLK_MESON_G12A) += g12a.o
  obj-$(CONFIG_CLK_MESON_G12A) += g12a-ao.o
diff --git a/drivers/clk/meson/axg-ao.c b/drivers/clk/meson/axg-ao.c
new file mode 100644
index 00..3f9617e9f7
--- /dev/null
+++ b/drivers/clk/meson/axg-ao.c
@@ -0,0 +1,89 @@
+// SPDX-License-Identifier: GPL-2.0+
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "clk_meson.h"
+
+struct meson_clk {
+    struct regmap *map;
+};
+
+#define AO_CLK_GATE0    0x40
+#define AO_SAR_CLK    0x90
+
+static struct meson_gate gates[] = {
+    MESON_GATE(CLKID_AO_SAR_ADC, AO_CLK_GATE0, 7),
+    MESON_GATE(CLKID_AO_SAR_ADC_CLK, AO_SAR_CLK, 7),
+};
+
+static int meson_set_gate(struct clk *clk, bool on)
+{
+    struct meson_clk *priv = dev_get_priv(clk->dev);
+    struct meson_gate *gate;
+
+    gate = [clk->id];
+
+    if (gate->reg == 0)
+    return 0;


I don't think you need this.
Hmm. You're right. The gates is all predefined. Therefore zero values 
cannot be there. I will fix it in g12-ao-clk as well.





+
+    regmap_update_bits(priv->map, gate->reg,
+   BIT(gate->bit), on ? BIT(gate->bit) : 0);
+
+    return 0;
+}
+
+static int meson_clk_enable(struct clk *clk)
+{
+    return meson_set_gate(clk, true);
+}
+
+static int meson_clk_disable(struct clk *clk)
+{
+    return meson_set_gate(clk, false);
+}
+
+static int meson_clk_probe(struct udevice *dev)
+{
+    struct meson_clk *priv = dev_get_priv(dev);
+
+    priv->map = syscon_node_to_regmap(dev_ofnode(dev_get_parent(dev)));
+    if (IS_ERR(priv->map))
+    return PTR_ERR(priv->map);
+
+    return 0;
+}
+
+static int meson_clk_request(struct clk *clk)
+{
+    if (clk->id >= ARRAY_SIZE(gates))
+    return -ENOENT;
+
+    return 0;
+}
+
+static struct clk_ops meson_clk_ops = {
+    .disable    = meson_clk_disable,
+    .enable    = meson_clk_enable,
+    .request    = meson_clk_request,
+};
+
+static const struct udevice_id meson_clk_ids[] = {
+    { .compatible = "amlogic,meson-axg-aoclkc" },
+    { }
+};
+
+U_BOOT_DRIVER(meson_clk_axg_ao) = {
+    .name    = "meson_clk_axg_ao",
+    .id    = UCLASS_CLK,
+    .of_match    = meson_clk_ids,
+    .priv_auto    = sizeof(struct meson_clk),
+    .ops    = _clk_ops,
+    .probe    = meson_clk_probe,
+};



Reviewed-by: Sean Anderson 


[PATCH v2 6/6] board: amlogic: jethub j100: enable saradc in config

2022-04-21 Thread Vyacheslav Bocharov
Enable ADC in board config file

Signed-off-by: Vyacheslav Bocharov 
---
 configs/jethub_j100_defconfig | 5 +
 1 file changed, 5 insertions(+)

diff --git a/configs/jethub_j100_defconfig b/configs/jethub_j100_defconfig
index 1c6db9f6a0..a30940bf1c 100644
--- a/configs/jethub_j100_defconfig
+++ b/configs/jethub_j100_defconfig
@@ -17,6 +17,7 @@ CONFIG_REMAKE_ELF=y
 CONFIG_OF_BOARD_SETUP=y
 # CONFIG_DISPLAY_CPUINFO is not set
 CONFIG_MISC_INIT_R=y
+CONFIG_CMD_ADC=y
 # CONFIG_CMD_BDI is not set
 # CONFIG_CMD_IMI is not set
 CONFIG_CMD_EEPROM=y
@@ -34,6 +35,10 @@ CONFIG_OF_CONTROL=y
 CONFIG_SYS_RELOC_GD_ENV_ADDR=y
 CONFIG_DM_I2C=y
 CONFIG_SYS_I2C_MESON=y
+CONFIG_ADC=y
+CONFIG_SARADC_MESON=y
+CONFIG_CLK=y
+CONFIG_CLK_MESON_AXG=y
 CONFIG_MMC_MESON_GX=y
 CONFIG_MTD_UBI=y
 CONFIG_PHY_REALTEK=y
-- 
2.30.2



[PATCH v2 5/6] board: amlogic: jethub j100: enable saradc in dts

2022-04-21 Thread Vyacheslav Bocharov
Prepare to use ADC channel 1 to check the hardware revision of the board.

Signed-off-by: Vyacheslav Bocharov 
---
 arch/arm/dts/meson-axg-jethome-jethub-j100.dts | 5 +
 1 file changed, 5 insertions(+)

diff --git a/arch/arm/dts/meson-axg-jethome-jethub-j100.dts 
b/arch/arm/dts/meson-axg-jethome-jethub-j100.dts
index 5783732dc6..00a0b268af 100644
--- a/arch/arm/dts/meson-axg-jethome-jethub-j100.dts
+++ b/arch/arm/dts/meson-axg-jethome-jethub-j100.dts
@@ -359,3 +359,8 @@
  {
#cooling-cells = <2>;
 };
+
+ {
+   status = "okay";
+   vref-supply = <_ao18>;
+};
-- 
2.30.2



[PATCH v2 4/6] adc: meson-saradc: add AXG variant

2022-04-21 Thread Vyacheslav Bocharov
Add support for the SARADC variant found on the AXG SoCs family.

Signed-off-by: Vyacheslav Bocharov 
---
 drivers/adc/meson-saradc.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/adc/meson-saradc.c b/drivers/adc/meson-saradc.c
index 1a45a3a265..37023512f0 100644
--- a/drivers/adc/meson-saradc.c
+++ b/drivers/adc/meson-saradc.c
@@ -737,6 +737,8 @@ static const struct udevice_id meson_saradc_ids[] = {
  .data = (ulong)_saradc_data },
{ .compatible = "amlogic,meson-g12a-saradc",
  .data = (ulong)_saradc_data },
+   { .compatible = "amlogic,meson-axg-saradc",
+ .data = (ulong)_saradc_data },
{ }
 };
 
-- 
2.30.2



[PATCH v2 2/6] clk: meson: fix driver name for g12a-ao clocks

2022-04-21 Thread Vyacheslav Bocharov
Update the clk-g12a-ao driver from "axg" to "g12a"

Signed-off-by: Vyacheslav Bocharov 
---
 drivers/clk/meson/g12a-ao.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/clk/meson/g12a-ao.c b/drivers/clk/meson/g12a-ao.c
index 0148529e04..17b11eb52a 100644
--- a/drivers/clk/meson/g12a-ao.c
+++ b/drivers/clk/meson/g12a-ao.c
@@ -73,7 +73,7 @@ static const struct udevice_id meson_clk_ids[] = {
{ }
 };
 
-U_BOOT_DRIVER(meson_clk_axg) = {
+U_BOOT_DRIVER(meson_clk_g12a_ao) = {
.name   = "meson_clk_g12a_ao",
.id = UCLASS_CLK,
.of_match   = meson_clk_ids,
-- 
2.30.2



[PATCH v2 3/6] clk: meson: update driver for g12a-ao clocks

2022-04-21 Thread Vyacheslav Bocharov
Move clk->id check to .request function

Signed-off-by: Vyacheslav Bocharov 
---
 drivers/clk/meson/g12a-ao.c | 12 +---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/drivers/clk/meson/g12a-ao.c b/drivers/clk/meson/g12a-ao.c
index 17b11eb52a..22c85cff1d 100644
--- a/drivers/clk/meson/g12a-ao.c
+++ b/drivers/clk/meson/g12a-ao.c
@@ -28,9 +28,6 @@ static int meson_set_gate(struct clk *clk, bool on)
struct meson_clk *priv = dev_get_priv(clk->dev);
struct meson_gate *gate;
 
-   if (clk->id >= ARRAY_SIZE(gates))
-   return -ENOENT;
-
gate = [clk->id];
 
if (gate->reg == 0)
@@ -63,9 +60,18 @@ static int meson_clk_probe(struct udevice *dev)
return 0;
 }
 
+static int meson_clk_request(struct clk *clk)
+{
+   if (clk->id >= ARRAY_SIZE(gates))
+   return -ENOENT;
+
+   return 0;
+}
+
 static struct clk_ops meson_clk_ops = {
.disable= meson_clk_disable,
.enable = meson_clk_enable,
+   .request= meson_clk_request,
 };
 
 static const struct udevice_id meson_clk_ids[] = {
-- 
2.30.2



[PATCH v2 1/6] clk: meson: add minimal driver for axg-ao clocks

2022-04-21 Thread Vyacheslav Bocharov
Add minimal driver AO clocks on meson AXG family. Only ADC related clocks
are supported.

Signed-off-by: Vyacheslav Bocharov 
---
 drivers/clk/meson/Makefile |  1 +
 drivers/clk/meson/axg-ao.c | 89 ++
 2 files changed, 90 insertions(+)
 create mode 100644 drivers/clk/meson/axg-ao.c

diff --git a/drivers/clk/meson/Makefile b/drivers/clk/meson/Makefile
index b9c6bd66cf..a486b13e9c 100644
--- a/drivers/clk/meson/Makefile
+++ b/drivers/clk/meson/Makefile
@@ -5,5 +5,6 @@
 
 obj-$(CONFIG_CLK_MESON_GX) += gxbb.o
 obj-$(CONFIG_CLK_MESON_AXG) += axg.o
+obj-$(CONFIG_CLK_MESON_AXG) += axg-ao.o
 obj-$(CONFIG_CLK_MESON_G12A) += g12a.o
 obj-$(CONFIG_CLK_MESON_G12A) += g12a-ao.o
diff --git a/drivers/clk/meson/axg-ao.c b/drivers/clk/meson/axg-ao.c
new file mode 100644
index 00..3f9617e9f7
--- /dev/null
+++ b/drivers/clk/meson/axg-ao.c
@@ -0,0 +1,89 @@
+// SPDX-License-Identifier: GPL-2.0+
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "clk_meson.h"
+
+struct meson_clk {
+   struct regmap *map;
+};
+
+#define AO_CLK_GATE0   0x40
+#define AO_SAR_CLK 0x90
+
+static struct meson_gate gates[] = {
+   MESON_GATE(CLKID_AO_SAR_ADC, AO_CLK_GATE0, 7),
+   MESON_GATE(CLKID_AO_SAR_ADC_CLK, AO_SAR_CLK, 7),
+};
+
+static int meson_set_gate(struct clk *clk, bool on)
+{
+   struct meson_clk *priv = dev_get_priv(clk->dev);
+   struct meson_gate *gate;
+
+   gate = [clk->id];
+
+   if (gate->reg == 0)
+   return 0;
+
+   regmap_update_bits(priv->map, gate->reg,
+  BIT(gate->bit), on ? BIT(gate->bit) : 0);
+
+   return 0;
+}
+
+static int meson_clk_enable(struct clk *clk)
+{
+   return meson_set_gate(clk, true);
+}
+
+static int meson_clk_disable(struct clk *clk)
+{
+   return meson_set_gate(clk, false);
+}
+
+static int meson_clk_probe(struct udevice *dev)
+{
+   struct meson_clk *priv = dev_get_priv(dev);
+
+   priv->map = syscon_node_to_regmap(dev_ofnode(dev_get_parent(dev)));
+   if (IS_ERR(priv->map))
+   return PTR_ERR(priv->map);
+
+   return 0;
+}
+
+static int meson_clk_request(struct clk *clk)
+{
+   if (clk->id >= ARRAY_SIZE(gates))
+   return -ENOENT;
+
+   return 0;
+}
+
+static struct clk_ops meson_clk_ops = {
+   .disable= meson_clk_disable,
+   .enable = meson_clk_enable,
+   .request= meson_clk_request,
+};
+
+static const struct udevice_id meson_clk_ids[] = {
+   { .compatible = "amlogic,meson-axg-aoclkc" },
+   { }
+};
+
+U_BOOT_DRIVER(meson_clk_axg_ao) = {
+   .name   = "meson_clk_axg_ao",
+   .id = UCLASS_CLK,
+   .of_match   = meson_clk_ids,
+   .priv_auto  = sizeof(struct meson_clk),
+   .ops= _clk_ops,
+   .probe  = meson_clk_probe,
+};
-- 
2.30.2



[PATCH v2 0/6] meson: add clk and adc support for JetHub D1 (j100)

2022-04-21 Thread Vyacheslav Bocharov
Prepare to use ADC channel 1 in JetHub D1 (j100) to check the hardware 
revision of the board.

- add support for AXG in saradc driver
- add simple clk-ao driver for AXG (base is taken from g12a)
- enable saradc in dts and board config file
- fix typo in the g12a-clk-ao driver name
- move clk->id check to .request function for g12a-clk-ao driver
- enable saradc in dts/board config for JetHub D1 (j100)

>From v1:
- move clk-id check to .request function for axg/g12a-ao clk driver

Vyacheslav Bocharov (6):
  clk: meson: add minimal driver for axg-ao clocks
  clk: meson: fix driver name for g12a-ao clocks
  clk: meson: update driver for g12a-ao clocks
  adc: meson-saradc: add AXG variant
  board: amlogic: jethub j100: enable saradc in dts
  board: amlogic: jethub j100: enable saradc in config

 .../arm/dts/meson-axg-jethome-jethub-j100.dts |  5 ++
 configs/jethub_j100_defconfig |  5 ++
 drivers/adc/meson-saradc.c|  2 +
 drivers/clk/meson/Makefile|  1 +
 drivers/clk/meson/axg-ao.c| 89 +++
 drivers/clk/meson/g12a-ao.c   | 14 ++-
 6 files changed, 112 insertions(+), 4 deletions(-)
 create mode 100644 drivers/clk/meson/axg-ao.c

-- 
2.30.2



[PATCH 5/5] board: amlogic: jethub j100: enable saradc in config

2022-04-20 Thread Vyacheslav Bocharov
Enable ADC in board config file

Signed-off-by: Vyacheslav Bocharov 
---
 configs/jethub_j100_defconfig | 5 +
 1 file changed, 5 insertions(+)

diff --git a/configs/jethub_j100_defconfig b/configs/jethub_j100_defconfig
index 1c6db9f6a0..a30940bf1c 100644
--- a/configs/jethub_j100_defconfig
+++ b/configs/jethub_j100_defconfig
@@ -17,6 +17,7 @@ CONFIG_REMAKE_ELF=y
 CONFIG_OF_BOARD_SETUP=y
 # CONFIG_DISPLAY_CPUINFO is not set
 CONFIG_MISC_INIT_R=y
+CONFIG_CMD_ADC=y
 # CONFIG_CMD_BDI is not set
 # CONFIG_CMD_IMI is not set
 CONFIG_CMD_EEPROM=y
@@ -34,6 +35,10 @@ CONFIG_OF_CONTROL=y
 CONFIG_SYS_RELOC_GD_ENV_ADDR=y
 CONFIG_DM_I2C=y
 CONFIG_SYS_I2C_MESON=y
+CONFIG_ADC=y
+CONFIG_SARADC_MESON=y
+CONFIG_CLK=y
+CONFIG_CLK_MESON_AXG=y
 CONFIG_MMC_MESON_GX=y
 CONFIG_MTD_UBI=y
 CONFIG_PHY_REALTEK=y
-- 
2.30.2



[PATCH 4/5] board: amlogic: jethub j100: enable saradc in dts

2022-04-20 Thread Vyacheslav Bocharov
Prepare to use ADC channel 1 to check the hardware revision of the board.

Signed-off-by: Vyacheslav Bocharov 
---
 arch/arm/dts/meson-axg-jethome-jethub-j100.dts | 5 +
 1 file changed, 5 insertions(+)

diff --git a/arch/arm/dts/meson-axg-jethome-jethub-j100.dts 
b/arch/arm/dts/meson-axg-jethome-jethub-j100.dts
index 5783732dc6..00a0b268af 100644
--- a/arch/arm/dts/meson-axg-jethome-jethub-j100.dts
+++ b/arch/arm/dts/meson-axg-jethome-jethub-j100.dts
@@ -359,3 +359,8 @@
  {
#cooling-cells = <2>;
 };
+
+ {
+   status = "okay";
+   vref-supply = <_ao18>;
+};
-- 
2.30.2



[PATCH 3/5] adc: meson-saradc: add AXG variant

2022-04-20 Thread Vyacheslav Bocharov
Add support for the SARADC variant found on the AXG SoCs family.

Signed-off-by: Vyacheslav Bocharov 
---
 drivers/adc/meson-saradc.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/adc/meson-saradc.c b/drivers/adc/meson-saradc.c
index 1a45a3a265..37023512f0 100644
--- a/drivers/adc/meson-saradc.c
+++ b/drivers/adc/meson-saradc.c
@@ -737,6 +737,8 @@ static const struct udevice_id meson_saradc_ids[] = {
  .data = (ulong)_saradc_data },
{ .compatible = "amlogic,meson-g12a-saradc",
  .data = (ulong)_saradc_data },
+   { .compatible = "amlogic,meson-axg-saradc",
+ .data = (ulong)_saradc_data },
{ }
 };
 
-- 
2.30.2



[PATCH 1/5] clk: meson: add minimal driver for axg-ao clocks

2022-04-20 Thread Vyacheslav Bocharov
Add minimal driver AO clocks on meson AXG family. Only ADC related clocks
are supported.

Signed-off-by: Vyacheslav Bocharov 
---
 drivers/clk/meson/Makefile |  1 +
 drivers/clk/meson/axg-ao.c | 83 ++
 2 files changed, 84 insertions(+)
 create mode 100644 drivers/clk/meson/axg-ao.c

diff --git a/drivers/clk/meson/Makefile b/drivers/clk/meson/Makefile
index b9c6bd66cf..a486b13e9c 100644
--- a/drivers/clk/meson/Makefile
+++ b/drivers/clk/meson/Makefile
@@ -5,5 +5,6 @@
 
 obj-$(CONFIG_CLK_MESON_GX) += gxbb.o
 obj-$(CONFIG_CLK_MESON_AXG) += axg.o
+obj-$(CONFIG_CLK_MESON_AXG) += axg-ao.o
 obj-$(CONFIG_CLK_MESON_G12A) += g12a.o
 obj-$(CONFIG_CLK_MESON_G12A) += g12a-ao.o
diff --git a/drivers/clk/meson/axg-ao.c b/drivers/clk/meson/axg-ao.c
new file mode 100644
index 00..264ec6f0d3
--- /dev/null
+++ b/drivers/clk/meson/axg-ao.c
@@ -0,0 +1,83 @@
+// SPDX-License-Identifier: GPL-2.0+
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "clk_meson.h"
+
+struct meson_clk {
+   struct regmap *map;
+};
+
+#define AO_CLK_GATE0   0x40
+#define AO_SAR_CLK 0x90
+
+static struct meson_gate gates[] = {
+   MESON_GATE(CLKID_AO_SAR_ADC, AO_CLK_GATE0, 7),
+   MESON_GATE(CLKID_AO_SAR_ADC_CLK, AO_SAR_CLK, 7),
+};
+
+static int meson_set_gate(struct clk *clk, bool on)
+{
+   struct meson_clk *priv = dev_get_priv(clk->dev);
+   struct meson_gate *gate;
+
+   if (clk->id >= ARRAY_SIZE(gates))
+   return -ENOENT;
+
+   gate = [clk->id];
+
+   if (gate->reg == 0)
+   return 0;
+
+   regmap_update_bits(priv->map, gate->reg,
+  BIT(gate->bit), on ? BIT(gate->bit) : 0);
+
+   return 0;
+}
+
+static int meson_clk_enable(struct clk *clk)
+{
+   return meson_set_gate(clk, true);
+}
+
+static int meson_clk_disable(struct clk *clk)
+{
+   return meson_set_gate(clk, false);
+}
+
+static int meson_clk_probe(struct udevice *dev)
+{
+   struct meson_clk *priv = dev_get_priv(dev);
+
+   priv->map = syscon_node_to_regmap(dev_ofnode(dev_get_parent(dev)));
+   if (IS_ERR(priv->map))
+   return PTR_ERR(priv->map);
+
+   return 0;
+}
+
+static struct clk_ops meson_clk_ops = {
+   .disable= meson_clk_disable,
+   .enable = meson_clk_enable,
+};
+
+static const struct udevice_id meson_clk_ids[] = {
+   { .compatible = "amlogic,meson-axg-aoclkc" },
+   { }
+};
+
+U_BOOT_DRIVER(meson_clk_axg_ao) = {
+   .name   = "meson_clk_axg_ao",
+   .id = UCLASS_CLK,
+   .of_match   = meson_clk_ids,
+   .priv_auto  = sizeof(struct meson_clk),
+   .ops= _clk_ops,
+   .probe  = meson_clk_probe,
+};
-- 
2.30.2



[PATCH 2/5] clk: meson: fix driver name for g12a-ao clocks

2022-04-20 Thread Vyacheslav Bocharov
Update the clk-g12a-ao driver from "axg" to "g12a"

Signed-off-by: Vyacheslav Bocharov 
---
 drivers/clk/meson/g12a-ao.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/clk/meson/g12a-ao.c b/drivers/clk/meson/g12a-ao.c
index 0148529e04..17b11eb52a 100644
--- a/drivers/clk/meson/g12a-ao.c
+++ b/drivers/clk/meson/g12a-ao.c
@@ -73,7 +73,7 @@ static const struct udevice_id meson_clk_ids[] = {
{ }
 };
 
-U_BOOT_DRIVER(meson_clk_axg) = {
+U_BOOT_DRIVER(meson_clk_g12a_ao) = {
.name   = "meson_clk_g12a_ao",
.id = UCLASS_CLK,
.of_match   = meson_clk_ids,
-- 
2.30.2



[PATCH 0/5] meson: add clk and adc support for JetHub D1 (j100)

2022-04-20 Thread Vyacheslav Bocharov
Prepare to use ADC channel 1 in JetHub D1 (j100) to check the hardware 
revision of the board.

- add support for AXG in saradc driver
- add simple clk-ao driver for AXG (base is taken from g12a)
- enable saradc in dts and board config file
- fix typo in the g12a-clk-ao driver name


Vyacheslav Bocharov (5):
  clk: meson: add minimal driver for axg-ao clocks
  clk: meson: fix driver name for g12a-ao clocks
  adc: meson-saradc: add AXG variant
  board: amlogic: jethub j100: enable saradc in dts
  board: amlogic: jethub j100: enable saradc in config

 .../arm/dts/meson-axg-jethome-jethub-j100.dts |  5 ++
 configs/jethub_j100_defconfig |  5 ++
 drivers/adc/meson-saradc.c|  2 +
 drivers/clk/meson/Makefile|  1 +
 drivers/clk/meson/axg-ao.c| 83 +++
 drivers/clk/meson/g12a-ao.c   |  2 +-
 6 files changed, 97 insertions(+), 1 deletion(-)
 create mode 100644 drivers/clk/meson/axg-ao.c

-- 
2.30.2



Re: [PATCH] configs: amlogic: Disable CONFIG_NET_RANDOM_ETHADDR when unnecessary

2021-11-22 Thread Vyacheslav

Sounds right for jethub boards.

Signed-off-by: Vyacheslav Bocharov 

22.11.2021 14:07, Neil Armstrong пишет:

On Meson GXL, GXM, AXG, G12A, G12B & SM1 SoCs, we can generate an unique
MAC address if none valid found in the eFuses storage.

Only the GXBB based boards doesn't have a fallback way to generate an
unique MAC address, so we rely on CONFIG_NET_RANDOM_ETHADDR to have
a valid one.

An exception is the Radxa Zero board who doesn't have Ethernet on board
so depends on an (or multiple) eventual USB adapters, so leaving the
CONFIG_NET_RANDOM_ETHADDR configs seems safer.

Suggested-by: Tom Rini 
Signed-off-by: Neil Armstrong 
---
  configs/bananapi-m5_defconfig| 1 -
  configs/beelink-gsking-x_defconfig   | 1 -
  configs/beelink-gtking_defconfig | 1 -
  configs/beelink-gtkingpro_defconfig  | 1 -
  configs/jethub_j80_defconfig | 1 -
  configs/khadas-vim2_defconfig| 1 -
  configs/khadas-vim3_defconfig| 1 -
  configs/khadas-vim3l_defconfig   | 1 -
  configs/khadas-vim_defconfig | 1 -
  configs/libretech-ac_defconfig   | 1 -
  configs/libretech-cc_defconfig   | 1 -
  configs/libretech-cc_v2_defconfig| 1 -
  configs/libretech-s905d-pc_defconfig | 1 -
  configs/libretech-s912-pc_defconfig  | 1 -
  configs/odroid-c4_defconfig  | 1 -
  configs/odroid-hc4_defconfig | 1 -
  configs/odroid-n2_defconfig  | 1 -
  configs/p212_defconfig   | 1 -
  configs/s400_defconfig   | 1 -
  configs/sei510_defconfig | 1 -
  configs/sei610_defconfig | 1 -
  configs/u200_defconfig   | 1 -
  configs/wetek-core2_defconfig| 1 -
  23 files changed, 23 deletions(-)

diff --git a/configs/bananapi-m5_defconfig b/configs/bananapi-m5_defconfig
index 7ca14a5f6a..4bf81b2faa 100644
--- a/configs/bananapi-m5_defconfig
+++ b/configs/bananapi-m5_defconfig
@@ -25,7 +25,6 @@ CONFIG_CMD_USB_MASS_STORAGE=y
  CONFIG_CMD_REGULATOR=y
  CONFIG_OF_CONTROL=y
  CONFIG_SYS_RELOC_GD_ENV_ADDR=y
-CONFIG_NET_RANDOM_ETHADDR=y
  CONFIG_ADC=y
  CONFIG_SARADC_MESON=y
  CONFIG_MMC_MESON_GX=y
diff --git a/configs/beelink-gsking-x_defconfig 
b/configs/beelink-gsking-x_defconfig
index 54ac1c9315..e60e754f56 100644
--- a/configs/beelink-gsking-x_defconfig
+++ b/configs/beelink-gsking-x_defconfig
@@ -26,7 +26,6 @@ CONFIG_CMD_USB_MASS_STORAGE=y
  CONFIG_CMD_REGULATOR=y
  CONFIG_OF_CONTROL=y
  CONFIG_SYS_RELOC_GD_ENV_ADDR=y
-CONFIG_NET_RANDOM_ETHADDR=y
  CONFIG_MMC_MESON_GX=y
  CONFIG_MTD=y
  CONFIG_DM_MTD=y
diff --git a/configs/beelink-gtking_defconfig b/configs/beelink-gtking_defconfig
index 7735c70e3f..2ec3221563 100644
--- a/configs/beelink-gtking_defconfig
+++ b/configs/beelink-gtking_defconfig
@@ -26,7 +26,6 @@ CONFIG_CMD_USB_MASS_STORAGE=y
  CONFIG_CMD_REGULATOR=y
  CONFIG_OF_CONTROL=y
  CONFIG_SYS_RELOC_GD_ENV_ADDR=y
-CONFIG_NET_RANDOM_ETHADDR=y
  CONFIG_MMC_MESON_GX=y
  CONFIG_MTD=y
  CONFIG_DM_MTD=y
diff --git a/configs/beelink-gtkingpro_defconfig 
b/configs/beelink-gtkingpro_defconfig
index 93c5739672..60d316d80a 100644
--- a/configs/beelink-gtkingpro_defconfig
+++ b/configs/beelink-gtkingpro_defconfig
@@ -26,7 +26,6 @@ CONFIG_CMD_USB_MASS_STORAGE=y
  CONFIG_CMD_REGULATOR=y
  CONFIG_OF_CONTROL=y
  CONFIG_SYS_RELOC_GD_ENV_ADDR=y
-CONFIG_NET_RANDOM_ETHADDR=y
  CONFIG_MMC_MESON_GX=y
  CONFIG_MTD=y
  CONFIG_DM_MTD=y
diff --git a/configs/jethub_j80_defconfig b/configs/jethub_j80_defconfig
index ad6bec0c43..eb1e4c4a53 100644
--- a/configs/jethub_j80_defconfig
+++ b/configs/jethub_j80_defconfig
@@ -33,7 +33,6 @@ CONFIG_CMD_REGULATOR=y
  CONFIG_PARTITION_TYPE_GUID=y
  CONFIG_OF_CONTROL=y
  CONFIG_SYS_RELOC_GD_ENV_ADDR=y
-CONFIG_NET_RANDOM_ETHADDR=y
  CONFIG_SARADC_MESON=y
  CONFIG_DM_I2C=y
  CONFIG_SYS_I2C_MESON=y
diff --git a/configs/khadas-vim2_defconfig b/configs/khadas-vim2_defconfig
index c852f7f3f9..81cff3cee8 100644
--- a/configs/khadas-vim2_defconfig
+++ b/configs/khadas-vim2_defconfig
@@ -29,7 +29,6 @@ CONFIG_CMD_USB_MASS_STORAGE=y
  CONFIG_CMD_REGULATOR=y
  CONFIG_OF_CONTROL=y
  CONFIG_SYS_RELOC_GD_ENV_ADDR=y
-CONFIG_NET_RANDOM_ETHADDR=y
  CONFIG_SARADC_MESON=y
  CONFIG_MMC_MESON_GX=y
  CONFIG_MTD=y
diff --git a/configs/khadas-vim3_defconfig b/configs/khadas-vim3_defconfig
index a225a564b2..65050efd3f 100644
--- a/configs/khadas-vim3_defconfig
+++ b/configs/khadas-vim3_defconfig
@@ -30,7 +30,6 @@ CONFIG_CMD_USB_MASS_STORAGE=y
  CONFIG_CMD_REGULATOR=y
  CONFIG_OF_CONTROL=y
  CONFIG_SYS_RELOC_GD_ENV_ADDR=y
-CONFIG_NET_RANDOM_ETHADDR=y
  CONFIG_ADC=y
  CONFIG_SARADC_MESON=y
  CONFIG_BUTTON=y
diff --git a/configs/khadas-vim3l_defconfig b/configs/khadas-vim3l_defconfig
index 9d94c31891..b9162c9f1e 100644
--- a/configs/khadas-vim3l_defconfig
+++ b/configs/khadas-vim3l_defconfig
@@ -30,7 +30,6 @@ CONFIG_CMD_USB_MASS_STORAGE=y
  CONFIG_CMD_REGULATOR=y
  CONFIG_OF_CONTROL=y
  CONFIG_SYS_RELOC_GD_ENV_ADDR=y
-CONFIG_NET_RANDOM_ETHADDR=y
  CONFIG_ADC=y
  CONFIG_SARADC_MESON=y
  CONFIG_BUTTON=y
diff --git a/configs/kh

Re: [PATCH] ARM: amlogic: add JetHub D1 eth mac generation with manufacturer OUI

2021-10-29 Thread Vyacheslav

Fix build warning in misc_init_r jethub-j100.c

Signed-off-by: Vyacheslav Bocharov 

---
 board/amlogic/jethub-j100/jethub-j100.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/board/amlogic/jethub-j100/jethub-j100.c 
b/board/amlogic/jethub-j100/jethub-j100.c

index 575bb31573..6a2c4ad4c3 100644
--- a/board/amlogic/jethub-j100/jethub-j100.c
+++ b/board/amlogic/jethub-j100/jethub-j100.c
@@ -13,6 +13,7 @@
 #include 
 #include 
 #include 
+#include 

 int misc_init_r(void)
 {
--
2.30.2



Re: [PATCH] ARM: amlogic: add JetHub D1 eth mac generation with manufacturer OUI

2021-10-29 Thread Vyacheslav

Thanks.

29.10.2021 15:08, Neil Armstrong пишет:

On 29/10/2021 09:08, Vyacheslav Bocharov wrote:

JetHome has own MAC OUI. Add jethub-j100 board file. Update config.

Signed-off-by: Vyacheslav Bocharov 
---
  board/amlogic/jethub-j100/MAINTAINERS   |  8 +
  board/amlogic/jethub-j100/Makefile  |  6 
  board/amlogic/jethub-j100/jethub-j100.c | 41 +
  board/amlogic/jethub-j80/MAINTAINERS|  3 +-
  configs/jethub_j100_defconfig   |  1 +
  5 files changed, 57 insertions(+), 2 deletions(-)
  create mode 100644 board/amlogic/jethub-j100/MAINTAINERS
  create mode 100644 board/amlogic/jethub-j100/Makefile
  create mode 100644 board/amlogic/jethub-j100/jethub-j100.c

diff --git a/board/amlogic/jethub-j100/MAINTAINERS 
b/board/amlogic/jethub-j100/MAINTAINERS
new file mode 100644
index 00..43f6a5fc86
--- /dev/null
+++ b/board/amlogic/jethub-j100/MAINTAINERS
@@ -0,0 +1,8 @@
+JetHome JetHub
+M: Vyacheslav Bocharov 
+S: Maintained
+L: u-boot-amlo...@groups.io
+F: board/amlogic/jethub-j100/
+F: configs/jethub_j100_defconfig
+F: doc/board/amlogic/jethub-j100.rst
+F: include/configs/jethub.h
diff --git a/board/amlogic/jethub-j100/Makefile 
b/board/amlogic/jethub-j100/Makefile
new file mode 100644
index 00..4d935af984
--- /dev/null
+++ b/board/amlogic/jethub-j100/Makefile
@@ -0,0 +1,6 @@
+# SPDX-License-Identifier: GPL-2.0+
+#
+# (C) Copyright 2021 Vyacheslav Bocharov
+# Author: Vyacheslav Bocharov 
+
+obj-y  := jethub-j100.o
diff --git a/board/amlogic/jethub-j100/jethub-j100.c 
b/board/amlogic/jethub-j100/jethub-j100.c
new file mode 100644
index 00..575bb31573
--- /dev/null
+++ b/board/amlogic/jethub-j100/jethub-j100.c
@@ -0,0 +1,41 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2021 Vyacheslav Bocharov
+ * Author: Vyacheslav Bocharov 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+int misc_init_r(void)
+{
+   u8 mac_addr[ARP_HLEN];
+   char serial[SM_SERIAL_SIZE];
+   u32 sid;
+
+   if (!meson_sm_get_serial(serial, SM_SERIAL_SIZE)) {
+   sid = crc32(0, (unsigned char *)serial, SM_SERIAL_SIZE);
+   /* Ensure the NIC specific bytes of the mac are not all 0 */
+   if ((sid & 0x) == 0)
+   sid |= 0x80;
+
+   /* OUI registered MAC address */
+   mac_addr[0] = 0x10;
+   mac_addr[1] = 0x27;
+   mac_addr[2] = 0xBE;
+   mac_addr[3] = (sid >> 16) & 0xff;
+   mac_addr[4] = (sid >>  8) & 0xff;
+   mac_addr[5] = (sid >>  0) & 0xff;
+
+   eth_env_set_enetaddr("ethaddr", mac_addr);
+   }
+
+   return 0;
+}
diff --git a/board/amlogic/jethub-j80/MAINTAINERS 
b/board/amlogic/jethub-j80/MAINTAINERS
index 459e9f89da..a899153117 100644
--- a/board/amlogic/jethub-j80/MAINTAINERS
+++ b/board/amlogic/jethub-j80/MAINTAINERS
@@ -4,6 +4,5 @@ S:  Maintained
  L:u-boot-amlo...@groups.io
  F:board/amlogic/jethub-j80/
  F:configs/jethub_j80_defconfig
-F: configs/jethub_j100_defconfig
  F:doc/board/amlogic/jethub-j80.rst
-F: doc/board/amlogic/jethub-j100.rst
+F: include/configs/jethub.h
diff --git a/configs/jethub_j100_defconfig b/configs/jethub_j100_defconfig
index 290ce4db85..ad026a89e0 100644
--- a/configs/jethub_j100_defconfig
+++ b/configs/jethub_j100_defconfig
@@ -1,4 +1,5 @@
  CONFIG_ARM=y
+CONFIG_SYS_BOARD="jethub-j100"
  CONFIG_SYS_CONFIG_NAME="jethub"
  CONFIG_ARCH_MESON=y
  CONFIG_SYS_TEXT_BASE=0x0100



Applied to u-boot-amlogic

I will probably send it next week along `add sm efuse write support and cmd for 
read/write efuse`

Thanks,
Neil


[PATCH] ARM: amlogic: add JetHub D1 eth mac generation with manufacturer OUI

2021-10-29 Thread Vyacheslav Bocharov
JetHome has own MAC OUI. Add jethub-j100 board file. Update config.

Signed-off-by: Vyacheslav Bocharov 
---
 board/amlogic/jethub-j100/MAINTAINERS   |  8 +
 board/amlogic/jethub-j100/Makefile  |  6 
 board/amlogic/jethub-j100/jethub-j100.c | 41 +
 board/amlogic/jethub-j80/MAINTAINERS|  3 +-
 configs/jethub_j100_defconfig   |  1 +
 5 files changed, 57 insertions(+), 2 deletions(-)
 create mode 100644 board/amlogic/jethub-j100/MAINTAINERS
 create mode 100644 board/amlogic/jethub-j100/Makefile
 create mode 100644 board/amlogic/jethub-j100/jethub-j100.c

diff --git a/board/amlogic/jethub-j100/MAINTAINERS 
b/board/amlogic/jethub-j100/MAINTAINERS
new file mode 100644
index 00..43f6a5fc86
--- /dev/null
+++ b/board/amlogic/jethub-j100/MAINTAINERS
@@ -0,0 +1,8 @@
+JetHome JetHub
+M: Vyacheslav Bocharov 
+S: Maintained
+L: u-boot-amlo...@groups.io
+F: board/amlogic/jethub-j100/
+F: configs/jethub_j100_defconfig
+F: doc/board/amlogic/jethub-j100.rst
+F: include/configs/jethub.h
diff --git a/board/amlogic/jethub-j100/Makefile 
b/board/amlogic/jethub-j100/Makefile
new file mode 100644
index 00..4d935af984
--- /dev/null
+++ b/board/amlogic/jethub-j100/Makefile
@@ -0,0 +1,6 @@
+# SPDX-License-Identifier: GPL-2.0+
+#
+# (C) Copyright 2021 Vyacheslav Bocharov
+# Author: Vyacheslav Bocharov 
+
+obj-y  := jethub-j100.o
diff --git a/board/amlogic/jethub-j100/jethub-j100.c 
b/board/amlogic/jethub-j100/jethub-j100.c
new file mode 100644
index 00..575bb31573
--- /dev/null
+++ b/board/amlogic/jethub-j100/jethub-j100.c
@@ -0,0 +1,41 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2021 Vyacheslav Bocharov
+ * Author: Vyacheslav Bocharov 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+int misc_init_r(void)
+{
+   u8 mac_addr[ARP_HLEN];
+   char serial[SM_SERIAL_SIZE];
+   u32 sid;
+
+   if (!meson_sm_get_serial(serial, SM_SERIAL_SIZE)) {
+   sid = crc32(0, (unsigned char *)serial, SM_SERIAL_SIZE);
+   /* Ensure the NIC specific bytes of the mac are not all 0 */
+   if ((sid & 0x) == 0)
+   sid |= 0x80;
+
+   /* OUI registered MAC address */
+   mac_addr[0] = 0x10;
+   mac_addr[1] = 0x27;
+   mac_addr[2] = 0xBE;
+   mac_addr[3] = (sid >> 16) & 0xff;
+   mac_addr[4] = (sid >>  8) & 0xff;
+   mac_addr[5] = (sid >>  0) & 0xff;
+
+   eth_env_set_enetaddr("ethaddr", mac_addr);
+   }
+
+   return 0;
+}
diff --git a/board/amlogic/jethub-j80/MAINTAINERS 
b/board/amlogic/jethub-j80/MAINTAINERS
index 459e9f89da..a899153117 100644
--- a/board/amlogic/jethub-j80/MAINTAINERS
+++ b/board/amlogic/jethub-j80/MAINTAINERS
@@ -4,6 +4,5 @@ S:  Maintained
 L: u-boot-amlo...@groups.io
 F: board/amlogic/jethub-j80/
 F: configs/jethub_j80_defconfig
-F: configs/jethub_j100_defconfig
 F: doc/board/amlogic/jethub-j80.rst
-F: doc/board/amlogic/jethub-j100.rst
+F: include/configs/jethub.h
diff --git a/configs/jethub_j100_defconfig b/configs/jethub_j100_defconfig
index 290ce4db85..ad026a89e0 100644
--- a/configs/jethub_j100_defconfig
+++ b/configs/jethub_j100_defconfig
@@ -1,4 +1,5 @@
 CONFIG_ARM=y
+CONFIG_SYS_BOARD="jethub-j100"
 CONFIG_SYS_CONFIG_NAME="jethub"
 CONFIG_ARCH_MESON=y
 CONFIG_SYS_TEXT_BASE=0x0100
-- 
2.30.2



[PATCH v2] ARM: amlogic: update JetHub D1/H1 configs (was: add SYS_LOAD_ADDR to JetHub D1/H1 configs)

2021-10-06 Thread Vyacheslav Bocharov
- late fix for 49c8ef0e45a91ec894ef15e7d043dafe8f1c5efd commit by Tom Rini.
- enable i2c, rtc, eeprom

Changes:
- add i2c, rtc, eeprom

Signed-off-by: Vyacheslav Bocharov 
---
 configs/jethub_j100_defconfig | 8 
 configs/jethub_j80_defconfig  | 8 
 2 files changed, 16 insertions(+)

diff --git a/configs/jethub_j100_defconfig b/configs/jethub_j100_defconfig
index 290ce4db85..533f251855 100644
--- a/configs/jethub_j100_defconfig
+++ b/configs/jethub_j100_defconfig
@@ -11,21 +11,27 @@ CONFIG_DEBUG_UART_BASE=0xff803000
 CONFIG_DEBUG_UART_CLOCK=2400
 CONFIG_IDENT_STRING=" jethubj100"
 CONFIG_DEBUG_UART=y
+CONFIG_SYS_LOAD_ADDR=0x0100
 CONFIG_OF_BOARD_SETUP=y
 # CONFIG_DISPLAY_CPUINFO is not set
 CONFIG_MISC_INIT_R=y
 # CONFIG_CMD_BDI is not set
 # CONFIG_CMD_IMI is not set
+CONFIG_CMD_EEPROM=y
 CONFIG_CMD_GPIO=y
 CONFIG_RANDOM_UUID=y
+CONFIG_CMD_I2C=y
 # CONFIG_CMD_LOADS is not set
 CONFIG_CMD_MMC=y
 CONFIG_CMD_USB=y
 CONFIG_CMD_USB_MASS_STORAGE=y
+CONFIG_CMD_RTC=y
 CONFIG_CMD_REGULATOR=y
 CONFIG_PARTITION_TYPE_GUID=y
 CONFIG_OF_CONTROL=y
 CONFIG_SYS_RELOC_GD_ENV_ADDR=y
+CONFIG_DM_I2C=y
+CONFIG_SYS_I2C_MESON=y
 CONFIG_MMC_MESON_GX=y
 CONFIG_MTD_UBI=y
 CONFIG_PHY_REALTEK=y
@@ -37,6 +43,8 @@ CONFIG_PINCTRL_MESON_AXG=y
 CONFIG_DM_REGULATOR=y
 CONFIG_DM_REGULATOR_FIXED=y
 CONFIG_DM_RESET=y
+CONFIG_DM_RTC=y
+CONFIG_RTC_PCF8563=y
 CONFIG_DEBUG_UART_ANNOUNCE=y
 CONFIG_DEBUG_UART_SKIP_INIT=y
 CONFIG_MESON_SERIAL=y
diff --git a/configs/jethub_j80_defconfig b/configs/jethub_j80_defconfig
index 7db05af3b0..ad6bec0c43 100644
--- a/configs/jethub_j80_defconfig
+++ b/configs/jethub_j80_defconfig
@@ -12,25 +12,31 @@ CONFIG_DEBUG_UART_BASE=0xc81004c0
 CONFIG_DEBUG_UART_CLOCK=2400
 CONFIG_IDENT_STRING=" jethubj80"
 CONFIG_DEBUG_UART=y
+CONFIG_SYS_LOAD_ADDR=0x0100
 CONFIG_OF_BOARD_SETUP=y
 CONFIG_CONSOLE_MUX=y
 # CONFIG_DISPLAY_CPUINFO is not set
 CONFIG_MISC_INIT_R=y
 # CONFIG_CMD_BDI is not set
 # CONFIG_CMD_IMI is not set
+CONFIG_CMD_EEPROM=y
 CONFIG_CMD_ADC=y
 CONFIG_CMD_GPIO=y
 CONFIG_RANDOM_UUID=y
+CONFIG_CMD_I2C=y
 # CONFIG_CMD_LOADS is not set
 CONFIG_CMD_MMC=y
 CONFIG_CMD_USB=y
 CONFIG_CMD_USB_MASS_STORAGE=y
+CONFIG_CMD_RTC=y
 CONFIG_CMD_REGULATOR=y
 CONFIG_PARTITION_TYPE_GUID=y
 CONFIG_OF_CONTROL=y
 CONFIG_SYS_RELOC_GD_ENV_ADDR=y
 CONFIG_NET_RANDOM_ETHADDR=y
 CONFIG_SARADC_MESON=y
+CONFIG_DM_I2C=y
+CONFIG_SYS_I2C_MESON=y
 CONFIG_MMC_MESON_GX=y
 CONFIG_MTD_UBI=y
 CONFIG_PHY_MESON_GXL=y
@@ -45,6 +51,8 @@ CONFIG_PINCTRL_MESON_GXL=y
 CONFIG_DM_REGULATOR=y
 CONFIG_DM_REGULATOR_FIXED=y
 CONFIG_DM_RESET=y
+CONFIG_DM_RTC=y
+CONFIG_RTC_PCF8563=y
 CONFIG_DEBUG_UART_ANNOUNCE=y
 CONFIG_DEBUG_UART_SKIP_INIT=y
 CONFIG_MESON_SERIAL=y
-- 
2.30.2



[PATCH] ARM: amlogic: add sm efuse write support and cmd for read/write efuse

2021-10-05 Thread Vyacheslav Bocharov
This adds support for amlogic efuse write and provides two subcommands
of "sm" command: "efuseread" and "efusewrite" to read/write bytes between
memory and efuse.

Signed-off-by: Vyacheslav Bocharov 
---
 arch/arm/mach-meson/sm.c | 68 +++-
 1 file changed, 67 insertions(+), 1 deletion(-)

diff --git a/arch/arm/mach-meson/sm.c b/arch/arm/mach-meson/sm.c
index 1a8f23cb1fa..fb437b94d14 100644
--- a/arch/arm/mach-meson/sm.c
+++ b/arch/arm/mach-meson/sm.c
@@ -68,6 +68,26 @@ ssize_t meson_sm_read_efuse(uintptr_t offset, void *buffer, 
size_t size)
return regs.regs[0];
 }
 
+ssize_t meson_sm_write_efuse(uintptr_t offset, void *buffer, size_t size)
+{
+   struct pt_regs regs;
+
+   meson_init_shmem();
+
+memcpy(shmem_input, buffer, size);
+
+   regs.regs[0] = FN_EFUSE_WRITE;
+   regs.regs[1] = offset;
+   regs.regs[2] = size;
+
+   smc_call();
+
+   if (regs.regs[0] == 0)
+   return -1;
+
+   return 0;
+}
+
 #define SM_CHIP_ID_LENGTH  119
 #define SM_CHIP_ID_OFFSET  4
 #define SM_CHIP_ID_SIZE12
@@ -187,9 +207,53 @@ static int do_sm_reboot_reason(struct cmd_tbl *cmdtp, int 
flag, int argc,
return CMD_RET_SUCCESS;
 }
 
+static int do_efuse_read(struct cmd_tbl *cmdtp, int flag, int argc,
+   char *const argv[])
+{
+   ulong address, offset, size;
+   int ret;
+
+   if (argc < 4)
+   return CMD_RET_USAGE;
+
+offset = simple_strtoul(argv[1], NULL, 0);
+size = simple_strtoul(argv[2], NULL, 0);
+
+address = simple_strtoul(argv[3], NULL, 0);
+
+   ret = meson_sm_read_efuse(offset, (void *)address, size);
+   if (ret)
+   return CMD_RET_FAILURE;
+
+   return CMD_RET_SUCCESS;
+}
+
+static int do_efuse_write(struct cmd_tbl *cmdtp, int flag, int argc,
+   char *const argv[])
+{
+   ulong address, offset, size;
+   int ret;
+
+   if (argc < 4)
+   return CMD_RET_USAGE;
+
+offset = simple_strtoul(argv[1], NULL, 0);
+size = simple_strtoul(argv[2], NULL, 0);
+
+address = simple_strtoul(argv[3], NULL, 0);
+
+   ret = meson_sm_write_efuse(offset, (void *)address, size);
+   if (ret)
+   return CMD_RET_FAILURE;
+
+   return CMD_RET_SUCCESS;
+}
+
 static struct cmd_tbl cmd_sm_sub[] = {
U_BOOT_CMD_MKENT(serial, 2, 1, do_sm_serial, "", ""),
U_BOOT_CMD_MKENT(reboot_reason, 1, 1, do_sm_reboot_reason, "", ""),
+U_BOOT_CMD_MKENT(efuseread, 4, 1, do_efuse_read, "", ""),
+U_BOOT_CMD_MKENT(efusewrite, 4, 0, do_efuse_write, "", ""),
 };
 
 static int do_sm(struct cmd_tbl *cmdtp, int flag, int argc,
@@ -216,5 +280,7 @@ U_BOOT_CMD(
sm, 5, 0, do_sm,
"Secure Monitor Control",
"serial  - read chip unique id to memory address\n"
-   "sm reboot_reason [name] - get reboot reason and store to to 
environment"
+   "sm reboot_reason [name] - get reboot reason and store to to 
environment\n"
+"sm efuseread- read efuse to memory 
address\n"
+"sm efusewrite- write into efuse from 
memory address"
 );
-- 
2.30.2



[PATCH] ARM: amlogic: add SYS_LOAD_ADDR to JetHub D1/H1 configs

2021-10-05 Thread Vyacheslav Bocharov
Late fix for 49c8ef0e45a91ec894ef15e7d043dafe8f1c5efd commit by Tom Rini.

Signed-off-by: Vyacheslav Bocharov 
---
 configs/jethub_j100_defconfig | 1 +
 configs/jethub_j80_defconfig  | 1 +
 2 files changed, 2 insertions(+)

diff --git a/configs/jethub_j100_defconfig b/configs/jethub_j100_defconfig
index 290ce4db850..25aee5a1471 100644
--- a/configs/jethub_j100_defconfig
+++ b/configs/jethub_j100_defconfig
@@ -2,6 +2,7 @@ CONFIG_ARM=y
 CONFIG_SYS_CONFIG_NAME="jethub"
 CONFIG_ARCH_MESON=y
 CONFIG_SYS_TEXT_BASE=0x0100
+CONFIG_SYS_LOAD_ADDR=0x0100
 CONFIG_NR_DRAM_BANKS=1
 CONFIG_ENV_SIZE=0x2000
 CONFIG_DM_GPIO=y
diff --git a/configs/jethub_j80_defconfig b/configs/jethub_j80_defconfig
index 7db05af3b0d..524d4cc9b7b 100644
--- a/configs/jethub_j80_defconfig
+++ b/configs/jethub_j80_defconfig
@@ -3,6 +3,7 @@ CONFIG_SYS_BOARD="jethub-j80"
 CONFIG_SYS_CONFIG_NAME="jethub"
 CONFIG_ARCH_MESON=y
 CONFIG_SYS_TEXT_BASE=0x0100
+CONFIG_SYS_LOAD_ADDR=0x0100
 CONFIG_NR_DRAM_BANKS=1
 CONFIG_ENV_SIZE=0x2000
 CONFIG_DM_GPIO=y
-- 
2.30.2



Re: [PATCH v2 2/3] ARM: amlogic: add JetHub D1/H1 device support

2021-09-20 Thread Vyacheslav

20.09.2021 09:43, Neil Armstrong wrote:

Hi,

On 19/09/2021 17:52, Vyacheslav Bocharov wrote:

Add support for new home automation devices.


While applying I had a few warnings:


+   if (!env_get("serial")) {
+   len = meson_sm_read_efuse(EFUSE_SN_OFFSET, serial,


ERROR: trailing whitespace
#777: FILE: board/amlogic/jethub-j80/jethub-j80.c:48:
+^I^Ilen = meson_sm_read_efuse(EFUSE_SN_OFFSET, serial, $

CHECK: Alignment should match open parenthesis
#778: FILE: board/amlogic/jethub-j80/jethub-j80.c:49:
+   len = meson_sm_read_efuse(EFUSE_SN_OFFSET, serial,
+   EFUSE_SN_SIZE);

CHECK: Alignment should match open parenthesis
#785: FILE: board/amlogic/jethub-j80/jethub-j80.c:56:
+   len = meson_sm_read_efuse(EFUSE_USID_OFFSET, usid,
+   EFUSE_USID_SIZE);


I'll double-check everything and resend a new version of the patches.



This file isn't part of any MAINTAINERS file, either add it to the s400 one or 
the j80 one.


I'll add it to jethub-j80/MAINTAINERS.

Thanks!




[PATCH v3 2/3] ARM: amlogic: add JetHub D1/H1 device support

2021-09-20 Thread Vyacheslav Bocharov
Add support for new home automation devices.

JetHome Jethub D1 (http://jethome.ru/jethub-d1) is a home automation controller 
with the following features:
- DIN Rail Mounting case
- Amlogic A113X (ARM Cortex-A53) quad-core up to 1.5GHz
- no video out
- 512Mb/1GB DDR3
- 8/16GB eMMC flash
- 1 x USB 2.0
- 1 x 10/100Mbps ethernet
- WiFi / Bluetooth AMPAK AP6255 (Broadcom BCM43455) IEEE 802.11a/b/g/n/ac, 
Bluetooth 4.2.
- TI CC2538 + CC2592 Zigbee Wireless Module with up to 20dBm output power and 
Zigbee 3.0 support.
- 2 x gpio LEDS
- GPIO user Button
- 1 x 1-Wire
- 2 x RS-485
- 4 x dry contact digital GPIO inputs
- 3 x relay GPIO outputs
- DC source with a voltage of 9 to 56 V / Passive POE

JetHome Jethub H1 (http://jethome.ru/jethub-h1) is a home automation controller 
with the following features:
- Square plastic case
- Amlogic S905W (ARM Cortex-A53) quad-core up to 1.5GHz
- no video out
- 1GB DDR3
- 8/16GB eMMC flash
- 2 x USB 2.0
- 1 x 10/100Mbps ethernet
- WiFi / Bluetooth RTL8822CS IEEE 802.11a/b/g/n/ac, Bluetooth 5.0.
- TI CC2538 + CC2592 Zigbee Wireless Module with up to 20dBm output power and 
Zigbee 3.0 support.
- MicroSD 2.x/3.x/4.x DS/HS cards.
- 1 x gpio LED
- ADC user Button
- DC source 5V microUSB with serial console

Patches from:
- JetHub H1
  https://lore.kernel.org/r/20210915085715.1134940-4-ad...@lexina.in
  https://git.kernel.org/amlogic/c/abfaae24ecf3e7f00508b60fa05e2b6789b8f607
- JetHub D1
  https://lore.kernel.org/r/20210915085715.1134940-5-ad...@lexina.in
  https://git.kernel.org/amlogic/c/8e279fb2903990cc6296ec56b3b80b2f854b6c79

Signed-off-by: Vyacheslav Bocharov 
Reviewed-by: Neil Armstrong 
---
 arch/arm/dts/Makefile |   2 +
 .../arm/dts/meson-axg-jethome-jethub-j100.dts | 361 ++
 .../meson-gxl-s905w-jethome-jethub-j80.dts| 241 
 board/amlogic/jethub-j80/MAINTAINERS  |   9 +
 board/amlogic/jethub-j80/Makefile |   6 +
 board/amlogic/jethub-j80/jethub-j80.c |  68 
 configs/jethub_j100_defconfig |  55 +++
 configs/jethub_j80_defconfig  |  63 +++
 8 files changed, 805 insertions(+)
 create mode 100644 arch/arm/dts/meson-axg-jethome-jethub-j100.dts
 create mode 100644 arch/arm/dts/meson-gxl-s905w-jethome-jethub-j80.dts
 create mode 100644 board/amlogic/jethub-j80/MAINTAINERS
 create mode 100644 board/amlogic/jethub-j80/Makefile
 create mode 100644 board/amlogic/jethub-j80/jethub-j80.c
 create mode 100644 configs/jethub_j100_defconfig
 create mode 100644 configs/jethub_j80_defconfig

diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
index f0160d2dc0..d1893a9812 100644
--- a/arch/arm/dts/Makefile
+++ b/arch/arm/dts/Makefile
@@ -169,10 +169,12 @@ dtb-$(CONFIG_ARCH_MESON) += \
meson-gxl-s905x-libretech-cc-v2.dtb \
meson-gxl-s905x-khadas-vim.dtb \
meson-gxl-s905d-libretech-pc.dtb \
+   meson-gxl-s905w-jethome-jethub-j80.dtb \
meson-gxm-khadas-vim2.dtb \
meson-gxm-s912-libretech-pc.dtb \
meson-gxm-wetek-core2.dtb \
meson-axg-s400.dtb \
+   meson-axg-jethome-jethub-j100.dtb \
meson-g12a-u200.dtb \
meson-g12a-sei510.dtb \
meson-g12b-gtking.dtb \
diff --git a/arch/arm/dts/meson-axg-jethome-jethub-j100.dts 
b/arch/arm/dts/meson-axg-jethome-jethub-j100.dts
new file mode 100644
index 00..5783732dc6
--- /dev/null
+++ b/arch/arm/dts/meson-axg-jethome-jethub-j100.dts
@@ -0,0 +1,361 @@
+// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
+/*
+ * Copyright (c) 2021 Vyacheslav Bocharov 
+ * Copyright (c) 2020 JetHome
+ * Author: Aleksandr Kazantsev 
+ * Author: Alexey Shevelkin 
+ * Author: Vyacheslav Bocharov 
+ */
+
+/dts-v1/;
+
+#include "meson-axg.dtsi"
+#include 
+#include 
+
+/ {
+   compatible = "jethome,jethub-j100", "amlogic,a113d", 
"amlogic,meson-axg";
+   model = "JetHome JetHub J100";
+   aliases {
+   serial0 = _AO;   /* Console */
+   serial1 = _AO_B; /* External UART (Wireless Module) */
+   ethernet0 = 
+   };
+
+   chosen {
+   stdout-path = "serial0:115200n8";
+   };
+
+   /* 1024MB RAM */
+   memory@0 {
+   device_type = "memory";
+   reg = <0x0 0x0 0x0 0x4000>;
+   };
+
+   reserved-memory {
+   linux,cma {
+   size = <0x0 0x40>;
+   };
+   };
+
+   emmc_pwrseq: emmc-pwrseq {
+   compatible = "mmc-pwrseq-emmc";
+   reset-gpios = < BOOT_9 GPIO_ACTIVE_LOW>;
+   };
+
+   vcc_3v3: regulator-vcc_3v3 {
+   compatible = "regulator-fixed";
+   regulator-name = "VCC_3V3";
+   regulator-min-microvolt = <330>;
+   regulator-max-microvolt = <330>;
+   vin-supply = <_3v3

[PATCH v3 3/3] ARM: amlogic: add JetHub D1/H1 docs

2021-09-20 Thread Vyacheslav Bocharov
Fix doc/board/amlogic/index.rst:
- Add S905W to S905X column.
- Add JetHub devices to the corresponding columns.
- Fix tabs to spaces for table alignment

Add doc/board/amlogic files:
- jethub-j100.rst
- jethub-j80.rst

Signed-off-by: Vyacheslav Bocharov 
Reviewed-by: Neil Armstrong 
---
 doc/board/amlogic/index.rst   | 128 +++---
 doc/board/amlogic/jethub-j100.rst | 108 +
 doc/board/amlogic/jethub-j80.rst  |  97 ++
 3 files changed, 270 insertions(+), 63 deletions(-)
 create mode 100644 doc/board/amlogic/jethub-j100.rst
 create mode 100644 doc/board/amlogic/jethub-j80.rst

diff --git a/doc/board/amlogic/index.rst b/doc/board/amlogic/index.rst
index 2913ab281a..c18f1b7e71 100644
--- a/doc/board/amlogic/index.rst
+++ b/doc/board/amlogic/index.rst
@@ -10,69 +10,69 @@ An up-do-date matrix is also available on: 
http://linux-meson.com
 
 This matrix concerns the actual source code version.
 
-+---+---+-+--+++-+--+
-|  | S905  | S905X   | S912 | 
A113X  | S905X2 | S922X   | S905X3   |
-|  |   | S805X   | S905D|  
  | S905D2 | A311D   | S905D3   |
-|  |   | |  |  
  | S905Y2 | |  |
-+===+===+=+==+++=+==+
-| Boards   | Odroid-C2 | P212| Khadas 
VIM2  | S400   | U200   | Odroid-N2   | SEI610   |
-|  | Nanopi-K2 | Khadas-VIM  | Libretech-PC |  
  | SEI510 | Khadas-VIM3 | Khadas-VIM3L |
-|  | P200  | LibreTech-CC v1 | WeTek Core2  |  
  || GT-King/Pro | Odroid-C4|
-|  | P201  | LibreTech-AC v2 |  |  
  || GSKing-X| Odroid-HC4   |
-|   |   | |  | 
   || | BananaPi-M5  |
-+---+---+-+--+++-+--+
-| UART | **Yes**   | **Yes** | **Yes**  | 
**Yes**| **Yes**| **Yes** | **Yes**  |
-+---+---+-+--+++-+--+
-| Pinctrl/GPIO | **Yes**   | **Yes** | **Yes**  | 
**Yes**| **Yes**| **Yes** | **Yes**  |
-+---+---+-+--+++-+--+
-| Clock Control| **Yes**   | **Yes** | **Yes**  | 
**Yes**| **Yes**| **Yes** | **Yes**  |
-+---+---+-+--+++-+--+
-| PWM  | **Yes**   | **Yes** | **Yes**  | 
**Yes**| **Yes**| **Yes** | **Yes**  |
-+---+---+-+--+++-+--+
-| Reset Control| **Yes**   | **Yes** | **Yes**  | 
**Yes**| **Yes**| **Yes** | **Yes**  |
-+---+---+-+--+++-+--+
-| Infrared Decoder | No| No  | No   | 
No | No | No  | No   |
-+---+---+-+--+++-+--+
-| Ethernet | **Yes**   | **Yes** | **Yes**  | 
**Yes**| **Yes**| **Yes** | **Yes**  |
-+---+---+-+--+++-+--+
-| Multi-core   | **Yes**   | **Yes** | **Yes**  | 
**Yes**| **Yes**| **Yes** | **Yes**  |
-+---+---+-+--+++-+--+
-| Fuse access  | **Yes**   | **Yes** |**Yes**   
|**Yes** |**Yes** |**Yes**  | **Yes**  |
-+---+---+-+--+++-+--+
-| SPI (FC) | **Yes**   | **Yes** | **Yes**  | 
**Yes**|**Yes

[PATCH v3 0/3] ARM: meson: add support for JetHub D1/H1

2021-09-20 Thread Vyacheslav Bocharov
Add support for new home automation devices manufactured by JetHome.
Patches prepared for use with the "ARM: meson: Sync Amlogic DT from Linux 5.14" 
patch series by Neil Armstrong

JetHome Jethub D1 (http://jethome.ru/jethub-d1) is a home automation controller 
with the following features:
- DIN Rail Mounting case
- Amlogic A113X (ARM Cortex-A53) quad-core up to 1.5GHz
- no video out
- 512Mb/1GB DDR3
- 8/16GB eMMC flash
- 1 x USB 2.0
- 1 x 10/100Mbps ethernet
- WiFi / Bluetooth AMPAK AP6255 (Broadcom BCM43455) IEEE 802.11a/b/g/n/ac, 
Bluetooth 4.2.
- TI CC2538 + CC2592 Zigbee Wireless Module with up to 20dBm output power and 
Zigbee 3.0 support.
- 2 x gpio LEDS
- GPIO user Button
- 1 x 1-Wire
- 2 x RS-485
- 4 x dry contact digital GPIO inputs
- 3 x relay GPIO outputs
- DC source with a voltage of 9 to 56 V / Passive POE

JetHome Jethub H1 (http://jethome.ru/jethub-h1) is a home automation controller 
with the following features:
- Square plastic case
- Amlogic S905W (ARM Cortex-A53) quad-core up to 1.5GHz
- no video out
- 1GB DDR3
- 8/16GB eMMC flash
- 2 x USB 2.0
- 1 x 10/100Mbps ethernet
- WiFi / Bluetooth RTL8822CS IEEE 802.11a/b/g/n/ac, Bluetooth 5.0.
- TI CC2538 + CC2592 Zigbee Wireless Module with up to 20dBm output power and 
Zigbee 3.0 support.
- MicroSD 2.x/3.x/4.x DS/HS cards.
- 1 x gpio LED
- ADC user Button
- DC source 5V microUSB with serial console

Changes from v2:
- fix "Alignment should match open parenthesis" in 
board/amlogic/jethub-j80/jethub-j80.c
- add missing files to board/amlogic/jethub-j80/MAINTAINERS
- fix unexpected unindent in doc files

Changes from v1:
- fix BOOT_TARGET_DEVICES in jethub.h (patch 1/3)
- add lore URLs to description (patch 2/3)

Signed-off-by: Vyacheslav Bocharov 

Vyacheslav Bocharov (3):
  ARM: amlogic: add JetHub common config header
  ARM: amlogic: add JetHub D1/H1 device support
  ARM: amlogic: add JetHub D1/H1 docs

 arch/arm/dts/Makefile |   2 +
 .../arm/dts/meson-axg-jethome-jethub-j100.dts | 361 ++
 .../meson-gxl-s905w-jethome-jethub-j80.dts| 241 
 board/amlogic/jethub-j80/MAINTAINERS  |   9 +
 board/amlogic/jethub-j80/Makefile |   6 +
 board/amlogic/jethub-j80/jethub-j80.c |  68 
 configs/jethub_j100_defconfig |  55 +++
 configs/jethub_j80_defconfig  |  63 +++
 doc/board/amlogic/index.rst   | 128 ---
 doc/board/amlogic/jethub-j100.rst | 108 ++
 doc/board/amlogic/jethub-j80.rst  |  97 +
 include/configs/jethub.h  |  40 ++
 12 files changed, 1115 insertions(+), 63 deletions(-)
 create mode 100644 arch/arm/dts/meson-axg-jethome-jethub-j100.dts
 create mode 100644 arch/arm/dts/meson-gxl-s905w-jethome-jethub-j80.dts
 create mode 100644 board/amlogic/jethub-j80/MAINTAINERS
 create mode 100644 board/amlogic/jethub-j80/Makefile
 create mode 100644 board/amlogic/jethub-j80/jethub-j80.c
 create mode 100644 configs/jethub_j100_defconfig
 create mode 100644 configs/jethub_j80_defconfig
 create mode 100644 doc/board/amlogic/jethub-j100.rst
 create mode 100644 doc/board/amlogic/jethub-j80.rst
 create mode 100644 include/configs/jethub.h

-- 
2.30.2



[PATCH v3 1/3] ARM: amlogic: add JetHub common config header

2021-09-20 Thread Vyacheslav Bocharov
JetHub devices uses its own boot sequence with "rescue" button

Signed-off-by: Vyacheslav Bocharov 
---
 include/configs/jethub.h | 40 
 1 file changed, 40 insertions(+)
 create mode 100644 include/configs/jethub.h

diff --git a/include/configs/jethub.h b/include/configs/jethub.h
new file mode 100644
index 00..35f85095ac
--- /dev/null
+++ b/include/configs/jethub.h
@@ -0,0 +1,40 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Configuration for JetHome devices
+ * Copyright (C) 2021 Vyacheslav Bocharov
+ * Author: Vyacheslav Bocharov 
+ */
+
+#ifndef __JETHUB_CONFIG_H
+#define __JETHUB_CONFIG_H
+
+#if defined(CONFIG_MESON_AXG)
+#define BOOTENV_DEV_RESCUE(devtypeu, devtypel, instance) \
+   "bootcmd_rescue=" \
+   "if gpio input 10; then " \
+   "run bootcmd_usb0;" \
+   "fi;\0"
+#else
+#define BOOTENV_DEV_RESCUE(devtypeu, devtypel, instance) \
+   "bootcmd_rescue=" \
+   "if test \"${userbutton}\" = \"true\"; then " \
+   "run bootcmd_mmc0; " \
+   "fi;\0"
+#endif
+
+#define BOOTENV_DEV_NAME_RESCUE(devtypeu, devtypel, instance) \
+   "rescue "
+
+#ifndef BOOT_TARGET_DEVICES
+#define BOOT_TARGET_DEVICES(func) \
+   func(RESCUE, rescue, na) \
+   func(MMC, mmc, 1) \
+   func(MMC, mmc, 0) \
+   BOOT_TARGET_DEVICES_USB(func) \
+   func(PXE, pxe, na) \
+   func(DHCP, dhcp, na)
+#endif
+
+#include 
+
+#endif /* __JETHUB_CONFIG_H */
-- 
2.30.2



[PATCH v2 3/3] ARM: amlogic: add JetHub D1/H1 docs

2021-09-19 Thread Vyacheslav Bocharov
Fix doc/board/amlogic/index.rst:
- Add S905W to S905X column.
- Add JetHub devices to the corresponding columns.
- Fix tabs to spaces for table alignment

Add doc/board/amlogic files:
- jethub-j100.rst
- jethub-j80.rst

Signed-off-by: Vyacheslav Bocharov 
Reviewed-by: Neil Armstrong 
---
 doc/board/amlogic/index.rst   | 128 +++---
 doc/board/amlogic/jethub-j100.rst | 108 +
 doc/board/amlogic/jethub-j80.rst  |  97 ++
 3 files changed, 270 insertions(+), 63 deletions(-)
 create mode 100644 doc/board/amlogic/jethub-j100.rst
 create mode 100644 doc/board/amlogic/jethub-j80.rst

diff --git a/doc/board/amlogic/index.rst b/doc/board/amlogic/index.rst
index 2913ab281a..c18f1b7e71 100644
--- a/doc/board/amlogic/index.rst
+++ b/doc/board/amlogic/index.rst
@@ -10,69 +10,69 @@ An up-do-date matrix is also available on: 
http://linux-meson.com
 
 This matrix concerns the actual source code version.
 
-+---+---+-+--+++-+--+
-|  | S905  | S905X   | S912 | 
A113X  | S905X2 | S922X   | S905X3   |
-|  |   | S805X   | S905D|  
  | S905D2 | A311D   | S905D3   |
-|  |   | |  |  
  | S905Y2 | |  |
-+===+===+=+==+++=+==+
-| Boards   | Odroid-C2 | P212| Khadas 
VIM2  | S400   | U200   | Odroid-N2   | SEI610   |
-|  | Nanopi-K2 | Khadas-VIM  | Libretech-PC |  
  | SEI510 | Khadas-VIM3 | Khadas-VIM3L |
-|  | P200  | LibreTech-CC v1 | WeTek Core2  |  
  || GT-King/Pro | Odroid-C4|
-|  | P201  | LibreTech-AC v2 |  |  
  || GSKing-X| Odroid-HC4   |
-|   |   | |  | 
   || | BananaPi-M5  |
-+---+---+-+--+++-+--+
-| UART | **Yes**   | **Yes** | **Yes**  | 
**Yes**| **Yes**| **Yes** | **Yes**  |
-+---+---+-+--+++-+--+
-| Pinctrl/GPIO | **Yes**   | **Yes** | **Yes**  | 
**Yes**| **Yes**| **Yes** | **Yes**  |
-+---+---+-+--+++-+--+
-| Clock Control| **Yes**   | **Yes** | **Yes**  | 
**Yes**| **Yes**| **Yes** | **Yes**  |
-+---+---+-+--+++-+--+
-| PWM  | **Yes**   | **Yes** | **Yes**  | 
**Yes**| **Yes**| **Yes** | **Yes**  |
-+---+---+-+--+++-+--+
-| Reset Control| **Yes**   | **Yes** | **Yes**  | 
**Yes**| **Yes**| **Yes** | **Yes**  |
-+---+---+-+--+++-+--+
-| Infrared Decoder | No| No  | No   | 
No | No | No  | No   |
-+---+---+-+--+++-+--+
-| Ethernet | **Yes**   | **Yes** | **Yes**  | 
**Yes**| **Yes**| **Yes** | **Yes**  |
-+---+---+-+--+++-+--+
-| Multi-core   | **Yes**   | **Yes** | **Yes**  | 
**Yes**| **Yes**| **Yes** | **Yes**  |
-+---+---+-+--+++-+--+
-| Fuse access  | **Yes**   | **Yes** |**Yes**   
|**Yes** |**Yes** |**Yes**  | **Yes**  |
-+---+---+-+--+++-+--+
-| SPI (FC) | **Yes**   | **Yes** | **Yes**  | 
**Yes**|**Yes

[PATCH v2 2/3] ARM: amlogic: add JetHub D1/H1 device support

2021-09-19 Thread Vyacheslav Bocharov
Add support for new home automation devices.

JetHome Jethub D1 (http://jethome.ru/jethub-d1) is a home automation controller 
with the following features:
- DIN Rail Mounting case
- Amlogic A113X (ARM Cortex-A53) quad-core up to 1.5GHz
- no video out
- 512Mb/1GB DDR3
- 8/16GB eMMC flash
- 1 x USB 2.0
- 1 x 10/100Mbps ethernet
- WiFi / Bluetooth AMPAK AP6255 (Broadcom BCM43455) IEEE 802.11a/b/g/n/ac, 
Bluetooth 4.2.
- TI CC2538 + CC2592 Zigbee Wireless Module with up to 20dBm output power and 
Zigbee 3.0 support.
- 2 x gpio LEDS
- GPIO user Button
- 1 x 1-Wire
- 2 x RS-485
- 4 x dry contact digital GPIO inputs
- 3 x relay GPIO outputs
- DC source with a voltage of 9 to 56 V / Passive POE

JetHome Jethub H1 (http://jethome.ru/jethub-h1) is a home automation controller 
with the following features:
- Square plastic case
- Amlogic S905W (ARM Cortex-A53) quad-core up to 1.5GHz
- no video out
- 1GB DDR3
- 8/16GB eMMC flash
- 2 x USB 2.0
- 1 x 10/100Mbps ethernet
- WiFi / Bluetooth RTL8822CS IEEE 802.11a/b/g/n/ac, Bluetooth 5.0.
- TI CC2538 + CC2592 Zigbee Wireless Module with up to 20dBm output power and 
Zigbee 3.0 support.
- MicroSD 2.x/3.x/4.x DS/HS cards.
- 1 x gpio LED
- ADC user Button
- DC source 5V microUSB with serial console

Patches from:
- JetHub H1
  https://lore.kernel.org/r/20210915085715.1134940-4-ad...@lexina.in
  https://git.kernel.org/amlogic/c/abfaae24ecf3e7f00508b60fa05e2b6789b8f607
- JetHub D1
  https://lore.kernel.org/r/20210915085715.1134940-5-ad...@lexina.in
  https://git.kernel.org/amlogic/c/8e279fb2903990cc6296ec56b3b80b2f854b6c79

Signed-off-by: Vyacheslav Bocharov 
Reviewed-by: Neil Armstrong 
---
 arch/arm/dts/Makefile |   2 +
 .../arm/dts/meson-axg-jethome-jethub-j100.dts | 361 ++
 .../meson-gxl-s905w-jethome-jethub-j80.dts| 241 
 board/amlogic/jethub-j80/MAINTAINERS  |   6 +
 board/amlogic/jethub-j80/Makefile |   6 +
 board/amlogic/jethub-j80/jethub-j80.c |  68 
 configs/jethub_j100_defconfig |  55 +++
 configs/jethub_j80_defconfig  |  63 +++
 8 files changed, 802 insertions(+)
 create mode 100644 arch/arm/dts/meson-axg-jethome-jethub-j100.dts
 create mode 100644 arch/arm/dts/meson-gxl-s905w-jethome-jethub-j80.dts
 create mode 100644 board/amlogic/jethub-j80/MAINTAINERS
 create mode 100644 board/amlogic/jethub-j80/Makefile
 create mode 100644 board/amlogic/jethub-j80/jethub-j80.c
 create mode 100644 configs/jethub_j100_defconfig
 create mode 100644 configs/jethub_j80_defconfig

diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
index f0160d2dc0..d1893a9812 100644
--- a/arch/arm/dts/Makefile
+++ b/arch/arm/dts/Makefile
@@ -169,10 +169,12 @@ dtb-$(CONFIG_ARCH_MESON) += \
meson-gxl-s905x-libretech-cc-v2.dtb \
meson-gxl-s905x-khadas-vim.dtb \
meson-gxl-s905d-libretech-pc.dtb \
+   meson-gxl-s905w-jethome-jethub-j80.dtb \
meson-gxm-khadas-vim2.dtb \
meson-gxm-s912-libretech-pc.dtb \
meson-gxm-wetek-core2.dtb \
meson-axg-s400.dtb \
+   meson-axg-jethome-jethub-j100.dtb \
meson-g12a-u200.dtb \
meson-g12a-sei510.dtb \
meson-g12b-gtking.dtb \
diff --git a/arch/arm/dts/meson-axg-jethome-jethub-j100.dts 
b/arch/arm/dts/meson-axg-jethome-jethub-j100.dts
new file mode 100644
index 00..5783732dc6
--- /dev/null
+++ b/arch/arm/dts/meson-axg-jethome-jethub-j100.dts
@@ -0,0 +1,361 @@
+// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
+/*
+ * Copyright (c) 2021 Vyacheslav Bocharov 
+ * Copyright (c) 2020 JetHome
+ * Author: Aleksandr Kazantsev 
+ * Author: Alexey Shevelkin 
+ * Author: Vyacheslav Bocharov 
+ */
+
+/dts-v1/;
+
+#include "meson-axg.dtsi"
+#include 
+#include 
+
+/ {
+   compatible = "jethome,jethub-j100", "amlogic,a113d", 
"amlogic,meson-axg";
+   model = "JetHome JetHub J100";
+   aliases {
+   serial0 = _AO;   /* Console */
+   serial1 = _AO_B; /* External UART (Wireless Module) */
+   ethernet0 = 
+   };
+
+   chosen {
+   stdout-path = "serial0:115200n8";
+   };
+
+   /* 1024MB RAM */
+   memory@0 {
+   device_type = "memory";
+   reg = <0x0 0x0 0x0 0x4000>;
+   };
+
+   reserved-memory {
+   linux,cma {
+   size = <0x0 0x40>;
+   };
+   };
+
+   emmc_pwrseq: emmc-pwrseq {
+   compatible = "mmc-pwrseq-emmc";
+   reset-gpios = < BOOT_9 GPIO_ACTIVE_LOW>;
+   };
+
+   vcc_3v3: regulator-vcc_3v3 {
+   compatible = "regulator-fixed";
+   regulator-name = "VCC_3V3";
+   regulator-min-microvolt = <330>;
+   regulator-max-microvolt = <330>;
+   vin-supply = <_3v3

[PATCH v2 0/3] ARM: meson: add support for JetHub D1/H1

2021-09-19 Thread Vyacheslav Bocharov
Add support for new home automation devices manufactured by JetHome.
Patches prepared for use with the "ARM: meson: Sync Amlogic DT from Linux 5.14" 
patch series by Neil Armstrong

JetHome Jethub D1 (http://jethome.ru/jethub-d1) is a home automation controller 
with the following features:
- DIN Rail Mounting case
- Amlogic A113X (ARM Cortex-A53) quad-core up to 1.5GHz
- no video out
- 512Mb/1GB DDR3
- 8/16GB eMMC flash
- 1 x USB 2.0
- 1 x 10/100Mbps ethernet
- WiFi / Bluetooth AMPAK AP6255 (Broadcom BCM43455) IEEE 802.11a/b/g/n/ac, 
Bluetooth 4.2.
- TI CC2538 + CC2592 Zigbee Wireless Module with up to 20dBm output power and 
Zigbee 3.0 support.
- 2 x gpio LEDS
- GPIO user Button
- 1 x 1-Wire
- 2 x RS-485
- 4 x dry contact digital GPIO inputs
- 3 x relay GPIO outputs
- DC source with a voltage of 9 to 56 V / Passive POE

JetHome Jethub H1 (http://jethome.ru/jethub-h1) is a home automation controller 
with the following features:
- Square plastic case
- Amlogic S905W (ARM Cortex-A53) quad-core up to 1.5GHz
- no video out
- 1GB DDR3
- 8/16GB eMMC flash
- 2 x USB 2.0
- 1 x 10/100Mbps ethernet
- WiFi / Bluetooth RTL8822CS IEEE 802.11a/b/g/n/ac, Bluetooth 5.0.
- TI CC2538 + CC2592 Zigbee Wireless Module with up to 20dBm output power and 
Zigbee 3.0 support.
- MicroSD 2.x/3.x/4.x DS/HS cards.
- 1 x gpio LED
- ADC user Button
- DC source 5V microUSB with serial console

Changes from v1:
- fix BOOT_TARGET_DEVICES in jethub.h (patch 1/3)
- add lore URLs to description (patch 2/3)

Signed-off-by: Vyacheslav Bocharov 

Vyacheslav Bocharov (3):
  ARM: amlogic: add JetHub common config header
  ARM: amlogic: add JetHub D1/H1 device support
  ARM: amlogic: add JetHub D1/H1 docs

 arch/arm/dts/Makefile |   2 +
 .../arm/dts/meson-axg-jethome-jethub-j100.dts | 361 ++
 .../meson-gxl-s905w-jethome-jethub-j80.dts| 241 
 board/amlogic/jethub-j80/MAINTAINERS  |   6 +
 board/amlogic/jethub-j80/Makefile |   6 +
 board/amlogic/jethub-j80/jethub-j80.c |  68 
 configs/jethub_j100_defconfig |  55 +++
 configs/jethub_j80_defconfig  |  63 +++
 doc/board/amlogic/index.rst   | 128 ---
 doc/board/amlogic/jethub-j100.rst | 108 ++
 doc/board/amlogic/jethub-j80.rst  |  97 +
 include/configs/jethub.h  |  40 ++
 12 files changed, 1112 insertions(+), 63 deletions(-)
 create mode 100644 arch/arm/dts/meson-axg-jethome-jethub-j100.dts
 create mode 100644 arch/arm/dts/meson-gxl-s905w-jethome-jethub-j80.dts
 create mode 100644 board/amlogic/jethub-j80/MAINTAINERS
 create mode 100644 board/amlogic/jethub-j80/Makefile
 create mode 100644 board/amlogic/jethub-j80/jethub-j80.c
 create mode 100644 configs/jethub_j100_defconfig
 create mode 100644 configs/jethub_j80_defconfig
 create mode 100644 doc/board/amlogic/jethub-j100.rst
 create mode 100644 doc/board/amlogic/jethub-j80.rst
 create mode 100644 include/configs/jethub.h

-- 
2.30.2



[PATCH v2 1/3] ARM: amlogic: add JetHub common config header

2021-09-19 Thread Vyacheslav Bocharov
JetHub devices uses its own boot sequence with "rescue" button

Signed-off-by: Vyacheslav Bocharov 
---
 include/configs/jethub.h | 40 
 1 file changed, 40 insertions(+)
 create mode 100644 include/configs/jethub.h

diff --git a/include/configs/jethub.h b/include/configs/jethub.h
new file mode 100644
index 00..35f85095ac
--- /dev/null
+++ b/include/configs/jethub.h
@@ -0,0 +1,40 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Configuration for JetHome devices
+ * Copyright (C) 2021 Vyacheslav Bocharov
+ * Author: Vyacheslav Bocharov 
+ */
+
+#ifndef __JETHUB_CONFIG_H
+#define __JETHUB_CONFIG_H
+
+#if defined(CONFIG_MESON_AXG)
+#define BOOTENV_DEV_RESCUE(devtypeu, devtypel, instance) \
+   "bootcmd_rescue=" \
+   "if gpio input 10; then " \
+   "run bootcmd_usb0;" \
+   "fi;\0"
+#else
+#define BOOTENV_DEV_RESCUE(devtypeu, devtypel, instance) \
+   "bootcmd_rescue=" \
+   "if test \"${userbutton}\" = \"true\"; then " \
+   "run bootcmd_mmc0; " \
+   "fi;\0"
+#endif
+
+#define BOOTENV_DEV_NAME_RESCUE(devtypeu, devtypel, instance) \
+   "rescue "
+
+#ifndef BOOT_TARGET_DEVICES
+#define BOOT_TARGET_DEVICES(func) \
+   func(RESCUE, rescue, na) \
+   func(MMC, mmc, 1) \
+   func(MMC, mmc, 0) \
+   BOOT_TARGET_DEVICES_USB(func) \
+   func(PXE, pxe, na) \
+   func(DHCP, dhcp, na)
+#endif
+
+#include 
+
+#endif /* __JETHUB_CONFIG_H */
-- 
2.30.2



[PATCH 2/3] ARM: amlogic: add JetHub D1/H1 device support

2021-09-19 Thread Vyacheslav Bocharov
Add support for new home automation devices.

JetHome Jethub D1 (http://jethome.ru/jethub-d1) is a home automation controller 
with the following features:
- DIN Rail Mounting case
- Amlogic A113X (ARM Cortex-A53) quad-core up to 1.5GHz
- no video out
- 512Mb/1GB DDR3
- 8/16GB eMMC flash
- 1 x USB 2.0
- 1 x 10/100Mbps ethernet
- WiFi / Bluetooth AMPAK AP6255 (Broadcom BCM43455) IEEE 802.11a/b/g/n/ac, 
Bluetooth 4.2.
- TI CC2538 + CC2592 Zigbee Wireless Module with up to 20dBm output power and 
Zigbee 3.0 support.
- 2 x gpio LEDS
- GPIO user Button
- 1 x 1-Wire
- 2 x RS-485
- 4 x dry contact digital GPIO inputs
- 3 x relay GPIO outputs
- DC source with a voltage of 9 to 56 V / Passive POE

JetHome Jethub H1 (http://jethome.ru/jethub-h1) is a home automation controller 
with the following features:
- Square plastic case
- Amlogic S905W (ARM Cortex-A53) quad-core up to 1.5GHz
- no video out
- 1GB DDR3
- 8/16GB eMMC flash
- 2 x USB 2.0
- 1 x 10/100Mbps ethernet
- WiFi / Bluetooth RTL8822CS IEEE 802.11a/b/g/n/ac, Bluetooth 5.0.
- TI CC2538 + CC2592 Zigbee Wireless Module with up to 20dBm output power and 
Zigbee 3.0 support.
- MicroSD 2.x/3.x/4.x DS/HS cards.
- 1 x gpio LED
- ADC user Button
- DC source 5V microUSB with serial console

Patches from:
- JetHub H1
  https://git.kernel.org/amlogic/c/abfaae24ecf3e7f00508b60fa05e2b6789b8f607
- JetHub D1
  https://git.kernel.org/amlogic/c/8e279fb2903990cc6296ec56b3b80b2f854b6c79

Signed-off-by: Vyacheslav Bocharov 
---
 arch/arm/dts/Makefile |   2 +
 .../arm/dts/meson-axg-jethome-jethub-j100.dts | 361 ++
 .../meson-gxl-s905w-jethome-jethub-j80.dts| 241 
 board/amlogic/jethub-j80/MAINTAINERS  |   6 +
 board/amlogic/jethub-j80/Makefile |   6 +
 board/amlogic/jethub-j80/jethub-j80.c |  68 
 configs/jethub_j100_defconfig |  55 +++
 configs/jethub_j80_defconfig  |  63 +++
 8 files changed, 802 insertions(+)
 create mode 100644 arch/arm/dts/meson-axg-jethome-jethub-j100.dts
 create mode 100644 arch/arm/dts/meson-gxl-s905w-jethome-jethub-j80.dts
 create mode 100644 board/amlogic/jethub-j80/MAINTAINERS
 create mode 100644 board/amlogic/jethub-j80/Makefile
 create mode 100644 board/amlogic/jethub-j80/jethub-j80.c
 create mode 100644 configs/jethub_j100_defconfig
 create mode 100644 configs/jethub_j80_defconfig

diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
index f0160d2dc0..d1893a9812 100644
--- a/arch/arm/dts/Makefile
+++ b/arch/arm/dts/Makefile
@@ -169,10 +169,12 @@ dtb-$(CONFIG_ARCH_MESON) += \
meson-gxl-s905x-libretech-cc-v2.dtb \
meson-gxl-s905x-khadas-vim.dtb \
meson-gxl-s905d-libretech-pc.dtb \
+   meson-gxl-s905w-jethome-jethub-j80.dtb \
meson-gxm-khadas-vim2.dtb \
meson-gxm-s912-libretech-pc.dtb \
meson-gxm-wetek-core2.dtb \
meson-axg-s400.dtb \
+   meson-axg-jethome-jethub-j100.dtb \
meson-g12a-u200.dtb \
meson-g12a-sei510.dtb \
meson-g12b-gtking.dtb \
diff --git a/arch/arm/dts/meson-axg-jethome-jethub-j100.dts 
b/arch/arm/dts/meson-axg-jethome-jethub-j100.dts
new file mode 100644
index 00..5783732dc6
--- /dev/null
+++ b/arch/arm/dts/meson-axg-jethome-jethub-j100.dts
@@ -0,0 +1,361 @@
+// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
+/*
+ * Copyright (c) 2021 Vyacheslav Bocharov 
+ * Copyright (c) 2020 JetHome
+ * Author: Aleksandr Kazantsev 
+ * Author: Alexey Shevelkin 
+ * Author: Vyacheslav Bocharov 
+ */
+
+/dts-v1/;
+
+#include "meson-axg.dtsi"
+#include 
+#include 
+
+/ {
+   compatible = "jethome,jethub-j100", "amlogic,a113d", 
"amlogic,meson-axg";
+   model = "JetHome JetHub J100";
+   aliases {
+   serial0 = _AO;   /* Console */
+   serial1 = _AO_B; /* External UART (Wireless Module) */
+   ethernet0 = 
+   };
+
+   chosen {
+   stdout-path = "serial0:115200n8";
+   };
+
+   /* 1024MB RAM */
+   memory@0 {
+   device_type = "memory";
+   reg = <0x0 0x0 0x0 0x4000>;
+   };
+
+   reserved-memory {
+   linux,cma {
+   size = <0x0 0x40>;
+   };
+   };
+
+   emmc_pwrseq: emmc-pwrseq {
+   compatible = "mmc-pwrseq-emmc";
+   reset-gpios = < BOOT_9 GPIO_ACTIVE_LOW>;
+   };
+
+   vcc_3v3: regulator-vcc_3v3 {
+   compatible = "regulator-fixed";
+   regulator-name = "VCC_3V3";
+   regulator-min-microvolt = <330>;
+   regulator-max-microvolt = <330>;
+   vin-supply = <_3v3>;
+   regulator-always-on;
+   };
+
+   vcc_5v: regulator-vcc_5v {
+   compatible = "regulator-fixed";
+   regulator-n

[PATCH 3/3] ARM: amlogic: add JetHub D1/H1 docs

2021-09-19 Thread Vyacheslav Bocharov
Fix doc/board/amlogic/index.rst:
- Add S905W to S905X column.
- Add JetHub devices to the corresponding columns.
- Fix tabs to spaces for table alignment

Add doc/board/amlogic files:
- jethub-j100.rst
- jethub-j80.rst

Signed-off-by: Vyacheslav Bocharov 
---
 doc/board/amlogic/index.rst   | 128 +++---
 doc/board/amlogic/jethub-j100.rst | 108 +
 doc/board/amlogic/jethub-j80.rst  |  97 ++
 3 files changed, 270 insertions(+), 63 deletions(-)
 create mode 100644 doc/board/amlogic/jethub-j100.rst
 create mode 100644 doc/board/amlogic/jethub-j80.rst

diff --git a/doc/board/amlogic/index.rst b/doc/board/amlogic/index.rst
index 2913ab281a..c18f1b7e71 100644
--- a/doc/board/amlogic/index.rst
+++ b/doc/board/amlogic/index.rst
@@ -10,69 +10,69 @@ An up-do-date matrix is also available on: 
http://linux-meson.com
 
 This matrix concerns the actual source code version.
 
-+---+---+-+--+++-+--+
-|  | S905  | S905X   | S912 | 
A113X  | S905X2 | S922X   | S905X3   |
-|  |   | S805X   | S905D|  
  | S905D2 | A311D   | S905D3   |
-|  |   | |  |  
  | S905Y2 | |  |
-+===+===+=+==+++=+==+
-| Boards   | Odroid-C2 | P212| Khadas 
VIM2  | S400   | U200   | Odroid-N2   | SEI610   |
-|  | Nanopi-K2 | Khadas-VIM  | Libretech-PC |  
  | SEI510 | Khadas-VIM3 | Khadas-VIM3L |
-|  | P200  | LibreTech-CC v1 | WeTek Core2  |  
  || GT-King/Pro | Odroid-C4|
-|  | P201  | LibreTech-AC v2 |  |  
  || GSKing-X| Odroid-HC4   |
-|   |   | |  | 
   || | BananaPi-M5  |
-+---+---+-+--+++-+--+
-| UART | **Yes**   | **Yes** | **Yes**  | 
**Yes**| **Yes**| **Yes** | **Yes**  |
-+---+---+-+--+++-+--+
-| Pinctrl/GPIO | **Yes**   | **Yes** | **Yes**  | 
**Yes**| **Yes**| **Yes** | **Yes**  |
-+---+---+-+--+++-+--+
-| Clock Control| **Yes**   | **Yes** | **Yes**  | 
**Yes**| **Yes**| **Yes** | **Yes**  |
-+---+---+-+--+++-+--+
-| PWM  | **Yes**   | **Yes** | **Yes**  | 
**Yes**| **Yes**| **Yes** | **Yes**  |
-+---+---+-+--+++-+--+
-| Reset Control| **Yes**   | **Yes** | **Yes**  | 
**Yes**| **Yes**| **Yes** | **Yes**  |
-+---+---+-+--+++-+--+
-| Infrared Decoder | No| No  | No   | 
No | No | No  | No   |
-+---+---+-+--+++-+--+
-| Ethernet | **Yes**   | **Yes** | **Yes**  | 
**Yes**| **Yes**| **Yes** | **Yes**  |
-+---+---+-+--+++-+--+
-| Multi-core   | **Yes**   | **Yes** | **Yes**  | 
**Yes**| **Yes**| **Yes** | **Yes**  |
-+---+---+-+--+++-+--+
-| Fuse access  | **Yes**   | **Yes** |**Yes**   
|**Yes** |**Yes** |**Yes**  | **Yes**  |
-+---+---+-+--+++-+--+
-| SPI (FC) | **Yes**   | **Yes** | **Yes**  | 
**Yes**|**Yes** | **Yes

[PATCH 0/3] ARM: meson: add support for JetHub D1/H1

2021-09-19 Thread Vyacheslav Bocharov
Add support for new home automation devices manufactured by JetHome.
Patches prepared for use with the "ARM: meson: Sync Amlogic DT from Linux 5.14" 
patch series by Neil Armstrong

JetHome Jethub D1 (http://jethome.ru/jethub-d1) is a home automation controller 
with the following features:
- DIN Rail Mounting case
- Amlogic A113X (ARM Cortex-A53) quad-core up to 1.5GHz
- no video out
- 512Mb/1GB DDR3
- 8/16GB eMMC flash
- 1 x USB 2.0
- 1 x 10/100Mbps ethernet
- WiFi / Bluetooth AMPAK AP6255 (Broadcom BCM43455) IEEE 802.11a/b/g/n/ac, 
Bluetooth 4.2.
- TI CC2538 + CC2592 Zigbee Wireless Module with up to 20dBm output power and 
Zigbee 3.0 support.
- 2 x gpio LEDS
- GPIO user Button
- 1 x 1-Wire
- 2 x RS-485
- 4 x dry contact digital GPIO inputs
- 3 x relay GPIO outputs
- DC source with a voltage of 9 to 56 V / Passive POE

JetHome Jethub H1 (http://jethome.ru/jethub-h1) is a home automation controller 
with the following features:
- Square plastic case
- Amlogic S905W (ARM Cortex-A53) quad-core up to 1.5GHz
- no video out
- 1GB DDR3
- 8/16GB eMMC flash
- 2 x USB 2.0
- 1 x 10/100Mbps ethernet
- WiFi / Bluetooth RTL8822CS IEEE 802.11a/b/g/n/ac, Bluetooth 5.0.
- TI CC2538 + CC2592 Zigbee Wireless Module with up to 20dBm output power and 
Zigbee 3.0 support.
- MicroSD 2.x/3.x/4.x DS/HS cards.
- 1 x gpio LED
- ADC user Button
- DC source 5V microUSB with serial console

Signed-off-by: Vyacheslav Bocharov 

Vyacheslav Bocharov (3):
  ARM: amlogic: add JetHub common config header
  ARM: amlogic: add JetHub D1/H1 device support
  ARM: amlogic: add JetHub D1/H1 docs

 arch/arm/dts/Makefile |   2 +
 .../arm/dts/meson-axg-jethome-jethub-j100.dts | 361 ++
 .../meson-gxl-s905w-jethome-jethub-j80.dts| 241 
 board/amlogic/jethub-j80/MAINTAINERS  |   6 +
 board/amlogic/jethub-j80/Makefile |   6 +
 board/amlogic/jethub-j80/jethub-j80.c |  68 
 configs/jethub_j100_defconfig |  55 +++
 configs/jethub_j80_defconfig  |  63 +++
 doc/board/amlogic/index.rst   | 128 ---
 doc/board/amlogic/jethub-j100.rst | 108 ++
 doc/board/amlogic/jethub-j80.rst  |  97 +
 include/configs/jethub.h  |  40 ++
 12 files changed, 1112 insertions(+), 63 deletions(-)
 create mode 100644 arch/arm/dts/meson-axg-jethome-jethub-j100.dts
 create mode 100644 arch/arm/dts/meson-gxl-s905w-jethome-jethub-j80.dts
 create mode 100644 board/amlogic/jethub-j80/MAINTAINERS
 create mode 100644 board/amlogic/jethub-j80/Makefile
 create mode 100644 board/amlogic/jethub-j80/jethub-j80.c
 create mode 100644 configs/jethub_j100_defconfig
 create mode 100644 configs/jethub_j80_defconfig
 create mode 100644 doc/board/amlogic/jethub-j100.rst
 create mode 100644 doc/board/amlogic/jethub-j80.rst
 create mode 100644 include/configs/jethub.h

-- 
2.30.2



[PATCH 1/3] ARM: amlogic: add JetHub common config header

2021-09-19 Thread Vyacheslav Bocharov
JetHub devices uses its own boot sequence with "rescue" button.
Add custom config header file that corrects boot order.

Signed-off-by: Vyacheslav Bocharov 
---
 include/configs/jethub.h | 40 
 1 file changed, 40 insertions(+)
 create mode 100644 include/configs/jethub.h

diff --git a/include/configs/jethub.h b/include/configs/jethub.h
new file mode 100644
index 00..09264f91a5
--- /dev/null
+++ b/include/configs/jethub.h
@@ -0,0 +1,40 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Configuration for JetHome devices
+ * Copyright (C) 2021 Vyacheslav Bocharov
+ * Author: Vyacheslav Bocharov 
+ */
+
+#ifndef __JETHUB_CONFIG_H
+#define __JETHUB_CONFIG_H
+
+#if defined(CONFIG_MESON_AXG)
+#define BOOTENV_DEV_RESCUE(devtypeu, devtypel, instance) \
+   "bootcmd_rescue=" \
+   "if gpio input 10; then " \
+   "run bootcmd_usb0;" \
+   "fi;\0"
+#else
+#define BOOTENV_DEV_RESCUE(devtypeu, devtypel, instance) \
+   "bootcmd_rescue=" \
+   "if test \"${userbutton}\" = \"true\"; then " \
+   "run bootcmd_mmc0; " \
+   "fi;\0"
+#endif
+
+#define BOOTENV_DEV_NAME_RESCUE(devtypeu, devtypel, instance) \
+   "rescue "
+
+#ifndef BOOT_TARGET_DEVICES
+#define BOOT_TARGET_DEVICES(func) \
+   func(RESCUE, mmc, 1) \
+   func(MMC, mmc, 1) \
+   func(MMC, mmc, 0) \
+   BOOT_TARGET_DEVICES_USB(func) \
+   func(PXE, pxe, na) \
+   func(DHCP, dhcp, na)
+#endif
+
+#include 
+
+#endif /* __JETHUB_CONFIG_H */
-- 
2.30.2



Re: [PATCH v3 02/10] usb: dwc3: meson-gxl: add AXG compatible

2021-09-18 Thread Vyacheslav

Tested-by: Vyacheslav Bocharov 

17.09.2021 10:37, Neil Armstrong пишет:

Upstream Linux uses the "amlogic,meson-axg-usb-ctrl" for AXG SoCs.

This adds it to the compatible list for this driver.

Reported-by: Vyacheslav Bocharov 
Signed-off-by: Neil Armstrong 
---
  drivers/usb/dwc3/dwc3-meson-gxl.c | 1 +
  1 file changed, 1 insertion(+)

diff --git a/drivers/usb/dwc3/dwc3-meson-gxl.c 
b/drivers/usb/dwc3/dwc3-meson-gxl.c
index 08467d6210..b8f3886173 100644
--- a/drivers/usb/dwc3/dwc3-meson-gxl.c
+++ b/drivers/usb/dwc3/dwc3-meson-gxl.c
@@ -409,6 +409,7 @@ static int dwc3_meson_gxl_remove(struct udevice *dev)
  }
  
  static const struct udevice_id dwc3_meson_gxl_ids[] = {

+   { .compatible = "amlogic,meson-axg-usb-ctrl" },
{ .compatible = "amlogic,meson-gxl-usb-ctrl" },
{ .compatible = "amlogic,meson-gxm-usb-ctrl" },
{ }


Re: [PATCH v2 1/9] ARM: meson: Sync Amlogic DT from Linux 5.14

2021-09-15 Thread Vyacheslav

08.09.2021 17:17, Neil Armstrong via groups.io wrote:

diff --git a/arch/arm/dts/meson-axg.dtsi b/arch/arm/dts/meson-axg.dtsi
index b9efc84692..3f5254eeb4 100644
--- a/arch/arm/dts/meson-axg.dtsi
+++ b/arch/arm/dts/meson-axg.dtsi

...

+
+   usb: usb@ffe09080 {
+   compatible = "amlogic,meson-axg-usb-ctrl";
+   reg = <0x0 0xffe09080 0x0 0x20>;
+   interrupts = ;
+   #address-cells = <2>;


Hi.
I have looked through the dts for axg and found that a usb node use 
"amlogic,meson-axg-usb-ctrl" that is not supported in uboot. In 
linux-kernel it exists in drivers/usb/dwc3/dwc3-meson-g12a.c

In previous dts usb node used amlogic,meson-gxl-usb-ctrl and it worked good.