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.

Signed-off-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Jerome Forissier <jerome@forissier.org>
This commit is contained in:
Tom Rini
2025-12-25 09:37:21 -06:00
committed by Jerome Forissier
parent f916c819a3
commit c832cd3b49

View File

@@ -22,6 +22,15 @@
DECLARE_GLOBAL_DATA_PTR; 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 # */ /* Well known TFTP port # */
#define WELL_KNOWN_PORT 69 #define WELL_KNOWN_PORT 69
/* Millisecs to timeout for lost pkt */ /* Millisecs to timeout for lost pkt */
@@ -95,7 +104,7 @@ static ushort tftp_windowsize;
static ushort tftp_next_ack; static ushort tftp_next_ack;
/* Last nack block we send */ /* Last nack block we send */
static ushort tftp_last_nack; static ushort tftp_last_nack;
#ifdef CONFIG_CMD_TFTPPUT #ifdef CMD_TFTPPUT
/* 1 if writing, else 0 */ /* 1 if writing, else 0 */
static int tftp_put_active; static int tftp_put_active;
/* 1 if we have sent the last block */ /* 1 if we have sent the last block */
@@ -183,13 +192,13 @@ static void new_transfer(void)
tftp_prev_block = 0; tftp_prev_block = 0;
tftp_block_wrap = 0; tftp_block_wrap = 0;
tftp_block_wrap_offset = 0; tftp_block_wrap_offset = 0;
#ifdef CONFIG_CMD_TFTPPUT #ifdef CMD_TFTPPUT
tftp_put_final_block_sent = 0; tftp_put_final_block_sent = 0;
#endif #endif
led_activity_blink(); led_activity_blink();
} }
#ifdef CONFIG_CMD_TFTPPUT #ifdef CMD_TFTPPUT
/** /**
* Load the next block from memory to be sent over tftp. * Load the next block from memory to be sent over tftp.
* *
@@ -329,7 +338,7 @@ static void tftp_send(void)
case STATE_SEND_WRQ: case STATE_SEND_WRQ:
xp = pkt; xp = pkt;
s = (ushort *)pkt; s = (ushort *)pkt;
#ifdef CONFIG_CMD_TFTPPUT #ifdef CMD_TFTPPUT
*s++ = htons(tftp_state == STATE_SEND_RRQ ? TFTP_RRQ : *s++ = htons(tftp_state == STATE_SEND_RRQ ? TFTP_RRQ :
TFTP_WRQ); TFTP_WRQ);
#else #else
@@ -372,7 +381,7 @@ static void tftp_send(void)
s[0] = htons(TFTP_ACK); s[0] = htons(TFTP_ACK);
s[1] = htons(tftp_cur_block); s[1] = htons(tftp_cur_block);
pkt = (uchar *)(s + 2); pkt = (uchar *)(s + 2);
#ifdef CONFIG_CMD_TFTPPUT #ifdef CMD_TFTPPUT
if (tftp_put_active) { if (tftp_put_active) {
int toload = tftp_block_size; int toload = tftp_block_size;
int loaded = load_block(tftp_cur_block, pkt, toload); int loaded = load_block(tftp_cur_block, pkt, toload);
@@ -437,7 +446,7 @@ static void tftp_send(void)
net_set_state(NETLOOP_FAIL); net_set_state(NETLOOP_FAIL);
} }
#ifdef CONFIG_CMD_TFTPPUT #ifdef CMD_TFTPPUT
static void icmp_handler(unsigned type, unsigned code, unsigned dest, static void icmp_handler(unsigned type, unsigned code, unsigned dest,
struct in_addr sip, unsigned src, uchar *pkt, struct in_addr sip, unsigned src, uchar *pkt,
unsigned len) unsigned len)
@@ -476,7 +485,7 @@ static void tftp_handler(uchar *pkt, unsigned dest, struct in_addr sip,
break; break;
case TFTP_ACK: case TFTP_ACK:
#ifdef CONFIG_CMD_TFTPPUT #ifdef CMD_TFTPPUT
if (tftp_put_active) { if (tftp_put_active) {
timeout_count = 0; timeout_count = 0;
if (tftp_put_final_block_sent) { 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; tftp_next_ack = tftp_windowsize;
#ifdef CONFIG_CMD_TFTPPUT #ifdef CMD_TFTPPUT
if (tftp_put_active && tftp_state == STATE_OACK) { if (tftp_put_active && tftp_state == STATE_OACK) {
/* Get ready to send the first block */ /* Get ready to send the first block */
tftp_state = STATE_DATA; tftp_state = STATE_DATA;
@@ -854,7 +863,7 @@ void tftp_start(enum proto_t protocol)
tftp_block_size_option = TFTP_MTU_BLOCKSIZE6; tftp_block_size_option = TFTP_MTU_BLOCKSIZE6;
} else { } else {
printf("TFTP %s server %pI4; our IP address is %pI4", printf("TFTP %s server %pI4; our IP address is %pI4",
#ifdef CONFIG_CMD_TFTPPUT #ifdef CMD_TFTPPUT
protocol == TFTPPUT ? "to" : "from", protocol == TFTPPUT ? "to" : "from",
#else #else
"from", "from",
@@ -888,7 +897,7 @@ void tftp_start(enum proto_t protocol)
} }
putc('\n'); putc('\n');
#ifdef CONFIG_CMD_TFTPPUT #ifdef CMD_TFTPPUT
tftp_put_active = (protocol == TFTPPUT); tftp_put_active = (protocol == TFTPPUT);
if (tftp_put_active) { if (tftp_put_active) {
printf("Save address: 0x%lx\n", image_save_addr); 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_timeout_handler(timeout_ms, tftp_timeout_handler);
net_set_udp_handler(tftp_handler); net_set_udp_handler(tftp_handler);
#ifdef CONFIG_CMD_TFTPPUT #ifdef CMD_TFTPPUT
net_set_icmp_handler(icmp_handler); net_set_icmp_handler(icmp_handler);
#endif #endif
tftp_remote_port = WELL_KNOWN_PORT; tftp_remote_port = WELL_KNOWN_PORT;