]> git.pld-linux.org Git - packages/crossavr-binutils.git/blame - crossavr-binutils-avr-size.patch
- updated to 2.21
[packages/crossavr-binutils.git] / crossavr-binutils-avr-size.patch
CommitLineData
b0a81564 1AVR specific only
2--------------------------------------------------------------------------------
3--- binutils/size.c 2007-08-06 13:56:14.000000000 -0600
4+++ binutils/size.c 2007-09-13 09:13:10.281250000 -0600
5@@ -35,10 +35,31 @@
6 #include "getopt.h"
7 #include "bucomm.h"
8
9-#ifndef BSD_DEFAULT
10-#define BSD_DEFAULT 1
11+typedef enum
12+{
13+ format_sysv = 0,
14+ format_bsd = 1,
15+ format_avr = 2,
16+} format_type_t;
17+
18+
19+/* Set the default format. */
20+#define FORMAT_DEFAULT_SYSV 0
21+#define FORMAT_DEFAULT_BSD 1
22+#define FORMAT_DEFAULT_AVR 0
23+
24+#if FORMAT_DEFAULT_SYSV
25+ #define FORMAT_DEFAULT format_sysv
26+ #define FORMAT_NAME "sysv"
27+#elif FORMAT_DEFAULT_BSD
28+ #define FORMAT_DEFAULT format_bsd
29+ #define FORMAT_NAME "berkeley"
30+#elif FORMAT_DEFAULT_AVR
31+ #define FORMAT_DEFAULT format_avr
32+ #define FORMAT_NAME "avr"
33 #endif
34
35+
36 /* Program options. */
37
38 static enum
39@@ -47,9 +68,8 @@ static enum
40 }
41 radix = decimal;
42
43-/* 0 means use AT&T-style output. */
44-static int berkeley_format = BSD_DEFAULT;
45
46+format_type_t format = FORMAT_DEFAULT;
47 static int show_version = 0;
48 static int show_help = 0;
49 static int show_totals = 0;
997dccbb 50@@ -63,6 +83,163 @@ static bfd_size_type total_textsize;
b0a81564 51 /* Program exit status. */
52 static int return_code = 0;
53
54+
55+/* AVR Size specific stuff */
56+
57+#define AVR64 64UL
58+#define AVR128 128UL
59+#define AVR256 256UL
60+#define AVR512 512UL
61+#define AVR1K 1024UL
62+#define AVR2K 2048UL
63+#define AVR4K 4096UL
64+#define AVR8K 8192UL
65+#define AVR16K 16384UL
66+#define AVR24K 24576UL
67+#define AVR32K 32768UL
68+#define AVR40K 40960UL
69+#define AVR64K 65536UL
70+#define AVR128K 131072UL
71+#define AVR256K 262144UL
72+
73+typedef struct
74+{
75+ char *name;
76+ long flash;
77+ long ram;
78+ long eeprom;
79+} avr_device_t;
80+
81+avr_device_t avr[] =
82+{
997dccbb 83+ {"atmega2560", AVR256K, AVR8K, AVR4K},
84+ {"atmega2561", AVR256K, AVR8K, AVR4K},
85+ {"atxmega256a3", AVR256K, AVR8K, AVR4K},
86+ {"atxmega256a3b", AVR256K, AVR8K, AVR4K},
87+ {"atxmega256a3v", AVR256K, AVR8K, AVR4K},
b0a81564 88+
997dccbb 89+ {"at43usb320", AVR128K, 608UL, 0},
90+ {"at90can128", AVR128K, AVR4K, AVR4K},
91+ {"at90usb1286", AVR128K, AVR8K, AVR4K},
92+ {"at90usb1287", AVR128K, AVR8K, AVR4K},
93+ {"atmega128", AVR128K, AVR4K, AVR4K},
94+ {"atmega1280", AVR128K, AVR8K, AVR4K},
95+ {"atmega1281", AVR128K, AVR8K, AVR4K},
96+ {"atmega1284P", AVR128K, AVR16K, AVR4K},
97+ {"atmega103", AVR128K, 4000UL, AVR4K},
98+ {"atxmega128a1", AVR128K, AVR8K, AVR2K},
99+ {"atxmega128a3", AVR128K, AVR16K, AVR2K},
b0a81564 100+
997dccbb 101+ {"at90can64", AVR64K, AVR4K, AVR2K},
102+ {"at90usb646", AVR64K, AVR4K, AVR2K},
103+ {"at90usb647", AVR64K, AVR4K, AVR2K},
104+ {"atmega64", AVR64K, AVR4K, AVR2K},
105+ {"atmega640", AVR64K, AVR8K, AVR4K},
106+ {"atmega644", AVR64K, AVR4K, AVR2K},
107+ {"atmega644p", AVR64K, AVR4K, AVR2K},
108+ {"atmega645", AVR64K, AVR4K, AVR2K},
109+ {"atmega6450", AVR64K, AVR4K, AVR2K},
110+ {"atmega649", AVR64K, AVR4K, AVR2K},
111+ {"atmega6490", AVR64K, AVR4K, AVR2K},
112+ {"atxmega64a1", AVR64K, AVR4K, AVR2K},
113+ {"atxmega64a3", AVR64K, AVR4K, AVR2K},
b0a81564 114+
997dccbb 115+ {"atmega406", AVR40K, AVR2K, AVR512},
b0a81564 116+
997dccbb 117+ {"at90can32", AVR32K, AVR2K, AVR1K},
118+ {"at94k", AVR32K, AVR4K, 0},
119+ {"atmega32", AVR32K, AVR2K, AVR1K},
120+ {"atmega323", AVR32K, AVR2K, AVR1K},
121+ {"atmega324p", AVR32K, AVR2K, AVR1K},
122+ {"atmega325", AVR32K, AVR2K, AVR1K},
123+ {"atmega325p", AVR32K, AVR2K, AVR1K},
124+ {"atmega3250", AVR32K, AVR2K, AVR1K},
125+ {"atmega3250p", AVR32K, AVR2K, AVR1K},
126+ {"atmega328p", AVR32K, AVR2K, AVR1K},
127+ {"atmega329", AVR32K, AVR2K, AVR1K},
128+ {"atmega329p", AVR32K, AVR2K, AVR1K},
129+ {"atmega3290", AVR32K, AVR2K, AVR1K},
130+ {"atmega3290p", AVR32K, AVR2K, AVR1K},
131+ {"atmega32hvb", AVR32K, AVR2K, AVR1K},
132+ {"atmega32c1", AVR32K, AVR2K, AVR1K},
133+ {"atmega32m1", AVR32K, AVR2K, AVR1K},
134+ {"atmega32u4", AVR32K, 2560UL, AVR1K},
135+ {"atmega32u6", AVR32K, 2560UL, AVR1K},
b0a81564 136+
997dccbb 137+ {"at43usb355", AVR24K, 1120, 0},
b0a81564 138+
997dccbb 139+ {"at76c711", AVR16K, AVR2K, 0},
140+ {"at90pwm216", AVR16K, AVR1K, AVR512},
141+ {"at90pwm316", AVR16K, AVR1K, AVR512},
142+ {"at90usb162", AVR16K, AVR512, AVR512},
143+ {"atmega16", AVR16K, AVR1K, AVR512},
144+ {"atmega161", AVR16K, AVR1K, AVR512},
145+ {"atmega162", AVR16K, AVR1K, AVR512},
146+ {"atmega163", AVR16K, AVR1K, AVR512},
147+ {"atmega164", AVR16K, AVR1K, AVR512},
148+ {"atmega164p", AVR16K, AVR1K, AVR512},
149+ {"atmega165", AVR16K, AVR1K, AVR512},
150+ {"atmega165p", AVR16K, AVR1K, AVR512},
151+ {"atmega168", AVR16K, AVR1K, AVR512},
152+ {"atmega168p", AVR16K, AVR1K, AVR512},
153+ {"atmega169", AVR16K, AVR1K, AVR512},
154+ {"atmega169p", AVR16K, AVR1K, AVR512},
155+ {"atmega16u4", AVR16K, 1280UL, AVR512},
156+ {"attiny167", AVR16K, AVR512, AVR512},
b0a81564 157+
997dccbb 158+ {"at90c8534", AVR8K, 352, AVR512},
159+ {"at90pwm1", AVR8K, AVR512, AVR512},
160+ {"at90pwm2", AVR8K, AVR512, AVR512},
161+ {"at90pwm2b", AVR8K, AVR512, AVR512},
162+ {"at90pwm3", AVR8K, AVR512, AVR512},
163+ {"at90pwm3b", AVR8K, AVR512, AVR512},
164+ {"at90s8515", AVR8K, AVR512, AVR512},
165+ {"at90s8535", AVR8K, AVR512, AVR512},
166+ {"at90usb82", AVR8K, AVR512, AVR512},
167+ {"atmega8", AVR8K, AVR1K, AVR512},
168+ {"atmega8515", AVR8K, AVR512, AVR512},
169+ {"atmega8535", AVR8K, AVR512, AVR512},
170+ {"atmega88", AVR8K, AVR1K, AVR512},
171+ {"atmega88p", AVR8K, AVR1K, AVR512},
172+ {"attiny84", AVR8K, AVR512, AVR512},
173+ {"attiny85", AVR8K, AVR512, AVR512},
174+ {"attiny861", AVR8K, AVR512, AVR512},
175+ {"attiny88", AVR8K, AVR256, AVR64},
b0a81564 176+
997dccbb 177+ {"at90s4414", AVR4K, 352, AVR256},
178+ {"at90s4433", AVR4K, AVR128, AVR256},
179+ {"at90s4434", AVR4K, 352, AVR256},
180+ {"atmega48", AVR4K, AVR512, AVR256},
181+ {"atmega48p", AVR4K, AVR512, AVR256},
182+ {"attiny43u", AVR4K, AVR256, AVR64},
183+ {"attiny44", AVR4K, AVR256, AVR256},
184+ {"attiny45", AVR4K, AVR256, AVR256},
185+ {"attiny461", AVR4K, AVR256, AVR256},
186+ {"attiny48", AVR4K, AVR256, AVR64},
b0a81564 187+
997dccbb 188+ {"at86rf401", AVR2K, 224, AVR128},
189+ {"at90s2313", AVR2K, AVR128, AVR128},
190+ {"at90s2323", AVR2K, AVR128, AVR128},
191+ {"at90s2333", AVR2K, 224, AVR128},
192+ {"at90s2343", AVR2K, AVR128, AVR128},
193+ {"attiny22", AVR2K, 224, AVR128},
194+ {"attiny2313", AVR2K, AVR128, AVR128},
195+ {"attiny24", AVR2K, AVR128, AVR128},
196+ {"attiny25", AVR2K, AVR128, AVR128},
197+ {"attiny26", AVR2K, AVR128, AVR128},
198+ {"attiny261", AVR2K, AVR128, AVR128},
199+ {"attiny28", AVR2K, 0, 0},
b0a81564 200+
997dccbb 201+ {"at90s1200", AVR1K, 0, AVR64},
202+ {"attiny11", AVR1K, 0, AVR64},
203+ {"attiny12", AVR1K, 0, AVR64},
204+ {"attiny13", AVR1K, AVR64, AVR64},
205+ {"attiny15", AVR1K, 0, AVR64},
b0a81564 206+};
207+
208+static char *avrmcu = NULL;
209+
210+
211 static char *target = NULL;
212
213 /* Forward declarations. */
997dccbb 214@@ -78,7 +247,8 @@ usage (FILE *stream, int status)
b0a81564 215 fprintf (stream, _(" Displays the sizes of sections inside binary files\n"));
216 fprintf (stream, _(" If no input file(s) are specified, a.out is assumed\n"));
217 fprintf (stream, _(" The options are:\n\
218- -A|-B --format={sysv|berkeley} Select output style (default is %s)\n\
219+ -A|-B|-C --format={sysv|berkeley|avr} Select output style (default is %s)\n\
220+ --mcu=<avrmcu> MCU name for AVR format only\n\
221 -o|-d|-x --radix={8|10|16} Display numbers in octal, decimal or hex\n\
222 -t --totals Display the total sizes (Berkeley only)\n\
223 --common Display total size for *COM* syms\n\
997dccbb 224@@ -87,11 +257,7 @@ usage (FILE *stream, int status)
b0a81564 225 -h --help Display this information\n\
226 -v --version Display the program's version\n\
227 \n"),
228-#if BSD_DEFAULT
229- "berkeley"
230-#else
231- "sysv"
232-#endif
233+FORMAT_NAME
234 );
235 list_supported_targets (program_name, stream);
236 if (REPORT_BUGS_TO[0] && status == 0)
997dccbb 237@@ -102,6 +268,7 @@ usage (FILE *stream, int status)
b0a81564 238 #define OPTION_FORMAT (200)
239 #define OPTION_RADIX (OPTION_FORMAT + 1)
240 #define OPTION_TARGET (OPTION_RADIX + 1)
241+#define OPTION_MCU (OPTION_TARGET + 1)
242
243 static struct option long_options[] =
244 {
997dccbb 245@@ -109,6 +276,7 @@ static struct option long_options[] =
b0a81564 246 {"format", required_argument, 0, OPTION_FORMAT},
247 {"radix", required_argument, 0, OPTION_RADIX},
248 {"target", required_argument, 0, OPTION_TARGET},
249+ {"mcu", required_argument, 0, 203},
250 {"totals", no_argument, &show_totals, 1},
251 {"version", no_argument, &show_version, 1},
252 {"help", no_argument, &show_help, 1},
997dccbb 253@@ -140,7 +308,7 @@ main (int argc, char **argv)
b0a81564 254 bfd_init ();
255 set_default_bfd_target ();
256
257- while ((c = getopt_long (argc, argv, "ABHhVvdfotx", long_options,
258+ while ((c = getopt_long (argc, argv, "ABCHhVvdfotx", long_options,
259 (int *) 0)) != EOF)
260 switch (c)
261 {
997dccbb 262@@ -149,11 +317,15 @@ main (int argc, char **argv)
b0a81564 263 {
264 case 'B':
265 case 'b':
266- berkeley_format = 1;
267+ format = format_bsd;
268 break;
269 case 'S':
270 case 's':
271- berkeley_format = 0;
272+ format = format_sysv;
273+ break;
274+ case 'A':
275+ case 'a':
276+ format = format_avr;
277 break;
278 default:
279 non_fatal (_("invalid argument to --format: %s"), optarg);
997dccbb 280@@ -161,6 +333,10 @@ main (int argc, char **argv)
b0a81564 281 }
282 break;
283
284+ case OPTION_MCU:
285+ avrmcu = optarg;
286+ break;
287+
288 case OPTION_TARGET:
289 target = optarg;
290 break;
997dccbb 291@@ -189,11 +365,14 @@ main (int argc, char **argv)
b0a81564 292 break;
293
294 case 'A':
295- berkeley_format = 0;
296+ format = format_sysv;
297 break;
298 case 'B':
299- berkeley_format = 1;
300+ format = format_bsd;
301 break;
302+ case 'C':
303+ format = format_avr;
304+ break;
305 case 'v':
306 case 'V':
307 show_version = 1;
997dccbb 308@@ -239,7 +418,7 @@ main (int argc, char **argv)
b0a81564 309 for (; optind < argc;)
310 display_file (argv[optind++]);
311
312- if (show_totals && berkeley_format)
313+ if (show_totals && format == format_bsd)
314 {
315 bfd_size_type total = total_textsize + total_datasize + total_bsssize;
316
997dccbb 317@@ -600,13 +779,117 @@ print_sysv_format (bfd *file)
b0a81564 318 printf ("\n\n");
319 }
320
321+
322+static avr_device_t *
323+avr_find_device (void)
324+{
325+ unsigned int i;
326+ if (avrmcu != NULL)
327+ {
328+ for (i = 0; i < sizeof(avr) / sizeof(avr[0]); i++)
329+ {
330+ if (strcmp(avr[i].name, avrmcu) == 0)
331+ {
332+ /* Match found */
333+ return (&avr[i]);
334+ }
335+ }
336+ }
337+ return (NULL);
338+}
339+
340+
341+
342+static void
343+print_avr_format (bfd *file)
344+{
345+ char *avr_name = "Unknown";
346+ int flashmax = 0;
347+ int rammax = 0;
348+ int eeprommax = 0;
349+ asection *section;
8cbbe116 350+ bfd_size_type avr_datasize = 0;
351+ bfd_size_type avr_textsize = 0;
352+ bfd_size_type avr_bsssize = 0;
b0a81564 353+ bfd_size_type bootloadersize = 0;
354+ bfd_size_type noinitsize = 0;
355+ bfd_size_type eepromsize = 0;
356+
357+ avr_device_t *avrdevice = avr_find_device();
358+ if (avrdevice != NULL)
359+ {
360+ avr_name = avrdevice->name;
361+ flashmax = avrdevice->flash;
362+ rammax = avrdevice->ram;
363+ eeprommax = avrdevice->eeprom;
364+ }
365+
366+ if ((section = bfd_get_section_by_name (file, ".data")) != NULL)
8cbbe116 367+ avr_datasize = bfd_section_size (file, section);
b0a81564 368+ if ((section = bfd_get_section_by_name (file, ".text")) != NULL)
8cbbe116 369+ avr_textsize = bfd_section_size (file, section);
b0a81564 370+ if ((section = bfd_get_section_by_name (file, ".bss")) != NULL)
8cbbe116 371+ avr_bsssize = bfd_section_size (file, section);
b0a81564 372+ if ((section = bfd_get_section_by_name (file, ".bootloader")) != NULL)
373+ bootloadersize = bfd_section_size (file, section);
374+ if ((section = bfd_get_section_by_name (file, ".noinit")) != NULL)
375+ noinitsize = bfd_section_size (file, section);
376+ if ((section = bfd_get_section_by_name (file, ".eeprom")) != NULL)
377+ eepromsize = bfd_section_size (file, section);
378+
8cbbe116 379+ bfd_size_type text = avr_textsize + avr_datasize + bootloadersize;
380+ bfd_size_type data = avr_datasize + avr_bsssize + noinitsize;
b0a81564 381+ bfd_size_type eeprom = eepromsize;
382+
383+ printf ("AVR Memory Usage\n"
384+ "----------------\n"
385+ "Device: %s\n\n", avr_name);
386+
387+ /* Text size */
388+ printf ("Program:%8ld bytes", text);
389+ if (flashmax > 0)
390+ {
391+ printf (" (%2.1f%% Full)", ((float)text / flashmax) * 100);
392+ }
393+ printf ("\n(.text + .data + .bootloader)\n\n");
394+
395+ /* Data size */
396+ printf ("Data: %8ld bytes", data);
397+ if (rammax > 0)
398+ {
399+ printf (" (%2.1f%% Full)", ((float)data / rammax) * 100);
400+ }
401+ printf ("\n(.data + .bss + .noinit)\n\n");
402+
403+ /* EEPROM size */
404+ if (eeprom > 0)
405+ {
406+ printf ("EEPROM: %8ld bytes", eeprom);
407+ if (eeprommax > 0)
408+ {
409+ printf (" (%2.1f%% Full)", ((float)eeprom / eeprommax) * 100);
410+ }
411+ printf ("\n(.eeprom)\n\n");
412+ }
413+}
414+
415+
416 static void
417 print_sizes (bfd *file)
418 {
419 if (show_common)
420 calculate_common_size (file);
421- if (berkeley_format)
422- print_berkeley_format (file);
423- else
424- print_sysv_format (file);
425+ switch (format)
426+ {
427+ case format_sysv:
428+ print_sysv_format (file);
429+ break;
430+ case format_bsd:
431+ print_berkeley_format (file);
432+ break;
433+ case format_avr:
434+ default:
435+ print_avr_format (file);
436+ break;
437+ }
438 }
This page took 0.20331 seconds and 4 git commands to generate.