Skip to content

Commit

Permalink
Changes for device firmware support.
Browse files Browse the repository at this point in the history
  • Loading branch information
OtherCrashOverride committed Jul 21, 2018
1 parent a0dfe3c commit 71dd56d
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 8 deletions.
33 changes: 29 additions & 4 deletions components/prboom-esp32-compat/i_system.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,14 +175,23 @@ typedef struct {
} FileDesc;

static FileDesc fds[32];
static size_t partition_address;

int I_Open(const char *wad, int flags) {
int x=3;
while (fds[x].part!=NULL) x++;
//if (strcmp(wad, "DOOM1.WAD")==0) {
fds[x].part=esp_partition_find_first(66, 6, NULL);
const esp_partition_t* partition = esp_partition_find_first(ESP_PARTITION_TYPE_APP,
ESP_PARTITION_SUBTYPE_APP_OTA_1, NULL);
if (partition == NULL)
{
printf("partition not found.\n");
abort();
}
partition_address = partition->address;
fds[x].part=0;
fds[x].offset=0;
fds[x].size=fds[x].part->size;
fds[x].size=0x400000; //fds[x].part->size;
// } else {
// lprintf(LO_INFO, "I_Open: open %s failed\n", wad);
// return -1;
Expand Down Expand Up @@ -273,11 +282,27 @@ void *I_Mmap(void *addr, size_t length, int prot, int flags, int ifd, off_t offs
i=getFreeHandle();

//lprintf(LO_INFO, "I_Mmap: mmaping offset %d size %d handle %d\n", (int)offset, (int)length, i);
err=esp_partition_mmap(fds[ifd].part, offset, length, SPI_FLASH_MMAP_DATA, (const void**)&retaddr, &mmapHandle[i].handle);
//err=esp_partition_mmap(fds[ifd].part, offset, length, SPI_FLASH_MMAP_DATA, (const void**)&retaddr, &mmapHandle[i].handle);

size_t phys_addr = partition_address + offset;
// offset within 64kB block
size_t region_offset = phys_addr & 0xffff;
size_t mmap_addr = phys_addr & 0xffff0000;
err = spi_flash_mmap(mmap_addr, length+region_offset, SPI_FLASH_MMAP_DATA, (const void**)&retaddr, &mmapHandle[i].handle);
// adjust returned pointer to point to the correct offset
if (err == ESP_OK) {
retaddr = (void*) (((ptrdiff_t) retaddr) + region_offset);
}

if (err==ESP_ERR_NO_MEM) {
lprintf(LO_ERROR, "I_Mmap: No free address space. Cleaning up unused cached mmaps...\n");
freeUnusedMmaps();
err=esp_partition_mmap(fds[ifd].part, offset, length, SPI_FLASH_MMAP_DATA, (const void**)&retaddr, &mmapHandle[i].handle);
//err=esp_partition_mmap(fds[ifd].part, offset, length, SPI_FLASH_MMAP_DATA, (const void**)&retaddr, &mmapHandle[i].handle);
err = spi_flash_mmap(mmap_addr, length+region_offset, SPI_FLASH_MMAP_DATA, (const void**)&retaddr, &mmapHandle[i].handle);
// adjust returned pointer to point to the correct offset
if (err == ESP_OK) {
retaddr = (void*) (((ptrdiff_t) retaddr) + region_offset);
}
}
mmapHandle[i].addr=retaddr;
mmapHandle[i].len=length;
Expand Down
Binary file added doom1-cut.wad00
Binary file not shown.
Binary file added doom1-cut.wad01
Binary file not shown.
2 changes: 2 additions & 0 deletions flashapp.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
. ${IDF_PATH}/add_path.sh
esptool.py --chip esp32 --port "/dev/ttyUSB0" --baud 921600 write_flash -fs detect --flash_freq 40m --flash_mode qio 0x100000 build/esp32-doom.bin
2 changes: 1 addition & 1 deletion flashwad.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash
. ${IDF_PATH}/add_path.sh
esptool.py --chip esp32 --port "/dev/ttyUSB0" --baud $((921600/2)) --before default_reset --after hard_reset write_flash --flash_mode dio --flash_freq 40m --flash_size detect 0x100000 "$1"
esptool.py --chip esp32 --port "/dev/ttyUSB0" --baud $((921600/2)) --before default_reset --after hard_reset write_flash --flash_mode dio --flash_freq 40m --flash_size detect 0x300000 doom1-cut.wad
15 changes: 12 additions & 3 deletions partitions.csv
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Espressif ESP32 Partition Table
# Name, Type, SubType, Offset, Size
factory, app, factory, 0x10000, 928k
wifidata,data, nvs, 0xFC000, 16K
wad, 66, 6, 0x100000, 15M
nvs, data, nvs, 0x9000, 0x4000
otadata, data, ota, 0xd000, 0x2000
phy_init, data, phy, 0xf000, 0x1000
firmware, app, factory, 0x10000, 0x0F0000
app_0, 0, ota_0, 0x100000, 0x200000
app_1, 0, ota_1, 0x300000, 0x200000
app_2, 0, ota_2, 0x500000, 0x200000
app_3, 0, ota_3, 0x700000, 0x200000
app_4, 0, ota_4, 0x900000, 0x200000
app_5, 0, ota_5, 0xb00000, 0x200000
app_6, 0, ota_6, 0xd00000, 0x200000
storage, data, spiffs, 0xf00000, 0x100000

0 comments on commit 71dd56d

Please sign in to comment.