Skip to content

Fix heap init error in rtos-less code #10078

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 26, 2019

Conversation

ccli8
Copy link
Contributor

@ccli8 ccli8 commented Mar 13, 2019

Description

This PR tries to fix heap initialization error in rtos-less code on ARM/ARMC6 toolchain. In rtos-less code, HEAP_START is defined in target mbed_rtx.h but not passed to _mbed_user_setup_stackheap or __rt_lib_init in mbed_retarget.cpp. The default defines for HEAP_START/HEAP_SIZE are for single-region targets. Heap initialization error will occur on two-region targets. We cannot include mbed_rtx.h in mbed_retarget.cpp because Mbed 2 targets don't provide it. Instead, this PR approaches it by weak reference to ARM_LIB_HEAP. Heap definition is fixed if ARM_LIB_HEAP is defined.

Pull request type

[X] Fix
[ ] Refactor
[ ] Target update
[ ] Functionality change
[ ] Docs update
[ ] Test update
[ ] Breaking change

Release Notes

On ARM/ARMC6 toolchain, fix heap initialization error for two-region memory model (ARM_LIB_HEAP + ARM_LIB_STACK) in rtos-less code. Original implementation just supports one-region memory model (ARM_LIB_STACK). This release fixes for two-region memory model.

@ciarmcom
Copy link
Member

@ccli8, thank you for your changes.
@ARMmbed/mbed-os-core @ARMmbed/mbed-os-maintainers please review.

@ciarmcom ciarmcom requested review from a team March 13, 2019 12:00
@0xc0170
Copy link
Contributor

0xc0170 commented Mar 15, 2019

Fix looks fine to me but having mbed_rtx include in platform does not much. This is the header file that defines stack and heap macros.
This might require additional refactor if that would be the case.

@ccli8
Copy link
Contributor Author

ccli8 commented Mar 27, 2019

Any update? How about make it "right" first and then refactor?

@cmonr
Copy link
Contributor

cmonr commented Mar 27, 2019

@ARMmbed/mbed-os-core @ARMmbed/mbed-os-hal Please review.

@cmonr cmonr requested a review from a team March 27, 2019 21:55
@ccli8
Copy link
Contributor Author

ccli8 commented Apr 8, 2019

Any update?

@0xc0170
Copy link
Contributor

0xc0170 commented Apr 8, 2019

CI started

@mbed-ci
Copy link

mbed-ci commented Apr 8, 2019

Test run: FAILED

Summary: 2 of 9 test jobs failed
Build number : 1
Build artifacts

Failed test jobs:

  • jenkins-ci/mbed-os-ci_mbed2-build-IAR8
  • jenkins-ci/mbed-os-ci_mbed2-build-GCC_ARM

@0xc0170
Copy link
Contributor

0xc0170 commented Apr 8, 2019

@mprse The above failures for mbed 2 - INITIAL_SP not defined for few targets. There was a consolidation of the stack pointer recently.
Can you review the failures above why are few targets failing now?

@0xc0170
Copy link
Contributor

0xc0170 commented Apr 10, 2019

I am slightly confused about mbed_rtx.h. and what it defines. It was created for Mbed OS 5, not Mbed 2. Thus including this by default results in some failures (some mbed 2 targets do not define INITIAL_SP). Thus we get these failures. Before we add these missing values, what about heap macros?

Also not all targets define them in mbed_rtx.h - is this documented ?

cc @deepikabhavnani

@0xc0170
Copy link
Contributor

0xc0170 commented Apr 10, 2019

NUCLEO_F030R8/
NUCLEO_F031K6/
NUCLEO_F042K6/
SAMD21G18A/
SAMD21J18A/
SAMR21G18A/

These targets are failing to build.
@ARMmbed/team-st-mcd Can you review these nucleos, why they do not define INITIAL_SP?

@jeromecoutant
Copy link
Collaborator

Can you review these nucleos, why they do not define INITIAL_SP?

Because they are not OS5, only OS2

@0xc0170
Copy link
Contributor

0xc0170 commented Apr 10, 2019

@ccli8 Would it be other way to fix this ? Pulling this header file has implications for mbed 2 targets.

Heap definitions should be placed somewhere else and pulled in to retarget.

@jeromecoutant
Copy link
Collaborator

See #9626: "INITIAL_SP definition is no more used (since #9092)"

@0xc0170
Copy link
Contributor

0xc0170 commented Apr 10, 2019

Thanks, missed that one today.

@ccli8 Would it be other way to fix this ? Pulling this header file has implications for mbed 2 targets.

@deepikabhavnani how to address this?

@mprse
Copy link
Contributor

mprse commented Apr 10, 2019

Generally, there is a problem with Mbed 2 and ARM compiler builds for targets which specify ARM_LIB_HEAP/ARM_LIB_STACK regions in scatter files. Is that correct?

The default defines for HEAP_START/HEAP_SIZE are for single-region targets:

#if !defined(HEAP_START)
// Heap here is considered starting after ZI ends to Stack start
extern uint32_t Image$$ARM_LIB_STACK$$ZI$$Base[];
extern uint32_t Image$$RW_IRAM1$$ZI$$Limit[];
#define HEAP_START Image$$RW_IRAM1$$ZI$$Limit
#define HEAP_SIZE ((uint32_t)((uint32_t) Image$$ARM_LIB_STACK$$ZI$$Base - (uint32_t) HEAP_START))
#endif
#define HEAP_LIMIT ((uint32_t)((uint32_t)HEAP_START + (uint32_t)HEAP_SIZE))

As far as I remember we assumed that by default only stack region is specified in the scatter files and then default defines are used(from mbed_retarget.cpp). Targets with two regions defined(ARM_LIB_HEAP and ARM_LIB_STACK) need to specify their own HEAP_START/HEAP_SIZE macros (usually in mbed_rtx.h).

Now since HEAP_START/HEAP_SIZE macros are defined in mbed_rtx.h we don't have them in case of Mbed 2 builds. This causes a failure in case of scatter files with two regions defined.

@mprse
Copy link
Contributor

mprse commented Apr 10, 2019

Personally, I think that we should add ARM_LIB_HEAP to all scatter files. Then we could remove all HEAP_*, STACK_* macros from mbed_rtx.h and relay only on linker symbols.

@deepikabhavnani
Copy link

Personally, I think that we should add ARM_LIB_HEAP to all scatter files. Then we could remove all HEAP_, STACK_ macros from mbed_rtx.h and relay only on linker symbols.

I will agree with @mprse on this, we should add ARM_LIB_HEAP to all scatter files and remove dependency of mbed_rtx.h.

In rtos-less code, heap is defined by assuming one-region. Through weak-reference to
ARM_LIB_HEAP, heap definition is fixed if ARM_LIB_HEAP is defined.
@ccli8 ccli8 force-pushed the nuvoton_fix-heap-in-rtosless branch from 41578f1 to 64515c0 Compare April 12, 2019 06:40
@ccli8
Copy link
Contributor Author

ccli8 commented Apr 12, 2019

I make the following modifications:

  1. Drop including mbed_rtx.h because Mbed 2 targets don't provide it.
  2. Through weak-reference to ARM_LIB_HEAP, heap definition is fixed if ARM_LIB_HEAP is defined.

@ccli8
Copy link
Contributor Author

ccli8 commented Apr 18, 2019

Any update?

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.

Looks fine to me. It would help to describe this via "Release notes" section (add it to your first comment here). This section will be added to the release notes.

@0xc0170
Copy link
Contributor

0xc0170 commented Apr 18, 2019

I restarted travis, CI will be started once approved.

Copy link
Contributor

@mprse mprse left a comment

Choose a reason for hiding this comment

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

👍

Copy link

@deepikabhavnani deepikabhavnani 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 change 👍

@ccli8
Copy link
Contributor Author

ccli8 commented Apr 19, 2019

Added "Release Notes" section.

@adbridge
Copy link
Contributor

ci started

@mbed-ci
Copy link

mbed-ci commented Apr 26, 2019

Test run: SUCCESS

Summary: 11 of 11 test jobs passed
Build number : 3
Build artifacts

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.

10 participants