diff options
-rw-r--r-- | android/console.c | 135 | ||||
-rw-r--r-- | hw/goldfish_device.h | 3 | ||||
-rw-r--r-- | hw/goldfish_mmc.c | 17 |
3 files changed, 149 insertions, 6 deletions
diff --git a/android/console.c b/android/console.c index ab32213..45da8aa 100644 --- a/android/console.c +++ b/android/console.c @@ -31,6 +31,8 @@ #include "hw/power_supply.h" #include "shaper.h" #include "modem_driver.h" +#include "block.h" +#include "block_int.h" #include "android/gps.h" #include "android/globals.h" #include "android/utils/bufprint.h" @@ -2066,6 +2068,135 @@ static const CommandDefRec geo_commands[] = /********************************************************************************************/ /********************************************************************************************/ /***** ******/ +/***** S D C A R D C O M M A N D S ******/ +/***** ******/ +/********************************************************************************************/ +/********************************************************************************************/ + +static int +do_sdcard_insert( ControlClient client, char* args ) +{ + char img[255]; + char *p; + int n; + int drv_idx; + + if (!args) { + control_write( client, "K0: argument missing, try 'sdcard insert <slot #> [imagefile]'\r\n" ); + return -1; + } + + memset(img, 0, sizeof(img)); + + n = strtoul(args, &p, 0); + if (n > 2) { + control_write( client, "K0: argument out of range\r\n" ); + return -1; + } + + if (p) { + p++; + strncpy(img, p, sizeof(img) -1); + } + + if (goldfish_mmc_is_media_inserted(n)) { + control_write( client, "K0: Slot %d already has media inserted\r\n", n ); + return -1; + } + + drv_idx = drive_get_index( IF_IDE, 0, n); + if (drv_idx >= 0) { + if (img[0] != '\0' && strcmp(img, drives_table[drv_idx].bdrv->filename)) { + if (drive_swap(drives_table[drv_idx].bdrv, img)) { + control_write (client, "K0: Drive swap failed\r\n"); + return -1; + } + } + } else { + drv_idx = drive_hotadd(img, "index=%d,media=disk", n); + if (drv_idx < 0) { + control_write (client, "K0: Drive hot-add failed\r\n"); + return -1; + } + } + + goldfish_mmc_insert(n, drives_table[drv_idx].bdrv); + + return 0; +} + +static int +do_sdcard_remove( ControlClient client, char* args ) +{ + int n; + int ins; + + if (!args) { + control_write( client, "K0: argument missing, try 'sdcard remove <slot #>'\r\n" ); + return -1; + } + + n = atoi(args); + + if ((ins = goldfish_mmc_is_media_inserted(n)) < 0) { + control_write( client, "K0: Slot %d is invalid\r\n", n ); + } else if (!ins) { + control_write( client, "K0: Slot %d has no media\r\n", n ); + return -1; + } + + goldfish_mmc_remove(n); + return 0; +} + +static int +do_sdcard_status( ControlClient client, char* args ) +{ + int i; + control_write( client, "Current SD card status:\r\n" ); + + for (i = 0; i < 2; i++) { + int drv_idx = drive_get_index( IF_IDE, 0, i); + + control_write( client, + " Slot %d, image %s, inserted %d\r\n", i, + (drv_idx >=0 ? drives_table[drv_idx].bdrv->filename : "none"), + goldfish_mmc_is_media_inserted(i)); + } + return 0; +} + +static int +do_sdcard_fail( ControlClient client, char* args ) +{ + return -ENOSYS; +} + +static const CommandDefRec sdcard_commands[] = +{ + { "insert", "hot-insert a virtual sdcard", + "'sdcard insert <slot #> [imagefile]'\r\n", + NULL, do_sdcard_insert, NULL }, + + { "remove", "hot-remove a virtual sdcard", + "'sdcard remove <slot #>'\r\n", + NULL, do_sdcard_remove, NULL }, + + { "status", "query virtual device status", + "'sdcard status'\r\n", + NULL, do_sdcard_status, NULL }, + + { "fail", "simulate an sdcard failure", + "'sdcard fail <read|write>'\r\n", + NULL, do_sdcard_fail, NULL }, + + { NULL, NULL, NULL, NULL, NULL, NULL } +}; + + +/********************************************************************************************/ +/********************************************************************************************/ +/***** ******/ /***** M A I N C O M M A N D S ******/ /***** ******/ /********************************************************************************************/ @@ -2176,6 +2307,10 @@ static const CommandDefRec main_commands[] = "allows you to modify the emulator window\r\n", NULL, NULL, window_commands }, + { "sdcard", "manage emulator sdcards", + "allows you to modify the emulator sdcard configuration\r\n", NULL, + NULL, sdcard_commands }, + { NULL, NULL, NULL, NULL, NULL, NULL } }; diff --git a/hw/goldfish_device.h b/hw/goldfish_device.h index 7eb21de..d0739b7 100644 --- a/hw/goldfish_device.h +++ b/hw/goldfish_device.h @@ -49,7 +49,8 @@ void goldfish_battery_display(void (* callback)(void *data, const char* string), void goldfish_mmc_init(uint32_t base, int id); void goldfish_mmc_insert(int id, BlockDriverState* bs); -void goldfish_mmc_remove(int id, BlockDriverState *bs); +void goldfish_mmc_remove(int id); +int goldfish_mmc_is_media_inserted(int id); void *goldfish_switch_add(char *name, uint32_t (*writefn)(void *opaque, uint32_t state), void *writeopaque, int id); void goldfish_switch_set_state(void *opaque, uint32_t state); diff --git a/hw/goldfish_mmc.c b/hw/goldfish_mmc.c index 124f865..8b5c137 100644 --- a/hw/goldfish_mmc.c +++ b/hw/goldfish_mmc.c @@ -560,18 +560,25 @@ static void goldfish_mmc_setbs(struct goldfish_mmc_state* s, BlockDriverState* b void goldfish_mmc_insert(int id, BlockDriverState* bs) { if (id >= GOLDFISH_MMC_MAX) { - fprintf(stderr, "mmc controller %d out of range\n", id); - return; + return -1; } goldfish_mmc_setbs(gDrvState[id], bs); } -void goldfish_mmc_remove(int id, BlockDriverState* bs) +int goldfish_mmc_is_media_inserted(int id) +{ + if (id > GOLDFISH_MMC_MAX) { + return -1; + } + + return (gDrvState[id]->bs != NULL); +} + +void goldfish_mmc_remove(int id) { if (id >= GOLDFISH_MMC_MAX) { - fprintf(stderr, "mmc controller %d out of range\n", id); - return; + return -1; } goldfish_mmc_setbs(gDrvState[id], NULL); |