avr-size.patch 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  1. diff --git a/binutils/size.c b/binutils/size.c
  2. index 3697087714..f99d45a6bf 100644
  3. --- a/binutils/size.c
  4. +++ b/binutils/size.c
  5. @@ -51,7 +51,8 @@ enum output_format
  6. {
  7. FORMAT_BERKLEY,
  8. FORMAT_SYSV,
  9. - FORMAT_GNU
  10. + FORMAT_GNU,
  11. + FORMAT_AVR
  12. };
  13. static enum output_format selected_output_format =
  14. #if BSD_DEFAULT
  15. @@ -74,6 +75,246 @@ static bfd_size_type total_textsize;
  16. /* Program exit status. */
  17. static int return_code = 0;
  18. +
  19. +/* AVR Size specific stuff */
  20. +
  21. +#define AVR64 64UL
  22. +#define AVR128 128UL
  23. +#define AVR256 256UL
  24. +#define AVR512 512UL
  25. +#define AVR1K 1024UL
  26. +#define AVR2K 2048UL
  27. +#define AVR4K 4096UL
  28. +#define AVR8K 8192UL
  29. +#define AVR16K 16384UL
  30. +#define AVR20K 20480UL
  31. +#define AVR24K 24576UL
  32. +#define AVR32K 32768UL
  33. +#define AVR36K 36864UL
  34. +#define AVR40K 40960UL
  35. +#define AVR64K 65536UL
  36. +#define AVR68K 69632UL
  37. +#define AVR128K 131072UL
  38. +#define AVR136K 139264UL
  39. +#define AVR200K 204800UL
  40. +#define AVR256K 262144UL
  41. +#define AVR264K 270336UL
  42. +
  43. +typedef struct
  44. +{
  45. + char *name;
  46. + long flash;
  47. + long ram;
  48. + long eeprom;
  49. +} avr_device_t;
  50. +
  51. +avr_device_t avr[] =
  52. +{
  53. + {"atxmega256a3", AVR264K, AVR16K, AVR4K},
  54. + {"atxmega256a3b", AVR264K, AVR16K, AVR4K},
  55. + {"atxmega256d3", AVR264K, AVR16K, AVR4K},
  56. +
  57. + {"atmega2560", AVR256K, AVR8K, AVR4K},
  58. + {"atmega2561", AVR256K, AVR8K, AVR4K},
  59. +
  60. + {"atxmega192a3", AVR200K, AVR16K, AVR2K},
  61. + {"atxmega192d3", AVR200K, AVR16K, AVR2K},
  62. +
  63. + {"atxmega128a1", AVR136K, AVR8K, AVR2K},
  64. + {"atxmega128a1u", AVR136K, AVR8K, AVR2K},
  65. + {"atxmega128a3", AVR136K, AVR8K, AVR2K},
  66. + {"atxmega128d3", AVR136K, AVR8K, AVR2K},
  67. +
  68. + {"at43usb320", AVR128K, 608UL, 0UL},
  69. + {"at90can128", AVR128K, AVR4K, AVR4K},
  70. + {"at90usb1286", AVR128K, AVR8K, AVR4K},
  71. + {"at90usb1287", AVR128K, AVR8K, AVR4K},
  72. + {"atmega128", AVR128K, AVR4K, AVR4K},
  73. + {"atmega1280", AVR128K, AVR8K, AVR4K},
  74. + {"atmega1281", AVR128K, AVR8K, AVR4K},
  75. + {"atmega1284p", AVR128K, AVR16K, AVR4K},
  76. + {"atmega128rfa1", AVR128K, AVR16K, AVR4K},
  77. + {"atmega103", AVR128K, 4000UL, AVR4K},
  78. +
  79. + {"atxmega64a1", AVR68K, AVR4K, AVR2K},
  80. + {"atxmega64a1u", AVR68K, AVR4K, AVR2K},
  81. + {"atxmega64a3", AVR68K, AVR4K, AVR2K},
  82. + {"atxmega64d3", AVR68K, AVR4K, AVR2K},
  83. +
  84. + {"at90can64", AVR64K, AVR4K, AVR2K},
  85. + {"at90scr100", AVR64K, AVR4K, AVR2K},
  86. + {"at90usb646", AVR64K, AVR4K, AVR2K},
  87. + {"at90usb647", AVR64K, AVR4K, AVR2K},
  88. + {"atmega64", AVR64K, AVR4K, AVR2K},
  89. + {"atmega640", AVR64K, AVR8K, AVR4K},
  90. + {"atmega644", AVR64K, AVR4K, AVR2K},
  91. + {"atmega644a", AVR64K, AVR4K, AVR2K},
  92. + {"atmega644p", AVR64K, AVR4K, AVR2K},
  93. + {"atmega644pa", AVR64K, AVR4K, AVR2K},
  94. + {"atmega645", AVR64K, AVR4K, AVR2K},
  95. + {"atmega645a", AVR64K, AVR4K, AVR2K},
  96. + {"atmega645p", AVR64K, AVR4K, AVR2K},
  97. + {"atmega6450", AVR64K, AVR4K, AVR2K},
  98. + {"atmega6450a", AVR64K, AVR4K, AVR2K},
  99. + {"atmega6450p", AVR64K, AVR4K, AVR2K},
  100. + {"atmega649", AVR64K, AVR4K, AVR2K},
  101. + {"atmega649a", AVR64K, AVR4K, AVR2K},
  102. + {"atmega649p", AVR64K, AVR4K, AVR2K},
  103. + {"atmega6490", AVR64K, AVR4K, AVR2K},
  104. + {"atmega6490a", AVR64K, AVR4K, AVR2K},
  105. + {"atmega6490p", AVR64K, AVR4K, AVR2K},
  106. + {"atmega64c1", AVR64K, AVR4K, AVR2K},
  107. + {"atmega64hve", AVR64K, AVR4K, AVR1K},
  108. + {"atmega64m1", AVR64K, AVR4K, AVR2K},
  109. + {"m3000", AVR64K, AVR4K, 0UL},
  110. +
  111. + {"atmega406", AVR40K, AVR2K, AVR512},
  112. +
  113. + {"atxmega32a4", AVR36K, AVR4K, AVR1K},
  114. + {"atxmega32d4", AVR36K, AVR4K, AVR1K},
  115. +
  116. + {"at90can32", AVR32K, AVR2K, AVR1K},
  117. + {"at94k", AVR32K, AVR4K, 0UL},
  118. + {"atmega32", AVR32K, AVR2K, AVR1K},
  119. + {"atmega323", AVR32K, AVR2K, AVR1K},
  120. + {"atmega324a", AVR32K, AVR2K, AVR1K},
  121. + {"atmega324p", AVR32K, AVR2K, AVR1K},
  122. + {"atmega324pa", AVR32K, AVR2K, AVR1K},
  123. + {"atmega325", AVR32K, AVR2K, AVR1K},
  124. + {"atmega325a", AVR32K, AVR2K, AVR1K},
  125. + {"atmega325p", AVR32K, AVR2K, AVR1K},
  126. + {"atmega3250", AVR32K, AVR2K, AVR1K},
  127. + {"atmega3250a", AVR32K, AVR2K, AVR1K},
  128. + {"atmega3250p", AVR32K, AVR2K, AVR1K},
  129. + {"atmega328", AVR32K, AVR2K, AVR1K},
  130. + {"atmega328p", AVR32K, AVR2K, AVR1K},
  131. + {"atmega329", AVR32K, AVR2K, AVR1K},
  132. + {"atmega329a", AVR32K, AVR2K, AVR1K},
  133. + {"atmega329p", AVR32K, AVR2K, AVR1K},
  134. + {"atmega329pa", AVR32K, AVR2K, AVR1K},
  135. + {"atmega3290", AVR32K, AVR2K, AVR1K},
  136. + {"atmega3290a", AVR32K, AVR2K, AVR1K},
  137. + {"atmega3290p", AVR32K, AVR2K, AVR1K},
  138. + {"atmega32hvb", AVR32K, AVR2K, AVR1K},
  139. + {"atmega32c1", AVR32K, AVR2K, AVR1K},
  140. + {"atmega32hvb", AVR32K, AVR2K, AVR1K},
  141. + {"atmega32m1", AVR32K, AVR2K, AVR1K},
  142. + {"atmega32u2", AVR32K, AVR1K, AVR1K},
  143. + {"atmega32u4", AVR32K, 2560UL, AVR1K},
  144. + {"atmega32u6", AVR32K, 2560UL, AVR1K},
  145. +
  146. + {"at43usb355", AVR24K, 1120UL, 0UL},
  147. +
  148. + {"atxmega16a4", AVR20K, AVR2K, AVR1K},
  149. + {"atxmega16d4", AVR20K, AVR2K, AVR1K},
  150. +
  151. + {"at76c711", AVR16K, AVR2K, 0UL},
  152. + {"at90pwm216", AVR16K, AVR1K, AVR512},
  153. + {"at90pwm316", AVR16K, AVR1K, AVR512},
  154. + {"at90usb162", AVR16K, AVR512, AVR512},
  155. + {"atmega16", AVR16K, AVR1K, AVR512},
  156. + {"atmega16a", AVR16K, AVR1K, AVR512},
  157. + {"atmega161", AVR16K, AVR1K, AVR512},
  158. + {"atmega162", AVR16K, AVR1K, AVR512},
  159. + {"atmega163", AVR16K, AVR1K, AVR512},
  160. + {"atmega164", AVR16K, AVR1K, AVR512},
  161. + {"atmega164a", AVR16K, AVR1K, AVR512},
  162. + {"atmega164p", AVR16K, AVR1K, AVR512},
  163. + {"atmega165a", AVR16K, AVR1K, AVR512},
  164. + {"atmega165", AVR16K, AVR1K, AVR512},
  165. + {"atmega165p", AVR16K, AVR1K, AVR512},
  166. + {"atmega168", AVR16K, AVR1K, AVR512},
  167. + {"atmega168a", AVR16K, AVR1K, AVR512},
  168. + {"atmega168p", AVR16K, AVR1K, AVR512},
  169. + {"atmega169", AVR16K, AVR1K, AVR512},
  170. + {"atmega169a", AVR16K, AVR1K, AVR512},
  171. + {"atmega169p", AVR16K, AVR1K, AVR512},
  172. + {"atmega169pa", AVR16K, AVR1K, AVR512},
  173. + {"atmega16hva", AVR16K, 768UL, AVR256},
  174. + {"atmega16hva2", AVR16K, AVR1K, AVR256},
  175. + {"atmega16hvb", AVR16K, AVR1K, AVR512},
  176. + {"atmega16m1", AVR16K, AVR1K, AVR512},
  177. + {"atmega16u2", AVR16K, AVR512, AVR512},
  178. + {"atmega16u4", AVR16K, 1280UL, AVR512},
  179. + {"attiny167", AVR16K, AVR512, AVR512},
  180. +
  181. + {"at90c8534", AVR8K, 352UL, AVR512},
  182. + {"at90pwm1", AVR8K, AVR512, AVR512},
  183. + {"at90pwm2", AVR8K, AVR512, AVR512},
  184. + {"at90pwm2b", AVR8K, AVR512, AVR512},
  185. + {"at90pwm3", AVR8K, AVR512, AVR512},
  186. + {"at90pwm3b", AVR8K, AVR512, AVR512},
  187. + {"at90pwm81", AVR8K, AVR256, AVR512},
  188. + {"at90s8515", AVR8K, AVR512, AVR512},
  189. + {"at90s8535", AVR8K, AVR512, AVR512},
  190. + {"at90usb82", AVR8K, AVR512, AVR512},
  191. + {"ata6289", AVR8K, AVR512, 320UL},
  192. + {"atmega8", AVR8K, AVR1K, AVR512},
  193. + {"atmega8515", AVR8K, AVR512, AVR512},
  194. + {"atmega8535", AVR8K, AVR512, AVR512},
  195. + {"atmega88", AVR8K, AVR1K, AVR512},
  196. + {"atmega88a", AVR8K, AVR1K, AVR512},
  197. + {"atmega88p", AVR8K, AVR1K, AVR512},
  198. + {"atmega88pa", AVR8K, AVR1K, AVR512},
  199. + {"atmega8hva", AVR8K, 768UL, AVR256},
  200. + {"atmega8u2", AVR8K, AVR512, AVR512},
  201. + {"attiny84", AVR8K, AVR512, AVR512},
  202. + {"attiny84a", AVR8K, AVR512, AVR512},
  203. + {"attiny85", AVR8K, AVR512, AVR512},
  204. + {"attiny861", AVR8K, AVR512, AVR512},
  205. + {"attiny861a", AVR8K, AVR512, AVR512},
  206. + {"attiny87", AVR8K, AVR512, AVR512},
  207. + {"attiny88", AVR8K, AVR512, AVR64},
  208. +
  209. + {"at90s4414", AVR4K, 352UL, AVR256},
  210. + {"at90s4433", AVR4K, AVR128, AVR256},
  211. + {"at90s4434", AVR4K, 352UL, AVR256},
  212. + {"atmega48", AVR4K, AVR512, AVR256},
  213. + {"atmega48a", AVR4K, AVR512, AVR256},
  214. + {"atmega48p", AVR4K, AVR512, AVR256},
  215. + {"attiny4313", AVR4K, AVR256, AVR256},
  216. + {"attiny43u", AVR4K, AVR256, AVR64},
  217. + {"attiny44", AVR4K, AVR256, AVR256},
  218. + {"attiny44a", AVR4K, AVR256, AVR256},
  219. + {"attiny45", AVR4K, AVR256, AVR256},
  220. + {"attiny461", AVR4K, AVR256, AVR256},
  221. + {"attiny461a", AVR4K, AVR256, AVR256},
  222. + {"attiny48", AVR4K, AVR256, AVR64},
  223. +
  224. + {"at86rf401", AVR2K, 224UL, AVR128},
  225. + {"at90s2313", AVR2K, AVR128, AVR128},
  226. + {"at90s2323", AVR2K, AVR128, AVR128},
  227. + {"at90s2333", AVR2K, 224UL, AVR128},
  228. + {"at90s2343", AVR2K, AVR128, AVR128},
  229. + {"attiny20", AVR2K, AVR128, 0UL},
  230. + {"attiny22", AVR2K, 224UL, AVR128},
  231. + {"attiny2313", AVR2K, AVR128, AVR128},
  232. + {"attiny2313a", AVR2K, AVR128, AVR128},
  233. + {"attiny24", AVR2K, AVR128, AVR128},
  234. + {"attiny24a", AVR2K, AVR128, AVR128},
  235. + {"attiny25", AVR2K, AVR128, AVR128},
  236. + {"attiny26", AVR2K, AVR128, AVR128},
  237. + {"attiny261", AVR2K, AVR128, AVR128},
  238. + {"attiny261a", AVR2K, AVR128, AVR128},
  239. + {"attiny28", AVR2K, 0UL, 0UL},
  240. + {"attiny40", AVR2K, AVR256, 0UL},
  241. +
  242. + {"at90s1200", AVR1K, 0UL, AVR64},
  243. + {"attiny9", AVR1K, 32UL, 0UL},
  244. + {"attiny10", AVR1K, 32UL, 0UL},
  245. + {"attiny11", AVR1K, 0UL, AVR64},
  246. + {"attiny12", AVR1K, 0UL, AVR64},
  247. + {"attiny13", AVR1K, AVR64, AVR64},
  248. + {"attiny13a", AVR1K, AVR64, AVR64},
  249. + {"attiny15", AVR1K, 0UL, AVR64},
  250. +
  251. + {"attiny4", AVR512, 32UL, 0UL},
  252. + {"attiny5", AVR512, 32UL, 0UL},
  253. +};
  254. +
  255. +static char *avrmcu = NULL;
  256. +
  257. +
  258. static char *target = NULL;
  259. /* Forward declarations. */
  260. @@ -89,7 +330,8 @@ usage (FILE *stream, int status)
  261. fprintf (stream, _(" Displays the sizes of sections inside binary files\n"));
  262. fprintf (stream, _(" If no input file(s) are specified, a.out is assumed\n"));
  263. fprintf (stream, _(" The options are:\n\
  264. - -A|-B|-G --format={sysv|berkeley|gnu} Select output style (default is %s)\n\
  265. + -A|-B|-G|-C --format={sysv|berkeley|gnu|avr} Select output style (default is %s)\n\
  266. + --mcu=<avrmcu> MCU name for AVR format only\n\
  267. -o|-d|-x --radix={8|10|16} Display numbers in octal, decimal or hex\n\
  268. -t --totals Display the total sizes (Berkeley only)\n\
  269. --common Display total size for *COM* syms\n\
  270. @@ -113,6 +355,7 @@ usage (FILE *stream, int status)
  271. #define OPTION_FORMAT (200)
  272. #define OPTION_RADIX (OPTION_FORMAT + 1)
  273. #define OPTION_TARGET (OPTION_RADIX + 1)
  274. +#define OPTION_MCU (OPTION_TARGET + 1)
  275. static struct option long_options[] =
  276. {
  277. @@ -120,6 +363,7 @@ static struct option long_options[] =
  278. {"format", required_argument, 0, OPTION_FORMAT},
  279. {"radix", required_argument, 0, OPTION_RADIX},
  280. {"target", required_argument, 0, OPTION_TARGET},
  281. + {"mcu", required_argument, 0, 203},
  282. {"totals", no_argument, &show_totals, 1},
  283. {"version", no_argument, &show_version, 1},
  284. {"help", no_argument, &show_help, 1},
  285. @@ -153,7 +397,7 @@ main (int argc, char **argv)
  286. fatal (_("fatal error: libbfd ABI mismatch"));
  287. set_default_bfd_target ();
  288. - while ((c = getopt_long (argc, argv, "ABGHhVvdfotx", long_options,
  289. + while ((c = getopt_long (argc, argv, "ABCGHhVvdfotx", long_options,
  290. (int *) 0)) != EOF)
  291. switch (c)
  292. {
  293. @@ -172,12 +416,20 @@ main (int argc, char **argv)
  294. case 'g':
  295. selected_output_format = FORMAT_GNU;
  296. break;
  297. + case 'A':
  298. + case 'a':
  299. + selected_output_format = FORMAT_AVR;
  300. + break;
  301. default:
  302. non_fatal (_("invalid argument to --format: %s"), optarg);
  303. usage (stderr, 1);
  304. }
  305. break;
  306. + case OPTION_MCU:
  307. + avrmcu = optarg;
  308. + break;
  309. +
  310. case OPTION_TARGET:
  311. target = optarg;
  312. break;
  313. @@ -214,6 +466,9 @@ main (int argc, char **argv)
  314. case 'G':
  315. selected_output_format = FORMAT_GNU;
  316. break;
  317. + case 'C':
  318. + selected_output_format = FORMAT_AVR;
  319. + break;
  320. case 'v':
  321. case 'V':
  322. show_version = 1;
  323. @@ -656,6 +911,98 @@ print_sysv_format (bfd *file)
  324. printf ("\n\n");
  325. }
  326. +static avr_device_t *
  327. +avr_find_device (void)
  328. +{
  329. + unsigned int i;
  330. + if (avrmcu != NULL)
  331. + {
  332. + for (i = 0; i < sizeof(avr) / sizeof(avr[0]); i++)
  333. + {
  334. + if (strcmp(avr[i].name, avrmcu) == 0)
  335. + {
  336. + /* Match found */
  337. + return (&avr[i]);
  338. + }
  339. + }
  340. + }
  341. + return (NULL);
  342. +}
  343. +
  344. +static void
  345. +print_avr_format (bfd *file)
  346. +{
  347. + char *avr_name = "Unknown";
  348. + int flashmax = 0;
  349. + int rammax = 0;
  350. + int eeprommax = 0;
  351. + asection *section;
  352. + bfd_size_type my_datasize = 0;
  353. + bfd_size_type my_textsize = 0;
  354. + bfd_size_type my_bsssize = 0;
  355. + bfd_size_type bootloadersize = 0;
  356. + bfd_size_type noinitsize = 0;
  357. + bfd_size_type eepromsize = 0;
  358. +
  359. + avr_device_t *avrdevice = avr_find_device();
  360. + if (avrdevice != NULL)
  361. + {
  362. + avr_name = avrdevice->name;
  363. + flashmax = avrdevice->flash;
  364. + rammax = avrdevice->ram;
  365. + eeprommax = avrdevice->eeprom;
  366. + }
  367. +
  368. + if ((section = bfd_get_section_by_name (file, ".data")) != NULL)
  369. + my_datasize = bfd_section_size (section);
  370. + if ((section = bfd_get_section_by_name (file, ".text")) != NULL)
  371. + my_textsize = bfd_section_size (section);
  372. + if ((section = bfd_get_section_by_name (file, ".bss")) != NULL)
  373. + my_bsssize = bfd_section_size (section);
  374. + if ((section = bfd_get_section_by_name (file, ".bootloader")) != NULL)
  375. + bootloadersize = bfd_section_size (section);
  376. + if ((section = bfd_get_section_by_name (file, ".noinit")) != NULL)
  377. + noinitsize = bfd_section_size (section);
  378. + if ((section = bfd_get_section_by_name (file, ".eeprom")) != NULL)
  379. + eepromsize = bfd_section_size (section);
  380. +
  381. + bfd_size_type text = my_textsize + my_datasize + bootloadersize;
  382. + bfd_size_type data = my_datasize + my_bsssize + noinitsize;
  383. + bfd_size_type eeprom = eepromsize;
  384. +
  385. + printf ("AVR Memory Usage\n"
  386. + "----------------\n"
  387. + "Device: %s\n\n", avr_name);
  388. +
  389. + /* Text size */
  390. + printf ("Program:%8ld bytes", text);
  391. + if (flashmax > 0)
  392. + {
  393. + printf (" (%2.1f%% Full)", ((float)text / flashmax) * 100);
  394. + }
  395. + printf ("\n(.text + .data + .bootloader)\n\n");
  396. +
  397. + /* Data size */
  398. + printf ("Data: %8ld bytes", data);
  399. + if (rammax > 0)
  400. + {
  401. + printf (" (%2.1f%% Full)", ((float)data / rammax) * 100);
  402. + }
  403. + printf ("\n(.data + .bss + .noinit)\n\n");
  404. +
  405. + /* EEPROM size */
  406. + if (eeprom > 0)
  407. + {
  408. + printf ("EEPROM: %8ld bytes", eeprom);
  409. + if (eeprommax > 0)
  410. + {
  411. + printf (" (%2.1f%% Full)", ((float)eeprom / eeprommax) * 100);
  412. + }
  413. + printf ("\n(.eeprom)\n\n");
  414. + }
  415. +}
  416. +
  417. +
  418. static void
  419. print_sizes (bfd *file)
  420. {
  421. @@ -663,6 +1010,8 @@ print_sizes (bfd *file)
  422. calculate_common_size (file);
  423. if (selected_output_format == FORMAT_SYSV)
  424. print_sysv_format (file);
  425. + else if (selected_output_format == FORMAT_AVR)
  426. + print_avr_format (file);
  427. else
  428. print_berkeley_or_gnu_format (file);
  429. }