Skip to content

Commit

Permalink
0.1.12 ota_write_status conditional and cosmetics
Browse files Browse the repository at this point in the history
and an excuse to test the new latest-pre-release system
  • Loading branch information
HomeACcessoryKid committed Dec 19, 2018
1 parent db9edf9 commit 90ca767
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 30 deletions.
28 changes: 14 additions & 14 deletions deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,27 @@ cd life-cycle-manager

#create/update the file versions/latest-pre-release but no new-line
```
echo -n 0.1.11 > versions/latest-pre-release
mkdir versions/0.1.11v
cp versions/certs.sector versions/0.1.11v
echo -n 0.1.12 > versions/latest-pre-release
mkdir versions/0.1.12v
cp versions/certs.sector versions/0.1.12v
```
#set local.mk to the ota-main program
```
make -j6 rebuild OTAVERSION=0.1.11
mv firmware/otamain.bin versions/0.1.11v
make -j6 rebuild OTAVERSION=0.1.12
mv firmware/otamain.bin versions/0.1.12v
```
#set local.mk back to ota-boot program
```
make -j6 rebuild OTAVERSION=0.1.11
mv firmware/otaboot.bin versions/0.1.11v
make -j6 rebuild OTAVERSION=0.1.11 OTABETA=1
cp firmware/otaboot.bin versions/0.1.11v/otabootbeta.bin
make -j6 rebuild OTAVERSION=0.1.12
mv firmware/otaboot.bin versions/0.1.12v
make -j6 rebuild OTAVERSION=0.1.12 OTABETA=1
cp firmware/otaboot.bin versions/0.1.12v/otabootbeta.bin
```

#remove the older versions files

#commit this as version 0.1.11
#set up a new github release 0.1.11 as a pre-release using the just commited master...
#commit this as version 0.1.12
#set up a new github release 0.1.12 as a pre-release using the just commited master...
#upload the certs and binaries to the pre-release assets on github

#erase the flash and upload the privatekey
Expand All @@ -41,14 +41,14 @@ esptool.py -p /dev/cu.usbserial-* --baud 230400 write_flash 0xf5000 privatekey.d
```
#upload the ota-boot BETA program to the device that contains the private key
```
make flash OTAVERSION=0.1.11 OTABETA=1
make flash OTAVERSION=0.1.12 OTABETA=1
```
#power cycle to prevent the bug for software reset after flash
#create the 3 signature files next to the bin file and upload to github one by one
#verify the hashes on the computer
```
openssl sha384 versions/0.1.11v/otamain.bin
xxd versions/0.1.11v/otamain.bin.sig
openssl sha384 versions/0.1.12v/otamain.bin
xxd versions/0.1.12v/otamain.bin.sig
```

#upload the file versions/latest-pre-release to the 'latest release' assets on github
Expand Down
4 changes: 2 additions & 2 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,9 @@ void ota_task(void *arg) {
ota_get_hash(user_repo, new_version, user_file, &signature);
file_size=ota_get_file(user_repo,new_version,user_file,BOOT0SECTOR);
if (file_size<=0 || ota_verify_hash(BOOT0SECTOR,&signature)) continue; //something went wrong, but now boot0 is broken so start over
ota_finalize_file(BOOT0SECTOR);
ota_finalize_file(BOOT0SECTOR); //TODO return status and if wrong, continue
ota_write_status(new_version); //we have been successful, hurray!
} //nothing to update
ota_write_status(new_version); //we have been successful, hurray!
break; //leads to boot=0 and starts updated user app
}
}
Expand Down
27 changes: 14 additions & 13 deletions ota.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,37 +219,38 @@ void ota_sign(int start_sector, int filesize, signature_t* signature, char* file
}

int ota_compare(char* newv, char* oldv) { //(if equal,0) (if newer,1) (if pre-release or older,-1)
UDPLGP("--- ota_compare\n");
UDPLGP("--- ota_compare ");
char* dot;
int valuen=0,valueo=0;
char news[MAXVERSIONLEN],olds[MAXVERSIONLEN];
char * new=news;
char * old=olds;
int result=0;

if (strcmp(newv,oldv)) { //https://semver.org/#spec-item-11
if (strchr(newv,'-')) return -1; //we cannot handle pre-releases in the 'latest version' concept
//they should not occur since they will block finding a valid production version.
//mark them properly as pre-release in github so they do now show up in releases/latest
if (strchr(newv,'-')) result=-1; //we cannot handle versions with pre-release suffix notation (yet)
//pre-release marker in github serves to identify those
strncpy(new,newv,MAXVERSIONLEN-1);
strncpy(old,oldv,MAXVERSIONLEN-1);
if ((dot=strchr(new,'.'))) {dot[0]=0; valuen=atoi(new); new=dot+1;}
if ((dot=strchr(old,'.'))) {dot[0]=0; valueo=atoi(old); old=dot+1;}
UDPLOG("%d-%d,%s-%s\n",valuen,valueo,new,old);
if (valuen>valueo) return 1;
if (valuen<valueo) return -1;
if (valuen>valueo) result=1;
if (valuen<valueo) result=-1;
valuen=valueo=0;
if ((dot=strchr(new,'.'))) {dot[0]=0; valuen=atoi(new); new=dot+1;}
if ((dot=strchr(old,'.'))) {dot[0]=0; valueo=atoi(old); old=dot+1;}
UDPLOG("%d-%d,%s-%s\n",valuen,valueo,new,old);
if (valuen>valueo) return 1;
if (valuen<valueo) return -1;
if (valuen>valueo) result=1;
if (valuen<valueo) result=-1;
valuen=atoi(new);
valueo=atoi(old);
UDPLOG("%d-%d\n",valuen,valueo);
if (valuen>valueo) return 1;
if (valuen<valueo) return -1;
if (valuen>valueo) result=1;
if (valuen<valueo) result=-1;
} //they are equal
return 0; //equal strings
UDPLGP("%d\n",result);
return result; //equal strings
}

static int ota_connect(char* host, int port, int *socket, WOLFSSL** ssl) {
Expand Down Expand Up @@ -406,7 +407,6 @@ void ota_set_verify(int onoff) {
wolfSSL_CTX_set_verify(ctx, SSL_VERIFY_NONE, NULL);
}
}
printf("--- end_set_verify...\n");
}

int ota_get_file_ex(char * repo, char * version, char * file, int sector, byte * buffer, int bufsz); //prototype needed
Expand Down Expand Up @@ -536,7 +536,7 @@ int ota_get_file_ex(char * repo, char * version, char * file, int sector, byte
strchr(location,' ')[0]=0;
location+=9; //flush "HTTP/1.1 "
slash=atoi(location);
UDPLOG("HTTP returns %d\n",slash);
UDPLGP("HTTP returns %d\n",slash);
if (slash!=302) {
wolfSSL_free(ssl);
lwip_close(socket);
Expand Down Expand Up @@ -684,6 +684,7 @@ void ota_finalize_file(int sector) {
UDPLGP("--- ota_finalize_file\n");

if (!spiflash_write(sector, file_first_byte, 1)) UDPLOG("error writing flash\n");
//TODO: add verification and retry and if wrong return status...
}

int ota_get_file(char * repo, char * version, char * file, int sector) { //number of bytes
Expand Down
File renamed without changes.
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion versions/latest-pre-release
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.11
0.1.12

0 comments on commit 90ca767

Please sign in to comment.