This is more or less a complete re-organization of the code.
* Use the actual byte size of the .bin file as the flash size,
as the algorithm for packing sections into the flash is complicated
* Match each section to a data region & find the high water mark in the
region
* Report on all the RAM regions, separately
Note that elftools is a requirement of esp-idf and so does not need to
be listed in our requirements.txt.
This detects an overflowed flash partition, such as
```
1452105 bytes used, -10313 bytes free in flash firmware space out of 1441792 bytes (1408.0kB).
444428 bytes used, 1652724 bytes free in ram for stack and heap out of 2097152 bytes (2048.0kB).
```
on a metro esp32-s2 built with debugging.
Unify USB-related makefile var and C def as CIRCUITPY_USB.
Always define it as 0 or 1, same as all other settings.
USB_AVAILABLE was conditionally defined in supervisor.mk,
but never actually used to #ifdef USB-related code.
Loosely related to #4546
As reported by @jerryneedell, this change was incorrect; the given
ESPTOOL_FLAGS caused `write_flash` to be repeated twice, which doesn't
work.
Closes#3981.
Originally, I believed the implementation might be shared with AudioOut,
as on the ESP32 (non-S2) the I2S peripheral was also used to drive the DAC.
However, this is not the case on ESP32-S2 and appears it will not be
the case with the ESP32-S3 or -C3, to the extent that there's skeletal
support for either of them in esp-idf master branch.
However, it could still be shared by I2SIn or PDMIn (the latter being
hypothetically implemented as I2SIn + digital postprocessing like we did
in the atmel-sam port, to my understanding), so I moved it to
the common-hal folder.
This can be useful so that e.g., on a Kaluga when programming via
the FTDI chip, you can override the variable to specify "--after=hard_reset"
to automatically return to running CircuitPython, choose a different
baud rate (921600 is about 2s faster than 460800), etc:
make BOARD=espressif_kaluga_1 ESPTOOL_FLAGS="-b 921600 --before=default_reset --after=hard_reset"
Very long ago, this was apparently not supported in esptool yet, at
least when operating over USB CDC. This now works just fine, and
our esp webtool relies on it as well. It makes flashing faster,
too.