Making MTD Partitions writeable

How to make read-only MTD partitions writable from Linux.
$ cat /proc/mtd
# makes MTD writable
$ echo 0x400 > /sys/class/mtd/mtd4/flags
$ fw_setenv serverip 172.16.11.137
# protects MTD
$ echo 0x800 > /sys/class/mtd/mtd4/flags