• Home
  • Raw
  • Download

Lines Matching refs:ubi

16 static inline unsigned long *init_seen(struct ubi_device *ubi)  in init_seen()  argument
20 if (!ubi_dbg_chk_fastmap(ubi)) in init_seen()
23 ret = kcalloc(BITS_TO_LONGS(ubi->peb_count), sizeof(unsigned long), in init_seen()
46 static inline void set_seen(struct ubi_device *ubi, int pnum, unsigned long *seen) in set_seen() argument
48 if (!ubi_dbg_chk_fastmap(ubi) || !seen) in set_seen()
59 static int self_check_seen(struct ubi_device *ubi, unsigned long *seen) in self_check_seen() argument
63 if (!ubi_dbg_chk_fastmap(ubi) || !seen) in self_check_seen()
66 for (pnum = 0; pnum < ubi->peb_count; pnum++) { in self_check_seen()
67 if (!test_bit(pnum, seen) && ubi->lookuptbl[pnum]) { in self_check_seen()
68 ubi_err(ubi, "self-check failed for PEB %d, fastmap didn't see it", pnum); in self_check_seen()
80 size_t ubi_calc_fm_size(struct ubi_device *ubi) in ubi_calc_fm_size() argument
88 (ubi->peb_count * sizeof(struct ubi_fm_ec)) + in ubi_calc_fm_size()
90 (ubi->peb_count * sizeof(__be32))) + in ubi_calc_fm_size()
92 return roundup(size, ubi->leb_size); in ubi_calc_fm_size()
104 static struct ubi_vid_io_buf *new_fm_vbuf(struct ubi_device *ubi, int vol_id) in new_fm_vbuf() argument
109 new = ubi_alloc_vid_buf(ubi, GFP_KERNEL); in new_fm_vbuf()
242 static int update_vol(struct ubi_device *ubi, struct ubi_attach_info *ai, in update_vol() argument
274 cmp_res = ubi_compare_lebs(ubi, aeb, new_aeb->pnum, new_vh); in update_vol()
336 static int process_pool_aeb(struct ubi_device *ubi, struct ubi_attach_info *ai, in process_pool_aeb() argument
352 ubi_err(ubi, "orphaned volume in fastmap pool!"); in process_pool_aeb()
359 return update_vol(ubi, ai, av, new_vh, new_aeb); in process_pool_aeb()
400 static int scan_pool(struct ubi_device *ubi, struct ubi_attach_info *ai, in scan_pool() argument
410 ech = kzalloc(ubi->ec_hdr_alsize, GFP_KERNEL); in scan_pool()
414 vb = ubi_alloc_vid_buf(ubi, GFP_KERNEL); in scan_pool()
434 if (ubi_io_is_bad(ubi, pnum)) { in scan_pool()
435 ubi_err(ubi, "bad PEB in fastmap pool!"); in scan_pool()
440 err = ubi_io_read_ec_hdr(ubi, pnum, ech, 0); in scan_pool()
442 ubi_err(ubi, "unable to read EC header! PEB:%i err:%i", in scan_pool()
455 if (image_seq && (image_seq != ubi->image_seq)) { in scan_pool()
456 ubi_err(ubi, "bad image seq: 0x%x, expected: 0x%x", in scan_pool()
457 be32_to_cpu(ech->image_seq), ubi->image_seq); in scan_pool()
462 err = ubi_io_read_vid_hdr(ubi, pnum, vb, 0); in scan_pool()
495 err = process_pool_aeb(ubi, ai, vh, new_aeb); in scan_pool()
502 ubi_err(ubi, "fastmap pool PEBs contains damaged PEBs!"); in scan_pool()
548 static int ubi_attach_fastmap(struct ubi_device *ubi, in ubi_attach_fastmap() argument
562 size_t fm_pos = 0, fm_size = ubi->fm_size; in ubi_attach_fastmap()
564 void *fm_raw = ubi->fm_buf; in ubi_attach_fastmap()
582 ubi_err(ubi, "bad fastmap header magic: 0x%x, expected: 0x%x", in ubi_attach_fastmap()
592 ubi_err(ubi, "bad fastmap pool magic: 0x%x, expected: 0x%x", in ubi_attach_fastmap()
602 ubi_err(ubi, "bad fastmap WL pool magic: 0x%x, expected: 0x%x", in ubi_attach_fastmap()
613 ubi_err(ubi, "bad pool size: %i", pool_size); in ubi_attach_fastmap()
618 ubi_err(ubi, "bad WL pool size: %i", wl_pool_size); in ubi_attach_fastmap()
625 ubi_err(ubi, "bad maximal pool size: %i", fm->max_pool_size); in ubi_attach_fastmap()
631 ubi_err(ubi, "bad maximal WL pool size: %i", in ubi_attach_fastmap()
699 ubi_err(ubi, "bad fastmap vol header magic: 0x%x, expected: 0x%x", in ubi_attach_fastmap()
712 ubi_err(ubi, "volume (ID %i) already exists", in ubi_attach_fastmap()
729 ubi_err(ubi, "bad fastmap EBA header magic: 0x%x, expected: 0x%x", in ubi_attach_fastmap()
749 ubi_err(ubi, "PEB %i is in EBA but not in used list", pnum); in ubi_attach_fastmap()
765 ret = scan_pool(ubi, ai, fmpl->pebs, pool_size, &max_sqnum, &free); in ubi_attach_fastmap()
769 ret = scan_pool(ubi, ai, fmpl_wl->pebs, wl_pool_size, &max_sqnum, &free); in ubi_attach_fastmap()
790 if (WARN_ON(count_fastmap_pebs(ai) != ubi->peb_count - in ubi_attach_fastmap()
842 int ubi_scan_fastmap(struct ubi_device *ubi, struct ubi_attach_info *ai, in ubi_scan_fastmap() argument
867 down_write(&ubi->fm_protect); in ubi_scan_fastmap()
868 memset(ubi->fm_buf, 0, ubi->fm_size); in ubi_scan_fastmap()
883 ret = ubi_io_read_data(ubi, fmsb, fm_anchor, 0, sizeof(*fmsb)); in ubi_scan_fastmap()
890 ubi_err(ubi, "bad super block magic: 0x%x, expected: 0x%x", in ubi_scan_fastmap()
897 ubi_err(ubi, "bad fastmap version: %i, expected: %i", in ubi_scan_fastmap()
905 ubi_err(ubi, "number of fastmap blocks is invalid: %i", in ubi_scan_fastmap()
911 fm_size = ubi->leb_size * used_blocks; in ubi_scan_fastmap()
912 if (fm_size != ubi->fm_size) { in ubi_scan_fastmap()
913 ubi_err(ubi, "bad fastmap size: %zi, expected: %zi", in ubi_scan_fastmap()
914 fm_size, ubi->fm_size); in ubi_scan_fastmap()
919 ech = kzalloc(ubi->ec_hdr_alsize, GFP_KERNEL); in ubi_scan_fastmap()
925 vb = ubi_alloc_vid_buf(ubi, GFP_KERNEL); in ubi_scan_fastmap()
938 if (ubi_io_is_bad(ubi, pnum)) { in ubi_scan_fastmap()
944 ubi_err(ubi, "Fastmap anchor PEB mismatch: PEB: %i vs. %i", in ubi_scan_fastmap()
950 ret = ubi_io_read_ec_hdr(ubi, pnum, ech, 0); in ubi_scan_fastmap()
952 ubi_err(ubi, "unable to read fastmap block# %i EC (PEB: %i)", in ubi_scan_fastmap()
961 if (!ubi->image_seq) in ubi_scan_fastmap()
962 ubi->image_seq = image_seq; in ubi_scan_fastmap()
968 if (image_seq && (image_seq != ubi->image_seq)) { in ubi_scan_fastmap()
969 ubi_err(ubi, "wrong image seq:%d instead of %d", in ubi_scan_fastmap()
970 be32_to_cpu(ech->image_seq), ubi->image_seq); in ubi_scan_fastmap()
975 ret = ubi_io_read_vid_hdr(ubi, pnum, vb, 0); in ubi_scan_fastmap()
977 ubi_err(ubi, "unable to read fastmap block# %i (PEB: %i)", in ubi_scan_fastmap()
984 ubi_err(ubi, "bad fastmap anchor vol_id: 0x%x, expected: 0x%x", in ubi_scan_fastmap()
992 ubi_err(ubi, "bad fastmap data vol_id: 0x%x, expected: 0x%x", in ubi_scan_fastmap()
1003 ret = ubi_io_read_data(ubi, ubi->fm_buf + (ubi->leb_size * i), in ubi_scan_fastmap()
1004 pnum, 0, ubi->leb_size); in ubi_scan_fastmap()
1006 ubi_err(ubi, "unable to read fastmap block# %i (PEB: %i, " in ubi_scan_fastmap()
1026 fmsb2 = (struct ubi_fm_sb *)(ubi->fm_buf); in ubi_scan_fastmap()
1029 crc = crc32(UBI_CRC32_INIT, ubi->fm_buf, fm_size); in ubi_scan_fastmap()
1031 ubi_err(ubi, "fastmap data CRC is invalid"); in ubi_scan_fastmap()
1032 ubi_err(ubi, "CRC should be: 0x%x, calc: 0x%x", in ubi_scan_fastmap()
1042 ret = ubi_attach_fastmap(ubi, ai, fm); in ubi_scan_fastmap()
1066 ubi->fm = fm; in ubi_scan_fastmap()
1067 ubi->fm_pool.max_size = ubi->fm->max_pool_size; in ubi_scan_fastmap()
1068 ubi->fm_wl_pool.max_size = ubi->fm->max_wl_pool_size; in ubi_scan_fastmap()
1069 ubi_msg(ubi, "attached by fastmap"); in ubi_scan_fastmap()
1070 ubi_msg(ubi, "fastmap pool size: %d", ubi->fm_pool.max_size); in ubi_scan_fastmap()
1071 ubi_msg(ubi, "fastmap WL pool size: %d", in ubi_scan_fastmap()
1072 ubi->fm_wl_pool.max_size); in ubi_scan_fastmap()
1073 ubi->fm_disabled = 0; in ubi_scan_fastmap()
1074 ubi->fast_attach = 1; in ubi_scan_fastmap()
1079 up_write(&ubi->fm_protect); in ubi_scan_fastmap()
1081 ubi_err(ubi, "Attach by fastmap failed, doing a full scan!"); in ubi_scan_fastmap()
1095 struct ubi_device *ubi = vol->ubi; in ubi_fastmap_init_checkmap() local
1097 if (!ubi->fast_attach) in ubi_fastmap_init_checkmap()
1120 static int ubi_write_fastmap(struct ubi_device *ubi, in ubi_write_fastmap() argument
1141 fm_raw = ubi->fm_buf; in ubi_write_fastmap()
1142 memset(ubi->fm_buf, 0, ubi->fm_size); in ubi_write_fastmap()
1144 avbuf = new_fm_vbuf(ubi, UBI_FM_SB_VOLUME_ID); in ubi_write_fastmap()
1150 dvbuf = new_fm_vbuf(ubi, UBI_FM_DATA_VOLUME_ID); in ubi_write_fastmap()
1159 seen_pebs = init_seen(ubi); in ubi_write_fastmap()
1165 spin_lock(&ubi->volumes_lock); in ubi_write_fastmap()
1166 spin_lock(&ubi->wl_lock); in ubi_write_fastmap()
1170 ubi_assert(fm_pos <= ubi->fm_size); in ubi_write_fastmap()
1174 ubi_assert(fm_pos <= ubi->fm_size); in ubi_write_fastmap()
1192 fmpl->size = cpu_to_be16(ubi->fm_pool.size); in ubi_write_fastmap()
1193 fmpl->max_size = cpu_to_be16(ubi->fm_pool.max_size); in ubi_write_fastmap()
1195 for (i = 0; i < ubi->fm_pool.size; i++) { in ubi_write_fastmap()
1196 fmpl->pebs[i] = cpu_to_be32(ubi->fm_pool.pebs[i]); in ubi_write_fastmap()
1197 set_seen(ubi, ubi->fm_pool.pebs[i], seen_pebs); in ubi_write_fastmap()
1203 fmpl_wl->size = cpu_to_be16(ubi->fm_wl_pool.size); in ubi_write_fastmap()
1204 fmpl_wl->max_size = cpu_to_be16(ubi->fm_wl_pool.max_size); in ubi_write_fastmap()
1206 for (i = 0; i < ubi->fm_wl_pool.size; i++) { in ubi_write_fastmap()
1207 fmpl_wl->pebs[i] = cpu_to_be32(ubi->fm_wl_pool.pebs[i]); in ubi_write_fastmap()
1208 set_seen(ubi, ubi->fm_wl_pool.pebs[i], seen_pebs); in ubi_write_fastmap()
1211 ubi_for_each_free_peb(ubi, wl_e, tmp_rb) { in ubi_write_fastmap()
1215 set_seen(ubi, wl_e->pnum, seen_pebs); in ubi_write_fastmap()
1220 ubi_assert(fm_pos <= ubi->fm_size); in ubi_write_fastmap()
1222 if (ubi->fm_next_anchor) { in ubi_write_fastmap()
1225 fec->pnum = cpu_to_be32(ubi->fm_next_anchor->pnum); in ubi_write_fastmap()
1226 set_seen(ubi, ubi->fm_next_anchor->pnum, seen_pebs); in ubi_write_fastmap()
1227 fec->ec = cpu_to_be32(ubi->fm_next_anchor->ec); in ubi_write_fastmap()
1231 ubi_assert(fm_pos <= ubi->fm_size); in ubi_write_fastmap()
1235 ubi_for_each_used_peb(ubi, wl_e, tmp_rb) { in ubi_write_fastmap()
1239 set_seen(ubi, wl_e->pnum, seen_pebs); in ubi_write_fastmap()
1244 ubi_assert(fm_pos <= ubi->fm_size); in ubi_write_fastmap()
1247 ubi_for_each_protected_peb(ubi, i, wl_e) { in ubi_write_fastmap()
1251 set_seen(ubi, wl_e->pnum, seen_pebs); in ubi_write_fastmap()
1256 ubi_assert(fm_pos <= ubi->fm_size); in ubi_write_fastmap()
1260 ubi_for_each_scrub_peb(ubi, wl_e, tmp_rb) { in ubi_write_fastmap()
1264 set_seen(ubi, wl_e->pnum, seen_pebs); in ubi_write_fastmap()
1269 ubi_assert(fm_pos <= ubi->fm_size); in ubi_write_fastmap()
1274 list_for_each_entry(ubi_wrk, &ubi->works, list) { in ubi_write_fastmap()
1282 set_seen(ubi, wl_e->pnum, seen_pebs); in ubi_write_fastmap()
1287 ubi_assert(fm_pos <= ubi->fm_size); in ubi_write_fastmap()
1293 vol = ubi->volumes[i]; in ubi_write_fastmap()
1302 ubi_assert(fm_pos <= ubi->fm_size); in ubi_write_fastmap()
1316 ubi_assert(fm_pos <= ubi->fm_size); in ubi_write_fastmap()
1329 fmh->bad_peb_count = cpu_to_be32(ubi->bad_peb_count); in ubi_write_fastmap()
1331 avhdr->sqnum = cpu_to_be64(ubi_next_sqnum(ubi)); in ubi_write_fastmap()
1334 spin_unlock(&ubi->wl_lock); in ubi_write_fastmap()
1335 spin_unlock(&ubi->volumes_lock); in ubi_write_fastmap()
1338 ret = ubi_io_write_vid_hdr(ubi, new_fm->e[0]->pnum, avbuf); in ubi_write_fastmap()
1340 ubi_err(ubi, "unable to write vid_hdr to fastmap SB!"); in ubi_write_fastmap()
1346 set_seen(ubi, new_fm->e[i]->pnum, seen_pebs); in ubi_write_fastmap()
1352 ubi->fm_size)); in ubi_write_fastmap()
1355 dvhdr->sqnum = cpu_to_be64(ubi_next_sqnum(ubi)); in ubi_write_fastmap()
1359 ret = ubi_io_write_vid_hdr(ubi, new_fm->e[i]->pnum, dvbuf); in ubi_write_fastmap()
1361 ubi_err(ubi, "unable to write vid_hdr to PEB %i!", in ubi_write_fastmap()
1368 ret = ubi_io_write_data(ubi, fm_raw + (i * ubi->leb_size), in ubi_write_fastmap()
1369 new_fm->e[i]->pnum, 0, ubi->leb_size); in ubi_write_fastmap()
1371 ubi_err(ubi, "unable to write fastmap to PEB %i!", in ubi_write_fastmap()
1378 ubi->fm = new_fm; in ubi_write_fastmap()
1380 ret = self_check_seen(ubi, seen_pebs); in ubi_write_fastmap()
1401 static int erase_block(struct ubi_device *ubi, int pnum) in erase_block() argument
1407 ec_hdr = kzalloc(ubi->ec_hdr_alsize, GFP_KERNEL); in erase_block()
1411 ret = ubi_io_read_ec_hdr(ubi, pnum, ec_hdr, 0); in erase_block()
1419 ret = ubi_io_sync_erase(ubi, pnum, 0); in erase_block()
1431 ret = ubi_io_write_ec_hdr(ubi, pnum, ec_hdr); in erase_block()
1453 static int invalidate_fastmap(struct ubi_device *ubi) in invalidate_fastmap() argument
1461 if (!ubi->fm) in invalidate_fastmap()
1464 ubi->fm = NULL; in invalidate_fastmap()
1471 vb = new_fm_vbuf(ubi, UBI_FM_SB_VOLUME_ID); in invalidate_fastmap()
1478 e = ubi_wl_get_fm_peb(ubi, 1); in invalidate_fastmap()
1486 vh->sqnum = cpu_to_be64(ubi_next_sqnum(ubi)); in invalidate_fastmap()
1487 ret = ubi_io_write_vid_hdr(ubi, e->pnum, vb); in invalidate_fastmap()
1489 ubi_wl_put_fm_peb(ubi, e, 0, 0); in invalidate_fastmap()
1496 ubi->fm = fm; in invalidate_fastmap()
1513 static void return_fm_pebs(struct ubi_device *ubi, in return_fm_pebs() argument
1523 ubi_wl_put_fm_peb(ubi, fm->e[i], i, in return_fm_pebs()
1537 int ubi_update_fastmap(struct ubi_device *ubi) in ubi_update_fastmap() argument
1543 down_write(&ubi->fm_protect); in ubi_update_fastmap()
1544 down_write(&ubi->work_sem); in ubi_update_fastmap()
1545 down_write(&ubi->fm_eba_sem); in ubi_update_fastmap()
1547 ubi_refill_pools(ubi); in ubi_update_fastmap()
1549 if (ubi->ro_mode || ubi->fm_disabled) { in ubi_update_fastmap()
1550 up_write(&ubi->fm_eba_sem); in ubi_update_fastmap()
1551 up_write(&ubi->work_sem); in ubi_update_fastmap()
1552 up_write(&ubi->fm_protect); in ubi_update_fastmap()
1558 up_write(&ubi->fm_eba_sem); in ubi_update_fastmap()
1559 up_write(&ubi->work_sem); in ubi_update_fastmap()
1560 up_write(&ubi->fm_protect); in ubi_update_fastmap()
1564 new_fm->used_blocks = ubi->fm_size / ubi->leb_size; in ubi_update_fastmap()
1565 old_fm = ubi->fm; in ubi_update_fastmap()
1566 ubi->fm = NULL; in ubi_update_fastmap()
1569 ubi_err(ubi, "fastmap too large"); in ubi_update_fastmap()
1575 spin_lock(&ubi->wl_lock); in ubi_update_fastmap()
1576 tmp_e = ubi_wl_get_fm_peb(ubi, 0); in ubi_update_fastmap()
1577 spin_unlock(&ubi->wl_lock); in ubi_update_fastmap()
1581 ret = erase_block(ubi, old_fm->e[i]->pnum); in ubi_update_fastmap()
1583 ubi_err(ubi, "could not erase old fastmap PEB"); in ubi_update_fastmap()
1586 ubi_wl_put_fm_peb(ubi, new_fm->e[j], in ubi_update_fastmap()
1595 ubi_err(ubi, "could not get any free erase block"); in ubi_update_fastmap()
1598 ubi_wl_put_fm_peb(ubi, new_fm->e[j], j, 0); in ubi_update_fastmap()
1609 ubi_wl_put_fm_peb(ubi, old_fm->e[i], i, in ubi_update_fastmap()
1619 ubi_wl_put_fm_peb(ubi, old_fm->e[i], i, in ubi_update_fastmap()
1625 spin_lock(&ubi->wl_lock); in ubi_update_fastmap()
1626 tmp_e = ubi->fm_anchor; in ubi_update_fastmap()
1627 ubi->fm_anchor = NULL; in ubi_update_fastmap()
1628 spin_unlock(&ubi->wl_lock); in ubi_update_fastmap()
1633 ret = erase_block(ubi, old_fm->e[0]->pnum); in ubi_update_fastmap()
1635 ubi_err(ubi, "could not erase old anchor PEB"); in ubi_update_fastmap()
1638 ubi_wl_put_fm_peb(ubi, new_fm->e[i], in ubi_update_fastmap()
1649 ubi_wl_put_fm_peb(ubi, old_fm->e[0], 0, in ubi_update_fastmap()
1656 ubi_err(ubi, "could not find any anchor PEB"); in ubi_update_fastmap()
1659 ubi_wl_put_fm_peb(ubi, new_fm->e[i], i, 0); in ubi_update_fastmap()
1669 ret = ubi_write_fastmap(ubi, new_fm); in ubi_update_fastmap()
1675 up_write(&ubi->fm_eba_sem); in ubi_update_fastmap()
1676 up_write(&ubi->work_sem); in ubi_update_fastmap()
1677 up_write(&ubi->fm_protect); in ubi_update_fastmap()
1680 ubi_ensure_anchor_pebs(ubi); in ubi_update_fastmap()
1685 ubi_warn(ubi, "Unable to write new fastmap, err=%i", ret); in ubi_update_fastmap()
1687 ret = invalidate_fastmap(ubi); in ubi_update_fastmap()
1689 ubi_err(ubi, "Unable to invalidate current fastmap!"); in ubi_update_fastmap()
1690 ubi_ro_mode(ubi); in ubi_update_fastmap()
1692 return_fm_pebs(ubi, old_fm); in ubi_update_fastmap()
1693 return_fm_pebs(ubi, new_fm); in ubi_update_fastmap()