"Das U-Boot" Source Tree
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'ubifixes-for-v2024-10-rc1' of https://source.denx.de/u-boot/custodians/u-boot-ubi

ubi changes for v2024.10-rc1

fs: ubifs: Add support for ZSTD decompression
from Piotr Wojtaszczyk

Fixes for ubi command from Martin Kurbanov

Tom Rini 005105b1 4d338362

+68 -8
+15 -6
cmd/ubi.c
··· 248 248 249 249 static struct ubi_volume *ubi_find_volume(char *volume) 250 250 { 251 - struct ubi_volume *vol = NULL; 251 + struct ubi_volume *vol; 252 252 int i; 253 253 254 254 for (i = 0; i < ubi->vtbl_slots; i++) { ··· 355 355 356 356 static int ubi_volume_continue_write(char *volume, void *buf, size_t size) 357 357 { 358 - int err = 1; 358 + int err; 359 359 struct ubi_volume *vol; 360 360 361 361 vol = ubi_find_volume(volume); 362 362 if (vol == NULL) 363 363 return ENODEV; 364 + 365 + if (!vol->updating) { 366 + printf("UBI volume update was not initiated\n"); 367 + return EINVAL; 368 + } 364 369 365 370 err = ubi_more_update_data(ubi, vol, buf, size); 366 371 if (err < 0) { ··· 391 396 int ubi_volume_begin_write(char *volume, void *buf, size_t size, 392 397 size_t full_size) 393 398 { 394 - int err = 1; 395 - int rsvd_bytes = 0; 399 + int err; 400 + int rsvd_bytes; 396 401 struct ubi_volume *vol; 397 402 398 403 vol = ubi_find_volume(volume); ··· 410 415 printf("Cannot start volume update\n"); 411 416 return -err; 412 417 } 418 + 419 + /* The volume is just wiped out */ 420 + if (!full_size) 421 + return 0; 413 422 414 423 return ubi_volume_continue_write(volume, buf, size); 415 424 } ··· 573 582 int ubi_part(char *part_name, const char *vid_header_offset) 574 583 { 575 584 struct mtd_info *mtd; 576 - int err = 0; 585 + int err; 577 586 578 587 if (ubi && ubi->mtd && !strcmp(ubi->mtd->name, part_name)) { 579 588 printf("UBI partition '%s' already selected\n", part_name); ··· 604 613 605 614 static int do_ubi(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) 606 615 { 607 - int64_t size = 0; 616 + int64_t size; 608 617 ulong addr = 0; 609 618 bool skipcheck = false; 610 619
+2
fs/ubifs/ubifs-media.h
··· 320 320 * UBIFS_COMPR_NONE: no compression 321 321 * UBIFS_COMPR_LZO: LZO compression 322 322 * UBIFS_COMPR_ZLIB: ZLIB compression 323 + * UBIFS_COMPR_ZSTD: ZSTD compression 323 324 * UBIFS_COMPR_TYPES_CNT: count of supported compression types 324 325 */ 325 326 enum { 326 327 UBIFS_COMPR_NONE, 327 328 UBIFS_COMPR_LZO, 328 329 UBIFS_COMPR_ZLIB, 330 + UBIFS_COMPR_ZSTD, 329 331 UBIFS_COMPR_TYPES_CNT, 330 332 }; 331 333
+51 -2
fs/ubifs/ubifs.c
··· 26 26 #include <linux/err.h> 27 27 #include <linux/lzo.h> 28 28 29 + #if IS_ENABLED(CONFIG_ZSTD) 30 + #include <linux/zstd.h> 31 + #include <abuf.h> 32 + #endif 33 + 29 34 DECLARE_GLOBAL_DATA_PTR; 30 35 31 36 /* compress.c */ ··· 41 46 (unsigned long *)out_len, 0, 0); 42 47 } 43 48 49 + #if IS_ENABLED(CONFIG_ZSTD) 50 + static int zstd_decompress_wrapper(const unsigned char *in, size_t in_len, 51 + unsigned char *out, size_t *out_len) 52 + { 53 + struct abuf abuf_in, abuf_out; 54 + int ret; 55 + 56 + abuf_init_set(&abuf_in, (void *)in, in_len); 57 + abuf_init_set(&abuf_out, (void *)out, *out_len); 58 + 59 + ret = zstd_decompress(&abuf_in, &abuf_out); 60 + if (ret < 0) 61 + return ret; 62 + 63 + *out_len = ret; 64 + return 0; 65 + } 66 + #endif 67 + 44 68 /* Fake description object for the "none" compressor */ 45 69 static struct ubifs_compressor none_compr = { 46 70 .compr_type = UBIFS_COMPR_NONE, ··· 70 94 .decompress = gzip_decompress, 71 95 }; 72 96 97 + #if IS_ENABLED(CONFIG_ZSTD) 98 + static struct ubifs_compressor zstd_compr = { 99 + .compr_type = UBIFS_COMPR_ZSTD, 100 + #ifndef __UBOOT__ 101 + .comp_mutex = &zstd_enc_mutex, 102 + .decomp_mutex = &zstd_dec_mutex, 103 + #endif 104 + .name = "zstd", 105 + .capi_name = "zstd", 106 + .decompress = zstd_decompress_wrapper, 107 + }; 108 + #endif 109 + 73 110 /* All UBIFS compressors */ 74 - struct ubifs_compressor *ubifs_compressors[UBIFS_COMPR_TYPES_CNT]; 111 + struct ubifs_compressor *ubifs_compressors[UBIFS_COMPR_TYPES_CNT] = {NULL}; 75 112 76 113 77 114 #ifdef __UBOOT__ ··· 165 202 166 203 compr = ubifs_compressors[compr_type]; 167 204 205 + if (unlikely(!compr)) { 206 + ubifs_err(c, "compression type %d is not compiled in", compr_type); 207 + return -EINVAL; 208 + } 209 + 168 210 if (unlikely(!compr->capi_name)) { 169 - ubifs_err(c, "%s compression is not compiled in", compr->name); 211 + ubifs_err(c, "%s compression is not compiled in", 212 + compr->name ? compr->name : "unknown"); 170 213 return -EINVAL; 171 214 } 172 215 ··· 230 273 err = compr_init(&zlib_compr); 231 274 if (err) 232 275 return err; 276 + 277 + #if IS_ENABLED(CONFIG_ZSTD) 278 + err = compr_init(&zstd_compr); 279 + if (err) 280 + return err; 281 + #endif 233 282 234 283 err = compr_init(&none_compr); 235 284 if (err)