# How can I apply patches about Nuttx

**URL:** <https://discuss.px4.io/t/how-can-i-apply-patches-about-nuttx/8642>\
**Category:** Uncategorized\
**Created:** [November 27, 2018, 8:53am UTC](https://discuss.px4.io/t/how-can-i-apply-patches-about-nuttx/8642 "2018-11-27T08:53:38Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kyuhyong\_You](https://discuss.px4.io/user_avatar/discuss.px4.io/kyuhyong_you/32/2210_2.png) [@Kyuhyong\_You](https://discuss.px4.io/u/Kyuhyong_You)\
**Post date:** [November 27, 2018, 8:53am UTC](https://discuss.px4.io/t/how-can-i-apply-patches-about-nuttx/8642/1 "2018-11-27T08:53:38Z")

</div>

Hi all,

I found some recent patches and updates for Nuttx here [GitHub - PX4/NuttX: Standard NuttX with current PX4 patches](https://github.com/PX4/NuttX) and would like to update  
my local branch.  
Is this is something can be done by simply replacing contents of /platforms/nuttx/Nuttx folder with new one?  
The reason for this is to make sure nuttx runs more reliable with no further delays in running apps.  
I see some jitter in time dt in some estimators, controllers.

Kyu

---

<div class="post-metadata">

**Author:** ![JulianOes](https://discuss.px4.io/user_avatar/discuss.px4.io/julianoes/32/30_2.png) [@JulianOes](https://discuss.px4.io/u/JulianOes)\
**Post date:** [November 27, 2018, 9:10am UTC](https://discuss.px4.io/t/how-can-i-apply-patches-about-nuttx/8642/2 "2018-11-27T09:10:50Z")

</div>

Hi Kyu,

From what I know, you could just go into the nuttx directory and get the latest like that:

```auto
cd platforms/nuttx/NuttX/nuttx
git fetch
git checkout master
git merge

```

This would mean that you’re using the latest master of PX4/NuttX, however, it also means that you’re running an untested state (if it even compiles). Generally, NuttX updates will go into the Firmware after a while, usually after a release is out and riskier changes can get in again.

If you plan to do serious testing and/or want to help with NuttX updates, make sure to also coordinate with @david_s5 who is usually driving this.

---

<div class="post-metadata">

**Author:** ![Kyuhyong\_You](https://discuss.px4.io/user_avatar/discuss.px4.io/kyuhyong_you/32/2210_2.png) [@Kyuhyong\_You](https://discuss.px4.io/u/Kyuhyong_You)\
**Post date:** [November 27, 2018, 12:18pm UTC](https://discuss.px4.io/t/how-can-i-apply-patches-about-nuttx/8642/3 "2018-11-27T12:18:03Z")

</div>

Hi @JulianOes,  
Thanks for your comment. I was able to update nuttx and successfully build after  
git submodule update --init --recursive  
Seems like flying itself is just as before though CPU usage downed a little bit.

Kyu

---

<div class="post-metadata">

**Author:** ![JulianOes](https://discuss.px4.io/user_avatar/discuss.px4.io/julianoes/32/30_2.png) [@JulianOes](https://discuss.px4.io/u/JulianOes)\
**Post date:** [November 27, 2018, 12:48pm UTC](https://discuss.px4.io/t/how-can-i-apply-patches-about-nuttx/8642/4 "2018-11-27T12:48:52Z")

</div>

If you do:

> [@Kyuhyong\_You](#):
>
> git submodule update --init --recursive

Then you’re essentially resetting the change you just did in the submodule and you are not testing any changes.  
Try `git status` to check what your source tree looks like and what submodules you have checked out, or use `export GIT_SUBMODULES_ARE_EVIL=1` to prevent the git submodule auto check to come up.

---

<div class="post-metadata">

**Author:** ![david\_s5](https://discuss.px4.io/user_avatar/discuss.px4.io/david_s5/32/4160_2.png) [@david\_s5](https://discuss.px4.io/u/david_s5)\
**Post date:** [November 27, 2018, 4:41pm UTC](https://discuss.px4.io/t/how-can-i-apply-patches-about-nuttx/8642/5 "2018-11-27T16:41:40Z")

</div>

@Kyuhyong_You,

I will be working on a branch over the next few weeks that will build PX4 on the most recent NuttX master.

---

<div class="post-metadata">

**Author:** ![Kyuhyong\_You](https://discuss.px4.io/user_avatar/discuss.px4.io/kyuhyong_you/32/2210_2.png) [@Kyuhyong\_You](https://discuss.px4.io/u/Kyuhyong_You)\
**Post date:** [November 28, 2018, 2:10am UTC](https://discuss.px4.io/t/how-can-i-apply-patches-about-nuttx/8642/6 "2018-11-28T02:10:45Z")

</div>

Ok I checked my branch on platforms/nuttx/NuttX/nuttx  
and it returns

> HEAD detached at 0ac630e  
> nothing to commit, working directory clean

So I redo

> ```
> git fetch
> git checkout master
> 
> ```

and I got these error

> Previous HEAD position was 0ac630e… [BACKPORT] Merged in david\_s5/nuttx/master\_kinetis\_usb\_fixes (pull request #634)  
> Switched to branch ‘master’  
> Your branch is behind ‘origin/master’ by 8 commits, and can be fast-forwarded.  
> (use “git pull” to update your local branch)

So I git pull again end up getting

> Updating d8cf3bf…5da7dba  
> Fast-forward  
> arch/arm/src/armv7-m/dwt.h | 210 ++++++++++±--------  
> arch/arm/src/armv7-m/itm.h | 137 ++++++±-----  
> arch/arm/src/armv7-m/tpi.h | 220 +++++++++++±--------  
> arch/arm/src/armv7-m/up\_itm.c | 4 ±  
> arch/arm/src/armv7-m/up\_itm\_syslog.c | 2 ±  
> arch/arm/src/lpc54xx/lpc54\_lowputc.c | 60 ±----  
> arch/arm/src/max326xx/common/max326\_start.c | 4 +  
> …/src/max326xx/max32660/max32660\_clockconfig.c | 4 ±  
> arch/arm/src/max326xx/max32660/max32660\_gpio.c | 4 ±  
> arch/arm/src/max326xx/max32660/max32660\_gpio.h | 2 ±  
> arch/arm/src/max326xx/max32660/max32660\_lowputc.c | 24 ±-  
> arch/arm/src/max326xx/max32660/max32660\_serial.c | 12 ±  
> configs/max32660-evsys/README.txt | 64 ++++±  
> configs/max32660-evsys/scripts/Make.defs | 4 +  
> configs/max32660-evsys/scripts/sram.ld | 115 +++++++++++  
> configs/stm32f4discovery/src/stm32\_critmon.c | 9 ±  
> net/socket/net\_clone.c | 6 +  
> net/socket/net\_close.c | 2 ±  
> net/socket/net\_sockets.c | 6 ±  
> net/socket/socket.h | 4 ±  
> wireless/bluetooth/bt\_att.c | 9 ±  
> 21 files changed, 551 insertions(+), 351 deletions(-)  
> create mode 100644 configs/max32660-evsys/scripts/sram.ld

Then I can git checkout master

> Already on ‘master’  
> Your branch is up-to-date with ‘origin/master’.

To rebuild I make clean and did **$ export GIT\_SUBMODULES\_ARE\_EVIL=1** thing followed by make again  
Now it gives bunch of submodule skipping message as follows

> GIT\_SUBMODULES\_ARE\_EVIL is defined - Skipping submodules tools/gencpp update.  
> GIT\_SUBMODULES\_ARE\_EVIL is defined - Skipping submodules tools/genmsg update.  
> GIT\_SUBMODULES\_ARE\_EVIL is defined - Skipping submodules src/lib/DriverFramework update.  
> GIT\_SUBMODULES\_ARE\_EVIL is defined - Skipping submodules ecl update.  
> GIT\_SUBMODULES\_ARE\_EVIL is defined - Skipping submodules matrix update.  
> – PX4 ECL: Very lightweight Estimation & Control Library v0.9.0-521-g3077e6a  
> GIT\_SUBMODULES\_ARE\_EVIL is defined - Skipping submodules devices update.  
> GIT\_SUBMODULES\_ARE\_EVIL is defined - Skipping submodules /home/dronedev/workspace/pitta/px4/fw/cf\_px4\_origin/mavlink/include/mavlink/v2.0 update.  
> GIT\_SUBMODULES\_ARE\_EVIL is defined - Skipping submodules nuttx update.  
> GIT\_SUBMODULES\_ARE\_EVIL is defined - Skipping submodules apps update.  
> – NuttX: crazyflie nsh cortex-m4  
> – ROMFS: px4fmu\_common  
> – Configuring done  
> – Generating done  
> – Build files have been written to: /home/dronedev/workspace/pitta/px4/fw/cf\_px4\_origin/build/crazyflie\_default  
> [10/506] git submodule ecl  
> GIT\_SUBMODULES\_ARE\_EVIL is defined - Skipping submodules ecl update.  
> [11/506] git submodule devices  
> GIT\_SUBMODULES\_ARE\_EVIL is defined - Skipping submodules devices update.  
> [12/506] git submodule /home/dronedev/…x4\_origin/mavlink/include/mavlink/v2.0  
> GIT\_SUBMODULES\_ARE\_EVIL is defined - Skipping submodules /home/dronedev/workspace/pitta/px4/fw/cf\_px4\_origin/mavlink/include/mavlink/v2.0 update.  
> [12/506] git submodule apps  
> GIT\_SUBMODULES\_ARE\_EVIL is defined - Skipping submodules apps update.  
> [12/506] git submodule nuttx  
> GIT\_SUBMODULES\_ARE\_EVIL is defined - Skipping submodules nuttx update.  
> [506/506] Creating /home/dronedev/work…razyflie\_default/crazyflie\_default.px4

Anyway it can rebuild just fine but not sure if I did all things right.  
Is there any way to check the current build or version of nuttx in nsh?  
@JulianOes Thank you for helping me out.

Kyu

–  
Added  
I still see git status shows  
HEAD detached at 0ac630e  
Which is not what current master shows as 166d898

---

<div class="post-metadata">

**Author:** ![JulianOes](https://discuss.px4.io/user_avatar/discuss.px4.io/julianoes/32/30_2.png) [@JulianOes](https://discuss.px4.io/u/JulianOes)\
**Post date:** [November 28, 2018, 8:32am UTC](https://discuss.px4.io/t/how-can-i-apply-patches-about-nuttx/8642/7 "2018-11-28T08:32:08Z")

</div>

Ok, I would start fresh like this:

```auto
cd Firmware
git checkout master
git pull
git submodule update --init --recursive

```

All is clean now:

```auto
git status
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean

```

Then I would go into the Nuttx directory and get the latest master there:

```auto
cd platforms/nuttx/NuttX/nuttx
git checkout master
git pull

```

NuttX is now at 5da7dba like you.

Then I go back and the status looks like this:

```auto
cd ../../../..

git status
On branch master
Your branch is up to date with 'origin/master'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

	modified: platforms/nuttx/NuttX/nuttx (new commits)

```

So, this tells me the NuttX submodule has now new commits, so is different from what the reference is by default.

Now it’s probably a good idea to do a clean builld:

```auto
export GIT_SUBMODULES_ARE_EVIL=1
make clean
make px4fmu-v2_default

```

The build fails, presumably there were some changes that need some work for the Firmware:

```auto
[3%] Copying NuttX/nuttx to /home/julianoes/src/Firmware-master/build/px4_fmu-v2_default/NuttX
cp: cannot create directory 'build/px4_fmu-v2_default/NuttX/nuttx/configs/stm32butterfly2/include': File exists
cp: cannot create directory 'build/px4_fmu-v2_default/NuttX/nuttx/configs/stm32f334-disco/include': File exists
cp: cannot create directory 'build/px4_fmu-v2_default/NuttX/nuttx/configs/stm32f334-disco/nsh': File exists
cp: cannot create directory 'build/px4_fmu-v2_default/NuttX/nuttx/configs/stm32f334-disco/scripts': File exists
cp: cannot create directory 'build/px4_fmu-v2_default/NuttX/nuttx/configs/stm32f3discovery/include': File exists
cp: cannot create directory 'build/px4_fmu-v2_default/NuttX/nuttx/configs/stm32f3discovery/nsh': File exists
...

```

Now it’s probably a good idea to wait for @david_s5 to create a branch to try this, as he wrote above:

> I will be working on a branch over the next few weeks that will build PX4 on the most recent NuttX master.

---

<div class="post-metadata">

**Author:** ![david\_s5](https://discuss.px4.io/user_avatar/discuss.px4.io/david_s5/32/4160_2.png) [@david\_s5](https://discuss.px4.io/u/david_s5)\
**Post date:** [November 28, 2018, 12:04pm UTC](https://discuss.px4.io/t/how-can-i-apply-patches-about-nuttx/8642/8 "2018-11-28T12:04:16Z")

</div>

Hi @JulianOes and @Kyuhyong_You

From 7.22 to 7.27+ Nuttx There are a lot of deltas in features and functionality and the way nuttx is configured and it’s build works. I have got one board to the link stage. Once that is resolved, I need to test. Then filter the deltas by board and apply and test those changes. Then I will push a WIP set of branches. (Nuttx:nuttx, apps and PX4 on 7.27+)
