Skip to content

Use pyelftools for Realtek post-build script #6621

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

Merged
merged 1 commit into from
Apr 17, 2018

Conversation

theotherjimmy
Copy link
Contributor

@theotherjimmy theotherjimmy commented Apr 12, 2018

Description

The online compiler can be very picky about what is and is not allowed in a post-build scirpt. For a while now, the Realtek post-build script has been preventing anyone from successfully compiling for the RTL8195AM in the online compiler. This refactor changes the code that was failing to be much simpler, and it works in the website. I have tested this on a staging site.

For reference, the traceback:

  File "/usr/src/mbed-sdk/tools/toolchains/__init__.py", line 1152, in link_program
    self.binary(r, elf, bin)
  File "/usr/src/mbed-sdk/tools/hooks.py", line 54, in wrapper
    post_res = tooldesc["post"](t_self, *args, **kwargs)
  File "/usr/src/mbed-sdk/tools/targets/__init__.py", line 538, in binary_hook
    rtl8195a_elf2bin(t_self, elf, binf)
  File "/usr/src/mbed-sdk/tools/targets/REALTEK_RTL8195AM.py", line 283, in rtl8195a_elf2bin
    segment = parse_load_segment(t_self.name, image_elf)
  File "/usr/src/mbed-sdk/tools/targets/REALTEK_RTL8195AM.py", line 212, in parse_load_segment
    return parse_load_segment_armcc(image_elf)
  File "/usr/src/mbed-sdk/tools/targets/REALTEK_RTL8195AM.py", line 143, in parse_load_segment_armcc
    for line in subprocess.check_output(cmd, shell=True, universal_newlines=True).split("\n"):
  File "/usr/lib/python2.7/subprocess.py", line 574, in check_output
    raise CalledProcessError(retcode, cmd, output=output)
CalledProcessError: Command '"/opt/armcc5_06_u3/bin/fromelf" --text -v --only=none /tmp/chroots/ch-e3a8e63e-cb37-4195-ae50-1fe69442b3e4/build/mbed-os-example-fat-filesystem.REALTEK_RTL8195AM.elf' returned non-zero exit status 127

Error 127 is "command not found" https://stackoverflow.com/questions/1763156/127-return-code-from#1763178. I fixed this by refactoring so that we don't use any commands.

Pull request type

[X] Fix
[ ] Refactor
[ ] New target
[ ] Feature
[ ] Breaking change

@theotherjimmy
Copy link
Contributor Author

@samchuarm @ARMmbed/team-realtek

@samchuarm
Copy link

Hi @ARMmbed/team-realtek , please review the changes and provide your feedback if any.

Copy link
Contributor

@tung7970 tung7970 left a comment

Choose a reason for hiding this comment

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

Thanks for the effort. It looks much nicer.

One small thing, shouldn't the 'attr' variable be better named 'addr' in function _parse_load_segment_inner ?

0xc0170
0xc0170 previously approved these changes Apr 16, 2018
Copy link
Contributor

@0xc0170 0xc0170 left a comment

Choose a reason for hiding this comment

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

+1 simplification, elftools 💯

@theotherjimmy
Copy link
Contributor Author

@tung7970 Yes, that's a typo. I'll fix that now.

@theotherjimmy
Copy link
Contributor Author

@0xc0170 @tung7970 I revised the commit to correct the typo. Could you both take another look?

Copy link
Contributor

@tung7970 tung7970 left a comment

Choose a reason for hiding this comment

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

LGTM

@cmonr
Copy link
Contributor

cmonr commented Apr 17, 2018

Interesting. Why does the code now no longer need to check compilers?

/morph build

@tung7970
Copy link
Contributor

The new script checks the elf file directly rather than output from each compiler’s elf dumper.

@mbed-ci
Copy link

mbed-ci commented Apr 17, 2018

Build : SUCCESS

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

Triggering tests

/morph test
/morph uvisor-test
/morph export-build
/morph mbed2-build

@mbed-ci
Copy link

mbed-ci commented Apr 17, 2018

@mbed-ci
Copy link

mbed-ci commented Apr 17, 2018

@adbridge
Copy link
Contributor

@theotherjimmy Is this fixing #5976 ??

@theotherjimmy
Copy link
Contributor Author

Yes, but I want to verify that once this goes live on the website, so I omitted a "Resolves" directive.

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

Successfully merging this pull request may close these issues.

7 participants