简体   繁体   English

SD卡:如何在不删除SD卡的情况下强制内核再次读取WP引脚

[英]SD card: how to force the kernel to read the WP pin again without removing the sdcard

I have the following udev rules to mount the first partition of the sd card to /mnt/sdcard. 我有以下udev规则将SD卡的第一个分区挂载到/ mnt / sdcard。

KERNEL=="mmcblk0p1", SUBSYSTEMS=="mmc", ATTRS{name}=="?*", ATTRS{serial}=="?*", ENV{ID_NAME}="$attr{name}", ENV{ID_SERIAL}="$attr{serial}", SYMLINK+="sdcard", RUN+="/usr/bin/mount_sdcard"

KERNEL=="mmcblk0", ACTION=="remove", RUN+="/usr/bin/unmount_sdcard"

My /usr/bin/mount_sdcard executable is : 我的/usr/bin/mount_sdcard可执行文件是:

#!/bin/sh

# log event
logger -t mount_sdcard -p user.warn "New SD Card detected"

# mount to /mnt/sdcard
mount_result=`mount $DEVNAME /mnt/sdcard 2>&1`

# On errors, send error to log
echo $mount_result | logger -t mount_sdcard -p user.error

if [ "x$mount_result" = "x" ]
then
    # print filesystem type
    stat -f /mnt/sdcard | grep Type | cut -d: -f4 | logger -t mount_sdcard -p user.warn

    # print space left on device
    df -h /dev/sdcard | logger -t mount_sdcard -p user.warn
fi

This code is working correctly and the partition is mounted read write (rw) when a sd card is inserted. 此代码工作正常,插入SD卡时分区挂载读写(rw)。

But if the sd card is already present at boot, the partition is mounted read only (ro). 但是如果sd卡在启动时已经存在,则分区以只读方式挂载(ro)。

In this case, I cannot mount the partition read write without removing and reinserting the sd card manually. 在这种情况下,我无法挂载分区读写而无需手动删除和重新插入SD卡。

I tried to unmount and then to mount again. 我试图卸载然后重新安装。 I tried to use the remount option: mount -o remount,rw /dev/mmcblk0p1 which seems to work but the partition is still marked as ro when running the mount command: 我尝试使用remount选项: mount -o remount,rw /dev/mmcblk0p1这似乎可以工作但是在运行mount命令时分区仍然标记为ro:

/dev/mmcblk0p1 on /mnt/sdcard type ext4 (ro,relatime,data=ordered)

Update: 更新:

The problem is more precise: This is on custom hardware where the WP (write protect) pin on the ARM processor is wired to an output of the processor. 问题更加精确:这是在自定义硬件上,其中ARM处理器上的WP(写保护)引脚连接到处理器的输出。

At boot, this output set the sdcard controller in read only mode and after the init this output is inverted to allow to write to the sd card. 在引导时,此输出将sdcard控制器设置为只读模式,在init之后,此输出被反转以允许写入SD卡。 The problem is that the kernel will try to read this WP pin only at boot and when a card is inserted. 问题是内核只会在启动时和插入卡时尝试读取此WP引脚。

==> at boot the kernel sd card controller set the card as ro: ==>启动内核SD卡控制器将卡设置为ro:

kernel: [    1.723728] mmc0: new high speed SD card at address 59b4
kernel: [    1.738262] mmcblk0: mmc0:59b4 USD   1.87 GiB (ro)

And after the WP pin changes and the card is removed/replugged, the kernel sd card controller will set the card as rw: 在WP引脚更改并且卡被移除/重新插入后,内核SD卡控制器将卡设置为rw:

kernel: [  527.931457] mmc0: new high speed SD card at address 59b4
kernel: [  527.943988] mmcblk0: mmc0:59b4 USD   1.87 GiB

My question changes: how to force the kernel to read the WP pin again without removing the sd card ? 我的问题发生了变化:如何在不删除SD卡的情况下强制内核再次读取WP引脚?

I was able to read the WP pin again by resetting the controller for this card with these commands: 通过使用以下命令重置此卡的控制器,我能够再次读取WP引脚:

First get the controller: 首先得到控制器:

$ readlink /sys/block/mmcblk0
../devices/soc0/soc/2100000.aips-bus/2194000.usdhc/mmc_host/mmc0/mmc0:59b4/block

Then unbind and bind the card: 然后取消绑定并绑定卡:

$ echo 2194000.usdhc > /sys/bus/platform/drivers/sdhci-esdhc-imx/unbind
$ echo 2194000.usdhc > /sys/bus/platform/drivers/sdhci-esdhc-imx/bind

A few things I would try: 我会尝试一些事情:

  • run fsck /dev/mmcblk0p1 . 运行fsck /dev/mmcblk0p1 The failure to mount a partition in rw mode is often a sign of unclean filesystem state. 无法在rw模式下挂载分区通常是不清洁文件系统状态的标志。 It's probably not the case here, since you can mount it correclty by replugging the card, but better be safe. 这可能不是这里的情况,因为您可以通过重新插入卡来安装它,但最好是安全的。

  • try to mount /dev/mmcblk0p1 via /etc/fstab to see if that works. 尝试通过/etc/fstab挂载/dev/mmcblk0p1以查看是否有效。 I understand it won't be a definitive solution, but at least you'd isolate issues with mount from issues with udev . 我知道它不会是一个明确的解决方案,但至少你可以通过udev解决mount问题。

  • compare dmesg output concerning the SD card at boot time with dmesg output when you replug the card afterwards. 比较dmesg关于在开机时与SD卡输出dmesg输出,当你以后重新插入卡。 It seems that the controller fails initialize properly at boot time, but the issue disappears later on. 似乎控制器在启动时未能正确初始化,但问题随后会消失。 Finding out what that intermittent issue is might solve it for you. 找出那个间歇性问题可能会为您解决。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM