esptool.py --port /dev/tty.SLAB_USBtoUART erase_flash
Micropython firmware for esp32 can be downloaded from here
esptool.py --chip esp32 -p /dev/tty.SLAB_USBtoUART write_flash -z 0x1000 /file_path
Micropython firmware for esp8266-12e can be downloaded from here