summaryrefslogtreecommitdiffstats
path: root/firmware/usbstack/usb_storage.c
AgeCommit message (Collapse)AuthorFilesLines
2018-07-30Workaround for usb_storage_init_connection() panicCástor Muñoz1-0/+1
For s5l8701, s5l8702 and as3525v2 targets. The crash occurs when USB is inserted or extracted while the playlist is being loaded or updated (it could take a few seconds for huge playlists), at this point all buflib memory is allocated and not freed before usb_starage_init_connection() is executed. This workaround mitigates this panic by using static memory for USB buffers, so this memory cannot be used for other tasks, in addition the problem still persist when playlist load is 'paused' by USB insertion and then updated after USB extraction. Change-Id: Iff1db5a949361fd543e0b494924d1f2906c84b5e
2017-03-12Do some housekeeping with fat.h and SECTOR_SIZEMichael Sevakis1-5/+1
Many includes of fat.h are pointless. Some includes are just for SECTOR_SIZE. Add a file 'firmware/include/fs_defines.h' for that and to define tuneable values that were scattered amongst various headers. Remove some local definitions of SECTOR_SIZE since they have to be in agreement with the rest of the fs code anyway. (We'll see what's in fact pointless in a moment ;) Change-Id: I9ba183bf58bd87f5c45eba7bd675c7e2c1c18ed5
2015-02-16Revert "usb_storage: make it a bit more correct"Amaury Pouly1-1/+0
Clearly this was a stupid commit, no idea why I did that. This reverts commit 074e911859a0d3464fde9b701b3cff712c5826e0.
2014-08-30Rewrite filesystem code (WIP)Michael Sevakis1-4/+1
This patch redoes the filesystem code from the FAT driver up to the clipboard code in onplay.c. Not every aspect of this is finished therefore it is still "WIP". I don't wish to do too much at once (haha!). What is left to do is get dircache back in the sim and find an implementation for the dircache indicies in the tagcache and playlist code or do something else that has the same benefit. Leaving these out for now does not make anything unusable. All the basics are done. Phone app code should probably get vetted (and app path handling just plain rewritten as environment expansions); the SDL app and Android run well. Main things addressed: 1) Thread safety: There is none right now in the trunk code. Most of what currently works is luck when multiple threads are involved or multiple descriptors to the same file are open. 2) POSIX compliance: Many of the functions behave nothing like their counterparts on a host system. This leads to inconsistent code or very different behavior from native to hosted. One huge offender was rename(). Going point by point would fill a book. 3) Actual running RAM usage: Many targets will use less RAM and less stack space (some more RAM because I upped the number of cache buffers for large memory). There's very little memory lying fallow in rarely-used areas (see 'Key core changes' below). Also, all targets may open the same number of directory streams whereas before those with less than 8MB RAM were limited to 8, not 12 implying those targets will save slightly less. 4) Performance: The test_disk plugin shows markedly improved performance, particularly in the area of (uncached) directory scanning, due partly to more optimal directory reading and to a better sector cache algorithm. Uncached times tend to be better while there is a bit of a slowdown in dircache due to it being a bit heavier of an implementation. It's not noticeable by a human as far as I can say. Key core changes: 1) Files and directories share core code and data structures. 2) The filesystem code knows which descriptors refer to same file. This ensures that changes from one stream are appropriately reflected in every open descriptor for that file (fileobj_mgr.c). 3) File and directory cache buffers are borrowed from the main sector cache. This means that when they are not in use by a file, they are not wasted, but used for the cache. Most of the time, only a few of them are needed. It also means that adding more file and directory handles is less expensive. All one must do in ensure a large enough cache to borrow from. 4) Relative path components are supported and the namespace is unified. It does not support full relative paths to an implied current directory; what is does support is use of "." and "..". Adding the former would not be very difficult. The namespace is unified in the sense that volumes may be specified several times along with relative parts, e.g.: "/<0>/foo/../../<1>/bar" :<=> "/<1>/bar". 5) Stack usage is down due to sharing of data, static allocation and less duplication of strings on the stack. This requires more serialization than I would like but since the number of threads is limited to a low number, the tradoff in favor of the stack seems reasonable. 6) Separates and heirarchicalizes (sic) the SIM and APP filesystem code. SIM path and volume handling is just like the target. Some aspects of the APP file code get more straightforward (e.g. no path hashing is needed). Dircache: Deserves its own section. Dircache is new but pays homage to the old. The old one was not compatible and so it, since it got redone, does all the stuff it always should have done such as: 1) It may be update and used at any time during the build process. No longer has one to wait for it to finish building to do basic file management (create, remove, rename, etc.). 2) It does not need to be either fully scanned or completely disabled; it can be incomplete (i.e. overfilled, missing paths), still be of benefit and be correct. 3) Handles mounting and dismounting of individual volumes which means a full rebuild is not needed just because you pop a new SD card in the slot. Now, because it reuses its freed entry data, may rebuild only that volume. 4) Much more fundamental to the file code. When it is built, it is the keeper of the master file list whether enabled or not ("disabled" is just a state of the cache). Its must always to ready to be started and bind all streams opened prior to being enabled. 5) Maintains any short filenames in OEM format which means that it does not need to be rebuilt when changing the default codepage. Miscellaneous Compatibility: 1) Update any other code that would otherwise not work such as the hotswap mounting code in various card drivers. 2) File management: Clipboard needed updating because of the behavioral changes. Still needs a little more work on some finer points. 3) Remove now-obsolete functionality such as the mutex's "no preempt" flag (which was only for the prior FAT driver). 4) struct dirinfo uses time_t rather than raw FAT directory entry time fields. I plan to follow up on genericizing everything there (i.e. no FAT attributes). 5) unicode.c needed some redoing so that the file code does not try try to load codepages during a scan, which is actually a problem with the current code. The default codepage, if any is required, is now kept in RAM separarately (bufalloced) from codepages specified to iso_decode() (which must not be bufalloced because the conversion may be done by playback threads). Brings with it some additional reusable core code: 1) Revised file functions: Reusable code that does things such as safe path concatenation and parsing without buffer limitations or data duplication. Variants that copy or alter the input path may be based off these. To do: 1) Put dircache functionality back in the sim. Treating it internally as a different kind of file system seems the best approach at this time. 2) Restore use of dircache indexes in the playlist and database or something effectively the same. Since the cache doesn't have to be complete in order to be used, not getting a hit on the cache doesn't unambiguously say if the path exists or not. Change-Id: Ia30f3082a136253e3a0eae0784e3091d138915c8 Reviewed-on: http://gerrit.rockbox.org/566 Reviewed-by: Michael Sevakis <jethead71@rockbox.org> Tested: Michael Sevakis <jethead71@rockbox.org>
2014-01-11Don't use core_alloc_maximum() in usb_storage.Frank Gevaerts1-6/+5
usb_storage needs a fairly reasonable amount of memory. Allocating what we need and no more allows other (future) USB drivers to get something too, and is much cleaner in general. Change-Id: Iec9573c0f251f02400f92d92727cbf2969785de0
2014-01-05Check that core_alloc_maximum() returned something useful, and panic if notFrank Gevaerts1-0/+5
Change-Id: I7ae40db0f81d1d51742501936b13b387f94a25e5
2013-12-23playback,talk: Share audiobuffer via core_alloc_maximum().Thomas Martitz1-5/+12
This fixes the radioart crash that was the result of buffering.c working on a freed buffer at the same time as buflib (radioart uses buffering.c for the images). With this change the buffer is owned by buflib exclusively so this cannot happen. As a result, audio_get_buffer() doesn't exist anymore. Callers should call core_alloc_maximum() directly. This buffer needs to be protected as usual against movement if necessary (previously it was not protected at all which cased the radioart crash), To get most of it they can adjust the willingness of the talk engine to give its buffer away (at the expense of disabling voice interface) with the new talk_buffer_set_policy() function. Change-Id: I52123012208d04967876a304451d634e2bef3a33
2013-08-17Cleanup MV/MD macros a little.Michael Sevakis1-4/+4
When using variadic macros there's no need for IF_MD2/IF_MV2 to deal with function parameters. IF_MD/IF_MV are enough. Throw in IF_MD_DRV/ID_MV_VOL that return the parameter if MD/MV, or 0 if not. Change-Id: I7605e6039f3be19cb47110c84dcb3c5516f2c3eb
2013-08-12Fix response length calculation for SCSI_REPORT_LUNSBertrik Sikken1-1/+2
Change-Id: I1167851bae20d9275eb2f441ce9dc73c8b2f09b1 Reviewed-on: http://gerrit.rockbox.org/488 Reviewed-by: Frank Gevaerts <frank@gevaerts.be> Reviewed-by: Bertrik Sikken <bertrik@sikken.nl> Tested-by: Bertrik Sikken <bertrik@sikken.nl>
2013-07-24usb stack: add more verbose debug logf()sMarcin Bukat1-0/+1
Change-Id: I087aefd2854978813c7e4ed7ef7da400f3692e39
2013-07-24usb_storage: make it a bit more correctAmaury Pouly1-0/+1
Add stall when unknown SCSI command is hit Change-Id: Icbeea905cd262ab296fb34470e54c665b8bab488
2013-05-17FS#12854 - ipod-time-sync sets wrong dayrbutil/mkamsboot/mkamsboot.cBoris Gjenero1-1/+1
Change-Id: I8ac7561119e51774b9aee377e7373a7e830a5780
2012-05-07fix a mistake of 803408f18 spotted by n1sRafaël Carré1-1/+1
When the source string terminates (with a 0) we pad the rest of the destination with spaces.
2012-05-07simplify yearday_to_daymonth()Rafaël Carré1-20/+9
2012-05-07simplify copy_paddedRafaël Carré1-11/+7
2011-12-31usb-target.h: removeRafaël Carré1-3/+0
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@31498 a1c6a512-1295-4272-9138-f99709370657
2011-12-31The AMSv1 driver limitation that disallows 64K transfers is a USB core ↵Frank Gevaerts1-2/+2
limitation, not a CPU limitation, so use the appropriate defines to test for it git-svn-id: svn://svn.rockbox.org/rockbox/trunk@31476 a1c6a512-1295-4272-9138-f99709370657
2011-12-29usb PACK_DATA: use a static inline to enable type checkingRafaël Carré1-3/+3
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@31467 a1c6a512-1295-4272-9138-f99709370657
2011-12-17Commit to certain names for cache coherency APIs and discard the aliases.Michael Sevakis1-1/+1
Wouldn't surprise me a bit to get some non-green. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@31339 a1c6a512-1295-4272-9138-f99709370657
2011-12-16Remove USB time sync code when there's no RTC.Boris Gjenero1-0/+17
Without an RTC, Rockbox doesn't keep time. In that situation, USB time sync previously did nothing but reported success. After this change, the USB time sync request won't be recognized on those targets. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@31319 a1c6a512-1295-4272-9138-f99709370657
2011-12-15Oops, fixed the wrong lineAmaury Pouly1-2/+2
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@31275 a1c6a512-1295-4272-9138-f99709370657
2011-12-15Remove two useless variable and hopefully finally fix redAmaury Pouly1-1/+1
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@31274 a1c6a512-1295-4272-9138-f99709370657
2011-12-15Add support for for per-drive logical sector size. This allows targets to ↵Amaury Pouly1-1/+1
have a different logical sector size for the internal storage and the sd card, like on the fuze+ for example. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@31270 a1c6a512-1295-4272-9138-f99709370657
2011-12-14FS#12378 : Remove various unused code, and comment out some unused code and ↵Boris Gjenero1-18/+0
data for reference or future use. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@31256 a1c6a512-1295-4272-9138-f99709370657
2011-10-21Use array index 'i' only -after- bounds checkThomas Jarosch1-2/+2
Reported by cppcheck git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30815 a1c6a512-1295-4272-9138-f99709370657
2011-09-09Add "USB Hide Internal Drive" option for multidrive devices with software usb.Frank Gevaerts1-10/+15
This option allows accessing the card slot from "dumb" USB hosts like some car audio systems that do not handle multi-LUN devices. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30489 a1c6a512-1295-4272-9138-f99709370657
2011-02-27iPod Classic CE-ATA Support (Part 2 of 4: Remove on-stack sector buffers, ↵Michael Sparmann1-2/+5
and replace them with a single statically allocated sector buffer that's arbitrated amongst users) git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29445 a1c6a512-1295-4272-9138-f99709370657
2011-01-15Bootloader USB mode for PP502x. Enable only on GoGear SA9200 for the time ↵Michael Sevakis1-2/+2
being. Add HAVE_BOOTLOADER_USB_MODE to config if BOOTLOADER is defined to enable it. Clean up some kernel stuff a little to support it. Mess up a bunch of other stuff (hopefully not too badly). git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29053 a1c6a512-1295-4272-9138-f99709370657
2011-01-05Gigabeat S: Make it a removable mass-storage device. Windows will assign a ↵Michael Sevakis1-36/+23
drive to only the main data partition by default. To access the bootloader partition instead, press 'Vol -' while it connects (in bootloader and firmware). Hopefully doesn't break anything for anyone. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@28972 a1c6a512-1295-4272-9138-f99709370657
2010-12-04Handle disk errors properly in USB storage driver. Fixes FS#10873Frank Gevaerts1-10/+14
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@28733 a1c6a512-1295-4272-9138-f99709370657
2010-10-02Fix outdated commentFrank Gevaerts1-1/+1
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@28196 a1c6a512-1295-4272-9138-f99709370657
2010-06-22usb_storage seems to be working now, enable USE_ROCKBOX_USB on C200v2, other ↵Tobias Diedrich1-4/+14
AMSv1 untested. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27039 a1c6a512-1295-4272-9138-f99709370657
2010-06-05remane hotswap.* to sdmmc.*. The contents have nothing at all to do with ↵Frank Gevaerts1-1/+0
hotswapping things git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26598 a1c6a512-1295-4272-9138-f99709370657
2010-05-19revert part of r26176 to avoid large static allocationRafaël Carré1-1/+1
we still need to convert uncached addresses to physical addresses git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26177 a1c6a512-1295-4272-9138-f99709370657
2010-05-19as3525: don't use IRAM for usb, and avoid usb storage using uncached ↵Rafaël Carré1-1/+1
addresses behind our back No need for special address handling, all addresses are equal to their physical address git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26176 a1c6a512-1295-4272-9138-f99709370657
2010-04-08Make usb storage wait for new commands in parallel with sending out the CSW ↵Frank Gevaerts1-19/+40
again, for a nice speed improvement. This is basically the same as was done before r24333, only this time it should be correct. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@25542 a1c6a512-1295-4272-9138-f99709370657
2010-04-03Add IO priority handling. Currently all IO has equal priority, except the ↵Frank Gevaerts1-4/+4
dircache scanning thread which is lower. This fixes the slow boot problem for me, with the added benefit that actual audio playback also starts faster. Lots of the changes are due to changing storage_(read|write)sectors() from macros to wrapper functions. This means that they have to be called with IF_MD2(drive,) again. Flyspray: FS#11167 Author: Frank Gevaerts git-svn-id: svn://svn.rockbox.org/rockbox/trunk@25459 a1c6a512-1295-4272-9138-f99709370657
2010-03-11Even more Nano2G FTL speedup. Now 8% faster than disk mode, 10% slower than ↵Michael Sparmann1-0/+8
the OFW. 4.5MB/s sustained (contiguous) write, 6.0MB/s read for me now. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@25109 a1c6a512-1295-4272-9138-f99709370657
2010-01-25don't start waiting for the new command in send_csw(). Although on the USB ↵Frank Gevaerts1-3/+3
level this is entirely correct, and about 10% to 15% faster, usb_storage_transfer_complete() could get slightly confused by this. The proper fix is obviously to make usb_storage_transfer_complete() not get confused, but that's a lot more work, and I prefer things to be correct to them being a bit faster right now git-svn-id: svn://svn.rockbox.org/rockbox/trunk@24333 a1c6a512-1295-4272-9138-f99709370657
2010-01-03Fix even more tabsAndree Buschmann1-1/+1
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@24155 a1c6a512-1295-4272-9138-f99709370657
2010-01-02Simplify some boolean expressions that compare directly against 'true'Bertrik Sikken1-1/+1
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@24144 a1c6a512-1295-4272-9138-f99709370657
2009-11-03Comment out LOGF_ENABLE defines everywhere, replace evil commentsJeffrey Goode1-1/+1
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@23497 a1c6a512-1295-4272-9138-f99709370657
2009-10-20iPod Nano 2G USB support based on the S3C6400X datasheet. Disabled by ↵Michael Sparmann1-0/+6
default for now. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@23285 a1c6a512-1295-4272-9138-f99709370657
2009-10-19Change control handling to start expecting host packets before sending data ↵Frank Gevaerts1-1/+1
to the host. This makes the handling less timing sensitive on some controllers git-svn-id: svn://svn.rockbox.org/rockbox/trunk@23263 a1c6a512-1295-4272-9138-f99709370657
2009-10-01get rid of one hardcoded 512. SECTOR_SIZE is still there. It should probably ↵Frank Gevaerts1-1/+1
move up (to storage.h?) so fat and usb storage can share it git-svn-id: svn://svn.rockbox.org/rockbox/trunk@22869 a1c6a512-1295-4272-9138-f99709370657
2009-08-11Move yearday_to_daymonth() to usb_storage.c. It's the only user, this ↵Frank Gevaerts1-0/+25
function is pretty specific, and it seems to be the cleanest way to avoid ram usage increases for unrelated targets git-svn-id: svn://svn.rockbox.org/rockbox/trunk@22259 a1c6a512-1295-4272-9138-f99709370657
2009-08-11Consolidate day of week calculationFrank Gevaerts1-10/+12
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@22258 a1c6a512-1295-4272-9138-f99709370657
2009-08-11Fix "statement with no effect" warningFrank Gevaerts1-1/+0
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@22256 a1c6a512-1295-4272-9138-f99709370657
2009-08-11Add support for setting the clock using a special SCSI command. This is the ↵Frank Gevaerts1-2/+40
same method that itunes uses, and there are host-side tools for it (e.g. libgpod) Flyspray: FS#10514 Author: Laurent Papier and myself git-svn-id: svn://svn.rockbox.org/rockbox/trunk@22255 a1c6a512-1295-4272-9138-f99709370657
2009-07-17Commit FS#9545, storage cleanup and multi-driver supportFrank Gevaerts1-23/+22
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21933 a1c6a512-1295-4272-9138-f99709370657