1. This forum section is a read-only archive which contains old newsgroup posts. If you wish to post a query, please do so in one of our main forum sections (here). This way you will get a faster, better response from the members on Motherboard Point.

Hex file not working

Discussion in 'Embedded' started by nik, Oct 7, 2008.

  1. nik

    nik Guest

    Hi guys....once again.

    To introduce again, I am using gcc (arm-elf-gcc V 4.1.1 ) as cross
    compiler for LPC2368 processor on Ubuntu and ....I am a newbee.

    Initially I had problems with with compiling and linking which are
    solved now. I am able to make the hex file also.But the hex file is
    not working on the processor.

    Here are the modified startup files , the source file and the linker

    /********************** crt0.S ************************************/

    .global _etext

    .global _data
    .global _edata
    .global __bss_start
    .global __bss_end__
    .global _stack

    .set UND_STACK_SIZE, 0x00000004
    .set ABT_STACK_SIZE, 0x00000004
    .set FIQ_STACK_SIZE, 0x00000004
    .set IRQ_STACK_SIZE, 0X00000080
    .set SVC_STACK_SIZE, 0x00000004

    .set MODE_USR, 0x10
    .set MODE_FIQ, 0x11
    .set MODE_IRQ, 0x12
    .set MODE_SVC, 0x13
    .set MODE_ABT, 0x17
    .set MODE_UND, 0x1B
    .set MODE_SYS, 0x1F

    .equ I_BIT, 0x80

    .equ F_BIT, 0x40

    .section .init, "ax"

    .code 32
    .align 2

    .global _boot
    .func _boot

    b _start
    ldr pc,_undf
    ldr pc,_swi
    ldr pc,_pabt
    ldr pc,_dabt
    ldr pc,[pc,#-0xFF0]
    ldr pc,_fiq

    #if 0

    _undf: .word _reset
    _swi: .word _reset
    _pabt: .word _reset
    _dabt: .word _reset
    _irq: .word _reset
    _fiq: .word _reset


    _undf: .word __undf
    _swi: .word __swi
    _pabt: .word __pabt
    _dabt: .word __dabt
    _irq: .word __irq
    _fiq: .word __fiq

    __undf: b .
    __swi: b .
    __pabt: b .
    __dabt: b .
    __irq: b .
    __fiq: b .
    .size _boot, . - _boot

    .global _start, start, _mainCRTStartup
    .func _start


    ldr r0,=_stack

    mov sp,r0
    sub r0,r0,#UND_STACK_SIZE
    mov sp,r0
    sub r0,r0,#ABT_STACK_SIZE
    mov sp,r0
    sub r0,r0,#FIQ_STACK_SIZE
    mov sp,r0
    sub r0,r0,#IRQ_STACK_SIZE
    mov sp,r0
    sub r0,r0,#SVC_STACK_SIZE
    mov sp,r0

    #ifdef ROM_RUN
    ldr r1,=_etext
    ldr r2,=_data
    ldr r3,=_edata
    1: cmp r2,r3
    ldrlo r0,[r1],#4
    strlo r0,[r2],#4
    blo 1b

    mov r0,#0
    ldr r1,=__bss_start
    ldr r2,=__bss_end__
    2: cmp r1,r2
    strlo r0,[r1],#4
    blo 2b

    mov r0,#0

    mov r1,r0

    mov r2,r0

    mov fp,r0

    mov r7,r0

    ldr r10,=main

    mov lr,pc

    bx r10

    .size _start, . - _start

    .global _reset, reset, exit, abort
    .func _reset
    #if 0

    mrs r0,cpsr
    orr r0,r0,#I_BIT|F_BIT
    msr cpsr,r0

    ldr r1,=(PS_BASE)
    ldr r0,=(PS_PIO)
    str r0,[r1,#PS_PCER_OFF]
    ldr r1,=(PIO_BASE)
    ldr r0,=(1<<23)
    str r0,[r1,#PIO_PER_OFF]

    str r0,[r1,#PIO_CODR_OFF]
    str r0,[r1,#PIO_OER_OFF]
    b .

    .size _reset, . - _reset

    /*************************************crt0.S ends



    /* ROM.ld: Linker Script File

    /* "RAMfunc" demo!!



    STACK_SIZE = 0x400;

    /* Memory Definitions */

    /* lpc2129 mt */



    ROM (rx) : ORIGIN = 0x00000000, LENGTH = 0x00080000

    RAM (rw) : ORIGIN = 0x40000000, LENGTH = 0x00008000


    /* Section Definitions */



    .text :


    *crt0.o (.text)






    } > ROM

    . = ALIGN(4);

    /* .data section which is used for initialized data */

    .data : AT (_etext)


    _data = .;




    SORT(CONSTRUCTORS) /* mt 4/2005 */

    . = ALIGN(4);


    } > RAM

    . = ALIGN(4);

    _edata = . ;

    PROVIDE (edata = .);

    /* .bss section which is used for uninitialized data */

    .bss (NOLOAD) :


    __bss_start = . ;

    __bss_start__ = . ;




    . = ALIGN(4);

    } > RAM

    . = ALIGN(4);

    __bss_end__ = . ;

    PROVIDE (__bss_end = .);

    .stack :


    . = ALIGN(256);
    /* . += STACK_SIZE;*/

    PROVIDE (_stack = .);
    . = ALIGN(4);

    } > RAM

    _end = . ;

    PROVIDE (end = .);


    /************************ ROM.ld ends*********************/

    /********************* new.c ***********************/

    #include "LPC23xx.h"

    int main()
    PLLFEED = 0xAA;
    PLLFEED = 0x55;
    PLLCFG = 0x40032;
    PLLFEED = 0xAA;
    PLLFEED = 0x55;
    PLLCON = 0X03;
    PLLFEED = 0xAA;
    PLLFEED = 0x55;
    while(!(PLLSTAT & 0x04000000))

    CCLKCFG = 0x05;

    IODIR0 = 0xFFFFFF;
    IOCLR0 = 0xFFFFFF;


    /****************************** new.c ends *************************/

    And the commands used are :

    arm-elf-gcc -c new.c -o new.o
    arm-elf-gcc -c crt0.S -o crt0.o
    arm-elf-gcc -mcpu=arm7tdmi-s -nostdlib -nostartfiles crt0.o ROM.ld
    new.o -o y.elf
    arm-elf-objcopy -O ihex y.elf zzz.hex

    I am definitely missing something , but unable to figure it out.

    All the geniuses out there...please help me out.

    Thanks a million.
    nik, Oct 7, 2008
    1. Advertisements

  2. nik

    nik Guest

    Guys ....Please please help me out.
    nik, Oct 7, 2008
    1. Advertisements

  3. nik

    nik Guest

    Thanks for responding Anthony.
    No , I dont have any debugger.

     > Is your code intended to run in Thumb mode?

    No It is intended to run completely in ARM mode.

    Do you think there are any issues with the startup file or the linker
    script ?

    nik, Oct 8, 2008
  4. nik

    sk.syed Guest

    I too had a similar problem when I tried to build IntelHex record
    using elf image.
    Alternatively you can try(if you have installed Keil tools)
    c:\keil\ARM\BIN30\fromelf.exe --ihex --target 0x00000000 --output
    zzz.hex y.elf

    ihex file expect a target address, say your board boots from a
    location 0xc000000 in flash you should use
    --target 0xc000000 above. Got it?

    sk.syed, Oct 8, 2008
  5. nik

    nik Guest

    Hello Syed,

    Thanks for the reply.But I am using gcc in Ubuntu.....so....keil is
    not an option.
    Anyways.....keep responding.

    nik, Oct 13, 2008
  6. nik

    nik Guest

    Hello Anthony,

    It will be of great help if you mail me the file.
    Please send it at

    nik, Oct 14, 2008
  7. nik

    CBFalconer Guest

    He did. He advised you to snip irrelevant quotes.
    CBFalconer, Oct 16, 2008
  8. nik

    CBFalconer Guest

    Congratulations. You learned to snip. Now you need to learn how
    to mark the snipped areas.
    CBFalconer, Oct 17, 2008
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.