From 1eca02d86384bd399f3d3b0fce5e6be48ce8156f Mon Sep 17 00:00:00 2001 From: Dave Chapman Date: Tue, 4 Aug 2009 20:32:30 +0000 Subject: Add support (on Linux and win32 only - I couldn't figure this out on OS X) for reading the XML device information from ipods. This information includes the RAM size, which is potentially useful for rbutil to distinguish between the two ipod video builds. This is implemented as both a new --dump-xml option (to dump the entire XML to a file) and a new 'ramsize' field in struct ipod_t. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@22165 a1c6a512-1295-4272-9138-f99709370657 --- rbutil/ipodpatcher/ipodpatcher.c | 80 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) (limited to 'rbutil/ipodpatcher/ipodpatcher.c') diff --git a/rbutil/ipodpatcher/ipodpatcher.c b/rbutil/ipodpatcher/ipodpatcher.c index dd650506a1..1a5268bb6d 100644 --- a/rbutil/ipodpatcher/ipodpatcher.c +++ b/rbutil/ipodpatcher/ipodpatcher.c @@ -1401,6 +1401,86 @@ int write_dos_partition_table(struct ipod_t* ipod) return 0; } +/* Get the XML Device Information, as documented here: + + http://www.ipodlinux.org/wiki/Device_Information +*/ + +int ipod_get_xmlinfo(struct ipod_t* ipod) +{ + unsigned char hdr[255]; + unsigned char buf[255]; + char* p; + int psize; + int npages; + int i; + + if (ipod_scsi_inquiry(ipod, 0xc0, buf, sizeof(buf)) < 0) + { + fprintf(stderr,"[ERR] Sending SCSI Command failed.\n"); + return -1; + } + + /* Reading directly into hdr[] causes problems (for an unknown reason) on + win32 */ + memcpy(hdr, buf, sizeof(hdr)); + + npages = hdr[3]; + + psize = npages * 0xf8; /* Hopefully this is enough. */ + + ipod->xmlinfo = malloc(psize); + ipod->xmlinfo_len = 0; + + if (ipod->xmlinfo == NULL) { + fprintf(stderr,"[ERR] Could not allocate RAM for xmlinfo\n"); + return -1; + } + + p = ipod->xmlinfo; + + for (i=0; i < npages; i++) { + if (ipod_scsi_inquiry(ipod, hdr[i+4], buf, sizeof(buf)) < 0) { + fprintf(stderr,"[ERR] Sending SCSI Command failed.\n"); + return -1; + } + + if ((buf[3] + ipod->xmlinfo_len) > psize) { + fprintf(stderr,"[ERR] Ran out of memory reading xmlinfo\n"); + free(ipod->xmlinfo); + ipod->xmlinfo = NULL; + ipod->xmlinfo_len = 0; + return -1; + } + + memcpy(p, buf + 4, buf[3]); + p += buf[3]; + ipod->xmlinfo_len += buf[3]; + } + + /* NULL-terminate the XML info */ + *p = 0; + + fprintf(stderr,"[INFO] Read XML info (%d bytes)\n",ipod->xmlinfo_len); + + return 0; +} + +void ipod_get_ramsize(struct ipod_t* ipod) +{ + const char needle[] = "RAM\n"; + char* p; + + if (ipod->xmlinfo == NULL) + return; + + p = strstr(ipod->xmlinfo, needle); + + if (p) { + ipod->ramsize = atoi(p + sizeof(needle) - 1); + } +} + #ifndef RBUTIL static inline uint32_t getuint32le(unsigned char* buf) -- cgit v1.2.3