Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 4 additions & 18 deletions can.c
Original file line number Diff line number Diff line change
@@ -1,19 +1,5 @@
/*
* Description: the can part for microcom project
*
* Copyright (C) 2010 by Marc Kleine-Budde <[email protected]>
*
* 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 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 at www.gnu.org
*
*/
// SPDX-License-Identifier: GPL-2.0-only
// SPDX-FileCopyrightText: 2010 by Marc Kleine-Budde <[email protected]>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only line that has a "by", maybe unify that and drop it.

#include "config.h"

#include <stdlib.h>
Expand All @@ -40,7 +26,7 @@ struct can_data {

static struct can_data data;

static ssize_t can_write(struct ios_ops *ios, const void *buf, size_t count)
static ssize_t can_write(struct ios_ops *ios, const unsigned char *buf, size_t count)
{
size_t loopcount;
ssize_t ret = 0, err;
Expand All @@ -67,7 +53,7 @@ static ssize_t can_write(struct ios_ops *ios, const void *buf, size_t count)
return ret;
}

static ssize_t can_read(struct ios_ops *ios, void *buf, size_t count)
static ssize_t can_read(struct ios_ops *ios, unsigned char *buf, size_t count)
{
struct can_frame from_can;
ssize_t ret;
Expand Down
11 changes: 3 additions & 8 deletions commands.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
/*
* Copyright (C) 2010 Sascha Hauer <[email protected]>
*
* 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.
*/
// SPDX-License-Identifier: GPL-2.0-only
// SPDX-FileCopyrightText: 2010 Sascha Hauer <[email protected]>
#include "config.h"

#include <stdlib.h>
Expand Down Expand Up @@ -156,6 +150,7 @@ static int cmd_quit(int argc, char *argv[])
static int cmd_sendescape(int argc, char *argv[])
{
unsigned char tmp = CTRL(escape_char);

ios->write(ios, &tmp, 1);
return 0;
}
Expand Down
112 changes: 60 additions & 52 deletions commands_fsl_imx.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
/*
* Copyright (C) 2010 Sascha Hauer <[email protected]>
*
* 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.
*/
// SPDX-License-Identifier: GPL-2.0-only
// SPDX-FileCopyrightText: 2010 Sascha Hauer <[email protected]>
#include "config.h"

#include <stdio.h>
Expand Down Expand Up @@ -51,7 +45,7 @@ static int get_ack(int fd)
return -1;
}
if (r != expect[i])
return -1;;
return -1;
}

return 0;
Expand Down Expand Up @@ -85,11 +79,11 @@ static int sync_com(int fd)

static int read_mem(int fd, uint32_t address, void *_buf, int size, int accesssize)
{
unsigned char buf[] = {0x1, 0x1, /* read command */
0x0, 0x0, 0x0, 0x0, /* address */
0x20, /* data size */
0x0, 0x0, 0x0, 0x0, /* count */
0x0, 0x0, 0x0, 0x0, 0x0}; /* fill */
unsigned char buf[] = { 0x1, 0x1, /* read command */
0x0, 0x0, 0x0, 0x0, /* address */
0x20, /* data size */
0x0, 0x0, 0x0, 0x0, /* count */
0x0, 0x0, 0x0, 0x0, 0x0 }; /* fill */
int i = 0, ret;
uint8_t *buf8 = _buf;
uint16_t *buf16 = _buf;
Expand Down Expand Up @@ -194,11 +188,11 @@ static int memory_display(char *addr, unsigned long offs, unsigned long nbytes,
* once, and all accesses are with the specified bus width.
*/
do {
char linebuf[DISP_LINE_LEN];
uint *uip = (uint *)linebuf;
ushort *usp = (ushort *)linebuf;
u_char *ucp = (u_char *)linebuf;
uint count = 52;
char linebuf[DISP_LINE_LEN];
uint *uip = (uint *)linebuf;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would replace all whitespace in this line with a single space (which matches the common style in the kernel).

ushort *usp = (ushort *)linebuf;
u_char *ucp = (u_char *)linebuf;
uint count = 52;

printf("%08lx:", offs);
linebytes = (nbytes > DISP_LINE_LEN) ? DISP_LINE_LEN : nbytes;
Expand All @@ -215,7 +209,7 @@ static int memory_display(char *addr, unsigned long offs, unsigned long nbytes,
offs += size;
}

while(count--)
while (count--)
printf(" ");

cp = (unsigned char *)linebuf;
Expand Down Expand Up @@ -261,14 +255,14 @@ static int md(int argc, char *argv[])

static int write_mem(uint32_t address, uint32_t val, int accesssize)
{
unsigned char buf[] = { 0x2, 0x2, /* write command */
0x0, 0x0, 0x0, 0x0, /* address */
0x0, /* data size */
0x0, 0x0, 0x0, 0x0, /* fill */
0x0, 0x0, 0x0, 0x0, /* value */
0x0, /* fill */
unsigned char buf[] = { 0x2, 0x2, /* write command */
0x0, 0x0, 0x0, 0x0, /* address */
0x0, /* data size */
0x0, 0x0, 0x0, 0x0, /* fill */
0x0, 0x0, 0x0, 0x0, /* value */
0x0, /* fill */
};
unsigned char expect[] = {0x12, 0x8a, 0x8a, 0x12};
unsigned char expect[] = { 0x12, 0x8a, 0x8a, 0x12 };
int i, ret;
unsigned char r;

Expand Down Expand Up @@ -317,7 +311,7 @@ static int write_mem(uint32_t address, uint32_t val, int accesssize)
return -1;
}
if (r != expect[i])
return -1;;
return -1;
}

return 0;
Expand Down Expand Up @@ -357,6 +351,7 @@ static int do_header(uint32_t addr)
0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0,
};

buf[0] = (addr >> 0) & 0xff;
buf[1] = (addr >> 8) & 0xff;
buf[2] = (addr >> 16) & 0xff;
Expand All @@ -377,12 +372,12 @@ static int upload_file(uint32_t address, char *name, unsigned char type)
{
uint32_t size;
int upfd, ret, i;
unsigned char buf[] = { 0x4, 0x4, /* upload command */
0x0, 0x0, 0x0, 0x0, /* address */
0x0, /* fill */
0x0, 0x0, 0x0, 0x0, /* filesize */
0x0, 0x0, 0x0, 0x0, /* fill */
0xaa, /* filetype */
unsigned char buf[] = { 0x4, 0x4, /* upload command */
0x0, 0x0, 0x0, 0x0, /* address */
0x0, /* fill */
0x0, 0x0, 0x0, 0x0, /* filesize */
0x0, 0x0, 0x0, 0x0, /* fill */
0xaa, /* filetype */
};
struct stat stat;

Expand Down Expand Up @@ -458,12 +453,11 @@ static int upload_file(uint32_t address, char *name, unsigned char type)
static int upload(int argc, char *argv[])
{
uint32_t address;
unsigned char buf[] = { 0x5, 0x5, /* status command */
0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0,
0x0, 0x0,
};
unsigned char buf[] = { 0x5, 0x5, /* status command */
0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0,
0x0, 0x0, };
int i, ret, type = 0;

if (argc < 3)
Expand Down Expand Up @@ -508,16 +502,16 @@ static int fsl_connect(int argc, char *argv[])
static void fsl_sniff_memwrite(void)
{
unsigned char buf[15];
int i;
uint32_t addr, val;

printf("mw ");
for (i = 0; i < 15; i++) {
read(ios->fd, &buf[i], 1);
if (read(ios->fd, buf, 15) < 15) {
printf("read error\n");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The more correct handling would be to read 7 bytes if the first read only gave you 8, right?

I guess you didn't test that and an alternative to fixing warnings in this code is to just drop the whole file?

return;
}

addr = (buf[1] << 24) | (buf[2] << 16) | (buf[3] << 8) | (buf[4] << 0);
val = (buf[10] << 24)| (buf[11] << 16) | (buf[12] << 8) | (buf[13] << 0);
val = (buf[10] << 24) | (buf[11] << 16) | (buf[12] << 8) | (buf[13] << 0);
printf("0x%08x 0x%08x\n", addr, val);
}

Expand All @@ -528,7 +522,10 @@ static void fsl_sniff_6(void)

printf("cmd6\n");
for (i = 0; i < 15; i++) {
read(ios->fd, &buf[i], 1);
if (read(ios->fd, &buf[i], 1) != 1) {
printf("read error\n");
return;
}
printf("%02x ", buf[i]);
}
printf("\n");
Expand All @@ -541,7 +538,10 @@ static void fsl_sniff_sts(void)

printf("cmd get status\n");
for (i = 0; i < 15; i++) {
read(ios->fd, &buf[i], 1);
if (read(ios->fd, &buf[i], 1) != 1) {
printf("read error\n");
return;
}
printf("%02x ", buf[i]);
}
printf("\n");
Expand All @@ -560,15 +560,16 @@ static void fsl_sniff_upload(void)

printf("upload ");

for (i = 0; i < 15; i++) {
read(ios->fd, &buf[i], 1);
if (read(ios->fd, buf, 15) < 15) {
printf("read error\n");
return;
}
addr = (buf[1] << 24) | (buf[2] << 16) | (buf[3] << 8) | (buf[4] << 0);
size = (buf[6] << 24) | (buf[7] << 16) | (buf[8] << 8) | (buf[9] << 0);

printf(" adr: 0x%08x size: 0x%08x type 0x%02x ", addr, size, buf[14]);

switch(buf[14]) {
switch (buf[14]) {
case 0xaa:
printf("(application)\n");
break;
Expand All @@ -582,7 +583,11 @@ static void fsl_sniff_upload(void)

for (i = 0; i < size; i++) {
unsigned char tmp;
read(ios->fd, &tmp, 1);

if (read(ios->fd, &tmp, 1) != 1) {
printf("read error\n");
return;
}
printf("%02x ", tmp);
if (!((i + 1) % 32))
printf("\n");
Expand All @@ -594,7 +599,10 @@ static int fsl_sniff(int argc, char *argv[])
{
while (1) {
unsigned char cmd;
read(ios->fd, &cmd, 1);
if (read(ios->fd, &cmd, 1) != 1) {
printf("read error\n");
return 1;
}
switch (cmd) {
case 0x2:
fsl_sniff_memwrite();
Expand All @@ -614,7 +622,7 @@ static int fsl_sniff(int argc, char *argv[])
default:
printf("unknown cmd 0x%02x\n", cmd);
break;
};
}
}

return 0;
Expand Down
Loading