nor_erase_prepare(9)
π nor_erase_prepare(9) β like, the kernel API manual bestie β¨
okay so this is a page from the Kernel API Manual (section 9, the kernel-API girlies π) and it's all about nor_erase_prepare. yes it sounds scary. no it's not. sit down, grab a strawberry π, let's go.
β¨ NAME β¨
nor_erase_prepare β prepare a NOR flash PEB for erasure. that's it, that's the whole job. π
πΈ SYNOPSIS πΈ
int nor_erase_prepare (struct ubi_device *ubi , int pnum );
π¦ ARGUMENTS π¦
ubiβ the UBI device description object. like, the whole entire device's ~vibe~ in struct form π«Άpnumβ the physical eraseblock number you're prepping. yes, that PEB. the one you're about to do crimes to π
π₯ DESCRIPTION π₯
okay so here's the tea. NOR flash β or at least some NOR flash β has this genuinely peculiar embedded PEB erasure algorithm. and by peculiar i mean it does the most. π
here's how it goes down: the PEB gets first filled with zeroes, and then it gets erased. and the filling-with-zeroes? it starts from the end of the PEB and works backwards. iconic behaviour, honestly. this exact thing was observed with Spansion S29GL512N NOR flash (put some respect on the name β¨).
so why do we care? because power cuts exist and they're haters. π in case of a power cut, we can end up with:
- intact data at the beginning of the PEB, and
- all zeroes at the end of the PEB
in other words β the EC and VID headers are totally fine β
, but a large chunk of data at the end of the PEB is now straight-up zeroed. and UBI, bless it, gets fooled: it mistakenly treats this PEB as used and associates it with an LEB. which then leads to subsequent failures (e.g., UBIFS fails). not slay. not slay at all. π
so this function is called before erasing NOR PEBs, and what it does is zero out the EC and VID magic numbers to invalidate them and prevent all those failures from happening. it's giving preventative care. it's giving main character energy in a power-cut scenario. π
returns zero in case of success and a negative error code in case of failure. no cap. π₯
β SEE ALSO β
kernel file ./drivers/mtd/ubi/io.c β and the whole friend group:
ubi_io_read(9), ubi_io_write(9), do_sync_erase(9), torture_peb(9), ubi_io_sync_erase(9), ubi_io_is_bad(9), ubi_io_mark_bad(9), validate_ec_hdr(9), ubi_io_read_ec_hdr(9), ubi_io_write_ec_hdr(9), validate_vid_hdr(9), ubi_io_read_vid_hdr(9), ubi_io_write_vid_hdr(9), self_check_not_bad(9), self_check_ec_hdr(9), self_check_peb_ec_hdr(9), self_check_vid_hdr(9), self_check_peb_vid_hdr(9), self_check_write(9), ubi_self_check_all_ff(9)
and that's the whole page bestie π§π go forth and invalidate those magic numbers responsibly.
source: ./drivers/mtd/ubi Β· version/date: October 2026 Β· page: nor_erase_prepare(9) β mwah, bye! πβ¨
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms