bin->hex Conversion Problem

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

bin->hex Conversion Problem

7,019 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by stephen55 on Wed Jul 24 15:55:09 MST 2013
Hello,

I am trying to create a .hex file starting at a non-zero location in memory with the checksum included, and I am running into a problem. In order to run checksum.exe I need to convert from .axf to .bin, run checksum, and then convert to .hex.  The problem is that the resulting .hex file does not begin where the linker script tells it to, but rather it begins at 0x0000. Everything works when I convert from .axf directly to .hex, so it leads me to believe that the problem is in the .bin to .hex conversion, or possibly in the .axf to .bin conversion. It's like information is being lost somewhere along the line.

From what I've read, the post-build steps to add in the checksum and end up with a .hex file are as follows:

//convert to a .bin ; run checksum ; convert to .hex
arm-none-eabi-objcopy -O binary ${BuildArtifactFileName} ${BuildArtifactFileBaseName}.bin;
checksum -p ${TargetChip} -d ${BuildArtifactFileBaseName}.bin;
arm-none-eabi-objcopy -I binary -O ihex ${BuildArtifactFileBaseName}.bin ${BuildArtifactFileBaseName}.hex;

I've taken out the checksum step and tried .axf -> .bin -> .hex and I get the same result, so the problem is not checksum.exe

Any ideas or obvious mistakes?

Target = LPC1769
Using RedSuite5
0 项奖励
回复
10 回复数

5,182 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Wed Mar 25 09:12:57 MST 2015

Quote: Maricato
Hardware its OK

:D

No, it's not  :)

Are you using a 12MHz crystal to generate 100MHz clock  :quest:   :O
0 项奖励
回复

5,182 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Maricato on Wed Mar 25 09:06:54 MST 2015
The 'GO' on Flash Magic don't help  :(

Hardware its OK,

I edit the original COMBLOCK example, to make the LEd link and it works.
But i use a test editor to add this GPIO access to add the LED, and run their make file on Linux to compile and generate the HEX File, and it make the LED blinking.

The simple example I post for LCPXpresso don't do anything.

I have Problems with compilers? or on HEX file generation?

Thanks
0 项奖励
回复

5,182 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Wed Mar 25 07:26:11 MST 2015

Quote: Maricato
What I made wrong?? Could you Help me?



Your project and your HEX file are working without problems  :O

After flashing it with FlashMagic and starting it with 'GO' LED is blinking  :D

So check your hardware...
0 项奖励
回复

5,182 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Maricato on Wed Mar 25 07:15:37 MST 2015
Thanks The FallGuy,

I try to start in 0x0000 to but don't succeed...
0 项奖励
回复

5,182 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by TheFallGuy on Wed Mar 25 07:08:12 MST 2015
The first obvious thing is that you are creating a hex image that is based at address 0x10000, so your code won't even get to run.

But why are you making life difficult for yourself? Buy yourself a LPC-Link2 debug probe and save yourself a lot of time.
0 项奖励
回复

5,182 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Maricato on Wed Mar 25 06:58:12 MST 2015
Hello everybody,

I'm new at ARM and LPCXpresso. I have on hands a COMBLOCK 1500B board with a LPC1759 ARM Cortex M3 MCU.
For my introducing to this tools I decide to start with a academic LED blink example on P1[20] GPIO. (I attach my project)

For configuration I use:

void led2_init (void)
{
// Set P1_20 to 00 - GPIO
LPC_PINCON->PINSEL3&= (~(3 << 8));

// Set GPIO - P0_20 - to be output
LPC_GPIO1->FIODIR |= (1 << 20);
}

// Function to turn LED on
void led2_on (void)
{
LPC_GPIO1->FIOSET = (1 << 20);
}

// Function to turn LED2 off
void led2_off (void)
{
LPC_GPIO1->FIOCLR = (1 << 20);
}

The project was build without any problems...
So for flash the MCU i use a external JTAG for this board and use Flash Magic tool to upload the HEX file.

I try your suggestions the post-build steps on LPCXpresso Project -> Properties -> C/C++ Build -> settings :

arm-none-eabi-objcopy -O binary "${BuildArtifactFileName}" "${BuildArtifactFileBaseName}.bin";
checksum -p ${TargetChip} -d ${BuildArtifactFileBaseName}.bin;
arm-none-eabi-objcopy -I binary -O ihex --change-addresses 0x10000 "${BuildArtifactFileBaseName}.bin" "${BuildArtifactFileBaseName}.hex";
arm-none-eabi-size ${BuildArtifactFileName};

I upload the code with Flash Magic to the MCU without problems, but I don't see activity on the LED...

What I made wrong?? Could you Help me?

Thanks,
0 项奖励
回复

5,182 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by stephen55 on Thu Jul 25 13:32:22 MST 2013
Alright I got it. The included version of objcopy doesn't use the --image-base option.  It has other options like --set-start, --change-start, --adjust-start.  Those didn't work, but the one that did work is --change-addresses.

So the post-build section looks like this:
arm-none-eabi-objcopy -O binary "${BuildArtifactFileName}" "${BuildArtifactFileBaseName}.bin";
checksum -p ${TargetChip} -d ${BuildArtifactFileBaseName}.bin;
arm-none-eabi-objcopy -I binary -O ihex --change-addresses 0x10000 "${BuildArtifactFileBaseName}.bin" "${BuildArtifactFileBaseName}.hex";
arm-none-eabi-size ${BuildArtifactFileName};

Thanks for pointing me in the right direction man. Who would have thought to actually look at the options to the tool I was using. I shower you in worthless internet praise.
0 项奖励
回复

5,182 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by stephen55 on Thu Jul 25 10:38:43 MST 2013

Quote: TKoe
Uh.. to change the starting address I just to to the project properties -> C/C++ Build -> MCU settings. There I change the "Location" address for the Flash (and size obviously, too) and hit "Apply" (<- that is important, it will have no effect if you don't click on Apply!).
Then in C/C++ Build -> Settings -> Build Steps I use the following command in Post-build steps:
<code>arm-none-eabi-size "${BuildArtifactFileName}"; arm-none-eabi-objcopy -O binary "${BuildArtifactFileName}" "${BuildArtifactFileBaseName}.bin" ; checksum -p ${TargetChip} -d "${BuildArtifactFileBaseName}.bin";  arm-none-eabi-objcopy -O ihex "${BuildArtifactFileName}" "${BuildArtifactFileBaseName}.hex" ;</code>

That has so far worked perfectly.


Or am I understanding the question wrong?



Hi TKoe,

By doing those steps, it looks like you are creating a .bin file with the checksum, and then creating a .hex file without the checksum. Is the checksum information actually in the .hex file? I tried it out and it wasn't in there. 


Quote: TheFallGuy
By definition, a binary file contains no address information. A binary file contains just data. So, converting to binary all address information is lost.

I think you can use objdump to re-base the hex file with the --image-base option.



Alright that makes sense. I still don't understand much about the binary format, but if it's being programmed to flash, I would think that there'd be some way of inferring address information from it.

The --image-base option sounds promising. I tried:
arm-none-eabi-objcopy --image-base 0x10000 -I binary -O ihex ${BuildArtifactFileBaseName}.bin ${BuildArtifactFileBaseName}.hex

It didn't work, but it seems like a possibility. I need to read up a little more.
0 项奖励
回复

5,182 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by TKoe on Thu Jul 25 03:56:56 MST 2013
Uh.. to change the starting address I just to to the project properties -> C/C++ Build -> MCU settings. There I change the "Location" address for the Flash (and size obviously, too) and hit "Apply" (<- that is important, it will have no effect if you don't click on Apply!).
Then in C/C++ Build -> Settings -> Build Steps I use the following command in Post-build steps:
<code>arm-none-eabi-size "${BuildArtifactFileName}"; arm-none-eabi-objcopy -O binary "${BuildArtifactFileName}" "${BuildArtifactFileBaseName}.bin" ; checksum -p ${TargetChip} -d "${BuildArtifactFileBaseName}.bin";  arm-none-eabi-objcopy -O ihex "${BuildArtifactFileName}" "${BuildArtifactFileBaseName}.hex" ;</code>

That has so far worked perfectly.


Or am I understanding the question wrong?
0 项奖励
回复

5,182 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by TheFallGuy on Wed Jul 24 21:38:00 MST 2013
By definition, a binary file contains no address information. A binary file contains just data. So, converting to binary all address information is lost.

I think you can use objdump to re-base the hex file with the --image-base option.
0 项奖励
回复