Rockbox

Tasklist

FS#10756 - Free unused init code

Attached to Project: Rockbox
Opened by Thomas Martitz (kugel.) - Tuesday, 03 November 2009, 13:24 GMT
Last edited by Thomas Martitz (kugel.) - Friday, 02 April 2010, 17:10 GMT
Task Type Patches
Category Operating System/Drivers
Status Closed
Assigned To No-one
Operating System All players
Severity Low
Priority Normal
Reported Version Release 3.4
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 0
Private No

Details

I've some code here that creates a dedicated section for init functions (i.e. those that are only called once and very early), inspired by the Linux Kernel.

There's little point in keeping that code in otherwise usable RAM. That's why my patch would copy move that code into a section that's overwritten later.

For example, as my current patch works for e200v1: The code is in the same address area as bss. Before bss is zeroed, the init code is copied to the codec buffer. After calling main(), the init code is called from the codec buffer. The bss, following sections are moved over the init code, which effectively frees the code size init functions take. I use a very similar approach as iram code does.

On my e200, it yields ~6.7k. I would like to know if this kind of self-modifying code is considerable for SVN, or if it's too dirty and/or dangerous. -6.7k isn't *that* much.

Where the init code lands (codec or plugin buffer), and if the mechanism is really used, is entirely up to 1 ifdef in config.h and the target's app.lds.
This task depends upon

Closed by  Thomas Martitz (kugel.)
Friday, 02 April 2010, 17:10 GMT
Reason for closing:  Accepted
Additional comments about closing:  Committed as of r25013.
Comment by Maurus Cuelenaere (mcuelenaere) - Tuesday, 03 November 2009, 13:36 GMT
I had the same idea some time ago, but instead of copying the init data at startup I tried putting all code at the end of the pcm buffer (before plugin start), so that it would get overwritten automatically on buffer fill.

However I failed doing this as I couldn't get the linker do this..
Comment by Thomas Martitz (kugel.) - Tuesday, 03 November 2009, 13:37 GMT
You need to copy, unless you want binaries that are almost as big as the RAM.
Comment by Maurus Cuelenaere (mcuelenaere) - Tuesday, 03 November 2009, 13:46 GMT
Hmm yes, too bad the main Rockbox binary doesn't use the ELF format or any other non-contiguous format (the Creative ZVM actually uses something similar to that, so in theory it could be done there).
Comment by Rafaël Carré (funman) - Tuesday, 03 November 2009, 15:26 GMT
Just spotted a left over addition in :

diff --git a/firmware/target/arm/sandisk/sansa-e200/lcd-e200.c b/firmware/target/arm/sandisk/sansa-e200/lcd-e200.c
index 03f6a1b..96d1326 100644
--- a/firmware/target/arm/sandisk/sansa-e200/lcd-e200.c
+++ b/firmware/target/arm/sandisk/sansa-e200/lcd-e200.c
@@ -353,6 +353,7 @@ static void lcd_display_off(void)
}
#endif

+void lcd_init_device(void) INIT_ATTR;
void lcd_init_device(void)
{
/* All this is magic worked out by MrH */
@@ -435,6 +436,7 @@ void lcd_init_device(void)
#endif

LCD_REG_6 |= 1; /* Start DMA */
+ _backlight_set_brightness(0);
}

#if defined(HAVE_LCD_ENABLE


And I think the description is wrong: the code isn't copied in bss section
Comment by Thomas Martitz (kugel.) - Tuesday, 03 November 2009, 15:44 GMT
Yea that was a left over from testing, I've spotted it already.

Where does the description indicate it's copied in the bss section?
Comment by Rafaël Carré (funman) - Tuesday, 03 November 2009, 15:50 GMT
"The code is in the same address area as bss. Before bss is zeroed, the init code is copied to the codec buffer."

What I see is that the copy in crt0.S is done just before bss zeroing, but I read the first sentence as "code is copied inside bss section"
Comment by Maurus Cuelenaere (mcuelenaere) - Tuesday, 08 December 2009, 15:56 GMT
Is there any reason for not committing this?
Comment by Thomas Martitz (kugel.) - Tuesday, 08 December 2009, 16:22 GMT
Upcoming release :) No need to risk things just now.
Comment by Maurus Cuelenaere (mcuelenaere) - Tuesday, 08 December 2009, 16:23 GMT
Ah /me always forgets those..
Comment by Rafaël Carré (funman) - Saturday, 16 January 2010, 08:49 GMT
Do we wait until the 3.5 ?
Comment by Thomas Martitz (kugel.) - Saturday, 16 January 2010, 10:48 GMT
I thought so, but it doesn't appear to happen :(

Loading...