net: tftpput: Rework to exclude code from xPL phases
PATCH 1/1 net: tftpput: Rework to exclude code from xPL phases
Given how the support for CONFIG_CMD_TFTPPUT is woven through the support for the tftp protocol we currently end up including "put" support in xPL phases, if enabled. This in turn can lead to size overflow on those platforms as xPL tends to be constrained. To resolve this, use "CMD_TFTPPUT" in the code to check for both CONFIG_CMD_TFTPPUT being true and not being in an xPL build phase.
---
Cc: Jerome Forissier <[email protected]>
--- net/tftp.c | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-)
net/tftp.c +20 -11
@@ -22,6 +22,15 @@DECLARE_GLOBAL_DATA_PTR ; +/* +* We cannot use the 'tftpput' command in xPL phases. Given how the +* support is integrated in the code, this is how we disable that support +* in xPL. +*/ +#if defined(CONFIG_CMD_TFTPPUT ) && !defined(CONFIG_XPL_BUILD ) +#define CMD_TFTPPUT +#endif +/* Well known TFTP port # */ #define WELL_KNOWN_PORT 69/* Millisecs to timeout for lost pkt */
@@ -95,7 +104,7 @@ static ushort tftp_windowsize;static ushort tftp_next_ack;/* Last nack block we send */ static ushort tftp_last_nack; -#ifdef CONFIG_CMD_TFTPPUT +#ifdef CMD_TFTPPUT /* 1 if writing, else 0 */ static int tftp_put_active;/* 1 if we have sent the last block */
@@ -183,13 +192,13 @@ static void new_transfer(void) tftp_prev_block =0 ; tftp_block_wrap =0 ; tftp_block_wrap_offset =0 ; -#ifdef CONFIG_CMD_TFTPPUT +#ifdef CMD_TFTPPUT tftp_put_final_block_sent =0 ;#endif led_activity_blink (); } -#ifdef CONFIG_CMD_TFTPPUT +#ifdef CMD_TFTPPUT /** * Load the next block from memory to be sent over tftp. *
@@ -329,7 +338,7 @@ static void tftp_send(void)case STATE_SEND_WRQ : xp = pkt; s = (ushort *)pkt; -#ifdef CONFIG_CMD_TFTPPUT +#ifdef CMD_TFTPPUT *s++ =htons (tftp_state ==STATE_SEND_RRQ ?TFTP_RRQ :TFTP_WRQ );#else
@@ -372,7 +381,7 @@ static void tftp_send(void) s[0 ] =htons (TFTP_ACK ); s[1 ] =htons (tftp_cur_block); pkt = (uchar *)(s +2 ); -#ifdef CONFIG_CMD_TFTPPUT +#ifdef CMD_TFTPPUT if (tftp_put_active) {int toload = tftp_block_size;int loaded =load_block (tftp_cur_block, pkt, toload);
@@ -437,7 +446,7 @@ static void tftp_send(void)net_set_state (NETLOOP_FAIL ); } -#ifdef CONFIG_CMD_TFTPPUT +#ifdef CMD_TFTPPUT static void icmp_handler (unsigned type,unsigned code,unsigned dest,struct in_addr sip,unsigned src,uchar *pkt,unsigned len)
@@ -476,7 +485,7 @@ static void tftp_handler(uchar *pkt, unsigned dest, struct in_addr sip,break ;case TFTP_ACK : -#ifdef CONFIG_CMD_TFTPPUT +#ifdef CMD_TFTPPUT if (tftp_put_active) { timeout_count =0 ;if (tftp_put_final_block_sent) {
@@ -578,7 +587,7 @@ static void tftp_handler(uchar *pkt, unsigned dest, struct in_addr sip, tftp_next_ack = tftp_windowsize; -#ifdef CONFIG_CMD_TFTPPUT +#ifdef CMD_TFTPPUT if (tftp_put_active && tftp_state ==STATE_OACK ) {/* Get ready to send the first block */ tftp_state =STATE_DATA ;
@@ -854,7 +863,7 @@ void tftp_start(enum proto_t protocol) tftp_block_size_option =TFTP_MTU_BLOCKSIZE6 ; }else { printf("TFTP %s server %pI4; our IP address is %pI4", -#ifdef CONFIG_CMD_TFTPPUT +#ifdef CMD_TFTPPUT protocol ==TFTPPUT ?"to" :"from" , #else "from",
@@ -888,7 +897,7 @@ void tftp_start(enum proto_t protocol) }putc ('\n' ); -#ifdef CONFIG_CMD_TFTPPUT +#ifdef CMD_TFTPPUT tftp_put_active = (protocol ==TFTPPUT );if (tftp_put_active) {printf ("Save address: 0x%lx\n" , image_save_addr);
@@ -911,7 +920,7 @@ void tftp_start(enum proto_t protocol)net_set_timeout_handler (timeout_ms, tftp_timeout_handler);net_set_udp_handler (tftp_handler); -#ifdef CONFIG_CMD_TFTPPUT +#ifdef CMD_TFTPPUT net_set_icmp_handler (icmp_handler);#endif tftp_remote_port =WELL_KNOWN_PORT ;
Signature · 1 line
2.43.0
Hi Tom,
Quoted 10 lines · Tom Rini
Given how the support for
CONFIG_CMD_TFTPPUTis woven through the support for the tftp protocol we currently end up including "put" support in xPL phases, if enabled. This in turn can lead to size overflow on those platforms as xPL tends to be constrained. To resolve this, use "CMD_TFTPPUT" in the code to check for bothCONFIG_CMD_TFTPPUTbeing true and not being in an xPL build phase.Signed-off-by Tom Rini <[email protected]>---
Cc: Jerome Forissier <[email protected]>
From now on, and pending discussions with my new employer, I'd rather use my personal email ([email protected]) for open source contributions. I've sent a patch to update MAINTAINERS and .mailmap [1].
[1] https://lists.denx.de/pipermail/u-boot/2026-January/606610.html
Quoted 3 lines
--- net/tftp.c | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-)
Thanks,
Signature · 1 line
Jerome
Quoted 10 lines · Jerome Forissier
Hi Tom,
Quoted 7 lines · Tom Rini
Given how the support for
CONFIG_CMD_TFTPPUTis woven through the support for the tftp protocol we currently end up including "put" support in xPL phases, if enabled. This in turn can lead to size overflow on those platforms as xPL tends to be constrained. To resolve this, use "CMD_TFTPPUT" in the code to check for bothCONFIG_CMD_TFTPPUTbeing true and not being in an xPL build phase.
Quoted 7 lines
Quoted 3 lines
Signed-off-by Tom Rini <[email protected]>---
Cc: Jerome Forissier <[email protected]>From now on, and pending discussions with my new employer, I'd rather use my personal email ([email protected]) for open source contributions. I've sent a patch to update
MAINTAINERSand .mailmap [1].
Understood, thanks! I wasn't sure what was valid yet and didn't want this missed.
Signature · 1 line
Tom
Hi Tom,
Quoted 21 lines · Tom Rini
Given how the support for
CONFIG_CMD_TFTPPUTis woven through the support for the tftp protocol we currently end up including "put" support in xPL phases, if enabled. This in turn can lead to size overflow on those platforms as xPL tends to be constrained. To resolve this, use "CMD_TFTPPUT" in the code to check for bothCONFIG_CMD_TFTPPUTbeing true and not being in an xPL build phase.Signed-off-by Tom Rini <[email protected]>---
Cc: Jerome Forissier <[email protected]>--- net/tftp.c | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-)net/tftp.c +0
-0@@ -22,6 +22,15 @@DECLARE_GLOBAL_DATA_PTR ;
net/tftp.c line 33
Quoted 10 lines
net/tftp.c +9
-0+/* +* We cannot use the 'tftpput' command in xPL phases. Given how the +* support is integrated in the code, this is how we disable that support +* in xPL. +*/ +#if defined(CONFIG_CMD_TFTPPUT ) && !defined(CONFIG_XPL_BUILD ) +#define CMD_TFTPPUT +#endif +
Doesn't
#if CONFIG_IS_ENABLED(CMD_TFTPPUT)
work?
Of course, CONFIG_SPL_CMD_TFTPPUT, TPL_, VPL_, ... will never exist, so that should tackle it properly and be more consistent with the reset of the (recent) code base?
Cheers,
Quentin
Quoted 35 lines · Quentin Schulz
Hi Tom,
Quoted 19 lines · Tom Rini
Given how the support for
CONFIG_CMD_TFTPPUTis woven through the support for the tftp protocol we currently end up including "put" support in xPL phases, if enabled. This in turn can lead to size overflow on those platforms as xPL tends to be constrained. To resolve this, use "CMD_TFTPPUT" in the code to check for bothCONFIG_CMD_TFTPPUTbeing true and not being in an xPL build phase.Signed-off-by Tom Rini <[email protected]>---
Cc: Jerome Forissier <[email protected]>--- net/tftp.c | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-)net/tftp.c +0
-0net/tftp.c line 31
Quoted 10 lines
net/tftp.c +9
-0@@ -22,6 +22,15 @@DECLARE_GLOBAL_DATA_PTR ; +/* +* We cannot use the 'tftpput' command in xPL phases. Given how the +* support is integrated in the code, this is how we disable that support +* in xPL. +*/ +#if defined(CONFIG_CMD_TFTPPUT ) && !defined(CONFIG_XPL_BUILD ) +#define CMD_TFTPPUT +#endif +Doesn't
Quoted 7 lines
#if
CONFIG_IS_ENABLED(CMD_TFTPPUT)work?
Of course,
CONFIG_SPL_CMD_TFTPPUT,TPL_,VPL_, ... will never exist, so that should tackle it properly and be more consistent with the reset of the (recent) code base?
That probably works too but is getting too clever and obfuscates the problem I feel. It makes a certain amount of sense to use *IS_ENABLED macros in the more recent portions of the code base where we've more generally split cmd processing from protocol implementation as well more cleanly sharing code between phases, but here I prefer something more clear especially since for CMD it really should never be valid in xPL phases, but I think we still do end up with a funny spot or two.
Signature · 1 line
Tom