diff options
author | shengyong <shengyong1@huawei.com> | 2015-05-26 06:07:10 -0400 |
---|---|---|
committer | Richard Weinberger <richard@nod.at> | 2015-06-02 05:47:51 -0400 |
commit | 2848594a20eb179eb591fd2a37d7edfe045811a0 (patch) | |
tree | e7b6f5de3151925ce23862e0a1867432110cd97c | |
parent | e96a8a3bb671ca02370e85993c3f50ee90691b95 (diff) |
UBI: add a helper function for updatting on-flash layout volumes
Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
-rw-r--r-- | drivers/mtd/ubi/vtbl.c | 45 |
1 files changed, 24 insertions, 21 deletions
diff --git a/drivers/mtd/ubi/vtbl.c b/drivers/mtd/ubi/vtbl.c index 68c9c5ea676f..80bdd5b88bac 100644 --- a/drivers/mtd/ubi/vtbl.c +++ b/drivers/mtd/ubi/vtbl.c | |||
@@ -70,6 +70,26 @@ static void self_vtbl_check(const struct ubi_device *ubi); | |||
70 | static struct ubi_vtbl_record empty_vtbl_record; | 70 | static struct ubi_vtbl_record empty_vtbl_record; |
71 | 71 | ||
72 | /** | 72 | /** |
73 | * ubi_update_layout_vol - helper for updatting layout volumes on flash | ||
74 | * @ubi: UBI device description object | ||
75 | */ | ||
76 | static int ubi_update_layout_vol(struct ubi_device *ubi) | ||
77 | { | ||
78 | struct ubi_volume *layout_vol; | ||
79 | int i, err; | ||
80 | |||
81 | layout_vol = ubi->volumes[vol_id2idx(ubi, UBI_LAYOUT_VOLUME_ID)]; | ||
82 | for (i = 0; i < UBI_LAYOUT_VOLUME_EBS; i++) { | ||
83 | err = ubi_eba_atomic_leb_change(ubi, layout_vol, i, ubi->vtbl, | ||
84 | ubi->vtbl_size); | ||
85 | if (err) | ||
86 | return err; | ||
87 | } | ||
88 | |||
89 | return 0; | ||
90 | } | ||
91 | |||
92 | /** | ||
73 | * ubi_change_vtbl_record - change volume table record. | 93 | * ubi_change_vtbl_record - change volume table record. |
74 | * @ubi: UBI device description object | 94 | * @ubi: UBI device description object |
75 | * @idx: table index to change | 95 | * @idx: table index to change |
@@ -83,12 +103,10 @@ static struct ubi_vtbl_record empty_vtbl_record; | |||
83 | int ubi_change_vtbl_record(struct ubi_device *ubi, int idx, | 103 | int ubi_change_vtbl_record(struct ubi_device *ubi, int idx, |
84 | struct ubi_vtbl_record *vtbl_rec) | 104 | struct ubi_vtbl_record *vtbl_rec) |
85 | { | 105 | { |
86 | int i, err; | 106 | int err; |
87 | uint32_t crc; | 107 | uint32_t crc; |
88 | struct ubi_volume *layout_vol; | ||
89 | 108 | ||
90 | ubi_assert(idx >= 0 && idx < ubi->vtbl_slots); | 109 | ubi_assert(idx >= 0 && idx < ubi->vtbl_slots); |
91 | layout_vol = ubi->volumes[vol_id2idx(ubi, UBI_LAYOUT_VOLUME_ID)]; | ||
92 | 110 | ||
93 | if (!vtbl_rec) | 111 | if (!vtbl_rec) |
94 | vtbl_rec = &empty_vtbl_record; | 112 | vtbl_rec = &empty_vtbl_record; |
@@ -98,15 +116,10 @@ int ubi_change_vtbl_record(struct ubi_device *ubi, int idx, | |||
98 | } | 116 | } |
99 | 117 | ||
100 | memcpy(&ubi->vtbl[idx], vtbl_rec, sizeof(struct ubi_vtbl_record)); | 118 | memcpy(&ubi->vtbl[idx], vtbl_rec, sizeof(struct ubi_vtbl_record)); |
101 | for (i = 0; i < UBI_LAYOUT_VOLUME_EBS; i++) { | 119 | err = ubi_update_layout_vol(ubi); |
102 | err = ubi_eba_atomic_leb_change(ubi, layout_vol, i, ubi->vtbl, | ||
103 | ubi->vtbl_size); | ||
104 | if (err) | ||
105 | return err; | ||
106 | } | ||
107 | 120 | ||
108 | self_vtbl_check(ubi); | 121 | self_vtbl_check(ubi); |
109 | return 0; | 122 | return err ? err : 0; |
110 | } | 123 | } |
111 | 124 | ||
112 | /** | 125 | /** |
@@ -121,9 +134,7 @@ int ubi_change_vtbl_record(struct ubi_device *ubi, int idx, | |||
121 | int ubi_vtbl_rename_volumes(struct ubi_device *ubi, | 134 | int ubi_vtbl_rename_volumes(struct ubi_device *ubi, |
122 | struct list_head *rename_list) | 135 | struct list_head *rename_list) |
123 | { | 136 | { |
124 | int i, err; | ||
125 | struct ubi_rename_entry *re; | 137 | struct ubi_rename_entry *re; |
126 | struct ubi_volume *layout_vol; | ||
127 | 138 | ||
128 | list_for_each_entry(re, rename_list, list) { | 139 | list_for_each_entry(re, rename_list, list) { |
129 | uint32_t crc; | 140 | uint32_t crc; |
@@ -145,15 +156,7 @@ int ubi_vtbl_rename_volumes(struct ubi_device *ubi, | |||
145 | vtbl_rec->crc = cpu_to_be32(crc); | 156 | vtbl_rec->crc = cpu_to_be32(crc); |
146 | } | 157 | } |
147 | 158 | ||
148 | layout_vol = ubi->volumes[vol_id2idx(ubi, UBI_LAYOUT_VOLUME_ID)]; | 159 | return ubi_update_layout_vol(ubi); |
149 | for (i = 0; i < UBI_LAYOUT_VOLUME_EBS; i++) { | ||
150 | err = ubi_eba_atomic_leb_change(ubi, layout_vol, i, ubi->vtbl, | ||
151 | ubi->vtbl_size); | ||
152 | if (err) | ||
153 | return err; | ||
154 | } | ||
155 | |||
156 | return 0; | ||
157 | } | 160 | } |
158 | 161 | ||
159 | /** | 162 | /** |