summaryrefslogtreecommitdiffstats
path: root/boot.c
diff options
context:
space:
mode:
authorWolfgang Wiedmeyer <wolfgit@wiedmeyer.de>2017-07-18 17:07:43 +0200
committerWolfgang Wiedmeyer <wolfgit@wiedmeyer.de>2017-07-18 17:07:43 +0200
commit9af74e1e2707bee3dcbf1008682566d330418d8a (patch)
tree4d3740628ba0d88e91f6c5c94abab4cf0d92ef50 /boot.c
parentbcf9438e27b3e678c815b544509706e7b7332451 (diff)
downloadi9305_modem-9af74e1e2707bee3dcbf1008682566d330418d8a.zip
i9305_modem-9af74e1e2707bee3dcbf1008682566d330418d8a.tar.gz
i9305_modem-9af74e1e2707bee3dcbf1008682566d330418d8a.tar.bz2
refactoring and first shot at EFS sync
Receiving the actual EFS data doesn't work yet. And sometimes, the modem ends up in states where it crashes after exchanging hellos. Signed-off-by: Wolfgang Wiedmeyer <wolfgit@wiedmeyer.de>
Diffstat (limited to 'boot.c')
-rw-r--r--boot.c244
1 files changed, 45 insertions, 199 deletions
diff --git a/boot.c b/boot.c
index 86a189e..d22de18 100644
--- a/boot.c
+++ b/boot.c
@@ -26,187 +26,40 @@
#include <sahara.h>
#include <i9305.h>
-int hello_handshake(int tty_fd)
+int configure_tty(int *tty_fd, time_t timeout_sec, long int timeout_usec)
{
- struct sah_hello_req hello_req;
- struct sah_hello_resp hello_resp;
- int rc;
-
- rc = read(tty_fd, &hello_req, sizeof(hello_req));
- if (rc < (int) sizeof(hello_req)
- || hello_req.header.command != SAH_COMMAND_HELLO_REQ) {
- printf("error receiving hello\n");
- return -1;
- }
-
- if (hello_req.mode != SAH_MODE_TRANSFER_PENDING
- && hello_req.mode != SAH_MODE_TRANSFER_COMPLETE) {
- printf("requested SAHARA mode %d is not supported\n", hello_req.mode);
- return -1;
- }
-
- hello_resp.header.command = SAH_COMMAND_HELLO_RESP;
- hello_resp.header.packet_size = sizeof(hello_resp);
- hello_resp.version = hello_req.version;
- hello_resp.min_version = hello_req.min_version;
- hello_resp.status = 0;
- hello_resp.mode = hello_req.mode;
-
- rc = write(tty_fd, &hello_resp, sizeof(hello_resp));
- if (rc < (int) sizeof(hello_resp)) {
- printf("failed to write hello response\n");
- return -1;
- }
-
- return 0;
-}
-
-int file_for_id(unsigned int id, char **file)
-{
- switch (id) {
- case 6:
- *file = FILE_APPS;
- break;
- case 8:
- *file = FILE_DSP1;
- break;
- case 12:
- *file = FILE_DSP2;
- break;
- case 16:
- *file = FILE_EFS1;
- break;
- case 17:
- *file = FILE_EFS2;
- break;
- case 20:
- *file = FILE_EFS3;
- break;
- case 21:
- *file = FILE_SBL1;
- break;
- case 22:
- *file = FILE_SBL2;
- break;
- case 23:
- *file = FILE_RPM;
- break;
- case 28:
- *file = FILE_DSP3;
- break;
- case 29:
- *file = FILE_ACDB;
- break;
- default:
- return -1;
- }
-
- return 0;
-}
-
-int send_data(int tty_fd, struct sah_header *header)
-{
- struct sah_data_req data_req;
- char *file = NULL;
- int file_fd;
- char file_data[MAX_DATA_SEND_SIZE];
- int rc;
-
- rc = read(tty_fd, header, sizeof(*header));
- if (rc < (int) sizeof(header)) {
- printf("failed to receive header for data request\n");
- return -1;
- }
-
- if (header->command == SAH_COMMAND_DATA_END_REQ)
- return 1;
-
- rc = read(tty_fd, &data_req, sizeof(data_req));
- if (rc < (int) sizeof(data_req)) {
- printf("error receiving data req\n");
- return -1;
- }
-
- if(data_req.size > MAX_DATA_SEND_SIZE) {
- printf("requested data size is too big\n");
- return -1;
- }
-
- rc = file_for_id(data_req.id, &file);
- if (rc < 0) {
- printf("failed to identify requested file\n");
- return -1;
- }
-
- file_fd = open(file, O_RDONLY);
- if (file_fd < 0) {
- printf("failed to open requested file\n");
- return -1;
- }
-
- lseek(file_fd, data_req.offset, SEEK_SET);
-
- rc = read(file_fd, &file_data, data_req.size);
- if (rc < (int) data_req.size) {
- printf("failed to read data from file\n");
- return -1;
- }
-
- write(tty_fd, &file_data, data_req.size);
- if (rc < (int) data_req.size) {
- printf("failed to send data\n");
- }
-
- return 0;
-}
-
-int send_file(int tty_fd, struct sah_data_end_ack *data_end_ack)
-{
- struct sah_header header;
- struct sah_data_end_req data_end_req;
+ int tty_dev;
+ struct termios termios;
+ struct timeval timeout;
+ fd_set fds;
int rc;
- rc = hello_handshake(tty_fd);
- if (rc < 0) {
- printf("failed to do hello handshake\n");
- return -1;
- }
-
- do {
- rc = send_data(tty_fd, &header);
- if (rc < 0) {
- printf("error while sending data\n");
- return -1;
- }
- } while (header.command == SAH_COMMAND_DATA_REQ);
-
- rc = read(tty_fd, &data_end_req, sizeof(data_end_req));
- if (rc < (int) sizeof(data_end_req)) {
- printf("error receiving data end request\n");
+ tty_dev = open(TTY_DEVICE, O_RDWR | O_SYNC);
+ if (tty_dev < 0) {
+ printf("failed to open modem tty device\n");
return -1;
+ } else {
+ printf("opened modem tty device\n");
}
- if (data_end_req.status != 0) {
- printf("file transfer end status is nonzero\n");
- return -1;
- }
+ tcgetattr(tty_dev, &termios);
+ cfmakeraw(&termios);
+ cfsetispeed(&termios, B9600);
+ cfsetospeed(&termios, B9600);
+ tcsetattr(tty_dev, TCSANOW, &termios);
- printf("id %d: file transfer complete\n", data_end_req.id);
+ FD_ZERO(&fds);
+ FD_SET(tty_dev, &fds);
+ timeout.tv_sec = timeout_sec;
+ timeout.tv_usec = timeout_usec;
- header.command = SAH_COMMAND_DATA_END_RESP;
- header.packet_size = 8;
- rc = write(tty_fd, &header, sizeof(header));
- if (rc < (int) sizeof(header)) {
- printf("failed to write data end response\n");
+ rc = select(tty_dev+1, NULL, &fds, NULL, &timeout);
+ if (rc <= 0) {
+ printf("failed to set timeout\n");
return -1;
}
- rc = read(tty_fd, data_end_ack, sizeof(*data_end_ack));
- if (rc < (int) sizeof(*data_end_ack)
- || data_end_ack->header.command != SAH_COMMAND_DATA_END_ACK) {
- printf("error receiving data end ack\n");
- return -1;
- }
+ *tty_fd = tty_dev;
return 0;
}
@@ -214,12 +67,8 @@ int send_file(int tty_fd, struct sah_data_end_ack *data_end_ack)
int main()
{
int mdm_dev, tty_dev;
- struct termios termios;
- struct timeval timeout;
- fd_set fds;
-
+ int mode;
struct sah_data_end_ack data_end_ack;
-
int rc;
mdm_dev = open(MDM_DEVICE, O_RDONLY | O_NONBLOCK);
@@ -240,29 +89,9 @@ int main()
// wait until modem is awake
sleep(2);
- tty_dev = open(TTY_DEVICE, O_RDWR | O_SYNC);
- if (tty_dev < 0) {
- printf("failed to open modem tty device\n");
- return -1;
- }
- else {
- printf("opened modem tty device\n");
- }
-
- tcgetattr(tty_dev, &termios);
- cfmakeraw(&termios);
- cfsetispeed(&termios, B9600);
- cfsetospeed(&termios, B9600);
- tcsetattr(tty_dev, TCSANOW, &termios);
-
- FD_ZERO(&fds);
- FD_SET(tty_dev, &fds);
- timeout.tv_sec = 2;
- timeout.tv_usec = 0;
-
- rc = select(tty_dev + 1, NULL, &fds, NULL, &timeout);
- if (rc <= 0) {
- printf("failed to set timeout\n");
+ rc = configure_tty(&tty_dev, 2, 0);
+ if (rc < 0) {
+ printf("failed to configure serial interface\n");
return -1;
}
@@ -276,6 +105,9 @@ int main()
if(data_end_ack.status == 1) {
printf("all files transferred\n");
+ } else {
+ printf("unknown status for data end ack\n");
+ return -1;
}
close(tty_dev);
@@ -285,7 +117,6 @@ int main()
printf("failed to wait for normal boot\n");
return -1;
}
-
printf("waited for normal boot\n");
rc = ioctl(mdm_dev, WAIT_FOR_ERROR);
@@ -302,5 +133,20 @@ int main()
else
printf("error: cdc-wdm device does not exist\n");
+ printf("\nconfiguring EFS sync\n");
+
+ rc = configure_tty(&tty_dev, 0, 500000);
+ if (rc < 0) {
+ printf("failed to configure serial interface\n");
+ }
+
+ while (1) {
+ rc = handle_memory_debug(tty_dev);
+ if (rc < 0) {
+ printf("error during modem operation\n");
+ return -1;
+ }
+ }
+
return 0;
}