SingingCat 0
application
app_update.c
1#include "main-header.h"
2#include "app_update.h"
3#include "partitions.h"
4#include "baseinfo.h"
5#include "flashapp.h"
6
7
8#define META_MAGIC 0x53434656
9/*
10 * static uint32_t get_max_seq() {
11 * int ct = loader_get_app_base_address_count();
12 * int i;
13 * uint32_t res = 0;
14 * for (i=0;i<ct;i++) {
15 * void *base = loader_get_app_base_address(i);
16 * if (base == NULL) {
17 * continue;
18 * }
19 * struct meta_header *mh = base - 1024;
20 * if (mh->magic != META_MAGIC) {
21 * continue;
22 * }
23 * printf("Sequence at @%p: %i\r\n",base,mh->meta_seq);
24 * if (mh->meta_seq > res) {
25 * res = mh->meta_seq;
26 * }
27 * }
28 * return res;
29 * }
30 */
31
36/*
37 * static int old_loader_set_latest_app(struct app_header *app) {
38 * struct meta_header *meta;
39 * struct meta_header newmeta;
40 *
41 * meta = ((void *)app) - 1024;
42 * newmeta.magic = META_MAGIC;
43 * uint32_t newseq = get_max_seq();
44 * newseq++;
45 * newmeta.meta_seq = newseq;
46 * printf("New meta sequence: %i\r\n",newseq);
47 * int r = 0;
48 * r = flash_write((byte *) &newmeta, meta,1024);
49 * return r;
50 * }
51 */
52// set an app to be 'latest'. do the right thing for old (appinfo) and new loaders (partitions)
53int set_latest_app(void *base) {
54 // if we have no loaderapi, we do not need to bother, because then we have a new loader
55 // which understands partitions
56 if (loader_has_api()) {
57 byte buf[1024]; // BUG in old loader: it reads 1k from stack onwards, so make sure stack has room on top
58 buf[0] = 1;
59 printf("Updating loader metadata of app @%p to become latest app\r\n", base);
60 int x;
61 if (buf[0] == 1) {
62 x = loader_set_latest_app(base);
63 }
64 if (x) {
65 printf("Failed to write metadata: %i\r\n", x);
66 } else {
67 printf("Metadata written\r\n");
68 }
69 }
70 printf("Set app %p in partition\r\n", base);
71 partition_set_latest_app(base);
72 return 0;
73}