Commit b7b236aa authored by Mick Michalski's avatar Mick Michalski
Browse files

Added prepost c code

parent e790c224
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
int setBuffer(char *buffer, int pos, int value){
if(buffer[pos] == value) return 0;
buffer[pos] = value;
return 1;
}
int main(void) {
char *devSettings = getenv("DEVICE_SETTINGS");
char buffer[128];
/* Get the current boot settings */
FILE *f = fopen(devSettings, "r");
fgets(buffer, 5, f);
fclose(f);
int doUpdate = 0;
/* Set the boot partition to the opposite of the current partition */
if(buffer[3] == '0') doUpdate += setBuffer(buffer, 1, '1');
else doUpdate += setBuffer(buffer, 1, '0');
if(doUpdate){
/* Create a temp file */
char tempFile[64];
strcpy(tempFile, "/tmp/swu-prepost-boot.XXXXXX");
int fd = mkstemp(tempFile);
write(fd, buffer, 4);
/* Write temp file to mtd0, then delete temp file */
snprintf(buffer, 127, "flashcp %s %s", tempFile, devSettings);
system(buffer);
unlink(tempFile); /* automatically close and delete when done */
}
return 0;
}
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
int setBuffer(char *buffer, int pos, int value){
if(buffer[pos] == value) return 0;
buffer[pos] = value;
return 1;
}
int main(void) {
char *devSettings = getenv("DEVICE_SETTINGS");
char buffer[128];
/* Get the current boot settings */
FILE *f = fopen(devSettings, "r");
fgets(buffer, 5, f);
fclose(f);
int doUpdate = 0;
/* Set the boot partition to the opposite of the current partition */
if(buffer[2] == '0') doUpdate += setBuffer(buffer, 0, '1');
else doUpdate += setBuffer(buffer, 0, '0');
if(doUpdate){
/* Create a temp file */
char tempFile[64];
strcpy(tempFile, "/tmp/swu-prepost-boot.XXXXXX");
int fd = mkstemp(tempFile);
write(fd, buffer, 4);
/* Write temp file to mtd0, then delete temp file */
snprintf(buffer, 127, "flashcp %s %s", tempFile, devSettings);
system(buffer);
unlink(tempFile); /* automatically close and delete when done */
}
return 0;
}
#include <stdlib.h>
#include <stdio.h>
int main(void) {
char *devSettings = getenv("DEVICE_SETTINGS");
char *devFsMain = getenv("DEVICE_FILESYSTEM_MAIN");
char *devFsAlt = getenv("DEVICE_FILESYSTEM_ALT");
char buffer[16];
FILE *f = fopen(devSettings, "r");
fgets(buffer, 5, f);
fclose(f);
char cmd[128];
system("rm /dev/dev-fs > /dev/null"); /* Delete the current link if exists, suppressing output */
if(buffer[3] == '0'){ /* The current filesystem */
snprintf(cmd, 127, "ln -s %s /dev/dev-fs", devFsAlt);
system(cmd); /* Create a new link to alt fs partition */
} else {
snprintf(cmd, 127, "ln -s %s /dev/dev-fs", devFsMain);
system(cmd); /* Create a new link to main fs partition */
}
return 0;
}
#include <stdlib.h>
#include <stdio.h>
int main(void) {
char *devSettings = getenv("DEVICE_SETTINGS");
char *devKMain = getenv("DEVICE_KERNEL_MAIN");
char *devKAlt = getenv("DEVICE_KERNEL_ALT");
char buffer[16];
FILE *f = fopen(devSettings, "r");
fgets(buffer, 5, f);
fclose(f);
char cmd[128];
system("rm /dev/dev-fs > /dev/null"); /* Delete the current link if exists, suppressing output */
if(buffer[2] == '0'){ /* The current filesystem */
snprintf(cmd, 127, "ln -s %s /dev/dev-fs", devKAlt);
system(cmd); /* Create a new link to alt kernel partition */
} else {
snprintf(cmd, 127, "ln -s %s /dev/dev-fs", devKMain);
system(cmd); /* Create a new link to main kernel partition */
}
return 0;
}
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
extern char **environ;
int main(void) {
char *devSettings = getenv("DEVICE_SETTINGS");
if(!devSettings) {
printf("No settings found");
return 1;
}
char buffer[128];
int doUpdate=0;
/* Get the current boot settings */
FILE *f = fopen(devSettings, "r");
fgets(buffer, 5, f);
fclose(f);
/* Set the current boot partitions */
if(buffer[2] != buffer[0]){
buffer[2] = buffer[0];
doUpdate = 1;
}
if(buffer[3] != buffer[1]){
buffer[3] = buffer[1];
doUpdate = 1;
}
if(doUpdate){
printf("Updating device settings with new boot partitions\n");
/* Create a temp file */
char tempFile[64];
strcpy(tempFile, "/tmp/swu-prepost-boot.XXXXXX");
int fd = mkstemp(tempFile);
write(fd, buffer, 4);
/* Write temp file to mtd0, then delete temp file */
snprintf(buffer, 127, "flashcp %s %s", tempFile, devSettings);
system(buffer);
unlink(tempFile); /* automatically close and delete when done */
} else {
printf("Device settings unchanged\n");
}
return 0;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment