summaryrefslogtreecommitdiffstats
path: root/meta-phosphor/aspeed-layer/recipes-connectivity/jsnbd/jsnbd/state_hook
blob: 0df6ff9730cf0ab39c7b4157225ebf4cbd1435f6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/sh

if [ $# -ne 2 ]
then
    echo "usage: $0 <start|stop> <config>" >&2
    exit 1
fi

action=$1
config=$2

gadget_name=mass-storage
gadget_dir=/sys/kernel/config/usb_gadget/$gadget_name

case "$config" in
0)
    nbd_device=/dev/nbd0
    ;;
*)
    echo "invalid config $config" >&2
    exit 1
    ;;
esac

set -ex

case "$action" in
start)
    mkdir -p $gadget_dir
    (
    cd $gadget_dir
    # http://www.linux-usb.org/usb.ids
    #    |-> 1d6b  Linux Foundation
    #          |-> 0104  Multifunction Composite Gadget
    echo "0x1d6b" > idVendor
    echo "0x0104" > idProduct
    mkdir -p strings/0x409
    echo "OpenBMC" > strings/0x409/manufacturer
    echo "Virtual Media Device" > strings/0x409/product
    mkdir -p configs/c.1/strings/0x409
    echo "config 1" > configs/c.1/strings/0x409/configuration
    mkdir -p functions/mass_storage.usb0
    ln -s functions/mass_storage.usb0 configs/c.1
    echo 1 > functions/mass_storage.usb0/lun.0/removable
    echo 1 > functions/mass_storage.usb0/lun.0/ro
    echo 0 > functions/mass_storage.usb0/lun.0/cdrom
    echo $nbd_device > functions/mass_storage.usb0/lun.0/file
    echo "1e6a0000.usb-vhub:p4" > UDC
    )
    ;;
stop)
    (
    cd $gadget_dir
    rm configs/c.1/mass_storage.usb0
    rmdir functions/mass_storage.usb0
    rmdir configs/c.1/strings/0x409
    rmdir configs/c.1
    rmdir strings/0x409
    )
    rmdir $gadget_dir
    ;;
*)
    echo "invalid action $action" >&2
    exit 1
esac

exit 0

OpenPOWER on IntegriCloud