Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f3c8eb83 authored by Elliott Hughes's avatar Elliott Hughes Committed by Gerrit Code Review
Browse files

Merge "Remove dead tools."

parents 8eb770d3 30249770
Loading
Loading
Loading
Loading
+0 −5
Original line number Diff line number Diff line
@@ -215,11 +215,6 @@ LOCAL_SHARED_LIBRARIES := \
    libcutils \
    libselinux \

# libusbhost is only used by lsusb, and that isn't usually included in toolbox.
# The linker strips out all the unused library code in the normal case.
LOCAL_STATIC_LIBRARIES := \
    libusbhost \

LOCAL_WHOLE_STATIC_LIBRARIES := $(patsubst %,libtoolbox_%,$(BSD_TOOLS))

LOCAL_MODULE := toolbox

toolbox/alarm.c

deleted100644 → 0
+0 −190
Original line number Diff line number Diff line
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
#include <time.h>
#include <asm/ioctl.h>
//#include <linux/rtc.h>
#include <linux/android_alarm.h>

int alarm_main(int argc, char *argv[])
{
	int c;
    int res;
	struct tm tm;
	time_t t;
	struct timespec ts;
//	struct rtc_time rtc_time;
	char strbuf[26];
	int afd;
	int nfd;
//	struct timeval timeout = { 0, 0 };
    int wait = 0;
	fd_set rfds;
	const char wake_lock_id[] = "alarm_test"; 
	int waitalarmmask = 0;

    int useutc = 0;
	android_alarm_type_t alarmtype_low = ANDROID_ALARM_RTC_WAKEUP;
	android_alarm_type_t alarmtype_high = ANDROID_ALARM_RTC_WAKEUP;
	android_alarm_type_t alarmtype = 0;

    do {
        //c = getopt(argc, argv, "uw:");
        c = getopt(argc, argv, "uwat:");
        if (c == EOF)
            break;
        switch (c) {
        case 'u':
            useutc = 1;
            break;
		case 't':
			alarmtype_low = alarmtype_high = strtol(optarg, NULL, 0);
			break;
		case 'a':
			alarmtype_low = ANDROID_ALARM_RTC_WAKEUP;
			alarmtype_high = ANDROID_ALARM_TYPE_COUNT - 1;
			break;
        case 'w':
            //timeout.tv_sec = strtol(optarg, NULL, 0);
            wait = 1;
            break;
        case '?':
            fprintf(stderr, "%s: invalid option -%c\n",
                argv[0], optopt);
            exit(1);
        }
    } while (1);
    if(optind + 2 < argc) {
        fprintf(stderr,"%s [-uwa] [-t type] [seconds]\n", argv[0]);
        return 1;
    }

    afd = open("/dev/alarm", O_RDWR);
    if(afd < 0) {
        fprintf(stderr, "Unable to open rtc: %s\n", strerror(errno));
        return 1;
    }

    if(optind == argc) {
		for(alarmtype = alarmtype_low; alarmtype <= alarmtype_high; alarmtype++) {
			waitalarmmask |= 1U << alarmtype;
		}
#if 0
        res = ioctl(fd, RTC_ALM_READ, &tm);
        if(res < 0) {
            fprintf(stderr, "Unable to read alarm: %s\n", strerror(errno));
			return 1;
        }
#endif
#if 0
		t = timegm(&tm);
        if(useutc)
            gmtime_r(&t, &tm);
        else
            localtime_r(&t, &tm);
#endif
#if 0
        asctime_r(&tm, strbuf);
        printf("%s", strbuf);
#endif
    }
    else if(optind + 1 == argc) {
#if 0
        res = ioctl(fd, RTC_RD_TIME, &tm);
        if(res < 0) {
            fprintf(stderr, "Unable to set alarm: %s\n", strerror(errno));
			return 1;
        }
        asctime_r(&tm, strbuf);
        printf("Now: %s", strbuf);
        time(&tv.tv_sec);
#endif
#if 0
		time(&ts.tv_sec);
		ts.tv_nsec = 0;
		
        //strptime(argv[optind], NULL, &tm);
        //tv.tv_sec = mktime(&tm);
        //tv.tv_usec = 0;
#endif
		for(alarmtype = alarmtype_low; alarmtype <= alarmtype_high; alarmtype++) {
			waitalarmmask |= 1U << alarmtype;
		    res = ioctl(afd, ANDROID_ALARM_GET_TIME(alarmtype), &ts);
		    if(res < 0) {
		        fprintf(stderr, "Unable to get current time: %s\n", strerror(errno));
				return 1;
		    }
		    ts.tv_sec += strtol(argv[optind], NULL, 0);
		    //strtotimeval(argv[optind], &tv);
			gmtime_r(&ts.tv_sec, &tm);
		    printf("time %s -> %ld.%09ld\n", argv[optind], ts.tv_sec, ts.tv_nsec);
		    asctime_r(&tm, strbuf);
		    printf("Requested %s", strbuf);
			
		    res = ioctl(afd, ANDROID_ALARM_SET(alarmtype), &ts);
		    if(res < 0) {
		        fprintf(stderr, "Unable to set alarm: %s\n", strerror(errno));
				return 1;
		    }
		}
#if 0
        res = ioctl(fd, RTC_ALM_SET, &tm);
        if(res < 0) {
            fprintf(stderr, "Unable to set alarm: %s\n", strerror(errno));
			return 1;
        }
        res = ioctl(fd, RTC_AIE_ON);
        if(res < 0) {
            fprintf(stderr, "Unable to enable alarm: %s\n", strerror(errno));
			return 1;
        }
#endif
    }
    else {
        fprintf(stderr,"%s [-u] [date]\n", argv[0]);
        return 1;
    }

	if(wait) {
		while(waitalarmmask) {
			printf("wait for alarm %x\n", waitalarmmask);
			res = ioctl(afd, ANDROID_ALARM_WAIT);
			if(res < 0) {
				fprintf(stderr, "alarm wait failed\n");
			}
			printf("got alarm %x\n", res);
			waitalarmmask &= ~res;
			nfd = open("/sys/android_power/acquire_full_wake_lock", O_RDWR);
			write(nfd, wake_lock_id, sizeof(wake_lock_id) - 1);
			close(nfd);
			//sleep(5);
			nfd = open("/sys/android_power/release_wake_lock", O_RDWR);
			write(nfd, wake_lock_id, sizeof(wake_lock_id) - 1);
			close(nfd);
		}
		printf("done\n");
	}
#if 0	
	FD_ZERO(&rfds);
	FD_SET(fd, &rfds);
	res = select(fd + 1, &rfds, NULL, NULL, &timeout);
    if(res < 0) {
        fprintf(stderr, "select failed: %s\n", strerror(errno));
		return 1;
    }
	if(res > 0) {
		int event;
		read(fd, &event, sizeof(event));
		fprintf(stderr, "got %x\n", event);
	}
	else {
		fprintf(stderr, "timeout waiting for alarm\n");
	}
#endif

    close(afd);

    return 0;
}

toolbox/exists.c

deleted100644 → 0
+0 −16
Original line number Diff line number Diff line
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>

int exists_main(int argc, char *argv[])
{
    struct stat s;

    if(argc < 2) return 1;

    if(stat(argv[1], &s)) {
        return 1;
    } else {
        return 0;
    }
}

toolbox/lsusb.c

deleted100644 → 0
+0 −227
Original line number Diff line number Diff line
/*
 * Copyright (C) 2010 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <endian.h>
#include <errno.h>
#include <stdio.h>
#include <stdint.h>
#include <string.h>

#include <usbhost/usbhost.h>

static int verbose = 0;
static char str_buff[4096];

static const char *get_str(struct usb_device *dev, int id)
{
    char *str = usb_device_get_string(dev, id);

    if (id && str) {
        strlcpy(str_buff, str, sizeof(str_buff));
        free(str);
    } else {
        snprintf(str_buff, sizeof(str_buff), "%02x", id);
    }

    return str_buff;
}


static void lsusb_parse_device_descriptor(struct usb_device *dev,
                                          struct usb_device_descriptor *desc)
{
    printf("  Device Descriptor\n");
    printf("\tbcdUSB: %04x\n", letoh16(desc->bcdUSB));
    printf("\tbDeviceClass: %02x\n", desc->bDeviceClass);
    printf("\tbDeviceSubClass: %02x\n", desc->bDeviceSubClass);
    printf("\tbDeviceProtocol: %02x\n", desc->bDeviceProtocol);
    printf("\tbMaxPacketSize0: %02x\n", desc->bMaxPacketSize0);
    printf("\tidVendor: %04x\n", letoh16(desc->idVendor));
    printf("\tidProduct: %04x\n", letoh16(desc->idProduct));
    printf("\tbcdDevice: %04x\n", letoh16(desc->bcdDevice));
    printf("\tiManufacturer: %s\n", get_str(dev, desc->iManufacturer));
    printf("\tiProduct: %s\n", get_str(dev, desc->iProduct));
    printf("\tiSerialNumber: %s\n", get_str(dev,desc->iSerialNumber));
    printf("\tbNumConfiguration: %02x\n", desc->bNumConfigurations);
    printf("\n");
}

static void lsusb_parse_config_descriptor(struct usb_device *dev,
                                          struct usb_config_descriptor *desc)
{
    printf("  Config Descriptor\n");
    printf("\twTotalLength: %04x\n", letoh16(desc->wTotalLength));
    printf("\tbNumInterfaces: %02x\n", desc->bNumInterfaces);
    printf("\tbConfigurationValue: %02x\n", desc->bConfigurationValue);
    printf("\tiConfiguration: %s\n", get_str(dev, desc->iConfiguration));
    printf("\tbmAttributes: %02x\n", desc->bmAttributes);
    printf("\tbMaxPower: %d mA\n", desc->bMaxPower * 2);
    printf("\n");
}

static void lsusb_parse_interface_descriptor(struct usb_device *dev,
                                             struct usb_interface_descriptor *desc)
{
    printf("  Interface Descriptor\n");
    printf("\tbInterfaceNumber: %02x\n", desc->bInterfaceNumber);
    printf("\tbAlternateSetting: %02x\n", desc->bAlternateSetting);
    printf("\tbNumEndpoints: %02x\n", desc->bNumEndpoints);
    printf("\tbInterfaceClass: %02x\n", desc->bInterfaceClass);
    printf("\tbInterfaceSubClass: %02x\n", desc->bInterfaceSubClass);
    printf("\tbInterfaceProtocol: %02x\n", desc->bInterfaceProtocol);
    printf("\tiInterface: %s\n", get_str(dev, desc->iInterface));
    printf("\n");
}

static void lsusb_parse_endpoint_descriptor(struct usb_device *dev,
                                            struct usb_endpoint_descriptor *desc)
{
    printf("  Endpoint Descriptor\n");
    printf("\tbEndpointAddress: %02x\n", desc->bEndpointAddress);
    printf("\tbmAttributes: %02x\n", desc->bmAttributes);
    printf("\twMaxPacketSize: %02x\n", letoh16(desc->wMaxPacketSize));
    printf("\tbInterval: %02x\n", desc->bInterval);
    printf("\tbRefresh: %02x\n", desc->bRefresh);
    printf("\tbSynchAddress: %02x\n", desc->bSynchAddress);
    printf("\n");
}

static void lsusb_dump_descriptor(struct usb_device *dev,
                                  struct usb_descriptor_header *desc)
{
    int i;
    printf("  Descriptor type %02x\n", desc->bDescriptorType);

    for (i = 0; i < desc->bLength; i++ ) {
        if ((i % 16) == 0)
            printf("\t%02x:", i);
        printf(" %02x", ((uint8_t *)desc)[i]);
        if ((i % 16) == 15)
            printf("\n");
    }

    if ((i % 16) != 0)
        printf("\n");
    printf("\n");
}

static void lsusb_parse_descriptor(struct usb_device *dev,
                                   struct usb_descriptor_header *desc)
{
    switch (desc->bDescriptorType) {
    case USB_DT_DEVICE:
        lsusb_parse_device_descriptor(dev, (struct usb_device_descriptor *) desc);
        break;

    case USB_DT_CONFIG:
        lsusb_parse_config_descriptor(dev, (struct usb_config_descriptor *) desc);
        break;

    case USB_DT_INTERFACE:
        lsusb_parse_interface_descriptor(dev, (struct usb_interface_descriptor *) desc);
        break;

    case USB_DT_ENDPOINT:
        lsusb_parse_endpoint_descriptor(dev, (struct usb_endpoint_descriptor *) desc);
        break;

    default:
        lsusb_dump_descriptor(dev, desc);

        break;
    }
}

static int lsusb_device_added(const char *dev_name, void *client_data)
{
    struct usb_device *dev = usb_device_open(dev_name);

    if (!dev) {
        fprintf(stderr, "can't open device %s: %s\n", dev_name, strerror(errno));
        return 0;
    }

    if (verbose) {
        struct usb_descriptor_iter iter;
        struct usb_descriptor_header *desc;

        printf("%s:\n", dev_name);

        usb_descriptor_iter_init(dev, &iter);

        while ((desc = usb_descriptor_iter_next(&iter)) != NULL)
            lsusb_parse_descriptor(dev, desc);

    } else {
        uint16_t vid, pid;
        char *mfg_name, *product_name, *serial;

        vid = usb_device_get_vendor_id(dev);
        pid = usb_device_get_product_id(dev);
        mfg_name = usb_device_get_manufacturer_name(dev);
        product_name = usb_device_get_product_name(dev);
        serial = usb_device_get_serial(dev);

        printf("%s: %04x:%04x %s %s %s\n", dev_name, vid, pid,
               mfg_name, product_name, serial);

        free(mfg_name);
        free(product_name);
        free(serial);
    }

    usb_device_close(dev);

    return 0;
}

static int lsusb_device_removed(const char *dev_name, void *client_data)
{
    return 0;
}


static int lsusb_discovery_done(void *client_data)
{
    return 1;
}



int lsusb_main(int argc, char **argv)
{
    struct usb_host_context *ctx;

    if (argc == 2 && !strcmp(argv[1], "-v"))
        verbose = 1;

    ctx = usb_host_init();
    if (!ctx) {
        perror("usb_host_init:");
        return 1;
    }

    usb_host_run(ctx,
                 lsusb_device_added,
                 lsusb_device_removed,
                 lsusb_discovery_done,
                 NULL);

    usb_host_cleanup(ctx);

    return 0;
}

toolbox/rotatefb.c

deleted100644 → 0
+0 −71
Original line number Diff line number Diff line
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <string.h>
#include <termios.h>
#include <unistd.h>
#include <errno.h>
#include <linux/fb.h>


int rotatefb_main(int argc, char *argv[])
{
    int c;
    char *fbdev = "/dev/graphics/fb0";
    int rotation = 0;
    int fd;
    int res;
    struct fb_var_screeninfo fbinfo;

    do {
        c = getopt(argc, argv, "d:");
        if (c == EOF)
            break;
        switch (c) {
        case 'd':
            fbdev = optarg;
            break;
        case '?':
            fprintf(stderr, "%s: invalid option -%c\n",
                argv[0], optopt);
            exit(1);
        }
    } while (1);

    if(optind + 1 != argc) {
        fprintf(stderr, "%s: specify rotation\n", argv[0]);
        exit(1);
    }
    rotation = atoi(argv[optind]);

    fd = open(fbdev, O_RDWR);
    if(fd < 0) {
        fprintf(stderr, "cannot open %s\n", fbdev);
        return 1;
    }

    res = ioctl(fd, FBIOGET_VSCREENINFO, &fbinfo);
    if(res < 0) {
        fprintf(stderr, "failed to get fbinfo: %s\n", strerror(errno));
        return 1;
    }
    if((fbinfo.rotate ^ rotation) & 1) {
        unsigned int xres = fbinfo.yres;
        fbinfo.yres = fbinfo.xres;
        fbinfo.xres = xres;
        fbinfo.xres_virtual = fbinfo.xres;
        fbinfo.yres_virtual = fbinfo.yres * 2;
        if(fbinfo.yoffset == xres)
            fbinfo.yoffset = fbinfo.yres;
    }
    fbinfo.rotate = rotation; 
    res = ioctl(fd, FBIOPUT_VSCREENINFO, &fbinfo);
    if(res < 0) {
        fprintf(stderr, "failed to set fbinfo: %s\n", strerror(errno));
        return 1;
    }

    return 0;
}
Loading