sysupgrade -v firmware.img Can't open device for writing!

HI!
My router Tp-Link TD-W8970 v1.2 with flash 16M
u-boot is compiled from https://github.com/GreenTeaDev/u-boot/tree/tdw8970-16m and flashed in flash by the programmer
My modifications are in [mypatch_18.06.1.patch](https://bugs.openwrt.org/index.php?getfile=595)
I downloaded the firmware of my own modification through UART

setenv ipaddr 192.168.1.1
setenv serverip 192.168.1.2
setenv bootargs 'board=WD8970'
tftpboot 0x80800000 openwrt-lantiq-xrx200-tplink_tdw8970-16m-squashfs-sysupgrade-end.bin
sf erase 0x20000 0xfa0000
sf write 0x80800000 0x20000 $(filesize)
reset

When I try to burn the same file, I get an error:

root@OpenWrt:/tmp# sysupgrade  -v firmware.img
Saving config files...
etc/config/ddns
etc/config/dhcp
etc/config/dropbear
etc/config/firewall
etc/config/fstab
etc/config/luci
etc/config/network
etc/config/openvpn_recipes
etc/config/polipo
etc/config/rpcd
etc/config/samba4
etc/config/system
etc/config/ucitrack
etc/config/uhttpd
etc/config/upnpd
etc/config/wireless
etc/dropbear/authorized_keys
etc/dropbear/dropbear_rsa_host_key
etc/group
etc/hosts
etc/inittab
etc/luci-uploads/.placeholder
etc/opkg/keys/1035ac73cc4e59e3
etc/opkg/keys/5151f69420c3f508
etc/opkg/keys/72a57f2191b211e0
etc/opkg/keys/792d9d9b39f180dc
etc/opkg/keys/9a01db7703afac2b
etc/opkg/keys/9ef4694208102c43
etc/opkg/keys/b26f36ae0f4106d
etc/opkg/keys/b5043e70f9a75cde
etc/opkg/keys/c10b9afab19ee428
etc/opkg/keys/dace9d4df16896bf
etc/opkg/keys/dd6de0d06bbd3d85
etc/passwd
etc/profile
etc/rc.local
etc/samba/secrets.tdb
etc/samba/smb.conf
etc/samba/smbpasswd
etc/shadow
etc/shells
etc/sysctl.conf
etc/xattr.conf
Commencing upgrade. Closing all shell sessions.
Watchdog handover: fd=3
- watchdog -
killall: telnetd: no process killed
Sending TERM to remaining processes ... netifd odhcpd uhttpd dbus-daemon avahi-daemon ntpd dnsmasq polipo smbd wsdd2 smbd-notifyd cleanupd br2684ctl vdsl_cpe_contro ubusd logd rpcd
Sending KILL to remaining processes ... smbd
Switching to ramdisk...
Performing system upgrade...
Could not open mtd device: firmware
Could not open mtd device: firmware
Could not open mtd device: firmware
Can't open device for writing!
cat: write error: Broken pipe
sysupgrade aborte[ 1075.782393] reboot: Resâ–’
ROM VER: 1.1.4
CFG 05

What am I doing wrong?
Please, help Me.

Hi. I found the bug on my own. The error occurs due to the conflict between the size of the 'firmware' partition and the size of the erasesize, which is 64k (0x10000). The partition size must be a multiple of the size of the erasesize.
How to reduce the size of the erasesize for a particular partition, for example, to 8192 bytes in sources code?
Thank you in advance.

I cannot comment about your problem report, just wanted to point out that the erasesize is a hardware property of the flash memory. It cannot be chosen freely in source code, it must match the hardware design.

I understand that erasesize size depends on the hardware properties of the flash.
But behind my "firmware" partition, a "uboot-env" partition has been created with a size of only 8192 bytes. And the output of the command cat /proc/mtd shows the size of the erasesize 8192 bytes (0x2000). Command: "mtd erase uboot-env" erases this partition correctly.
That's why I had a question how to change the size of the erasesize of the "firmware" partition.