summaryrefslogtreecommitdiff
path: root/firmware
diff options
context:
space:
mode:
authorAidan MacDonald <amachronic@protonmail.com>2022-01-18 18:57:06 +0000
committerAidan MacDonald <amachronic@protonmail.com>2022-02-12 10:24:32 -0500
commite8faf2f2adeb9066de3c968a57803bb262f61ee1 (patch)
tree130c2e3d904da7876ac88ea089f85f48cab5e313 /firmware
parent95dfc489b5a602f68202b206c434f8485e9d3915 (diff)
downloadrockbox-e8faf2f2adeb9066de3c968a57803bb262f61ee1.tar.gz
rockbox-e8faf2f2adeb9066de3c968a57803bb262f61ee1.zip
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
Diffstat (limited to 'firmware')
-rw-r--r--firmware/buflib.c6
-rw-r--r--firmware/common/zip.c4
-rw-r--r--firmware/include/buflib.h6
-rw-r--r--firmware/rolo.c2
-rw-r--r--firmware/target/mips/ingenic_x1000/installer-x1000.c2
-rw-r--r--firmware/usbstack/usb_storage.c7
6 files changed, 18 insertions, 9 deletions
diff --git a/firmware/buflib.c b/firmware/buflib.c
index 0e90e7fe72..c6ec011653 100644
--- a/firmware/buflib.c
+++ b/firmware/buflib.c
@@ -97,6 +97,12 @@
97 97
98#define BPANICF panicf 98#define BPANICF panicf
99 99
100struct buflib_callbacks buflib_ops_locked = {
101 .move_callback = NULL,
102 .shrink_callback = NULL,
103 .sync_callback = NULL,
104};
105
100#define IS_MOVABLE(a) (!a[2].ops || a[2].ops->move_callback) 106#define IS_MOVABLE(a) (!a[2].ops || a[2].ops->move_callback)
101static union buflib_data* find_first_free(struct buflib_context *ctx); 107static union buflib_data* find_first_free(struct buflib_context *ctx);
102static union buflib_data* find_block_before(struct buflib_context *ctx, 108static union buflib_data* find_block_before(struct buflib_context *ctx,
diff --git a/firmware/common/zip.c b/firmware/common/zip.c
index 9512d6c239..36b90a9223 100644
--- a/firmware/common/zip.c
+++ b/firmware/common/zip.c
@@ -32,9 +32,7 @@
32#include "crc32.h" 32#include "crc32.h"
33#include "rbendian.h" 33#include "rbendian.h"
34 34
35#define zip_core_alloc(N) core_alloc_ex("zip",(N),&dummy_ops) 35#define zip_core_alloc(N) core_alloc_ex("zip",(N),&buflib_ops_locked)
36
37static struct buflib_callbacks dummy_ops;
38 36
39enum { 37enum {
40 ZIP_SIG_ED = 0x06054b50, 38 ZIP_SIG_ED = 0x06054b50,
diff --git a/firmware/include/buflib.h b/firmware/include/buflib.h
index 7f534c6ce0..e805ebbf1b 100644
--- a/firmware/include/buflib.h
+++ b/firmware/include/buflib.h
@@ -129,6 +129,12 @@ struct buflib_callbacks {
129 void (*sync_callback)(int handle, bool sync_on); 129 void (*sync_callback)(int handle, bool sync_on);
130}; 130};
131 131
132/** A set of all NULL callbacks for use with allocations that need to stay
133 * locked in RAM and not moved or shrunk. These type of allocations should
134 * be avoided as much as possible to avoid memory fragmentation but it can
135 * suitable for short-lived allocations. */
136extern struct buflib_callbacks buflib_ops_locked;
137
132#define BUFLIB_SHRINK_SIZE_MASK (~BUFLIB_SHRINK_POS_MASK) 138#define BUFLIB_SHRINK_SIZE_MASK (~BUFLIB_SHRINK_POS_MASK)
133#define BUFLIB_SHRINK_POS_FRONT (1u<<31) 139#define BUFLIB_SHRINK_POS_FRONT (1u<<31)
134#define BUFLIB_SHRINK_POS_BACK (1u<<30) 140#define BUFLIB_SHRINK_POS_BACK (1u<<30)
diff --git a/firmware/rolo.c b/firmware/rolo.c
index 5f936c95f4..f95fc4bd4d 100644
--- a/firmware/rolo.c
+++ b/firmware/rolo.c
@@ -242,7 +242,7 @@ int rolo_load(const char* filename)
242 242
243 /* get the system buffer. release only in case of error, otherwise 243 /* get the system buffer. release only in case of error, otherwise
244 * we don't return anyway */ 244 * we don't return anyway */
245 rolo_handle = core_alloc_maximum("rolo", &filebuf_size, NULL); 245 rolo_handle = core_alloc_maximum("rolo", &filebuf_size, &buflib_ops_locked);
246 if (rolo_handle < 0) 246 if (rolo_handle < 0)
247 { 247 {
248 rolo_error("OOM"); 248 rolo_error("OOM");
diff --git a/firmware/target/mips/ingenic_x1000/installer-x1000.c b/firmware/target/mips/ingenic_x1000/installer-x1000.c
index 0a09ad0e91..66aa42d4a1 100644
--- a/firmware/target/mips/ingenic_x1000/installer-x1000.c
+++ b/firmware/target/mips/ingenic_x1000/installer-x1000.c
@@ -148,7 +148,7 @@ static int updater_init(struct updater* u)
148 148
149 /* buf_len is a bit oversized here, but it's not really important */ 149 /* buf_len is a bit oversized here, but it's not really important */
150 u->buf_len = u->img_len + sizeof(mtar_t) + 2*CACHEALIGN_SIZE; 150 u->buf_len = u->img_len + sizeof(mtar_t) + 2*CACHEALIGN_SIZE;
151 u->buf_hnd = core_alloc("boot_image", u->buf_len); 151 u->buf_hnd = core_alloc_ex("boot_image", u->buf_len, &buflib_ops_locked);
152 if(u->buf_hnd < 0) { 152 if(u->buf_hnd < 0) {
153 rc = IERR_OUT_OF_MEMORY; 153 rc = IERR_OUT_OF_MEMORY;
154 goto error; 154 goto error;
diff --git a/firmware/usbstack/usb_storage.c b/firmware/usbstack/usb_storage.c
index a32cf185e7..eb82f72eae 100644
--- a/firmware/usbstack/usb_storage.c
+++ b/firmware/usbstack/usb_storage.c
@@ -449,12 +449,11 @@ void usb_storage_init_connection(void)
449#endif 449#endif
450#else 450#else
451 unsigned char * buffer; 451 unsigned char * buffer;
452 /* dummy ops with no callbacks, needed because by
453 * default buflib buffers can be moved around which must be avoided */
454 static struct buflib_callbacks dummy_ops;
455 452
456 // Add 31 to handle worst-case misalignment 453 // Add 31 to handle worst-case misalignment
457 usb_handle = core_alloc_ex("usb storage", ALLOCATE_BUFFER_SIZE + MAX_CBW_SIZE + 31, &dummy_ops); 454 usb_handle = core_alloc_ex("usb storage",
455 ALLOCATE_BUFFER_SIZE + MAX_CBW_SIZE + 31,
456 &buflib_ops_locked);
458 if (usb_handle < 0) 457 if (usb_handle < 0)
459 panicf("%s(): OOM", __func__); 458 panicf("%s(): OOM", __func__);
460 459