1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
diff --git a/apps/plugin.c b/apps/plugin.c
index 767c593..e5c2c86 100644
--- a/apps/plugin.c
+++ b/apps/plugin.c
@@ -382,10 +382,8 @@ static const struct plugin_api rockbox_api = {
     trigger_cpu_boost,
     cancel_cpu_boost,
 #endif
-#if NUM_CORES > 1
     cpucache_flush,
     cpucache_invalidate,
-#endif
     timer_register,
     timer_unregister,
     timer_set_period,
@@ -620,9 +618,6 @@ static const struct plugin_api rockbox_api = {
     plugin_get_audio_buffer,
     plugin_tsr,
     plugin_get_current_filename,
-#ifdef PLUGIN_USE_IRAM
-    plugin_iram_init,
-#endif
 #if defined(DEBUG) || defined(SIMULATOR)
     debugf,
 #endif
@@ -919,23 +914,6 @@ void* plugin_get_audio_buffer(size_t *buffer_size)
 #endif
 }

-#ifdef PLUGIN_USE_IRAM
-/* Initializes plugin IRAM */
-void plugin_iram_init(char *iramstart, char *iramcopy, size_t iram_size,
-                      char *iedata, size_t iedata_size)
-{
-    /* We need to stop audio playback in order to use codec IRAM */
-    audio_hard_stop();
-    memcpy(iramstart, iramcopy, iram_size);
-    memset(iedata, 0, iedata_size);
-    memset(iramcopy, 0, iram_size);
-#if NUM_CORES > 1
-    /* writeback cleared iedata and iramcopy areas */
-    cpucache_flush();
-#endif
-}
-#endif /* PLUGIN_USE_IRAM */
-
 /* The plugin wants to stay resident after leaving its main function, e.g.
    runs from timer or own thread. The callback is registered to later
    instruct it to free its resources before a new plugin gets loaded. */
diff --git a/apps/plugin.h b/apps/plugin.h
index 2f187f1..8afde21 100644
--- a/apps/plugin.h
+++ b/apps/plugin.h
@@ -147,12 +147,12 @@ void* plugin_get_buffer(size_t *buffer_size);
 #define PLUGIN_MAGIC 0x526F634B /* RocK */

 /* increase this every time the api struct changes */
-#define PLUGIN_API_VERSION 191
+#define PLUGIN_API_VERSION 192

 /* update this to latest version if a change to the api struct breaks
    backwards compatibility (and please take the opportunity to sort in any
    new function which are "waiting" at the end of the function table) */
-#define PLUGIN_MIN_API_VERSION 191
+#define PLUGIN_MIN_API_VERSION 192

 /* plugin return codes */
 /* internal returns start at 0x100 to make exit(1..255) work */
@@ -496,10 +496,8 @@ struct plugin_api {
     void (*trigger_cpu_boost)(void);
     void (*cancel_cpu_boost)(void);
 #endif
-#if NUM_CORES > 1
     void (*cpucache_flush)(void);
     void (*cpucache_invalidate)(void);
-#endif
     bool (*timer_register)(int reg_prio, void (*unregister_callback)(void),
                            long cycles, void (*timer_callback)(void)
                            IF_COP(, int core));
@@ -769,10 +767,6 @@ struct plugin_api {
     void* (*plugin_get_audio_buffer)(size_t *buffer_size);
     void (*plugin_tsr)(bool (*exit_callback)(bool reenter));
     char* (*plugin_get_current_filename)(void);
-#ifdef PLUGIN_USE_IRAM
-    void (*plugin_iram_init)(char *iramstart, char *iramcopy, size_t iram_size,
-                             char *iedata, size_t iedata_size);
-#endif
 #if defined(DEBUG) || defined(SIMULATOR)
     void (*debugf)(const char *fmt, ...) ATTRIBUTE_PRINTF(1, 2);
 #endif
@@ -929,30 +923,12 @@ extern unsigned char plugin_end_addr[];
         NULL, NULL, plugin__start, &rb };
 #endif /* CONFIG_PLATFORM */

-#ifdef PLUGIN_USE_IRAM
-/* Declare IRAM variables */
-#define PLUGIN_IRAM_DECLARE \
-    extern char iramcopy[]; \
-    extern char iramstart[]; \
-    extern char iramend[]; \
-    extern char iedata[]; \
-    extern char iend[];
-/* Initialize IRAM */
-#define PLUGIN_IRAM_INIT(api) \
-    (api)->plugin_iram_init(iramstart, iramcopy, iramend-iramstart, \
-                            iedata, iend-iedata);
-#else
 #define PLUGIN_IRAM_DECLARE
 #define PLUGIN_IRAM_INIT(api)
-#endif /* PLUGIN_USE_IRAM */
-#endif /* PLUGIN */
+#endif

 int plugin_load(const char* plugin, const void* parameter);
 void* plugin_get_audio_buffer(size_t *buffer_size);
-#ifdef PLUGIN_USE_IRAM
-void plugin_iram_init(char *iramstart, char *iramcopy, size_t iram_size,
-                      char *iedata, size_t iedata_size);
-#endif

 /* plugin_tsr,
     callback returns true to allow the new plugin to load,
diff --git a/apps/plugins/mpegplayer/header.c b/apps/plugins/mpegplayer/header.c
index 001cafe..8b1956b 100644
--- a/apps/plugins/mpegplayer/header.c
+++ b/apps/plugins/mpegplayer/header.c
@@ -87,8 +87,8 @@ const uint8_t default_mpeg2_scan_alt[64] =
     38, 46, 54, 62, 39, 47, 55, 63
 };

-uint8_t mpeg2_scan_norm[64] IDATA_ATTR;
-uint8_t mpeg2_scan_alt[64] IDATA_ATTR;
+uint8_t mpeg2_scan_norm[64] IBSS_ATTR;
+uint8_t mpeg2_scan_alt[64] IBSS_ATTR;

 void mpeg2_header_state_init (mpeg2dec_t * mpeg2dec)
 {
diff --git a/apps/plugins/plugin_crt0.c b/apps/plugins/plugin_crt0.c
index e34124c..49f5275 100644
--- a/apps/plugins/plugin_crt0.c
+++ b/apps/plugins/plugin_crt0.c
@@ -35,6 +35,12 @@ extern enum plugin_status plugin_start(const void*);
 extern unsigned char plugin_bss_start[];
 extern unsigned char plugin_end_addr[];

+extern char iramcopy[];
+extern char iramstart[];
+extern char iramend[];
+extern char iedata[];
+extern char iend[];
+
 static jmp_buf __exit_env;
 /* only 1 atexit handler for now, chain in the exit handler if you need more */
 static void (*atexit_handler)(void);
@@ -63,8 +69,29 @@ enum plugin_status plugin__start(const void *param)
     int exit_ret;
     enum plugin_status ret;

-    /* zero out the bss section */
+
 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
+#ifdef PLUGIN_USE_IRAM
+/*
+void plugin_iram_init(char *iramstart, char *iramcopy, size_t iram_size,
+                      char *iedata, size_t iedata_size);
+                      
+(api)->plugin_iram_init(iramstart, iramcopy, iramend-iramstart, \
+                        iedata, iend-iedata);
+*/
+    size_t iram_size = iramend - iramstart;
+    size_t ibss_size = iend - iedata;
+    if (iram_size > 0 || ibss_size > 0)
+    {
+        /* We need to stop audio playback in order to use codec IRAM */
+        rb->audio_stop();
+        rb->memcpy(iramstart, iramcopy, iram_size); /* copy code&data */
+        rb->memset(iedata, 0, ibss_size); /* zero ibss */
+        /* writeback cleared iedata and iramcopy areas */
+        rb->cpucache_flush();
+    }
+#endif
+    /* zero bss */
     rb->memset(plugin_bss_start, 0, plugin_end_addr - plugin_bss_start);
 #endif
     /* we come back here if exit() was called or the plugin returned normally */