[ELDK] mmap: first byte always wrong

Alberto Caballero alberto.kavan at gmail.com
Thu Nov 25 23:35:19 CET 2010

Hi all,

I am developing over an EP440xS board. I have stored a valid U-Boot image
into the board Flash. Kernel and Ramdisk image is stored at 0xFF000000
address and the test data image at 0xFD000000 address.

Once the Linux is started, I run my program that tries to copy the image
from Flash into a Linux file. As first step, I try to read the image magic
number, but I always get the first byte wrong, usually set to 0xFF. The rest
of the magic number bytes are correct, as the rest of the image header

Instead of getting 0x27 0x05 0x19 0x56 I am getting 0xFF 0x05 0x19 0x56.

Any ideas of what's going on? Any suggestion?

Best regards,


This is an extract of the code I am using:

---------------------------------------------------------------- Cut
#define SIZE            0x00100000  // 1MB size
#define IH_MAGIC        0x27051956    /* Image Magic Number        */
#define IH_NMLEN        32    /* Image Name Length        */

volatile unsigned char *base;
int fdMem;
void *where;

typedef struct image_header {
    unsigned int    ih_magic;    /* Image Header Magic Number    */
    unsigned int    ih_hcrc;    /* Image Header CRC Checksum    */
    unsigned int    ih_time;    /* Image Creation Timestamp    */
    unsigned int    ih_size;    /* Image Data Size        */
    unsigned int    ih_load;    /* Data     Load  Address        */
    unsigned int    ih_ep;        /* Entry Point Address        */
    unsigned int    ih_dcrc;    /* Image Data CRC Checksum    */
    unsigned char    ih_os;        /* Operating System        */
    unsigned char    ih_arch;    /* CPU architecture        */
    unsigned char    ih_type;    /* Image Type            */
    unsigned char    ih_comp;    /* Compression Type        */
    unsigned char    ih_name[IH_NMLEN];    /* Image Name        */
} image_header_t;

int ReadMem(int address)
    int ret = 0;

    // Open memory device

    // Check device opened
    if (fdMem < 0)
        ret = -1;
        // Map memory
        if (where == (void *)0xffffffff)
            ret = -1;
            base=(void *)where;

    return ret;

int GetFileFromMem(int addr, char* path)
    int             index;
    int             ret = 0;
    int             fdFile;
    image_header_t  header;

    // Read memory
    ret = ReadMem(addr);

    if (ret != -1)
        memcpy((void*)&header, (void*)base, sizeof(image_header_t));

        // Check header magic number
        if (ntohl(header.ih_magic) != IH_MAGIC)
            printf("ERROR: Magic [%d - %d]\n",header.ih_magic, IH_MAGIC);
            ret = -1;
            printf("Image data size: %d\n", header.ih_size);

            // Open output file
            fdFile = open(path, O_RDWR | O_CREAT);
            index = header.ih_size;

            // Write output file
            write(fdFile, (void*)(base+sizeof(image_header_t)),

            // Close output file

    return ret;
---------------------------------------------------------------- Cut

More information about the eldk mailing list