Пример #1
0
static int simpan_sfile( struct t_simpan_file *pgr) {
	printf(" Save struct SIMPAN_FILE ke flash ..");
	if(prepare_flash(SEKTOR_SFILE, SEKTOR_SFILE)) return -1;
	printf("..");
	
	if(hapus_flash(SEKTOR_SFILE, SEKTOR_SFILE)) return -1;
	printf("..");
	
	if(prepare_flash(SEKTOR_SFILE, SEKTOR_SFILE)) return -1;
	printf("..");
	
	if(tulis_flash(ALMT_SFILE, (unsigned short *) pgr, (sizeof (struct t_simpan_file)))) return -1;
	
	printf(".. OK\r\n");
	return 0;
}
Пример #2
0
void save_mesin(void)
{
	printf("Save struct mesin ke flash ..");
	if(prepare_flash(SEKTOR_MESIN, SEKTOR_MESIN)) return;
	printf("..");
	
	if(hapus_flash(SEKTOR_MESIN, SEKTOR_MESIN)) return;
	printf("..");
	
	if(prepare_flash(SEKTOR_MESIN, SEKTOR_MESIN)) return;
	printf("..");
	
	if(tulis_flash(ALMT_MESIN, (unsigned short *) &mesin, sizeof (mesin))) return;
	printf(".. OK\r\n");
	
}
Пример #3
0
static int simpan_env( struct t_env *pgr)
{
	printf(" Save struct GROUP ke flash ..");
	if(prepare_flash(SEKTOR_ENV, SEKTOR_ENV)) return -1;
	printf("..");
	
	if(hapus_flash(SEKTOR_ENV, SEKTOR_ENV)) return -1;
	printf("..");
	
	if(prepare_flash(SEKTOR_ENV, SEKTOR_ENV)) return -1;
	printf("..");
	
	if(tulis_flash(ALMT_ENV, (unsigned short *) pgr, (sizeof (struct t_group)))) return -1;
	
	printf(".. OK\r\n");
	return 0;
}
Пример #4
0
int do_ddr (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
	char  *buff,*buff_ptr = NULL;
	int ddr_config,ddr_config2,ext_mod;
	long *val;

	/*
	 * We use the last specified parameters, unless new ones are
	 * entered.
	 */

	/* last sector of uboot 0xbf040000 - 0xbf050000
	 * write MAGIC at 0xbf04ffe0 
	 * write sector at 0xbf04ffe4
	 * write size at   0xbf04ffe8
         */

	if ((flag & CMD_FLAG_REPEAT) == 0)
	{
		if (argc == 2) {
			ddr_config = simple_strtoul(argv[1], NULL, 10);
			ddr_config2 = CFG_DDR_CONFIG2_VAL;
			ext_mod = CFG_DDR_EXT_MODE_VAL;
		}
		else if (argc == 3) {
			ddr_config = simple_strtoul(argv[1], NULL, 10);
			ddr_config2 = simple_strtoul(argv[2], NULL, 10);
			ext_mod = CFG_DDR_EXT_MODE_VAL;
		}
		else if (argc == 4) {
			ddr_config = simple_strtoul(argv[1], NULL, 10);
			ddr_config2 = simple_strtoul(argv[2], NULL, 10);
			ext_mod = simple_strtoul(argv[3], NULL, 10);
		}
		else {
			printf("Invalid number of arguments:%d\n",argc);
			return -1;
		}
	}

	buff = (char *) malloc(CFG_FLASH_SECTOR_SIZE + 4);
	buff_ptr = buff;

	prepare_flash(&buff_ptr,&val);
	*val++ = (long)CFG_DDR_MAGIC;
	*val++ = ddr_config;
	*val++ = ddr_config2;
	*val   = ext_mod;

        flash_write(buff_ptr,(long)(UBOOT_ENV_SEC_START),CFG_FLASH_SECTOR_SIZE);

	printf("Programed values ext_mod:0x%0.8x ",*val--);
	printf(" ddr_config2:0x%0.8x ddr_config:0x%0.8x \n",*val--,*val);
	free(buff);

	return 0;
}
Пример #5
0
static int process_file_data(struct update_context *ctx, int ignore_data) {
  uint32_t bytes_to_write =
      ctx->file_info.file_size - ctx->file_info.file_received_bytes;
  bytes_to_write =
      bytes_to_write < ctx->data_len ? bytes_to_write : ctx->data_len;

  LOG(LL_DEBUG,
      ("File size: %u, received: %u to_write: %u", ctx->file_info.file_size,
       ctx->file_info.file_received_bytes, bytes_to_write));

  /*
   * if ignore_data=1 we have to skip all received data
   * (usually - extra files in archive)
   * if ignore_data=0 we have to write data to flash
   */
  if (!ignore_data) {
    if (prepare_flash(ctx, bytes_to_write) < 0) {
      ctx->status_msg = "Failed to erase flash";
      return -1;
    }

    /* Write buffer size must be aligned to 4 */
    uint32_t bytes_to_write_aligned = bytes_to_write & -4;
    LOG(LL_DEBUG, ("Aligned size=%u", bytes_to_write_aligned));

    ctx->file_info.crc_current =
        mz_crc32(ctx->file_info.crc_current, ctx->data, bytes_to_write_aligned);

    LOG(LL_DEBUG, ("Writing %u bytes @%X", bytes_to_write_aligned,
                   ctx->current_write_address));

    if (spi_flash_write(ctx->current_write_address, (uint32_t *) ctx->data,
                        bytes_to_write_aligned) != 0) {
      LOG(LL_ERROR, ("Failed to write to flash"));
      ctx->status_msg = "Failed to write to flash";
      return -1;
    }

    ctx->current_write_address += bytes_to_write_aligned;
    ctx->file_info.file_received_bytes += bytes_to_write_aligned;
    context_remove_data(ctx, bytes_to_write_aligned);

    uint32_t rest =
        ctx->file_info.file_size - ctx->file_info.file_received_bytes;

    LOG(LL_DEBUG, ("Rest=%u", rest));
    if (rest != 0 && rest < 4 && ctx->data_len >= 4) {
      /* File size is not aligned to 4, using align buf to write it */
      uint8_t align_buf[4] = {0xFF, 0xFF, 0xFF, 0xFF};
      memcpy(align_buf, ctx->data, rest);
      LOG(LL_DEBUG, ("Writing 4 bytes @%X", ctx->current_write_address));
      if (spi_flash_write(ctx->current_write_address, (uint32_t *) align_buf,
                          4) != 0) {
        LOG(LL_ERROR, ("Failed to write to flash"));
        ctx->status_msg = "Failed to write to flash";
        return -1;
      }
      ctx->file_info.crc_current =
          mz_crc32(ctx->file_info.crc_current, ctx->data, rest);

      ctx->file_info.file_received_bytes += rest;
      context_remove_data(ctx, rest);
    }
    if (ctx->file_info.file_received_bytes == ctx->file_info.file_size) {
      LOG(LL_INFO, ("Wrote %s (%u bytes)", ctx->file_info.file_name,
                    ctx->file_info.file_size))
    }
  } else {