Commit Graph

20 Commits

Author SHA1 Message Date
bbeaavr
7a5ae7e0a5 Add "modem_tng" alias for tunning partition 2023-01-17 23:01:35 -06:00
Luca Weiss
695d0668ff storage: fix out of bounds read
Given that shadow_len is size_t (unsigned integer), subtracting a number
from it will make it wrap around < 0 and become positive again so the
subsequent "if (n > 0)" check will be mostly useless. On AOSP this makes
rmtfs segfault, on Linux distributions rmtfs happily reads beyond the
end of the buf.

Fix this by casting both parameters to ssize_t (which is signed) to
correctly use the if and not read beyond the end of shadow_buf.

Relevant trace using extra debug statements:
  storage_populate_shadow_buf: file=/dev/disk/by-partlabel/fsg shadow_buf=0xffffa5217060 shadow_len=0x280000
  <snip>
  storage_pread: memcpy shadow_buf=0xffffa5217060 offset=0x27fc00 n=0x200
  storage_pread: memcpy shadow_buf=0xffffa5217060 offset=0x27fe00 n=0x200
  storage_pread: memcpy shadow_buf=0xffffa5217060 offset=0x280000 n=0x0 - don't read!
  storage_pread: memcpy shadow_buf=0xffffa5217060 offset=0x280200 n=0x200
  storage_pread: memcpy shadow_buf=0xffffa5217060 offset=0x280400 n=0x200
  storage_pread: memcpy shadow_buf=0xffffa5217060 offset=0x280600 n=0x200
  storage_pread: memcpy shadow_buf=0xffffa5217060 offset=0x280800 n=0x200
  <snip>

Signed-off-by: Luca Weiss <luca.weiss@fairphone.com>
2022-07-18 15:27:49 -05:00
Evan Green
b08ef6f98e Use fdatasync instead of O_SYNC on storage
Opening the backing files with O_SYNC makes things really slow. So slow
in fact that the modem times out after 10 seconds waiting for the last
EFS sync to go through. I think this takes forever because rmtfs is
doing 512-byte reads and writes.

One option would be to make this bigger. But a better option is to not
use O_SYNC, but explicitly do an fdatasync() after the iovec operation
is complete. This is better because 1) it's way faster, we no longer see
10-12 second delays at rebooto time, and 2) partial syncs of the EFS
file aren't useful anyway.

Use fdatasync() as opposed to fsync() since it's not important for the
metadata to be synced, just the file contents.

Signed-off-by: Evan Green <evangreen86@gmail.com>
2021-08-09 14:33:25 -07:00
Bjorn Andersson
293ab8babb storage: Sync changes
Open the storage devices as O_SYNC, to make sure modem writes aren't
lingering in the event of power loss or sudden reboot.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2021-04-08 11:56:53 -05:00
Bjorn Andersson
1cc12d3dc1 storage: Use storage_close() to free up resources on exit
Use storage_close() to free up the shadow buffers as well, to avoid any
lingering allocations.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2020-12-07 08:43:18 -08:00
Vincent Knecht
417f04a9a7 storage: Add modem_tunning partition needed for Alcatel Idol 3 devices 2020-11-13 09:02:56 -08:00
John Stultz
0d00985e5e sharedmem: Fix pointer arithmetic warnings.
Building rmtfs on AOSP, we see a lot of the following:
  warning: arithmetic on a pointer to void is a GNU extension

Fix this by casting the void* ptrs to char* when doing pointer
arithmatic.

Signed-off-by: John Stultz <john.stultz@linaro.org>
[AmitP: Fixed cherry-pick conflicts and updated commit log]
Signed-off-by: Amit Pundir <amit.pundir@linaro.org>
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2020-09-28 10:08:11 -05:00
Amit Pundir
5b1471efa8 storage: Use -o option to override partition by-name
Instead of hardcoding BY_PARTLABEL_PATH for AOSP,
reuse -o option as suggested by Bjorn to expand John's
patch to find correct partition by-name on newer
kernels (which is /dev/block/platform/soc*/*.*/by-name).

For example: On db845c running v5.4+ kernel we run:
rmtfs -o /dev/block/platform/soc@0/1d84000.ufshc/by-name -P -r -s

Signed-off-by: Amit Pundir <amit.pundir@linaro.org>
Signed-off-by: John Stultz <john.stultz@linaro.org>
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2020-09-28 10:07:23 -05:00
Amit Pundir
9ef260ba6f ANDROID: Add Android support
* Add Android.bp makefile to build rmtfs for AOSP.
* libudev is not supported on AOSP so read
  /sys/class/rmtfs sysfs entries directly.

Signed-off-by: Amit Pundir <amit.pundir@linaro.org>
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2020-02-03 09:13:59 -08:00
Bjorn Andersson
df6c19d033 storage: Track opened files without backing storage
Upon populating the shadow_buf the no fd is associated with the rmtfd.
Therefor the next open request will conclude that the rmtfd is available
and use the same entry. Fix this by checking for both associated fd and
shadow_buf in the open call.

Fixes: c35633ab23 ("storage: Allow read only backing storage")
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2019-07-28 13:11:53 -07:00
Bjorn Andersson
42edb9c07a storage: Support operating on raw partitions
Most devices has partitions named modemst1, modemst2, fsg and fsc
backing the rmtfs. Add a new argument '-P' to get the storage
implementation to use these partitions directly instead of files.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2019-07-17 12:23:19 -07:00
Bjorn Andersson
c35633ab23 storage: Allow read only backing storage
Add a new argument '-r' to prevent writes back to the backing storage.
This is useful for experimenting with the remote storage, without having
the files overwritten.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2019-07-17 12:23:02 -07:00
Bjorn Andersson
e6d703b3c8 storage: Revise API
Pass "struct rmtfd" instead of file descriptors in the interface. This
cleans up the api a little bit, but more importantly allow us to
associate additional things with the remote file descriptors.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2019-07-17 12:22:26 -07:00
Bjorn Andersson
152b96981e storage: Rename caller to "remote fd"
The caller (and caller_id) are really "remote file descriptors", so
rename them based on this.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2019-07-17 12:22:26 -07:00
Bjorn Andersson
886608484b rmtfs: Use pread/pwrite for storage
Instead of relying on an initial lseek, use pread/pwrite. This creates a
cleaner interface towards the storage.c implementation, allowing us to
provide a memory-only implementation of the backing storage.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2019-07-17 12:22:26 -07:00
Evan Green
cfb76ff6ee storage: Allow specifying the storage directory
Enable the specification of storage paths other than /boot, using
a new -o command line argument. Getoptify the command line arguments
for better processing.
2018-12-19 09:21:06 -08:00
Joey Hewitt
a75ad5dc2a sharedmem: support uio device
Also a fix to error-reporting for opening the storage.
2018-05-21 17:05:29 -07:00
Bjorn Andersson
8c79959935 storage: Reuse already open caller objects
In the event that the remote crashes, or for other reasons try to open a
partition that we already have open we should reuse the caller objects,
so that we don't run out of them. This should likely be replaced by a
working mechanism for notifications when the remote is going away.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2016-11-29 09:09:04 -08:00
Bjorn Andersson
6e467200c5 rmtfs: Include fsc partition in white list
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2016-02-08 16:29:51 -08:00
Bjorn Andersson
1f12cea75b rmtfs: Initial rmtfs implementation
The rmtfs tool pushlishes the two QMI services "rmtfs" and "rfsa", and
implements the necessary requests for rmtfs that's needed to boot the
modem subsystem on a Qualcomm based board.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2016-02-07 09:32:14 -08:00