All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lukasz Majewski <l.majewski@samsung.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 4/6] usb:command: Support for USB Download command
Date: Thu, 12 Apr 2012 09:17:27 +0200	[thread overview]
Message-ID: <1334215049-20362-5-git-send-email-l.majewski@samsung.com> (raw)
In-Reply-To: <1334215049-20362-1-git-send-email-l.majewski@samsung.com>

Support for usbdownload command, which starts USB Downloading process
compliant with Samsung's THOR protocol.

Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Cc: Marek Vasut <marex@denx.de>
---
 common/Makefile   |    1 +
 common/cmd_usbd.c |  161 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 162 insertions(+), 0 deletions(-)
 create mode 100644 common/cmd_usbd.c

diff --git a/common/Makefile b/common/Makefile
index d9f10f3..2392893 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -161,6 +161,7 @@ COBJS-y += cmd_usb.o
 COBJS-y += usb.o usb_hub.o
 COBJS-$(CONFIG_USB_STORAGE) += usb_storage.o
 endif
+COBJS-$(CONFIG_USBDOWNLOAD_GADGET) += cmd_usbd.o
 COBJS-$(CONFIG_CMD_XIMG) += cmd_ximg.o
 COBJS-$(CONFIG_YAFFS2) += cmd_yaffs2.o
 COBJS-$(CONFIG_CMD_SPL) += cmd_spl.o
diff --git a/common/cmd_usbd.c b/common/cmd_usbd.c
new file mode 100644
index 0000000..583f2a5
--- /dev/null
+++ b/common/cmd_usbd.c
@@ -0,0 +1,161 @@
+/*
+ * cmd_usbd.c -- USB THOR Downloader gadget
+ *
+ * Copyright (C) 2012 Lukasz Majewski <l.majewski@samsung.com>
+ * All rights reserved.
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+#define DEBUG
+#include <common.h>
+#include <usbd_thor.h>
+#include <asm/errno.h>
+#include <malloc.h>
+#include <g_dnl.h>
+
+#define STR_SIZE 16
+
+static char dnl_tab[4][STR_SIZE];
+
+char *find_dnl_entry(char* s, char *name)
+{
+	char *st, *c;
+
+	for (; s; strsep(&s, ";"), st = s) {
+		st = strchr(s, ' ');
+
+		if (!strncmp(s, name, st - s)) {
+			for (c = s; c; strsep(&c, ";"))
+				;
+			return s;
+		}
+	}
+	return NULL;
+}
+
+int img_store(struct g_dnl *dnl, int medium)
+{
+	char cmd_buf[128];
+
+	memset(cmd_buf, '\0', sizeof(cmd_buf));
+
+	switch (medium) {
+	case MMC:
+		sprintf(cmd_buf, "%s write 0x%x %s %s", &dnl_tab[1][0],
+			(unsigned int) dnl->rx_buf, &dnl_tab[2][0],
+			&dnl_tab[3][0]);
+		break;
+	case FAT:
+		sprintf(cmd_buf, "%swrite mmc %s:%s 0x%x %s %x",
+			&dnl_tab[1][0], &dnl_tab[2][0], &dnl_tab[3][0],
+			(unsigned int) dnl->rx_buf, &dnl_tab[0][0],
+			dnl->file_size);
+		break;
+	case RAW:
+		sprintf(cmd_buf, "mmc write 0x%x %x %x",
+			(unsigned int) dnl->rx_buf, dnl->p, dnl->packet_size);
+		break;
+	}
+
+	debug("%s: %s\n", __func__, cmd_buf);
+	run_command(cmd_buf, 0);
+
+	return 0;
+}
+
+int do_usbd_down(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+	/* Simple argv[0] passing is not working since 'usbdown' cmd can
+	   be run by */
+	/* 'usb', 'usbd' or 'usbdown' */
+	char *str, *st, *str_env;
+
+	int ret = 0, i = 0;
+	static char *s = "thor";
+	static struct g_dnl *dnl;
+
+	dnl = memalign(CONFIG_SYS_CACHELINE_SIZE, sizeof(struct g_dnl));
+
+	puts("THOR Downloader\n");
+
+	g_dnl_init(s, dnl);
+
+	ret = dnl_init(dnl);
+	if (ret)
+		printf("%s: USBDOWN failed\n", __func__);
+
+	ret = dnl_command(dnl);
+	if (ret < 0)
+		printf("%s: COMMAND failed: %d\n", __func__, ret);
+
+	debug("DNL: file:%s size:%d\n", dnl->file_name, dnl->file_size);
+
+	str_env = getenv("dnl_info");
+	if (str_env == NULL) {
+		puts("DNL: \"dnl_info\" variable not defined!\n");
+		return -1;
+	}
+	debug("dnl_info: %s\n", str_env);
+
+	str = find_dnl_entry(str_env, dnl->file_name);
+	if (str == NULL) {
+		printf("File: %s not at \"dnl_info\"!\n", dnl->file_name);
+		return -1;
+	}
+
+	debug("%s:str: %s\n", __func__, str);
+
+	memset(dnl_tab, '\0', sizeof(dnl_tab));
+	do {
+		st = strsep(&str, " ");
+		strncpy(&dnl_tab[i++][0], st, strlen(st));
+
+	} while (str);
+
+	if (strncmp(dnl->file_name, &dnl_tab[0][0], strlen(&dnl_tab[0][0]))) {
+		printf("Parsed string not match file: %s!\n", dnl->file_name);
+		return -1;
+	}
+
+	debug("%s %s %s %s\n", &dnl_tab[0][0], &dnl_tab[1][0],
+	       &dnl_tab[2][0], &dnl_tab[3][0]);
+
+	if (!strncmp(&dnl_tab[1][0], "mmc", strlen("mmc"))) {
+		dnl->store = img_store;
+		dnl->medium = MMC;
+	} else if (!strncmp(&dnl_tab[1][0], "fat", strlen("fat"))) {
+		dnl->store = img_store;
+		dnl->medium = FAT;
+	} else if (!strncmp(&dnl_tab[1][0], "raw", strlen("raw"))) {
+		dnl->store = img_store;
+		dnl->medium = RAW;
+	} else {
+		printf("DNL: Medium: %s not recognized!", &dnl_tab[1][0]);
+	}
+
+	ret = dnl_download(dnl);
+	if (ret < 0)
+		printf("%s: DOWNLOAD failed: %d\n", __func__, ret);
+
+	ret = dnl_command(dnl);
+	if (ret < 0)
+		printf("%s: COMMAND failed: %d\n", __func__, ret);
+
+	return 0;
+}
+
+U_BOOT_CMD(usbdown, CONFIG_SYS_MAXARGS, 1, do_usbd_down,
+	   "Initialize USB device and Run  THOR USB downloader", NULL
+);
-- 
1.7.2.3

  parent reply	other threads:[~2012-04-12  7:17 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-12  7:17 [U-Boot] [PATCH 0/6] usb:composite:download Composite download gadget Lukasz Majewski
2012-04-12  7:17 ` [U-Boot] [PATCH 1/6] usb:composite:g_dnl: Composite gadget (g_dnl) for USB downloading functions Lukasz Majewski
2012-04-14  9:55   ` Marek Vasut
2012-04-12  7:17 ` [U-Boot] [PATCH 2/6] usb:g_dnl:f_usbd_thor: USB Download function to support THOR protocol Lukasz Majewski
2012-04-14  9:58   ` Marek Vasut
2012-04-14 13:12   ` Wolfgang Denk
2012-04-14 13:29   ` Wolfgang Denk
2012-04-12  7:17 ` [U-Boot] [PATCH 3/6] usb:g_dnl:thor: THOR protocol back end support for f_usbd_thor function Lukasz Majewski
2012-04-14 10:00   ` Marek Vasut
2012-04-14 13:30   ` Wolfgang Denk
2012-04-12  7:17 ` Lukasz Majewski [this message]
2012-04-14 10:04   ` [U-Boot] [PATCH 4/6] usb:command: Support for USB Download command Marek Vasut
2012-04-14 13:33   ` Wolfgang Denk
2012-04-12  7:17 ` [U-Boot] [PATCH 5/6] usb:g_dnl: Support for g_dnl download usb gadget for GONI board Lukasz Majewski
2012-04-14 13:39   ` Wolfgang Denk
2012-04-12  7:17 ` [U-Boot] [PATCH 6/6] usb:g_dnl: Support for g_dnl download usb gadget for TRATS board Lukasz Majewski
2012-04-14 13:40   ` Wolfgang Denk

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1334215049-20362-5-git-send-email-l.majewski@samsung.com \
    --to=l.majewski@samsung.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.