Commit graph

11441 commits

Author SHA1 Message Date
Aidan MacDonald
db2817eb1a Fix red in commit 131566b8f8
Use per-function sections to avoid linking in x1000_boot_linux()
on normal builds, which prevents link errors due to referencing
a non-existent usb_close().

Change-Id: Ied7b233603c49fc856db8445e368675b181e2f1f
2022-07-10 15:58:45 +01:00
Aidan MacDonald
47cbeb2e67 x1000: add support for simple on-die ECC with NAND flash
Many SPI NAND flash chips have on-die ECC engines that report
ECC status via the status feature register. This code handles
the common case where ECC status is reported with 2 bits: one
bit to indicate if flips were detected & corrected, and another
bit to indicate an uncorrectable error.

Change-Id: I5d587cd960ca9d090d2629e890724a6bc411e70c
2022-07-10 15:22:32 +01:00
Aidan MacDonald
df29c7991a x1000: add setup_chip hook for NAND chips
Add a chip setup hook for configuring vendor specific registers
after the chip is identified.

Change-Id: Ifffa7f01be16fd147a9db3d6e402b7b0debd7e12
2022-07-10 15:22:31 +01:00
Aidan MacDonald
ad8ace53e5 x1000: remove 'typedef struct' from NAND driver
Using 'typedef struct' is not in line with the project coding style
and somewhat problematic, so get rid of it here.

Change-Id: Icfe79de72ed82cb7526e9f4e8296ec12084c01ac
2022-07-10 15:22:10 +01:00
Aidan MacDonald
cc017f211a x1000: support 2nd device ID byte for NAND flash
Some components have additional ID bytes. Add support for an
optional 2nd device ID byte during the identification routine.

Change-Id: I5bbad73fb57004067c6f13f223f7bf4d43ff7849
2022-07-10 15:22:10 +01:00
Aidan MacDonald
131566b8f8 x1000: fix linux boot USB issues
If the USB controller is active when we hand over to Linux it'll
often trigger "irq nobody cared" warnings. Disabling the controller
before boot prevents that.

Also move the USB PHY bit workaround from the dualboot cleanup hook
to the main Linux boot function. Mainline kernels don't clear these
bits either.

Change-Id: Ieaf896c3b8c3e58a8c47de5afeb384ae2511a5fa
2022-07-10 09:48:39 -04:00
Aidan MacDonald
d0d13baf3e x1000: fix command line passing for linux boot
Change-Id: I2a016a5f64ef980f49a8cbdcbb0e0af9ad768ce0
2022-07-10 09:48:39 -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
Aidan MacDonald
7e0492444c usb: remove "Ask" USB Mode (FS#13317)
USB ask mode is basically a footgun: it can't work on native targets
and doesn't work reliably on hosted ones, and it continually produces
a slow trickle of problems. FS#13317 gives a rundown of the issues.
Removing the setting seems like the best solution for now, since a fix
would be pretty involved.

This partially reverts 60f581e8f5. The USB Mode setting is left in
place so the option can be added back later in a non-buggy way.

Change-Id: Ie01b28dd2ed95a31b509a7834d85bac8eb866098
2022-06-21 18:11:53 -04:00
Solomon Peachy
7296f30490 jz4760: Reformat USB driver a little. Prep work for later changes.
Change-Id: I74d068661ea8a8a59a88f0c2c5a938dcf6fb8b20
2022-06-12 17:09:32 -04:00
Aidan MacDonald
4d01168b9b x1000: add flash probe tool to bootloader
The flash probe mimics the boot ROM's flash read routines and
dumps the manufacturer & device IDs and 16-byte parameter data
to a file on the SD card.

Change-Id: I3d413bd0cc05a9d7f2285b85454420c3e90274e9
2022-05-30 14:08:02 +01:00
Aidan MacDonald
e05aa27124 x1000: move NAND commands to header file
Change-Id: Ic95b80494a101f7b349e115d82e9dfe3a64b643f
2022-05-30 14:02:13 +01:00
Aidan MacDonald
5ee9a45126 mips: stop backtraces at main()
Initialize ra=0 before calling main so backtraces don't walk
through the startup code.

Change-Id: Ia8796ce38b32d14025b47b3e00061267ee25cbaf
2022-05-22 07:16:11 -04:00
Aidan MacDonald
981e972839 mips: add native backtrace implementation
Should make debugging crashes on native MIPS targets far easier.
This is by no means a 100% complete or robust implementation but
it seems to handle the vast majority of functions.

Change-Id: Id5f430270e02b5092b79026b6876675c784aa649
2022-05-22 07:16:11 -04:00
Aidan MacDonald
2315266628 kernel: remove unused function mutex_test()
No longer needed since the only user was in the Archos code.

Change-Id: I763f58050c70f2bb1d8cc0a044c63698f3157a8d
2022-05-14 11:29:55 -04:00
Aidan MacDonald
dafc8e5904 kernel: remove unused kernel/pthread/*.c files
These don't seem usable and it looks like the files were added by
accident by d66346789c "buflib: Check the validity of of handles
passed to buflib_get_data() in DEBUG builds."

Change-Id: I4d4601f1fef7901c08ae86448853d008f48d5f43
2022-05-14 11:29:55 -04:00
William Wilgus
79864c6ec2 add const to const * strings
I don't think this will amke any difference except maybe for hosted ports

Change-Id: I84f898aea92a6963901a6d889dd18b63f24c9a41
2022-05-03 23:00:58 -04:00
Aidan MacDonald
a234df30df Fix sim build for glibc >=2.34
Change-Id: If63787514b6bffc0afb71f9d651f8c6f0c328a2d
2022-04-18 09:54:07 -04:00
Aidan MacDonald
fca7b8e2ff Fix undefined behavior that blocks compiling with UBSan
Left shifts are not defined in C if they would cause signed overflow,
so these expressions get instrumented, which makes them unusable as
switch values and triggers compile errors when compiling with UBSan.

Change-Id: I0588d4be1e00ba1cfde0eac119ead368b20d10c9
2022-04-17 11:37:34 -04:00
William Wilgus
c4156b1909 viewports, set flags to VP_DEFAULT_FLAGS
flags were getting un-initialized memory
it really didn't matter with the flags getting initialized
anyway
But once I added a new flag that didn't explicitly
set or clear the flag at init well here we are

set flags to VP_DEFAULT_FLAGS in viewport_set_defaults()

add the flags variable to the default vp's set to 0
(it was already initialized to 0 by bss, make it explicit)

Change-Id: I3a9a062455b4cf66d2b8c70fdf05402a5c0c091c
2022-04-17 10:59:56 -04:00
Aidan MacDonald
d55dceff37 apps: Add ability to do a clean reboot
Allow a clean shutdown to end in either power off or reboot. Add a
new event SYS_REBOOT to signal it and sys_reboot() to trigger the
event. SYS_REBOOT signals a reboot request and should be listened
for alongside SYS_POWEROFF events.

Change-Id: I99ba7fb5feed2bb5a0a40a274e8466ad74fe3a43
2022-04-16 14:36:39 +01:00
William Wilgus
ff08841ea9 viewport FIX RED remote screens
Change-Id: I894a5c3e9053f44dee4803e9cdbbcb8f651ee318
2022-04-15 08:16:28 -04:00
William Wilgus
d56d96031c viewports add flag to disable updates
when drwing multiple areas of the screen with other gui elements
you might want to combine updates into a single screen redraw

Change-Id: Ie4130366fa13e25d3d14e937257d11547dd61134
2022-04-15 01:54:42 -04:00
Aidan MacDonald
98f762316f system: update MEM_ALIGN_ATTR for targets with CPU caches
MEM_ALIGN_ATTR should take advantage of cache line alignment on
all native CPUs which define it, not just ARM CPUs. (This could
arguably be done for hosted targets too, but we don't necessarily
know the size of a cache line there.)

Change-Id: Ife9302105ea57388afd55ce31da848b00b5b1b25
2022-04-01 12:08:41 -04:00
Dana Conrad
de285741bf ErosQ Native: Make power delay bootloader-only
gotta go fast

Change-Id: Ic01e4aa70a2bec4c48ae7cf8f32f8dfd366decad
2022-04-01 12:04:46 -04:00
Dana Conrad
7aa2a23b95 Eros Q Native: Add Original Firmware Boot option
Hold "Play" to boot the OF, or boot it from the recovery menu
by holding "Vol. Up". If you had the hosted port installed on your
player before installing the native port, you'll still have to go
through the hosted bootloader.

A couple notes:

- When booting from the menu, the recovery menu disappears, then
  reappears before going into the OF.

- You need to hold the play button for like a half second after the
  blue light comes on in order to get into the OF.

The recovery appears to be there, but it doesn't seem to be intended
for end users - it just says "Updater V1.1 - Insert TF Pls". I haven't
tested it beyond seeing that it boots, so I'm going to comment it out
for now.

Change-Id: Ie271ee479bb628cc74141b7fe07273b3f193f358
2022-04-01 12:04:30 -04:00
Aidan MacDonald
4f05a9d066 Add path_strip_last_volume
This gets the volume that the path eventually refers to by parsing
the last volume specifier and returning the part of the path after
it (which does not contain any volume specifiers). The initial part
of the path therefore contains everything up to and including the
last volume specifier.

Change-Id: I9a935543256f8f22e0b8b1e3c88d4e47bd9dae8a
2022-04-01 11:40:02 -04:00
Aidan MacDonald
412dbaeffe hosted: call 'sync' before poweroff
Might be needed to avoid filesystem corruption with buggy OF kernels.

Change-Id: I589eec6c1536beccf849716f11204b4b83a942a1
2022-03-31 21:40:04 -04:00
Aidan MacDonald
7243f6b343 x1000: Add multiboot support
Enables multiboot for the FiiO M3K, Shanling Q1, and Eros Q native port.
Note this requires an up-to-date Rockbox _and_ bootloader.

Usage instructions will (eventually) be found on the wiki:
https://www.rockbox.org/wiki/MultibootBootloader

Change-Id: Ia2da1ad6ef611e499d2fbafa93838387bc1023ba
2022-03-27 10:35:02 -04:00
Aidan MacDonald
bcbb5a8b00 multiboot: Allow searching in volume 0 for redirect file
Searching in volume 0 is necessary for multiboot targets with only
one drive, like the M3K/Q1/ErosQ. Without this the search code will
never look at the redirect file on these targets.

The search bound is configured with a setting MULTIBOOT_MIN_VOLUME,
which defaults to 0, but is defined to 1 for Sansa players so they
keep their old behavior.

Change-Id: I6dc5cf98db4258731de2c68c3ab1182b4a4a655b
2022-03-27 09:50:33 -04:00
Aidan MacDonald
5d0f697e87 x1000: remove the last vestiges of boot option support
There should be no need for any compatibility hacks since this
value was mostly used internally between the SPL and bootloader.
clk_init() was the only user in the main Rockbox binary which
accessed it, but when loaded by the Rockbox bootloader that code
will not be reached since BOOT_FLAG_CLK_INIT is already set.

Change-Id: Idd68b9834172e652b47432bfb1e00c923ea35407
2022-03-25 21:36:51 +00:00
Aidan MacDonald
3ae4a98e3b x1000: spl: remove selectable boot option support
Now the SPL boots the Rockbox bootloader unconditionally, which
allows for some simplification.

Change-Id: Id75c82db25a87e0e9043bb0771f622b1fc9482fb
2022-03-25 21:36:51 +00:00
Aidan MacDonald
2810c549a6 x1000: spl: remove dual boot support code
Removes the SPL's dual boot support code, and removes the dual
boot selection code on the M3K and Q1 since they can now do it
from the main bootloader.

Change-Id: Ie1b27e98c6ed4b3e37db86cfb485d6f3a6c5b25e
2022-03-25 21:36:51 +00:00
Aidan MacDonald
7cb49cfb33 x1000: spl: split off NAND storage to separate file
Just tidying. No functional changes.

Change-Id: I8aa85c789d1a6bd357797c6c95e38a7325eba809
2022-03-25 21:36:51 +00:00
Aidan MacDonald
5160c90690 x1000: bootloader: add screenshot function
Screenshots of the recovery menu will be useful for documentation.

This can be disabled by turning off HAVE_BOOTLOADER_SCREENDUMP in
the target config file if the bootloader should ever run up against
max size limits.

Change-Id: I62ec1e465df2ca7a8a0e78625d88b31f6c4ef078
2022-03-25 21:36:51 +00:00
Aidan MacDonald
5b011c8dca x1000: add bad block marker position to nand_chip info
Change-Id: I6f466d87f6f11bc3e23463c469f318ecb7049ba7
2022-03-24 23:40:07 +00:00
Aidan MacDonald
41a8b874d2 linuxboot: add meaningful error codes
Change-Id: Ied964e99c389902bb1786c414c5d0fa20056040d
2022-03-24 23:40:07 +00:00
Aidan MacDonald
6a6c6083fa x1000: bootloader: fix Linux self-extracting kernel boot
Basically, there's longstanding bug in Linux with self-extracting
kernels on MIPS which just happened to manifest now on the M3K as
a hang on boot. The fix is applied to the M3K and Q1 since they
both use this type of kernel image.

Change-Id: I17d2bad6eebd677cd6d2e0bf146450c71fcf1229
2022-03-24 23:40:07 +00:00
Aidan MacDonald
44fbb1a593 x1000: bootloader: add LCD dualboot cleanup for the M3K
Disable LCD interrupts before booting the OF - the OF kernel
hangs at boot if they are enabled.

Change-Id: I4f119818d0243953cdd620e17d9509b4fb16cc28
2022-03-24 23:40:07 +00:00
Aidan MacDonald
9bde653410 firmware: allow screendump in bootloader
Enabled if target defines HAVE_BOOTLOADER_SCREENDUMP

Change-Id: Idc135ef81e55d0f3eb8e7d2763d455c6455cf8fd
2022-03-24 18:59:50 -04:00
Aidan MacDonald
e956f7dc83 firmware: minor screendump related cleanups
- Remove unused redefinitions of screen_dump() from bootloaders
- Use empty do-while when screendump is compiled out

Change-Id: I3ccdb0390ddaa28d8f561ff744d0db6aaef17f5d
2022-03-24 18:59:50 -04:00
William Wilgus
cfeeb7889d Lcd save function pointer to frame buffer get_address_fn before loops
Calling multiple levels of indirection in a loop slows things down

Really these need to be rewritten to take a start and end address
like most of the rest of the codebase

But this is safer without having test hardware in hand

Change-Id: Idae7b92ee779d020ed7fcc9334e2d5a9c710e64d
2022-03-21 23:53:48 -04:00
William Wilgus
60e5786b48 lcd-bitmap-common optimize a few viewport functions
Change-Id: I71cd61f66e875280d07f17a9e828fbecc305bad2
2022-03-21 10:00:04 -04:00
William Wilgus
b65763bc10 [COV] fix uninitialized warning
Change-Id: Ib526aeac51d626d02b073b26efd3020115641caa
2022-03-18 20:19:18 -04:00
Aidan MacDonald
67f7d399e5 x1000: restore crt0.S cache flush
I-cache must be flushed after copying code to IRAM... duh.

Change-Id: I6eacc4b7c4385175724c947f6c53f7bbddcb6295
2022-03-16 23:21:29 +00:00
Aidan MacDonald
c676736792 x1000: optimize crt0.S, improve correctness
Replace inline section copy/fill loops with subroutines, which
reduces code size a bit and and handle zero size copies properly.

Remove the cache initialization loop as well. There's no actual
reason for this because the SPL initializes the caches and just
dropping the cache can even be harmful (in this case it wasn't,
because the SPL flushes the whole cache right before calling in).

Change-Id: I7cddc9ed6d060b1f1bdd75544297883d014cad2d
2022-03-16 12:02:24 -04:00
Wolfram Sang
0df71c952c rds: make newly added function static
It won't be called outside the RDS core.

Change-Id: I22f9d7984213f32ad1db49368327243ba2aa917b
2022-03-16 11:54:26 -04:00
William Wilgus
a5c16d2990 rb_namespace add logf
add logging to the namespace file to allow debug of root redirect

Change-Id: I6032aea880998c05dacf3d0d2e0d222205b9376e
2022-03-15 00:45:00 -04: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
Aidan MacDonald
8b4949381c x1000: add TCSM section to linker script
This is intended for debugging OF kernel boot problems and has
to be enabled manually at compile time to make it usable.

Change-Id: Ie5ce9f0a7639be0acf5e3879cfc3a7b8b89caa5c
2022-03-12 14:50:45 -05:00
Aidan MacDonald
d56964cc2b x1000: add dual boot helpers for the main bootloader
Two helpers (_init_clocktree and _init_uart2) already existed in
the SPL and are copied verbatim from there. The SPL versions are
still present and will be removed when dual boot works from the
main bootloader.

The other two helpers (_cleanup and _load_pdma_fw) are new.

Change-Id: I4661667966e26f52e6c5142f1947d2a34b7008ef
2022-03-12 18:25:10 +00:00
Aidan MacDonald
a87f93d8ff x1000: add function for booting linux kernels
Change-Id: I0750b084fe88d21a8686daf0681b32b1dcba8fec
2022-03-12 18:25:10 +00:00
Aidan MacDonald
58225bd2c8 x1000: remove plugin and codec buffers on bootloader
On the bootloader there's no point reserving memory for these,
the only users of codecbuf/pluginbuf are in the apps/ tree.

Change-Id: Ib57b4d59aff8f4dcc753d7993956ed15e61cdc52
2022-03-12 18:25:10 +00:00
Aidan MacDonald
38eafb60ff x1000: use core_alloc in bootloader for loading rockbox
Using the audio buffer directly is a bad idea because this will
render core_alloc non-functional if load_firmware() writes into
the buffer but then fails, for example on a checksum mismatch.

Change-Id: Ib2d17bcea53bdea1c4c5496cec0c4eee5dd66069
2022-03-12 18:25:10 +00: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
603412f447 x1000: Clarify definition & usage of RAM areas
Document what the symbols are supposed to mean, fixup SPL's
usage of DRAM_END which should really be SDRAM_END instead.
No functional changes.

Change-Id: Ie85b0ee35fea8b7858891e5b9d6634eaae42c9f8
2022-03-11 11:15:56 -05:00
Aidan MacDonald
428491df69 x1000: support new binary header in rolo
Change-Id: I192c3d69616c39534ff329174c4d8d4a357d014d
2022-03-11 11:15:56 -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
Aidan MacDonald
439b4e8bca multiboot: Remove bad multiboot code from hosted RoLo
This looks like it was copy-pasted blindly from elsewhere and it
wouldn't even compile, since hosted RoLo is completely different
from native RoLo.

Change-Id: I4074f5323dcbdae85db8a04f222c858e9a228432
2022-03-11 10:58:20 -05:00
Aidan MacDonald
eae9f6f5b7 erosqnative: Fix missing END marker in LCD enable sequence
Change-Id: I75b3a396174e84d72e70c6f177bc1702021805f1
2022-03-11 10:42:18 -05:00
William Wilgus
f6a2bf28e1 BUGFIX file.c open failure leaves open file handle
Change-Id: Iad8eef2f65af0549da4dbec654c85adb2f325711
2022-03-11 03:18:38 -05:00
Aidan MacDonald
ca12478df6 x1000: add simple binary header to declare the load address
The header format is basic, a variable length list of values
tagged by 4-byte strings. The main application to to allow a
loader to determine the load address of the binary at runtime
instead of using a hardcoded address. But the header contents
aren't fixed and it could be extended for other purposes too.

Change-Id: If51d85b4c2eb53c919a91b54985b157e8e5c20ef
2022-03-06 23:22:49 +00: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
ee87bfb933 Add support code for dealing with U-Boot uImages
Adds a loader for the legacy uImage format that is commonly used on
embedded Linux systems. It verifies checksums and supports uncompressed
and gzipped images. Supports arbitrary reader functions to allow the
images to be streamed off any storage device, for optimal RAM use.

Change-Id: I93c35f9a6f323999a22a07300e05627fabfcbd2c
2022-03-04 09:02:56 -05:00
Aidan MacDonald
d541a3a191 x1000: fix nand driver reference counting
Somehow I screwed this up as well. Seems it didn't cause trouble.

Change-Id: I5ab99dd9182a4e60d55984fecbf20ca823dbd004
2022-03-04 08:57:35 -05:00
Aidan MacDonald
3cb7167e22 x1000: fix bug in nand_read_bytes
This didn't account for partial page reads properly which resulted
in corrupted data. Fortunately, current released bootloaders do not
perform such reads so they don't trigger this bug.

Change-Id: I426a95ef8d0f20f4567498530e216d80e1aceef2
2022-03-04 08:57:35 -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
0ddac1fdaf Fix Red SDL, Android mounting root directory
Not actually used in either atm

Change-Id: I40e0143fdde1970ac485bf664962c62d4c493d57
2022-03-03 20:08:12 -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
Wolfram Sang
95dfc489b5 sync clock with RDS time
Tested with my SansaClip+. I don't think this will need extra battery
but let me know if I am wrong.

Change-Id: I287dae134113e0f8a138af68f5087b8ea45b0f4c
2022-02-07 22:04:10 +01:00
Wolfram Sang
5b8873bf33 RFT: convert Gigabeat RDS to thread
This kind of reverts 7b596416bf ("Gigabeat S: Update RDS processing to
use asynchronous I2C rather than thread."). However, requiring RDS to
run in thread context will a) allow more upcoming features and b) remove
quite some complexity from the codebase (see the diffstat here) because
Gigabeat is the only user. iMX31 should be able to handle one more
thread, as it can even run Linux.

Change-Id: I46130034595ba66392c5417c275d036f4bd26943
2022-02-07 22:01:20 +01:00
Aidan MacDonald
b25d8457bc Shanling Q1: fix DAC power mode switching
The OST prescaler bugfix (7a5130a277) broke runtime switching
between 1.0V and 2.0V modes. The 1ms delay after shutting down
the DAC isn't long enough to reset it, so it gets stuck in the
power mode assigned at boot. Change the delay back to 4ms, the
effective value prior to the OST bugfix.

Change-Id: Ic4583d1a6fa82540062aa185386f14bbf785a3f4
2022-01-30 17:37:24 +00:00
Wolfram Sang
76a2a00732 si4700: optimize RDS cache update a little
use si4700_read() instead of si4700_read_reg() to make it clear we are
not interested in the register itself but in the cache update. Also, a
tiny bit more efficient as we save a function call and don't request a
return value we don't use anyhow.

Change-Id: Ibbb66fd9e5ea748ba11ac3c2a0570f5219b72637
2022-01-30 12:27:30 -05:00
Aidan MacDonald
127bb1b6e1 FiiO M3K: remove volume setting on rec. screen
This controls the playback volume, which is not useful for
the M3K because it's impossible to play back and record at
the same time.

Change-Id: I5b0931c22b484f3ff6441d6c88079f18ec70f7f8
2022-01-29 15:13:54 -05:00
Aidan MacDonald
c1f1d91404 FiiO M3K: audio recording
Recording works now, although I'm sure there will be a few
things that need fine-tuning. A major issue is that writing
to the SD card creates noticable interference, which happens
on the original firmware too but seems worse under Rockbox.

(Since Rockbox waits until RAM fills up before writing data,
the interference will only be heard on >50 MiB recordings.)

Change-Id: I5561dd9668c3bdd34e92f34ef50848aef8c0b7eb
2022-01-29 19:28:03 +00:00
Aidan MacDonald
d93e054419 fiiom3k: power down amp before switching DAC power modes
As detailed in the <Low Power Mode> section of the AK4376A
datasheet, the amp should be powered down before switching
power modes (or to a sample rate <= 12 KHz).

Change-Id: I3ab0a21c78a3ad2bb418b64c916f7dbe2a843efa
2022-01-16 19:35:40 -05:00
Aidan MacDonald
dac3175445 audiohw: avoid magic numbers for DAC power mode
Define proper symbolic constants for power mode. Also allow
targets to define the default power mode setting.

Change-Id: Ia07cf854dce47d0a6aa88e067471f1ff9fbc45fb
2022-01-16 19:35:40 -05:00
Aidan MacDonald
18b3e91707 x1000: internal codec audio driver
Change-Id: I2eb551ec6b593951c33ae6b93df2a23dc6612c43
2022-01-16 19:17:25 -05:00
Aidan MacDonald
15e3d37110 x1000: core PCM recording support
Change-Id: I71883272cc3bffadc1235b0931c3f42bb38e4c1e
2022-01-16 19:17:25 -05:00
Aidan MacDonald
c62c323ebc axp-pmu: adc refactor
Remove the battery power ADC since it's not used right now,
and seems to fluctuate too rapidly to be of much use.

Change-Id: If115e4e3ce14d4c18ce899f5a889f7f99ab66489
2022-01-09 20:12:41 +00:00
Aidan MacDonald
b490f08b7c axp-pmu: remove chip ID code
It's useless except to developers, who can easily add code
somewhere to print the ID.

Change-Id: I486240f1c7b45808a1a830abdb22b9381d69cb3f
2022-01-09 19:58:35 +00:00
Aidan MacDonald
eee8243102 axp-pmu: clean up charge current setting
Change-Id: Ifac30f728887c376a83052c826b4bb6a98bbd27a
2022-01-09 19:58:35 +00:00
Aidan MacDonald
eaee5e7339 Revert "AXP PMU rewrite (again)"
This caused LCD problems on the ErosQ, where the screen would
go white until being put through a sleep/wake cycle. The exact
reason for this isn't obvious, but the problem didn't exist
prior to the AXP driver rewrite.

The two dependent changes,

42999913ba - x1000: Increase USB current limit to 500 mA at all times
90dd2f84a9 - x1000: Correctly limit USB charging current

ended up bringing the USB charging situation back to where it
was prior to the rewrite, so the cleanest option is to revert
the whole lot.

This reverts commit 42999913ba.
This reverts commit 90dd2f84a9.
This reverts commit 2d89143962.

Change-Id: I1cff2bfdd1b189df14bcf8cce42db725caa470d7
2022-01-09 19:58:34 +00:00
Aidan MacDonald
42999913ba x1000: Increase USB current limit to 500 mA at all times
The 100 mA USB current limit added in commit 90dd2f84a9
is a problem when booting with a completely dead battery.
Often 100 mA isn't enough to power the player, never mind
charge the battery, so revert to the old behavior of only
limiting charge current.

Given that the original firmware on these devices isn't
following the USB spec to the letter, it's probably not
worth trying to make Rockbox do so unless and until it
causes a real problem - which hasn't happened yet.

Change-Id: I179a08310c226fe01460680c62fd25fd69079256
2022-01-02 20:11:03 +00:00
Aidan MacDonald
83c2398384 x1000: Fix USB connection problems in bootloader
This problem actually had nothing to do with USB boot; it's
because the cable is plugged in when the USB mode menu item
is selected. The USB thread detected the select button press
and went into charge-only mode (as it usually does when you
hold down a key in Rockbox). This is fixed by having the USB
thread ignore most keys in the bootloader.

USB connect events are delivered via the button queue, and
there were also cases where the connection could be missed
if the event happened within another UI screen. This should
also be fixed.

Change-Id: I077d705a6ac845c8713219eee45d26aa6addfa61
2022-01-02 20:11:03 +00:00
Aidan MacDonald
af872b54ec powermgmt: Bugfixes to time estimation code
Guard against division by zero and prevent the time_now
value from going negative if the counter drops below zero.

Change-Id: Ia8cadfe76086d6d0200964c1f27bab0be708b135
2022-01-02 20:11:03 +00:00
Aidan MacDonald
96cfe329a6 powermgmt: Better time estimation
This method, while far from perfect, is able to make use of
real-time battery usage information and updates frequently
in fine-grained increments. This should make time estimates
a lot more useful than they previously were.

Change-Id: I66c6daba88210f60a27e239fbbcc56869be3b878
2021-12-28 10:47:40 -05:00
Aidan MacDonald
90dd2f84a9 x1000: Correctly limit USB charging current
The way this was done before was wrong - limiting the charge
current is not enough since the device will draw additional
power to run. Use the AXP192's vbus current limit control to
stay compliant with the USB specification.

Change-Id: I91b84e3480a432e49bec53cf2a17e4e3444404a4
2021-12-28 15:20:27 +00:00
Aidan MacDonald
2d89143962 AXP PMU rewrite (again)
I noticed a few mistakes in the old driver code and it was in
need of an overhaul anyway... I decided to scale things back,
simplify the code and remove most of the debug menus, netting
a nice code size savings.

One new feature is an advanced debug menu which is accessible
by recompiling the code with AXP_EXTRA_DEBUG. It adds quite a
bit of code size and isn't useful other than for development
so it must be manually enabled by editing the source.

Change-Id: I30e17c1194c14823decd726a574ed14451d4cb2d
2021-12-28 15:20:27 +00:00
Aidan MacDonald
22d0c4da70 Revert "powermgmt: Remove an unnecessary function"
This reverts commit 6ff1a935b9.

Reason: it created a mismatch between the displayed voltage
and percent since the voltage was unfiltered but percentage
was based off the filtered voltage.

Change-Id: I4cba099f2e1edf0ef7c4e17a32f566aa66f5b933
2021-12-23 11:40:22 +00:00
Aidan MacDonald
1a313dc9bf Report battery current on all X1000 native targets
This allows battery run time to be calculated from the
actual battery usage on the FiiO M3K and Shanling Q1.
This isn't very good for the time being and the estimate
tends to go all over the place due to small variations
in current or voltage.

The Eros Q can support this feature as well, but since
it already has fixed estimates defined and the quality
of the "real time" estimate is low I am not enabling it
there.

Change-Id: Id34a93ee4b7d66f9f7e56ef0f5149f67e8e72039
2021-12-23 11:39:58 +00:00
Aidan MacDonald
ad05c872fe powermgmt: Add battery current measurement
This allows targets to report the actual discharging or
charging current if they are able to.

Change-Id: I0b538e6ac94346f1434e45f83c8da8c1260a53a3
2021-12-23 11:39:58 +00:00
Aidan MacDonald
923f92cb12 Fix yellow from 4506f2b58d
Change-Id: I60bb56830ef5ba0fcde4564cdafef594af400c70
2021-12-23 11:37:15 +00:00
Aidan MacDonald
4506f2b58d powermgmt: Refactor battery measurement code
I've tried to clean up cruft and clarify what's being
done, prior to adding new features. The behavior should
be unchanged.

Change-Id: If8a68b7b48173d283df981a21cdd854b714e7695
2021-12-23 00:12:43 +00:00
William Wilgus
8060c79775 allow sim to shutdown while 'charging'
Change-Id: I28a9312d1ce6bf68d8ee6fc2cca680047bfec810
2021-12-11 09:59:39 -05:00
Christian Soffke
a3684e090e m3k simulator: remove white border
Change-Id: I1503dadc966af568c8a4482e1d7f5641092594f0
2021-12-10 19:46:09 +01:00
Christian Soffke
f1eb0483d6 m3k simulator: add screen bezel
Change-Id: I4a34e5be7a459f909b81266b70c30f2968068696
2021-12-10 18:01:38 +01:00
Christian Soffke
7e0e4fe888 Add setting to hide shutdown message
Also keeps display from lighting up before shutdown,
which reduces distractions, especially at night and
when the sleep timer is used by allowing the
screen to remain dark.

Change-Id: I1c2d1966f6fb9766532adf01e8828876a871857f
2021-12-08 22:26:38 -05:00
Aidan MacDonald
f02cd18ad0 powermgmt: Refactor battery current estimation
Create a new battery_current() function to report the
the battery's charging/discharging current. Move the
old runcurrent() implementation into it and clean up
some of the related defines.

Change-Id: I7dbe5b6532d291fa72add1cb23b30e3cbac8c3ca
2021-12-05 15:11:34 -05:00
Aidan MacDonald
6ff1a935b9 powermgmt: Remove an unnecessary function
Remove battery_read_info() which is a simple wrapper
function only used by debug screens. Use the polling
functions directly to save a bit of code size.

Change-Id: I2919f78105bab186f6933dc1823f9fa67fe74f3e
2021-12-05 14:18:32 -05:00
Aidan MacDonald
e3ee1908dd powermgmt: Small cleanups to battery capacity code
- Don't include the 'battery capacity' setting unless the
  target allows changing it.
- Clean up the preprocessor conditionals used to check for
  variable battery capacity support.
- Don't use a variable for battery capacity unless it is
  actually needed.

Change-Id: I3d8a338f107014f2c5098bc0a44ef0cfb4df9356
2021-12-05 13:37:25 -05:00
Aidan MacDonald
204be7f637 fiiom3k: Remove unneeded powermgmt-target.h
Change-Id: I6af46c860d62d9bc297467050d43e47bff2049b8
2021-12-05 13:14:47 -05:00
Aidan MacDonald
8eb685ffdf Remove a couple of #ifdefs
Give iBasso DX50/DX90 empty adc-target.h headers like all
the other hosted targets to avoid special cases.

Change-Id: Iaae15642fdec4ff18bc9ac01245753135128f676
2021-12-05 13:14:47 -05:00
Aidan MacDonald
a6e90d2355 powermgmt: Remove outdated defines
CHARGING_DEBUG_FILE is not referenced anywhere else so
just remove the #ifdef block.

Change-Id: Icf4bd4edb7d38bdc86477d7d1f4e7bf9cf697d31
2021-12-05 13:14:47 -05:00
Aidan MacDonald
34b7b715e8 lcd-16bit: rewrite mono_bitmap_part
Rewrite the loop to update the framebuffer by rows rather
than by columns. This should (a) be more efficient on the
majority of targets using horizontal stride framebuffers,
(b) skimp a bit on code size and (c) avoid AddressSanitizer
errors caused by reading past the end of the source buffer.

Change-Id: I238d191d63bfdecd25336fd8879a63d9d6ab7087
2021-12-05 13:13:36 -05:00
Aidan MacDonald
2512ed1c56 Make inline functions in headers 'static inline'
Future-proofing against newer versions of GCC/binutils which
are stricter about the use of 'inline' functions in headers.

Change-Id: Id620812ed340f0d790ba6c5b8b5cb1d700acfbbf
2021-12-02 21:31:54 +00:00
Solomon Peachy
4162a46184 config: Get rid of an (incorrect) duplicate definition for USB_DESIGNWARE
Change-Id: I9778a1a7b5e2e15b3775dbaed719c64b4e52194b
2021-11-29 20:14:41 -05:00
Aidan MacDonald
98f1271aec x1000: Fix AIC I2S divider clamping with EXCLK source
Change-Id: I19c2d25bbd7276ac5efd6f6b3b9ee64d6801f972
2021-11-27 15:27:45 -05:00
Aidan MacDonald
9eaa14dc02 usb-designware: fix setup packet error handling
This handles the case where the host sends a new setup packet
in the middle of an ongoing control transfer.

Change-Id: I1d2e02467e9b813c9827cc0699cb87a500515e31
2021-11-27 09:29:44 -05:00
Aidan MacDonald
e4d8431211 Update microtar users to new library API
Change-Id: I8e74efb53b8a8c9a4d69b2a20024434e2868e4e0
2021-11-27 13:13:39 +00:00
Aidan MacDonald
44acbc6629 Shanling Q1: enable multi-touch reporting
The FT6x06 driver used for the Shanling Q1's touchscreen
has been extended to report more than one touch point. It
can also return the gesture detected by the controller,
but this doesn't seem to report anything useful on the Q1.

Multi-touch is only useful in 3x3 grid mode since the Rockbox
button API cannot report more than one touch point.

The FiiO M3K uses the same driver so it's been updated to the
multi-touch API, but functionality is unchanged.

Change-Id: I4de42f44808d6eb902e3da212d8f936b7a5042c7
2021-11-24 18:49:03 -05:00
Solomon Peachy
3d07ec46ee jz47x0: Minor code quality improvements in the jz47xx USB drivers
* Replace magic nubmers with #defined constant
 * Tweak some logf messages

No functional changes!

Change-Id: I6a5e4c371a471197a8edbb853967e461621d73f8
2021-11-22 08:08:12 -05:00
Aidan MacDonald
bff63a4f90 touchscreen: change odd sentinel value for time of last touch
Using tick 0xffff does not make any sense, use -1 instead.

Change-Id: Id574eb35418c6713c4fc91ed539aadc42fd29aa5
2021-11-21 20:26:20 +00:00
Aidan MacDonald
ad66c3b807 touchscreen: use repeat acceleration for button input
Touch devices have physical buttons too, and these should be
subject to repeat acceleration. That feature was disabled for
the sake of better touch event responsiveness (apparently).

So, re-enable the acceleration feature & add a special case
to exempt BUTTON_TOUCHSCREEN from acceleration.

Change-Id: I9e097e27457fbd6b824f098e8b325ff35c59dde4
2021-11-21 20:26:20 +00:00
Wolfram Sang
336ea51af6 WIP: Samsung YPR0/1: switch to generic SI47xx polling
Should work(tm). But I don't have the hardware, so it needs to be
tested.

Change-Id: Ic086434f570dcddacb5b7e7a1acce4b8cafc5c03
2021-11-18 16:53:57 -05:00
Wolfram Sang
de0346065b Sansa Clip+: add RDS support
Based on a patch by Amaury Pouly which was based on a patch from Ryan
Hitchman.

I mainly moved the code for polling into the tuner driver so it can be
reused by other targets. I added the CONFIG parameter for the polling
frequency (in ticks) to save energy. Also, I did some minor cleanups.

Change-Id: I95a62e7e1e42c62dbf47ecb27a3b312a42be62aa
2021-11-18 16:44:21 -05:00
Aidan MacDonald
701d4ba77e x1000: Merge makefiles used for the bootloader
All three X1000 native targets turned out to have a very
similar boot configuration and used a nearly identical
makefile. Eliminate this duplication by moving the logic
into the main makefile.

Change-Id: I13044b9675c0abd605b8accdb2fee4f54549b020
2021-11-18 14:14:54 -05:00
Aidan MacDonald
6e61e6f0c8 usb_core: don't buffer control request unnecessarily
Due to how the old control request API worked, the request
pointer (and the pointed-to contents) passed by the driver
must remain valid for the lifetime of the request.

The buffered copy wasn't used consistently anyway, so it
should be safe to just get rid of it.

(This only affects the old API compatibility layer.)

Change-Id: I00294c718a7515a91b84f7c7cae5220c73aa5960
2021-11-14 17:58:39 +00:00
Aidan MacDonald
f8810be6de usb_core: More legacy control API fixes
In the old API, usb_core_transfer_complete() would ignore
any completions on EP0. The legacy control API will also
ignore most completions on EP0, but it only did so after
filling in the completion event.

If the driver submits a spurious completion on EP0, then
this could clobber a previously queued completion event.

Fix this by deciding whether to ignore the completion
*before* modifying the event data.

Change-Id: I68526898a96efa594ada4e94bb6851aaaf12e92a
2021-11-13 18:37:33 +00:00
Dana Conrad
59ef877c94 x1000: delay power thread until valid battery read
Appears to return 0 until the axp has (presumably) completed
its first real measurement.

Note about erosq: keep the power_inint() delay large to ensure
nothing breaks in the bootloader for the time being.

Change-Id: I444e858207cc401c42f1e6ceacf067ad543d4ff8
2021-11-12 16:31:27 -05:00
Wolfram Sang
67fb558c89 as3525: debug: use 'kHz' where applicable instead of "MHz" or "KHz"
Change-Id: I84c24402d664b5a1a37c81aebfc438bd04bc8af4
2021-11-10 21:53:15 -05:00
Dana Conrad
9ee321cf90 ErosqNative: increase battery stabilization delay again
Hopefully 250 is long enough for any devices out there!

Change-Id: I80e084dceb62acd8d1f51d873b18a4be9c3447d8
2021-11-10 07:22:57 -05:00
Aidan MacDonald
7af98ce6bb usb: Fix possible SET ADDRESS data corruption
The address from the packet needs to be saved before sending
the response -- after the response the request being pointed
to could get overwritten. This used to be done correctly but
I unintentionally broke it when updating the handler to the
new control request API.

Change-Id: I9b11548baf20dce44a82301731405dc8e8f1cef3
2021-11-09 14:45:07 +00:00
William Wilgus
9f1cab154c lcd-16bit-common move bugfix to sim only
Ive seen no ill effects having this disabled on target so
limit it to the sim to stop Address Sanitizer from dumping
on the extra byte read. the bad data is never used AFAICT
since the loop ends

Change-Id: I8cb54e9d1f8fe28747867d861a015edb3dbfa5ff
2021-11-08 17:52:09 -05:00
Aidan MacDonald
8c954c68e5 usb: Attempt to fix race condition in compatibility layer
Because usb_core_legacy_control_request() is called by an
interrupt handler the global variables used to track the
current control request at the very least need to be volatile.

It might also be necessary to disable IRQs but I'm not sure
of that.

Change-Id: I0f0bb86d0ad63734e8d3c73cb1c52fedf5a98120
2021-11-08 21:46:36 +00:00
Solomon Peachy
5e663f0420 xduoox3ii: Ignore the remote events when headphones aren't plugged in
This prevents the actual insertion/removal from triggering false events

Change-Id: I54114ce903e110c31eca6b2ce258a0cf5f6b782b
2021-11-03 13:16:40 -04:00
William Wilgus
684565b8f3 USB fix red for device without HAVE_USB_POWER again.
Change-Id: I3122d532cbb8d5b5cb9040f08707c1514bc1b18e
2021-10-31 21:36:21 -04:00
William Wilgus
d72a0ed65d Use USB events for storing plugin_menu state
use usb connected callback to cancel menu reentry after USB plug/unplug

Change-Id: I8267deed6e8ada94ca527392f56f50ef22def1d7
2021-10-31 12:42:24 -04:00
William Wilgus
7a6737f471 USB Events fix red on devices without HAVE_USB_POWER
Change-Id: I112e6379d4bed019d7e047e5802f104e250d926e
2021-10-31 12:30:27 -04:00
William Wilgus
894a9d9063 USB add Insertion and Extraction callback events
We have this nice event library laying around probably a few more places
we could use event callbacks

Change-Id: I9180fa9d78788d161f2587110644ca3e08df6f50
2021-10-31 12:02:38 -04:00
Aidan MacDonald
0f68866ae5 fiiom3k: bump power on delay to 200ms
Needed due to a report that 80ms was not working.

Change-Id: I5f0f750b0530f5b84ffba58c5d7ff8b283095c4b
2021-10-18 23:03:04 +01:00
Aidan MacDonald
957add9d75 fiiom3k: adjust power on delay to 80ms
OST timer fix (7a5130a277) causes a boot failure on some units,
the battery voltage reading needs more time to stabilize.

Change-Id: Ic4a9ba90a16fab8ac6d27dbbe7af381f7c810f8f
2021-10-18 21:45:03 +01:00
Dana Conrad
6253cdebed ErosQNative: Fix mdelay calls due to g3859
The battery stabilization delay call seems to need to be
about 170 at minimum now, let's do 190 for safety (+20ms).

Change-Id: Ifd0248891abe827dfcc3e6baf48cc5bef0d0cc1c
2021-10-16 16:58:19 -04:00
Aidan MacDonald
7a5130a277 x1000: fix broken OST2 timer prescaler
It turns out the prescaler fields in OST_CTRL are 2 bits wide,
not 3. The programming manual (as usual) is ambiguous and its
diagram shows 2-bit wide fields, but the bit positions in the
text give a 3-bit wide field. Ingenic's Linux code and my own
testing shows that they are, in fact, 2 bits wide.

This caused the OST2 divisor to be 16 instead of 4; the OST1
divisor was correct. This means that all udelay/mdelay calls
took 4x longer than they should've. After this change the OST2
prescaler will be 4, as intended, and udelay/mdelay calls will
wait for the intended duration.

Change-Id: I2ac0a9190f49b59a840c649bf586131f5f9fde82
2021-10-16 16:58:19 -04:00
Aidan MacDonald
d085d01f5e x1000: enable DMA for USB driver
This boosts USB transfer performance a bit, ~10% for reads and
~25% for writes, for large-ish file transfers. Rockbox is still
around 33-50% slower than the OF.

Change-Id: I236a1e5c69a290c47ed27b70cb2631111fc157ed
2021-10-16 21:14:42 +01:00
Aidan MacDonald
4fc37eb47f usb-designware: port to new USB API
List of all platforms using this driver:

- Sansa Clip+ (tested, works)
- Sansa Clip v2 (untested)
- Sansa Clip Zip (tested, works)
- Sansa Fuze v2 (untested)
- iPod 6G (untested)
- iPod Nano 2G (untested)
- FiiO M3K (tested, works)
- Shanling Q1 (tested, works)
- Eros Q (tested, works)

Change-Id: I403ec64b030ea38f22cb52b31865639a78cd11e4
2021-10-16 21:14:42 +01:00
Aidan MacDonald
24294bda15 usb: ensure RX buffers are a multiple of the packet size
When performing an OUT transfer which is not a multiple of the
max packet size, the last packet of the OUT transfer should be
a short packet. However, there's no guarantee the host sends
the expected amount of data in the final packet.

The DWC2 USB controller handles this case by accepting any size
packet and copying it out to memory. So if the packet is bigger
than expected, it'll overrun the caller's buffer and Bad Things
will happen.

The USB 2.0 spec seems to endorse this behavior. Section 8.5.1
says "an ACK handshake indicates the endpoint has space for a
wMaxPacketSize data payload." So it is possible that other USB
controllers share the DWC2's behavior.

The simplest solution is to force all USB RX buffers to be big
enough to hold the transfer size, rounded up to a multiple of
the max packet size. For example, a transfer of 700 bytes would
require a 1024-byte buffer if the MPS = 512 bytes.

Change-Id: Ibb84d2b2d53aec8800a3a7c2449f7a17480acbcf
2021-10-16 21:14:42 +01:00
Aidan MacDonald
a665c1faad usb: remove dead code in usb_storage driver
Change-Id: Id6fc3520dad1adace33fd1014288ccb4cf5818af
2021-10-16 21:14:42 +01:00
Aidan MacDonald
988f244c74 usb: port usb_storage control request handling to new API
Change-Id: I1a19e09fdc0f05473d53c39bab0761d5cb8f6ff0
2021-10-16 21:14:42 +01:00
Aidan MacDonald
1b2cc053d3 usb: port usb_hid control request handling to new API
Change-Id: I9028cf06e91c9fcbe271f6ad81d6b252cb4e7cec
2021-10-16 21:14:42 +01:00
Aidan MacDonald
3318ba4795 usb: port usb_serial control requests handling to new API
Change-Id: I1405c9279e0e8e490e2bb2d03ff192b36db2634b
2021-10-16 21:14:42 +01:00
Aidan MacDonald
77731c3579 usb: port usb_core control request handling to new API
Change-Id: I3850c9cfcb87831e56884c83e31f728590b76f83
2021-10-16 21:14:42 +01:00
Aidan MacDonald
82efb1150e usb: implement new API with legacy emulation layer
All existing USB drivers now define USB_LEGACY_CONTROL_API to
enable the emulation layer.

Control request handlers will be ported in follow-up commits.

Change-Id: I4be1ce7c372f2f6fee5978a4858c841b72e77405
2021-10-16 21:14:42 +01:00
Aidan MacDonald
dff8320a5d usb: add request data argument to all control request handlers
Change-Id: I237143fa0d95c914b8e25ed22f8acde96ec00551
2021-10-16 21:14:42 +01:00
Aidan MacDonald
b69d43c247 usb: give USB transfer completion events two data pointers
Change-Id: I036cc7f02c2f86a364d2dba59493a6aa893f2c16
2021-10-16 21:14:42 +01:00