Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a6ec475a92 | ||
|
|
783222ed00 | ||
|
|
a6ef73359c |
No files matched your search
@@ -7,3 +7,7 @@ LDFLAGS+=-L/usr/pkg/lib -Wl,-R/usr/pkg/lib
|
||||
|
||||
HAVE_USB=1
|
||||
HAVE_GUI=1
|
||||
|
||||
# For linking against this copy of libusb
|
||||
#CFLAGS+=-I../libusb
|
||||
|
||||
@@ -60,6 +60,7 @@ int compress_image(char *srcf, char *dstf, int w, int h)
|
||||
fdout = open( dstf, O_TRUNC | O_CREAT | O_WRONLY , 0660 );
|
||||
if (fdout == -1) {
|
||||
printf("Cannot open file '%s' for writing\n", dstf);
|
||||
fclose(fd);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -107,5 +107,7 @@ int rgb2yuv(char *from, char *to, int width, int height)
|
||||
for ( i = 0 ; i < height ; i+=2 )
|
||||
for ( j = 0; j < width ; j +=2 )
|
||||
write ( fout,&dstV[j+(i*width)], 1);
|
||||
|
||||
free(dstV); free(dstU); free(dstY); free(src);
|
||||
return 1;
|
||||
}
|
||||
@@ -119,5 +119,6 @@ int uncompress_image(char *srcf, char *dstf)
|
||||
//printf("logotool -w %d -h %d -v %s\n", width, height, dstf);
|
||||
printf("eval PATH=$PWD:$PATH logotool -w %d -h %d -m %s\n", width, height, dstf);
|
||||
|
||||
free(dst); free(src);
|
||||
return 0;
|
||||
}
|
||||
@@ -1,388 +0,0 @@
|
||||
/*
|
||||
cold-flash.c - Cold flashing
|
||||
Copyright (C) 2011-2012 Pali Rohár <pali.rohar@gmail.com>
|
||||
|
||||
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 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <usb.h>
|
||||
|
||||
#define READ_DEV 0x81
|
||||
#define WRITE_DEV 0x01
|
||||
#define READ_TIMEOUT 500
|
||||
#define WRITE_TIMEOUT 3000
|
||||
|
||||
static uint32_t tab[256];
|
||||
|
||||
static void crc32_gentab(void) {
|
||||
|
||||
int i, j;
|
||||
uint32_t crc;
|
||||
uint32_t poly = 0xEDB88320L;
|
||||
|
||||
for ( i = 0; i < 256; i++) {
|
||||
|
||||
crc = i;
|
||||
|
||||
for ( j = 8; j > 0; j-- ) {
|
||||
|
||||
if (crc & 1)
|
||||
crc = (crc >> 1) ^ poly;
|
||||
else
|
||||
crc >>= 1;
|
||||
|
||||
}
|
||||
|
||||
tab[i] = crc;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static uint32_t crc32(unsigned char * bytes, size_t size, uint32_t crc) {
|
||||
|
||||
static int gen = 0;
|
||||
uint32_t i;
|
||||
|
||||
if ( ! gen ) {
|
||||
crc32_gentab();
|
||||
gen = 1;
|
||||
}
|
||||
|
||||
for ( i = 0; i < size; ++i )
|
||||
crc = (crc >> 8) ^ tab[(crc ^ bytes[i]) & 0xff];
|
||||
|
||||
return crc;
|
||||
|
||||
}
|
||||
|
||||
/* Omap download message */
|
||||
static const uint8_t omap_download_msg[4] = { 0x02, 0x00, 0x03, 0xF0 };
|
||||
|
||||
/* Structure of X-Loader message */
|
||||
struct xloader_msg {
|
||||
uint8_t type[4]; /* 4 bytes - type of message */
|
||||
uint8_t size[4]; /* 4 bytes - size of file */
|
||||
uint8_t crc1[4]; /* 4 bytes - crc32 of file */
|
||||
uint8_t crc2[4]; /* 4 bytes - crc32 of first 12 bytes of message */
|
||||
};
|
||||
|
||||
#define XLOADER_MSG_TYPE_PING 0x6301326E
|
||||
#define XLOADER_MSG_TYPE_SEND 0x6302326E
|
||||
|
||||
struct xloader_msg xloader_msg_create(uint32_t type, FILE * file, size_t offset, uint32_t size) {
|
||||
|
||||
struct xloader_msg msg;
|
||||
uint8_t buffer[1024];
|
||||
size_t need, readed;
|
||||
uint32_t crc = 0;
|
||||
int ret;
|
||||
|
||||
memcpy(msg.type, &type, 4);
|
||||
memcpy(msg.size, &size, 4);
|
||||
|
||||
if ( file ) {
|
||||
fseek(file, offset, SEEK_SET);
|
||||
readed = 0;
|
||||
while ( readed < size ) {
|
||||
need = size - readed;
|
||||
if ( need > sizeof(buffer) )
|
||||
need = sizeof(buffer);
|
||||
ret = fread(buffer, 1, need, file);
|
||||
if ( ret < 0 )
|
||||
break;
|
||||
crc = crc32(buffer, ret, crc);
|
||||
readed += ret;
|
||||
}
|
||||
}
|
||||
|
||||
memcpy(msg.crc1, &crc, 4);
|
||||
|
||||
crc = crc32((unsigned char *)&msg, 12, 0);
|
||||
memcpy(msg.crc2, &crc, 4);
|
||||
|
||||
return msg;
|
||||
|
||||
}
|
||||
|
||||
static int read_asic(usb_dev_handle * udev) {
|
||||
|
||||
uint8_t asic_buffer[127];
|
||||
int asic_size = 69;
|
||||
int i, ret;
|
||||
|
||||
printf("Waiting for ASIC ID...\n");
|
||||
ret = usb_bulk_read(udev, READ_DEV, (char *)asic_buffer, sizeof(asic_buffer), READ_TIMEOUT);
|
||||
if ( ret != asic_size ) {
|
||||
fprintf(stderr, "Invalid size of ASIC ID\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
printf("Got ASIC ID:");
|
||||
for ( i = 0; i < asic_size; ++i )
|
||||
printf(" 0x%.2X", (unsigned int)asic_buffer[i]);
|
||||
printf("\n");
|
||||
|
||||
return 1;
|
||||
|
||||
}
|
||||
|
||||
static int send_2nd(usb_dev_handle * udev, FILE * file, size_t offset, size_t size) {
|
||||
|
||||
uint8_t buffer[1024];
|
||||
uint32_t size32;
|
||||
size_t need, readed;
|
||||
int ret;
|
||||
|
||||
size32 = size;
|
||||
fseek(file, offset, SEEK_SET);
|
||||
|
||||
if ( size == 0 ) {
|
||||
fprintf(stderr, "2nd X-Loader image has zero size\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ( size > UINT32_MAX ) {
|
||||
fprintf(stderr, "2nd X-Loader image is too big\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
printf("Sending OMAP download message...\n");
|
||||
ret = usb_bulk_write(udev, WRITE_DEV, (char *)omap_download_msg, sizeof(omap_download_msg), WRITE_TIMEOUT);
|
||||
usleep(5000);
|
||||
if ( ret != sizeof(omap_download_msg) ) {
|
||||
fprintf(stderr, "Error while sending OMAP download message\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
printf("Sending 2nd X-Loader image size...\n");
|
||||
ret = usb_bulk_write(udev, WRITE_DEV, (char *)&size32, sizeof(size32), WRITE_TIMEOUT);
|
||||
usleep(5000);
|
||||
if ( ret != sizeof(size32) ) {
|
||||
fprintf(stderr, "Error while sending 2nd X-Loader image size\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
printf("Sending 2nd X-Loader image...\n");
|
||||
readed = 0;
|
||||
while ( readed < size ) {
|
||||
need = size - readed;
|
||||
if ( need > sizeof(buffer) )
|
||||
need = sizeof(buffer);
|
||||
ret = fread(buffer, 1, need, file);
|
||||
if ( ret < 0 )
|
||||
break;
|
||||
if ( usb_bulk_write(udev, WRITE_DEV, (char *)buffer, ret, WRITE_TIMEOUT) != ret ) {
|
||||
fprintf(stderr, "Error while sending 2nd X-Loader image\n");
|
||||
return 0;
|
||||
}
|
||||
readed += ret;
|
||||
}
|
||||
usleep(50000);
|
||||
|
||||
return 1;
|
||||
|
||||
}
|
||||
|
||||
static int send_secondary(usb_dev_handle * udev, FILE * file, size_t offset, size_t size) {
|
||||
|
||||
struct xloader_msg init_msg;
|
||||
uint8_t buffer[1024];
|
||||
uint32_t size32;
|
||||
size_t need, readed;
|
||||
int ret;
|
||||
|
||||
size32 = size;
|
||||
fseek(file, offset, SEEK_SET);
|
||||
|
||||
if ( size == 0 ) {
|
||||
fprintf(stderr, "2nd Secondary image has zero size\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ( size > UINT32_MAX ) {
|
||||
fprintf(stderr, "2nd Secondary image is too big\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
init_msg = xloader_msg_create(XLOADER_MSG_TYPE_SEND, file, offset, size32);
|
||||
|
||||
printf("Sending X-Loader init message...\n");
|
||||
ret = usb_bulk_write(udev, WRITE_DEV, (char *)&init_msg, sizeof(init_msg), WRITE_TIMEOUT);
|
||||
usleep(5000);
|
||||
if ( ret != sizeof(init_msg) ) {
|
||||
fprintf(stderr, "Error while sending X-Loader init message\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
printf("Waiting for X-Loader response...\n");
|
||||
ret = usb_bulk_read(udev, READ_DEV, (char *)&size32, sizeof(size32), READ_TIMEOUT); /* size32 - dummy value */
|
||||
if ( ret != sizeof(size32) ) {
|
||||
fprintf(stderr, "Error no response\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
printf("Sending Secondary image...\n");
|
||||
readed = 0;
|
||||
while ( readed < size ) {
|
||||
need = size - readed;
|
||||
if ( need > sizeof(buffer) )
|
||||
need = sizeof(buffer);
|
||||
ret = fread(buffer, 1, need, file);
|
||||
if ( ret < 0 )
|
||||
break;
|
||||
if ( usb_bulk_write(udev, WRITE_DEV, (char *)buffer, ret, WRITE_TIMEOUT) != ret ) {
|
||||
fprintf(stderr, "Error while sending Secondary image\n");
|
||||
return 0;
|
||||
}
|
||||
readed += ret;
|
||||
}
|
||||
usleep(5000);
|
||||
|
||||
printf("Waiting for X-Loader response...\n");
|
||||
ret = usb_bulk_read(udev, READ_DEV, (char *)&size32, sizeof(size32), READ_TIMEOUT); /* size32 - dummy value */
|
||||
if ( ret != sizeof(size32) ) {
|
||||
fprintf(stderr, "Error no response\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
||||
}
|
||||
|
||||
static int ping_timeout(usb_dev_handle * udev) {
|
||||
|
||||
int ret;
|
||||
int pong = 0;
|
||||
int try_ping = 10;
|
||||
|
||||
while ( try_ping > 0 ) {
|
||||
|
||||
struct xloader_msg ping_msg = xloader_msg_create(XLOADER_MSG_TYPE_PING, NULL, 0, 0);
|
||||
int try_read = 4;
|
||||
|
||||
printf("Sending X-Loader ping message\n");
|
||||
ret = usb_bulk_write(udev, WRITE_DEV, (char *)&ping_msg, sizeof(ping_msg), WRITE_TIMEOUT);
|
||||
if ( ret != sizeof(ping_msg) ) {
|
||||
fprintf(stderr, "Error while sending X-Loader ping message\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
printf("Waiting for X-Loader pong response...\n");
|
||||
while ( try_read > 0 ) {
|
||||
|
||||
uint32_t ping_read;
|
||||
ret = usb_bulk_read(udev, READ_DEV, (char *)&ping_read, sizeof(ping_read), READ_TIMEOUT);
|
||||
if ( ret == sizeof(ping_read) ) {
|
||||
printf("Got it\n");
|
||||
pong = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
usleep(5000);
|
||||
--try_read;
|
||||
|
||||
}
|
||||
|
||||
if ( pong )
|
||||
break;
|
||||
|
||||
printf("Responce timeout\n");
|
||||
--try_ping;
|
||||
|
||||
}
|
||||
|
||||
if (pong)
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
int cold_flash(usb_dev_handle * udev, const char * x2nd, const char * secondary) {
|
||||
|
||||
size_t size1, size2;
|
||||
FILE * file1 = NULL;
|
||||
FILE * file2 = NULL;
|
||||
int ret = 1;
|
||||
|
||||
file1 = fopen(x2nd, "r");
|
||||
if ( ! file1 ) {
|
||||
fprintf(stderr, "Cannot open 2nd X-Loader file '%s': %s\n", x2nd, strerror(errno));
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
file2 = fopen(secondary, "r");
|
||||
if ( ! file2 ) {
|
||||
fprintf(stderr, "Cannot open Secondary file '%s': %s\n", secondary, strerror(errno));
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
fseek(file1, 0, SEEK_END);
|
||||
size1 = ftell(file1);
|
||||
|
||||
fseek(file2, 0, SEEK_END);
|
||||
size2 = ftell(file2);
|
||||
|
||||
if ( usb_set_configuration(udev, 1) < 0 ) {
|
||||
fprintf(stderr, "usb_set_configuration failed: %s\n", strerror(errno));
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if ( usb_claim_interface(udev, 1) < 0 ) {
|
||||
fprintf(stderr, "usb_claim_interface failed: %s\n", strerror(errno));
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if ( ! read_asic(udev) ) {
|
||||
fprintf(stderr, "Reading ASIC ID failed\n");
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if ( ! send_2nd(udev, file1, size1, 0) ) {
|
||||
fprintf(stderr, "Sending 2nd X-Loader image failed\n");
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if ( ! ping_timeout(udev) ) {
|
||||
fprintf(stderr, "Sending X-Loader ping failed\n");
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if ( ! send_secondary(udev, file2, size2, 0) ) {
|
||||
fprintf(stderr, "Sending Secondary image failed\n");
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
printf("Done\n");
|
||||
ret = 0;
|
||||
|
||||
cleanup:
|
||||
if (file1)
|
||||
fclose(file1);
|
||||
if (file2)
|
||||
fclose(file2);
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
/*int fiasco_cold_flash(usb_dev_handle * udev, const char * device, const char * hw_rev, const char * fiasco) {
|
||||
|
||||
|
||||
}*/
|
||||
+4
-4
@@ -69,17 +69,14 @@ __rf_extract_exit:
|
||||
* This function was covardly copied from nanddump.c @ mtd-utils-20060907
|
||||
*/
|
||||
#define _GNU_SOURCE
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <getopt.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
//#include <asm/types.h>
|
||||
#include <mtd/mtd-user.h>
|
||||
#ifndef loff_t
|
||||
@@ -172,6 +169,9 @@ int check_badblocks(char *mtddev)
|
||||
return 1;
|
||||
}
|
||||
|
||||
memset(&stat1, 0, sizeof(stat1));
|
||||
memset(&stat2, 0, sizeof(stat2));
|
||||
|
||||
fprintf(stderr, "Block size %u, page size %u, OOB size %u\n",
|
||||
meminfo.erasesize, meminfo.writesize, meminfo.oobsize);
|
||||
fprintf(stderr, "Size %u, flags %u, type 0x%x\n",
|
||||
@@ -513,7 +513,7 @@ int dump_config()
|
||||
break;
|
||||
if (!memcmp(buf,"ConF", 4)) {
|
||||
loop:
|
||||
read(fd, buf, 4);
|
||||
ret = read(fd, buf, 4);
|
||||
if (ret == -1) break;
|
||||
printf("\n0x%08x : ConF %02x %02x %02x %02x : ", i,
|
||||
buf[0], buf[1], buf[2], buf[3]);
|
||||
|
||||
+6
-1
@@ -42,7 +42,12 @@ long fpid_size(const char *filename)
|
||||
{
|
||||
long sz;
|
||||
FILE *fd = fopen(filename, "r");
|
||||
fseek(fd, 0, SEEK_END);
|
||||
if (fd == NULL)
|
||||
return -1;
|
||||
if (fseek(fd, 0, SEEK_END) != 0) {
|
||||
fclose(fd);
|
||||
return -1;
|
||||
}
|
||||
sz = ftell(fd);
|
||||
fclose(fd);
|
||||
return sz;
|
||||
|
||||
+3
-1
@@ -44,8 +44,10 @@ usho do_hash_file(const char *filename, const char *type)
|
||||
|
||||
do {
|
||||
ret = fread(&buf, 1, BSIZE, fd);
|
||||
if (ret == -1)
|
||||
if (ret == -1) {
|
||||
fclose(fd);
|
||||
return 0;
|
||||
}
|
||||
hash ^= do_hash((usho *)&buf, ret);
|
||||
} while(ret);
|
||||
|
||||
|
||||
-99
@@ -68,105 +68,6 @@ void show_usage()
|
||||
int i;
|
||||
show_title();
|
||||
|
||||
#if 0
|
||||
// TODO: remove console: serial.c
|
||||
// TODO: remove inject usb and supported list
|
||||
// TODO: remove option for calculate hash
|
||||
|
||||
printf (""
|
||||
|
||||
#if defined(WITH_USB) && ! defined(WITH_DEVICE)
|
||||
"Over USB:\n"
|
||||
" -b [cmdline] boot default or loaded kernel with cmdline (default: use default kernel cmdline)\n"
|
||||
" -R reboot device\n"
|
||||
" -l load all specified images to RAM\n"
|
||||
" -f flash all specified images\n"
|
||||
" -c cold flash 2nd and secondary images\n"
|
||||
"\n"
|
||||
#endif
|
||||
|
||||
#ifdef WITH_DEVICE
|
||||
"On device:\n"
|
||||
" -R reboot device\n"
|
||||
" -f flash all specified images\n"
|
||||
" -x [/dev/mtd] check for bad blocks on mtd device (default: check all)\n"
|
||||
" -E dump all images from device to fiasco image, see -M and -t\n"
|
||||
" -e [dir] dump all images from device to directory, see -t (default: current dir)\n"
|
||||
"\n"
|
||||
#endif
|
||||
|
||||
#if defined(WITH_USB) || defined(WITH_DEVICE)
|
||||
"Device configuration:\n"
|
||||
" -i identify, show all information about device\n"
|
||||
" -D 0|1|2 change root device: 0 - flash, 1 - mmc, 2 - usb\n"
|
||||
" -U 0|1 disable/enable USB host mode\n"
|
||||
" -r 0|1 disable/enable R&D mode\n"
|
||||
" -F flags change R&D flags, flags are comma separated list, can be empty\n"
|
||||
" -H rev change HW revision\n"
|
||||
" -K ver change kernel version string\n"
|
||||
" -N ver change NOLO version string\n"
|
||||
" -S ver change SW release version string\n"
|
||||
" -C ver change content eMMC version string\n"
|
||||
"\n"
|
||||
#endif
|
||||
|
||||
"Normal image specification:\n"
|
||||
" -m [arg] specify normal image\n"
|
||||
" arg is [[[dev:[hw:]]ver:]type:]file[%%lay]\n"
|
||||
" dev is device name string (default: emtpy)\n"
|
||||
" hw are comma separated list of HW revisions (default: empty)\n"
|
||||
" ver is image version string (default: empty)\n"
|
||||
" type is image type (default: try autodetect)\n"
|
||||
" file is image file name\n"
|
||||
" lay is layout file name (default: none)\n"
|
||||
"\n"
|
||||
|
||||
"Fiasco image specification:\n"
|
||||
" -M file specify input fiasco image\n"
|
||||
" -t [types] filter images by comma separated list of image types (default: do not filter)\n"
|
||||
" -d [dev] filter images by device (default: do not filter)\n"
|
||||
" -w [hw] filter images by HW revision (default: do not filter)\n"
|
||||
" -u [dir] unpack fiasco image to directory (default: current dir)\n"
|
||||
" -g [ver] generate fiasco image for SW release version (default: without SW release)\n"
|
||||
"\n"
|
||||
|
||||
"Other options:\n"
|
||||
" -I identify images\n"
|
||||
#if defined(WITH_USB) || defined(WITH_DEVICE)
|
||||
" -c console prompt mode\n"
|
||||
#endif
|
||||
#if ( defined(WITH_USB) || defined(WITH_DEVICE) ) && defined(WITH_SQUEUES)
|
||||
" -Q enter shared queues server mode (for gui or remote)\n"
|
||||
#endif
|
||||
" -s simulate, do not flash or write on disk\n"
|
||||
" -n disable hash, checksum and image type checking\n"
|
||||
" -v be verbose and noisy\n"
|
||||
" -V show 0xFFFF version information\n"
|
||||
" -h show this help message\n"
|
||||
"\n"
|
||||
|
||||
#if defined(WITH_USB) || defined(WITH_DEVICE)
|
||||
"R&D flags:\n"
|
||||
" no-omap-wd disable auto reboot by OMAP watchdog\n"
|
||||
" no-ext-wd disable auto reboot by external watchdog\n"
|
||||
" no-lifeguard-reset disable auto reboot by lifeguard\n"
|
||||
" serial-console enable serial console\n"
|
||||
" no-usb-timeout disable usb timeout\n"
|
||||
" sti-console enable sti console\n"
|
||||
" no-charging disable battery charging\n"
|
||||
" force-power-key force omap boot reason to power key\n"
|
||||
"\n"
|
||||
#endif
|
||||
|
||||
);
|
||||
|
||||
printf( "Image types:\n");
|
||||
for ( i = 0; image_types[i]; ++i )
|
||||
printf(" %-15s %s\n", image_types[i], image_desc[i]);
|
||||
printf( "\n");
|
||||
|
||||
#endif
|
||||
|
||||
#if HAVE_USB
|
||||
printf ("Over USB:\n"
|
||||
" -b [arg] boots the kernel with arguments\n"
|
||||
|
||||
+22
-27
@@ -43,38 +43,33 @@ void process_message(char *msg)
|
||||
{
|
||||
char *str;
|
||||
char *arg;
|
||||
int c=1;
|
||||
if (msg == NULL)
|
||||
return;
|
||||
printf("[x] (%s)\n", msg);
|
||||
str = strdup(msg);
|
||||
arg = strchr(str, ':');
|
||||
if (c!=0) {
|
||||
arg[0]='\0';
|
||||
arg = arg +1;
|
||||
if (!strcmp(str, "flash")) {
|
||||
const char *type = fpid_file(arg);
|
||||
if (type == NULL) {
|
||||
squeue_push2(p, "error", "Unknown piece format", 1);
|
||||
} else flash_image(arg, type, NULL, NULL, NULL);
|
||||
} else
|
||||
if (!strcmp(str, "reset")) {
|
||||
if (reboot_board() == 0) {
|
||||
squeue_push2(p,"info", "Device reboots", 1);
|
||||
} else squeue_push2(p,"error", "Cannot reboot device", 1);
|
||||
} else
|
||||
if (!strcmp(str, "info")) {
|
||||
get_rd_flags();
|
||||
squeue_push2(p, "info", strbuf, 1);
|
||||
get_nolo_version();
|
||||
squeue_push2(p, "info", strbuf, 1);
|
||||
get_usb_mode();
|
||||
squeue_push2(p, "info", strbuf, 1);
|
||||
} else
|
||||
squeue_push2(p, "error", "invalid command", 0);
|
||||
} else {
|
||||
squeue_push2(p, "error", "invalid command format", 0);
|
||||
}
|
||||
arg[0]='\0';
|
||||
arg = arg +1;
|
||||
if (!strcmp(str, "flash")) {
|
||||
const char *type = fpid_file(arg);
|
||||
if (type == NULL) {
|
||||
squeue_push2(p, "error", "Unknown piece format", 1);
|
||||
} else flash_image(arg, type, NULL, NULL, NULL);
|
||||
} else
|
||||
if (!strcmp(str, "reset")) {
|
||||
if (reboot_board() == 0) {
|
||||
squeue_push2(p,"info", "Device reboots", 1);
|
||||
} else squeue_push2(p,"error", "Cannot reboot device", 1);
|
||||
} else
|
||||
if (!strcmp(str, "info")) {
|
||||
get_rd_flags();
|
||||
squeue_push2(p, "info", strbuf, 1);
|
||||
get_nolo_version();
|
||||
squeue_push2(p, "info", strbuf, 1);
|
||||
get_usb_mode();
|
||||
squeue_push2(p, "info", strbuf, 1);
|
||||
} else
|
||||
squeue_push2(p, "error", "invalid command", 0);
|
||||
free(str);
|
||||
}
|
||||
|
||||
|
||||
+6
-1
@@ -40,13 +40,18 @@ struct squeue_t *squeue_open(const char *file, int mode)
|
||||
struct squeue_t *q;
|
||||
char *pool;
|
||||
int shmid;
|
||||
int fd;
|
||||
key_t k;
|
||||
|
||||
k = ftok(file, 0x34);
|
||||
if (k == -1) {
|
||||
perror("ftok");
|
||||
squeue_release(file);
|
||||
close(creat(file, 0666));
|
||||
if ((fd = creat(file, 0666)) == -1) {
|
||||
perror("creat");
|
||||
return NULL;
|
||||
}
|
||||
close(fd);
|
||||
chmod(file, 0666);
|
||||
k = ftok(file, 0xa3);
|
||||
if (k == -1) {
|
||||
|
||||
Reference in new issue
Block a user