summaryrefslogtreecommitdiffstats
path: root/firmware/rolo.c
diff options
context:
space:
mode:
authorThomas Martitz <kugel@rockbox.org>2011-08-14 15:13:00 +0000
committerThomas Martitz <kugel@rockbox.org>2011-08-14 15:13:00 +0000
commitd1322b71595336740eb5e18e5deed056ddb71c7a (patch)
tree812db6a9c2e9d78405ec0ed38465fd88dc5be748 /firmware/rolo.c
parent9b9bd73dfb212d4192fccc5fc5e269fc6499139c (diff)
downloadrockbox-d1322b71595336740eb5e18e5deed056ddb71c7a.tar.gz
rockbox-d1322b71595336740eb5e18e5deed056ddb71c7a.tar.bz2
rockbox-d1322b71595336740eb5e18e5deed056ddb71c7a.zip
GSoC/Buflib: Replace all direct accesses to audiobuf with buffer API functions.
Namely, introduce buffer_get_buffer() and buffer_release_buffer(). buffer_get_buffer() aquires all available and grabs a lock, attempting to call buffer_alloc() or buffer_get_buffer() while this lock is locked will cause a panicf() (doesn't actually happen, but is for debugging purpose). buffer_release_buffer() unlocks that lock and can additionally increment the audiobuf buffer to make an allocation. Pass 0 to only unlock if buffer was used temporarily only. buffer_available() is a replacement function to query audiobuflen, i.e. what's left in the buffer. Buffer init is moved up in the init chain and handles ipodvideo64mb internally. Further changes happened to mp3data.c and talk.c as to not call the above API functions, but get the buffer from callers. The caller is the audio system which has the buffer lock while mp3data.c and talk mess with the buffer. mpeg.c now implements some buffer related functions of playback.h, especially audio_get_buffer(), allowing to reduce #ifdef hell a tiny bit. audiobuf and audiobufend are local to buffer.c now. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30308 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/rolo.c')
-rw-r--r--firmware/rolo.c28
1 files changed, 21 insertions, 7 deletions
diff --git a/firmware/rolo.c b/firmware/rolo.c
index 078a4e9827..9b6f4fec4a 100644
--- a/firmware/rolo.c
+++ b/firmware/rolo.c
@@ -99,6 +99,7 @@ void rolo_restart_cop(void)
static void rolo_error(const char *text)
{
+ buffer_release_buffer(0);
lcd_clear_display();
lcd_puts(0, 0, "ROLO error:");
lcd_puts_scroll(0, 1, text);
@@ -213,6 +214,8 @@ int rolo_load(const char* filename)
unsigned short checksum,file_checksum;
#endif
unsigned char* ramstart = (void*)&loadaddress;
+ unsigned char* filebuf;
+ size_t filebuf_size;
lcd_clear_display();
lcd_puts(0, 0, "ROLO...");
@@ -235,6 +238,10 @@ int rolo_load(const char* filename)
length = filesize(fd) - FIRMWARE_OFFSET_FILE_DATA;
+ /* get the system buffer. release only in case of error, otherwise
+ * we don't return anyway */
+ filebuf = buffer_get_buffer(&filebuf_size);
+
#if CONFIG_CPU != SH7034
/* Read and save checksum */
lseek(fd, FIRMWARE_OFFSET_FILE_CRC, SEEK_SET);
@@ -260,7 +267,14 @@ int rolo_load(const char* filename)
lseek(fd, FIRMWARE_OFFSET_FILE_DATA, SEEK_SET);
- if (read(fd, audiobuf, length) != length) {
+ /* this shouldn't happen, but well */
+ if ((long)filebuf_size < length)
+ {
+ rolo_error("File too big");
+ return -1;
+ }
+
+ if (read(fd, filebuf, length) != length) {
rolo_error("Error Reading File");
return -1;
}
@@ -268,12 +282,12 @@ int rolo_load(const char* filename)
#ifdef MI4_FORMAT
/* Check CRC32 to see if we have a valid file */
chksum_crc32gentab();
- checksum = chksum_crc32 (audiobuf, length);
+ checksum = chksum_crc32 (filebuf, length);
#else
checksum = MODEL_NUMBER;
for(i = 0;i < length;i++) {
- checksum += audiobuf[i];
+ checksum += filebuf[i];
}
#endif
@@ -329,12 +343,12 @@ int rolo_load(const char* filename)
lseek(fd, FIRMWARE_OFFSET_FILE_DATA, SEEK_SET);
/* verify that file can be read and descrambled */
- if ((audiobuf + (2*length)+4) >= audiobufend) {
+ if ((size_t)((2*length)+4) >= filebuf_size) {
rolo_error("Not enough room to load file");
return -1;
}
- if (read(fd, &audiobuf[length], length) != (int)length) {
+ if (read(fd, &filebuf[length], length) != (int)length) {
rolo_error("Error Reading File");
return -1;
}
@@ -342,7 +356,7 @@ int rolo_load(const char* filename)
lcd_puts(0, 1, "Descramble");
lcd_update();
- checksum = descramble(audiobuf + length, audiobuf, length);
+ checksum = descramble(filebuf + length, filebuf, length);
/* Verify checksum against file header */
if (checksum != file_checksum) {
@@ -374,7 +388,7 @@ int rolo_load(const char* filename)
PAIOR = 0x0FA0;
#endif
#endif
- rolo_restart(audiobuf, ramstart, length);
+ rolo_restart(filebuf, ramstart, length);
return 0; /* this is never reached */
(void)checksum; (void)file_checksum;