| # apebs = # wlar, wlar[vtblpnum1].status = free, wlar[vtblpnum2] = wl-entry(m1, used), wlar[vtblpnum1] = wl-entry(m0, free), apebs[vtblpnum2] = mkpeb(aehdr, avhdr0, buf1, m2, false), apebs = apebs, apebs1 = apebs, apebs2 = apebs, buf0 = copy(apebs[vtblpnum2].data, 0, mkbuf(LEB_SIZE), 0, LEB_SIZE), m3 = avhdr0.leb, n2 = n2, n3 = LEB_SIZE, n4 = vtblpnum1, q = q, q1 = q, q2 = q, v0 = avhdr0.vol, vols = vols, vols1 = vols, vols2 = vols, vtblpnum3 = n2, wlar0 = wlar, vtblpnum2 < # wlar, vtblpnum1 < # wlar, bflipset-cons(bflipset0, wlar), is-aligned(LEB_SIZE, EB_PAGE_SIZE), ubi-cons(apebs, vols, wlar, q, bflipset0, n2, n1), ubi-io-inv(apebs), ubi-io-peb-inv(mkpeb(aehdr, avhdr0, buf1, m2, false)), unique-sqns(apebs), valid-ebatbl(apebs, wlar, vols, n2), valid-eraseq(q), valid-eraseq(wlar, q), valid-eraseq(apebs, q), valid-global-sqn(apebs, n1), valid-vtbl(apebs, vols, wlar, n2), valid-wl(apebs, wlar), m1 + WL_THRESHOLD ≤ m0, LEB_SIZE ≤ # copy(apebs[vtblpnum2].data, 0, mkbuf(LEB_SIZE), 0, LEB_SIZE), LEB_SIZE ≤ LEB_SIZE, avhdr0.vol ∈ vols ∧ avhdr0.leb < # vols[avhdr0.vol] ∨ avhdr0.vol = VTBL_VOLID ∧ avhdr0.leb = VTBL_LNUM ⊦ [ubi_atomic_leb_change# (avhdr0.vol, avhdr0.leb, vtblpnum1, LEB_SIZE, copy(apebs[vtblpnum2].data, 0, mkbuf(LEB_SIZE), 0, LEB_SIZE), EB_PAGE_SIZE ; vols, wlar, q, bflipset0, n2, n1, apebs ; err0)] ( (err0 = ESUCCESS ∨ ⌊err0⌋ ) ∧ id○(apebs, apebs2, n4) ∧ ubi-io-inv(apebs) ∧ # apebs = # wlar ∧ unique-sqns(apebs) ∧ valid-global-sqn(apebs, n1) ∧ valid-wl(apebs, wlar) ∧ valid-eraseq(q) ∧ valid-eraseq(wlar, q) ∧ valid-eraseq(apebs, q) ∧ ¬ VTBL_VOLID ∈ vols ∧ bflipset-cons(bflipset0, wlar) ∧ ( v0 ∈ vols2 ∨ is-encoded(to-vtbl(vols2), subarray(buf0, 0, n3)) ∧ n3 = LEB_SIZE ∨ err0 ≠ ESUCCESS → valid-ebatbl(apebs, wlar, vols, n2) ∧ valid-vtbl(apebs, vols, wlar, n2)) ∧ ( err0 = ESUCCESS ∧ v0 = VTBL_VOLID ∧ m3 = VTBL_LNUM → (∀ v0, m0. ¬ v0 ∈ vols2 ∧ is-encoded(to-vtbl(vols2)[v0, m0], subarray(buf0, 0, n3)) ∧ n3 = LEB_SIZE → valid-ebatbl(apebs, wlar, vols[v0, fill(mkebatbl(m0), unmapped)], n2) ∧ valid-vtbl(apebs, vols[v0, fill(mkebatbl(m0), unmapped)], wlar, n2))) ∧ (err0 = ESUCCESS ∧ v0 ∈ vols2 ∧ vols2[v0][m3] ≠ unmapped → q = q2 + eq-entry(vols2[v0][m3].pnum, v0 × m3)) ∧ (err0 = ESUCCESS ∧ v0 = VTBL_VOLID ∧ m3 = VTBL_LNUM → q = q2 + eq-entry(vtblpnum3, v0 × m3)) ∧ id(apebs, apebs2, mapped-pebs(vols2)) ∧ (v0 = VTBL_VOLID ∧ m3 = VTBL_LNUM ∨ err0 ≠ ESUCCESS → vols = vols2) ∧ (v0 ∈ vols2 ∧ err0 = ESUCCESS → vols = vols2[v0, vols2[v0][m3, ⌜n4⌝ ]]) ∧ ( err0 = ESUCCESS → apebs[n4].fill = align↑(datasize(buf0, n3), EB_PAGE_SIZE) ∧ apebs[n4].data = subarray(buf0, 0, n3) + mkempbuf(LEB_SIZE - n3) ∧ q.lebrefs ⊆ q2.lebrefs ++ (v0 × m3)) ∧ (err0 ≠ ESUCCESS → q.lebrefs = q2.lebrefs) → [if err0 ≠ ESUCCESS then debug#("ubi: wear-leveling of PEB " + vtblpnum2.toString + " to PEB " + vtblpnum1.toString + " failed"); if err0 = ESUCCESS then {ubi_erase_worker_helper#(vtblpnum2; wlar, apebs; err0); if err0 = ESUCCESS then q := q.butlast}] ( # apebs = # wlar ∧ unique-sqns(apebs) ∧ valid-global-sqn(apebs, n1) ∧ valid-wl(apebs, wlar) ∧ valid-eraseq(q) ∧ valid-eraseq(wlar, q) ∧ valid-eraseq(apebs, q) ∧ ¬ VTBL_VOLID ∈ vols ∧ bflipset-cons(bflipset0, wlar) ∧ valid-ebatbl(apebs, wlar, vols, n2) ∧ valid-vtbl(apebs, vols, wlar, n2) ∧ ubi-io-inv(apebs) ∧ ( vols1 = vols ∧ id(apebs, apebs1, mapped-pebs(vols)) ∧ q.lebrefs ⊆ q1.lebrefs ++ (VTBL_VOLID × VTBL_LNUM) ∨ (∃ v, m, n. v ∈ vols1 ∧ m < # vols1[v] ∧ vols1[v][m] ≠ unmapped ∧ vols = vols1[v, vols1[v][m, ⌜n⌝ ]] ∧ id(apebs, apebs1, mapped-pebs(vols1) -- vols1[v][m].pnum) ∧ apebs[n].data = apebs1[vols1[v][m].pnum].data ∧ apebs[n].fill ≤ apebs1[vols1[v][m].pnum].fill ∧ q.lebrefs ⊆ q1.lebrefs ++ (v × m))) → err0 = ESUCCESS → Δ wlar < Δ wlar0)), VTBL_VOLID ∈ vols, avhdr0.vol = VTBL_VOLID ∧ avhdr0.leb = VTBL_LNUM |
# apebs = # wlar, wlar[vtblpnum2] = wl-entry(m1, used), wlar[vtblpnum1] = wl-entry(m0, free), apebs[vtblpnum2] = mkpeb(aehdr, avhdr0, buf1, m2, false), apebs1 = apebs, q1 = q, vols1 = vols, vtblpnum3 = n2, wlar0 = wlar, avhdr0.leb < # vols[avhdr0.vol], vtblpnum2 < # wlar, vtblpnum1 < # wlar, bflipset-cons(bflipset0, wlar), is-aligned(LEB_SIZE, EB_PAGE_SIZE), ubi-io-inv(apebs), ubi-io-peb-inv(mkpeb(aehdr, avhdr0, buf1, m2, false)), unique-sqns(apebs), valid-ebatbl(apebs, wlar, vols, n2), valid-eraseq(q), valid-eraseq(wlar, q), valid-eraseq(apebs, q), valid-global-sqn(apebs, n1), valid-vtbl(apebs, vols, wlar, n2), valid-wl(apebs, wlar), avhdr0.vol ∈ vols, m1 + WL_THRESHOLD ≤ m0, ¬ VTBL_VOLID ∈ vols ⊦ [ubi_atomic_leb_change# (avhdr0.vol, avhdr0.leb, vtblpnum1, LEB_SIZE, copy(apebs[vtblpnum2].data, 0, mkbuf(LEB_SIZE), 0, LEB_SIZE), EB_PAGE_SIZE ; vols, wlar, q, bflipset0, n2, n1, apebs ; err0)] ( (err0 = ESUCCESS ∨ ⌊err0⌋ ) ∧ id○(apebs, apebs1, vtblpnum1) ∧ ubi-io-inv(apebs) ∧ # apebs = # wlar ∧ unique-sqns(apebs) ∧ valid-global-sqn(apebs, n1) ∧ valid-wl(apebs, wlar) ∧ valid-eraseq(q) ∧ valid-eraseq(wlar, q) ∧ valid-eraseq(apebs, q) ∧ ¬ VTBL_VOLID ∈ vols ∧ bflipset-cons(bflipset0, wlar) ∧ ( avhdr0.vol ∈ vols1 ∨ is-encoded(to-vtbl(vols1), buf1) ∨ err0 ≠ ESUCCESS → valid-ebatbl(apebs, wlar, vols, n2) ∧ valid-vtbl(apebs, vols, wlar, n2)) ∧ ( err0 = ESUCCESS ∧ avhdr0.vol = VTBL_VOLID ∧ avhdr0.leb = VTBL_LNUM → (∀ v, m. ¬ v ∈ vols1 ∧ is-encoded(to-vtbl(vols1)[v, m], buf1) → valid-ebatbl(apebs, wlar, vols[v, fill(mkebatbl(m), unmapped)], n2) ∧ valid-vtbl(apebs, vols[v, fill(mkebatbl(m), unmapped)], wlar, n2))) ∧ ( err0 = ESUCCESS ∧ avhdr0.vol ∈ vols1 ∧ vols1[avhdr0.vol][avhdr0.leb] ≠ unmapped → q = q1 + eq-entry(vols1[avhdr0.vol][avhdr0.leb].pnum, avhdr0.vol × avhdr0.leb) ') ∧ (err0 = ESUCCESS ∧ avhdr0.vol = VTBL_VOLID ∧ avhdr0.leb = VTBL_LNUM → q = q1 + eq-entry(vtblpnum3, avhdr0.vol × avhdr0.leb) ') ∧ id(apebs, apebs1, mapped-pebs(vols1)) ∧ (avhdr0.vol = VTBL_VOLID ∧ avhdr0.leb = VTBL_LNUM ∨ err0 ≠ ESUCCESS → vols = vols1) ∧ (avhdr0.vol ∈ vols1 ∧ err0 = ESUCCESS → vols = vols1[avhdr0.vol, vols1[avhdr0.vol][avhdr0.leb, ⌜vtblpnum1⌝ ]]) ∧ ( err0 = ESUCCESS → apebs[vtblpnum1].fill = align↑(datasize(apebs[vtblpnum1].data, LEB_SIZE), EB_PAGE_SIZE) ∧ apebs[vtblpnum1].data = buf1 ∧ q.lebrefs ⊆ q1.lebrefs ++ (avhdr0.vol × avhdr0.leb)) ∧ (err0 ≠ ESUCCESS → q.lebrefs = q1.lebrefs) → [if err0 ≠ ESUCCESS then debug#("ubi: wear-leveling of PEB " + vtblpnum2.toString + " to PEB " + vtblpnum1.toString + " failed"); if err0 = ESUCCESS then {ubi_erase_worker_helper#(vtblpnum2; wlar, apebs; err0); if err0 = ESUCCESS then q := q.butlast}] ( # apebs = # wlar ∧ unique-sqns(apebs) ∧ valid-global-sqn(apebs, n1) ∧ valid-wl(apebs, wlar) ∧ valid-eraseq(q) ∧ valid-eraseq(wlar, q) ∧ valid-eraseq(apebs, q) ∧ bflipset-cons(bflipset0, wlar) ∧ valid-ebatbl(apebs, wlar, vols, n2) ∧ valid-vtbl(apebs, vols, wlar, n2) ∧ ubi-io-inv(apebs) ∧ ( vols1 = vols ∧ id(apebs, apebs1, mapped-pebs(vols)) ∧ q.lebrefs ⊆ q1.lebrefs ++ (VTBL_VOLID × VTBL_LNUM) ∨ (∃ v, m, n. v ∈ vols1 ∧ m < # vols1[v] ∧ vols1[v][m] ≠ unmapped ∧ vols = vols1[v, vols1[v][m, ⌜n⌝ ]] ∧ id(apebs, apebs1, mapped-pebs(vols1) -- vols1[v][m].pnum) ∧ apebs[n].data = apebs1[vols1[v][m].pnum].data ∧ apebs[n].fill ≤ apebs1[vols1[v][m].pnum].fill ∧ q.lebrefs ⊆ q1.lebrefs ++ (v × m))) → err0 = ESUCCESS → Δ wlar < Δ wlar0)), avhdr0.vol = VTBL_VOLID ∧ avhdr0.leb = VTBL_LNUM
Used simplifier rules: # buf = n ⊦ subarray(buf, 0, n) = buf; (s)% ⊦ m < n → n ≠ 0; (s)% ⊦ wl-entry(m, stat).status = stat; (s)%f: ⊦ m < n → n ≠ 0; (forward) from specification nat-basic%append-a: ⊦ (buf + buf0) + buf1 = buf + buf0 + buf1; from specification array-splice[buffer]% ⊦ buf + mkempbuf(0) = buf; (s)% ⊦ m - m = 0; (s)% ⊦ q + eqent = q + eqent '; (s)%⊦ ubi-cons(apebs, vols, wlar, q, bflipset, n0, n1) ↔ # apebs = # wlar ∧ unique-sqns(apebs) ∧ valid-global-sqn(apebs, n1) ∧ valid-wl(apebs, wlar) ∧ valid-eraseq(q) ∧ valid-eraseq(wlar, q) ∧ valid-eraseq(apebs, q) ∧ ¬ VTBL_VOLID ∈ vols ∧ bflipset-cons(bflipset, wlar) ∧ valid-ebatbl(apebs, wlar, vols, n0) ∧ valid-vtbl(apebs, vols, wlar, n0); (s)% ⊦ m ≤ m; (s)%# buf = m, # buf0 = m ⊦ copy(buf, 0, buf0, 0, m) = buf; (s)% ⊦ # mkbuf(n) = n; (s)%⊦ ubi-io-peb-inv(mkpeb(aehdr, avhdr, buf, n, boolvar)) → # buf = LEB_SIZE; (s)% ⊦ mkpeb(aehdr, avhdr, buf, m, boolvar).data = buf; (s)