]> git.gag.com Git - fw/stlink/blobdiff - src/st-term.c
st-term magic byte via commandline argument
[fw/stlink] / src / st-term.c
index bbf7ea37ef714a7e39062c5ee6ee5f173d44e0b0..4f2f9f77cf6722f450502db38b4ca4785ea62f9b 100644 (file)
@@ -30,6 +30,7 @@ struct stlinky*  stlinky_detect(stlink_t* sl)
 {
        static const uint32_t sram_base = 0x20000000;
        struct stlinky* st = malloc(sizeof(struct stlinky));
+       int multiple=0;
        st->sl = sl;
        printf("sram: 0x%x bytes @ 0x%zx\n", sl->sram_base, sl->sram_size);
        uint32_t off;
@@ -37,14 +38,22 @@ struct stlinky*  stlinky_detect(stlink_t* sl)
                stlink_read_mem32(sl, sram_base + off, 4);
                if (STLINKY_MAGIC == READ_UINT32_LE(sl->q_buf))
                {
+                       if (multiple > 0)
+                       printf("WARNING: another ");
                        printf("stlinky detected at 0x%x\n", sram_base + off);
                        st->off = sram_base + off;
                        stlink_read_mem32(sl, st->off + 4, 4);
                        st->bufsize = (size_t) *(unsigned char*) sl->q_buf;
                        printf("stlinky buffer size 0x%zu \n", st->bufsize);
-                       return st;
+                       multiple++;
                }
        }
+       if (multiple > 0) {
+               if (multiple > 1) {
+                       printf("Using last stlinky structure detected\n");
+               }
+               return st;
+       }
        return NULL;
 }
 
@@ -139,10 +148,8 @@ void cleanup(int dummy)
 
 int main(int ac, char** av) {
        stlink_t* sl;
-
-       /* unused */
-       ac = ac;
-       av = av;
+       struct stlinky *st;
+       
        sl = stlink_open_usb(10, 1);
        if (sl != NULL) {
                printf("ST-Linky proof-of-concept terminal :: Created by Necromant for lulz\n");
@@ -165,7 +172,19 @@ int main(int ac, char** av) {
                /* TODO: Make timeout adjustable via command line */
                sleep(1);
 
-               struct stlinky *st = stlinky_detect(sl);
+               if(ac == 1){ 
+                       st = stlinky_detect(sl);
+               }else if(ac == 2){
+                       st = malloc(sizeof(struct stlinky));
+                       st->sl = sl;
+                       st->off = (int)strtol(av[1], NULL, 16);
+                       printf("using stlinky at 0x%x\n", st->off);
+                       stlink_read_mem32(sl, st->off + 4, 4);
+                       st->bufsize = (size_t) *(unsigned char*) sl->q_buf;
+                       printf("stlinky buffer size 0x%zu \n", st->bufsize);
+               }else{
+                       goto bailout;
+               }
                if (st == NULL)
                {
                        printf("stlinky magic not found in sram :(\n");