diff --git a/app/user/wrap_printf.s b/app/user/wrap_printf.s index 026ac452..3344056f 100644 --- a/app/user/wrap_printf.s +++ b/app/user/wrap_printf.s @@ -44,7 +44,13 @@ .align 4 .literal_position __wrap_printf: - addi a1, a1, -48 /* get some stack space */ + movi a9, os_printf_enabled /* a9 is caller saved */ + l8ui a9, a9, 0 /* load os_printf_enabled flag */ + bnez a9, 1f /* if it's enabled, we print everything */ + movi a9, _irom0_sdktext_end /* else we check if it's SDK called */ + bgeu a0, a9, 1f /* ...and only print from user code */ + ret +1:addi a1, a1, -48 /* get some stack space */ s32i a0, a1, 0 /* store a0 at the bottom */ s32i a2, a1, 16 /* copy the formatting string and first few arguments */ s32i a3, a1, 20 /* ...onto the stack in a way that we get a struct */ @@ -61,3 +67,9 @@ __wrap_printf: l32i a0, a1, 0 /* restore return address into a0 */ addi a1, a1, 48 /* release the stack */ ret /* all done */ + +/* Flag for controlling whether SDK printf()s are suppressed or not. + * This is to provide an RTOS-safe reimplementation of system_set_os_print(). */ +.section ".data" +.globl os_printf_enabled +os_printf_enabled: .byte 1 diff --git a/ld/nodemcu.ld b/ld/nodemcu.ld index 7e832b36..f338ed64 100644 --- a/ld/nodemcu.ld +++ b/ld/nodemcu.ld @@ -91,6 +91,12 @@ SECTIONS .irom0.text : ALIGN(0x1000) { _irom0_text_start = ABSOLUTE(.); + + /* To be able to suppress SDK printfs, we place all SDK code first, with + * a marker at the end that we can easily compare against. */ + */rtos-sdk/lib/lib*.a:*.o(.irom*) + _irom0_sdktext_end = ABSOLUTE(.); + *(.servercert.flash) *(.clientcert.flash) *(.irom0.literal .irom.literal .irom.text.literal .irom0.text .irom.text) @@ -108,10 +114,6 @@ SECTIONS KEEP(*(.lua_rotable)) LONG(0) LONG(0) /* Null-terminate the array */ - /* SDK doesn't use libc functions, and are therefore safe to put in flash */ - */libc.a:*.o(.text* .literal*) - /* end libc functions */ - _irom0_text_end = ABSOLUTE(.); _flash_used_end = ABSOLUTE(.); } >irom0_0_seg :irom0_0_phdr =0xffffffff diff --git a/sdk-overrides/include/user_interface.h b/sdk-overrides/include/user_interface.h index e195e1c9..09a1078f 100644 --- a/sdk-overrides/include/user_interface.h +++ b/sdk-overrides/include/user_interface.h @@ -3,7 +3,6 @@ #define ets_timer_arm_new(tmr, ms, rpt, isms) os_timer_arm(tmr,ms,rpt) -//#include_next "user_interface.h" #include "espressif/esp_system.h" #include "espressif/esp_misc.h" #include "espressif/esp_wifi.h" @@ -11,9 +10,10 @@ #include "espressif/esp_softap.h" #include "espressif/esp_timer.h" - -// FIXME -static inline void system_set_os_print(uint8 onoff) { (void)onoff; } +static inline void system_set_os_print(uint8_t onoff) { + extern uint8_t os_printf_enabled; + os_printf_enabled = onoff; +} bool wifi_softap_deauth(uint8 mac[6]);