1
0
Fork 0
forked from len0rd/rockbox
Commit graph

687 commits

Author SHA1 Message Date
Solomon Peachy
aef5cec1ad disk: Minor cleanups with respect to virtual<->logical sector mapping
Change-Id: Ib20c73c8afe6cf71165600ace1b2ca4b10de2ae8
2025-09-22 22:12:59 -04:00
Solomon Peachy
44ce302348 janitorial: move FAT code from firmware/drivers to firmware/common
It's not a "driver" that interacts with hardware.

Change-Id: I7d688e1086aa118569ebc1440e20b48d0ae4881e
2025-09-17 08:23:41 -04:00
Solomon Peachy
5c38669476 fat: Fix warning with fat_file_sector_size with (MAX_VARIABLE_LOG_SECTOR && HAVE_MULTIVOLUME)
Change-Id: I9bc7206b8121645688f5901ab448eba4077cba92
2025-09-16 16:50:32 -04:00
Solomon Peachy
a2c10f6189 unicode: Support characters beyond the first unicode plane
We used 16-bit variables to store the 'character code' everywhere but
this won't let us represent anything beyond U+FFFF.

This patch changes those variables to a custom type that can be 32 or 16
bits depending on the build, and adjusts numerous internal APIs and
datastructures to match.  This includes:

 * utf8decode() and friends
 * font manipulation, caching, rendering, and generation
 * on-screen keyboard
 * FAT filesystem (parsing and generating utf16 LFNs)
 * WIN32 simulator platform code

Note that this patch doesn't _enable_ >16bit unicode support; a followup
patch will turn that on for appropriate targets.

Appears to work on:

  * hosted linux, native, linux simulator in both 16/32-bit modes.

Needs testing on:

  * windows and macos simulator (16bit+32bit)

Change-Id: Iba111b27d2433019b6bff937cf1ebd2c4353a0e8
2025-09-12 09:24:30 -04:00
Solomon Peachy
4ad041e17a disk: Always try to mount the first partition on a disk.
We've received multiple reports from users of 6th gen iPods where we
fail to find any mountable partition.  A user was able to supply an MBR
dump, which showed that the "type" listed for parition 0 was set to 0x00
(ie "unused"), leading us to (correctly) completely ignore that entry.
However, it looks like the stock firmware ignores the type and
unconditionally uses the first entry even if it's nominally "invalid"

So, to deal with this, always try to mount partition 0 if it is not one
of the two "extended partition table" types.  If that speculative mount
succeeds, we now treat it as type 0x0c (Fat32 w/LBA) internally.

Note that this will not allow the partition to be mountable over USB, as
the MBR is still incorrect, leading the host OS to ignore the partition.
Further complicating things, the stock Apple firmware always constructs
a fake MBR to hand to the host!

To prevent user confusion with these devices, we may consider faking the
MBR too; alternatively we could correct the MBR and write it back to
disk, perhaps via a debug menu option.

Change-Id: I1e9392d20401eb94ecc6d70263fb0e45392a9bd4
2025-08-31 19:31:20 -04:00
Solomon Peachy
84504c7471 Revert "internals: Support characters beyond the first unicode plane (WIP)"
This reverts commit d05c59f35b.
2025-08-20 16:09:49 -04:00
Solomon Peachy
d05c59f35b internals: Support characters beyond the first unicode plane (WIP)
We used 16-bit variables to store the 'character code' everywhere but
this won't let us represent anything beyond U+FFFF.

This patch changes those variables to a custom type that can be 32 or 16
bits depending on the build, and adjusts numerous internal APIs and
datastructures to match.  This includes:

 * utf8decode() and friends
 * on-screen keyboard
 * font manipulation, caching, rendering, and generation
 * VFAT code parses and generates utf16 dirents
 * WIN32 simulator reads and writes utf16 filenames

Note that this patch doesn't _enable_ >16bit unicode support; a followup
patch will turn that on for appropriate targets.

Known bugs:

  * Native players in 32-bit unicode mode generate mangled filename
    entries if they include UTF16 surrogate codepoints.  Root cause
    is unclear, and may reside in core dircache code.

Needs testing on:

 * windows simulator (16bit+32bit)

Change-Id: I193a00fe2a11a4181ddc82df2d71be52bf00b6e6
2025-08-20 16:08:43 -04:00
Roman Artiukhin
3cb4e63253 strnatcmp: Sort dots first
Moves special folders (like .rockbox) on top and makes filenames sorting look more consistent with folders sorting. See https://forums.rockbox.org/index.php/topic,55303

Change-Id: I6ffd9b3ea0acfcbab69f09415f4e9f53737e7769
2025-05-18 22:50:05 -04:00
Roman Artiukhin
e08b8fcc74 strcasecmp: Optimize size and speed
Applies changes similar to strncasecmp in 64c0cfb0.

Change-Id: I5f80b0031dd12c58d982578f5c5224c7f59cd915
2025-05-18 16:57:35 -04:00
Solomon Peachy
400ae7cb22 disk: GPT lookup code now supports virtual logical sector sizes
GPT superblocks are located at sector 1 and max_sector-1. If the system
uses a "virtual" sector that's larger than the drive's logical sector,
we need to map those virtual sector numbers to the drive's logical
sector.

If DEFAULT_VIRT_SECTOR_SIZE is defined, try that multiplier as well
as the standard multiplier of 1.

It's not practical to try every intermediate value so instead, if
DEFAULT_VIRT_SECTOR_SIZE is defined, try that as well as the standard
multiplier of 1.

This still leaves a handful of targets that don't set DEFAULT_VIRT
but do set MAX_VIRT.

Change-Id: I3accffcb97436b043836e072bfc620318a9b1230
2025-04-30 22:02:48 -04:00
Solomon Peachy
64de7aa8d2 disk: If primary GPT header is missing, try secondary one
Basically the GPT is supposed to live at sector 1, but a backup copy is
stored on the final sector.

This gives us a little bit of extra flexibility on systems that might
require sector 1 for other things, but in any case it's a more robust
arrangement.

Change-Id: I8925ffc743629cf2eba51861042492e35b41664b
2025-04-30 19:21:54 -04:00
Solomon Peachy
e4a16c23ee misc: Fix two more -Wunused-const-variable warnings
Only exposed in bootloader builds

Change-Id: Iee277112c027b28eccd0432c8b231a4084450dbe
2025-04-29 20:56:19 -04:00
Solomon Peachy
c31518201c disk: In "superfloppy" mode, create a fake partition entry
We normally create a table of the partition sizes/types present
on a drive.  Howeever, if the drive is set up as a "superfloppy",
where there is no partition table and a single filesystem starting
at sector 0, this "pinfo" table is not populated.

So now, populate the pinfo table with a single entry that matches
the filesystem type, start, and size.

Change-Id: Ifa8760909109d67ff96481b1fc7f26c64280a00a
2025-04-29 20:20:16 -04:00
Solomon Peachy
5b1158e64a misc: Properly annotate some intentional case fallthroughs
Change-Id: Ie758f17fefac72aca1aa28a8ba1126b9334fe134
2025-04-22 20:54:37 -04:00
Roman Artiukhin
059df3782f unicode: Explicitly set INT_MAX for unlimited utf8_size
-1 could be supplied unintentionally from user code when utf8_size is computable value

Fixup for 004304dc and 1f548f74

Change-Id: I93008ea289bdb134f051975c25b0db9d0e64b823
2025-03-28 15:05:13 -04:00
William Wilgus
50da856992 [BugFix] itoa conflicts with mingw rename to itoa_buf
Change-Id: Ife361f2fd8c8946db5bb2e0e58c0981b2ed3c5f3
2025-02-18 10:41:18 -05:00
William Wilgus
f55fe21f66 add itoa(), replace snprintf("%d") calls
we can save some space and still end up with a 20% faster function

Change-Id: Ia58900122944b8527ef01a673afe18ea794acb41
2025-02-03 01:23:49 -05:00
William Wilgus
f501dd00eb short circuit is_diacritic for 5-15% text drawing speed-up
characters less than the first diacritic in the symbol table (0x300)
return false after checking the MRU table

we gain some performance by eliding the function call all together if less than first diacritic

Change-Id: I02c14e350eb168eca808523affad443cd43888b4
2025-01-31 21:48:44 -05:00
William Wilgus
e79996e031 [Bugfix] strcasestr
I pushed the wrong version of the function it was an experiment
on resetting haystack past the searched string but it is missing the
rest of the logic and therefore misses strings that should match

Change-Id: I23391d2e753840bfeaab8e26d9987198272fe7b8
2024-12-31 23:06:08 -05:00
William Wilgus
186ad1234b [BugFix] pathfuncs.c path_append_ex basepath_max might cause buffer ovfl
strlcpy returns the length of the string that would have been copied
had there been sufficient space basepath_max might still be
larger than buf_size yet smaller than len
which would result in a null terminator being written past buf[buf_size-1]

Change-Id: I43e8ba9f72ea35bfe4f759ecd102c2e4bd26eb75
2024-12-30 19:35:33 -05:00
William Wilgus
27aff7ec8d strcasestr optimize for speed and size
revisit this and shave a bit more off on code size

Change-Id: I90546b931780c6779960129619a41cc6592c44e1
2024-12-30 16:42:55 -05:00
Dana Conrad
7d3cc24dec FS#13519: multivolume: Ensure absolute paths get drive designation
Change-Id: I8419af670ca101b11bba29d9fd577f21fa22fd42
2024-12-17 21:18:06 -05:00
Vencislav Atanasov
5d7c8a0df1 Convert non-ASCII characters to UTF-8
Comments and notes are converted to UTF-8. Already broken multibyte characters are fixed using common sense.

This patch contains no code changes.

Change-Id: Ia511ab84936cb2495ac17309493a9b98727a7902
2024-12-15 21:16:12 -05:00
Roman Artiukhin
1f548f74e6 unicode: add utf16decode with utf8 buffer size check
Make use of it in id3tags and cuesheet

Change-Id: I153c23f1f7312e9d5e1de9f03725f2d2ab0abc93
2024-12-15 15:44:57 -05:00
Roman Artiukhin
004304dc65 unicode: add iso_decode_ex with utf8 buffer size check
Make use of it in id3tags, playlist and cuesheet

Change-Id: Ibc8abc0faf16688bc9b826b7a712d1dfe9bf75b2
2024-12-15 09:26:26 -05:00
Roman Artiukhin
a23002cd5e unicode: Unify check for UTF-16 BOM
Adds utf16_has_bom function

Change-Id: I67ea474c9cf6ca6e6684351c2f54131164b7903c
2024-12-13 17:38:05 +02:00
William Wilgus
afb0e845cf strcasestr smaller function for PREFER_SIZE_OVER_SPEED
tester script:
https://onlinegdb.com/TbILrA5E7

Change-Id: Ie5a37db13500510e30e87a20782f13adfe2b4d78
2024-11-28 15:07:55 -05:00
William Wilgus
cb478d9d3f add INIT_ATTR to dircache_load and core_load_key_remap
both of these are only called in main at init

Change-Id: If2020c2832df837aca23a331474bbf2352d803d4
2024-11-26 22:13:43 -05:00
Solomon Peachy
dfbbfb12d4 storage: Misc corrections and cleanups
* Make the partial sector logic a little clearer (no functional change)
 * Corrections for debugging messages
 * Also use MAX_VIRT_SECTOR_SIZE in BOUNCE_BUFFER calculations

Change-Id: I89363824b092b2e3bddd5e0f75bf81200c9bc513
2024-11-26 08:37:55 -05:00
Solomon Peachy
9bf033dd66 ata: Prefer using "virtual" sector size where possible
Normally, if a device uses larger physical sector size than the logical
size and supports so-called "512e" mode, we let the device deal with
partial sector reads/writes.

However, if MAX_VIRT_SECTOR_SIZE is defined, we support
partitioning/filesystems that use a larger "virtual" sector than the
logical sector.  typically this matches the physical sector size of the
drive, which means that despite a small logical sector size, all I/O
is done in terms of the physical sector size.

Therefore, when MAX_VIRT_SECTOR_SIZE and MAX_PHYS_SECTOR_SIZE are
enabled (currently only ipod5g and ipod6g), prefer software-based
partial sector I/O.

Change-Id: I0815ad0a2f987b89bb2debfbf3d0ed64cdf85525
2024-11-15 07:24:08 -05:00
Solomon Peachy
a4fe20a278 filestr_cache: Some more 64-bit sector_t fixes
This isn't strictly needed for FAT32, but the core file cache code
needs to be able to reference >32bit sector addresses.

Change-Id: I57838f1228c1d45f6a8c4755c5d1f9063c13b3dd
2024-11-11 10:38:58 -05:00
Solomon Peachy
1516c48a37 storage: Support a default virtual sector size
Normally, we figure out the virual sector size from the filesystem info.
However, if there's no filesystem, we fall back to the hardware's
logical sector size.

Some device firmware (eg ipod5g/6g) need their partition tables set up
with larger-than-logical sector sizes; this way we can present the
"correct" sector size to maintain interoperability with the stock
firmware and make it so that the drive can still be properly partitioned
from within rockbox.

This patch adds support for DEFAULT_VIRT_SECTOR_SIZE.  Nothing uses it yet.

Change-Id: Iae746a50ffc37c51abb2c9b82d3c4596f1fa7559
2024-11-09 17:48:00 -05:00
Solomon Peachy
c61ad40812 storage: Wrap runtime variable sector size with MAX_VARIABLE_LOG_SECTOR
When enabled this allows 512n and 4Kn drives to be used with a single build.
(So far all ATA SSDs use 512 byte logical sectors)

Change-Id: I902d2318ca8abb581699c0bca68d6e3ec227d064
2024-11-09 16:34:06 -05:00
Solomon Peachy
bc6c189dcb storage: rename MAX_LOG_SECTOR_SIZE to MAX_VIRT_SECTOR_SIZE
Change-Id: I34f00748c1b0935d65af5f0fc6bdd13356ff31e1
2024-11-09 16:32:40 -05:00
Solomon Peachy
7ecab006c0 fat: Allow use of variable logical sector sizes
Only used if MAX_LOG_SECTOR_SIZE is defined

This allows a single build to seamlessly work with (eg) 512B or 4K sectors.

Change-Id: I85d2a6612afca6a1d7a3bd49c588b5745ab2b220
2024-11-09 16:32:40 -05:00
Solomon Peachy
9e70991174 disk: Simplify LOG_SECTOR_SIZE() definition
Change-Id: I49cca4fe5e92f7b443427c2b8e95bae8955b9ea0
2024-11-07 07:51:14 -05:00
Solomon Peachy
f58fad943e diskcache: Size the buffers for MAX_LOG_SECTOR_SIZE
Because if we get a logical sector size > min sector size
we'll trigger buffer overflows.

Change-Id: Ibd24f91a0f8601fbd8c5a5dfeef4ebe5c081f664
2024-11-07 07:49:17 -05:00
Solomon Peachy
4be6285444 disk: MAX_LOG_SECTOR_SIZE also applies to a few non-ATA targets
Fuze+, native Sonys, and some of the Zens use 2K sectoring from
 the partition/filesystem perspective, even though the underlying
 storage used 512-byte sectoring.

Change-Id: I247d8cae2582c63ec1d4dda0fb225b1a25c8e16a
2024-11-02 14:48:54 -04:00
Solomon Peachy
a8c52b1bfb disk: Support a non-fixed (logical) SECTOR_SIZE
This allows a single build to support ATA drives with (eg) 512B and 4K
 logical sector sizes.  This is needed because ATA drives are user-
 replaceable and we don't know what could get plugged in.

 * Add disk_get_log_sector_size() API  (no-op for non-ATA storage)
 * Mostly a no-op if MAX_LOG_SECTOR_SIZE is not enabled
 * Sanity-check that storage's logical sector size is not larger
   than what we're built for

NOTE:  Other layers (eg ATA, FAT, etc) still need to be made aware of this.

Change-Id: Id6183ef0573cb0778fa9a91302e600c3e710eebd
2024-11-02 13:50:53 -04:00
Solomon Peachy
d401501fda disk: Clean up identing (no funcitonal change)
Change-Id: I7a689132b155579ab3938231330f5bde7566809b
2024-10-31 21:51:42 -04:00
William Wilgus
a2cc7546d8 Add DeviceData to bootloaders
same vein as bootdata but for devices that need to pass info back to a
running firmware

Change-Id: I0cdcdc0475804dfbbee415ab487104ae8fc8ac69
2024-09-02 13:29:43 -04:00
Solomon Peachy
15e5237469 storage: 64-bit sector offsets
* Create new 'sector_t' type alias:
    * uint64_t for all targets with HAVE_LBA48 or HAVE_SDUC
    * unsigned long for the everything else
 * Alter all storage APIs to use sector_t instead of 'unsigned long'
 * Alter Volume/Partition/storage info structures to use sector_t
 * Disk cache converted to sector_t
 * ATA Core:
    * convert to using sector_t for sector addresses and drive sizes
    * Always fill out upper 16 bits of LBA48 addresses
    * IDENTIFY INFO is fixed at 512 bytes, not SECTOR_SIZE
 * USB mass storage:
    * convert to using sector_t for sector addesses and drive sizes
    * Implement READ_16/WRITE_16 for LBA48 addresses
 * Convert FAT code to use sector_t for all sector references
 * output_dyn_value() now accepts int64_t instead of 'int'
 * Corrected "rockbox info" to work for (MULTIVOLUME & !MULTIDRIVE)
 * Better reporting of disk and (logical+physical) sector sizes in debug info
 * Detect SDUC cards and report on storage debug_info screen

To-do: SDUC

 * Refactor SD core to remove duplicate code in every driver
   * Card probe and init state machine
 * Implement core SDUC support
   * SD2.0 needs to be 2.0+ (fixed for jz47xx and x1000)
   * Host and Card ID (ACMD41)
   * 32-bit addressing for all read/write/erase operations (CMD22)
 * ADD SDUC to target device drivers, defining HAVE_SDUC as appropriate

Change-Id: Ib0138781a0081664d11511037685503df1b93608
2024-08-12 14:23:44 -04:00
Solomon Peachy
e722334ab1 init_volume_names() has to be called AFTER storage_init()
...So just move that call into storage_init and be done with it!

Hopefully this doesn't cause any functional regressions.

Change-Id: I08700fbd1613638606a23ee3a0c2149123c2c24a
2024-07-28 21:15:41 -04:00
Solomon Peachy
78283bda64 talk: Voice the volume name when browsing and when voicing full paths
Change-Id: I56660e168edd135a09cd5c021504a58ec9d40093
2024-07-28 16:54:33 -04:00
William Wilgus
67db38e766 [Bugfix] initialize the volume names for the sim
init_volume_names() wasn't being called by the sim

Change-Id: Ife0d345cf29bd4a0a658ed194ee85ca4852bc92f
2024-07-24 23:43:36 -04:00
William Wilgus
c0ac043c6d get_volume_name generate volume names once then reuse
Change-Id: I36c62bfb28af9770b551a1193fbb66eb6fbac76a
2024-07-23 18:35:52 -04:00
Solomon Peachy
b4668e2bd6 libc: Check for a null string argument in *printf
If we are passed a null string argument, use the fixed string "(null)"
instead.

Change-Id: I4f70ae76cdcac1104ff1e42dc3b1a5f03e2723fe
2024-06-20 15:22:36 -04:00
William Wilgus
7b12cc3927 pathfuncs.c remove strip_leading_separators()
This should actually be strip_extra_leading_separators() but
its not used anywhere else yet and I don't see enough callers
in core to make it worth the extra overhead

Change-Id: Icdd292869b4198bed7725c51820f6b2111ad739d
2024-06-16 12:33:16 -04:00
William Wilgus
d68c314cea [coverity] vuprintf.c format_double_radix() initialize data struct
it appears this is  false positive but its compliaining
about the uninitialized pointer,
 not a bad idea to initialize pointers to NULL anyway

Change-Id: I5832a19ab13971c7d55580694eef70591a3a9acb
2024-06-05 19:16:07 -04:00
William Wilgus
dad01f29ff [coverity] multiboot.c write_bootdata_ fix memset size
the payload arg was swapped with the size arg

Change-Id: I1e1ef6e842a4fd00f7d4a656438fccbe7abc429a
2024-06-04 15:56:56 -04:00