From d544ce46a78c834492ae1116cd1d1e47cb9d8cb0 Mon Sep 17 00:00:00 2001 From: Solomon Peachy Date: Thu, 15 Oct 2020 10:18:16 -0400 Subject: [PATCH] hosted: Unify the USB code for the hiby-based players. * Specify exported USB VID/PID in target config header * Don't fail if the sd filesystem has already been remounted (ie due to platform hotplug) Change-Id: Ifd2dae0c4f15086bf2bf89eb093018b3c4d2b75d --- firmware/SOURCES | 7 +- firmware/export/config/agptekrocker.h | 4 + firmware/export/config/aigoerosq.h | 4 + firmware/export/config/xduoox20.h | 4 + firmware/export/config/xduoox3ii.h | 4 + firmware/target/hosted/aigo/usb-erosq.c | 118 ------------------ .../{agptek/usb-agptek.c => usb-hiby.c} | 6 +- firmware/target/hosted/xduoo/usb-xduoo.c | 118 ------------------ 8 files changed, 23 insertions(+), 242 deletions(-) delete mode 100644 firmware/target/hosted/aigo/usb-erosq.c rename firmware/target/hosted/{agptek/usb-agptek.c => usb-hiby.c} (95%) delete mode 100644 firmware/target/hosted/xduoo/usb-xduoo.c diff --git a/firmware/SOURCES b/firmware/SOURCES index 8bf3d96bdf..7f08e4870f 100644 --- a/firmware/SOURCES +++ b/firmware/SOURCES @@ -134,7 +134,6 @@ target/hosted/agptek/button-agptek.c target/hosted/agptek/debug-agptek.c target/hosted/agptek/power-agptek.c target/hosted/agptek/powermgmt-agptek.c -target/hosted/agptek/usb-agptek.c #endif #if (defined(XDUOO_X3II) || defined(XDUOO_X20)) && !defined(SIMULATOR) @@ -142,7 +141,10 @@ target/hosted/xduoo/button-xduoo.c target/hosted/xduoo/debug-xduoo.c target/hosted/xduoo/power-xduoo.c target/hosted/xduoo/powermgmt-xduoo.c -target/hosted/xduoo/usb-xduoo.c +#endif + +#if defined(HIBY_LINUX) && !defined(SIMULATOR) +target/hosted/usb-hiby.c #endif #if (defined(FIIO_M3K)) && !defined(SIMULATOR) @@ -160,7 +162,6 @@ target/hosted/aigo/button-erosq.c target/hosted/aigo/debug-erosq.c target/hosted/aigo/power-erosq.c target/hosted/aigo/powermgmt-erosq.c -target/hosted/aigo/usb-erosq.c #endif #if defined(SAMSUNG_YPR0) && !defined(SIMULATOR) diff --git a/firmware/export/config/agptekrocker.h b/firmware/export/config/agptekrocker.h index f0e98d4db2..3323124900 100644 --- a/firmware/export/config/agptekrocker.h +++ b/firmware/export/config/agptekrocker.h @@ -131,3 +131,7 @@ #define BOOTFILE_EXT "rocker" #define BOOTFILE "rockbox." BOOTFILE_EXT #define BOOTDIR "/.rockbox" + +/* USB */ +#define USB_VID_STR "C502" +#define USB_PID_STR "0029" diff --git a/firmware/export/config/aigoerosq.h b/firmware/export/config/aigoerosq.h index 5a520707d9..d6761a4470 100644 --- a/firmware/export/config/aigoerosq.h +++ b/firmware/export/config/aigoerosq.h @@ -135,3 +135,7 @@ #define BOOTFILE_EXT "erosq" #define BOOTFILE "rockbox." BOOTFILE_EXT #define BOOTDIR "/.rockbox" + +/* USB */ +#define USB_VID_STR "C502" +#define USB_PID_STR "0023" diff --git a/firmware/export/config/xduoox20.h b/firmware/export/config/xduoox20.h index e12346e1bc..7266370e9d 100644 --- a/firmware/export/config/xduoox20.h +++ b/firmware/export/config/xduoox20.h @@ -131,3 +131,7 @@ #define BOOTFILE "rockbox." BOOTFILE_EXT #define BOOTDIR "/.rockbox" +/* USB */ +#define USB_VID_STR "C502" +#define USB_PID_STR "003C" // XXX this is probably wrong + diff --git a/firmware/export/config/xduoox3ii.h b/firmware/export/config/xduoox3ii.h index c9047eb224..1da6e71ade 100644 --- a/firmware/export/config/xduoox3ii.h +++ b/firmware/export/config/xduoox3ii.h @@ -133,3 +133,7 @@ #define BOOTFILE_EXT "x3ii" #define BOOTFILE "rockbox." BOOTFILE_EXT #define BOOTDIR "/.rockbox" + +/* USB */ +#define USB_VID_STR "C502" +#define USB_PID_STR "003C" diff --git a/firmware/target/hosted/aigo/usb-erosq.c b/firmware/target/hosted/aigo/usb-erosq.c deleted file mode 100644 index 2a3acf4d62..0000000000 --- a/firmware/target/hosted/aigo/usb-erosq.c +++ /dev/null @@ -1,118 +0,0 @@ -/*************************************************************************** - * __________ __ ___ - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * - * Copyright (C) 2018 by Marcin Bukat - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY - * KIND, either express or implied. - * - ****************************************************************************/ - -#include -#include -#include -#include "config.h" -#include "disk.h" -#include "usb.h" -#include "sysfs.h" -#include "power.h" -#include "power-erosq.h" - -static bool adb_mode = false; - -/* TODO: implement usb detection properly */ -int usb_detect(void) -{ - return power_input_status() == POWER_INPUT_USB_CHARGER ? USB_INSERTED : USB_EXTRACTED; -} - -void usb_enable(bool on) -{ - /* Ignore usb enable/disable when ADB is enabled so we can fireup adb shell - * without entering ums mode - */ - if (!adb_mode) - { - sysfs_set_int("/sys/class/android_usb/android0/enable", on ? 1 : 0); - } -} - -/* This is called by usb thread after usb extract in order to return - * regular FS access - * - * returns the # of successful mounts -*/ -int disk_mount_all(void) -{ - const char *dev[] = {"/dev/mmcblk0p1", "/dev/mmcblk0"}; - const char *fs[] = {"vfat", "exfat"}; - - sysfs_set_string("/sys/class/android_usb/android0/f_mass_storage/lun/file", ""); - - for (int i=0; i<2; i++) - { - for (int j=0; j<2; j++) - { - if (mount(dev[i], "/mnt/sd_0", fs[j], 0, NULL) == 0) - { - return 1; - } - } - } - - return 0; -} - -/* This is called by usb thread after all threads ACKs usb inserted message - * - * returns the # of successful unmounts - */ -int disk_unmount_all(void) -{ - if (umount("/mnt/sd_0") == 0) - { - sysfs_set_string("/sys/class/android_usb/android0/f_mass_storage/lun/file", "/dev/mmcblk0"); - return 1; - } - - return 0; -} - -void usb_init_device(void) -{ - char functions[32] = {0}; - - /* Check if ADB was activated in bootloader */ - sysfs_get_string("/sys/class/android_usb/android0/functions", functions, sizeof(functions)); - adb_mode = (strstr(functions, "adb") == NULL) ? false : true; - - usb_enable(false); - - if (adb_mode) - { - sysfs_set_string("/sys/class/android_usb/android0/functions", "mass_storage,adb"); - sysfs_set_string("/sys/class/android_usb/android0/idVendor", "18D1"); - sysfs_set_string("/sys/class/android_usb/android0/idProduct", "D002"); - } - else - { - sysfs_set_string("/sys/class/android_usb/android0/functions", "mass_storage"); - sysfs_set_string("/sys/class/android_usb/android0/idVendor", "C502"); - sysfs_set_string("/sys/class/android_usb/android0/idProduct", "0023"); - } - - sysfs_set_string("/sys/class/android_usb/android0/iManufacturer", "Rockbox.org"); - sysfs_set_string("/sys/class/android_usb/android0/iProduct", "Rockbox media player"); - sysfs_set_string("/sys/class/android_usb/android0/iSerial", "0123456789ABCDEF"); - sysfs_set_string("/sys/class/android_usb/android0/f_mass_storage/inquiry_string", "ErosQ 0100"); -} diff --git a/firmware/target/hosted/agptek/usb-agptek.c b/firmware/target/hosted/usb-hiby.c similarity index 95% rename from firmware/target/hosted/agptek/usb-agptek.c rename to firmware/target/hosted/usb-hiby.c index 6c805edb5a..6c35e76e29 100644 --- a/firmware/target/hosted/agptek/usb-agptek.c +++ b/firmware/target/hosted/usb-hiby.c @@ -26,7 +26,6 @@ #include "usb.h" #include "sysfs.h" #include "power.h" -#include "power-agptek.h" static bool adb_mode = false; @@ -63,7 +62,8 @@ int disk_mount_all(void) { for (int j=0; j<2; j++) { - if (mount(dev[i], "/mnt/sd_0", fs[j], 0, NULL) == 0) + int rval = mount(dev[i], PIVOT_ROOT, fs[j], 0, NULL); + if (rval == 0 || errno == -EBUSY) { return 1; } @@ -114,5 +114,5 @@ void usb_init_device(void) sysfs_set_string("/sys/class/android_usb/android0/iManufacturer", "Rockbox.org"); sysfs_set_string("/sys/class/android_usb/android0/iProduct", "Rockbox media player"); sysfs_set_string("/sys/class/android_usb/android0/iSerial", "0123456789ABCDEF"); - sysfs_set_string("/sys/class/android_usb/android0/f_mass_storage/inquiry_string", "Agptek Rocker 0100"); + sysfs_set_string("/sys/class/android_usb/android0/f_mass_storage/inquiry_string", "Rockbox 0100"); } diff --git a/firmware/target/hosted/xduoo/usb-xduoo.c b/firmware/target/hosted/xduoo/usb-xduoo.c deleted file mode 100644 index 19248ad262..0000000000 --- a/firmware/target/hosted/xduoo/usb-xduoo.c +++ /dev/null @@ -1,118 +0,0 @@ -/*************************************************************************** - * __________ __ ___ - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * - * Copyright (C) 2018 by Marcin Bukat - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY - * KIND, either express or implied. - * - ****************************************************************************/ - -#include -#include -#include -#include "config.h" -#include "disk.h" -#include "usb.h" -#include "sysfs.h" -#include "power.h" -#include "power-xduoo.h" - -static bool adb_mode = false; - -/* TODO: implement usb detection properly */ -int usb_detect(void) -{ - return power_input_status() == POWER_INPUT_USB_CHARGER ? USB_INSERTED : USB_EXTRACTED; -} - -void usb_enable(bool on) -{ - /* Ignore usb enable/disable when ADB is enabled so we can fireup adb shell - * without entering ums mode - */ - if (!adb_mode) - { - sysfs_set_int("/sys/class/android_usb/android0/enable", on ? 1 : 0); - } -} - -/* This is called by usb thread after usb extract in order to return - * regular FS access - * - * returns the # of successful mounts -*/ -int disk_mount_all(void) -{ - const char *dev[] = {"/dev/mmcblk0p1", "/dev/mmcblk0"}; - const char *fs[] = {"vfat", "exfat"}; - - sysfs_set_string("/sys/class/android_usb/android0/f_mass_storage/lun/file", ""); - - for (int i=0; i<2; i++) - { - for (int j=0; j<2; j++) - { - if (mount(dev[i], "/mnt/sd_0", fs[j], 0, NULL) == 0) - { - return 1; - } - } - } - - return 0; -} - -/* This is called by usb thread after all threads ACKs usb inserted message - * - * returns the # of successful unmounts - */ -int disk_unmount_all(void) -{ - if (umount("/mnt/sd_0") == 0) - { - sysfs_set_string("/sys/class/android_usb/android0/f_mass_storage/lun/file", "/dev/mmcblk0"); - return 1; - } - - return 0; -} - -void usb_init_device(void) -{ - char functions[32] = {0}; - - /* Check if ADB was activated in bootloader */ - sysfs_get_string("/sys/class/android_usb/android0/functions", functions, sizeof(functions)); - adb_mode = (strstr(functions, "adb") == NULL) ? false : true; - - usb_enable(false); - - if (adb_mode) - { - sysfs_set_string("/sys/class/android_usb/android0/functions", "mass_storage,adb"); - sysfs_set_string("/sys/class/android_usb/android0/idVendor", "18D1"); - sysfs_set_string("/sys/class/android_usb/android0/idProduct", "D002"); - } - else - { - sysfs_set_string("/sys/class/android_usb/android0/functions", "mass_storage"); - sysfs_set_string("/sys/class/android_usb/android0/idVendor", "C502"); - sysfs_set_string("/sys/class/android_usb/android0/idProduct", "0029"); - } - - sysfs_set_string("/sys/class/android_usb/android0/iManufacturer", "Rockbox.org"); - sysfs_set_string("/sys/class/android_usb/android0/iProduct", "Rockbox media player"); - sysfs_set_string("/sys/class/android_usb/android0/iSerial", "0123456789ABCDEF"); - sysfs_set_string("/sys/class/android_usb/android0/f_mass_storage/inquiry_string", "xDuoo 0100"); -}