Re: fitimage: Allow match against config node name

2022-09-16 Thread Ahmad Fatoum
Hello Hans,

On 16.09.22 15:36, Hans Christian Lønstad wrote:
> Support fitimage configuration nodes without populated compatible fields
> 
> Yocto fit image recipe does not populate the compatible field
> in the generated ITS file configuration nodes.
> Barebox is thus only able to load the default configuration
> preventing the use of variant based bootloader update bundles.
> 
> If the compatible match fails, fall through using a global
> variable boot.fitnode allowing a match against the configuration
> node name.
> 
> This allows variant boards to pick the correct configuration.

Thanks for your patch.

> 
> ---
> common/image-fit.c | 18 ++
> 1 file changed, 18 insertions(+)
> 
> diff --git a/common/image-fit.c b/common/image-fit.c
> index a410632d70..f92e813a8b 100644
> --- a/common/image-fit.c
> +++ b/common/image-fit.c
> @@ -7,6 +7,7 @@
> 
> #define pr_fmt(fmt) "FIT: " fmt
> #include 
> +#include 
> #include 
> #include 
> #include 
> @@ -663,6 +664,7 @@ static int fit_find_compatible_unit(struct device_node 
> *conf_node,
> struct device_node *barebox_root;
> const char *machine;
> int ret;
> + const char *config_node;
> 
> barebox_root = of_get_root_node();
> if (!barebox_root)
> @@ -680,6 +682,22 @@ static int fit_find_compatible_unit(struct device_node 
> *conf_node,
> }
> }
> 
> + /*
> + * If the match against compatible in config node does not match
> + * (or is missing as in Yocto fitimage recipe)
> + * check for matching node name using global.boot.fitnode
> + */
> + config_node = getenv("global.boot.fitnode");
> + if (config_node) {
> + for_each_child_of_node (conf_node, child) {
> + if (strcmp(child->name, config_node) == 0) {
> + *unit = child->name;
> + pr_info("matching node name unit '%s' found\n", *unit);
> + return 0;
> + }
> + }
> + }

Whitespace is broken (git send-email normally does the correct thing).

But are you aware that you can have your boot-target like:

bootm /dev/mmc0.fit@configuration1

and that configuration1 will be chosen? Does this already cover
your use case? If it does, a documentation patch adding this
information at the place where you didn't find it is surely
a welcome alternate contribution. ;)

(also generally speaking magicvars need to be documented with
 BAREBOX_MAGICVAR).

Cheers,
Ahmad


> +
> default_unit:
> pr_info("No match found. Trying default.\n");
> if (of_property_read_string(conf_node, "default", unit) == 0)


-- 
Pengutronix e.K.   | |
Steuerwalder Str. 21   | http://www.pengutronix.de/  |
31137 Hildesheim, Germany  | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |



fitimage: Allow match against config node name

2022-09-16 Thread Hans Christian Lønstad
Support fitimage configuration nodes without populated compatible fields

Yocto fit image recipe does not populate the compatible field
in the generated ITS file configuration nodes.
Barebox is thus only able to load the default configuration
preventing the use of variant based bootloader update bundles.

If the compatible match fails, fall through using a global
variable boot.fitnode allowing a match against the configuration
node name.

This allows variant boards to pick the correct configuration.

---
common/image-fit.c | 18 ++
1 file changed, 18 insertions(+)

diff --git a/common/image-fit.c b/common/image-fit.c
index a410632d70..f92e813a8b 100644
--- a/common/image-fit.c
+++ b/common/image-fit.c
@@ -7,6 +7,7 @@

#define pr_fmt(fmt) "FIT: " fmt
#include 
+#include 
#include 
#include 
#include 
@@ -663,6 +664,7 @@ static int fit_find_compatible_unit(struct device_node 
*conf_node,
struct device_node *barebox_root;
const char *machine;
int ret;
+ const char *config_node;

barebox_root = of_get_root_node();
if (!barebox_root)
@@ -680,6 +682,22 @@ static int fit_find_compatible_unit(struct device_node 
*conf_node,
}
}

+ /*
+ * If the match against compatible in config node does not match
+ * (or is missing as in Yocto fitimage recipe)
+ * check for matching node name using global.boot.fitnode
+ */
+ config_node = getenv("global.boot.fitnode");
+ if (config_node) {
+ for_each_child_of_node (conf_node, child) {
+ if (strcmp(child->name, config_node) == 0) {
+ *unit = child->name;
+ pr_info("matching node name unit '%s' found\n", *unit);
+ return 0;
+ }
+ }
+ }
+
default_unit:
pr_info("No match found. Trying default.\n");
if (of_property_read_string(conf_node, "default", unit) == 0)
-- 
2.34.1


Re: [PATCH 2/3] tftp: implement UDP reorder cache using lists

2022-09-16 Thread Enrico Scholz
Sascha Hauer  writes:

> The UDP reorder cache can be much easier implemented using lists.
> As a bonus the cache grows and shrinks on demand and no fixed size
> has to be configured at compile time.

There are three variants of the cache

- small, fixed sized array with linear search (very first
  implementation)  -->  O(n)
- list --> O(n) on insert, O(1) on lookup
- bitmap --> O(1)


Performance wise, I think the list implementation is the slowest one
(although the fixed sized array is O(n) on every operation, this should
be still faster for small n than the list operations and the related
memory management).

>From code size, the list implementation is in the middle.

I am not sure whether dynamic shrinking/growing of the cache is so
important or whether a small, fixed sized cache suffices.  In my
experience, only the first couple of packets really matter regarding
reordering.

Of course, the 'kfifo' could be replaced completely by a custom buffer
implementation where packets are inserted at the correct position.  O(1)
for every operation + zero additional memory.


> -static inline bool is_block_before(uint16_t a, uint16_t b)
> -{
> - return (int16_t)(b - a) > 0;
> -}
> -
> 
>  static int tftp_window_cache_insert(struct tftp_cache *cache, uint16_t id,
>   void const *data, size_t len)
>  {
> ...
> + list_for_each_entry(block, >blocks, list) {

fwiw, iterating in the reverse direction will find the position probably
faster


> + if (block->id == id)
> + return 0;
> + if (block->id < id)

This will break when wrapping at 65535; the removed 'is_block_before()'
function was written for this case.


> @@ -614,12 +431,26 @@ static void tftp_apply_window_cache(struct file_priv 
> *priv)
>   if (priv->state != STATE_RDATA)
>   return;
>  
> - block = tftp_window_cache_pop(cache);
> + if (list_empty(>blocks))
> + return;
>  
> - debug_assert(block);
> - debug_assert(block->id == (uint16_t)(priv->last_block + 1));
> + block = list_first_entry(>blocks, struct tftp_block, 
> list);
> +
> + if (block->id < priv->last_block + 1) {

ditto; wrapping at 65535


> + /* shouldn't happen, but be sure */
> + list_del(>list);
> + free(block);
> + continue;
> + }
> +
> + if (block->id != priv->last_block + 1)

ditto; wrapping at 65535.  Resp. should be written as

|   if (block->id != (uint16_t)(priv->last_block + 1))



Enrico



Re: [PATCH] net: Bring up all interfaces before going interactive

2022-09-16 Thread Sascha Hauer
On Fri, Sep 16, 2022 at 02:49:42PM +0200, Sascha Hauer wrote:
> So far we only bring up network interfaces when we actually need them.
> This means we could be idling in the shell for long and once the user
> decides to do networking he has to wait for the link to be established.
> We can do better: Before going interactive bring up all known network
> interfaces which makes the links established when the user needs them.
> 
> To implement this we have to rework carrier checking a bit, because
> otherwise barebox would wait for the links to be established before
> dropping to the shell.
> 
> Signed-off-by: Sascha Hauer 
> ---
>  common/startup.c |  3 +++
>  include/net.h|  3 +++
>  net/eth.c| 34 +-
>  3 files changed, 27 insertions(+), 13 deletions(-)
> 
> diff --git a/common/startup.c b/common/startup.c
> index f53b73f81a..f63a0ae7d5 100644
> --- a/common/startup.c
> +++ b/common/startup.c
> @@ -37,6 +37,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
>  
>  extern initcall_t __barebox_initcalls_start[], 
> __barebox_early_initcalls_end[],
> @@ -208,6 +209,8 @@ enum autoboot_state do_autoboot_countdown(void)
>   );
>   command_slice_acquire();
>  
> + eth_open_all();
> +

We could make the user experience even a bit better by doing this call
before waiting for the autoboot timeout which then speeds up netboot a
bit.

Sascha

-- 
Pengutronix e.K.   | |
Steuerwalder Str. 21   | http://www.pengutronix.de/  |
31137 Hildesheim, Germany  | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |



[PATCH 1/3] tftp: remove selftest

2022-09-16 Thread Sascha Hauer
The out-of-order packet caching will be reworked in the next commit and
most of the functions the self test tests will vanish, so nothing to
test anymore.

Signed-off-by: Sascha Hauer 
---
 fs/tftp.c | 102 --
 test/self/Kconfig |   7 
 2 files changed, 109 deletions(-)

diff --git a/fs/tftp.c b/fs/tftp.c
index e0886c49d2..f089e2f693 100644
--- a/fs/tftp.c
+++ b/fs/tftp.c
@@ -1237,105 +1237,3 @@ static int tftp_init(void)
return register_fs_driver(_driver);
 }
 coredevice_initcall(tftp_init);
-
-
-BSELFTEST_GLOBALS();
-
-static int __maybe_unused tftp_window_cache_selftest(void)
-{
-   struct tftp_cache   *cache = malloc(sizeof *cache);
-
-   if (!cache)
-   return -ENOMEM;
-
-   (void)skipped_tests;
-
-   expect_it( is_block_before(0, 1));
-   expect_it(!is_block_before(1, 0));
-   expect_it( is_block_before(65535, 0));
-   expect_it(!is_block_before(0, 65535));
-
-   expect_eq(get_block_delta(0, 1), 1);
-   expect_eq(get_block_delta(65535, 0), 1);
-   expect_eq(get_block_delta(65535, 1), 2);
-
-   expect_it(!in_window(0, 1, 3));
-   expect_it( in_window(1, 1, 3));
-   expect_it( in_window(2, 1, 3));
-   expect_it( in_window(3, 1, 3));
-   expect_it(!in_window(4, 1, 3));
-
-   expect_it(!in_window(65534, 65535, 1));
-   expect_it( in_window(65535, 65535, 1));
-   expect_it( in_window(0, 65535, 1));
-   expect_it( in_window(1, 65535, 1));
-   expect_it(!in_window(2, 65535, 1));
-
-
-   tftp_window_cache_init(cache, 512, 5);
-
-   if (tftp_window_cache_size(cache) < 4)
-   goto out;
-
-   expect_eq(tftp_window_cache_size(cache), 4);
-
-   /* sequence 1 */
-   expect_ok (tftp_window_cache_insert(cache, 20, "20", 2));
-   expect_ok (tftp_window_cache_insert(cache, 22, "22", 2));
-   expect_ok (tftp_window_cache_insert(cache, 21, "21", 2));
-   expect_ok (tftp_window_cache_insert(cache, 23, "23", 2));
-   expect_err(tftp_window_cache_insert(cache, 24, "24", 2));
-   expect_err(tftp_window_cache_insert(cache, 19, "19", 2));
-   expect_ok (tftp_window_cache_insert(cache, 22, "22", 2));
-   expect_ok (tftp_window_cache_insert(cache, 20, "20", 2));
-
-   expect_eq(tftp_window_cache_pop(cache)->id, 20);
-   expect_eq(tftp_window_cache_pop(cache)->id, 21);
-   expect_eq(tftp_window_cache_pop(cache)->id, 22);
-   expect_eq(tftp_window_cache_pop(cache)->id, 23);
-   expect_eq(cache->id, TFTP_CACHE_NO_ID);
-
-   /* sequence 2 */
-   expect_ok (tftp_window_cache_insert(cache, 30, "30", 2));
-   expect_ok (tftp_window_cache_insert(cache, 32, "32", 2));
-   expect_err(tftp_window_cache_insert(cache, 34, "34", 2));
-
-   expect_it(tftp_window_cache_starts_with(cache, 30));
-   expect_eq(tftp_window_cache_pop(cache)->id, 30);
-
-   expect_ok (tftp_window_cache_insert(cache, 34, "34", 2));
-   expect_err(tftp_window_cache_insert(cache, 35, "35", 2));
-
-   expect_it(!tftp_window_cache_starts_with(cache, 30));
-   expect_it(!tftp_window_cache_starts_with(cache, 31));
-   expect_it(!tftp_window_cache_starts_with(cache, 32));
-   expect_NULL(tftp_window_cache_pop(cache));
-
-   expect_it(tftp_window_cache_starts_with(cache, 32));
-   expect_eq(tftp_window_cache_pop(cache)->id, 32);
-
-   expect_NULL(tftp_window_cache_pop(cache));
-   expect_eq(tftp_window_cache_pop(cache)->id, 34);
-
-   expect_eq(cache->id, TFTP_CACHE_NO_ID);
-
-   /* sequence 3 */
-   expect_ok(tftp_window_cache_insert(cache, 40, "40", 2));
-   expect_ok(tftp_window_cache_insert(cache, 42, "42", 2));
-   expect_ok(tftp_window_cache_insert(cache, 43, "43", 2));
-
-   expect_it(!tftp_window_cache_remove_id(cache, 30));
-   expect_it(!tftp_window_cache_remove_id(cache, 41));
-   expect_it(!tftp_window_cache_remove_id(cache, 44));
-
-   expect_it( tftp_window_cache_remove_id(cache, 42));
-   expect_it(!tftp_window_cache_remove_id(cache, 42));
-
-out:
-   tftp_window_cache_free(cache);
-
-   return 0;
-}
-#ifdef CONFIG_SELFTEST_TFTP
-bselftest(core, tftp_window_cache_selftest);
-#endif
diff --git a/test/self/Kconfig b/test/self/Kconfig
index 03cfa89987..680196a4fe 100644
--- a/test/self/Kconfig
+++ b/test/self/Kconfig
@@ -32,7 +32,6 @@ config SELFTEST_ENABLE_ALL
select SELFTEST_PROGRESS_NOTIFIER
select SELFTEST_OF_MANIPULATION
select SELFTEST_ENVIRONMENT_VARIABLES if ENVIRONMENT_VARIABLES
-   imply SELFTEST_TFTP
help
  Selects all self-tests compatible with current configuration
 
@@ -58,10 +57,4 @@ config SELFTEST_PROGRESS_NOTIFIER
 config SELFTEST_ENVIRONMENT_VARIABLES
bool "environment variable selftest"
 
-config SELFTEST_TFTP
-   bool "tftp selftest"
-   depends on FS_TFTP
-   help
- Tests tftp functionality
-
 endif
-- 
2.30.2

[PATCH 3/3] net: designware_eqos: Allocate more receive buffers

2022-09-16 Thread Sascha Hauer
With RFC7440 support in TFTP we can make good use of more receive
buffers. Increase the number.

Signed-off-by: Sascha Hauer 
---
 drivers/net/designware_eqos.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/designware_eqos.c b/drivers/net/designware_eqos.c
index 79b9979697..7ff0b8489c 100644
--- a/drivers/net/designware_eqos.c
+++ b/drivers/net/designware_eqos.c
@@ -169,7 +169,7 @@ struct eqos_dma_regs {
 /* We assume ARCH_DMA_MINALIGN >= 16; 16 is the EQOS HW minimum */
 #define EQOS_DESCRIPTOR_ALIGN  64
 #define EQOS_DESCRIPTORS_TX4
-#define EQOS_DESCRIPTORS_RX4
+#define EQOS_DESCRIPTORS_RX64
 #define EQOS_DESCRIPTORS_NUM   (EQOS_DESCRIPTORS_TX + EQOS_DESCRIPTORS_RX)
 #define EQOS_DESCRIPTORS_SIZE  ALIGN(EQOS_DESCRIPTORS_NUM * \
  EQOS_DESCRIPTOR_SIZE, 
EQOS_DESCRIPTOR_ALIGN)
-- 
2.30.2




[PATCH 2/3] tftp: implement UDP reorder cache using lists

2022-09-16 Thread Sascha Hauer
The UDP reorder cache can be much easier implemented using lists.
As a bonus the cache grows and shrinks on demand and no fixed size
has to be configured at compile time.

Signed-off-by: Sascha Hauer 
---
 fs/Kconfig |  22 -
 fs/tftp.c  | 242 -
 2 files changed, 36 insertions(+), 228 deletions(-)

diff --git a/fs/Kconfig b/fs/Kconfig
index cf884e0646..0c49342859 100644
--- a/fs/Kconfig
+++ b/fs/Kconfig
@@ -57,28 +57,6 @@ config FS_TFTP_MAX_WINDOW_SIZE
  Requires tftp "windowsize" (RFC 7440) support on server side
  to have an effect.
 
-config FS_TFTP_REORDER_CACHE_SIZE
-   int
-   prompt "number of out-of-order tftp packets to be cached"
-   depends on FS_TFTP
-   default 16 if FS_TFTP_MAX_WINDOW_SIZE > 16
-   default  0 if FS_TFTP_MAX_WINDOW_SIZE = 1
-## TODO: it should be 'FS_TFTP_MAX_WINDOW_SIZE - 1' but this
-## is not supported by Kconfig
-   default FS_TFTP_MAX_WINDOW_SIZE
-   range 0 FS_TFTP_MAX_WINDOW_SIZE
-   help
- UDP allows reordering of datagrams; with this option,
- unexpected tftp packets will be cached and later
- reassembled.  This increases stability of the tftp download
- with the cost of memory (around 1440 bytes per cache
- element) and barebox binary size (around 700 bytes).
-
- A value of 0 disables caching.
-
- Requires tftp "windowsize" (RFC 7440) support on server side
- to have an effect.
-
 config FS_OMAP4_USBBOOT
bool
prompt "Filesystem over usb boot"
diff --git a/fs/tftp.c b/fs/tftp.c
index f089e2f693..0094825217 100644
--- a/fs/tftp.c
+++ b/fs/tftp.c
@@ -78,9 +78,6 @@
 /* allocate this number of blocks more than needed in the fifo */
 #define TFTP_EXTRA_BLOCKS  2
 
-/* size of cache which deals with udp reordering */
-#define TFTP_WINDOW_CACHE_NUM  CONFIG_FS_TFTP_REORDER_CACHE_SIZE
-
 /* marker for an emtpy 'tftp_cache' */
 #define TFTP_CACHE_NO_ID   (-1)
 
@@ -101,24 +98,12 @@ struct tftp_block {
uint16_t id;
uint16_t len;
 
-   struct list_head head;
+   struct list_head list;
uint8_t data[];
 };
 
 struct tftp_cache {
-   /* The id located at @pos or TFTP_CACHE_NO_ID when cache is empty.  It
-  is possible that the corresponding bit in @used is NOT set. */
-   unsigned intid;
-   unsigned intpos;
-
-   /* bitmask */
-   unsigned long   used[BITS_TO_LONGS(TFTP_WINDOW_CACHE_NUM)];
-
-   /* size of the cache; is limited by TFTP_WINDOW_CACHE_NUM and the
-  actual window size */
-   unsigned intsize;
-   unsigned intblock_len;
-   struct tftp_block   *blocks[TFTP_WINDOW_CACHE_NUM];
+   struct list_headblocks;
 };
 
 struct file_priv {
@@ -145,18 +130,6 @@ struct tftp_priv {
IPaddr_t server;
 };
 
-static inline bool is_block_before(uint16_t a, uint16_t b)
-{
-   return (int16_t)(b - a) > 0;
-}
-
-static inline uint16_t get_block_delta(uint16_t a, uint16_t b)
-{
-   debug_assert(!is_block_before(b, a));
-
-   return b - a;
-}
-
 static bool in_window(uint16_t block, uint16_t start, uint16_t end)
 {
/* handle the three cases:
@@ -169,191 +142,37 @@ static bool in_window(uint16_t block, uint16_t start, 
uint16_t end)
(end   <= start && start <= block));
 }
 
-static inline size_t tftp_window_cache_size(struct tftp_cache const *cache)
-{
-   /* allows to optimize away the cache code when TFTP_WINDOW_CACHE_SIZE
-  is 0 */
-   return TFTP_WINDOW_CACHE_NUM == 0 ? 0 : cache->size;
-}
-
-static void tftp_window_cache_init(struct tftp_cache *cache,
-  uint16_t block_len, uint16_t window_size)
-{
-   debug_assert(window_size > 0);
-
-   *cache = (struct tftp_cache) {
-   .id = TFTP_CACHE_NO_ID,
-   .block_len  = block_len,
-   .size   = min_t(uint16_t, window_size - 1,
-   ARRAY_SIZE(cache->blocks)),
-   };
-}
-
 static void tftp_window_cache_free(struct tftp_cache *cache)
 {
-   size_t  cache_size = tftp_window_cache_size(cache);
-   size_t  i;
+   struct tftp_block *block, *tmp;
 
-   for (i = 0; i < cache_size; ++i) {
-   free(cache->blocks[i]);
-   cache->blocks[i] = NULL;
-   }
-}
-
-static void tftp_window_cache_reset(struct tftp_cache *cache)
-{
-   cache->id = TFTP_CACHE_NO_ID;
-   memset(cache->used, 0, sizeof cache->used);
-}
-
-static int tftp_window_cache_get_pos(struct tftp_cache const *cache, uint16_t 
id)
-{
-   size_t  cache_size = tftp_window_cache_size(cache);
-   unsigned intpos;
-
-   if (cache_size == 0)
-   return -1;
-
-   if (cache->id == TFTP_CACHE_NO_ID)
-   return -1;
-
-   if (!in_window(id, 

[PATCH 0/3] tftp updates

2022-09-16 Thread Sascha Hauer
This series has some updates for the recently introduced RFC7440
support.

Also I found it useful to increase the number of receive packets in the
network driver I am currently using. Other drivers might be adjusted as
well accordingly.

Sascha

Sascha Hauer (3):
  tftp: remove selftest
  tftp: implement UDP reorder cache using lists
  net: designware_eqos: Allocate more receive buffers

 drivers/net/designware_eqos.c |   2 +-
 fs/Kconfig|  22 ---
 fs/tftp.c | 344 --
 test/self/Kconfig |   7 -
 4 files changed, 37 insertions(+), 338 deletions(-)

-- 
2.30.2




[PATCH] net: Bring up all interfaces before going interactive

2022-09-16 Thread Sascha Hauer
So far we only bring up network interfaces when we actually need them.
This means we could be idling in the shell for long and once the user
decides to do networking he has to wait for the link to be established.
We can do better: Before going interactive bring up all known network
interfaces which makes the links established when the user needs them.

To implement this we have to rework carrier checking a bit, because
otherwise barebox would wait for the links to be established before
dropping to the shell.

Signed-off-by: Sascha Hauer 
---
 common/startup.c |  3 +++
 include/net.h|  3 +++
 net/eth.c| 34 +-
 3 files changed, 27 insertions(+), 13 deletions(-)

diff --git a/common/startup.c b/common/startup.c
index f53b73f81a..f63a0ae7d5 100644
--- a/common/startup.c
+++ b/common/startup.c
@@ -37,6 +37,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 extern initcall_t __barebox_initcalls_start[], __barebox_early_initcalls_end[],
@@ -208,6 +209,8 @@ enum autoboot_state do_autoboot_countdown(void)
);
command_slice_acquire();
 
+   eth_open_all();
+
if (ret == 0)
autoboot_state = AUTOBOOT_BOOT;
else if (menu_exists && outkey == 'm')
diff --git a/include/net.h b/include/net.h
index 310bf5169d..338033d698 100644
--- a/include/net.h
+++ b/include/net.h
@@ -79,6 +79,8 @@ struct eth_device {
 #define ETH_MODE_STATIC 1
 #define ETH_MODE_DISABLED 2
unsigned int global_mode;
+
+   uint64_t last_link_check;
 };
 
 #define dev_to_edev(d) container_of(d, struct eth_device, dev)
@@ -109,6 +111,7 @@ int eth_open(struct eth_device *edev);
 void eth_close(struct eth_device *edev);
 int eth_send(struct eth_device *edev, void *packet, int length);  /* 
Send a packet */
 int eth_rx(void);  /* Check for received packets   */
+void eth_open_all(void);
 struct eth_device *of_find_eth_device_by_node(struct device_node *np);
 
 /* associate a MAC address to a ethernet device. Should be called by
diff --git a/net/eth.c b/net/eth.c
index bc641dc8e4..8f6ff7db3a 100644
--- a/net/eth.c
+++ b/net/eth.c
@@ -20,8 +20,6 @@
 #include 
 #include 
 
-static uint64_t last_link_check;
-
 LIST_HEAD(netdev_list);
 
 struct eth_ethaddr {
@@ -173,7 +171,7 @@ int eth_complete(struct string_list *sl, char *instr)
 /*
  * Check for link if we haven't done so for longer.
  */
-static int eth_carrier_check(struct eth_device *edev, int force)
+static int eth_carrier_check(struct eth_device *edev, bool may_wait)
 {
int ret;
 
@@ -183,15 +181,17 @@ static int eth_carrier_check(struct eth_device *edev, int 
force)
if (!edev->phydev)
return 0;
 
-   if (force)
-   phy_wait_aneg_done(edev->phydev);
-
-   if (force || is_timeout(last_link_check, 5 * SECOND) ||
-   !edev->phydev->link) {
+   if (!edev->last_link_check ||
+   is_timeout(edev->last_link_check, 5 * SECOND)) {
ret = phy_update_status(edev->phydev);
if (ret)
return ret;
-   last_link_check = get_time_ns();
+   edev->last_link_check = get_time_ns();
+   }
+
+   if (may_wait && !edev->phydev->link) {
+   phy_wait_aneg_done(edev->phydev);
+   edev->last_link_check = get_time_ns();
}
 
return edev->phydev->link ? 0 : -ENETDOWN;
@@ -237,7 +237,7 @@ int eth_send(struct eth_device *edev, void *packet, int 
length)
if (slice_acquired(eth_device_slice(edev)))
return eth_queue(edev, packet, length);
 
-   ret = eth_carrier_check(edev, 0);
+   ret = eth_carrier_check(edev, true);
if (ret)
return ret;
 
@@ -258,7 +258,7 @@ static void eth_do_work(struct eth_device *edev)
int ret;
 
if (!phy_acquired(edev->phydev)) {
-   ret = eth_carrier_check(edev, 0);
+   ret = eth_carrier_check(edev, false);
if (ret)
return;
}
@@ -455,12 +455,12 @@ int eth_open(struct eth_device *edev)
if (edev->active)
return 0;
 
+   edev->last_link_check = 0;
+
ret = edev->open(edev);
if (!ret)
edev->active = 1;
 
-   eth_carrier_check(edev, 1);
-
return ret;
 }
 
@@ -522,6 +522,14 @@ struct eth_device *of_find_eth_device_by_node(struct 
device_node *np)
 }
 EXPORT_SYMBOL(of_find_eth_device_by_node);
 
+void eth_open_all(void)
+{
+   struct eth_device *edev;
+
+   list_for_each_entry(edev, _list, list)
+   eth_open(edev);
+}
+
 static int of_populate_ethaddr(void)
 {
char str[sizeof("xx:xx:xx:xx:xx:xx")];
-- 
2.30.2




[PATCH] net: Use dma_alloc to allocate net packet

2022-09-16 Thread Sascha Hauer
network packets are often DMAed by the network drivers, so allocate
them with dma_alloc() rather than assuming that an arbitrarily chosen
alignment is sufficient

This fixes network transfers on a Rockchip RK3568 board which
occasionally sent out packets with corrupt data.

Signed-off-by: Sascha Hauer 
---
 include/net.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/include/net.h b/include/net.h
index b50b6e76c8..310bf5169d 100644
--- a/include/net.h
+++ b/include/net.h
@@ -19,6 +19,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -470,7 +471,7 @@ struct net_connection {
 
 static inline char *net_alloc_packet(void)
 {
-   return xmemalign(32, PKTSIZE);
+   return dma_alloc(PKTSIZE);
 }
 
 struct net_connection *net_udp_new(IPaddr_t dest, uint16_t dport,
-- 
2.30.2




Re: [RFC] Documentation/conf.py: fix copyright years

2022-09-16 Thread Antony Pavlov
On Fri, 16 Sep 2022 08:28:43 +0200
Sascha Hauer  wrote:

Hi Sascha!

> On Thu, Sep 15, 2022 at 09:18:20AM +0300, Antony Pavlov wrote:
> > On Mon, 12 Sep 2022 11:46:27 +0300
> > Antony Pavlov  wrote:
> > 
> > Hi Sascha!
> > 
> > Here is the barebox documentation generated in my gitlab CI/CD system with 
> > 'make docs':
> >   
> > https://frantony.gitlab.io/-/barebox/-/jobs/3029093142/artifacts/Documentation/html/index.html
> > 
> > and this is the barebox documentation from barebox.org:
> >   https://www.barebox.org/doc/latest/index.html
> > 
> > The index.html pages look different (different color scheme is used, no 
> > barebox logo in the left top
> > conner after 'make docs' etc).
> > 
> > Could you please publish an instruction how to reproduce barebox html 
> > documentation from barebox.org?
> 
> We have the theme here internally. Sorry, I can't give you any
> instructions on how to reproduce the docs as found on the website.
> What do you need them for?

I want to extend my gitlab.com CI-CD scripts.

-- 
Best regards,
  Antony Pavlov



Re: [RFC] Documentation/conf.py: fix copyright years

2022-09-16 Thread Sascha Hauer
On Mon, Sep 12, 2022 at 11:46:27AM +0300, Antony Pavlov wrote:
> N.B. N-dash is used!
> 
> Signed-off-by: Antony Pavlov 
> ---
>  Documentation/conf.py | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Applied, thanks

Sascha

> 
> diff --git a/Documentation/conf.py b/Documentation/conf.py
> index bcd8633c919..5fb8b07c380 100644
> --- a/Documentation/conf.py
> +++ b/Documentation/conf.py
> @@ -44,7 +44,7 @@ master_doc = 'index'
>  
>  # General information about the project.
>  project = u'barebox'
> -copyright = u'2014, The barebox project'
> +copyright = u'2014–2022, The barebox project'
>  
>  # The version info for the project you're documenting, acts as replacement 
> for
>  # |version| and |release|, also used in various other places throughout the
> -- 
> 2.37.2
> 
> 

-- 
Pengutronix e.K.   | |
Steuerwalder Str. 21   | http://www.pengutronix.de/  |
31137 Hildesheim, Germany  | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |



Re: [RFC] Documentation/conf.py: fix copyright years

2022-09-16 Thread Sascha Hauer
Hi Antony,

On Thu, Sep 15, 2022 at 09:18:20AM +0300, Antony Pavlov wrote:
> On Mon, 12 Sep 2022 11:46:27 +0300
> Antony Pavlov  wrote:
> 
> Hi Sascha!
> 
> Here is the barebox documentation generated in my gitlab CI/CD system with 
> 'make docs':
>   
> https://frantony.gitlab.io/-/barebox/-/jobs/3029093142/artifacts/Documentation/html/index.html
> 
> and this is the barebox documentation from barebox.org:
>   https://www.barebox.org/doc/latest/index.html
> 
> The index.html pages look different (different color scheme is used, no 
> barebox logo in the left top
> conner after 'make docs' etc).
> 
> Could you please publish an instruction how to reproduce barebox html 
> documentation from barebox.org?

We have the theme here internally. Sorry, I can't give you any
instructions on how to reproduce the docs as found on the website.
What do you need them for?

Sascha

-- 
Pengutronix e.K.   | |
Steuerwalder Str. 21   | http://www.pengutronix.de/  |
31137 Hildesheim, Germany  | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |