You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

120 lines
2.6 KiB

#include <vxWorks.h>
#include <vsbConfig.h>
#include <stdio.h>
#include <moduleLib.h>
#include <usrLib.h>
#include <cacheLib.h>
#include <sysSymTbl.h>
#include <fcntl.h>
#include "config.h"
#if defined(INCLUDE_IPFTPS)
#include <ipcom_sysvar.h>
#include <ipcom_sock.h>
#include <ipftps.h>
int usr_ipftps_authenticate_nopasswd(Ipftps_session *session, char *password)
{
printf("ftp passthor\r\n");
return 0;
}
#endif
#define VXWORKS_POS (0x400000)
int lfsLowRawWrite(unsigned long offset, const char *buffer, int size);
int loadUserApp()
{
SEGMENT_ID seg;
SYMBOL_DESC symDesc;
MODULE_ID module = ld(1, 0, "/tffs0/UserApp.out");
void (*appEntry)(void) = NULL;
if (module != NULL) {
/* flush text segment */
seg = moduleSegFirst(module);
while (seg) {
if (seg->type == SEGMENT_TEXT) {
/* printf("flush: %p, size: 0x%x\r\n", seg->address, seg->size); */
cacheFlush(DATA_CACHE, seg->address, seg->size);
}
seg = moduleSegNext(seg);
}
memset(&symDesc, 0, sizeof symDesc);
symDesc.mask = SYM_FIND_BY_NAME;
symDesc.name = "AppEntry";
if (symFind(sysSymTbl, &symDesc) == OK) {
appEntry = (void (*)(void))(symDesc.value);
printf("AppEntry: %p\r\n", appEntry);
taskSpawn ("tUserApp", 100, 0, 0x10000,
(FUNCPTR) appEntry,0,0,0,0,0,0,0,0,0,0);
}
}
return 0;
}
#if defined(__DCC__)
void usrAppInit(void)
{
loadUserApp();
}
#endif
int mw(unsigned long addr, unsigned int val)
{
volatile unsigned int long *ptr = (volatile unsigned long *)(addr);
*ptr = val;
return 0;
}
int updateVxWorks(const char *file, int pos)
{
struct stat stbuf;
size_t size;
int fd, status;
unsigned char *ptr;
if (stat(file, &stbuf) != OK) {
printf("Can't stat %s\r\n", file);
return ERROR;
}
size = (stbuf.st_size + 0x10000 - 1) / 0x10000;
size *= 0x10000;
ptr = malloc(size);
if (ptr == NULL) {
printf("%s: out of memory\r\n", __FUNCTION__);
return ERROR;
}
memset(ptr, 0xff, size);
fd = open(file, O_RDONLY, 0);
if (fd < 0) {
printf("%s: can't open to read\r\n", __FUNCTION__);
free(ptr);
return ERROR;
}
printf("Reading: %d bytes\r\n", stbuf.st_size);
size = read(fd, ptr, stbuf.st_size);
close(fd);
if (size != stbuf.st_size) {
printf("%s: read size mismatch %d != filesize %d\r\n", __FUNCTION__, size, stbuf.st_size);
free(ptr);
return ERROR;
}
size = (stbuf.st_size + 0x100 - 1) / 0x100;
size *= 0x100;
printf("Write to flash\r\n");
if (pos <= 0) {
pos = VXWORKS_POS;
}
status = lfsLowRawWrite(pos, ptr, size);
free(ptr);
printf("%s\r\n", status == OK ? "Success" : "Failed");
return status;
}