Project

General

Profile

Using USB Mass Storage Peripheral driver » make_usb_mem.sh

Jonathan Cormier, 10/02/2014 02:38 PM

 
1
#!/bin/sh
2

    
3
# Create a loopback file in /dev/shm. Format fat32 and give to g_mass_storage driver.
4

    
5
FILE=/dev/shm/20M
6
set -x
7

    
8
die()
9
{
10
    echo $@
11
    exit
12
}
13

    
14
rm -f $FILE
15

    
16
# Create 20M file with all zeros
17
dd if=/dev/zero of=$FILE bs=1M count=20 || die
18

    
19
# opkg install util-linux-sfdisk
20
# Create one large fat32 partition
21
sfdisk --force $FILE << EOF
22
unit: sectors
23
8,,c;
24
EOF
25

    
26
# Attach loopback file to /dev/loop0
27
[ ! -e /dev/loop0 ] && mknod /dev/loop0 b 7 0
28
losetup -o 4096 /dev/loop0 $FILE || die
29

    
30
# Format fat32
31
mkfs.vfat /dev/loop0 || die
32

    
33
# Mount fat32 partition
34
mkdir -p /mnt/loop
35
mount -t vfat /dev/loop0 /mnt/loop || die
36

    
37
# Add files to loop device
38
touch /mnt/loop/testfile || die
39

    
40
# Unmount and unAttach
41
umount /mnt/loop || die
42
losetup -d /dev/loop0 || die
43

    
44
# Load mass storage driver module
45
modprobe g_mass_storage file=$FILE stall=0 removable=1 || die
46

    
47
echo "Plugin usb cable"
48

    
(2-2/2) Go to top
Add picture from clipboard (Maximum size: 1 GB)