FreeCalypso > hg > freecalypso-reveng
changeset 293:23e5b940cb8b
blobstat: mostly complete
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 21 Sep 2019 21:07:45 +0000 |
parents | 6791499809e0 |
children | ff2a6433687f |
files | blobstat/globals.c blobstat/grokmap.c blobstat/om-libclass blobstat/readclass.c blobstat/struct.h |
diffstat | 5 files changed, 535 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/blobstat/globals.c Sat Sep 21 21:07:45 2019 +0000 @@ -0,0 +1,5 @@ +#include <sys/types.h> +#include "struct.h" + +struct category *category_list; +struct libentry *libentry_list;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/blobstat/grokmap.c Sat Sep 21 21:07:45 2019 +0000 @@ -0,0 +1,247 @@ +#include <sys/types.h> +#include <ctype.h> +#include <string.h> +#include <strings.h> +#include <stdio.h> +#include <stdlib.h> +#include "struct.h" + +extern struct libentry *libentry_list; + +static FILE *mapfile; +static char linebuf[1024]; +static int lineno; +static char *filename_for_errs; + +static struct category * +find_category_of_object(libname, member) + char *libname, *member; +{ + struct libentry *p; + + for (p = libentry_list; p; p = p->next) { + if (strcmp(p->libname, libname)) + continue; + if (!p->member || !strcmp(p->member, member)) + return(p->cat); + } + return(0); +} + +static void +getline() +{ + char *cp; + + if (!fgets(linebuf, sizeof linebuf, mapfile)) { + fprintf(stderr, "%s: premature EOF\n", filename_for_errs); + exit(1); + } + lineno++; + cp = index(linebuf, '\n'); + if (!cp) { + fprintf(stderr, "%s line %d: too long or unterminated\n", + filename_for_errs, lineno); + exit(1); + } + if (cp > linebuf && cp[-1] == '\r') + *--cp = '\0'; +} + +static +valid_section_name_char(c, first) +{ + if (isalpha(c) || c == '_' || c == '.' || c == '$') + return(1); + else if (isdigit(c) && !first) + return(1); + else + return(0); +} + +static +parse_input_section_line(libnameout, memberout) + char *libnameout, **memberout; +{ + int i; + char *cp; + + for (i = 0; i < 18; i++) + if (linebuf[i] != ' ') { +inv_input_sec_line: fprintf(stderr, + "%s line %d: invalid input section line\n", + filename_for_errs, lineno); + exit(1); + } + while (i < 26) + if (!isxdigit(linebuf[i++])) + goto inv_input_sec_line; + while (i < 30) + if (linebuf[i++] != ' ') + goto inv_input_sec_line; + while (i < 38) + if (!isxdigit(linebuf[i++])) + goto inv_input_sec_line; + while (i < 43) + if (linebuf[i++] != ' ') + goto inv_input_sec_line; + if (isalpha(linebuf[43])) { + cp = linebuf + 43; + while (isalnum(*cp) || *cp == '_') + cp++; + if (strncmp(cp, ".lib : ", 7)) + return(0); + cp += 4; + *cp++ = '\0'; + strcpy(libnameout, linebuf + 43); + cp += 2; + if (!isalpha(*cp)) + goto inv_input_sec_line; + *memberout = cp; + while (isalnum(*cp) || *cp == '_' || *cp == '.') + cp++; + if (*cp != ' ') + goto inv_input_sec_line; + *cp = '\0'; + return(1); + } else if (linebuf[43] == ' ') { + cp = linebuf + 43; + while (*cp == ' ') + cp++; + if (*cp++ != ':') + goto inv_input_sec_line; + if (*cp++ != ' ') + goto inv_input_sec_line; + if (!isalpha(*cp)) + goto inv_input_sec_line; + *memberout = cp; + while (isalnum(*cp) || *cp == '_' || *cp == '.') + cp++; + if (*cp != ' ') + goto inv_input_sec_line; + *cp = '\0'; + return(1); + } else + return(0); +} + +static +process_output_section() +{ + int c, i; + int uninit; + char libname[1024], *member; + struct category *cat; + + getline(); + if (!linebuf[0]) + return(1); + if (!valid_section_name_char(linebuf[0], 1)) { +inv_outsec_line: + fprintf(stderr, + "%s line %d: invalid output section beginning line\n", + filename_for_errs, lineno); + exit(1); + } + for (i = 1; ; i++) { + c = linebuf[i]; + if (c == '\0' || c == ' ') + break; + if (!valid_section_name_char(c, 0)) + goto inv_outsec_line; + } + if (!c) { + if (i < 8) + goto inv_outsec_line; + getline(); + for (i = 0; i < 8; i++) + if (linebuf[i] != ' ') + goto inv_outsec_line; + } else { + if (i > 7) + goto inv_outsec_line; + for (; i < 8; i++) + if (linebuf[i] != ' ') + goto inv_outsec_line; + } + if (linebuf[i++] != '0') + goto inv_outsec_line; + while (i < 13) + if (linebuf[i++] != ' ') + goto inv_outsec_line; + while (i < 21) + if (!isxdigit(linebuf[i++])) + goto inv_outsec_line; + while (i < 25) + if (linebuf[i++] != ' ') + goto inv_outsec_line; + while (i < 33) + if (!isxdigit(linebuf[i++])) + goto inv_outsec_line; + while (i < 38) + if (linebuf[i++] != ' ') + goto inv_outsec_line; + uninit = !strcmp(linebuf + 38, "UNINITIALIZED"); + /* input section lines */ + libname[0] = '\0'; + for (;;) { + getline(); + if (!linebuf[0]) + break; + if (!parse_input_section_line(libname, &member)) + continue; + if (!libname[0]) { + fprintf(stderr, "%s line %d: missing library name\n", + filename_for_errs, lineno); + exit(1); + } + cat = find_category_of_object(libname, member); + if (!cat) { + fprintf(stderr, "%s line %d: unknown library object\n", + filename_for_errs, lineno); + exit(1); + } + if (!uninit) + cat->accum += strtoul(linebuf + 30, 0, 16); + } + return(0); +} + +process_map_file(filename) + char *filename; +{ + filename_for_errs = filename; + mapfile = fopen(filename, "r"); + if (!mapfile) { + perror(filename); + exit(1); + } + do + getline(); + while (strcmp(linebuf, "SECTION ALLOCATION MAP")); + /* 4 fixed info lines */ + getline(); + if (linebuf[0]) { +bad_sectionmap_hdr: + fprintf(stderr, + "%s line %d: wrong lines after SECTION ALLOCATION MAP\n", + filename_for_errs, lineno); + exit(1); + } + getline(); + if (strcmp(linebuf, + " output attributes/")) + goto bad_sectionmap_hdr; + getline(); + if (strcmp(linebuf, + "section page origin length input sections")) + goto bad_sectionmap_hdr; + getline(); + if (strcmp(linebuf, + "-------- ---- ---------- ---------- ----------------")) + goto bad_sectionmap_hdr; + while (!process_output_section()) + ; + fclose(mapfile); + return(0); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/blobstat/om-libclass Sat Sep 21 21:07:45 2019 +0000 @@ -0,0 +1,111 @@ +# This classification spec lists all of the component libraries used by +# Openmoko in building their mokoN firmwares, and classifies each lib +# as to whether OM had the source for it, or had it as a binary-only blob. + +ccddata.lib blob + +# ACI libs +aci.lib src +aciext.lib src +aci_dti_mng.lib src +atiext.lib src +config_gprs_fl.lib src +config_gprs_ir.lib src + +# G23M protocol stack libs +cc.lib blob +cci.lib blob +cci_ir.lib blob +dl.lib blob +dti.lib blob +fad.lib blob +gmm.lib blob +grlc.lib blob +grlc_ir.lib blob +grr.lib blob +l1_pei.lib blob +l2r.lib blob +llc.lib blob +mm.lib blob +ra.lib blob +rlp.lib blob +rr.lib blob +sim_b_lib.lib blob +sm.lib blob +sms.lib blob +sndcp.lib blob +ss.lib blob +t30.lib blob +uart_b_lib.lib blob +ppp.lib blob +ppp_ir.lib blob + +# BuSyB as received by OM from TI was not set up to recompile alr and comlib +# from source, but OM did have source for these two components, this source +# was exactly corresponding to the prebuilt libs they used, and it would have +# been easy for them to tweak BuSyB to recompile these components from source +# had they cared to, so we'll count them in the source category. + +alr.lib src +comlib.lib src + +# Condat drivers +gdi.lib src + +# GPF +ccd_na7_db.lib blob +frame_na7_db_fl.lib blob +frame_na7_db_ir.lib blob +misc_na7_db_fl.lib src +misc_na7_db_ir.lib src +osx_na7_db.lib blob +tif_na7_db_fl.lib src +tif_na7_db_ir.lib src + +# core drivers +drivers_flash.lib src + +# Layer 1 +tpudrv.lib blob +l1_ext.lib blob +l1_int.lib blob +l1_custom_ext.lib blob +l1_custom_int.lib blob + +riviera_core_flash.lib src +riviera_cust_flash.lib src + +# services +atp.lib src +audio.lib src +audio_bgd.lib src +cst.lib src +dar.lib src +dar_gbl_var.lib src +etm.lib src +lls.lib src +mks.lib src + +# app drivers +abb.lib src +buzzer.lib src +ffs.lib src +ffs_drv.lib src +ffs_pcm.lib src +kpd.lib src +lcc.lib src +power.lib src +rtc_drv.lib src +sim_drv.lib src +spi_drv.lib src +uart_drv.lib src + +# system glue +main.lib blob +bootloader.lib blob + +# Nucleus and TI's compiler stuff +nucleus_flash_nodbg.lib blob +nucleus_int_ram_nodbg.lib blob +rts16le_flash.lib blob +rts16le_int_ram.lib blob
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/blobstat/readclass.c Sat Sep 21 21:07:45 2019 +0000 @@ -0,0 +1,160 @@ +#include <sys/types.h> +#include <ctype.h> +#include <string.h> +#include <strings.h> +#include <stdio.h> +#include <stdlib.h> +#include "struct.h" + +extern struct category *category_list; +extern struct libentry *libentry_list; + +static struct category * +find_or_create_cat(catname) + char *catname; +{ + struct category *p, **pp; + char *buf; + + for (pp = &category_list; p = *pp; pp = &p->next) + if (!strcmp(p->name, catname)) + return(p); + buf = malloc(sizeof(struct category) + strlen(catname) + 1); + if (!buf) { + perror("malloc"); + exit(1); + } + p = (struct category *) buf; + p->name = buf + sizeof(struct category); + strcpy(p->name, catname); + p->accum = 0; + p->next = 0; + *pp = p; + return(p); +} + +static +add_whole_lib(libname, cat) + char *libname; + struct category *cat; +{ + struct libentry *p, **pp; + char *buf; + + for (pp = &libentry_list; p = *pp; pp = &p->next) + if (!strcmp(p->libname, libname)) + return(-1); + buf = malloc(sizeof(struct libentry) + strlen(libname) + 1); + if (!buf) { + perror("malloc"); + exit(1); + } + p = (struct libentry *) buf; + p->libname = buf + sizeof(struct libentry); + strcpy(p->libname, libname); + p->member = 0; + p->cat = cat; + p->next = 0; + *pp = p; + return(0); +} + +static +add_lib_member(libname, member, cat) + char *libname, *member; + struct category *cat; +{ + struct libentry *p, **pp; + char *buf; + + for (pp = &libentry_list; p = *pp; pp = &p->next) { + if (strcmp(p->libname, libname)) + continue; + if (!p->member || !strcmp(p->member, member)) + return(-1); + } + buf = malloc(sizeof(struct libentry) + strlen(libname) + + strlen(member) + 2); + if (!buf) { + perror("malloc"); + exit(1); + } + p = (struct libentry *) buf; + buf += sizeof(struct libentry); + p->libname = buf; + strcpy(p->libname, libname); + buf += strlen(libname) + 1; + p->member = buf; + strcpy(p->member, member); + p->cat = cat; + p->next = 0; + *pp = p; + return(0); +} + +static void +process_line(linebuf, lineno, filename_for_errs) + char *linebuf, *filename_for_errs; + int lineno; +{ + char *cp, *libname, *member, *catname; + struct category *cat; + int rc; + + for (cp = linebuf; isspace(*cp); cp++) + ; + if (*cp == '\0' || *cp == '#') + return; + for (libname = cp; *cp && !isspace(*cp); cp++) + ; + if (!*cp) { +inv: fprintf(stderr, "%s line %d: invalid syntax\n", + filename_for_errs, lineno); + exit(1); + } + *cp++ = '\0'; + while (isspace(*cp)) + cp++; + if (*cp == '\0' || *cp == '#') + goto inv; + for (catname = cp; *cp && !isspace(*cp); cp++) + ; + if (*cp) + *cp++ = '\0'; + while (isspace(*cp)) + cp++; + if (*cp != '\0' && *cp != '#') + goto inv; + member = index(libname, ':'); + if (member) + *member++ = '\0'; + cat = find_or_create_cat(catname); + if (member) + rc = add_lib_member(libname, member, cat); + else + rc = add_whole_lib(libname, cat); + if (rc < 0) { + fprintf(stderr, + "%s line %d: conflict with earlier declaration\n", + filename_for_errs, lineno); + exit(1); + } +} + +read_class_file(filename) + char *filename; +{ + FILE *inf; + int lineno; + char linebuf[512]; + + inf = fopen(filename, "r"); + if (!inf) { + perror(filename); + exit(1); + } + for (lineno = 1; fgets(linebuf, sizeof linebuf, inf); lineno++) + process_line(linebuf, lineno, filename); + fclose(inf); + return(0); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/blobstat/struct.h Sat Sep 21 21:07:45 2019 +0000 @@ -0,0 +1,12 @@ +struct category { + char *name; + u_long accum; + struct category *next; +}; + +struct libentry { + char *libname; + char *member; + struct category *cat; + struct libentry *next; +};