Using mobile as lun devices (Part 1).

How to convert your mobile device (Samsung Galaxy Ace S5830i) to a card reader.

let there be charge ...

On Mode

Ever wonder as how Froyo, Gingerbread and Ice-Cream-Sandwich allowed user to read micro SD-Card like a regular card-reader while connected to PC via usb ?

This is how it worked. Older versions of android when connected to pc via usb popped up asking to enable usb-storage.

connect-usb-storage-1

Figure 1

connect-usb-storage-2

Figure 2

connect-usb-storage-3

Figure 3

 


Figure 4
cfdisk /dev/sde
After enabling usb-storage

After disconnect.

cfdisk /dev/sde
cfdisk: cannot open /dev/sde: No medium found

Magic behind above feature: output from within android adb shell

id
uid=2000(shell) gid=2000(shell) groups=1003(graphics),1004(input),1007(log),
1009(mount),1011(adb),1015(sdcard_rw),3001(net_bt_admin),3002(net_bt),3003(inet)
cat /sys/devices/lm-2/gadget/lun0/file
/dev/block/vold/179:0
cat /sys/devices/virtual/usb_composite/usb_mass_storage/enable
1
ls -l /dev/block/vold/
brw-r----- root     sdcard_rw 179,   2 2023-10-10 13:12 179:2
brw-r----- root     sdcard_rw 179,   1 2023-10-10 13:13 179:1
brw-r----- root     sdcard_rw 179,   0 2023-10-10 13:12 179:0
ls -l /dev/block/mmcblk*
brw------- root     root     179,   0 2023-10-10 13:12 mmcblk0
brw------- root     root     179,   1 2023-10-10 13:12 mmcblk0p1
brw------- root     root     179,   2 2023-10-10 13:12 mmcblk0p2

Device that I used, Samsung Galaxy Ace S5830i.

Why choose this device ?

1. Small in size.
2. It has sd-card slot on its side, making it convenient to add/remove card easily.
3. Not in use as touch does not work anymore.

Off Mode

Steps described below is intended for Samsung Galaxy Ace S5830i only and may/may not work for any other device.

Steps described below requires pre-understanding on howto to unlock bootloader of mobile device, along-with usage of required tools/utils needed to do so.

Steps described below requires addition and/or removal and/or flashing of softwares/rom not intended by original device manufacturer or software vendor.

Please do not attempt if you are not sure what you are doing. Author of this article will not be responsible of any such attempt resulting in bricking or non-working of such device to any extent.

Please do not try on any other device.

You have been warned.

Step 1
  • Get and flash/upgrade to rom CM7_cooperve_RC_04.zip (cynogenmod).
Note: rom - CM9_cooperve_Beta_05.zip may also work, but be cautioned.
These roms comes with ext4 module enabled and converts partitions to ext4.

Step 2
  • Get boot.img from kernel_CM7_v4.0_cooperve.zip
    1. Extract boot.img and modify files.
    2. Re-pack it to boot.img with modified files.
    3. Flash back boot.img to the device.
The resulting image would have following changed files.
|-- sbin
|   |-- adbd        (1)
|-- init.charge.rc  (2)
`-- default.prop    (3)
  • Changes in above files.

1. init.charge.rc (additions)

on post-fs
    exec sfsck /dev/stl10 ext4
    mount ext4 /dev/stl10 /cache wait nosuid nodev noatime journal_async_commit
    exec sfsck /dev/stl11 ext4
    mount ext4 /dev/stl11 /data  wait nosuid nodev noatime journal_async_commit
    start boot_recovery

service adbd /sbin/adbd recovery
    disabled

on property:persist.service.adb.enable=1
    start adbd

service boot_recovery /system/bin/sh /cache/bin/recovery.misc.sh
    user root
    oneshot
    disabled

2. default.prop (additions or value only change)

ro.secure=0
ro.allow.mock.location=0
ro.debuggable=1
persist.service.adb.enable=1

3. sbin/adbd - most adbd are not compiled with root option enabled, meaning, it will not provide adbd shell as root when logged in.
One needs to either compile or copy from compatible boot.img like CWM made for such device.

Step 3
  • Create new files on device with given content.

1. File: /cache/bin/recovery.misc.sh

#!/sbin/sh
DATE=$(date)
mount -o remount,rw /
mount -o remount,ro /dev/stl9   # system
echo $DATE >> /tmp/recovery.misc.log

echo 10 > /sys/class/backlight/aat1401-backlight/brightness
echo 0 > /sys/class/backlight/aat1401-backlight/brightness

. /cache/bin/luns.sh &

# remount as read-only
mount -o remount,ro /dev/stl10  # cache
mount -o remount,ro /dev/stl11  # data

2. File: /cache/bin/luns.sh

#!/sbin/sh
DATE=$(date)
echo "$DATE LUNS" >> /tmp/recovery.misc.log
F=/sys/devices/lm-2/gadget/lun0/file
ON=/sys/devices/virtual/usb_composite/usb_mass_storage/enable
F1=/dev/block/mmcblk0
echo 0 > $ON && echo "$F1" > $F && echo 1 > $ON

For some reason if you are unable to edit these files, using busybox vi <file name> on device itself, then copy and save these scripts to your /home/user as recovery.misc.sh, luns.sh using your favourite editor. then use adb to push it to /cache/bin/ (see adb docs on howto).

Any direct description on how to apply/use tools and utils to achieve above mentioned steps have been omitted from this page.
Please refrain from asking such process or methods.

There are host of forums and sites where one can get such information.
eg. forum.xda-developers.com

Note of advice, consider this article more as fun on learning internals of mobile devices.

Please do not use micro-sd card with existing data for this test/experiment. Once it works to your satisfaction, you may try to use other cards.

The author will not be liable to any extent for loss of any data and/or damage of micro-sd card.

Step 4
  • Shut-down (off) the device.
  • Insert a micro-sd card (tested upto 32Gb).
  • Attach device via usb to a desktop/laptop.
  • Wait for 5-10 secs, and now the card is mountable.

Well, now I have a most sophisticated card-reader in town. It would be something to implement this using a high-end expensive mobile ;-) .

What happened to this feature in newer versions of android ?

I haven't had a chance to dig into newer ones, but from what I read on about newer android features, that this has been removed, or well hidden under deep settings.
One reason as why, because, unmounting sd-card in use can result in data loss and/or corruption of sd-card.

BONUS Feature

Off Mode Booting

Can I boot an existing bootable linux micro sd-card after successful completion of step 4 above ?

Yes, this is an extra benefit of converting the device to a card-reader. Once you have created or made available such card, then follow step 4 above and it can be booted.

NOTE: For off-mode booting
1. After inserting micro-sd card, make sure devices' usb is plugged in and charge mode is active, meaning you see the battery icon come on and then fade off.
2. Do not unplug the usb, just reboot the attached desktop/laptop instead.

Author

V.Krishn


Resources


Edit - History - Print - Recent Changes - Search
Page last modified on November 23, 2023, at 02:06 AM