avr-size.patch 13 KB

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