Initialise eMMC partitions prior to first boot in Yocto [ANSWERED]

Moderators: Oren.R, Eran.M

brendan
Posts: 13
Joined: Fri Oct 21, 2016 2:16 am

Initialise eMMC partitions prior to first boot in Yocto [ANSWERED]

Postby brendan » Mon Feb 27, 2017 8:04 am

I am using Yocto to generate the required files to get my iMX6 VAR SOM Solo up and running. I have no issues with generating these files or anything but I am wondering what I need to do to format and partition the eMMC prior to loading the files onto my board.

I have a bash script which does this by sfdisk and mkfs.ext4 commands however this script is run after the system has initialised.

Code: Select all

mkdir -p /tmp/emmc_ro
mkdir -p /tmp/emmc_rw
if [ ! -e /dev/mmcblk0p1 ]; then
    sfdisk /dev/mmcblk0 << EOF
    , 1G
    , +
    write
    EOF
        mkfs.ext4 /dev/mmcblk0p1
        mkfs.ext4 /dev/mmcblk0p2
fi
 


Any help would be greatly appreciated.

Eran.M
Posts: 140
Joined: Tue Jan 26, 2016 10:49 am

Re: Initialise eMMC partitions prior to first boot in Yocto

Postby Eran.M » Mon Feb 27, 2017 12:06 pm

You can do it in multiple ways:
- Boot from SD card (for example, our recovery SD card): http://variwiki.com/index.php?title=VAR ... ing_Jethro
- Boot from network (using tftp and nfs): http://variwiki.com/index.php?title=VAR ... h_From_Net
- Use the USB mass storage gadget via U-Boot: http://variwiki.com/index.php?title=U-B ... age_gadget

brendan
Posts: 13
Joined: Fri Oct 21, 2016 2:16 am

Re: Initialise eMMC partitions prior to first boot in Yocto

Postby brendan » Mon Feb 27, 2017 10:58 pm

Eran.M wrote:You can do it in multiple ways:
- Boot from SD card (for example, our recovery SD card): http://variwiki.com/index.php?title=VAR ... ing_Jethro
- Boot from network (using tftp and nfs): http://variwiki.com/index.php?title=VAR ... h_From_Net
- Use the USB mass storage gadget via U-Boot: http://variwiki.com/index.php?title=U-B ... age_gadget


Thanks for your reply. I'm still wanting to have my rootfs and boot from NAND, and just format and mount the eMMC for usage as secondary storage.

The link you supplied: http://variwiki.com/index.php?title=VAR ... ing_Jethro looks similar to what I want to achieve however I do not want to flash the eMMC with the rootfs.

Am I right that the first section of code here will achieve the above. Unmount the eMMC, delete the data, create the partition table, format the eMMC as ext4, then mount the eMMC and once booted into NAND it will see the eMMC partition and able to have read/write permissions to the eMMC (treating it like external storage?).

I also notice that there seems to be p1 to p7 partitions that are deleted? I am just unsure on what the exact purpose of the code is below when doing fdisk to partition the eMMC, I am only looking to have 2 partitions; 1gb then the remainder (2.5gb) to be the final partition (such as my simple bash script in my original post).

Code: Select all

$ export node=/dev/mmcblk0

Make sure the eMMC is not mounted:
$ umount ${node}p*

Delete current data on eMMC:
$ dd if=/dev/zero of=${node}p1 bs=1024 count=1024
$ dd if=/dev/zero of=${node}p2 bs=1024 count=1024
$ dd if=/dev/zero of=${node}p3 bs=1024 count=1024
$ dd if=/dev/zero of=${node}p4 bs=1024 count=1024
$ dd if=/dev/zero of=${node}p5 bs=1024 count=1024
$ dd if=/dev/zero of=${node}p6 bs=1024 count=1024
$ dd if=/dev/zero of=${node}p7 bs=1024 count=1024
$ sync
$ (echo d; echo 1; echo d; echo 2; echo d; echo 3; echo d; echo w) | fdisk $node
$ sync
$ dd if=/dev/zero of=$node bs=1M count=4
$ sync

Create a partition table:
$ (echo n; echo p; echo 1; echo; echo; echo p; echo w) | fdisk -u $node
$ sync

Format the rootfs partition with ext4 file system:
$ mkfs.ext4 ${node}p1 -L rootfs


Second part which is flashing the eMMC with the rootfs (which I feel is not required for my purpose)

Code: Select all

Flash the rootfs:
$ mkdir /run/media/mmcblk0p1
$ mount ${node}p1 /run/media/mmcblk0p1
$ tar xvpf rootfs.tar.bz2 -C /run/media/mmcblk1p1/
$ sync
$ umount /run/media/mmcblk0p1


And finally, set the U-Boot env. variable "rootfs_device" to "emmc" by one of the following two methods:
$ fw_setenv rootfs_device emmc
(A "Warning: Bad CRC, using default environment" message is expected, since this is the first write of the U-Boot environment to the NAND flash)

or:
Reboot and stop at the U-Boot command line, and enter the following:
=> setenv rootfs_device emmc
=> saveenv


I am just new to bash scripting and wanted to confirm that I didn't write over the NAND in trying to do the above and that I am actually formatting the eMMC properly.

Thanks

Eran.M
Posts: 140
Joined: Tue Jan 26, 2016 10:49 am

Re: Initialise eMMC partitions prior to first boot in Yocto

Postby Eran.M » Mon Feb 27, 2017 11:09 pm

I didn't realize you wanted to have the rootfs on the NAND flash.
You can indeed run your script after the system has booted, and /dev/mmcblk0 is indeed the eMMC, and writing to it will not affect the NAND flash at all.

brendan
Posts: 13
Joined: Fri Oct 21, 2016 2:16 am

Re: Initialise eMMC partitions prior to first boot in Yocto

Postby brendan » Tue Feb 28, 2017 6:51 am

Eran.M wrote:I didn't realize you wanted to have the rootfs on the NAND flash.
You can indeed run your script after the system has booted, and /dev/mmcblk0 is indeed the eMMC, and writing to it will not affect the NAND flash at all.


Would there be a way where I can modify the rootfs ubi/ubifs so that the eMMC is initialised before it is flashed onto NAND?

Eran.M
Posts: 140
Joined: Tue Jan 26, 2016 10:49 am

Re: Initialise eMMC partitions prior to first boot in Yocto

Postby Eran.M » Tue Feb 28, 2017 7:14 am

What method are you using to flash the NAND?

brendan
Posts: 13
Joined: Fri Oct 21, 2016 2:16 am

Re: Initialise eMMC partitions prior to first boot in Yocto

Postby brendan » Tue Feb 28, 2017 10:57 pm

Eran.M wrote:What method are you using to flash the NAND?


I flash it by using the SPL and uboot.img stored on the MMC (SD card) and using the commands:

Code: Select all

$ flash_erase /dev/mtd0 0 0
$ kobs-ng init -x SPL --search_exponent=1 -v
$ flash_erase /dev/mtd1  0 0
$ nandwrite -p /dev/mtd1 u-boot.img


from http://www.variwiki.com/index.php?title ... ng_to_NAND

Then via TFTP is when I load the .dtb and .ubi.

I was just considering what the best method for initialising the eMMC prior to booting would be, I am considering placing my original bash script in etc/init.d/ and having it execute on run time but I was just wondering if there any other solutions (ones that could possibly be a better approach).

Eran.M
Posts: 140
Joined: Tue Jan 26, 2016 10:49 am

Re: Initialise eMMC partitions prior to first boot in Yocto

Postby Eran.M » Wed Mar 01, 2017 7:37 am

So you are booting from an SD card, in order to write the NAND?

brendan
Posts: 13
Joined: Fri Oct 21, 2016 2:16 am

Re: Initialise eMMC partitions prior to first boot in Yocto

Postby brendan » Wed Mar 01, 2017 11:07 pm

Eran.M wrote:So you are booting from an SD card, in order to write the NAND?


Yes that is correct. What I'm visualising in my head is the .ubi is modified (or have the right files/scripts) so when the .ubi/.ubifs is loaded that the two partitions on eMMC are just formatted as ext4 and formatted (one being rw and one being ro). I know I can do this by using a shellscript to be executed after systemd has loaded everything etc. however I don't want to rely on this method.

Eran.M
Posts: 140
Joined: Tue Jan 26, 2016 10:49 am

Re: Initialise eMMC partitions prior to first boot in Yocto

Postby Eran.M » Wed Mar 01, 2017 11:37 pm

You can run the scrpit from the SD card, right before/after you flash the NAND.


Return to “Yocto”

Who is online

Users browsing this forum: No registered users and 3 guests

cron