Skip to content

AArch64 semihosting#20392

Merged
alalek merged 20 commits intoopencv:masterfrom
fpetrogalli:aarch64-semihosting
Jul 21, 2021
Merged

AArch64 semihosting#20392
alalek merged 20 commits intoopencv:masterfrom
fpetrogalli:aarch64-semihosting

Conversation

@fpetrogalli
Copy link
Copy Markdown
Contributor

@fpetrogalli fpetrogalli commented Jul 12, 2021

This patch provide a toolchain file that allows to build the library
for semihosting applications [1]. Minimal changes have been applied to
the code to be able to compile with a baremetal toolchain.

[1] https://developer.arm.com/documentation/100863/latest

The option `CV_SEMIHOSTING` is used to guard the bits in the code that
are specific to the target.

To build the code:

    cmake ../opencv/ \
        -DCMAKE_TOOLCHAIN_FILE=../opencv/platforms/semihosting/aarch64-semihosting.toolchain.cmake \
        -DSEMIHOSTING_TOOLCHAIN_PATH=/path/to/baremetal-toolchain/bin/ \
        -DBUILD_EXAMPLES=ON -GNinja

A barematel toolchain for targeting aarch64 semihosting can be found
at [2], under `aarch64-none-elf`.

[2] https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-a/downloads

The folder `samples/semihosting` provides two example semihosting
applications.

The two binaries can be executed on the host platform with:

    qemu-aarch64 ./bin/example_semihosting_histogram
    qemu-aarch64 ./bin/example_semihosting_norm

Similarly, the test and perf executables of the modules can be run
with:

    qemu-aarch64 ./bin/opecv_[test|perf]_<module>

Notice that filesystem support is disabled by the toolchain file,
hence some of the test that depend on filesystem support will fail.

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or other license that is incompatible with OpenCV
  • The PR is proposed to proper branch
  • There is reference to original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake
force_builders=linux,docs,ARMv8,ARMv7,Custom
build_image:Custom=javascript
buildworker:Custom=linux-4,linux-6

@fpetrogalli fpetrogalli changed the title Aarch64 semihosting AArch64 semihosting Jul 12, 2021
@fpetrogalli fpetrogalli force-pushed the aarch64-semihosting branch from 01dbc29 to 774158b Compare July 12, 2021 11:52
@alalek
Copy link
Copy Markdown
Member

alalek commented Jul 12, 2021

@fpetrogalli How this patch correlates with baremetal PR #19921 ? Does it replace that PR?

@fpetrogalli
Copy link
Copy Markdown
Contributor Author

@fpetrogalli How this patch correlates with baremetal PR #19921 ? Does it replace that PR?

yes, indeed, this patch replaces #19921

@fpetrogalli
Copy link
Copy Markdown
Contributor Author

@alalek - I have added some instructions in the commit message on how to compile this code for semihosting, and how to run it on an x86 host.

@fpetrogalli
Copy link
Copy Markdown
Contributor Author

@alalek - I am not sure what is happening with this failure: https://pullrequest.opencv.org/buildbot/builders/precommit_windows64/builds/29988

Any advice on what might be going on?

@alalek
Copy link
Copy Markdown
Member

alalek commented Jul 13, 2021

Error messages are:

C:\build\precommit_opencl\opencv\samples\semihosting\norm\norm.cpp(10,10): fatal error C1083: Cannot open include file: 'raw_pixels.hpp': No such file or directory
C:\build\precommit_opencl\opencv\samples\semihosting\histogram\histogram.cpp(10,10): fatal error C1083: Cannot open include file: 'raw_pixels.hpp': No such file or directory

@fpetrogalli fpetrogalli force-pushed the aarch64-semihosting branch from c57ca61 to 98a1842 Compare July 14, 2021 15:31
@fpetrogalli
Copy link
Copy Markdown
Contributor Author

Error messages are:

C:\build\precommit_opencl\opencv\samples\semihosting\norm\norm.cpp(10,10): fatal error C1083: Cannot open include file: 'raw_pixels.hpp': No such file or directory
C:\build\precommit_opencl\opencv\samples\semihosting\histogram\histogram.cpp(10,10): fatal error C1083: Cannot open include file: 'raw_pixels.hpp': No such file or directory

Good point, I think I fixed it with the last commit 98a1842 (let's wait for the bots to be happy, though).

@fpetrogalli fpetrogalli force-pushed the aarch64-semihosting branch from 98a1842 to ec70dcc Compare July 14, 2021 15:44
@fpetrogalli fpetrogalli marked this pull request as ready for review July 14, 2021 15:44
Copy link
Copy Markdown
Member

@alalek alalek left a comment

Choose a reason for hiding this comment

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

Looks good to me 👍

@fpetrogalli
Copy link
Copy Markdown
Contributor Author

Looks good to me 👍

Thank you @alalek. I am actually particularly grateful for suggesting the idea of breaking the functionality down in multiple independent submissions :).

Francesco Petrogalli added 14 commits July 19, 2021 08:40
Because of this change, all the tests loading data will file, but tat
least the core module can be tested with the following line:

    opencv_test_core --gtest_filter=-"*Core_InputOutput*:*Core_globbing.accuracy*"
This patch provide a toolchain file that allows to build the library
for semihosting applications [1]. Minimal changes have been applied to
the code to be able to compile with a baremetal toolchain.

[1] https://developer.arm.com/documentation/100863/latest

The option `CV_SEMIHOSTING` is used to guard the bits in the code that
are specific to the target.

To build the code:

    cmake ../opencv/ \
        -DCMAKE_TOOLCHAIN_FILE=../opencv/platforms/semihosting/aarch64-semihosting.toolchain.cmake \
        -DSEMIHOSTING_TOOLCHAIN_PATH=/path/to/baremetal-toolchain/bin/ \
        -DBUILD_EXAMPLES=ON -GNinja

A barematel toolchain for targeting aarch64 semihosting can be found
at [2], under `aarch64-none-elf`.

[2] https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-a/downloads

The folder `samples/semihosting` provides two example semihosting
applications.

The two binaries can be executed on the host platform with:

    qemu-aarch64 ./bin/example_semihosting_histogram
    qemu-aarch64 ./bin/example_semihosting_norm

Similarly, the test and perf executables of the modules can be run
with:

    qemu-aarch64 ./bin/opecv_[test|perf]_<module>

Notice that filesystem support is disabled by the toolchain file,
hence some of the test that depend on filesystem support will fail.
Use the facilities provided by Cmake to generate the header file
instead of a shell script, so that the build doesn't fail on systems
that do not have a unix shell.
@fpetrogalli fpetrogalli force-pushed the aarch64-semihosting branch from df30d6d to 9a285a9 Compare July 19, 2021 09:42
Copy link
Copy Markdown
Contributor

@vpisarev vpisarev left a comment

Choose a reason for hiding this comment

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

@fpetrogalli,

  1. could you please add platform/selfhosting/README.md with a short description (e.g. a bit extended version of the top comment in this pull request) of what it is, why and how to use it?
  2. are those 3 samples necessary? can we reduce this number? I'm thinking of cleaning the list of OpenCV samples, which are too many, in my opinion. In this particular case, does any of the 3 samples shows some unique features, or it all can be demonstrated with 1-2 samples?

@fpetrogalli
Copy link
Copy Markdown
Contributor Author

@vpisarev , re:

2. are those 3 samples necessary? can we reduce this number? I'm thinking of cleaning the list of OpenCV samples, which are too many, in my opinion. In this particular case, does any of the 3 samples shows some unique features, or it all can be demonstrated with 1-2 samples?

The samples are 2. I think I would like to keep both of them because they cover for two different modules. I see some values in showing how the two LOCAL_DEPS are populated accordingly.

@fpetrogalli
Copy link
Copy Markdown
Contributor Author

@vpisarev - I have added the README file.

@fpetrogalli
Copy link
Copy Markdown
Contributor Author

Thank you @asmorkalov !

@vpisarev vpisarev self-requested a review July 21, 2021 13:26
Copy link
Copy Markdown
Contributor

@vpisarev vpisarev left a comment

Choose a reason for hiding this comment

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

thanks, @fpetrogalli, great job! 👍

@vpisarev
Copy link
Copy Markdown
Contributor

@alalek, I guess, it can be squashed and merged now

@alalek alalek merged commit d29c7e7 into opencv:master Jul 21, 2021
@fpetrogalli
Copy link
Copy Markdown
Contributor Author

@alalek @asmorkalov @vpisarev - thank you all for the great support and help!

@alalek alalek mentioned this pull request Oct 15, 2021
a-sajjad72 pushed a commit to a-sajjad72/opencv that referenced this pull request Mar 30, 2023
AArch64 semihosting

* [ts] Disable filesystem support in the TS module.

Because of this change, all the tests loading data will file, but tat
least the core module can be tested with the following line:

    opencv_test_core --gtest_filter=-"*Core_InputOutput*:*Core_globbing.accuracy*"

* [aarch64] Build OpenCV for AArch64 semihosting.

This patch provide a toolchain file that allows to build the library
for semihosting applications [1]. Minimal changes have been applied to
the code to be able to compile with a baremetal toolchain.

[1] https://developer.arm.com/documentation/100863/latest

The option `CV_SEMIHOSTING` is used to guard the bits in the code that
are specific to the target.

To build the code:

    cmake ../opencv/ \
        -DCMAKE_TOOLCHAIN_FILE=../opencv/platforms/semihosting/aarch64-semihosting.toolchain.cmake \
        -DSEMIHOSTING_TOOLCHAIN_PATH=/path/to/baremetal-toolchain/bin/ \
        -DBUILD_EXAMPLES=ON -GNinja

A barematel toolchain for targeting aarch64 semihosting can be found
at [2], under `aarch64-none-elf`.

[2] https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-a/downloads

The folder `samples/semihosting` provides two example semihosting
applications.

The two binaries can be executed on the host platform with:

    qemu-aarch64 ./bin/example_semihosting_histogram
    qemu-aarch64 ./bin/example_semihosting_norm

Similarly, the test and perf executables of the modules can be run
with:

    qemu-aarch64 ./bin/opecv_[test|perf]_<module>

Notice that filesystem support is disabled by the toolchain file,
hence some of the test that depend on filesystem support will fail.

* [semihosting] Remove blank like at the end of file. [NFC]

The spurious blankline was reported by
https://pullrequest.opencv.org/buildbot/builders/precommit_docs/builds/31158.

* [semihosting] Make the raw pixel file generation OS independent.

Use the facilities provided by Cmake to generate the header file
instead of a shell script, so that the build doesn't fail on systems
that do not have a unix shell.

* [semihosting] Rename variable for semihosting compilation.

* [semihosting] Move the cmake configuration to a variable file.

* [semihosting] Make the guard macro private for the core module.

* [semihosting] Remove space. [NFC]

* [semihosting] Improve comment with information about semihosting. [NFC]

* [semihosting] Update license statement on top of sourvce file. [NFC]

* [semihosting] Replace BM_SUFFIX with SEMIHOSTING_SUFFIX. [NFC]

* [semihosting] Remove double space. [NFC]

* [semihosting] Add some text output to the sample applications.

* [semihosting] Remove duplicate entry in cmake configuration. [NFCI]

* [semihosting] Replace `long` with `int` in sample apps. [NFCI]

* [semihosting] Use `configure_file` to create the random pixels. [NFCI]

* [semihosting][bugfix] Fix name of cmakedefine variable.

* [semihosting][samples] Use CV_8UC1 for grayscale images. [NFCI]

* [semihosting] Add readme file.

* [semihosting] Remove blank like at the end of README. [NFC]

This fixes the failure at
https://pullrequest.opencv.org/buildbot/builders/precommit_docs/builds/31272.
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.

4 participants