The Flash library gives applications the ability to erase and program flash from applications. This library calls into ROM functions, so an application could program and erase a sector of flash while running from another flash area.
The Flash sample application demonstrates how to erase and program the flash.