| 116 | |
| 117 | [=#emmc-uboot] |
| 118 | ==== U-Boot Support |
| 119 | U-Boot provides access to eMMC devices through the {{{mmc}}} command and interface but adds an additional argument to the {{{mmc}}} interface to describe the hardware partition. The interface is therefore described as 'mmc <dev> <part>' where 'dev' is the mmc device (some boards have more than one) and 'part' is the hardware partition: 0=user, 1=boot0, 2=boot1. |
| 120 | |
| 121 | Use the {{{mmc dev}}} command to specify the device and partition: |
| 122 | {{{#!bash |
| 123 | mmc dev 0 0 # select user hw partition |
| 124 | mmc dev 0 1 # select boot0 hw partition |
| 125 | mmc dev 0 2 # select boot1 hw partition |
| 126 | }}} |
| 127 | |
| 128 | If U-Boot has been built with {{{CONFIG_SUPPORT_EMMC_BOOT}}} some additional mmc commands are available: |
| 129 | * mmc bootbus <dev> <boot_bus_width> <reset_boot_bus_width> <boot_mode> |
| 130 | * mmc bootpart-resize <dev> <boot-part-size-mb> <rpmb-part-size-mb> |
| 131 | * mmc partconf <dev> <boot_ack> <boot-partition> <partition-access> # set PARTITION_CONFIG field |
| 132 | * mmc rst-function <dev> <value> # change RST_n_FUNCTION field between 0|1|2 (write-once) |
| 133 | |
| 134 | The {{{mmc partconf}}} command can be used to configure the PARTITION_CONFIG specifying what hardware partition to boot from: |
| 135 | {{{#!bash |
| 136 | mmc partconf 0 0 0 0 # disable boot partition (default unset condition; boots from user partition) |
| 137 | mmc partconf 0 1 1 0 # set boot0 partition (with ack) |
| 138 | mmc partconf 0 1 2 0 # set boot1 partition (with ack) |
| 139 | mmc partconf 0 1 7 0 # set user partition (with ack) |
| 140 | }}} |
| 141 | |
| 142 | If U-Boot has been built with {{{CONFIG_SUPPORT_EMMC_RPMB}}} the {{{mmc rpmb}}} command is available for reading, writing and programming the key for the Replay Protection Memory Block (RPMB) partition in eMMC. |
| 143 | |
| 144 | When using U-Boot to write to eMMC (or microSD) it is often useful to use the {{{gzwrite}}} command. For example if you have a compressed 'disk image' you can write it to your eMMC (assuming it is mmc dev 0) with: |
| 145 | {{{#!bash |
| 146 | tftpboot ${loadaddr} disk-image.gz && gzwrite mmc 0 ${loadaddr} ${filesize} |
| 147 | }}} |
| 148 | * The {{{disk-image.gz}}} contains a partition table at offset 0x0 as well as partitions at their respective offsets (according to the partition table) and has been compressed with gzip |
| 149 | * If you know the flash offset of a specific partition (which you can determine using the {{{part list mmc 0}}} command) you can also use gzwrite to flash a compressed partition image |
| 150 | |
| 151 | |
| 152 | [=#emmc-linux] |
| 153 | ==== Linux Support |
| 154 | Linux presents the various hardware partitions as separate devices: |
| 155 | - /dev/mmcblk0boot0 - BOOT0 partition |
| 156 | - /dev/mmcblk0boot1 - BOOT1 partition |
| 157 | - /dev/mmcblk0rpmb - RPMB partition |
| 158 | - /dev/mmcblk0 - USER partition |
| 159 | |
| 160 | Note that the BOOT partitions by default are read-only as they are typically used for sensitive boot firmware. To write to them you can disable {{{force_ro}}} in sysfs via: |
| 161 | {{{#!bash |
| 162 | echo 0 > /sys/class/block/mmcblk0boot0/force_ro |
| 163 | }}} |
| 164 | |
| 165 | The Linux {{{mmc}}} application from the {{{mmc-utils}}} package provides access to eMMC configuration through CSD registers. |
| 166 | |
| 167 | You can use the {{{mmc}}} utility to configure the eMMC PARTITION_CONFIG to specify the boot device on power-up via {{{mmc bootpart enable <boot_partition> <send_ack> <device>}}} where boot_partition specifies the hardware partition (1=boot0, 2=boot1, 7=user), send_ack specifies the device must send an awknoledgement (for fast boot), and device is the root mmc block device of the eMMC: |
| 168 | {{{#!bash |
| 169 | # set boot partition to boot0 |
| 170 | mmc bootpart enable 1 0 /dev/mmcblk0 |
| 171 | # set boot partition to boot1 |
| 172 | mmc bootpart enable 2 0 /dev/mmcblk0 |
| 173 | # set boot partition to user |
| 174 | mmc bootpart enable 7 0 /dev/mmcblk0 |
| 175 | }}} |
| 176 | |
| 177 | Some additional use cases: |
| 178 | {{{#!bash |
| 179 | # show PARTITION_CONFIG: |
| 180 | mmc extcsd read /dev/mmcblk0 | grep PARTITION_CONFIG |
| 181 | # show BUS CONFIG: |
| 182 | mmc extcsd read /dev/mmcblk0 | grep BOOT_BUS_CONDITIONS |
| 183 | # disable boot partition |
| 184 | mmc bootpart enable 0 0 /dev/mmcblk0 |
| 185 | }}} |
| 186 | |
| 187 | References: |
| 188 | * https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/mmc/mmc-tools.txt |
| 189 | |
242 | | [=#emmc-uboot] |
243 | | === U-Boot Support === |
244 | | U-Boot provides access to eMMC devices through the {{{mmc}}} command and interface but adds an additional argument to the {{{mmc}}} interface to describe the hardware partition. The interface is therefore described as 'mmc <dev> <part>' where 'dev' is the mmc device (some boards have more than one) and 'part' is the hardware partition: 0=user, 1=boot0, 2=boot1. |
245 | | |
246 | | Use the {{{mmc dev}}} command to specify the device and partition: |
247 | | {{{#!bash |
248 | | mmc dev 0 0 # select user hw partition |
249 | | mmc dev 0 1 # select boot0 hw partition |
250 | | mmc dev 0 2 # select boot1 hw partition |
251 | | }}} |
252 | | |
253 | | If U-Boot has been built with {{{CONFIG_SUPPORT_EMMC_BOOT}}} some additional mmc commands are available: |
254 | | * mmc bootbus <dev> <boot_bus_width> <reset_boot_bus_width> <boot_mode> |
255 | | * mmc bootpart-resize <dev> <boot-part-size-mb> <rpmb-part-size-mb> |
256 | | * mmc partconf <dev> <boot_ack> <boot-partition> <partition-access> # set PARTITION_CONFIG field |
257 | | * mmc rst-function <dev> <value> # change RST_n_FUNCTION field between 0|1|2 (write-once) |
258 | | |
259 | | The {{{mmc partconf}}} command can be used to configure the PARTITION_CONFIG specifying what hardware partition to boot from: |
260 | | {{{#!bash |
261 | | mmc partconf 0 0 0 0 # disable boot partition (default unset condition; boots from user partition) |
262 | | mmc partconf 0 1 1 0 # set boot0 partition (with ack) |
263 | | mmc partconf 0 1 2 0 # set boot1 partition (with ack) |
264 | | mmc partconf 0 1 7 0 # set user partition (with ack) |
265 | | }}} |
266 | | |
267 | | If U-Boot has been built with {{{CONFIG_SUPPORT_EMMC_RPMB}}} the {{{mmc rpmb}}} command is available for reading, writing and programming the key for the Replay Protection Memory Block (RPMB) partition in eMMC. |
268 | | |
269 | | When using U-Boot to write to eMMC (or microSD) it is often useful to use the {{{gzwrite}}} command. For example if you have a compressed 'disk image' you can write it to your eMMC (assuming it is mmc dev 0) with: |
270 | | {{{#!bash |
271 | | tftpboot ${loadaddr} disk-image.gz && gzwrite mmc 0 ${loadaddr} ${filesize} |
272 | | }}} |
273 | | * The {{{disk-image.gz}}} contains a partition table at offset 0x0 as well as partitions at their respective offsets (according to the partition table) and has been compressed with gzip |
274 | | * If you know the flash offset of a specific partition (which you can determine using the {{{part list mmc 0}}} command) you can also use gzwrite to flash a compressed partition image |
275 | | |
276 | | |
277 | | [=#emmc-linux] |
278 | | === Linux Support === |
279 | | Linux presents the various hardware partitions as separate devices: |
280 | | - /dev/mmcblk0boot0 - BOOT0 partition |
281 | | - /dev/mmcblk0boot1 - BOOT1 partition |
282 | | - /dev/mmcblk0rpmb - RPMB partition |
283 | | - /dev/mmcblk0 - USER partition |
284 | | |
285 | | Note that the BOOT partitions by default are read-only as they are typically used for sensitive boot firmware. To write to them you can disable {{{force_ro}}} in sysfs via: |
286 | | {{{#!bash |
287 | | echo 0 > /sys/class/block/mmcblk0boot0/force_ro |
288 | | }}} |
289 | | |
290 | | The Linux {{{mmc}}} application from the {{{mmc-utils}}} package provides access to eMMC configuration through CSD registers. |
291 | | |
292 | | You can use the {{{mmc}}} utility to configure the eMMC PARTITION_CONFIG to specify the boot device on power-up via {{{mmc bootpart enable <boot_partition> <send_ack> <device>}}} where boot_partition specifies the hardware partition (1=boot0, 2=boot1, 7=user), send_ack specifies the device must send an awknoledgement (for fast boot), and device is the root mmc block device of the eMMC: |
293 | | {{{#!bash |
294 | | # set boot partition to boot0 |
295 | | mmc bootpart enable 1 0 /dev/mmcblk0 |
296 | | # set boot partition to boot1 |
297 | | mmc bootpart enable 2 0 /dev/mmcblk0 |
298 | | # set boot partition to user |
299 | | mmc bootpart enable 7 0 /dev/mmcblk0 |
300 | | }}} |
301 | | |
302 | | Some additional use cases: |
303 | | {{{#!bash |
304 | | # show PARTITION_CONFIG: |
305 | | mmc extcsd read /dev/mmcblk0 | grep PARTITION_CONFIG |
306 | | # show BUS CONFIG: |
307 | | mmc extcsd read /dev/mmcblk0 | grep BOOT_BUS_CONDITIONS |
308 | | # disable boot partition |
309 | | mmc bootpart enable 0 0 /dev/mmcblk0 |
310 | | }}} |
311 | | |
312 | | References: |
313 | | * https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/mmc/mmc-tools.txt |
314 | | |