Commit graph

295 commits

Author SHA1 Message Date
Aidan MacDonald
f995c26de9 buflib: Add CONFIG_BUFLIB_BACKEND for selecting a buflib backend
Defaults to the normal "mempool" backend, which is currently the
only implementation.

Change-Id: I56d034a6e0f5edc90c39526d1551945eec6ca336
2023-01-15 10:04:13 +00:00
Aidan MacDonald
680261fbb7 buflib: Prep for multiple backend support, rename to buflib_mempool
Rename the current buflib implementation to buflib_mempool.

Change-Id: Iefdf74be1f7d8fcd19e6ce2289c3d1459b54d013
2023-01-15 10:04:13 +00:00
Aidan MacDonald
719d48afc4 buflib: Refactor various debugging features
Gate buflib_get_data() checking, debug printing, and buflib
integrity checks behind individual defines in buflib.h, and
turn them all off by default. If needed, they can be turned
on manually when compiling.

The buflib debug menu is only available if debug printing is
enabled, so after this commit it will no longer be included
in normal builds -- it isn't very useful to end users.

Change-Id: Iab25b7852bc7c5592ce04c9c45762046a87d5bc3
2023-01-13 10:32:57 +00:00
Aidan MacDonald
5a3ee83555 buflib: Remove CRC checks
The CRC is a fairly useless safety check because we already
have specific checks to validate the metadata, and CRCs are
only verified before calling the move callback. Removing the
check should not significantly reduce buflib's robustness.

Change-Id: Ica99bd92fc514819b4fd9f359b4272e581020f75
2023-01-13 10:32:57 +00:00
Aidan MacDonald
1e9ad3ca0d Remove buflib allocation names, part two
Remove allocation names from the buflib API and fix up all callers.

Change-Id: I3df922e258d5f0d711d70e72b56b4ed634fb0f5a
2023-01-13 10:32:54 +00:00
William Wilgus
7faf6be35f chunk_alloc
chunk_alloc allows arrays (or any data) to be allocated in smaller chunks

you have to save the indices..
 variable data will have variable indices you need to
 store these as [chunk_alloc] doesn't keep track
 if you have a fixed size for each
 alloc you can do indice / sizeof(data)
 or index * sizeof(data) to convert

Lots of debug stuff still in and it needs optimization

User provides chunk_size and max_chunks
max_chunks * struct chunk will be allocated at start
with (1) chunk_size allocation initially

alloc_chunk() with size = 0 shrinks the last allocation to the size of the data used

add OOM checks on buflib_alloc -- oops

move bytes available to the header -- less memory per chunk & better alignment
keep track of the current in use chunk index -- should speed things up a bit

Now allows:
realloc chunk header
larger allocations than chunk size

reallocs smaller than existing will shrink the current array
rather than alloc a new and copy data

Comments welcome :)

Change-Id: I8ed170eef73da95da19430a80b32e5debf0c8276
2023-01-10 23:59:19 -05:00
William Wilgus
f37ebe5ed2 [BugFix] root redirect failed to match the peoper drive when internal drive is missing
HAVE_MULTIVOLUME is a subset of HAVE_MULTIDRIVE
in normal circumstances they are interchangable
but when the internal drive is not found the assumption falls apart

at the moment most of the bootloader are less selective about what drives/volumes
they will mount therefore the volume might not match between what the bootloader
returns for multiboot and what the firmware sees

updating bootloaders will fix this but it should probably be made more robust
at the same time

Change-Id: I93acd4a539894f093211b74b030df3b2c6a0aa11
2022-12-18 23:32:13 -05:00
William Wilgus
f6c719d7ec replace strlcpy with strmemccpy
replace applicable calls to strlcpy with calls to strmemccpy
which null terminates on truncation

in theory the strmemccpy calls should be slightly faster since they
don't traverse the rest of the source string on truncation
but I seriously doubt there is too much of that going on in the code base

Change-Id: Ia0251514e36a6242bbf3f03c5e0df123aba60ed2
2022-11-14 23:56:16 -05:00
William Wilgus
f94a14b859 increase the number of file & directory handles for devices with more ram
Change-Id: I06f517b3b1388aa43fe1aa9edae53c92d0b137e8
2022-11-14 08:21:29 -05:00
William Wilgus
c756a8a89d make splash split on control characters
splits on spaces also considers \r\n\f\v\t as mandatory breaks

I'm still working on the strptokspn function
my goal is to use it directly rather than storing the matched char
and modifying the source string with \0 in order to tokenize the output
--Done

Change-Id: I7f378b5b9c4df8f10899b9a55a98950afb3931dc
2022-11-12 06:22:16 -05:00
Aidan MacDonald
5e864ecde9 linked list: add lld_insert_prev/next()
Change-Id: I55ff061ccc0e6e2dad3125a8150c082c163db329
2022-10-16 16:10:24 +01:00
Aidan MacDonald
ee9679993b linked list: inline list init functions
These functions are so trivial it's always cheaper to inline them.

Change-Id: Ie0c77c8b6e7a716312105445a22e62ff57a76d90
2022-10-16 16:10:24 +01:00
Aidan MacDonald
f47aa584a8 buflib: add pin/unpin operation
An allocation is pinned by calling buflib_pin() to up its pin count.
The pin count is like a reference count: when above 0, buflib won't
move the allocation and won't call its move callbacks. This makes it
safe to hold the pointer returned by buflib_get_data() across yields
or allocations.

Note that pinned allocations can still shrink because there are some
use cases where this would be valid, if buffer users coordinate with
the shrink callback.

Change-Id: I0d0c2a8ac7d891d3ad6b3d0eb80c5b5a1b4b9a9d
2022-09-19 15:09:51 -04:00
Aidan MacDonald
8f896b14d3 buflib: remove the 'name' member from union buflib_data
Using a length 1 char array to point to the name buffer triggers
a -Warray-bounds warning from GCC when fortified strcpy is used.

This type of construct isn't safe in general -- if the compiler
makes assumptions based on the array bound it can create subtle
bugs when accessing the array out of bounds.

Instead, add a function get_block_name() which returns a pointer
to the name field by casting. This suppresses the warning and it
should be a bit more portable.

Change-Id: I25d4f46f799022ad0ec23bef0218f7595cc741ea
2022-09-19 15:09:51 -04:00
Aidan MacDonald
6e9b1b344b buflib: remove buflib_print_allocs / buflib_print_blocks
These don't have any users and there is already another way to
print blocks (which is actually used by the debug menu).

Change-Id: Ic6a4f874c6499c42bc046e8af3e4aaddc9e68276
2022-09-19 15:09:51 -04:00
Aidan MacDonald
3090cf0da4 buflib: update BUFLIB_ALLOC_OVERHEAD
Allocation overhead should be 5 units, not 6.

Change-Id: I30aa0925aa49eb25d232f7de2bf8b8ce1509d862
2022-09-19 15:09:51 -04:00
Aidan MacDonald
ec9e484f64 firmware: Add load/store with endianness functions
Define common functions for loading 16/32/64-bit unsigned integers
with big, little, or host endianness, and distinguishing unaligned
and aligned cases.

Unaligned loads are supported generically by default, but this can
be overridden with a more efficient implementation on architectures
which support unaligned loads natively.

Change-Id: I3d826ec1a7646777876366eeece2cbccab60c1fb
2022-06-26 17:19:40 +01:00
William Wilgus
6fdc160fab dircache_redirect.h, hide root volume when only one mounted
there is no need to show the root of the drive when only the
internal is mounted

Change-Id: I310c48befa51742d05b6d5ce501d0b7c2c7c7ab7
2022-03-13 17:40:17 -04:00
William Wilgus
97ec0a7e73 Root redirect un-hide root volume
this appears to be problematic for now

Change-Id: Ieb789f5ec10a0d25c559e9bfc2497cbc4f59c0ad
2022-03-11 20:11:31 -05:00
Aidan MacDonald
7fa48faeb5 multiboot: Refactor duplicated functions to a separate file
The implementation of write_bootdata() and get_redirect_dir() was
copied verbatim in two different places, obviously a bad thing for
maintainability. This moves them to a new file multiboot.c as they
are only used for multiboot.

Change-Id: Id0279216e4dd019f8bf612a81d3835eff010e506
2022-03-11 10:58:20 -05:00
William Wilgus
bc3fa53937 Sansa Multiboot Root Redirect Enhance + bug fix
filename buffer was too small to retrieve redirect path

if redirected to sd root remove <SD1> as it is redundant

Change-Id: I1326601f1ba4a18d6bc173798759eb762b55528c
2022-03-06 16:42:26 -05:00
Aidan MacDonald
3bd5f335f7 inflate: Add helper for getting decompressed data size
Helper for another semi-typical operation: find out how big of a
buffer should be allocated before decompressing. This can be useful
when the stream container doesn't specify the decompressed size.

Change-Id: I5f1536f809bb6f9bc6023120c024c3de7cea4269
2022-03-04 08:44:56 -05:00
Aidan MacDonald
ce4620413b inflate: Add helpers for using in-memory buffers
Using an in-memory buffer for the input or output data for 'inflate'
is likely to be extremely common and there's really only one way to
do it, so predefined helpers should be provided.

Change-Id: Ifd22e7b140a08e0e7dc05aec6b340dff5e2d9d0a
2022-03-04 08:44:56 -05:00
William Wilgus
fe4628fc30 Fix Red Multiboot Firmware Root Redirect
Exclude bootloaders

Change-Id: Id26120df0a047711efe49a43917dfec4c25107cb
2022-03-03 23:20:07 -05:00
William Wilgus
c9857098ac Multiboot Firmware Root Redirect - WIP
Loads external drive into root namespace
Root Redirects can now be put into different folders
For instance placing '/_test' into SD1/rockbox_main.<playername>
will redirect to /<1>/_test/.rockbox
Debug menu>Bootdata now has root directory listed in addition to RAW Bootdata

Redirect root work from Michael Sevakis g#1556, RESTORED -> g#4256

Change-Id: Ia97cf50ff5f5b440877f9c005da6f12c53af931e
2022-03-03 22:08:28 -05:00
William Wilgus
c7bbd5b090 Fix Red SDL, Android mounting root directory, and all the yellow too
Change-Id: Ic5077140fdcb1e3168111336bc428c27a782123c
2022-03-03 20:38:57 -05:00
William Wilgus
9daacabd65 [RESTORED!] Allow mounting of any directory as the root directory.
Provide definitions for the macros:
* RB_ROOT_VOL_HIDDEN(v) to exclude certain items from the root.
* RB_ROOT_CONTENTS to return a string with the name of the
directory to mount in the root.

Defaults are in export/rbpaths.h

It's a bit much for those that don't need the full functionality.
Some conditional define can cut it back a lot to cut out things only
needed if alternate root mounts are required. I'm just not bothering
yet. The basic concept would be applied to all targets to keep file
code from forking too much.

Change-Id: I3b5a14c530ff4b10d97f67636237d96875eb8969
Author: Michael Sevakis
2022-03-03 18:58:07 -05:00
Aidan MacDonald
e8faf2f2ad buflib: add a common dummy callbacks struct & use it
There are various allocations that can't be moved or shrunk.
Provide a global callback struct for this use case instead of
making each caller declare its own dummy struct.

Also fixed ROLO and x1000 installer code which incorrectly
used movable allocations.

Change-Id: I00088396b9826e02e69a4a33477fe1a7816374f1
2022-02-12 10:24:32 -05:00
James Buren
e4c5b082e8 inflate: fix public function pointers
Change-Id: I7f1273b832a04a7d7c1b386c08c17438e3d93fc2
2021-08-09 16:25:43 +00:00
James Buren
60933d98c6 inflate: import initial module for deflate decompression
This will eventually be used by the ZIP module and other things
that support DEFLATE based streams.

Change-Id: I4acc9561eb56c9c368d1defab9c14e0454d105e1
2021-08-07 03:03:27 +00:00
James Buren
f32fc84ef6 adler32: import adapted implementation from tinf/zlib
This adds an adapted version of the adler32 algorithm from tinf/zlib
which will be necessary to support ZLIB deflate streams in the future.

Change-Id: Ie60e15acb288acf56a2d44e3d3e912e1b3eb2216
2021-07-30 23:11:49 +00:00
James Buren
8846e087c0 zip: implement zip extraction support
This adds code sufficient to extract files to available storage given a
suitable root directory to extract to. It works on an already open zip
handle and also supports chain-loading a secondary callback in the event
that integration into the process is desired.

Change-Id: Id200d8f20d84a0cbd22906470de8bbd21d4525ef
2021-07-11 05:14:20 +00:00
James Buren
a1bcca645b zip: rename modts field to mtime
This brings it more in line with other structs with this exact same data
type and usage.

Change-Id: I5fe8564750ef28ccd0b12efedca2e6958369f712
2021-07-10 13:44:03 +00:00
James Buren
a9f36efa62 file/fat: rework utime function as modtime extension
This eliminates the dependence on a special struct since we were only
using the modtime anyway. But it no longer fits any known standard APIs
so I have converted it to our own extension instead. This can still be
adapted to existing hosted APIs if the need arises.

Change-Id: Ic8800698ddfd3a1a48b7cf921c0d0f865302d034
2021-07-08 17:47:51 +00:00
James Buren
c174d3a544 file/fat: add utime function
This emulates the traditional utime function from UNIX clones to allow
for manual updates of the modification timestamp on files and directories.

This should only prove useful for non-native targets as those usually
have a libc version of utime.

Change-Id: Iea8a1d328e78b92c400d3354ee80689c7cf53af8
2021-07-08 13:15:30 +00:00
James Buren
49ca4b3e5e timefuncs: add dostime_localtime function
This does the opposite of dostime_mktime, converting time_t back to
the two dos date time values. We use gmtime_r for native because that
is what is available and acts the same as localtime_r on other platforms
with a regular libc available.

Change-Id: If79469d0aae2d7c5dcdd905fbf04963669aa1138
2021-07-07 17:31:00 +00:00
James Buren
b87e75f768 zip: import initial module
This provides rudimentary support for parsing the contents of a ZIP
file. For now this just supports uncompressed file entries but DEFLATE
support is planned. This also only implements a low level public API
so more work will be needed to make it usable by application code.

Change-Id: Ia68b3078e5276666a0e5023f4bc7a9f94272738a
2021-07-05 19:30:05 +00:00
James Buren
c9f2308a1d fat: move fattime_mktime to timefuncs
This moves the time conversion function to timefuncs since it has
uses on ports that don't use the FAT driver. This function has no
dependency on the FAT driver as it is so this should not cause any
issues. To reflect this separation the function was renamed to
dostime_mktime since it is really for DOS timestamps. The places
where it was used have also been updated.

Change-Id: Id98b1448d5c6fcda286846e1d2c736db682bfb52
2021-07-03 00:19:58 +00:00
James Buren
581081a3df mi4: replace chksum_crc32 with crc_32r
This uses an equivalent algorithm but with a different initial value
than we normally use (all bits off vs all bits on). Use the new crc_32r
to replace the original MI4 crc32 implementation.

This frees up some extra space on mi4 targets which gives us more
room on a few very space constrained targets (sansa c200/e200, etc).

Change-Id: Iaaac3ae353b30566156b1404cbf31ca32926203d
2021-06-21 09:36:54 +00:00
James Buren
fc92081080 rockbox: add a crc32 reverse polynomial function
This uses the reverse of the polynomial used by the current crc_32
function. The code for this was derived from the implementation used
by tinf. This version is space optimized and should be a good way to
reduce code duplication in other parts of rockbox that use the same
crc32 algorithm. This is mainly of use in areas where DEFLATE is in
use.

Change-Id: I918da5b4ea4dc441c0e7e6b5007abcc2da463bcb
2021-06-21 03:37:17 +00:00
Moshe Piekarski
b895fb6643 Add tm->yday to RTC ports missing it
Change-Id: I86882262bafb8d06f925aabb87ebd1b5dcb0cd53
2021-05-12 10:52:03 +00:00
James Buren
6b3b4df6f6 rockbox: move firmware checksum algorithms into a common header
Before this was just implemented inline wherever it was needed. Now
it is provided as 2 inline functions in a header called checksum.h.
There should be no differences in actual behavior.

Change-Id: I5d756cc01dc6225f5cc8b6af90911a3fc7b57cd5
2020-11-22 05:12:04 +00:00
William Wilgus
f850bbbbc4 Revert root_redirect :(
This reverts commit 31fc46ded6.

Change-Id: Ia78618c0e8b25ca65f7c8ae0db1cb9c9b321bad9
2020-08-20 21:54:00 -04:00
William Wilgus
bd744059cf Multiboot Firmware Root Redirect
Firmware now includes rudimentary redirect functionality
but this only supports /.rockbox in the root of the device

This patch allows loading external drive and directory into root namespace

Root Redirects can now be put into different folders
For instance placing '/_test' into SD1/rockbox_main.<playername>
will redirect to /<1>/_test/.rockbox

Debug menu>Bootdata now has root directory listed in addition to RAW Bootdata

Redirect root work from Michael Sevakis g#1556

Redirect will be updated if code refactor is ever done

Requires Multiboot bootloader (already in main)

Change-Id: I697b3d0499f85e789c3020bc2133fbe0023f72a2
2020-08-20 19:19:55 -04:00
William Wilgus
5ef28cccf9 Allow mounting of any directory as the root directory.
Provide definitions for the macros:
* RB_ROOT_VOL_HIDDEN(v) to exclude certain items from the root.
* RB_ROOT_CONTENTS to return a string with the name of the
directory to mount in the root.

Defaults are in export/rbpaths.h

It's a bit much for those that don't need the full functionality.
Some conditional define can cut it back a lot to cut out things only
needed if alternate root mounts are required. I'm just not bothering
yet. The basic concept would be applied to all targets to keep file
code from forking too much.

Change-Id: I90b5c0a1c949283d3102c16734b0b6ac73901a30
2020-08-20 23:08:57 +00:00
Solomon Peachy
658026e626 [4/4] Remove HAVE_LCD_BITMAP, as it's now the only choice.
Note:  I left behind lcd_bitmap in features.txt, because removing it
would require considerable work in the manual and the translations.

Change-Id: Ia8ca7761f610d9332a0d22a7d189775fb15ec88a
2020-07-24 21:20:13 +00:00
Michael Sevakis
b70fecf21d Add proper float formatting to vuprintf
Wanted to see how gnarly it is to do.

Big number handling could be done with better algorithms
since it can get a bit slow with large integers or tiny
fractions with many lead zeros when only a few digits are
needed.

Anyway, it supports %e, %E, %f, %F, %g and %G. No %a or long
double support seems warranted at the moment.

Assumes IEEE 754 double format but it's laid out to be able to
replace a function to handle others if needed.

Tested in a driver program that has a duplicate vuprintf and
the content was pasted in once it looked sound enough to put
up a patch.

Change-Id: I6dae8624d3208e644c88e36e6a17d8fc9144f988
2019-07-19 22:07:41 -04:00
Franklin Wei
439a0d1d91 rbendian.h: fall back to generic swap macros
Change-Id: If85086c0fd6b22d50759b16d2545e1798832d12c
2019-07-09 11:20:55 -04:00
William Wilgus
0f5f5c3390 Fix Sim & checkwps for newer distros
__builtin found fix for rbendian.h
tools/configure defines SIM_USE_BYTESWAP_H if byteswap.h is found in
/usr/include/ maybe there is a better mechanism for this

Change-Id: I4d004e68313e8b32aa5587582be36bc459fdaf6b
2018-12-08 03:19:14 -06:00
William Wilgus
9450689483 Fix Sim for newer distros
__builtin found fix for rbendian.h
tools/configure defines SIM_USE_BYTESWAP_H if byteswap.h is found in
/usr/include/ maybe there is a better mechanism for this

genshortcut.sh is a simple script to make .desktop shortcut files
several newer distros don't allow you to run the simulator from the
file manager, this or perhaps a different method can probably be
included while building a sim at a later date.

for now it can be run manually like so:
similar to ../tools/configure
run from your simulator folder
../tools/genshortcut.sh exepath shortname icon
ex. ../tools/genshortcut.sh ./rockboxui clip+sim music-app

Change-Id: Ia05d3a9349b27c5968a4a7a68b2eb480e60faec3
2018-12-07 21:04:30 +01:00