title: SD card: how to force the kernel to read the WP pin again without removing the sdcard
body: <p>I have the following udev rules to mount the first partition of the sd card to /mnt/sdcard.</p>
  
  <pre><code>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"
  </code></pre>
  
  <p>My <code>/usr/bin/mount_sdcard</code> executable is :</p>
  
  <pre><code>#!/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&gt;&amp;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
  </code></pre>
  
  <p>This code is working correctly and the partition is mounted read write (rw) when a sd card is inserted.</p>
  
  <p>But if the sd card is already present at boot, the partition is mounted read only (ro).</p>
  
  <p>In this case, I cannot mount the partition read write without removing and reinserting the sd card manually.</p>
  
  <p>I tried to unmount and then to mount again. I tried to use the remount option:  <code>mount -o remount,rw /dev/mmcblk0p1</code> which seems to work but the partition is still marked as ro when running the <code>mount</code> command:</p>
  
  <pre><code>/dev/mmcblk0p1 on /mnt/sdcard type ext4 (ro,relatime,data=ordered)
  </code></pre>
  
  <p><strong>Update:</strong></p>
  
  <p>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.</p>
  
  <p>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.
  The problem is that the kernel will try to read this WP pin only at boot and when a card is inserted.</p>
  
  <p>==> at boot the kernel sd card controller set the card as ro:</p>
  
  <pre><code>kernel: [    1.723728] mmc0: new high speed SD card at address 59b4
  kernel: [    1.738262] mmcblk0: mmc0:59b4 USD   1.87 GiB (ro)
  </code></pre>
  
  <p>And after the WP pin changes and the card is removed/replugged, the kernel sd card controller will set the card as rw:</p>
  
  <pre><code>kernel: [  527.931457] mmc0: new high speed SD card at address 59b4
  kernel: [  527.943988] mmcblk0: mmc0:59b4 USD   1.87 GiB
  </code></pre>
  
  <p>My question changes: how to force the kernel to read the WP pin again without removing the sd card ?</p>