Skip to content

SDK is getting fat (relief inside) #162

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

Closed
kriegste opened this issue Aug 18, 2018 · 10 comments
Closed

SDK is getting fat (relief inside) #162

kriegste opened this issue Aug 18, 2018 · 10 comments

Comments

@kriegste
Copy link

Like most other software the SDK is getting bigger and bigger and some people might already hit a limit with their tiny EEPROMs. We soon will.

So I tried some gcc optimization switches and found out that

-fno-guess-branch-probability
-freorder-blocks-and-partition
-fno-cse-follow-jumps

in the Makefile save me a few kilobytes. I even recompiled lwip and mbedtls to save more. These switches only affect the automatic optimization process in gcc. They do not alter the function of the code.
So my request would be that Espressif compiled the other libs with these switches to find out if more space can be saved.

@gilpinheiro
Copy link

Thanks for sharing that. I gave it a try in my project (I'm also compiling in mbedtls) and I saved about 2.2k. Modest but nice.

@fvpalha
Copy link

fvpalha commented Aug 20, 2018

I saved 448 bytes. Thank you.

CFLAGS = -I. -w -Os -ggdb -std=c99 -g -O2 -Wpointer-arith -Wundef \ -Wall -Werror -Wno-implicit -Wl,-EL -Wno-implicit-function-declaration \ -fno-exceptions -fno-inline-functions -nostdlib -mlongcalls \ -mtext-section-literals -ffunction-sections -fdata-sections \ -fno-builtin-printf -fno-jump-tables -mno-serialize-volatile \ -fno-guess-branch-probability -freorder-blocks-and-partition -fno-cse-follow-jumps \ -D__ets__ -DICACHE_FLASH -DUSE_US_TIMER -DUSE_OPTIMIZE_PRINTF

@kriegste
Copy link
Author

Remove -O2 and you should save more (it overwrites the preceding -Os which is better).

@fvpalha
Copy link

fvpalha commented Aug 21, 2018

Thank you @kriegste
Now I saved 2032 bytes.

CFLAGS = -I. -w -Os -ggdb -std=c99 -g -Wpointer-arith -Wundef \ -Wall -Werror -Wno-implicit -Wl,-EL -Wno-implicit-function-declaration \ -fno-exceptions -fno-inline-functions -nostdlib -mlongcalls \ -mtext-section-literals -ffunction-sections -fdata-sections \ -fno-builtin-printf -fno-jump-tables -mno-serialize-volatile \ -fno-guess-branch-probability -freorder-blocks-and-partition -fno-cse-follow-jumps \ -D__ets__ -DICACHE_FLASH -DUSE_US_TIMER -DUSE_OPTIMIZE_PRINTF

@kriegste
Copy link
Author

As a side note:
c172368
may not be necessary (yet) if SDK and AT were compiled with those optimization parameters...

@xcguang
Copy link
Collaborator

xcguang commented Aug 23, 2018

@kriegste
Yes,because the bin is too large, and if want to use 515+512 map,you have to layout partition table and recompile it(the libmbedtls.a is larger 40KB+ than libssl.a, maybe you can try it). About this, we are writing documents.

By the way, your gcc optimization is very wonderful, and we will add them next version.

@kriegste
Copy link
Author

I personally do not use the AT firmware so I will not touch it.

But after a quick look it seems there still is plenty of space between 0x01000 and 0x79000 (480 kB) and 0x81000 and 0xFB000 (488 kB).

Editing the original ld file is necessary, I think. For example I am currently squeezing two (OTA) 492 kB images into a 1 MB flash without any problems.

#define SYSTEM_PARTITION_OTA_SIZE							0x6A000
#define SYSTEM_PARTITION_OTA_2_ADDR							0x81000
#define SYSTEM_PARTITION_RF_CAL_ADDR						0xfb000
#define SYSTEM_PARTITION_PHY_DATA_ADDR						0xfc000
#define SYSTEM_PARTITION_SYSTEM_PARAMETER_ADDR				0xfd000
#define SYSTEM_PARTITION_AT_PARAMETER_ADDR					0x7d000
#define SYSTEM_PARTITION_SSL_CLIENT_CERT_PRIVKEY_ADDR		0x7c000
#define SYSTEM_PARTITION_SSL_CLIENT_CA_ADDR					0x7b000
#define SYSTEM_PARTITION_WPA2_ENTERPRISE_CERT_PRIVKEY_ADDR	0x7a000
#define SYSTEM_PARTITION_WPA2_ENTERPRISE_CA_ADDR			0x79000

static const partition_item_t at_partition_table[] = {
	{SYSTEM_PARTITION_BOOTLOADER,					0x0, 												0x1000},
	{SYSTEM_PARTITION_OTA_1,						0x1000,												SYSTEM_PARTITION_OTA_SIZE},
	{SYSTEM_PARTITION_OTA_2,						SYSTEM_PARTITION_OTA_2_ADDR, 						SYSTEM_PARTITION_OTA_SIZE},
	{SYSTEM_PARTITION_RF_CAL,						SYSTEM_PARTITION_RF_CAL_ADDR, 						0x1000},
	{SYSTEM_PARTITION_PHY_DATA,						SYSTEM_PARTITION_PHY_DATA_ADDR, 					0x1000},
	{SYSTEM_PARTITION_SYSTEM_PARAMETER,				SYSTEM_PARTITION_SYSTEM_PARAMETER_ADDR, 			0x3000},
	{SYSTEM_PARTITION_AT_PARAMETER,					SYSTEM_PARTITION_AT_PARAMETER_ADDR, 				0x3000},
	{SYSTEM_PARTITION_SSL_CLIENT_CERT_PRIVKEY,		SYSTEM_PARTITION_SSL_CLIENT_CERT_PRIVKEY_ADDR, 		0x1000},
	{SYSTEM_PARTITION_SSL_CLIENT_CA,				SYSTEM_PARTITION_SSL_CLIENT_CA_ADDR, 				0x1000},
	#ifdef CONFIG_AT_WPA2_ENTERPRISE_COMMAND_ENABLE
		{SYSTEM_PARTITION_WPA2_ENTERPRISE_CERT_PRIVKEY,	SYSTEM_PARTITION_WPA2_ENTERPRISE_CERT_PRIVKEY_ADDR,	0x1000},
		{SYSTEM_PARTITION_WPA2_ENTERPRISE_CA,			SYSTEM_PARTITION_WPA2_ENTERPRISE_CA_ADDR,			0x1000},
	#endif
};

@kriegste
Copy link
Author

kriegste commented Aug 27, 2018

You can try setting

line 8 in
https://github.com/espressif/ESP8266_NONOS_SDK/blob/master/ld/eagle.app.v6.new.1024.app1.ld
to
irom0_0_seg : org = 0x40201010, len = 0x78000

and

line 8 in
https://github.com/espressif/ESP8266_NONOS_SDK/blob/master/ld/eagle.app.v6.new.1024.app2.ld
to
irom0_0_seg : org = 0x40281010, len = 0x78000

Then recompile the AT projects and see if it fits now (it should).

@xcguang
Copy link
Collaborator

xcguang commented Feb 21, 2019

Added the following flags in the latest master branch

-fno-guess-branch-probability -freorder-blocks-and-partition -fno-cse-follow-jumps

The internal lib is compiled by xt-xcc, and the xt-xcc does not support these flags. If compiling the internal lib using gcc with these flags, it seems more bigger, so I gave up.

@kriegste
Copy link
Author

Thanks much for trying!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants