Skip to content

ARMCC - FromELF multiple regions #5021

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

chrissnow
Copy link
Contributor

Description

ELF files containing multiple regions were being converted to a folder with each region as a separate file, this caused the build scripts to fail since the .bin was not created.

This was noticed when building LPC1768 with a bootloader as the CRP word is set as a seperate region.

Status

READY

Migrations

NO

Related PRs

Todos

Deploy notes

Steps to test or reproduce

Enable bootloader support for LPC1768 and try and build

Link: mbed-os-example-bootloader-blinky_application
[DEBUG] Link: C:/Keil_v5/ARM/ARMCC\bin\armlink --via .\BUILD\lpc1768\arm\.link_files.txt
[DEBUG] Return: 0
Elf2Bin: mbed-os-example-bootloader-blinky_application
[DEBUG] FromELF: C:/Keil_v5/ARM/ARMCC\bin\fromelf --bin -o .\BUILD\lpc1768\arm\mbed-os-example-bootloader-blinky_application.bin .\BUILD\lpc1768\arm\mbed-os-example-bootloader-blinky_application.elf
[DEBUG] Return: 1
[DEBUG] Errors: Error: Q0147E: Failed to create Directory .\BUILD\lpc1768\arm\mbed-os-example-bootloader-blinky_application.bin\ER$$.ARM.__at_0x02FC: File exists
[DEBUG] Errors: Finished: 0 information, 0 warning and 1 error messages.
Traceback (most recent call last):
  File "c:\Code\Chris\mbed-os-example-bootloader-blinky\mbed-os\tools\make.py", line 296, in <module>
    stats_depth=options.stats_depth)
  File "c:\Code\Chris\mbed-os-example-bootloader-blinky\mbed-os\tools\build_api.py", line 544, in build_project
    res, _ = toolchain.link_program(resources, build_path, name + "_application")
  File "c:\Code\Chris\mbed-os-example-bootloader-blinky\mbed-os\tools\toolchains\__init__.py", line 1128, in link_program
    self.binary(r, elf, bin)
  File "c:\Code\Chris\mbed-os-example-bootloader-blinky\mbed-os\tools\hooks.py", line 51, in wrapper
    res = function(t_self, *args, **kwargs)
  File "c:\Code\Chris\mbed-os-example-bootloader-blinky\mbed-os\tools\toolchains\arm.py", line 229, in binary
    self.default_cmd(cmd)
  File "c:\Code\Chris\mbed-os-example-bootloader-blinky\mbed-os\tools\toolchains\__init__.py", line 1152, in default_cmd
    raise ToolException(_stderr)
ToolException: Error: Q0147E: Failed to create Directory .\BUILD\lpc1768\arm\mbed-os-example-bootloader-blinky_application.bin\ER$$.ARM.__at_0x02FC: File exists
Finished: 0 information, 0 warning and 1 error messages.

[mbed] ERROR: "c:\python27\python.exe" returned error code 1.
[mbed] ERROR: Command "c:\python27\python.exe -u c:\Code\Chris\mbed-os-example-bootloader-blinky\mbed-os\tools\make.py -t arm -m lpc1768 --source . --build .\BUILD\lpc1768\arm -v" in "c:\Code\Chris\mbed-os-example-bootloader-blinky"
---

image

image

Copy link
Contributor

@theotherjimmy theotherjimmy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome diff. How backwards compatible do you think this is?

@chrissnow
Copy link
Contributor Author

chrissnow commented Sep 5, 2017

It shouldn't make any difference if there is a single region.
http://www.keil.com/support/man/docs/armutil/armutil_pge1362128886407.htm

--bincombined
Produces plain binary output. It generates one output file for an image containing multiple load regions.

@chrissnow
Copy link
Contributor Author

chrissnow commented Sep 5, 2017

http://www.keil.com/support/man/docs/armutil/armutil_pge1362128885938.htm

--bin
If you convert an ELF image containing multiple load regions to a binary format, fromelf creates an output directory named destination and generates one binary output file for each load region in the input image. fromelf places the output files in the destination directory.

@theotherjimmy
Copy link
Contributor

Thanks for the clarification. I think that --bincombined is probably what we wanted in the first place anyway.

@chrissnow
Copy link
Contributor Author

How can I find the reason for failure?

@theotherjimmy
Copy link
Contributor

@chrissnow I'm looking for the error right now. Just a moment.

@theotherjimmy
Copy link
Contributor

I think the logging borked for that job. @tommikas Could you verify? It looks very suspicious:

[eth-8023] Traceback (most recent call last):
[eth-8023]   File "/usr/lib/python2.7/logging/__init__.py", line 861, in emit
[eth-8023]     msg = self.format(record)
[eth-8023]   File "/usr/lib/python2.7/logging/__init__.py", line 734, in format
[eth-8023]     return fmt.format(record)
[eth-8023]   File "/usr/lib/python2.7/logging/__init__.py", line 465, in format
[eth-8023]     record.message = record.getMessage()
[eth-8023]   File "/usr/lib/python2.7/logging/__init__.py", line 329, in getMessage
[eth-8023]     msg = msg % self.args
[eth-8023] TypeError: not all arguments converted during string formatting
[eth-8023] Logged from file opentmi_client.py, line 189
[eth-8023] Traceback (most recent call last):
[eth-8023]   File "/usr/lib/python2.7/logging/__init__.py", line 861, in emit
[eth-8023]     msg = self.format(record)
[eth-8023]   File "/usr/lib/python2.7/logging/__init__.py", line 734, in format
[eth-8023]     return fmt.format(record)
[eth-8023]   File "/usr/lib/python2.7/logging/__init__.py", line 465, in format
[eth-8023]     record.message = record.getMessage()
[eth-8023]   File "/usr/lib/python2.7/logging/__init__.py", line 329, in getMessage
[eth-8023]     msg = msg % self.args
[eth-8023] TypeError: not all arguments converted during string formatting

@theotherjimmy
Copy link
Contributor

@chrissnow I'm not sure why it failed. Maybe @tommikas can help us out with this one.

@tommikas
Copy link
Contributor

tommikas commented Sep 6, 2017

@theotherjimmy Looks like some 6lowpan tests failed. A few other builds also failed for the same reason so it's probably nothing to do with this PR. I'll restart the builds.

@chrissnow
Copy link
Contributor Author

@theotherjimmy it passed this time :-) , Thanks @tommikas

…ltiple regions are converted to a single binary and not a folder of regions
@0xc0170
Copy link
Contributor

0xc0170 commented Sep 20, 2017

cc @c1728p9

@c1728p9
Copy link
Contributor

c1728p9 commented Sep 20, 2017

@chrissnow, with this change are you able to get mbed-os-example-bootloader-blinky_application running, or does this only enable you to build a binary? I would imagine this change still does not create a bootable image.

Normally the CRP region (0x02FC) lies inside a load region as seen in the lpc1768 scatter file. If you are building blinky with a bootloader then the application is at a higher address, so the CRP (fixed at 0x02FC) no longer resides in in a load region.

A safer solution would be to put the CRP data in a section relative to the load region. That way when you build a program with a bootloader the CRP moves with the application. An example of this can be found in the K64F scatter file which has a dedicated execution region in the load region for flash settings.

@chrissnow
Copy link
Contributor Author

@c1728p9 With this change alone no, see #5038, this just fixed the build tools should multiple regions exist for whatever reason. CRP is addressed in there (partly in line with your suggestion).

@c1728p9
Copy link
Contributor

c1728p9 commented Sep 20, 2017

@chrissnow, with the changes in #5038 do you still see two separate regions created?

@chrissnow
Copy link
Contributor Author

@c1728p9 not as it stands, though that might not be the case if I add extra ER as suggested.

@c1728p9
Copy link
Contributor

c1728p9 commented Sep 20, 2017

@chrissnow I believe an extra binary will only be created if there are multiple LRs (Load Regions). Extra ERs (Execution Regions) shouldn't be a problem, as many targets already have several ERs.

Typically when there are multiple LRs and building creates a directory rather than a binary it indicates something is wrong in the scatter file. Adding this change may mask scatter file errors. Rather than having an obvious error at compile time, a binary will be created that does not work.

@0xc0170
Copy link
Contributor

0xc0170 commented Sep 21, 2017

@chrissnow I believe an extra binary will only be created if there are multiple LRs (Load Regions). Extra ERs (Execution Regions) shouldn't be a problem, as many targets already have several ERs.

From --bincombined: Produces plain binary output. It generates one output file for an image containing multiple load regions. That is correct.

I found few devices, LPC407X_8X, also REALTEK has 3. Is this regular use case to have multiple load regions?

@theotherjimmy
Copy link
Contributor

/morph test

@mbed-bot
Copy link

Result: ABORTED

Your command has finished executing! Here's what you wrote!

/morph test

@0xc0170
Copy link
Contributor

0xc0170 commented Sep 22, 2017

This was aborted, needs an approval from @c1728p9

@c1728p9
Copy link
Contributor

c1728p9 commented Sep 22, 2017

It looks like the LPC4088_DM's post build hook makes use of multiple regions being created if the binary is big enough. It does this by manually combining the regions with little padding (up to 512K). With this PR padding is done automatically, but rather than 512K it pads the entire address space from LR_IROM1 to LR_IROM which is ~640MB.

@chrissnow
Copy link
Contributor Author

Short of using hex files over bin there isn't much you can do about this.

If nothing else the build tools should deal with this gracefully, it's a bit cryptic as it stands.

@0xc0170
Copy link
Contributor

0xc0170 commented Sep 26, 2017

If nothing else the build tools should deal with this gracefully, it's a bit cryptic as it stands.

@theotherjimmy @c1728p9 What are you opinions for this?

@c1728p9
Copy link
Contributor

c1728p9 commented Sep 26, 2017

Maybe the mbed-os build tools should print a nicely formatted error message if this occurs and there isn't a post build hook for the platform. @theotherjimmy what do you think?

@theotherjimmy
Copy link
Contributor

@c1728p9 That sounds fine. What would you like the tools to say?

@0xc0170
Copy link
Contributor

0xc0170 commented Oct 9, 2017

@theotherjimmy @c1728p9 bump

@studavekar
Copy link
Contributor

/morph build

@mbed-ci
Copy link

mbed-ci commented Oct 11, 2017

Build : SUCCESS

Build number : 96
Build artifacts/logs : http://mbed-os.s3-website-eu-west-1.amazonaws.com/?prefix=builds/5021/

Triggering tests

/test mbed-os

@mbed-ci
Copy link

mbed-ci commented Oct 11, 2017

@0xc0170
Copy link
Contributor

0xc0170 commented Oct 13, 2017

Maybe the mbed-os build tools should print a nicely formatted error message if this occurs and there isn't a post build hook for the platform. @theotherjimmy what do you think?

I set this to needs: clarification. I would like to see this closed with a new tracking issue for tools

@0xc0170
Copy link
Contributor

0xc0170 commented Nov 20, 2017

Tracking issue created #5537. We can close this for now

@chrissnow Thanks for the effort!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants