Skip to content

Update Mbed 5 boot sequence #7794

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 2 commits into from
Aug 30, 2018
Merged

Update Mbed 5 boot sequence #7794

merged 2 commits into from
Aug 30, 2018

Conversation

c1728p9
Copy link
Contributor

@c1728p9 c1728p9 commented Aug 14, 2018

Description

Refactor the Mbed 5 boot process to make is simpler and more modular. This is done by breaking the boot sequence into 4 distinct steps - Target setup, Toolchain setup, RTOS setup and Mbed setup. This patch also move toolchain specific code into a per toolchain folder to make it more maintainable.

Pull request type

[ ] Fix
[x] Refactor
[ ] Target update
[ ] Feature
[ ] Breaking change

@c1728p9 c1728p9 requested review from mprse and bulislaw August 14, 2018 22:32
@c1728p9
Copy link
Contributor Author

c1728p9 commented Aug 15, 2018

Docs for this change can be found here:
ARMmbed/mbed-os-5-docs#662

@amq
Copy link
Contributor

amq commented Aug 15, 2018

Is this related? #7382

@c1728p9
Copy link
Contributor Author

c1728p9 commented Aug 15, 2018

this is unrelated

Copy link
Contributor

@bridadan bridadan left a comment

Choose a reason for hiding this comment

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

I realize I'm not on the reviewers list but I was perusing some of the PRs and noticed a couple of comment oopsies in this one! Very cool change though!

/**
* SDK hook for running code before ctors or OS
*
* This is a weak function which can be overridden at by a target's
Copy link
Contributor

Choose a reason for hiding this comment

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

English nit:

This is a weak function which can be overridden at by a target's

should probably just be "by".

/**
* Application hook for running code before main
*
* This is a weak function which can be overridden at by an application
Copy link
Contributor

Choose a reason for hiding this comment

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

English nit:

This is a weak function which can be overridden at by an application

should probably just be "by".

@c1728p9
Copy link
Contributor Author

c1728p9 commented Aug 15, 2018

Thanks for the review @bridadan. I update the PR to fix those typos.

@@ -43,6 +43,10 @@ extern osMutexId_t singleton_mutex_id;
inline static void singleton_lock(void)
{
#ifdef MBED_CONF_RTOS_PRESENT
if (!singleton_mutex_id) {
// RTOS has not booted yet so no mutex is needed
return;

Choose a reason for hiding this comment

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

Should we throw an MBED_ERROR here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nope, this case is expected to be hit early in the boot sequence when when the RTOS has not yet started.

Copy link
Collaborator

Choose a reason for hiding this comment

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

It does seem to be the case for STM boards...


/* Define stack sizes if they haven't been set already */
#if !defined(ISR_STACK_SIZE)
#define ISR_STACK_SIZE ((uint32_t)1024)

Choose a reason for hiding this comment

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

Define is used by ARM and GCC_ARM toolchain, can we move it to "mbed_boot.h" ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

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... this was much needed refactoring 👍


void mbed_toolchain_init()
{
#if defined(MBED_CONF_RTOS_PRESENT)
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we need this checks, nothing in rtos/ folder will be compiled in if the RTOS is disabled.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -0,0 +1,159 @@
/* mbed Microcontroller Library
Copy link
Member

Choose a reason for hiding this comment

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

You are using doxy, but it's not going to be anchored nicely. Is it worth creating a group and turning all the comments (even the file global one) into doxy?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

* - The RTOS has been started by a call to mbed_rtos_start
* - The toolchain has been initialized by a call to mbed_toolchain_init
*/
void mbed_main(void);
Copy link
Member

Choose a reason for hiding this comment

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

I'm guessing for compatibility reasons that need to stay, but from the conceptual point of view it doesn't have much sense as it's run from the same context than main. Would it make sense to add app entry point before RTOS and target entry point after RTOS?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It would be easy to add these hooks, although I would be hesitant to add them without having a use case in mind.

}

osKernelStart();
while (1); // Code should never get here
Copy link
Member

Choose a reason for hiding this comment

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

Actually should we assert/error out here, rather than spin forever in case something goes wrong in RTX?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@c1728p9
Copy link
Contributor Author

c1728p9 commented Aug 21, 2018

I made the following changes:

  • Removed detailed boot procedure from mbed_boot.c since this is no longer relevent
  • Added doxygen group to mbed_boot.h
  • Added error if RTOS initialization fails
  • Moved ISR_STACK_SIZE into mbed_boot.h
  • Remove define MBED_CONF_RTOS_PRESENT

@andrewleech
Copy link
Contributor

I really like your goal and work you've done here.
I've often found it incredibly hard to trace through the startup procedure, especially on new boards/targets when there's problems getting to main for any variety of reasons.

This is probably outside your desired scope, but would it take much effort to add an mbed config system entry to disable rtos aka: #7800

I regularly need to run mbed without the rtos on smaller targets that do not have enough ram/flash to support the os.

Currently the only way I know of to do this is adding the rtos and events libraries to .mbedignore

mbed-os/rtos/*
mbed-os/events/*

Unfortunately, I just tested this with this PR and it no longer works.

Compile [  0.3%]: main.cpp
[Fatal Error] Mutex.h@26,23: cmsis_os2.h: No such file or directory
[ERROR] In file included from ./mbed-os/features/netsocket/InternetSocket.h:25:0,
                 from ./mbed-os/features/netsocket/UDPSocket.h:23,
                 from ./mbed-os/features/netsocket/nsapi.h:40,
                 from ./mbed-os/mbed.h:26,
                 from .\main.cpp:1:
./mbed-os/rtos/Mutex.h:26:23: fatal error: cmsis_os2.h: No such file or directory
 #include "cmsis_os2.h"
                       ^
compilation terminated.

It would be great if you could make a better supported method of disabling the rtos!

@andrewleech
Copy link
Contributor

In case it wasn't clear in my last message,
This PR breaks the ability to run mbed with rtos disabled.

This may not be a particularly supported use case, but it is a critical need for many applications.

@0xc0170
Copy link
Contributor

0xc0170 commented Aug 23, 2018

@andrewleech Thanks for the feedback. This is supported use case (this approach could be found in the issues/questions - its being used).

From your error log, what does main.cpp contain? The error comes from there. How to reproduce this failure? Looking at the changes here, I do not see where this would break it.

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 - nice cleanup!

From the changes, this only touches rtos, not certain how this affects non rtos build as reported above. Please review it

@andrewleech
Copy link
Contributor

@0xc0170 It was a new project, fresh clone of mbed os with this branch checked out (0e7c3bfa) and the basic hello world main.cpp

#include "mbed.h"
 
DigitalOut myled(LED1);
 
int main() {
    while(1) {
        myled = 1;
        wait(0.2);
        myled = 0;
        wait(0.2);
    }
}

I tried compiling (I think for NRF52_DK) with .mbedignore as above and got that error. Stuck a '#' in front of both lines and it compiled fine.

Just tried it again, mbed compile --clean -m NRF52_DK with and without the lines commented, same result.

@bridadan
Copy link
Contributor

@0xc0170 The problem is probably the inclusion of rtos related headers in the toolchain boot source files. These rtos headers won't be present if the rtos directory is being ignored.

@deepikabhavnani
Copy link

deepikabhavnani commented Aug 23, 2018

@andrewleech

I tried non-rtos build with blinky and shared .mbedignore and noted issue exists on the master branch as well. Our network interfaces are dependent on rtos, agree we have not done great job in separating those and adding appropriate errors.

You can add a separate issue to mbed-os to take care of this in future. For now non-rtos blinky works with below:

mbed-os/rtos/*
mbed-os/events/*
mbed-os/features/*

@0xc0170
Copy link
Contributor

0xc0170 commented Aug 24, 2018

Thanks @deepikabhavnani . Please review and leave feedback here. We can start CI soon

@andrewleech Please create an issue, we shall fix it !

@andrewleech
Copy link
Contributor

I'm so sorry I forgot to check master build as well, @c1728p9 sorry for the distraction. I love what you've done here.

@c1728p9
Copy link
Contributor Author

c1728p9 commented Aug 29, 2018

Fixed ARM failures

@cmonr
Copy link
Contributor

cmonr commented Aug 29, 2018

/morph build

@mbed-ci
Copy link

mbed-ci commented Aug 29, 2018

Build : SUCCESS

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

Triggering tests

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

@mbed-ci
Copy link

mbed-ci commented Aug 29, 2018

@mbed-ci
Copy link

mbed-ci commented Aug 29, 2018

@0xc0170
Copy link
Contributor

0xc0170 commented Aug 29, 2018

There's one device that hard faults, please verify

@cmonr
Copy link
Contributor

cmonr commented Aug 29, 2018

@c1728p9 Fyi ^^^

@cmonr
Copy link
Contributor

cmonr commented Aug 29, 2018

/morph build

@cmonr
Copy link
Contributor

cmonr commented Aug 29, 2018

Crud. Only meant to retest... Oh well.

@mbed-ci
Copy link

mbed-ci commented Aug 29, 2018

Build : SUCCESS

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

Triggering tests

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

@mbed-ci
Copy link

mbed-ci commented Aug 29, 2018

@cmonr
Copy link
Contributor

cmonr commented Aug 29, 2018

GnuArmEclipse had an error initializing storage... Huh.
/morph export-build

@cmonr
Copy link
Contributor

cmonr commented Aug 29, 2018

Reshuffling the Integration Test queue. Will restart shortly.

@mbed-ci
Copy link

mbed-ci commented Aug 29, 2018

@cmonr
Copy link
Contributor

cmonr commented Aug 29, 2018

Fatal error: A1023E: File "/tmp/filetQiJyd" could not be opened: No such file or directory

This is less than useful...

/morph export-build

@mbed-ci
Copy link

mbed-ci commented Aug 30, 2018

@0xc0170
Copy link
Contributor

0xc0170 commented Aug 30, 2018

/morph export-build
/morph test

@0xc0170
Copy link
Contributor

0xc0170 commented Aug 30, 2018

/morph test

@mbed-ci
Copy link

mbed-ci commented Aug 30, 2018

@mbed-ci
Copy link

mbed-ci commented Aug 30, 2018

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.