Commit 1087a7942c055db6fbb6ef6028a77599989561fc
Committed by
Tom Rini
1 parent
f2006808f0
Exists in
smarc_8mq_lf_v2020.04
and in
17 other branches
env: enable accessing the environment in an EXT4 partition
For example to store the environment in a file named "/uboot.env" in MMC "0", where partition "1" contains the EXT4 filesystem, the following configs should be added to the board's default config: CONFIG_ENV_IS_IN_EXT4=y CONFIG_ENV_EXT4_DEVICE_AND_PART="0:1" CONFIG_ENV_EXT4_FILE="/uboot.env" CONFIG_ENV_EXT4_INTERFACE="mmc" Signed-off-by: Jorge Ramirez-Ortiz <jorge.ramirez-ortiz@linaro.org> [trini: Fix some line over 80 chars issues] Signed-off-by: Tom Rini <trini@konsulko.com>
Showing 3 changed files with 59 additions and 12 deletions Side-by-side Diff
env/Kconfig
... | ... | @@ -81,6 +81,13 @@ |
81 | 81 | - CONFIG_FAT_WRITE: |
82 | 82 | This must be enabled. Otherwise it cannot save the environment file. |
83 | 83 | |
84 | +config ENV_IS_IN_EXT4 | |
85 | + bool "Environment is in a EXT4 filesystem" | |
86 | + depends on !CHAIN_OF_TRUST | |
87 | + select EXT4_WRITE | |
88 | + help | |
89 | + Define this if you want to use the EXT4 file system for the environment. | |
90 | + | |
84 | 91 | config ENV_IS_IN_FLASH |
85 | 92 | bool "Environment in flash memory" |
86 | 93 | depends on !CHAIN_OF_TRUST |
... | ... | @@ -395,6 +402,38 @@ |
395 | 402 | help |
396 | 403 | It's a string of the FAT file name. This file use to store the |
397 | 404 | environment. |
405 | + | |
406 | +config ENV_EXT4_INTERFACE | |
407 | + string "Name of the block device for the environment" | |
408 | + depends on ENV_IS_IN_EXT4 | |
409 | + help | |
410 | + Define this to a string that is the name of the block device. | |
411 | + | |
412 | +config ENV_EXT4_DEVICE_AND_PART | |
413 | + string "Device and partition for where to store the environemt in EXT4" | |
414 | + depends on ENV_IS_IN_EXT4 | |
415 | + help | |
416 | + Define this to a string to specify the partition of the device. It can | |
417 | + be as following: | |
418 | + | |
419 | + "D:P", "D:0", "D", "D:" or "D:auto" (D, P are integers. And P >= 1) | |
420 | + - "D:P": device D partition P. Error occurs if device D has no | |
421 | + partition table. | |
422 | + - "D:0": device D. | |
423 | + - "D" or "D:": device D partition 1 if device D has partition | |
424 | + table, or the whole device D if has no partition | |
425 | + table. | |
426 | + - "D:auto": first partition in device D with bootable flag set. | |
427 | + If none, first valid partition in device D. If no | |
428 | + partition table then means device D. | |
429 | + | |
430 | +config ENV_EXT4_FILE | |
431 | + string "Name of the EXT4 file to use for the environemnt" | |
432 | + depends on ENV_IS_IN_EXT4 | |
433 | + default "uboot.env" | |
434 | + help | |
435 | + It's a string of the EXT4 file name. This file use to store the | |
436 | + environment (explicit path to the file) | |
398 | 437 | |
399 | 438 | if ARCH_SUNXI |
400 | 439 |
env/env.c
... | ... | @@ -32,6 +32,8 @@ |
32 | 32 | return ENVL_EEPROM; |
33 | 33 | else if IS_ENABLED(CONFIG_ENV_IS_IN_FAT) |
34 | 34 | return ENVL_FAT; |
35 | + else if IS_ENABLED(CONFIG_ENV_IS_IN_EXT4) | |
36 | + return ENVL_EXT4; | |
35 | 37 | else if IS_ENABLED(CONFIG_ENV_IS_IN_FLASH) |
36 | 38 | return ENVL_FLASH; |
37 | 39 | else if IS_ENABLED(CONFIG_ENV_IS_IN_MMC) |
env/ext4.c
... | ... | @@ -46,9 +46,9 @@ |
46 | 46 | if (err) |
47 | 47 | return err; |
48 | 48 | |
49 | - part = blk_get_device_part_str(EXT4_ENV_INTERFACE, | |
50 | - EXT4_ENV_DEVICE_AND_PART, | |
51 | - &dev_desc, &info, 1); | |
49 | + part = blk_get_device_part_str(CONFIG_ENV_EXT4_INTERFACE, | |
50 | + CONFIG_ENV_EXT4_DEVICE_AND_PART, | |
51 | + &dev_desc, &info, 1); | |
52 | 52 | if (part < 0) |
53 | 53 | return 1; |
54 | 54 | |
55 | 55 | |
56 | 56 | |
... | ... | @@ -57,16 +57,19 @@ |
57 | 57 | |
58 | 58 | if (!ext4fs_mount(info.size)) { |
59 | 59 | printf("\n** Unable to use %s %s for saveenv **\n", |
60 | - EXT4_ENV_INTERFACE, EXT4_ENV_DEVICE_AND_PART); | |
60 | + CONFIG_ENV_EXT4_INTERFACE, | |
61 | + CONFIG_ENV_EXT4_DEVICE_AND_PART); | |
61 | 62 | return 1; |
62 | 63 | } |
63 | 64 | |
64 | - err = ext4fs_write(EXT4_ENV_FILE, (void *)&env_new, sizeof(env_t)); | |
65 | + err = ext4fs_write(CONFIG_ENV_EXT4_FILE, (void *)&env_new, | |
66 | + sizeof(env_t)); | |
65 | 67 | ext4fs_close(); |
66 | 68 | |
67 | 69 | if (err == -1) { |
68 | 70 | printf("\n** Unable to write \"%s\" from %s%d:%d **\n", |
69 | - EXT4_ENV_FILE, EXT4_ENV_INTERFACE, dev, part); | |
71 | + CONFIG_ENV_EXT4_FILE, CONFIG_ENV_EXT4_INTERFACE, dev, | |
72 | + part); | |
70 | 73 | return 1; |
71 | 74 | } |
72 | 75 | |
... | ... | @@ -84,9 +87,9 @@ |
84 | 87 | int err; |
85 | 88 | loff_t off; |
86 | 89 | |
87 | - part = blk_get_device_part_str(EXT4_ENV_INTERFACE, | |
88 | - EXT4_ENV_DEVICE_AND_PART, | |
89 | - &dev_desc, &info, 1); | |
90 | + part = blk_get_device_part_str(CONFIG_ENV_EXT4_INTERFACE, | |
91 | + CONFIG_ENV_EXT4_DEVICE_AND_PART, | |
92 | + &dev_desc, &info, 1); | |
90 | 93 | if (part < 0) |
91 | 94 | goto err_env_relocate; |
92 | 95 | |
93 | 96 | |
94 | 97 | |
... | ... | @@ -95,16 +98,19 @@ |
95 | 98 | |
96 | 99 | if (!ext4fs_mount(info.size)) { |
97 | 100 | printf("\n** Unable to use %s %s for loading the env **\n", |
98 | - EXT4_ENV_INTERFACE, EXT4_ENV_DEVICE_AND_PART); | |
101 | + CONFIG_ENV_EXT4_INTERFACE, | |
102 | + CONFIG_ENV_EXT4_DEVICE_AND_PART); | |
99 | 103 | goto err_env_relocate; |
100 | 104 | } |
101 | 105 | |
102 | - err = ext4_read_file(EXT4_ENV_FILE, buf, 0, CONFIG_ENV_SIZE, &off); | |
106 | + err = ext4_read_file(CONFIG_ENV_EXT4_FILE, buf, 0, CONFIG_ENV_SIZE, | |
107 | + &off); | |
103 | 108 | ext4fs_close(); |
104 | 109 | |
105 | 110 | if (err == -1) { |
106 | 111 | printf("\n** Unable to read \"%s\" from %s%d:%d **\n", |
107 | - EXT4_ENV_FILE, EXT4_ENV_INTERFACE, dev, part); | |
112 | + CONFIG_ENV_EXT4_FILE, CONFIG_ENV_EXT4_INTERFACE, dev, | |
113 | + part); | |
108 | 114 | goto err_env_relocate; |
109 | 115 | } |
110 | 116 |