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:
committed by
Jerome Forissier
parent
f916c819a3
commit
c832cd3b49
31
net/tftp.c
31
net/tftp.c
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user