diff options
author | Marcin Bukat <marcin.bukat@gmail.com> | 2018-03-13 21:24:56 +0100 |
---|---|---|
committer | Marcin Bukat <marcin.bukat@gmail.com> | 2018-06-12 10:31:15 +0200 |
commit | 7692558674be24dfe51d7be84b4d01995c23e67b (patch) | |
tree | 9cf8909c361ea6373ee81d46518cc168c5d60074 | |
parent | d5889b3d94c0ff2403c2c6c9c89500b85e050bca (diff) | |
download | rockbox-7692558674be24dfe51d7be84b4d01995c23e67b.tar.gz rockbox-7692558674be24dfe51d7be84b4d01995c23e67b.zip |
Agptek Rocker: Implement USB mass storage driver
Agptek uses composite android driver.
Change-Id: Iece188ad640f3dfd24c171946c14da4c3516b6d5
-rw-r--r-- | apps/main.c | 4 | ||||
-rw-r--r-- | bootloader/rocker_linux.c | 14 | ||||
-rw-r--r-- | firmware/SOURCES | 1 | ||||
-rw-r--r-- | firmware/export/config/agptekrocker.h | 2 | ||||
-rw-r--r-- | firmware/target/hosted/agptek/power-agptek.c | 22 | ||||
-rw-r--r-- | firmware/target/hosted/agptek/power-agptek.h | 3 | ||||
-rw-r--r-- | firmware/target/hosted/agptek/powermgmt-agptek.c | 4 | ||||
-rw-r--r-- | firmware/target/hosted/agptek/usb-agptek.c | 118 |
8 files changed, 149 insertions, 19 deletions
diff --git a/apps/main.c b/apps/main.c index 88a6630f94..7d9d859681 100644 --- a/apps/main.c +++ b/apps/main.c | |||
@@ -335,6 +335,10 @@ static void init(void) | |||
335 | font_init(); | 335 | font_init(); |
336 | #endif | 336 | #endif |
337 | show_logo(); | 337 | show_logo(); |
338 | #ifndef USB_NONE | ||
339 | usb_init(); | ||
340 | usb_start_monitoring(); | ||
341 | #endif | ||
338 | button_init(); | 342 | button_init(); |
339 | powermgmt_init(); | 343 | powermgmt_init(); |
340 | backlight_init(); | 344 | backlight_init(); |
diff --git a/bootloader/rocker_linux.c b/bootloader/rocker_linux.c index dd912ee378..cb0e5b66e5 100644 --- a/bootloader/rocker_linux.c +++ b/bootloader/rocker_linux.c | |||
@@ -449,6 +449,7 @@ static void tools_screen(void) | |||
449 | power_off(); | 449 | power_off(); |
450 | } | 450 | } |
451 | 451 | ||
452 | #if 0 | ||
452 | /* open log file */ | 453 | /* open log file */ |
453 | static int open_log(void) | 454 | static int open_log(void) |
454 | { | 455 | { |
@@ -467,11 +468,13 @@ static int open_log(void) | |||
467 | /* re-open the file, truncate in case the move was unsuccessful */ | 468 | /* re-open the file, truncate in case the move was unsuccessful */ |
468 | return open("/mnt/sd_0/rockbox.log", O_RDWR | O_CREAT | O_APPEND | O_TRUNC); | 469 | return open("/mnt/sd_0/rockbox.log", O_RDWR | O_CREAT | O_APPEND | O_TRUNC); |
469 | } | 470 | } |
471 | #endif | ||
470 | 472 | ||
471 | int main(int argc, char **argv) | 473 | int main(int argc, char **argv) |
472 | { | 474 | { |
473 | (void) argc; | 475 | (void) argc; |
474 | (void) argv; | 476 | (void) argv; |
477 | #if 0 | ||
475 | /* redirect stdout and stderr to have error messages logged somewhere on the | 478 | /* redirect stdout and stderr to have error messages logged somewhere on the |
476 | * user partition */ | 479 | * user partition */ |
477 | int fd = open_log(); | 480 | int fd = open_log(); |
@@ -485,6 +488,7 @@ int main(int argc, char **argv) | |||
485 | printf("Rockbox boot loader\n"); | 488 | printf("Rockbox boot loader\n"); |
486 | printf("Version: %s\n", rbversion); | 489 | printf("Version: %s\n", rbversion); |
487 | printf("%s\n", MODEL_NAME); | 490 | printf("%s\n", MODEL_NAME); |
491 | #endif | ||
488 | 492 | ||
489 | system_init(); | 493 | system_init(); |
490 | core_allocator_init(); | 494 | core_allocator_init(); |
@@ -506,10 +510,12 @@ int main(int argc, char **argv) | |||
506 | enum boot_mode mode = get_boot_mode(); | 510 | enum boot_mode mode = get_boot_mode(); |
507 | if(mode == BOOT_USB || mode == BOOT_OF) | 511 | if(mode == BOOT_USB || mode == BOOT_OF) |
508 | { | 512 | { |
513 | #if 0 | ||
509 | fflush(stdout); | 514 | fflush(stdout); |
510 | fflush(stderr); | 515 | fflush(stderr); |
511 | close(fileno(stdout)); | 516 | close(fileno(stdout)); |
512 | close(fileno(stderr)); | 517 | close(fileno(stderr)); |
518 | #endif | ||
513 | /* for now the only way we have to trigger USB mode it to run the OF */ | 519 | /* for now the only way we have to trigger USB mode it to run the OF */ |
514 | /* boot OF */ | 520 | /* boot OF */ |
515 | execvp("/usr/bin/hiby_player", argv); | 521 | execvp("/usr/bin/hiby_player", argv); |
@@ -522,13 +528,9 @@ int main(int argc, char **argv) | |||
522 | } | 528 | } |
523 | else if(mode == BOOT_ROCKBOX) | 529 | else if(mode == BOOT_ROCKBOX) |
524 | { | 530 | { |
525 | /* Rockbox expects /.rockbox to contain themes, rocks, etc, but we | ||
526 | * cannot easily create this symlink because the root filesystem is | ||
527 | * mounted read-only. Although we could remount it read-write temporarily, | ||
528 | * this is neededlessly complicated and we defer this job to the dualboot | ||
529 | * install script */ | ||
530 | fflush(stdout); | 531 | fflush(stdout); |
531 | execl("/mnt/sd_0/.rockbox/rockbox.rocker", "rockbox.rocker", NULL); | 532 | system("/bin/cp /mnt/sd_0/.rockbox/rockbox.rocker /tmp"); |
533 | execl("/tmp/rockbox.rocker", "rockbox.rocker", NULL); | ||
532 | printf("execvp failed: %s\n", strerror(errno)); | 534 | printf("execvp failed: %s\n", strerror(errno)); |
533 | /* fallback to OF in case of failure */ | 535 | /* fallback to OF in case of failure */ |
534 | error_screen("Cannot boot Rockbox"); | 536 | error_screen("Cannot boot Rockbox"); |
diff --git a/firmware/SOURCES b/firmware/SOURCES index b85111af44..fdfa811804 100644 --- a/firmware/SOURCES +++ b/firmware/SOURCES | |||
@@ -124,6 +124,7 @@ target/hosted/agptek/lcd-agptek.c | |||
124 | target/hosted/agptek/power-agptek.c | 124 | target/hosted/agptek/power-agptek.c |
125 | target/hosted/agptek/powermgmt-agptek.c | 125 | target/hosted/agptek/powermgmt-agptek.c |
126 | target/hosted/agptek/system-agptek.c | 126 | target/hosted/agptek/system-agptek.c |
127 | target/hosted/agptek/usb-agptek.c | ||
127 | #endif | 128 | #endif |
128 | 129 | ||
129 | #if defined(SAMSUNG_YPR0) && !defined(SIMULATOR) | 130 | #if defined(SAMSUNG_YPR0) && !defined(SIMULATOR) |
diff --git a/firmware/export/config/agptekrocker.h b/firmware/export/config/agptekrocker.h index 517448b86d..6a0a6689b3 100644 --- a/firmware/export/config/agptekrocker.h +++ b/firmware/export/config/agptekrocker.h | |||
@@ -79,7 +79,7 @@ | |||
79 | #ifndef SIMULATOR | 79 | #ifndef SIMULATOR |
80 | /* We have usb power and can detect usb but it is handled by Linux */ | 80 | /* We have usb power and can detect usb but it is handled by Linux */ |
81 | #define HAVE_USB_POWER | 81 | #define HAVE_USB_POWER |
82 | #define USB_NONE | 82 | |
83 | #endif | 83 | #endif |
84 | 84 | ||
85 | #define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE | 85 | #define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE |
diff --git a/firmware/target/hosted/agptek/power-agptek.c b/firmware/target/hosted/agptek/power-agptek.c index 7403801681..023d3888b9 100644 --- a/firmware/target/hosted/agptek/power-agptek.c +++ b/firmware/target/hosted/agptek/power-agptek.c | |||
@@ -35,19 +35,23 @@ const char * const sysfs_bat_voltage = | |||
35 | const char * const sysfs_bat_status = | 35 | const char * const sysfs_bat_status = |
36 | "/sys/class/power_supply/battery/status"; | 36 | "/sys/class/power_supply/battery/status"; |
37 | 37 | ||
38 | unsigned int agptek_power_get_status(void) | 38 | const char * const sysfs_pow_supply = |
39 | "/sys/class/power_supply/usb/present"; | ||
40 | |||
41 | unsigned int agptek_power_input_status(void) | ||
42 | { | ||
43 | int present = 0; | ||
44 | sysfs_get_int(sysfs_pow_supply, &present); | ||
45 | |||
46 | return present ? POWER_INPUT_USB_CHARGER : POWER_INPUT_NONE; | ||
47 | } | ||
48 | |||
49 | bool agptek_power_charging_status(void) | ||
39 | { | 50 | { |
40 | char buf[12] = {0}; | 51 | char buf[12] = {0}; |
41 | sysfs_get_string(sysfs_bat_status, buf, sizeof(buf)); | 52 | sysfs_get_string(sysfs_bat_status, buf, sizeof(buf)); |
42 | 53 | ||
43 | if (strncmp(buf, "Charging", 8) == 0) | 54 | return (strncmp(buf, "Charging", 8) == 0); |
44 | { | ||
45 | return POWER_INPUT_USB_CHARGER; | ||
46 | } | ||
47 | else | ||
48 | { | ||
49 | return POWER_INPUT_NONE; | ||
50 | } | ||
51 | } | 55 | } |
52 | 56 | ||
53 | unsigned int agptek_power_get_battery_voltage(void) | 57 | unsigned int agptek_power_get_battery_voltage(void) |
diff --git a/firmware/target/hosted/agptek/power-agptek.h b/firmware/target/hosted/agptek/power-agptek.h index 16f32b76ad..1ae2ff43d6 100644 --- a/firmware/target/hosted/agptek/power-agptek.h +++ b/firmware/target/hosted/agptek/power-agptek.h | |||
@@ -23,7 +23,8 @@ | |||
23 | #include <stdbool.h> | 23 | #include <stdbool.h> |
24 | #include "config.h" | 24 | #include "config.h" |
25 | 25 | ||
26 | unsigned int agptek_power_get_status(void); | 26 | unsigned int agptek_power_input_status(void); |
27 | bool agptek_power_charging_status(void); | ||
27 | unsigned int agptek_power_get_battery_voltage(void); | 28 | unsigned int agptek_power_get_battery_voltage(void); |
28 | #endif /* _POWER_AGPTEK_H_ */ | 29 | #endif /* _POWER_AGPTEK_H_ */ |
29 | 30 | ||
diff --git a/firmware/target/hosted/agptek/powermgmt-agptek.c b/firmware/target/hosted/agptek/powermgmt-agptek.c index 3371d1e793..6bfccb4115 100644 --- a/firmware/target/hosted/agptek/powermgmt-agptek.c +++ b/firmware/target/hosted/agptek/powermgmt-agptek.c | |||
@@ -49,7 +49,7 @@ const unsigned short const percent_to_volt_charge[11] = | |||
49 | unsigned int power_input_status(void) | 49 | unsigned int power_input_status(void) |
50 | { | 50 | { |
51 | /* POWER_INPUT_USB_CHARGER, POWER_INPUT_NONE */ | 51 | /* POWER_INPUT_USB_CHARGER, POWER_INPUT_NONE */ |
52 | return agptek_power_get_status(); | 52 | return agptek_power_input_status(); |
53 | } | 53 | } |
54 | 54 | ||
55 | int _battery_voltage(void) | 55 | int _battery_voltage(void) |
@@ -59,5 +59,5 @@ int _battery_voltage(void) | |||
59 | 59 | ||
60 | bool charging_state(void) | 60 | bool charging_state(void) |
61 | { | 61 | { |
62 | return agptek_power_get_status() == POWER_INPUT_USB_CHARGER; | 62 | return agptek_power_charging_status(); |
63 | } | 63 | } |
diff --git a/firmware/target/hosted/agptek/usb-agptek.c b/firmware/target/hosted/agptek/usb-agptek.c new file mode 100644 index 0000000000..6c805edb5a --- /dev/null +++ b/firmware/target/hosted/agptek/usb-agptek.c | |||
@@ -0,0 +1,118 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___ | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * | ||
9 | * Copyright (C) 2018 by Marcin Bukat | ||
10 | * | ||
11 | * This program is free software; you can redistribute it and/or | ||
12 | * modify it under the terms of the GNU General Public License | ||
13 | * as published by the Free Software Foundation; either version 2 | ||
14 | * of the License, or (at your option) any later version. | ||
15 | * | ||
16 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
17 | * KIND, either express or implied. | ||
18 | * | ||
19 | ****************************************************************************/ | ||
20 | |||
21 | #include <stdlib.h> | ||
22 | #include <sys/mount.h> | ||
23 | #include <string.h> | ||
24 | #include "config.h" | ||
25 | #include "disk.h" | ||
26 | #include "usb.h" | ||
27 | #include "sysfs.h" | ||
28 | #include "power.h" | ||
29 | #include "power-agptek.h" | ||
30 | |||
31 | static bool adb_mode = false; | ||
32 | |||
33 | /* TODO: implement usb detection properly */ | ||
34 | int usb_detect(void) | ||
35 | { | ||
36 | return power_input_status() == POWER_INPUT_USB_CHARGER ? USB_INSERTED : USB_EXTRACTED; | ||
37 | } | ||
38 | |||
39 | void usb_enable(bool on) | ||
40 | { | ||
41 | /* Ignore usb enable/disable when ADB is enabled so we can fireup adb shell | ||
42 | * without entering ums mode | ||
43 | */ | ||
44 | if (!adb_mode) | ||
45 | { | ||
46 | sysfs_set_int("/sys/class/android_usb/android0/enable", on ? 1 : 0); | ||
47 | } | ||
48 | } | ||
49 | |||
50 | /* This is called by usb thread after usb extract in order to return | ||
51 | * regular FS access | ||
52 | * | ||
53 | * returns the # of successful mounts | ||
54 | */ | ||
55 | int disk_mount_all(void) | ||
56 | { | ||
57 | const char *dev[] = {"/dev/mmcblk0p1", "/dev/mmcblk0"}; | ||
58 | const char *fs[] = {"vfat", "exfat"}; | ||
59 | |||
60 | sysfs_set_string("/sys/class/android_usb/android0/f_mass_storage/lun/file", ""); | ||
61 | |||
62 | for (int i=0; i<2; i++) | ||
63 | { | ||
64 | for (int j=0; j<2; j++) | ||
65 | { | ||
66 | if (mount(dev[i], "/mnt/sd_0", fs[j], 0, NULL) == 0) | ||
67 | { | ||
68 | return 1; | ||
69 | } | ||
70 | } | ||
71 | } | ||
72 | |||
73 | return 0; | ||
74 | } | ||
75 | |||
76 | /* This is called by usb thread after all threads ACKs usb inserted message | ||
77 | * | ||
78 | * returns the # of successful unmounts | ||
79 | */ | ||
80 | int disk_unmount_all(void) | ||
81 | { | ||
82 | if (umount("/mnt/sd_0") == 0) | ||
83 | { | ||
84 | sysfs_set_string("/sys/class/android_usb/android0/f_mass_storage/lun/file", "/dev/mmcblk0"); | ||
85 | return 1; | ||
86 | } | ||
87 | |||
88 | return 0; | ||
89 | } | ||
90 | |||
91 | void usb_init_device(void) | ||
92 | { | ||
93 | char functions[32] = {0}; | ||
94 | |||
95 | /* Check if ADB was activated in bootloader */ | ||
96 | sysfs_get_string("/sys/class/android_usb/android0/functions", functions, sizeof(functions)); | ||
97 | adb_mode = (strstr(functions, "adb") == NULL) ? false : true; | ||
98 | |||
99 | usb_enable(false); | ||
100 | |||
101 | if (adb_mode) | ||
102 | { | ||
103 | sysfs_set_string("/sys/class/android_usb/android0/functions", "mass_storage,adb"); | ||
104 | sysfs_set_string("/sys/class/android_usb/android0/idVendor", "18D1"); | ||
105 | sysfs_set_string("/sys/class/android_usb/android0/idProduct", "D002"); | ||
106 | } | ||
107 | else | ||
108 | { | ||
109 | sysfs_set_string("/sys/class/android_usb/android0/functions", "mass_storage"); | ||
110 | sysfs_set_string("/sys/class/android_usb/android0/idVendor", "C502"); | ||
111 | sysfs_set_string("/sys/class/android_usb/android0/idProduct", "0029"); | ||
112 | } | ||
113 | |||
114 | sysfs_set_string("/sys/class/android_usb/android0/iManufacturer", "Rockbox.org"); | ||
115 | sysfs_set_string("/sys/class/android_usb/android0/iProduct", "Rockbox media player"); | ||
116 | sysfs_set_string("/sys/class/android_usb/android0/iSerial", "0123456789ABCDEF"); | ||
117 | sysfs_set_string("/sys/class/android_usb/android0/f_mass_storage/inquiry_string", "Agptek Rocker 0100"); | ||
118 | } | ||