Accessing memory loaded via tftp

1

I am trying to access data from a file that I load in via tftp. I'm using an AM3358 processor

tftp 81000000 mydata

and I can see the data being correctly loaded

=> md 81000000
81000000: 00004000 00000000 00002000 00000400    .@....... ......

In the u-boot code, I create a pointer to this address and then attempt to de-reference it, but the value is incorrect which makes me think I'm using the incorrect address

unsigned long addr = 0x81000000;
uint32_t *ptr = &addr;
uint32_t val = *(ptr+0);
printf("addr %ul val: %ul", addr, val);

Furthermore, I'm trying to load the address of mydata into a 32-bit LCD register, but the physical address of 0x81000000 is beyond that of a 32-bit number. I believe I'm just confused as to what address mapping is involved here.

bdi yields

=> bdi
arch_number = 0x00000000
boot_params = 0x80000100
DRAM bank   = 0x00000000
-> start    = 0x80000000
-> size     = 0x20000000
baudrate    = 115200 bps
TLB addr    = 0x9fff0000
relocaddr   = 0x9ffb4000
reloc off   = 0x1f7b4000
irq_sp      = 0x9df8ba90
sp start    = 0x9df8ba80
Early malloc usage: 4a8 / 1000
fdt_blob    = 0x9df8bea0
u-boot
asked on Stack Overflow Oct 5, 2020 by newuser98998 • edited Oct 5, 2020 by newuser98998

1 Answer

0

Why would 0x81000000 not be a valid 32 bit number ?

0x00000000 <= 0x81000000 <= 0xFFFFFFFF.

I think there may be an error in your logic: you are initializing ptrwith the address of addr, not the address of its content.

The correct code would rather be something like:

uint32_t addr = 0x81000000;
uint32_t *ptr = (uint32_t*)(uintptr_t) addr;
uint32_t val = *(ptr+0);
printf("addr %ul val: %ul", addr, val);

This can be tested on your PC - you may need to add support for building 32 bit applications, i.e. execute sudo apt-get install gcc-multilib on Ubuntu.

ptr.c:

#include <stdio.h>
#include <stdint.h>

int
main ()
{
  uint32_t addr = 0x81000000; // gcc 9.3.0 is complaining about uint32_t *ptr = &addr;
  
  // your code
  {
    uint32_t *ptr = &addr;
    printf ("%p\n", ptr);
  }

  // correct code
  {
    uint32_t *ptr = (uint32_t *) (uintptr_t) addr;
    printf ("%p\n", ptr);
  }
}

gcc -m32 -o ptr ptr.c

./ptr
0xff83bc60
0x81000000

This would be why you cannot access the content of the file you transferred using TFTP, you are reading from an incorrect, but valid address.

answered on Stack Overflow Oct 5, 2020 by Frant • edited Oct 8, 2020 by Frant

User contributions licensed under CC BY-SA 3.0