Example #1
0
uint8_t lcdShowAnim(char *fname) {
    FIL file;            /* File object */
	int res;
    UINT readbytes;
	uint8_t state=0;
    uint16_t framems=0;

	res=f_open(&file, fname, FA_OPEN_EXISTING|FA_READ);
	if(res != FR_OK)
		return 1;

	getInputWaitRelease();
	while(!getInputRaw()){
		res = f_read(&file, &framems, sizeof(framems), &readbytes);
        /*
        lcdPrint("ms=");lcdPrintln(IntToStr(framems,4,0));
        lcdPrint("off=");lcdPrintln(IntToStr(f_tell(&file),4,0));
        */
        if(res != FR_OK)
            return 1;
		if(readbytes<sizeof(framems)){
			f_lseek(&file,0);
            continue;
        };
        lcdShowImage(&file);
        getInputWaitTimeout(framems);
	}

    return 0;
}
Example #2
0
UINT file_writeblock(void* buf, uint32_t addr, uint16_t size) {
  UINT bytes_written;
  file_res = f_lseek(&file_handle, addr);
  if(file_res) return 0;
  file_res = f_write(&file_handle, buf, size, &bytes_written);
  return bytes_written;
}
Example #3
0
/**
* @brief  Show_Image
*         Displays BMP image
* @param  None
* @retval None
*/
static void Show_Image(void)
{

  uint16_t i = 0;
  uint16_t numOfReadBytes = 0;
  FRESULT res;

  //LCD_SetDisplayWindow(239, 319, 240, 320);
  //LCD_WriteReg(R3, 0x1008);
  //LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */

  /* Bypass Bitmap header */
  f_lseek (&file, 54);

  while (HCD_IsDeviceConnected(&USB_OTG_Core))
  {
    res = f_read(&file, Image_Buf, IMAGE_BUFFER_SIZE, (void *)&numOfReadBytes);
    if((numOfReadBytes == 0) || (res != FR_OK)) /*EOF or Error*/
    {
      break;
    }
    for(i = 0 ; i < IMAGE_BUFFER_SIZE; i+= 2)
    {
      //LCD_WriteRAM(Image_Buf[i+1] << 8 | Image_Buf[i]);
    }
  }

}
/**
 * This function is used to copy the data from SD/eMMC to destination
 * address
 *
 * @param SrcAddress is the address of the SD flash where copy should
 * start from
 *
 * @param DestAddress is the address of the destination where it
 * should copy to
 *
 * @param Length Length of the bytes to be copied
 *
 * @return
 * 		- XFSBL_SUCCESS for successful copy
 * 		- errors as mentioned in xfsbl_error.h
 *
 *****************************************************************************/
u32 XFsbl_SdCopy(u32 SrcAddress, PTRSIZE DestAddress, u32 Length)
{
	u32 Status;

	FRESULT rc;	 /* Result code */
	UINT br=0U;

	rc = f_lseek(&fil, SrcAddress);
	if (rc != FR_OK) {
		XFsbl_Printf(DEBUG_INFO,
			"SD: Unable to seek to %x\n", SrcAddress);
		Status = XFSBL_ERROR_SD_F_LSEEK;
		XFsbl_Printf(DEBUG_GENERAL,"XFSBL_ERROR_SD_F_LSEEK\n\r");
		goto END;
	}

	rc = f_read(&fil, (void*)DestAddress, Length, &br);

	if (rc != FR_OK) {
		XFsbl_Printf(DEBUG_GENERAL,
			"SD: f_read returned %d\r\n", rc);
		Status = XFSBL_ERROR_SD_F_READ;
		XFsbl_Printf(DEBUG_GENERAL,"XFSBL_ERROR_SD_F_READ\n\r");
		goto END;
	}

	Status = XFSBL_SUCCESS;
END:
	return Status;
}
Example #5
0
// lseek
static off_t mmcfs_lseek_r( struct _reent *r, int fd, off_t off, int whence )
{
  FIL* pFile = mmcfs_fd_table + fd;
  u32 newpos = 0;

  switch( whence )
  {
    case SEEK_SET:
      // seek from beginning of file
      newpos = off;
      break;

    case SEEK_CUR:
      // seek from current position
      newpos = pFile->fptr + off;
      break;

    case SEEK_END:
      // seek from end of file
      newpos = pFile->fsize + off;
      break;

    default:
      return -1;
  }
  if (f_lseek (pFile, newpos) != FR_OK)
    return -1;
  return newpos;
}
Example #6
0
File: fs.c Project: mikemow/rxTools
size_t FileWrite(File *Handle, void *buf, size_t size, size_t foffset) {
	UINT bytes_written = 0;
	if (f_tell(Handle) != foffset) { f_lseek(Handle, foffset); } //Avoid crazy lseeks
	f_write(Handle, buf, size, &bytes_written);
	f_sync(Handle);
	return bytes_written;
}
/*******************************************************************************
* Function Name  : GetGBKCode_from_sd
* Description    : 从SD卡字库中读取自摸数据到指定的缓冲区
* Input          : pBuffer---数据保存地址
*				   					c--汉字字符低字节码
* Output         : None
* Return         : 0(success)  -1(fail)
* Attention		 	 : None
*******************************************************************************/
int GetGBKCode_from_sd(unsigned char* pBuffer,const unsigned char * c)
{
    unsigned char High8bit,Low8bit;
    unsigned int pos;
    High8bit=*c;     /* 取高8位数据 */
    Low8bit=*(c+1);  /* 取低8位数据 */

//  printf("%d ,%d\r\n",High8bit,Low8bit);
//	printf("%x ,%x\r\n",High8bit,Low8bit);

    pos = ((High8bit-0xa0-16)*94+Low8bit-0xa0-1)*2*16 ;
    f_mount(1, &myfs[0]);
    myres = f_open(&myfsrc , "0:/HZLIB.bin", FA_OPEN_EXISTING | FA_READ);

    if ( myres == FR_OK )
    {
        f_lseek (&myfsrc, pos);		//指针偏移
        myres = f_read( &myfsrc, pBuffer, 32, &mybr );		 //16*16大小的汉字 其字模 占用16*2个字节

        f_close(&myfsrc);

        return 0;
    }
    else
        return -1;
}
Example #8
0
static int32_t filerProcessRead(filerFileStruct_t *f) {
    uint32_t res;
    UINT bytes;

    if (!f->open) {
        res = f_open(&f->fp, f->fileName, FA_OPEN_EXISTING | FA_READ);
        if (res != FR_OK)
            return -1;

        f->open = 1;
    }

    if (f->seek >= 0) {
        res = f_lseek(&f->fp, f->seek);
        if (res != FR_OK) {
            f->open = 0;
            return -1;
        }
    }

    res = f_read(&f->fp, f->buf, f->length, &bytes);
    if (res != FR_OK) {
        f->open = 0;
        return -1;
    }

    return bytes;
}
Example #9
0
size_t FileRead(File *Handle, void* buf, size_t size, size_t foffset)
{
    UINT bytes_read = 0;
    f_lseek(Handle, foffset);
    f_read(Handle, buf, size, &bytes_read);
    return bytes_read;
}
Example #10
0
static int32_t filerProcessWrite(filerFileStruct_t *f) {
    uint32_t res;
    UINT bytes;

    if (!f->open) {
        res = f_open(&f->fp, f->fileName, FA_CREATE_ALWAYS | FA_WRITE);
        if (res != FR_OK)
            return -1;

        f->open = 1;
    }

    if (f->seek >= 0) {
        res = f_lseek(&f->fp, f->seek);
        if (res != FR_OK) {
            f->open = 0;
            return -1;
        }
    }

    res = f_write(&f->fp, f->buf, f->length, &bytes);
    if (res != FR_OK) {
        f->open = 0;
        return -1;
    }

    return bytes;
}
Example #11
0
uint8_t write_sdcard()
{

	char a[1]={'b'};
	FRESULT iFResult;
	UINT  writtenBytes=0;
	UINT  writeBytes=1;
	//iFResult = f_open(&g_sNewFile, "/log.txt", FA_OPEN_ALWAYS | FA_READ | FA_WRITE);
	iFResult = f_open(&g_sNewFile, "/log1.txt", FA_OPEN_ALWAYS | FA_READ| FA_WRITE);
	if(iFResult != FR_OK)
		{
		//	UARTprintf("iFResult:%d\n", (int)iFResult);
		    return((int)iFResult);
		}
	iFResult = f_lseek(&g_sNewFile, g_sNewFile.fsize);
	if(iFResult != FR_OK)
	{
	//	UARTprintf("iFResult:%d\n", (int)iFResult);
	    return((int)iFResult);
	}
	f_write(&g_sNewFile, a, writeBytes, &writtenBytes);
	f_write(&g_sNewFile, a, writeBytes, &writtenBytes);
	f_close(&g_sNewFile);
	return 1;
}
Example #12
0
static bool_t sendFile (uint8_t dest, uint8_t id, uint8_t page) {
  char filename[20];
  chsnprintf(filename, sizeof filename, "tosqa%03d.bin", id);
  FRESULT res = f_stat(filename, &filinfo);
  if (res == 0)
    res = f_open(&fil, filename, FA_OPEN_EXISTING | FA_READ);
  if (res != 0)
    return false;

  chprintf(chp1, "(%s: %db)", filename, filinfo.fsize);
  chThdSleepMilliseconds(100);
    
  CANTxFrame txmsg;
  txmsg.IDE = CAN_IDE_EXT;
  txmsg.EID = 0x1F123400 + dest;
  txmsg.RTR = CAN_RTR_DATA;
  txmsg.DLC = 8;

  res = f_lseek(&fil, (page - 1) * 4096);
  if (res == 0) {  
    int i;
    for (i = 0; i < 512; ++i) {
      UINT count;
      res = f_read(&fil, txmsg.data8, 8, &count);
      if (res != 0 || (i == 0 && count == 0))
        break;
      memset(txmsg.data8 + count, 0xFF, 8 - count);
      canTransmit(&CAND1, 1, &txmsg, 100); // 1 mailbox, must send in-order!
      // don't call echoToBridge for these bulk transfers
    }
  }
  
  f_close(&fil);
  return res == 0;
}
Example #13
0
/**
 Opens the log file (path defined as LOG_FILE_PATH) and
 sets file pointer to the end of file

 @return FR_OK 		.... log file was opened successfully
 @return FR_NO_FILE  .... memory alloctaion went wrong
 @return other RC    .... see return codes of f_open()
 */
FRESULT initLog()
{
#if ENABLE_LOG
	FRESULT rc = FR_NO_FILE;
	log_file = (FIL*) pvPortMalloc(sizeof(FIL));

	vTaskSuspendAll();

	fs_enable(400000);

	if (log_file != NULL)
	{
#if DEBUG_LOG
		printf("Opening file, memory OK \n");
#endif
		rc = f_open(log_file, LOG_FILE_PATH, FA_WRITE);

		//goto end of file
		if (rc == FR_OK)
		f_lseek(log_file, log_file->fsize);
	}

	xTaskResumeAll();

	return rc;
#else
	return -1;
#endif
}
Example #14
0
void Write_SystermState(int state_n)
{ 
#ifdef My_DEBUG 
	unsigned char state[13];
  unsigned char state_detail = 0;
	
  unsigned char time[16] = {0x0, 0x0, 0x2d, 0x0, 0x0, 0x2d, 0x0, 0x0, 
  							0x3a, 0x0, 0x0, 0x3a, 0x0, 0x0, 0xd, 0xa};
  memset(state, 0,13);
  if(f_mount(0, &fs) != FR_OK) return;
  
  Get_RTCtime();
  time[0] = (my_time.month/10) + 0x30;
  time[1] = (my_time.month%10) + 0x30;
  time[3] = (my_time.day/10) + 0x30;
  time[4] = (my_time.day%10) + 0x30;
  time[6] = (my_time.hour/10) + 0x30;
  time[7] = (my_time.hour%10) + 0x30;
  time[9] = (my_time.min/10) + 0x30;
  time[10] = (my_time.min%10) + 0x30;
  time[12] = (my_time.sec/10) + 0x30;
  time[13] = (my_time.sec%10) + 0x30;

  if(f_open(&sys_fdst, "systerm.log", /*FA_CREATE_ALWAYS |*/ FA_WRITE | FA_READ) != FR_OK)
  {
    f_open(&sys_fdst, "systerm.log", FA_CREATE_NEW | FA_WRITE | FA_READ);
  }
  else
  {
	  f_lseek(&sys_fdst, sys_fdst.fsize);
  }
  
  f_write(&sys_fdst, (void *)time, sizeof(time), &bw);
  f_lseek(&sys_fdst, sys_fdst.fsize);
	
	if(state_n == SYS_RST){
    if(SET == RCC_GetFlagStatus(RCC_FLAG_PORRST)) state_detail += 1;
		if(SET == RCC_GetFlagStatus(RCC_FLAG_SFTRST)) state_detail += 2;
		if(SET == RCC_GetFlagStatus(RCC_FLAG_IWDGRST)) state_detail += 4;
  }
	sprintf(state,"state:%2d-%2d\r\n", state_n, state_detail);
	f_write(&sys_fdst, (void *)state, 13, &bw);
	
  f_close(&sys_fdst);
  f_mount(0, NULL);
#endif  
}
Example #15
0
size_t FileWrite(File *Handle, void* buf, size_t size, size_t foffset)
{
    UINT bytes_written = 0;
    f_lseek(Handle, foffset);
    f_write(Handle, buf, size, &bytes_written);
	f_sync(&file);
    return bytes_written;
}
Example #16
0
void sdcard_resetFile(FIL * file) {
    FRESULT fres = f_lseek(file, 0);

    if (fres != (FRESULT)FR_OK) {
        UARTprintf("f_lseek result: %d\r\n", fres);
    }

}
Example #17
0
File: fs.c Project: LITTOMA/rxTools
bool FileOpen(File *Handle, const char* path, bool truncate)
{
    unsigned flags = FA_READ | FA_WRITE;
    flags |= truncate ? FA_CREATE_ALWAYS : FA_OPEN_EXISTING; //: FA_OPEN_ALWAYS;
    bool ret = (f_open(Handle, path, flags) == FR_OK);
    f_lseek(Handle, 0);
    return ret;
}
Example #18
0
bool get_program_metadata(const char *filename, uint32_t icon[32], int *icon_size, char *name, int name_size)
{
    AMX_HEADER hdr;
    FIL file;
    unsigned bytes;
    
    FRESULT status = f_open(&file, filename, FA_READ);
    if (status != FR_OK)
        return false;
    
    f_read(&file, &hdr, sizeof(hdr), &bytes);
    if (bytes != sizeof(hdr) || hdr.magic != AMX_MAGIC)
    {
        f_close(&file);
        return false;
    }
    
    int bytecount;
    int icon_dataptr;
    if (get_data_array(&hdr, &file, "get_program_icon", &icon_dataptr, &bytecount))
    {
        *icon_size = bytecount / 4;
        if (*icon_size > 32) *icon_size = 32;
        
        f_lseek(&file, hdr.dat + icon_dataptr);
        f_read(&file, icon, *icon_size * 4, &bytes);
    }
    
    int name_dataptr;
    if (get_data_array(&hdr, &file, "get_program_name", &name_dataptr, &bytecount))
    {
        f_lseek(&file, hdr.dat + name_dataptr);
        f_read(&file, name, name_size, &bytes);
        
        for (int i = 0; i + 4 <= name_size; i += 4)
        {
            uint32_t *p = (uint32_t*)(name + i);
            *p = __builtin_bswap32(*p);
        }
        
        name[name_size - 1] = 0; // Just to make sure that it has terminator somewhere
    }
    
    f_close(&file);
    return true;
}
Example #19
0
int8_t sd::append_string(uint8_t* filename,uint8_t* buffer){
	FIL write_file;
	get_file_handle(filename,&write_file,FA_OPEN_ALWAYS | FA_WRITE | FA_READ);	// open and create if not existing
	f_lseek(&write_file,write_file.fsize);										// append -> jump to end
	int8_t status=writeString(&write_file,buffer);								// write the string
	f_close(&write_file);														// close the file
	return status;
}
Example #20
0
bool FileOpen(File *Handle, const char *path, bool truncate) {
	unsigned flags = FA_READ | FA_WRITE;
	flags |= truncate ? FA_CREATE_ALWAYS : FA_OPEN_EXISTING; //: FA_OPEN_ALWAYS;
	bool ret = (f_open(Handle, path, flags) == FR_OK);
	if (f_tell(Handle)) { f_lseek(Handle, 0); } //Only seek to head if not
	f_sync(Handle);
	return ret;
}
Example #21
0
UINT file_readblock(void* buf, uint32_t addr, uint16_t size) {
  UINT bytes_read;
  file_res = f_lseek(&file_handle, addr);
  if(file_handle.fptr != addr) {
    return 0;
  }
  file_res = f_read(&file_handle, buf, size, &bytes_read);
  return bytes_read;
}
Example #22
0
unsigned int ini_getentry(const char *filename, const char *entry, char *value, unsigned int len) //entry in upper case
{
  FRESULT res;
  unsigned int found, rd;
  char c, *ptr;

  ptr  = value;
  *ptr = 0;

  res = f_open(&fileobj, filename, FA_OPEN_EXISTING | FA_READ);
  if(res != FR_OK)
  {
    return 1;
  }

  found = ini_searchentry(&fileobj, entry, 0);
  if(found == 0)
  {
    f_close(&fileobj);
    return 2;
  }

  res = f_lseek(&fileobj, found);
  if(res != FR_OK)
  {
    f_close(&fileobj);
    return 3;
  }

  //read value
  if(len)
  {
    len--; //null at end
    while(len)
    {
      res = f_read(&fileobj, &c, 1, &rd);
      if((res != FR_OK) || (rd != 1))
      {
        break;
      }
      else if((c == 0) || (c == '\r') || (c == '\n'))
      {
        break;
      }
      *ptr++ = c;
      len--;
    }
    *ptr = 0;
  }

  f_close(&fileobj);

  //remove space at start and end of string
  strrmvspace(value, value);

  return 0;
}
Example #23
0
       // f_write(&file, "Hello world!\r\n", 14, &bw);
char File_Write_Custom_Length(long int location, int length, char *Input_Array){ 
	
	errCode = f_lseek(&file, location);
  Fat_FS_Error(errCode,"f_lseek");
	
	errCode = f_write(&file, Input_Array, length , &bw);
  Fat_FS_Error(errCode,"f_write");
	return 0; 	
}
Example #24
0
/***********************software update****************************************/
void Write_Soft_Date(void  *data, 
      				int offset, 
					int cnt				
	    			)
{  
  f_lseek(&soft_fsrc, offset);
 
  f_write(&soft_fsrc, data, cnt, &bw);
}
Example #25
0
static off_t fatfs_lseek(mount_point_t *point, file_t *file, off_t offset, int whence)
{
    privinfo_t *priv = file->ctx;
    FRESULT res;

    if (priv == NULL) {
        seterrno(EINVAL);
        return -1;
    }

    switch (whence) {
    case SEEK_SET:
        res = f_lseek(&priv->file, offset);
        if (res == FR_OK) {
            return f_tell(&priv->file);
        } else {
            fatfs_result_to_errno(res);
            return -1;
        }

    case SEEK_CUR:
        res = f_lseek(&priv->file, f_tell(&priv->file) + offset);
        if (res == FR_OK) {
            return f_tell(&priv->file);
        } else {
            fatfs_result_to_errno(res);
            return -1;
        }

    case SEEK_END:
        res = f_lseek(&priv->file, f_size(&priv->file) + offset);
        if (res == FR_OK) {
            return f_tell(&priv->file);
        } else {
            fatfs_result_to_errno(res);
            return -1;
        }

    default:
        seterrno(EINVAL);
        return -1;
    }
    return 0;
}
Example #26
0
STATIC mp_obj_t file_obj_make_new(mp_obj_t type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
    mp_arg_check_num(n_args, n_kw, 1, 2, false);

    const char *fname = mp_obj_str_get_str(args[0]);

    int mode = 0;
    if (n_args == 1) {
        mode = FA_READ;
    } else {
        const char *mode_s = mp_obj_str_get_str(args[1]);
        // TODO make sure only one of r, w, x, a, and b, t are specified
        while (*mode_s) {
            switch (*mode_s++) {
                case 'r':
                    mode |= FA_READ;
                    break;
                case 'w':
                    mode |= FA_WRITE | FA_CREATE_ALWAYS;
                    break;
                case 'x':
                    mode |= FA_WRITE | FA_CREATE_NEW;
                    break;
                case 'a':
                    mode |= FA_WRITE | FA_OPEN_ALWAYS;
                    break;
                case '+':
                    mode |= FA_READ | FA_WRITE;
                    break;
                #if MICROPY_PY_IO_FILEIO
                case 'b':
                    type = (mp_obj_t)&mp_type_fileio;
                    break;
                #endif
                case 't':
                    type = (mp_obj_t)&mp_type_textio;
                    break;
            }
        }
    }

    pyb_file_obj_t *o = m_new_obj_with_finaliser(pyb_file_obj_t);
    o->base.type = type;

    FRESULT res = f_open(&o->fp, fname, mode);
    if (res != FR_OK) {
        m_del_obj(pyb_file_obj_t, o);
        nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(fresult_to_errno_table[res])));
    }

    // for 'a' mode, we must begin at the end of the file
    if ((mode & FA_OPEN_ALWAYS) != 0) {
        f_lseek(&o->fp, f_size(&o->fp));
    }

    return o;
}
Example #27
0
File: main.c Project: ADTL/ARMWork
static uint32_t Mp3ReadId3V2Text(FIL* pInFile, uint32_t unDataLen, char* pszBuffer, uint32_t unBufferSize)
{
  UINT unRead = 0;
  BYTE byEncoding = 0;
  if((f_read(pInFile, &byEncoding, 1, &unRead) == FR_OK) && (unRead == 1))
  {
    unDataLen--;
    if(unDataLen <= (unBufferSize - 1))
    {
      if((f_read(pInFile, pszBuffer, unDataLen, &unRead) == FR_OK) ||
          (unRead == unDataLen))
      {
        if(byEncoding == 0)
        {
          // ISO-8859-1 multibyte
          // just add a terminating zero
          pszBuffer[unDataLen] = 0;
        }
        else if(byEncoding == 1)
        {
          // UTF16LE unicode
          uint32_t r = 0;
          uint32_t w = 0;
          if((unDataLen > 2) && (pszBuffer[0] == 0xFF) && (pszBuffer[1] == 0xFE))
          {
            // ignore BOM, assume LE
            r = 2;
          }
          for(; r < unDataLen; r += 2, w += 1)
          {
            // should be acceptable for 7 bit ascii
            pszBuffer[w] = pszBuffer[r];
          }
          pszBuffer[w] = 0;
        }
      }
      else
      {
        return 1;
      }
    }
    else
    {
      // we won't read a partial text
      if(f_lseek(pInFile, f_tell(pInFile) + unDataLen) != FR_OK)
      {
        return 1;
      }
    }
  }
  else
  {
    return 1;
  }
  return 0;
}
Example #28
0
void prepare_data(uint32_t msu_offset) {
  DBG_MSU1 printf("Data requested! Offset=%08lx page1=%08lx page2=%08lx\n", msu_offset, msu_page1_start, msu_page2_start);
  if(   ((msu_offset < msu_page1_start)
     || (msu_offset >= msu_page1_start + msu_page_size))
     && ((msu_offset < msu_page2_start)
     || (msu_offset >= msu_page2_start + msu_page_size))) {
    DBG_MSU1 printf("offset %08lx out of range (%08lx-%08lx, %08lx-%08lx), reload\n", msu_offset, msu_page1_start,
           msu_page1_start+msu_page_size-1, msu_page2_start, msu_page2_start+msu_page_size-1);
    /* "cache miss" */
    /* fill buffer */
    set_msu_addr(0x0);
    sd_offload_tgt=2;
    ff_sd_offload=1;
    msu_res = f_lseek(&msufile, msu_offset);
    DBG_MSU1 printf("seek to %08lx, res = %d\n", msu_offset, msu_res);
    sd_offload_tgt=2;
    ff_sd_offload=1;
    msu_res = f_read(&msufile, file_buf, 16384, &msu_data_bytes_read);
    DBG_MSU1 printf("read res = %d\n", msu_res);
    DBG_MSU1 printf("read %d bytes\n", msu_data_bytes_read);
    msu_reset(0x0);
    msu_page1_start = msu_offset;
    msu_page2_start = msu_offset + msu_page_size;
  } else {
    if (msu_offset >= msu_page1_start && msu_offset <= msu_page1_start + msu_page_size) {
      msu_reset(0x0000 + msu_offset - msu_page1_start);
      DBG_MSU1 printf("inside page1, new offset: %08lx\n", 0x0000 + msu_offset-msu_page1_start);
      if(!(msu_page2_start == msu_page1_start + msu_page_size)) {
        set_msu_addr(0x2000);
        sd_offload_tgt=2;
        ff_sd_offload=1;
        f_read(&msufile, file_buf, 8192, &msu_data_bytes_read);
        DBG_MSU1 printf("next page dirty (was: %08lx), loaded page2 (start now: ", msu_page2_start);
        msu_page2_start = msu_page1_start + msu_page_size;
        DBG_MSU1 printf("%08lx)\n", msu_page2_start);
      }
    } else if (msu_offset >= msu_page2_start && msu_offset <= msu_page2_start + msu_page_size) {
      DBG_MSU1 printf("inside page2, new offset: %08lx\n", 0x2000 + msu_offset-msu_page2_start);
      msu_reset(0x2000 + msu_offset - msu_page2_start);
      if(!(msu_page1_start == msu_page2_start + msu_page_size)) {
        set_msu_addr(0x0);
        sd_offload_tgt=2;
        ff_sd_offload=1;
        f_read(&msufile, file_buf, 8192, &msu_data_bytes_read);
        DBG_MSU1 printf("next page dirty (was: %08lx), loaded page1 (start now: ", msu_page1_start);
        msu_page1_start = msu_page2_start + msu_page_size;
        DBG_MSU1 printf("%08lx)\n", msu_page1_start);
      }
    } else printf("!!!WATWATWAT!!!\n");
  }
  /* clear bank bit to mask bank reset artifact */
  fpga_status_now &= ~0x2000;
  fpga_status_prev &= ~0x2000;
  /* clear busy bit */
  set_msu_status(0x00, 0x10);
}
Example #29
0
FRESULT applyPatch(void *file, const char *patch)
{
	Elf32_Ehdr ehdr;
	Elf32_Shdr shdr;
	FRESULT r;
	FIL f;
	UINT br;
	unsigned int cur, offset;

	r = f_open(&f, patch, FA_READ);
	if (r != FR_OK)
		return r;

	r = f_read(&f, &ehdr, sizeof(ehdr), &br);
	if (br < sizeof(ehdr)) {
		f_close(&f);
		return r == FR_OK ? EOF : r;
	}

	cur = ehdr.e_shoff;
	for (; ehdr.e_shnum; ehdr.e_shnum--, cur += sizeof(shdr)) {
		if (f_lseek(&f, cur) != FR_OK)
			continue;

		f_read(&f, &shdr, sizeof(shdr), &br);
		if (br < sizeof(shdr))
			continue;

		if (shdr.sh_type != SHT_PROGBITS || !(shdr.sh_flags & SHF_ALLOC))
			continue;

		offset = locateSecInFirm(&shdr, (FirmHdr *)file);
		if (offset == 0)
			continue;

		if (f_lseek(&f, shdr.sh_offset) != FR_OK)
			continue;

		f_read(&f, (void *)((uintptr_t)file + offset), shdr.sh_size, &br);
	}

	return FR_OK;
}
Example #30
0
void FileStore::GoToEnd()
{
  if(!inUse)
  {
    platform->Message(HOST_MESSAGE, "Attempt to seek on a non-open file.\n");
    return;
  }
  unsigned long e = Length();
  f_lseek(&file, e);
}