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
10 -#define BSD_DEFAULT 1
19 +/* Set the default format. */
20 +#define FORMAT_DEFAULT_SYSV 0
21 +#define FORMAT_DEFAULT_BSD 1
22 +#define FORMAT_DEFAULT_AVR 0
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"
36 /* Program options. */
39 @@ -47,9 +68,8 @@ static enum
43 -/* 0 means use AT&T-style output. */
44 -static int berkeley_format = BSD_DEFAULT;
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;
50 @@ -63,6 +83,156 @@ static bfd_size_type total_textsize;
51 /* Program exit status. */
52 static int return_code = 0;
55 +/* AVR Size specific stuff */
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
83 + {"atmega2560", AVR256K, AVR8K, AVR4K},
84 + {"atmega2561", AVR256K, AVR8K, AVR4K},
86 + {"at43usb320", AVR128K, 608UL, 0},
87 + {"at90can128", AVR128K, AVR4K, AVR4K},
88 + {"at90usb1286", AVR128K, AVR8K, AVR4K},
89 + {"at90usb1287", AVR128K, AVR8K, AVR4K},
90 + {"atmega128", AVR128K, AVR4K, AVR4K},
91 + {"atmega1280", AVR128K, AVR8K, AVR4K},
92 + {"atmega1281", AVR128K, AVR8K, AVR4K},
93 + {"atmega1284P", AVR128K, AVR16K, AVR4K},
94 + {"atmega103", AVR128K, 4000UL, AVR4K},
95 + {"atxmega128a1",AVR128K, AVR8K, AVR2K},
97 + {"at90can64", AVR64K, AVR4K, AVR2K},
98 + {"at90usb646", AVR64K, AVR4K, AVR2K},
99 + {"at90usb647", AVR64K, AVR4K, AVR2K},
100 + {"atmega64", AVR64K, AVR4K, AVR2K},
101 + {"atmega640", AVR64K, AVR8K, AVR4K},
102 + {"atmega644", AVR64K, AVR4K, AVR2K},
103 + {"atmega644p", AVR64K, AVR4K, AVR2K},
104 + {"atmega645", AVR64K, AVR4K, AVR2K},
105 + {"atmega6450", AVR64K, AVR4K, AVR2K},
106 + {"atmega649", AVR64K, AVR4K, AVR2K},
107 + {"atmega6490", AVR64K, AVR4K, AVR2K},
108 + {"atxmega64a1", AVR64K, AVR4K, AVR2K},
110 + {"atmega406", AVR40K, AVR512, AVR2K},
112 + {"at90can32", AVR32K, AVR2K, AVR1K},
113 + {"at94k", AVR32K, AVR4K, 0},
114 + {"atmega32", AVR32K, AVR2K, AVR1K},
115 + {"atmega323", AVR32K, AVR2K, AVR1K},
116 + {"atmega324p", AVR32K, AVR2K, AVR1K},
117 + {"atmega325", AVR32K, AVR2K, AVR1K},
118 + {"atmega325p", AVR32K, AVR2K, AVR1K},
119 + {"atmega3250", AVR32K, AVR2K, AVR1K},
120 + {"atmega3250p", AVR32K, AVR2K, AVR1K},
121 + {"atmega328p", AVR32K, AVR2K, AVR1K},
122 + {"atmega329", AVR32K, AVR2K, AVR1K},
123 + {"atmega329p", AVR32K, AVR2K, AVR1K},
124 + {"atmega3290", AVR32K, AVR2K, AVR1K},
125 + {"atmega3290p", AVR32K, AVR2K, AVR1K},
126 + {"atmega32hvb", AVR32K, AVR2K, AVR1K},
127 + {"atmega32c1", AVR32K, AVR2K, AVR1K},
128 + {"atmega32m1", AVR32K, AVR2K, AVR1K},
129 + {"atmega32u4", AVR32K, 2560UL, AVR1K},
131 + {"at43usb355", AVR24K, 1120, 0},
133 + {"at76c711", AVR16K, AVR2K, 0},
134 + {"at90pwm216", AVR16K, AVR1K, AVR512},
135 + {"at90pwm316", AVR16K, AVR1K, AVR512},
136 + {"at90usb162", AVR16K, AVR512, AVR512},
137 + {"atmega16", AVR16K, AVR1K, AVR512},
138 + {"atmega161", AVR16K, AVR1K, AVR512},
139 + {"atmega162", AVR16K, AVR1K, AVR512},
140 + {"atmega163", AVR16K, AVR1K, AVR512},
141 + {"atmega164", AVR16K, AVR1K, AVR512},
142 + {"atmega164p", AVR16K, AVR1K, AVR512},
143 + {"atmega165", AVR16K, AVR1K, AVR512},
144 + {"atmega165p", AVR16K, AVR1K, AVR512},
145 + {"atmega168", AVR16K, AVR1K, AVR512},
146 + {"atmega168p", AVR16K, AVR1K, AVR512},
147 + {"atmega169", AVR16K, AVR1K, AVR512},
148 + {"atmega169p", AVR16K, AVR1K, AVR512},
149 + {"attiny167", AVR16K, AVR512, AVR512},
151 + {"at90c8534", AVR8K, 352, AVR512},
152 + {"at90pwm1", AVR8K, AVR512, AVR512},
153 + {"at90pwm2", AVR8K, AVR512, AVR512},
154 + {"at90pwm2b", AVR8K, AVR512, AVR512},
155 + {"at90pwm3", AVR8K, AVR512, AVR512},
156 + {"at90pwm3b", AVR8K, AVR512, AVR512},
157 + {"at90s8515", AVR8K, AVR512, AVR512},
158 + {"at90s8535", AVR8K, AVR512, AVR512},
159 + {"at90usb82", AVR8K, AVR512, AVR512},
160 + {"atmega8", AVR8K, AVR1K, AVR512},
161 + {"atmega8515", AVR8K, AVR512, AVR512},
162 + {"atmega8535", AVR8K, AVR512, AVR512},
163 + {"atmega88", AVR8K, AVR1K, AVR512},
164 + {"atmega88p", AVR8K, AVR1K, AVR512},
165 + {"attiny84", AVR8K, AVR512, AVR512},
166 + {"attiny85", AVR8K, AVR512, AVR512},
167 + {"attiny861", AVR8K, AVR512, AVR512},
168 + {"attiny88", AVR8K, AVR256, AVR64},
170 + {"at90s4414", AVR4K, 352, AVR256},
171 + {"at90s4433", AVR4K, AVR128, AVR256},
172 + {"at90s4434", AVR4K, 352, AVR256},
173 + {"atmega48", AVR4K, AVR512, AVR256},
174 + {"atmega48p", AVR4K, AVR512, AVR256},
175 + {"attiny43u", AVR4K, AVR256, AVR64},
176 + {"attiny44", AVR4K, AVR256, AVR256},
177 + {"attiny45", AVR4K, AVR256, AVR256},
178 + {"attiny461", AVR4K, AVR256, AVR256},
179 + {"attiny48", AVR4K, AVR256, AVR64},
181 + {"at86rf401", AVR2K, 224, AVR128},
182 + {"at90s2313", AVR2K, AVR128, AVR128},
183 + {"at90s2323", AVR2K, AVR128, AVR128},
184 + {"at90s2333", AVR2K, 224, AVR128},
185 + {"at90s2343", AVR2K, AVR128, AVR128},
186 + {"attiny22", AVR2K, 224, AVR128},
187 + {"attiny2313", AVR2K, AVR128, AVR128},
188 + {"attiny24", AVR2K, AVR128, AVR128},
189 + {"attiny25", AVR2K, AVR128, AVR128},
190 + {"attiny26", AVR2K, AVR128, AVR128},
191 + {"attiny261", AVR2K, AVR128, AVR128},
192 + {"attiny28", AVR2K, 0, 0},
194 + {"at90s1200", AVR1K, 0, AVR64},
195 + {"attiny11", AVR1K, 0, AVR64},
196 + {"attiny12", AVR1K, 0, AVR64},
197 + {"attiny13", AVR1K, AVR64, AVR64},
198 + {"attiny15", AVR1K, 0, AVR64},
201 +static char *avrmcu = NULL;
204 static char *target = NULL;
206 /* Forward declarations. */
207 @@ -78,7 +240,8 @@ usage (FILE *stream, int status)
208 fprintf (stream, _(" Displays the sizes of sections inside binary files\n"));
209 fprintf (stream, _(" If no input file(s) are specified, a.out is assumed\n"));
210 fprintf (stream, _(" The options are:\n\
211 - -A|-B --format={sysv|berkeley} Select output style (default is %s)\n\
212 + -A|-B|-C --format={sysv|berkeley|avr} Select output style (default is %s)\n\
213 + --mcu=<avrmcu> MCU name for AVR format only\n\
214 -o|-d|-x --radix={8|10|16} Display numbers in octal, decimal or hex\n\
215 -t --totals Display the total sizes (Berkeley only)\n\
216 --common Display total size for *COM* syms\n\
217 @@ -87,11 +250,7 @@ usage (FILE *stream, int status)
218 -h --help Display this information\n\
219 -v --version Display the program's version\n\
228 list_supported_targets (program_name, stream);
229 if (REPORT_BUGS_TO[0] && status == 0)
230 @@ -102,6 +261,7 @@ usage (FILE *stream, int status)
231 #define OPTION_FORMAT (200)
232 #define OPTION_RADIX (OPTION_FORMAT + 1)
233 #define OPTION_TARGET (OPTION_RADIX + 1)
234 +#define OPTION_MCU (OPTION_TARGET + 1)
236 static struct option long_options[] =
238 @@ -109,6 +269,7 @@ static struct option long_options[] =
239 {"format", required_argument, 0, OPTION_FORMAT},
240 {"radix", required_argument, 0, OPTION_RADIX},
241 {"target", required_argument, 0, OPTION_TARGET},
242 + {"mcu", required_argument, 0, 203},
243 {"totals", no_argument, &show_totals, 1},
244 {"version", no_argument, &show_version, 1},
245 {"help", no_argument, &show_help, 1},
246 @@ -140,7 +301,7 @@ main (int argc, char **argv)
248 set_default_bfd_target ();
250 - while ((c = getopt_long (argc, argv, "ABHhVvdfotx", long_options,
251 + while ((c = getopt_long (argc, argv, "ABCHhVvdfotx", long_options,
255 @@ -149,11 +310,15 @@ main (int argc, char **argv)
259 - berkeley_format = 1;
260 + format = format_bsd;
264 - berkeley_format = 0;
265 + format = format_sysv;
269 + format = format_avr;
272 non_fatal (_("invalid argument to --format: %s"), optarg);
273 @@ -161,6 +326,10 @@ main (int argc, char **argv)
284 @@ -189,11 +358,14 @@ main (int argc, char **argv)
288 - berkeley_format = 0;
289 + format = format_sysv;
292 - berkeley_format = 1;
293 + format = format_bsd;
296 + format = format_avr;
301 @@ -239,7 +411,7 @@ main (int argc, char **argv)
302 for (; optind < argc;)
303 display_file (argv[optind++]);
305 - if (show_totals && berkeley_format)
306 + if (show_totals && format == format_bsd)
308 bfd_size_type total = total_textsize + total_datasize + total_bsssize;
310 @@ -600,13 +772,117 @@ print_sysv_format (bfd *file)
315 +static avr_device_t *
316 +avr_find_device (void)
319 + if (avrmcu != NULL)
321 + for (i = 0; i < sizeof(avr) / sizeof(avr[0]); i++)
323 + if (strcmp(avr[i].name, avrmcu) == 0)
336 +print_avr_format (bfd *file)
338 + char *avr_name = "Unknown";
343 + bfd_size_type datasize = 0;
344 + bfd_size_type textsize = 0;
345 + bfd_size_type bsssize = 0;
346 + bfd_size_type bootloadersize = 0;
347 + bfd_size_type noinitsize = 0;
348 + bfd_size_type eepromsize = 0;
350 + avr_device_t *avrdevice = avr_find_device();
351 + if (avrdevice != NULL)
353 + avr_name = avrdevice->name;
354 + flashmax = avrdevice->flash;
355 + rammax = avrdevice->ram;
356 + eeprommax = avrdevice->eeprom;
359 + if ((section = bfd_get_section_by_name (file, ".data")) != NULL)
360 + datasize = bfd_section_size (file, section);
361 + if ((section = bfd_get_section_by_name (file, ".text")) != NULL)
362 + textsize = bfd_section_size (file, section);
363 + if ((section = bfd_get_section_by_name (file, ".bss")) != NULL)
364 + bsssize = bfd_section_size (file, section);
365 + if ((section = bfd_get_section_by_name (file, ".bootloader")) != NULL)
366 + bootloadersize = bfd_section_size (file, section);
367 + if ((section = bfd_get_section_by_name (file, ".noinit")) != NULL)
368 + noinitsize = bfd_section_size (file, section);
369 + if ((section = bfd_get_section_by_name (file, ".eeprom")) != NULL)
370 + eepromsize = bfd_section_size (file, section);
372 + bfd_size_type text = textsize + datasize + bootloadersize;
373 + bfd_size_type data = datasize + bsssize + noinitsize;
374 + bfd_size_type eeprom = eepromsize;
376 + printf ("AVR Memory Usage\n"
377 + "----------------\n"
378 + "Device: %s\n\n", avr_name);
381 + printf ("Program:%8ld bytes", text);
384 + printf (" (%2.1f%% Full)", ((float)text / flashmax) * 100);
386 + printf ("\n(.text + .data + .bootloader)\n\n");
389 + printf ("Data: %8ld bytes", data);
392 + printf (" (%2.1f%% Full)", ((float)data / rammax) * 100);
394 + printf ("\n(.data + .bss + .noinit)\n\n");
399 + printf ("EEPROM: %8ld bytes", eeprom);
402 + printf (" (%2.1f%% Full)", ((float)eeprom / eeprommax) * 100);
404 + printf ("\n(.eeprom)\n\n");
410 print_sizes (bfd *file)
413 calculate_common_size (file);
414 - if (berkeley_format)
415 - print_berkeley_format (file);
417 - print_sysv_format (file);
421 + print_sysv_format (file);
424 + print_berkeley_format (file);
428 + print_avr_format (file);