aboutsummaryrefslogtreecommitdiff
path: root/src/target/target.c
diff options
context:
space:
mode:
authorAndreas Fritiofson <andreas.fritiofson@gmail.com>2012-02-13 01:19:57 +0100
committerSpencer Oliver <spen@spen-soft.co.uk>2012-02-23 14:04:01 +0000
commit2eb564b756bb2b7c63c1510845a42491ef82fa8d (patch)
tree7b7bf5116de57996a78cca0fd662c4c174c3b978 /src/target/target.c
parent813f4a5411af9a397d6e9bbc682a43738b06baeb (diff)
target: add function to get number of bytes available in working area
This is a much cleaner solution to the problem of allocating as much working area as possible than what is currently being done in most/all flash drivers (which is: try an arbitrary sized chunk, if it fails, pick a smaller number, rinse and repeat). Use this function to find out how much working area is available, limit or restrict that amount at will and then simply allocate it. Change-Id: Ib7d5d0b7485aed3e0a4fad60c1bedb7dfd16146f Signed-off-by: Andreas Fritiofson <andreas.fritiofson@gmail.com> Reviewed-on: http://openocd.zylin.com/446 Tested-by: jenkins Reviewed-by: Spencer Oliver <spen@spen-soft.co.uk>
Diffstat (limited to 'src/target/target.c')
-rw-r--r--src/target/target.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/target/target.c b/src/target/target.c
index 26607c57..5b37ef03 100644
--- a/src/target/target.c
+++ b/src/target/target.c
@@ -1502,6 +1502,25 @@ void target_free_all_working_areas(struct target *target)
target_free_all_working_areas_restore(target, 1);
}
+/* Find the largest number of bytes that can be allocated */
+uint32_t target_get_working_area_avail(struct target *target)
+{
+ struct working_area *c = target->working_areas;
+ uint32_t max_size = 0;
+
+ if (c == NULL)
+ return target->working_area_size;
+
+ while (c) {
+ if (c->free && max_size < c->size)
+ max_size = c->size;
+
+ c = c->next;
+ }
+
+ return max_size;
+}
+
int target_arch_state(struct target *target)
{
int retval;