Skip to content

Commit

Permalink
Updated info about espressifs version
Browse files Browse the repository at this point in the history
  • Loading branch information
Ebiroll committed May 11, 2020
1 parent 24480b7 commit bb68057
Show file tree
Hide file tree
Showing 2 changed files with 136 additions and 1 deletion.
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ xtensa-esp32-elf-gdb build/app-template.elf -ex 'target remote:1234'
(gdb) monitor quit
```


## Windows 10

Enable the windows subsystem for linux on Windows 10,
Expand Down Expand Up @@ -124,6 +123,25 @@ Latest version of esp-idf recomends
As location of partition is different for cmake
gcc ../../toflash-cmake.c -o qemu_flash

## Update May 2020
Espressifs implementation is a bit to slow but more accurate.
They have also released a useable rom file.
This shows a way of how to have this version in parallell.
Unless yoou have a really fast computer I do not recomend this version as
it is way too slow. And debugging does not work so well.
To build a parallell qeum_espressif qemu binary with espressifs implementation.
```
cd
git clone https://github.com/Ebiroll/qemu-xtensa-esp32 -b esp-develop esp-develop
mkdir qemu_espressif
cd qemu_espressif
../esp-develop/configure --target-list=xtensa-softmmu --enable-debug --enable-sanitizers --disable-strip --disable-capstone --disable-vnc
make
cp ../esp-develop/pc-bios/esp32-r0-rom.bin .
Make sure you have a usable esp32flash.bin file then start with
xtensa-softmmu/qemu-system-xtensa -nographic -M esp32 -drive file=esp32flash.bin,if=mtd,format=raw -s
```

## Update Nov 2019
Espressif has released a qemu for esp32
https://github.com/espressif/qemu
Expand Down
117 changes: 117 additions & 0 deletions toflash_espressif.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//
// qemu_toflash
//
// python /home/olas/esp/esp-idf/components/esptool_py/esptool/esptool.py --chip esp32 --port /dev/ttyUSB0 --baud 115200 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 40m --flash_size detect
// 0x1000 /home/olas/esp/esp-idf/examples/system/ota/build/bootloader/bootloader.bin
// 0x10000 /home/olas/esp/esp-idf/examples/system/ota/build/ota.bin
// 0x8000 /home/olas/esp/esp-idf/examples/system/ota/build/partitions_two_ota.bin
//

void merge_flash(char *binfile,char *flashfile,int flash_pos,int patch_hash)
{
FILE *fbin;
FILE *fflash;
unsigned char *tmp_data;
int j=0;

int file_size=0;
int flash_size=0;

fbin = fopen(binfile, "rb");
if (fbin == NULL) {
printf(" Can't open '%s' for reading.\n", binfile);
return;
}

if (fseek(fbin, 0 , SEEK_END) != 0) {
printf(" Can't seek end of '%s'.\n", binfile);
/* Handle Error */
}
file_size = ftell(fbin);

if (fseek(fbin, 0 , SEEK_SET) != 0) {
/* Handle Error */
}

fflash = fopen(flashfile, "rb+");
if (fflash == NULL) {
printf(" Can't open '%s' for writing.\n", flashfile);
return;
}
if (fseek(fflash, 0 , SEEK_END) != 0) {
printf(" Can't seek end of '%s'.\n", flashfile);
/* Handle Error */
}
flash_size = ftell(fflash);
rewind(fflash);
fseek(fflash,flash_pos,SEEK_SET);


tmp_data=malloc((1+file_size)*sizeof(char));

if (file_size<=0) {
printf("Not able to get file size %s",binfile);
}

int len_read=fread(tmp_data,sizeof(char),file_size,fbin);

if (patch_hash==1) {
for (j=0;j<33;j++)
{
tmp_data[file_size-j]=0;
}
}


int len_write=fwrite(tmp_data,sizeof(char),file_size,fflash);

if (len_read!=len_write) {
printf("Not able to merge %s, %d bytes read,%d to write,%d file_size\n",binfile,len_read,len_write,file_size);
//while()


}

fclose(fbin);

if (fseek(fflash, 0x3E8000*4 , SEEK_SET) != 0) {
}

fclose(fflash);

free(tmp_data);
}


int main(int argc,char *argv[])
{

if (argc>1) {
if (strcmp(argv[1],"-bl")==0) {
printf("Overwrite bootloader only \n");
merge_flash("build/bootloader/bootloader.bin","esp32flash.bin",0x1000,0);
system("cp esp32flash.bin ~/qemu_espressif");
exit(0);

}
}
// Overwrites esp32flash.bin file

system("dd if=/dev/zero bs=1M count=4 | tr \"\\000\" \"\\377\" > esp32flash.bin");

// Add bootloader
merge_flash("build/bootloader/bootloader.bin","esp32flash.bin",0x1000,0);
// Add partitions,
merge_flash("build/partition_table/partition-table.bin","esp32flash.bin",0x8000,0);
// Add application
if (argc>1) {
merge_flash(argv[1],"esp32flash.bin",0x10000,0);
} else {
merge_flash("build/app-template.bin","esp32flash.bin",0x10000,0);
}
system("cp esp32flash.bin ~/qemu_esp32");
}

0 comments on commit bb68057

Please sign in to comment.