eMMC Q&A
Q1: How to enale eMMC in kernel?
Enable the following config in menuconfig.
Device Drivers → <M> MMC/SD/SDIO card support ---> → [*] SStar SoC platform drivers -→ → <M> EMMC driver → [*] UNIFY EMMC DRIVER < > SStar SD/MMC Card Interface Support
SD and eMMC use the same set of GPIO, so when you need to enable eMMC Driver, the SD Driver should be disabled. The kdrv_emmc.ko file will be generated under kernel/modules, add kdrv_emmc.ko field to project/kbuild/customize/4.9.84/p3/dispcam kernel_mod_list
, and the kdrv_emmc.ko file will be included when the image is packaged, kdrv_emmc.ko will be insmod when booting.
Q2: How to use eMMC or SD card as Linux Swap partition?
-
Enable swap function when compiling the kernel
-
Execute
$ make menuconfig
in the kernel directory -
Enter the General setup option, enable the swap function, and then save and exit
-
Check the .config file and confirm that the swap function is enabled
-
Recompile the kernel, and then burn it to demo board
$ make clean; make -j8
-
-
Create swap partition on eMMC/SD card
-
Use the following command in Linux to view the system partition
# cat /proc/partitions
You can see that there is a 120GB mmcblk0 device that has not been partitioned on the system.
-
Use the fdisk command to create a new swap partition
Enter the fdisk operation interface:
# fdisk /dev/mmcblk0
Execute the m command to view the basic functions supported by fdisk:
Execute the p command to view the current partition:
You can see that the current mmcblk0 has not been partitioned.
Execute the commands in the following figure in turn. Create a 1GB swap partition, use the w command to save and exit the fdisk tool:
-
View the newly created swap partition
-
-
Use mkswap to set up swap partition
# mkswap /dev/mmcblk0p1
-
Use swapon to enable swap function
# swapon /dev/mmcblk0p1
-
View the usage of system memory (including swap partition)
# free or free -m
You can see that the swap function has been enabled in the system, and the swap partition size is about 1GB.
-
Automatically load swap partition at system startup
Use swapon to manually enable the swap function, and use swapoff to manually disable it. If you want automatic implementation, you can configure it by modifying /etc/fstab:
$ vi /etc/fstab
Add a line of configuration to automatically load the /dev/mmcblk0p1 partition as the swap partition when Linux startup.
-
Test whether the swap function is normal
A test program is provided to check the swap function of Linux. It continues to apply for 1MB of memory until the total available physical memory exceeds the system's available physical memory (the available physical memory of the system in the test environment is about 70MB, and the test program will apply for about 255MB in total). If the swap function is disabled, the test program will report out of memory and exit; if it is enabled, the system will use the swap partition as the memory expansion space, and the test program can be executed normally.
Source code of the test program: swap_test.c, execute swap_test after cross-compilation.
Cross compilation example:
$ arm-linux-gnueabihf-gcc swap_test.c -o swap_test
After compiling, send swap_test to the demo board through tftp or other methods, and then add executable permissions:
# chmod +x swap_test
View the current system memory usage:
# free -m
Let swap_test run in the background:
#./swap_test &
Use
free-m
to continuously check the current system memory usage and find that the available physical memory has been decreasing. When it is reduced to 0, the system starts to use the Swap partition:Finally, the test program runs successfully:
Note: EMMC and SDIO share a set of pins. If the hardware refers to the SDIO circuit design, it needs to be changed to regular power supply when testing EMMC.
...