Skip to content

sys: stdio_null: add null driver#10741

Merged
aabadie merged 2 commits intoRIOT-OS:masterfrom
basilfx:feature/stdio_null
Dec 3, 2019
Merged

sys: stdio_null: add null driver#10741
aabadie merged 2 commits intoRIOT-OS:masterfrom
basilfx:feature/stdio_null

Conversation

@basilfx
Copy link
Member

@basilfx basilfx commented Jan 9, 2019

Contribution description

This PR provides a null driver for STDIO, so that it doesn't depend on UART or RTT.

I created this to test #10215, where the bootloader easily exceeds the default 4KiB on EFM32 targets, because due to periph_uart still being included (which includes other big stuff). With this null driver, I could save an additional 2KiB. This makes sense for something like a bootloader, but anything that depends on reading from UART will break.

I've added a warning with DEVELHELP=1, because I assume you enabled it to show some output.

It took me five minutes to create, so if this doesn't make any sense, that I don't feel bad ;-)

Testing procedure

Add USEMODULE=stdio_null to any application to see what it saves. In particular, add this to bootloaders/riotboot/Makefile and observe that tests/riotboot still works.

Here is an example for tests/minimal.

As usual:

basilfx:minimal/ (feature/stdio_null) $ BOARD=samr21-xpro make -j8
Building application "tests_minimal" for "samr21-xpro" with MCU "samd21".

"make" -C boards/samr21-xpro
"make" -C core
"make" -C cpu/samd21
"make" -C drivers
"make" -C sys
"make" -C cpu/cortexm_common
"make" -C cpu/sam0_common
"make" -C cpu/samd21/periph
"make" -C sys/isrpipe
"make" -C drivers/periph_common
"make" -C sys/newlib_syscalls_default
"make" -C cpu/sam0_common/periph
"make" -C cpu/cortexm_common/periph
"make" -C sys/pm_layered
"make" -C sys/stdio_uart
"make" -C sys/tsrb
   text	   data	    bss	    dec	    hex	filename
   3260	     36	   2604	   5900	   170c	tests/minimal/bin/samr21-xpro/tests_minimal.elf

With USEMODULE=stdio_null:

basilfx:minimal/ (feature/stdio_null) $ USEMODULE=stdio_null BOARD=samr21-xpro make -j8
Building application "tests_minimal" for "samr21-xpro" with MCU "samd21".

"make" -C boards/samr21-xpro
"make" -C core
"make" -C cpu/samd21
"make" -C drivers
"make" -C sys
"make" -C cpu/cortexm_common
"make" -C drivers/periph_common
"make" -C sys/isrpipe
"make" -C cpu/sam0_common
"make" -C cpu/sam0_common/periph
"make" -C sys/newlib_syscalls_default
"make" -C sys/pm_layered
"make" -C cpu/samd21/periph
"make" -C sys/stdio_null
"make" -C sys/stdio_uart
"make" -C sys/tsrb
"make" -C cpu/cortexm_common/periph
   text	   data	    bss	    dec	    hex	filename
   2232	     16	   2524	   4772	   12a4	tests/minimal/bin/samr21-xpro/tests_minimal.elf

With DEVELHELP=1 USEMODULE=stdio_null:

basilfx:minimal/ (feature/stdio_null) $ DEVELHELP=1 USEMODULE=stdio_null BOARD=samr21-xpro make -j8
Building application "tests_minimal" for "samr21-xpro" with MCU "samd21".

"make" -C boards/samr21-xpro
"make" -C core
"make" -C cpu/samd21
"make" -C drivers
"make" -C sys
"make" -C cpu/cortexm_common
"make" -C cpu/sam0_common
"make" -C cpu/sam0_common/periph
"make" -C sys/newlib_syscalls_default
"make" -C drivers/periph_common
"make" -C cpu/samd21/periph
"make" -C sys/pm_layered
"make" -C cpu/cortexm_common/periph
"make" -C sys/stdio_null
Makefile:2: STDIO disabled via stdio_null, but DEVELHELP enabled
   text    data     bss     dec     hex filename
  10088     120    2532   12740    31c4 tests/minimal/bin/samr21-xpro/tests_minimal.elf

Issues/PRs references

#9503
#10215

@basilfx basilfx added Type: new feature The issue requests / The PR implemements a new feature for RIOT CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Jan 9, 2019
smlng
smlng previously requested changes Jan 10, 2019
@miri64
Copy link
Member

miri64 commented Jan 10, 2019

I don't understand. Why not just exclude the stdio_uart module?

@basilfx
Copy link
Member Author

basilfx commented Jan 10, 2019

That produces the following error (using origin/master):

basilfx:minimal/ (master) $ DISABLE_MODULE=stdio_uart BOARD=slstk3402a make -j4
Required modules were disabled using DISABLE_MODULE: stdio_uart


EXPECT ERRORS!


tests/minimal/../../Makefile.include:736: tests/minimal/bin/slstk3402a/stdio_uart.a
tests/minimal/../../Makefile.include:738: *** BASELIBS value changed.  Stop.

There is a hard dependency on stdio_init():

@miri64
Copy link
Member

miri64 commented Jan 10, 2019

There is a hard dependency on stdio_init():

Is it possible to remove that dependency instead?

@basilfx
Copy link
Member Author

basilfx commented Jan 10, 2019

Is it possible to remove that dependency instead?

Probably. But I don't know the impact on existing applications. First of all, vfs_bind_stdio() is still invoked from stdio_init(), so I guess it will break any application that writes to file descriptor 0, 1 or 3.

To me, this optional driver is similar to telling an application to write to /dev/null, without changing the application to remove everything related to reading/writing to stdio.

It's a self-contained alternative. Otherwise we would have to do a lot of #ifdefs anywhere we use stdio_%.

@kaspar030
Copy link
Contributor

Is it possible to remove that dependency instead?

"I have a branch(tm)". Disabling stdio completely needs some ground work. I'll start PR'ing.

@miri64
Copy link
Member

miri64 commented Jan 10, 2019

Probably. But I don't know the impact on existing applications. First of all, vfs_bind_stdio() is still invoked from stdio_init(), so I guess it will break any application that writes to file descriptor 0, 1 or 3.

To me, this optional driver is similar to telling an application to write to /dev/null, without changing the application to remove everything related to reading/writing to stdio.

It's a self-contained alternative. Otherwise we would have to do a lot of #ifdefs anywhere we use stdio_%.

Ok, right. As an optional alternative I am fine with this approach. Nevertheless, we should investigate if an alternative without any dependency to stdio (but without #ifdefs around every printf()) is viable.

@kaspar030
Copy link
Contributor

Nevertheless, we should investigate if an alternative without any dependency to stdio (but without #ifdefs around every printf()) is viable.

Well, one way is to use LOG_ macros instead of printf, as they can be disabled completely. Dropping stdio_uart and periph/uart goes a long way, but being able to also drop newlib's stdio code has the most wins...

+1 for adding this, even if the only user is the bootloader on EFM32.

@basilfx basilfx force-pushed the feature/stdio_null branch from 04f15bd to 43adad8 Compare January 10, 2019 13:31
@basilfx
Copy link
Member Author

basilfx commented Jan 10, 2019

I fixed the comments by @smlng and I also committed 43adad8 to ensure Makefile.dep doesn't compile stdio_uart whenever stdio_rtt or stdio_null is selected. That was still the case.

@jcarrano
Copy link
Contributor

I added commit to #9258 (this one) that provides this same functionality, but without adding a null driver. Instead I intercept read() and write() (actually, the reentrant versions). I think it is important to be honest about the fact that it is a stub and set error codes appropriately.

Space savings are similar, but I need to rebase my branch on top of yours to do a proper comparison.

@danpetry
Copy link
Contributor

Personally I think that we should look at working on a full solution rather than a quick fix, unless this is urgently needed by anyone other than @basilfx ...

@basilfx
Copy link
Member Author

basilfx commented Jan 16, 2019

I would need it to get the boot loader fit. We could also replace it later on.

@stale
Copy link

stale bot commented Aug 10, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you want me to ignore this issue, please mark it with the "State: don't stale" label. Thank you for your contributions.

@stale stale bot added the State: stale State: The issue / PR has no activity for >185 days label Aug 10, 2019
@stale stale bot closed this Sep 10, 2019
@kaspar030 kaspar030 reopened this Nov 19, 2019
@stale stale bot removed the State: stale State: The issue / PR has no activity for >185 days label Nov 19, 2019
@kaspar030
Copy link
Contributor

@basilfx would you rebase pls?

@basilfx
Copy link
Member Author

basilfx commented Nov 19, 2019

@kaspar030 Done! I also updated the PR description after retesting. Still seems to work ;-)

@kaspar030
Copy link
Contributor

Here is an example for tests/minimal.

Could you add this module to tests/minimal, so it is actually compiled at least somewhere?

@kaspar030
Copy link
Contributor

Could you add this module to tests/minimal, so it is actually compiled at least somewhere?

or to riotboot?

@basilfx basilfx force-pushed the feature/stdio_null branch 2 times, most recently from 830c695 to 2dff32c Compare November 19, 2019 17:30
@basilfx
Copy link
Member Author

basilfx commented Nov 19, 2019

Added it to tests/minimal. Also took the liberty of squashing the PR.

basilfx:minimal/ (feature/stdio_null) $ BOARD=samr21-xpro make -j8
Building application "tests_minimal" for "samr21-xpro" with MCU "samd21".

"make" -C boards/samr21-xpro
"make" -C core
"make" -C cpu/samd21
"make" -C drivers
"make" -C sys
"make" -C cpu/cortexm_common
"make" -C cpu/sam0_common
"make" -C cpu/samd21/periph
"make" -C drivers/periph_common
"make" -C sys/newlib_syscalls_default
"make" -C sys/pm_layered
"make" -C cpu/cortexm_common/periph
"make" -C cpu/sam0_common/periph
"make" -C sys/stdio_null
   text    data     bss     dec     hex filename
   2236      16    2524    4776    12a8 tests/minimal/bin/samr21-xpro/tests_minimal.elf

@basilfx
Copy link
Member Author

basilfx commented Nov 19, 2019

I'll create a separate PR (#12744) to isolate that last commit.

@aabadie aabadie added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Nov 22, 2019
@aabadie
Copy link
Contributor

aabadie commented Nov 22, 2019

#12768 has just been merged so Murdock should pass now (I retriggered it).

@basilfx
Copy link
Member Author

basilfx commented Nov 26, 2019

Rebased. Murdock is happy. I think the comments by @smlng have been resolved some time ago already :-)

@smlng smlng dismissed their stale review November 26, 2019 21:27

comments addressed

Copy link
Contributor

@aabadie aabadie 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 and the CI is green. Let's go with this one.

ACK and go!

@aabadie aabadie merged commit bd254df into RIOT-OS:master Dec 3, 2019
@fjmolinas fjmolinas added this to the Release 2020.01 milestone Dec 13, 2019
@basilfx basilfx deleted the feature/stdio_null branch October 20, 2020 19:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Type: new feature The issue requests / The PR implemements a new feature for RIOT

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants