public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
From: Fabien Chevalier <fchevalier@silicom.fr>
To: BlueZ development <bluez-devel@lists.sourceforge.net>
Cc: denis.kenzior@trolltech.com, Marcel Holtmann <marcel@holtmann.org>
Subject: Re: [Bluez-devel] [PATCH] makes STLC2500 start without files download &	other cleanup
Date: Thu, 04 Oct 2007 14:42:20 +0200	[thread overview]
Message-ID: <4704DFAC.2050709@silicom.fr> (raw)
In-Reply-To: <47049EBF.2000103@silicom.fr>

[-- Attachment #1: Type: text/plain, Size: 6623 bytes --]

All,

I didn't notice the ST firmware was in bluez-firmware package.
So i finally was able to regression test it.
==> Result is it still works fine with firmware download too.

Cheers,

Fabien

> All,
> 
> I cooked up a patch for the STLC2500 startup sequence.
> The changes are listed below:
> 
> * Makes the firmware & parameters download optional : even though those 
> are supposed to be mandatory, practive shows that the chip can run 
> without them.
> * Cleanup the speed setting step : call the Ericsson routines directly 
> instead of duplicating the code.
> * Reset the chip only once after all settings & downloads have been done.
> 
> I couldn't regression test the file download stuff as i don't have any 
> firmware patch files or parameters files to download.
> 
> Denis, it would be great if you could give this patch a try on a 
> Greenphone, see if i didn't break anything :-)
> 
> Cheers,
> 
> Fabien
> 
> 
> 
> ------------------------------------------------------------------------
> 
> --- tools/hciattach.c	(.../trunk)	(révision 89)
> +++ tools/hciattach.c	(.../branches/20070928_1730)	(révision 89)
> @@ -829,62 +829,20 @@
>  
>  extern int stlc2500_init(int fd, bdaddr_t *bdaddr);
>  
>  static int stlc2500(int fd, struct uart_t *u, struct termios *ti)
>  {
>  	bdaddr_t bdaddr;
> -	char cmd[5];
>  	unsigned char resp[10];
>  	int n;
> +	int rvalue;
>  
> -	/* STLC2500 Set Baud Rate stuff */
> -	/* We should set the baud rate first, so the firmware download */
> -	/* goes much faster */
> -
> -	/* STLC2500 Seems to support the Ericsson set baud rate stuff */
> -	/* It should also support the ST Set Baud Rate command */
> -	/* (as in st() function above, but those commands never succeed */
> -	cmd[0] = HCI_COMMAND_PKT;
> -	cmd[1] = 0x09;
> -	cmd[2] = 0xfc;
> -	cmd[3] = 0x01;
> -
> -	switch (u->speed) {
> -	case 57600:
> -		cmd[4] = 0x03;
> -		break;
> -	case 115200:
> -		cmd[4] = 0x02;
> -		break;
> -	case 230400:
> -		cmd[4] = 0x01;
> -		break;
> -	case 460800:
> -		cmd[4] = 0x00;
> -		break;
> -	case 921600:
> -		cmd[4] = 0x20;
> -		break;
> -	default:
> -		cmd[4] = 0x02;
> -		u->speed = 115200;
> -		break;
> -	}
> -
> -#ifdef STLC2500_DEBUG
> -	fprintf(stderr, "Sending Baud Rate %02x\n", cmd[4]);
> -#endif
> -	/* Send initialization command */
> -	if (write(fd, cmd, 5) != 5) {
> -		perror("Failed to write init command");
> -		return -1;
> -	}
> -
> -	/* Need to wait here to give a chance for the device to set baud */
> -	/* But no more than 0.5 seconds */
> -	usleep(200000);
> +	/* STLC2500 has an ericsson core */
> +	rvalue = ericsson(fd, u, ti);
> +	if(rvalue != 0)
> +		return rvalue;
>  
>  #ifdef STLC2500_DEBUG
>  	fprintf(stderr, "Setting speed\n");
>  #endif
>  	if (set_speed(fd, ti, u->speed) < 0) {
>  		perror("Can't set baud rate");
> Index: tools/hciattach_st.c
> ===================================================================
> --- tools/hciattach_st.c	(.../trunk)	(révision 89)
> +++ tools/hciattach_st.c	(.../branches/20070928_1730)	(révision 89)
> @@ -119,13 +119,13 @@
>  	DIR *dir;
>  	struct dirent *d;
>  	char pathname[PATH_MAX], filename[NAME_MAX], prefix[20];
>  	unsigned char cmd[256];
>  	unsigned char buf[256];
>  	uint8_t seqnum = 0;
> -	int fd, size, len;
> +	int fd, size, len, found_fw_file;
>  
>  	memset(filename, 0, sizeof(filename));
>  
>  	snprintf(prefix, sizeof(prefix), "STLC2500_R%d_%02d_",
>  						version >> 8, version & 0xff);
>  
> @@ -135,12 +135,13 @@
>  		strcpy(pathname, ".");
>  		dir = opendir(pathname);
>  		if (!dir)
>  			return -errno;
>  	}
>  
> +	found_fw_file = 0;	
>  	while (1) {
>  		d = readdir(dir);
>  		if (!d)
>  			break;
>  
>  		if (strncmp(d->d_name + strlen(d->d_name) - strlen(suffix),
> @@ -149,16 +150,20 @@
>  
>  		if (strncmp(d->d_name, prefix, strlen(prefix)))
>  			continue;
>  
>  		snprintf(filename, sizeof(filename), "%s/%s",
>  							pathname, d->d_name);
> +		found_fw_file = 1;
>  	}
>  
>  	closedir(dir);
>  
> +	if(!found_fw_file)
> +		return -ENOENT;
> +
>  	printf("Loading file %s\n", filename);
>  
>  	fd = open(filename, O_RDONLY);
>  	if (fd < 0) {
>  		perror("Can't open firmware file");
>  		return -errno;
> @@ -191,47 +196,54 @@
>  int stlc2500_init(int dd, bdaddr_t *bdaddr)
>  {
>  	unsigned char cmd[16];
>  	unsigned char buf[254];
>  	uint16_t version;
>  	int len;
> +	int err;
>  
> -	len = do_command(dd, 0x04, 0x0001, NULL, 0, buf, sizeof(buf));
> +	/* Hci_Cmd_Ericsson_Read_Revision_Information */	
> +	len = do_command(dd, 0xff, 0x000f, NULL, 0, buf, sizeof(buf));
>  	if (len < 0)
>  		return -1;
>  
> -	version = buf[2] << 8 | buf[1];
> -
> -	if (load_file(dd, version, ".ptc") < 0)
> -		return -1;
> +	printf("%s\n", buf);
>  
> -	len = do_command(dd, 0x03, 0x0003, NULL, 0, buf, sizeof(buf));
> +	/* HCI_Read_Local_Version_Information */	
> +	len = do_command(dd, 0x04, 0x0001, NULL, 0, buf, sizeof(buf));
>  	if (len < 0)
>  		return -1;
>  
> -	if (load_file(dd, buf[2] << 8 | buf[1], ".ssf") < 0)
> -		return -1;
> -
> -	len = do_command(dd, 0x03, 0x0003, NULL, 0, buf, sizeof(buf));
> -	if (len < 0)
> -		return -1;
> +	version = buf[2] << 8 | buf[1];
>  
> -	len = do_command(dd, 0xff, 0x000f, NULL, 0, buf, sizeof(buf));
> -	if (len < 0)
> -		return -1;
> +	err = load_file(dd, version, ".ptc");
> +	if(err < 0) {
> +		if(err == -ENOENT) 	
> +			fprintf(stderr, "No ROM patch file loaded.\n");
> +		else
> +			return -1;
> +	}
>  
> -	printf("%s\n", buf);
> +	err = load_file(dd, buf[2] << 8 | buf[1], ".ssf");
> +	if(err < 0) {
> +		if(err == -ENOENT) 	
> +			fprintf(stderr, "No static settings file loaded.\n");
> +		else
> +			return -1;
> +	}
>  
>  	cmd[0] = 0xfe;
>  	cmd[1] = 0x06;
>  	bacpy((bdaddr_t *) (cmd + 2), bdaddr);
>  
> +	/* Hci_Cmd_ST_Store_In_NVDS */	
>  	len = do_command(dd, 0xff, 0x0022, cmd, 8, buf, sizeof(buf));
>  	if (len < 0)
>  		return -1;
>  
> +	/* HCI_Reset : applies parameters*/
>  	len = do_command(dd, 0x03, 0x0003, NULL, 0, buf, sizeof(buf));
>  	if (len < 0)
>  		return -1;
>  
>  	return 0;
>  }
> 
> 
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc.
> Still grepping through log files to find problems?  Stop.
> Now Search log events and configuration files using AJAX and a browser.
> Download your FREE copy of Splunk now >> http://get.splunk.com/
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Bluez-devel mailing list
> Bluez-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/bluez-devel


[-- Attachment #2: fchevalier.vcf --]
[-- Type: text/x-vcard, Size: 253 bytes --]

begin:vcard
fn:Fabien CHEVALIER
n:CHEVALIER;Fabien
org:SILICOM
adr:;;4 rue de Jouanet; RENNES ATALANTE;;35700;FRANCE
email;internet:fchevalier@silicom.fr
title:Software & Studies Engineer
tel;work:+33 (0) 2 99 84 17 17
version:2.1
end:vcard


  reply	other threads:[~2007-10-04 12:42 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-10-04  8:05 [PATCH] makes STLC2500 start without files download & other cleanup Fabien Chevalier
2007-10-04 12:42 ` Fabien Chevalier [this message]
2007-10-04 13:18   ` [Bluez-devel] " Fabien Chevalier
2007-10-04 13:22     ` Fabien Chevalier

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=4704DFAC.2050709@silicom.fr \
    --to=fchevalier@silicom.fr \
    --cc=bluez-devel@lists.sourceforge.net \
    --cc=denis.kenzior@trolltech.com \
    --cc=marcel@holtmann.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox