colibri_imx6: fix video stdout in default environment
[oweals/u-boot.git] / net / tftp.c
index eca801aa194eb7fb71b5ed8f1de31faaf12f3502..180140e495b15482f9ac2c0fef87a0b87f6cf8da 100644 (file)
@@ -9,6 +9,10 @@
 #include <common.h>
 #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>
@@ -131,14 +135,9 @@ static char tftp_filename[MAX_LEN];
  * 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)
 {
@@ -170,8 +169,13 @@ 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;
@@ -215,8 +219,8 @@ static int load_block(unsigned block, uchar *dst, unsigned len)
        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;
 }
@@ -599,23 +603,22 @@ static void tftp_timeout_handler(void)
        }
 }
 
-/* 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
        struct lmb lmb;
        phys_size_t max_size;
 
-       lmb_init_and_reserve(&lmb, gd->bd->bi_dram[0].start,
-                            gd->bd->bi_dram[0].size, (void *)gd->fdt_blob);
+       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;
 }
 
@@ -705,9 +708,9 @@ void tftp_start(enum proto_t protocol)
 #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();