#include <command.h>
#include <efi_loader.h>
#include <env.h>
+#include <image.h>
+#include <lmb.h>
+#include <log.h>
#include <mapmem.h>
#include <net.h>
#include <net/tftp.h>
* almost-MTU block sizes. At least try... fall back to 512 if need be.
* (but those using CONFIG_IP_DEFRAG may want to set a larger block in cfg file)
*/
-#ifdef CONFIG_TFTP_BLOCKSIZE
-#define TFTP_MTU_BLOCKSIZE CONFIG_TFTP_BLOCKSIZE
-#else
-#define TFTP_MTU_BLOCKSIZE 1468
-#endif
static unsigned short tftp_block_size = TFTP_BLOCK_SIZE;
-static unsigned short tftp_block_size_option = TFTP_MTU_BLOCKSIZE;
+static unsigned short tftp_block_size_option = CONFIG_TFTP_BLOCKSIZE;
static inline int store_block(int block, uchar *src, unsigned int len)
{
void *ptr;
#ifdef CONFIG_LMB
+ ulong end_addr = tftp_load_addr + tftp_load_size;
+
+ if (!end_addr)
+ end_addr = ULONG_MAX;
+
if (store_addr < tftp_load_addr ||
- store_addr + len > tftp_load_addr + tftp_load_size) {
+ store_addr + len > end_addr) {
puts("\nTFTP error: ");
puts("trying to overwrite reserved memory...\n");
return -1;
ulong tosend = len;
tosend = min(net_boot_file_size - offset, tosend);
- (void)memcpy(dst, (void *)(save_addr + offset), tosend);
- debug("%s: block=%d, offset=%ld, len=%d, tosend=%ld\n", __func__,
+ (void)memcpy(dst, (void *)(image_save_addr + offset), tosend);
+ debug("%s: block=%u, offset=%lu, len=%u, tosend=%lu\n", __func__,
block, offset, len, tosend);
return tosend;
}
}
}
-/* Initialize tftp_load_addr and tftp_load_size from load_addr and lmb */
+/* Initialize tftp_load_addr and tftp_load_size from image_load_addr and lmb */
static int tftp_init_load_addr(void)
{
#ifdef CONFIG_LMB
lmb_init_and_reserve(&lmb, gd->bd, (void *)gd->fdt_blob);
- max_size = lmb_get_free_size(&lmb, load_addr);
+ max_size = lmb_get_free_size(&lmb, image_load_addr);
if (!max_size)
return -1;
tftp_load_size = max_size;
#endif
- tftp_load_addr = load_addr;
+ tftp_load_addr = image_load_addr;
return 0;
}
#ifdef CONFIG_CMD_TFTPPUT
tftp_put_active = (protocol == TFTPPUT);
if (tftp_put_active) {
- printf("Save address: 0x%lx\n", save_addr);
- printf("Save size: 0x%lx\n", save_size);
- net_boot_file_size = save_size;
+ printf("Save address: 0x%lx\n", image_save_addr);
+ printf("Save size: 0x%lx\n", image_save_size);
+ net_boot_file_size = image_save_size;
puts("Saving: *\b");
tftp_state = STATE_SEND_WRQ;
new_transfer();