diff --git a/buptest.c b/buptest.c index 428b2e9..07e2fd7 100644 --- a/buptest.c +++ b/buptest.c @@ -98,9 +98,57 @@ unsigned int dump_read_8(unsigned int address) { return value & 0xff; // ODD , A0=1,LDS } +int check_emulator() { + + DIR* dir; + struct dirent* ent; + char buf[512]; + + long pid; + char pname[100] = {0,}; + char state; + FILE *fp=NULL; + const char *name = "emulator"; + + if (!(dir = opendir("/proc"))) { + perror("can't open /proc, assuming emulator running"); + return 1; + } + + while((ent = readdir(dir)) != NULL) { + long lpid = atol(ent->d_name); + if(lpid < 0) + continue; + snprintf(buf, sizeof(buf), "/proc/%ld/stat", lpid); + fp = fopen(buf, "r"); + + if (fp) { + if ( (fscanf(fp, "%ld (%[^)]) %c", &pid, pname, &state)) != 3 ){ + printf("fscanf failed, assuming emulator running\n"); + fclose(fp); + closedir(dir); + return 1; + } + if (!strcmp(pname, name)) { + fclose(fp); + closedir(dir); + return 1; + } + fclose(fp); + } + } + + closedir(dir); + return 0; +} + int main(int argc, char *argv[]) { uint32_t test_size = 512 * SIZE_KILO, cur_loop = 0; + if (check_emulator()) { + printf("PiStorm emulator running, please stop this before running buptest\n"); + return 1; + } clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &f2); srand((unsigned int)f2.tv_nsec); diff --git a/nprog.sh b/nprog.sh index adbe1eb..d865d57 100755 --- a/nprog.sh +++ b/nprog.sh @@ -1 +1,15 @@ -sudo openocd -f ./nprog/68new.cfg +if pgrep -x "emulator" > /dev/null +then + echo "PiStorm emulator is running, please stop it first" + exit 1 +fi +echo "Flashing..." +sudo openocd -f ./nprog/68new.cfg > nprog_log.txt 2>&1 +if [ $? -ne 0 ] +then + echo "Flashing failed, please see nprog_log.txt for details" + exit 1 +else + echo "Flashing successful!" +fi + diff --git a/nprog_240.sh b/nprog_240.sh index 2d2ec30..2f45515 100755 --- a/nprog_240.sh +++ b/nprog_240.sh @@ -1 +1,15 @@ -sudo openocd -f ./nprog/68_240.cfg +if pgrep -x "emulator" > /dev/null +then + echo "PiStorm emulator is running, please stop it first" + exit 1 +fi +echo "Flashing..." +sudo openocd -f ./nprog/68_240.cfg > nprog_log.txt 2>&1 +if [ $? -ne 0 ] +then + echo "Flashing failed, please see nprog_log.txt for details" + exit 1 +else + echo "Flashing successful!" +fi + diff --git a/nprog_240_experimental.sh b/nprog_240_experimental.sh index 69c3b94..202b521 100755 --- a/nprog_240_experimental.sh +++ b/nprog_240_experimental.sh @@ -1 +1,15 @@ -sudo openocd -f ./nprog/68_240_experimental.cfg +if pgrep -x "emulator" > /dev/null +then + echo "PiStorm emulator is running, please stop it first" + exit 1 +fi +echo "Flashing..." +sudo openocd -f ./nprog/68_240_experimental.cfg > nprog_log.txt 2>&1 +if [ $? -ne 0 ] +then + echo "Flashing failed, please see nprog_log.txt for details" + exit 1 +else + echo "Flashing successful!" +fi + diff --git a/nprog_experimental.sh b/nprog_experimental.sh index e08519b..b78a4ef 100755 --- a/nprog_experimental.sh +++ b/nprog_experimental.sh @@ -1 +1,15 @@ -sudo openocd -f ./nprog/68new_experimental.cfg +if pgrep -x "emulator" > /dev/null +then + echo "PiStorm emulator is running, please stop it first" + exit 1 +fi +echo "Flashing..." +sudo openocd -f ./nprog/68new_experimental.cfg > nprog_log.txt 2>&1 +if [ $? -ne 0 ] +then + echo "Flashing failed, please see nprog_log.txt for details" + exit 1 +else + echo "Flashing successful!" +fi +