Exemple #1
0
int
main(int argc, char **argv)
{
	const char	*keyring;
	const char	*cmd;
	ssize_t		 cc;
	size_t		 size;
	pgpv_t		 pgp;
	char		*in;
	int		 ssh;
	int		 ok;
	int		 i;

	memset(&pgp, 0x0, sizeof(pgp));
	keyring = NULL;
	ssh = 0;
	ok = 1;
	cmd = "verify";
	while ((i = getopt(argc, argv, "S:c:k:v")) != -1) {
		switch(i) {
		case 'S':
			ssh = 1;
			keyring = optarg;
			break;
		case 'c':
			cmd = optarg;
			break;
		case 'k':
			keyring = optarg;
			break;
		case 'v':
			printf("%s\n", NETPGPVERIFY_VERSION);
			exit(EXIT_SUCCESS);
		default:
			break;
		}
	}
	if (ssh) {
		if (!pgpv_read_ssh_pubkeys(&pgp, keyring, -1)) {
			fprintf(stderr, "can't read ssh keyring\n");
			exit(EXIT_FAILURE);
		}
	} else if (!pgpv_read_pubring(&pgp, keyring, -1)) {
		fprintf(stderr, "can't read keyring\n");
		exit(EXIT_FAILURE);
	}
	if (optind == argc) {
		in = getstdin(&cc, &size);
		ok = verify_data(&pgp, cmd, "[stdin]", in, cc);
	} else {
		for (ok = 1, i = optind ; i < argc ; i++) {
			if (!verify_data(&pgp, cmd, argv[i], argv[i], -1)) {
				ok = 0;
			}
		}
	}
	pgpv_close(&pgp);
	exit((ok) ? EXIT_SUCCESS : EXIT_FAILURE);
}
Exemple #2
0
int32_t  flash_test(uint32_t u32StartAddr, uint32_t u32EndAddr, uint32_t u32Pattern)
{
    uint32_t    u32Addr;

    for (u32Addr = u32StartAddr; u32Addr < u32EndAddr; u32Addr += FMC_FLASH_PAGE_SIZE)
    {
        printf("    Flash test address: 0x%x    \r", u32Addr);

        /* Erase page -  FMC_Erase(u32Addr); */
        FMC->ISPCMD = FMC_ISPCMD_PAGE_ERASE;
        FMC->ISPADR = u32Addr;
        FMC->ISPTRG = FMC_ISPTRG_ISPGO_Msk;
        while (FMC->ISPTRG & FMC_ISPTRG_ISPGO_Msk) ;

        // Verify if page contents are all 0xFFFFFFFF
        if (verify_data(u32Addr, u32Addr + FMC_FLASH_PAGE_SIZE, 0xFFFFFFFF) < 0)
        {
            printf("\nPage 0x%x erase verify failed!\n", u32Addr);
            return -1;
        }

        // Write test pattern to fill the whole page
        if (fill_data_pattern(u32Addr, u32Addr + FMC_FLASH_PAGE_SIZE, u32Pattern) < 0)
        {
            printf("Failed to write page 0x%x!\n", u32Addr);
            return -1;
        }

        // Verify if page contents are all equal to test pattern
        if (verify_data(u32Addr, u32Addr + FMC_FLASH_PAGE_SIZE, u32Pattern) < 0)
        {
            printf("\nData verify failed!\n ");
            return -1;
        }

        /* Erase page -  FMC_Erase(u32Addr); */
        FMC->ISPCMD = FMC_ISPCMD_PAGE_ERASE;
        FMC->ISPADR = u32Addr;
        FMC->ISPTRG = FMC_ISPTRG_ISPGO_Msk;
        while (FMC->ISPTRG & FMC_ISPTRG_ISPGO_Msk) ;

        // Verify if page contents are all 0xFFFFFFFF
        if (verify_data(u32Addr, u32Addr + FMC_FLASH_PAGE_SIZE, 0xFFFFFFFF) < 0)
        {
            printf("\nPage 0x%x erase verify failed!\n", u32Addr);
            return -1;
        }
    }
    printf("\r    Flash Test Passed.          \n");
    return 0;
}
Exemple #3
0
int SshFunc::verify_data(char *key, size_t keylen, struct iovec *sigbufs, int num_bufs, ...)
{
    int i, rc;
    va_list argp;
    char *para;
    size_t para_len;
    struct iovec *tmp_bufs;

    if (!sshAuth) 
        return 0;

    tmp_bufs = new struct iovec[num_bufs];
    va_start(argp, num_bufs);
    for (i = 0; i < num_bufs; i++) {
        para = va_arg(argp, char *);
        para_len = va_arg(argp, int);
        tmp_bufs[i].iov_base = para;
        tmp_bufs[i].iov_len = para_len;
    }
    va_end(argp); 
    rc = verify_data(key, keylen, tmp_bufs, num_bufs, sigbufs);
    delete []tmp_bufs;

    return rc;
}
static void
array_test(void *mem_ctx, struct gl_shader_program *prog,
	   unsigned actual_index, const char *name,
	   enum glsl_base_type base_type,
	   unsigned columns, unsigned rows, unsigned array_size,
	   unsigned excess_data_size)
{
   const glsl_type *const element_type =
      glsl_type::get_instance(base_type, rows, columns);

   const unsigned red_zone_components =
      establish_uniform_storage(prog, 3, actual_index, name, element_type,
				array_size);

   /* The constant value generated may have more array elements than the
    * uniform that it initializes.  In the real compiler and linker this can
    * happen when a uniform array is compacted because some of the tail
    * elements are not used.  In this case, the type of the uniform will be
    * modified, but the initializer will not.
    */
   ir_constant *val;
   generate_array_data(mem_ctx, base_type, columns, rows,
		       array_size + excess_data_size, val);

   linker::set_uniform_initializer(mem_ctx, prog, name, element_type, val);

   verify_initialization(prog, actual_index);
   verify_data(prog->UniformStorage[actual_index].storage, array_size,
	       val, red_zone_components);
}
/*
 * Test following possible scenarios,
 * Case 1:
 * Sequential create a file and dataset with H5D_ALLOC_TIME_EARLY and large
 * size, no write, close, reopen in parallel, read to verify all return
 * the fill value.
 * Case 2:
 * Sequential create a file and dataset with H5D_ALLOC_TIME_EARLY but small
 * size, no write, close, reopen in parallel, extend to large size, then close,
 * then reopen in parallel and read to verify all return the fill value.
 * Case 3:
 * Sequential create a file and dataset with H5D_ALLOC_TIME_EARLY and large
 * size, write just a small part of the dataset (second to the last), close,
 * then reopen in parallel, read to verify all return the fill value except
 * those small portion that has been written.  Without closing it, writes
 * all parts of the dataset in a interleave pattern, close it, and reopen
 * it, read to verify all data are as written.
 */
void
test_chunk_alloc(void)
{
    const char *filename;
    hid_t file_id, dataset;

    file_id = dataset = -1;
  
    filename = GetTestParameters();
    if (VERBOSE_MED)
	printf("Extend Chunked allocation test on file %s\n", filename);

    /* Case 1 */
    /* Create chunked dataset without writing anything.*/
    create_chunked_dataset(filename, DSETCHUNKS, none);
    /* reopen dataset in parallel and check for file size */
    parallel_access_dataset(filename, DSETCHUNKS, open_only, &file_id, &dataset);
    /* reopen dataset in parallel, read and verify the data */
    verify_data(filename, DSETCHUNKS, none, CLOSE, &file_id, &dataset); 

/* Case 2 sometimes fails.  See bug 281 and 636. Skip it for now, need to fix it later. */
if (VERBOSE_LO){
    printf("Started Case 2\n");
    /* Case 2 */
    /* Create chunked dataset without writing anything */
    create_chunked_dataset(filename, 20, none);
    /* reopen dataset in parallel and only extend it */
    parallel_access_dataset(filename, DSETCHUNKS, extend_only, &file_id, &dataset);
    /* reopen dataset in parallel, read and verify the data */
    verify_data(filename, DSETCHUNKS, none, CLOSE, &file_id, &dataset);
    printf("Finished Case 2\n");
} else {
if (MAINPROCESS)
    printf("Skipped Case 2. Use '-v l' to test it.\n");
}

    /* Case 3 */
    /* Create chunked dataset and write in the second to last chunk */
    create_chunked_dataset(filename, DSETCHUNKS, sec_last);
    /* Reopen dataset in parallel, read and verify the data. The file and dataset are not closed*/
    verify_data(filename, DSETCHUNKS, sec_last, NO_CLOSE, &file_id, &dataset); 
    /* All processes write in all the chunks in a interleaved way */
    parallel_access_dataset(filename, DSETCHUNKS, write_all, &file_id, &dataset);
    /* reopen dataset in parallel, read and verify the data */
    verify_data(filename, DSETCHUNKS, all, CLOSE, &file_id, &dataset); 

}
int cb_check_data(spctx_t* ctx)
{
    if(mode == MODE_VERIFY)
	return verify_data(ctx);
    else if(mode == MODE_SIGN)
	return sign_data(ctx);
    else
        return -1;
}
Exemple #7
0
static void verify_sync(void)
{
	int fd = eopen(Option.file, O_RDONLY);
	int rc = eread(fd, Data, sizeof(Data));
	if (rc != sizeof(Data)) {
		fatal("Expeted %d bytes read but read %d", sizeof(Data), rc);
	}
	verify_data();
	eclose(fd);
}
/*
 * Test following possible scenarios,
 * Case 1:
 * Sequential create a file and dataset with H5D_ALLOC_TIME_EARLY and large
 * size, no write, close, reopen in parallel, read to verify all return
 * the fill value.
 * Case 2:
 * Sequential create a file and dataset with H5D_ALLOC_TIME_EARLY but small
 * size, no write, close, reopen in parallel, extend to large size, then close,
 * then reopen in parallel and read to verify all return the fill value.
 * Case 3:
 * Sequential create a file and dataset with H5D_ALLOC_TIME_EARLY and large
 * size, write just a small part of the dataset (second to the last), close,
 * then reopen in parallel, read to verify all return the fill value except
 * those small portion that has been written.  Without closing it, writes
 * all parts of the dataset in a interleave pattern, close it, and reopen
 * it, read to verify all data are as written.
 */
void
test_chunk_alloc(void)
{
    const char *filename;
    hid_t file_id, dataset;

    file_id = dataset = -1;

    /* Initialize MPI */
    MPI_Comm_size(MPI_COMM_WORLD,&mpi_size);
    MPI_Comm_rank(MPI_COMM_WORLD,&mpi_rank);

    filename = GetTestParameters();
    if (VERBOSE_MED)
  printf("Extend Chunked allocation test on file %s\n", filename);

    /* Case 1 */
    /* Create chunked dataset without writing anything.*/
    create_chunked_dataset(filename, CHUNK_FACTOR, none);
    /* reopen dataset in parallel and check for file size */
    parallel_access_dataset(filename, CHUNK_FACTOR, open_only, &file_id, &dataset);
    /* reopen dataset in parallel, read and verify the data */
    verify_data(filename, CHUNK_FACTOR, none, CLOSE, &file_id, &dataset);

    /* Case 2 */
    /* Create chunked dataset without writing anything */
    create_chunked_dataset(filename, 20, none);
    /* reopen dataset in parallel and only extend it */
    parallel_access_dataset(filename, CHUNK_FACTOR, extend_only, &file_id, &dataset);
    /* reopen dataset in parallel, read and verify the data */
    verify_data(filename, CHUNK_FACTOR, none, CLOSE, &file_id, &dataset);

    /* Case 3 */
    /* Create chunked dataset and write in the second to last chunk */
    create_chunked_dataset(filename, CHUNK_FACTOR, sec_last);
    /* Reopen dataset in parallel, read and verify the data. The file and dataset are not closed*/
    verify_data(filename, CHUNK_FACTOR, sec_last, NO_CLOSE, &file_id, &dataset);
    /* All processes write in all the chunks in a interleaved way */
    parallel_access_dataset(filename, CHUNK_FACTOR, write_all, &file_id, &dataset);
    /* reopen dataset in parallel, read and verify the data */
    verify_data(filename, CHUNK_FACTOR, all, CLOSE, &file_id, &dataset);

}
Exemple #9
0
int SshFunc::verify_data(char *key, size_t klen, struct iovec *sigbufs, char *fmt, ...)
{
    int i, rc;
    va_list argp;
    char *para, *p, *pos;
    size_t para_len;
    int num_bufs = get_sizes(fmt);
    struct iovec *tmp_bufs;
    int *d_nums;
    char *skey = key;
    size_t sklen = klen;

    if (!sshAuth) 
        return 0;

    tmp_bufs = new struct iovec[num_bufs];
    d_nums = new int[num_bufs];
    if (key == NULL) {
        skey = session_key;
        sklen = key_len;
    }
    va_start(argp, fmt);
    pos = p = fmt;
    i = -1;
    while (*p != '\0') {
        switch (*p) {
            case 'd':
                d_nums[i] = va_arg(argp, int);
                d_nums[i] = ntohl(d_nums[i]);
                tmp_bufs[i].iov_len = sizeof(int);
                tmp_bufs[i].iov_base = &d_nums[i];
                break;
            case 's':
                tmp_bufs[i].iov_base = va_arg(argp, char *);
                if (*pos != 's') {
                    tmp_bufs[i].iov_len = atoi((const char *)pos);
                } else {
                    tmp_bufs[i].iov_len = strlen((char *)tmp_bufs[i].iov_base) + 1;
                }
                break;
            case '%':
                pos = p + 1;
                i++;
                break;
        }
        p++;
    }
    va_end(argp);

    rc = verify_data(skey, sklen, tmp_bufs, num_bufs, sigbufs);
    delete []d_nums;
    delete []tmp_bufs;

    return rc;
}
Exemple #10
0
void Test_sdcard(void)
{
	if (Sdio_verification!=FALSE)
	{
		#ifdef ENABLE_WRITE_MODE
			/* Write a single sector of data (512 bytes) */
			if (!sdcardinfo.sdck_wp())
			{
				prep_data(0, 1);
				/* Warning: This may corrupt SD card data! */
				if (sdmmc_write_blocks((void *) lbuff, 1, 1) == 0) 
				{
					errorc = -3;
					goto error_exit1;
				}
				/* Wait for write to finish (at the card) */
				wait_for_program_finish();
			}
		#endif
		memset(lbuff, 0, sizeof(lbuff));
		/* Read a single sector of data (512 bytes) */
		if (sdmmc_read_blocks((void *) lbuff, 1, 1) == 0) 
		{
			errorc = -4;
			goto error_exit1;
		}
		#ifdef ENABLE_WRITE_MODE
		/* Verify data and halt if an error occurs */
		if (!sdcardinfo.sdck_wp()) 
		{
			if (verify_data(1, 0, 1) == 0) 
			{
				errorc = -5;
				goto error_exit1;
			}
			lpc_printf("SD card Verified!");
			Sdio_verification = TRUE;
			goto exit1;
		}
		#endif	
	

exit1:
	return;	
}	
error_exit1:
	lpc_printf("\n\rSD Card read/write operation not succeeded.");
	Sdio_verification = FALSE;
}
Exemple #11
0
int SshFunc::verify_data(char *bufs[], int sizes[], int num_bufs, struct iovec *sigbufs)
{
    int i, rc;
    struct iovec *tmp_bufs;

    if (!sshAuth) 
        return 0;

    tmp_bufs = new struct iovec[num_bufs];
    for (i = 0; i < num_bufs; i++) {
        tmp_bufs[i].iov_base = bufs[i];
        tmp_bufs[i].iov_len = sizes[i];
    }
    rc = verify_data(session_key, key_len, tmp_bufs, num_bufs, sigbufs);
    delete []tmp_bufs;

    return rc;
} 
static void
non_array_test(void *mem_ctx, struct gl_shader_program *prog,
	       unsigned actual_index, const char *name,
	       enum glsl_base_type base_type,
	       unsigned columns, unsigned rows)
{
   const glsl_type *const type =
      glsl_type::get_instance(base_type, rows, columns);

   unsigned red_zone_components =
      establish_uniform_storage(prog, 3, actual_index, name, type, 0);

   ir_constant *val;
   generate_data(mem_ctx, base_type, columns, rows, val);

   linker::set_uniform_initializer(mem_ctx, prog, name, type, val, 0xF00F);

   verify_data(prog->UniformStorage[actual_index].storage, 0, val,
	       red_zone_components, 0xF00F);
}
Exemple #13
0
/***********************************************************************
 *
 * Function: c_entry
 *
 * Purpose: Application entry point from the startup code
 *
 * Processing:
 *     See function.
 *
 * Parameters: None
 *
 * Outputs: None
 *
 * Returns: Always returns 1, or <0 on an error
 *
 * Notes: None
 *
 **********************************************************************/
void c_entry(void)
{
	UNS_32 noBlocks, *a1, sector, progblk, blkcnt;
	UNS_32 loadsize, loadcount;
	UNS_8 *p8, tmp[16];
	UNS_32 good_blks[64];
	int idx = 0;
	UNS_32 blksize = 0, size = 0, offset = 0, ret;
	  
	memset(spare, 0xFF, sizeof(spare));

    uart_output_init();

	/* Now to download the image */
	uart_output((UNS_8 *)"X");

	/* Wait for 'p' */
	while (!uart_input(&tmp[0], 1));

	/* Wait for 8 bytes from other side */
	idx = 0;
	while (idx < 8)
	{
		idx += uart_input(&tmp[idx], (8 - idx));
	}
	uart_output((UNS_8 *)"o");

	a1 = (UNS_32 *) tmp;

	/* Get size of secondary file */
	loadsize = a1[1];

	/* Receive complete file using UART */
	loadcount = 0;
	p8 = (UNS_8 *) BURNER_LOAD_ADDR;
	while (loadsize > loadcount)
	{
		loadcount += uart_input(p8 + loadcount, (loadsize - loadcount));
	}
	uart_output((UNS_8 *)"t");

	/* Init NAND controller */
	if (nand_lb_slc_init() == 0) 
	{
   		uart_output((UNS_8 *)"Cannot initialize SLC NAND device\r\n");
		while (1);
	}

    /* Disable write protect */
    nand_flash_wp_disable();

	rdbuff8 = (UNS_8 *) rdbuff;
  
	/* Calculate Required Blocks for flashing stage1 application */ 
	blksize = nandgeom.data_bytes_per_page * nandgeom.pages_per_block;
	noBlocks = loadsize /blksize;
	if ((noBlocks * blksize) < loadsize)
	{
		noBlocks++;
	}
  
	/* Erase blocks starting from 1 & leave bad blocks */
	progblk = 1;
	uart_output((UNS_8 *)"Formatting blocks...\r\n");
	blkcnt = 0;

	do 
	{
		/* Check if block is bad or not */
		ret = nand_lb_slc_is_block_bad(progblk);
		if(ret == 0)
		{
			/* Get sector address for first page of block */
			sector = nand_bp_to_sector(progblk, 0);
			if (nand_lb_slc_erase_block(progblk) == 0)
			{
				/* Erase failure */
				uart_output((UNS_8 *)"Error: Erase failure\r\n");
				while(1);
			}

			/* Really, Block is reased? */
			nand_lb_slc_read_sector(sector, rdbuff8, NULL);
			idx = compdata(rdbuff8,0xFF);
			if(idx >= 0)
			{
				uart_output((UNS_8 *)"Error: Erase failure...\r\n");	
				while (1);
			}

			good_blks[blkcnt] = progblk;
			blkcnt++;
		}
		progblk++;
	}while(blkcnt < noBlocks);

	uart_output((UNS_8 *)"Format complete\r\n");

	uart_output((UNS_8 *)"Writting S1 image into flash...\r\n");
	offset = 0;
  
	for (blkcnt = 0; blkcnt < noBlocks; blkcnt++)
	{
		progblk = good_blks[blkcnt];
		sector = nand_bp_to_sector(progblk, 0);

		if(loadsize <= blksize)
			size = loadsize;
		else
			size = blksize;

		/* Write 1 block size or less data into Flash */
		if (nand_write_sectors(sector, p8 + offset, size) <= 0)
		{
			uart_output((UNS_8 *)"Error: Failed to write data...\r\n");
			while(1);
		}

		idx = verify_data(sector, p8 + offset, rdbuff8, size);
		if(idx >= 0)
		{
			uart_output((UNS_8 *)"...Failed\r\n");
			while(1);
		}

		loadsize -= blksize;
		offset += blksize;
		progblk++;
	}
	uart_output((UNS_8 *)"NAND flash is programmed Successfully\r\n");		

	/* Loop forever */
	while (1);
}
Exemple #14
0
/*********************************************************************//**
 * @brief		Main SDIO program body
 * @param[in]	None
 * @return 		int
 **********************************************************************/
void Sdio_init(void)
{

	uint32_t dms, sdio_clk;
	int32_t loops, blk;
	uint8_t buf[50];
	errorc = 1;

	/* Configure the IO's for the LEDs */
		/* Setup muxing for SD interface */
		/*Xplorer*/
	scu_pinmux(0x1 ,11 , SDFASTINOUTPIN, FUNC7);      /* P1.11 SDIO D2 */
	scu_pinmux(0x1 ,10 , SDFASTINOUTPIN, FUNC7);      /* P1.10 SDIO D1 */
	scu_pinmux(0x1 ,9 , SDFASTINOUTPIN, FUNC7);      /* P1.9 SDIO D0 */
	scu_pinmux(0x1 ,6, SDFASTINOUTPIN, FUNC7);      /* P1.6 SDIO command */
	scu_pinmux(0x1 ,12 , SDFASTINOUTPIN, FUNC7);      /* P1.12 SDIO D3 */

	LPC_SCU->SFSCLK_2 = 0x04;						/*	CLK2 Enable*/


	CGU_EntityConnect(CGU_CLKSRC_PLL1, CGU_BASE_SDIO);

	/* Generate interrupt @ 100 Hz */

	/* The SDIO driver needs to know the SDIO clock rate */
	sdio_clk = CGU_GetPCLKFrequency(CGU_PERIPHERAL_SDIO);

	/* This init sdio with sdio_clk */
	sdif_init(sdio_clk, sdmmc_irq);

	/* Wait for a card to be inserted (note CD is not on the
	   SDMMC power rail and can be polled without enabling
	   SD slot power */

	/* Allow some time for the power supply to settle and the
	   card to fully seat in the slot */
	dms = u32Milliseconds + 250;
	while (dms > u32Milliseconds);

	/* Enumerate the card once detected. Note this function may
	   block for a little while. */
	if (!sdmmc_acquire(sdmmc_setup_wakeup, sdmmc_irq_driven_wait,
		sdmmc_waitms, &sdcardinfo)) {
		errorc = -1;
		goto error_exit;
	}
	lpc_printf("SD card detected and initialized..!\r\n");
	/* Setup card specific callbacks - use driver functions, but these can
	   be changed to custom functions or unique functions per slot. These
	   aren't used in the drivers, so setup of these is optional, but they
	   are setup here to be complete. */
	sdcardinfo.sdck_det = sdif_card_ndetect;
	sdcardinfo.sdck_wp = sdif_card_wp_on;
	sdcardinfo.sd_setpow = sdif_power_onoff;
	sdcardinfo.sd_setrst = sdif_reset;
	memset(lbuff, 0, sizeof(lbuff));
	if (sdmmc_read_blocks((void *) lbuff, 0, 0) == 0) {
		errorc = -2;
		goto error_exit;
	}
#ifdef ENABLE_WRITE_MODE
	lpc_printf("Writing data to sector 1 of SD card and verifying:\r\n");
	/* Write a single sector of data (512 bytes) */
	if (!sdcardinfo.sdck_wp()) {
		prep_data(0, 1);
		/* Warning: This may corrupt SD card data! */
		if (sdmmc_write_blocks((void *) lbuff, 1, 1) == 0) {
			errorc = -3;
			goto error_exit;
		}
		/* Wait for write to finish (at the card) */
		wait_for_program_finish();
	}
#endif
	memset(lbuff, 0, sizeof(lbuff));
	/* Read a single sector of data (512 bytes) */
	if (sdmmc_read_blocks((void *) lbuff, 1, 1) == 0) {
		errorc = -4;
		goto error_exit;
	}
#ifdef ENABLE_WRITE_MODE
	/* Verify data and halt if an error occurs */
	if (!sdcardinfo.sdck_wp()) {
		if (verify_data(1, 0, 1) == 0) {
			errorc = -5;
			goto error_exit;
		}
		lpc_printf("Verified!\r\n");
	}
#endif

#ifdef USE_MULTPLE_TRANSFER
#ifdef ENABLE_WRITE_MODE
 	lpc_printf("Writing data in Multitransfer mode and verifying:\r\n");
	/* Write data using multiple sector write */
	if (!sdcardinfo.sdck_wp()) {
		prep_data(0x10, 3);
		/* Warning: This may corrupt SD card data! */
		if (sdmmc_write_blocks((void *) lbuff, 1, MULT_XFER_MAX_SECTORS) == 0) {
			errorc = -6;
			goto error_exit;
		}
		wait_for_program_finish();
	}
#endif
	memset(lbuff, 0, sizeof(lbuff));
	/* Read data using multiple sector read */
	if (sdmmc_read_blocks((void *) lbuff, 1, MULT_XFER_MAX_SECTORS) == 0) {
		errorc = -7;
		goto error_exit;
	}

#ifdef ENABLE_WRITE_MODE
	/* Verify data and halt if an error occurs */
	if (!sdcardinfo.sdck_wp()) {
		if (verify_data(MULT_XFER_MAX_SECTORS, 0x10, 3) == 0) {
			errorc = -8;
			goto error_exit;
		}
		lpc_printf("Verified!\r\n");
	}
#endif
   	lpc_printf("measure continuous read speed...\r\n");
	tstartr = u32Milliseconds;
	loops = 1000;
	blk = 64;
	while (loops-- > 0) {
		if (sdmmc_read_blocks((void *) lbuff, blk, (blk + MULT_XFER_MAX_SECTORS - 1)) == 0) {
			errorc = -8;
			goto error_exit;
		}

		blk += MULT_XFER_MAX_SECTORS;
	}
	tstopr = u32Milliseconds;
	memset(buf, 0, sizeof(buf));
	lpc_printf("read speed = %d kB/s\r\n", MULT_XFER_MAX_SECTORS*512*1000/(tstopr-tstartr));

#ifdef ENABLE_WRITE_MODE
	lpc_printf("measure continuous write speed...\r\n");

	if (!sdcardinfo.sdck_wp()) {
		tstartw = u32Milliseconds;
		loops = 200;
		blk = 64;
		while (loops-- > 0) {
			if (sdmmc_write_blocks((void *) lbuff, blk, (blk + MULT_XFER_MAX_SECTORS - 1)) == 0) {
				errorc = -9;
				goto error_exit;
			}
			blk += MULT_XFER_MAX_SECTORS;
			wait_for_program_finish();
		}
		tstopw = u32Milliseconds;
	}
	memset(buf, 0, sizeof(buf));
	lpc_printf("write speed = %d kB/s\r\n", MULT_XFER_MAX_SECTORS*512*200/(tstopw-tstartw));
#endif
#endif
	goto exit;
	error_exit:
	lpc_printf("SD Card read/write operation not succeeded.\r\n");
	Sdio_verification = FALSE;
exit:
	return;
}
static int remotetest_exec(int dest, u64 *val)
{
    void *dev_handle;
    void *event_handles[3];
    void *cb_handle;
    int ret;
    u64 errmask = 0;
    uint32_t ouint;
    uint32_t oalen;

    /*                       */
    ret = daldevice_attach(REMOTE_UNITTEST_DEVICEID, NULL,
                           dest, &dev_handle);
    if (ret) {
        printk(KERN_INFO "%s: failed to attach (%d)\n", __func__, ret);
        *val = 0xffffffff;
        return 0;
    }

    /*                        */
    ret = remote_unittest_0(dev_handle, REMOTE_UNITTEST_INARG_1);
    if (ret)
        rpc_error(0);

    /*                        */
    ret = remote_unittest_1(dev_handle, REMOTE_UNITTEST_INARG_1,
                            REMOTE_UNITTEST_INARG_2);
    if (ret)
        rpc_error(1);

    /*                        */
    ouint = 0;
    ret = remote_unittest_2(dev_handle, REMOTE_UNITTEST_INARG_1, &ouint);
    if (ret)
        rpc_error(2);
    else if (ouint != REMOTE_UNITTEST_OUTARG_1)
        verify_error(2, "ouint");

    /*                        */
    ret = remote_unittest_3(dev_handle, REMOTE_UNITTEST_INARG_1,
                            REMOTE_UNITTEST_INARG_2,
                            REMOTE_UNITTEST_INARG_3);
    if (ret)
        rpc_error(3);

    /*                        */
    ouint = 0;
    ret = remote_unittest_4(dev_handle, REMOTE_UNITTEST_INARG_1,
                            REMOTE_UNITTEST_INARG_2, &ouint);
    if (ret)
        rpc_error(4);
    else if (ouint != REMOTE_UNITTEST_OUTARG_1)
        verify_error(4, "ouint");

    /*                        */
    init_data(&in_data);
    ret = remote_unittest_5(dev_handle, &in_data, sizeof(in_data));
    if (ret)
        rpc_error(5);

    /*                        */
    init_data(&in_data);
    ret = remote_unittest_6(dev_handle, REMOTE_UNITTEST_INARG_1,
                            &in_data.test, sizeof(in_data.test));
    if (ret)
        rpc_error(6);

    /*                        */
    init_data(&in_data);
    memset(&out_data, 0, sizeof(out_data));
    ret = remote_unittest_7(dev_handle, &in_data, sizeof(in_data),
                            &out_data.test, sizeof(out_data.test),
                            &oalen);
    if (ret)
        rpc_error(7);
    else if (oalen != sizeof(out_data.test))
        verify_error(7, "oalen");
    else if (verify_uint32_buffer(out_data.test))
        verify_error(7, "obuf");

    /*                        */
    init_bytebuf(in_bytebuf);
    memset(&out_data, 0, sizeof(out_data));
    ret = remote_unittest_8(dev_handle, in_bytebuf, sizeof(in_bytebuf),
                            &out_data, sizeof(out_data));
    if (ret)
        rpc_error(8);
    else if (verify_data(&out_data))
        verify_error(8, "obuf");

    /*                        */
    memset(&out_bytebuf, 0, sizeof(out_bytebuf));
    ret = remote_unittest_9(dev_handle, out_bytebuf, sizeof(out_bytebuf));
    if (ret)
        rpc_error(9);
    else if (verify_bytebuf(out_bytebuf))
        verify_error(9, "obuf");

    /*                         */
    init_bytebuf(in_bytebuf);
    memset(&out_bytebuf, 0, sizeof(out_bytebuf));
    ret = remote_unittest_10(dev_handle, REMOTE_UNITTEST_INARG_1,
                             in_bytebuf, sizeof(in_bytebuf),
                             out_bytebuf, sizeof(out_bytebuf), &oalen);
    if (ret)
        rpc_error(10);
    else if (oalen != sizeof(out_bytebuf))
        verify_error(10, "oalen");
    else if (verify_bytebuf(out_bytebuf))
        verify_error(10, "obuf");

    /*                         */
    memset(&out_bytebuf, 0, sizeof(out_bytebuf));
    ret = remote_unittest_11(dev_handle, REMOTE_UNITTEST_INARG_1,
                             out_bytebuf, sizeof(out_bytebuf));
    if (ret)
        rpc_error(11);
    else if (verify_bytebuf(out_bytebuf))
        verify_error(11, "obuf");

    /*                         */
    memset(&out_bytebuf, 0, sizeof(out_bytebuf));
    ret = remote_unittest_12(dev_handle, REMOTE_UNITTEST_INARG_1,
                             out_bytebuf, sizeof(out_bytebuf), &oalen);
    if (ret)
        rpc_error(12);
    else if (oalen != sizeof(out_bytebuf))
        verify_error(12, "oalen");
    else if (verify_bytebuf(out_bytebuf))
        verify_error(12, "obuf");

    /*                         */
    init_data(&in_data);
    memset(&out_data, 0, sizeof(out_data));
    ret = remote_unittest_13(dev_handle, in_data.test, sizeof(in_data.test),
                             &in_data, sizeof(in_data),
                             &out_data, sizeof(out_data));
    if (ret)
        rpc_error(13);
    else if (verify_data(&out_data))
        verify_error(13, "obuf");

    /*                         */
    init_data(&in_data);
    memset(out_bytebuf, 0, sizeof(out_bytebuf));
    memset(out_bytebuf2, 0, sizeof(out_bytebuf2));
    ret = remote_unittest_14(dev_handle,
                             in_data.test, sizeof(in_data.test),
                             out_bytebuf, sizeof(out_bytebuf),
                             out_bytebuf2, sizeof(out_bytebuf2), &oalen);
    if (ret)
        rpc_error(14);
    else if (verify_bytebuf(out_bytebuf))
        verify_error(14, "obuf");
    else if (oalen != sizeof(out_bytebuf2))
        verify_error(14, "oalen");
    else if (verify_bytebuf(out_bytebuf2))
        verify_error(14, "obuf2");

    /*                         */
    init_data(&in_data);
    memset(out_bytebuf, 0, sizeof(out_bytebuf));
    memset(&out_data, 0, sizeof(out_data));
    ret = remote_unittest_15(dev_handle,
                             in_data.test, sizeof(in_data.test),
                             &in_data, sizeof(in_data),
                             &out_data, sizeof(out_data), &oalen,
                             out_bytebuf, sizeof(out_bytebuf));
    if (ret)
        rpc_error(15);
    else if (oalen != sizeof(out_data))
        verify_error(15, "oalen");
    else if (verify_bytebuf(out_bytebuf))
        verify_error(15, "obuf");
    else if (verify_data(&out_data))
        verify_error(15, "obuf2");

    /*                               */
    event_handles[0] = dalrpc_alloc_event(dev_handle);
    event_handles[1] = dalrpc_alloc_event(dev_handle);
    event_handles[2] = dalrpc_alloc_event(dev_handle);
    cb_handle = dalrpc_alloc_cb(dev_handle, test_cb, &out_data);
    in_data.regular_event = (uint32_t)event_handles[2];
    in_data.payload_event = (uint32_t)cb_handle;
    ret = remote_unittest_eventcfg(dev_handle, &in_data, sizeof(in_data));
    if (ret) {
        errmask |= (1 << 16);
        printk(KERN_INFO "%s: failed to configure asynch (%d)\n",
               __func__, ret);
    }

    /*            */
    ret = remote_unittest_eventtrig(dev_handle,
                                    REMOTE_UNITTEST_REGULAR_EVENT);
    if (ret) {
        errmask |= (1 << 17);
        printk(KERN_INFO "%s: failed to trigger event (%d)\n",
               __func__, ret);
    }
    ret = dalrpc_event_wait(event_handles[2], 1000);
    if (ret) {
        errmask |= (1 << 18);
        printk(KERN_INFO "%s: failed to receive event (%d)\n",
               __func__, ret);
    }

    /*                  */
    ret = remote_unittest_eventtrig(dev_handle,
                                    REMOTE_UNITTEST_REGULAR_EVENT);
    if (ret) {
        errmask |= (1 << 19);
        printk(KERN_INFO "%s: failed to trigger event (%d)\n",
               __func__, ret);
    }
    ret = dalrpc_event_wait_multiple(3, event_handles, 1000);
    if (ret != 2) {
        errmask |= (1 << 20);
        printk(KERN_INFO "%s: failed to receive event (%d)\n",
               __func__, ret);
    }

    /*               */
    ret = remote_unittest_eventtrig(dev_handle,
                                    REMOTE_UNITTEST_CALLBACK_EVENT);
    if (ret) {
        errmask |= (1 << 21);
        printk(KERN_INFO "%s: failed to trigger callback (%d)\n",
               __func__, ret);
    } else
        while (block_until_cb)
            ;

    dalrpc_dealloc_cb(dev_handle, cb_handle);
    dalrpc_dealloc_event(dev_handle, event_handles[0]);
    dalrpc_dealloc_event(dev_handle, event_handles[1]);
    dalrpc_dealloc_event(dev_handle, event_handles[2]);

    /*                       */
    ret = daldevice_detach(dev_handle);
    if (ret) {
        errmask |= (1 << 22);
        printk(KERN_INFO "%s: failed to detach (%d)\n", __func__, ret);
    }

    printk(KERN_INFO "%s: remote_unittest complete\n", __func__);

    *val = errmask;
    return 0;
}
Exemple #16
0
static int verify_hash_table(
                JournalFile *f,
                int data_fd, uint64_t n_data,
                int entry_fd, uint64_t n_entries,
                int entry_array_fd, uint64_t n_entry_arrays,
                usec_t *last_usec,
                bool show_progress) {

        uint64_t i, n;
        int r;

        assert(f);
        assert(data_fd >= 0);
        assert(entry_fd >= 0);
        assert(entry_array_fd >= 0);
        assert(last_usec);

        n = le64toh(f->header->data_hash_table_size) / sizeof(HashItem);
        if (n <= 0)
                return 0;

        r = journal_file_map_data_hash_table(f);
        if (r < 0)
                return log_error_errno(r, "Failed to map data hash table: %m");

        for (i = 0; i < n; i++) {
                uint64_t last = 0, p;

                if (show_progress)
                        draw_progress(0xC000 + scale_progress(0x3FFF, i, n), last_usec);

                p = le64toh(f->data_hash_table[i].head_hash_offset);
                while (p != 0) {
                        Object *o;
                        uint64_t next;

                        if (!contains_uint64(f->mmap, data_fd, n_data, p)) {
                                error(p, "Invalid data object at hash entry %"PRIu64" of %"PRIu64, i, n);
                                return -EBADMSG;
                        }

                        r = journal_file_move_to_object(f, OBJECT_DATA, p, &o);
                        if (r < 0)
                                return r;

                        next = le64toh(o->data.next_hash_offset);
                        if (next != 0 && next <= p) {
                                error(p, "Hash chain has a cycle in hash entry %"PRIu64" of %"PRIu64, i, n);
                                return -EBADMSG;
                        }

                        if (le64toh(o->data.hash) % n != i) {
                                error(p, "Hash value mismatch in hash entry %"PRIu64" of %"PRIu64, i, n);
                                return -EBADMSG;
                        }

                        r = verify_data(f, o, p, entry_fd, n_entries, entry_array_fd, n_entry_arrays);
                        if (r < 0)
                                return r;

                        last = p;
                        p = next;
                }

                if (last != le64toh(f->data_hash_table[i].tail_hash_offset)) {
                        error(p, "Tail hash pointer mismatch in hash table");
                        return -EBADMSG;
                }
        }

        return 0;
}
Exemple #17
0
/** Perform pingpong benchmark the enough times to get a reliable result. */
static void bench_pingpong(int is_master,
                           const unsigned char *sendbuf,
                           unsigned char *recvbuf,
                           size_t m,
                           int other,
                           void (*pingpong)(int,
                                            const void *,
                                            void *,
                                            size_t,
                                            int),
                           const char *suffix,
                           double mintime)
{
    uint64_t numsubrepeats = 1;
    uint64_t bestnumsubrepeats = -1;
    double besttime = INFINITY;

    /* avoid the first few tests, as they tend to be outliers */
    for (uint64_t r = 0; r < WARMUP_REPEATS; ++r) {
        subbench_pingpong(is_master, sendbuf, recvbuf, m,
                          other, pingpong, numsubrepeats);
    }

    for (uint64_t r = 0; r < NUM_REPEATS; ++r) {

        double time;
        while (1) {
            time = subbench_pingpong(is_master, sendbuf, recvbuf, m,
                                     other, pingpong, numsubrepeats);
            int should_break;
            if (is_master) {
                should_break = time >= mintime;
                xtry(MPI_Send(&should_break, 1, MPI_INT, other,
                              0, MPI_COMM_WORLD));
            } else {
                xtry(MPI_Recv(&should_break, 1, MPI_INT, other,
                              MPI_ANY_TAG, MPI_COMM_WORLD, MPI_STATUS_IGNORE));
            }
            if (should_break) {
                break;
            }
            numsubrepeats *= 2;
        }

        if (is_master) {
            time /= numsubrepeats;
            printf("time_%s_%zu /s = %.17g\n", suffix, r, time);
            if (time < besttime) {
                besttime = time;
                bestnumsubrepeats = numsubrepeats;
            }
        }
    }

    if (is_master) {
        printf("time_%s /s = %.17g\n", suffix, besttime);
        printf("numsubrepeats_%s = %zu\n", suffix, bestnumsubrepeats);
    }

    verify_data(recvbuf, m, other);
    memset(recvbuf, 0, m);
}
Exemple #18
0
/***********************************************************************
 *
 * Function: c_entry
 *
 * Purpose: Application entry point from the startup code
 *
 * Processing:
 *     See function.
 *
 * Parameters: None
 *
 * Outputs: None
 *
 * Returns: Always returns 1, or <0 on an error
 *
 * Notes: None
 *
 **********************************************************************/
void c_entry(void)
{
  UNS_32 ptw, *a1, sector, progblk;
  UNS_32 loadsize, loadcount;
  UNS_8 tmp16, tmp16i;
  UNS_8 *p8, tmp [16];
  int idx = 0;

  uart_output_init();

  /* Now to download the image */
  uart_output((UNS_8*)"X");

  /* Wait for 'p' */
  while (!uart_input(&tmp[0], 1));

  /* Wait for 8 bytes from other side */
  idx = 0;
  while (idx < 8)
  {
	  idx += uart_input(&tmp[idx], (8 - idx));
  }
  uart_output((UNS_8*)"o");

  a1 = (UNS_32 *) tmp;

  /* Get size of secondary file */
  loadsize = a1[1];

  /* Receive complete file using UART */
  loadcount = 0;
  p8 = (UNS_8 *) BURNER_LOAD_ADDR;
  while (loadsize > loadcount)
  {
	  loadcount += uart_input(p8 + loadcount, (loadsize - loadcount));
  }
  uart_output((UNS_8*)"t");

  if (loadsize > (31 * 512))
  {
   	uart_output((UNS_8*)"Image too large for kickstart, 15.5K max!\r\n");
	while (1);
  }

  /* Init NAND controller */
  if (nand_sb_mlc_init() == 0) 
  {
   	uart_output((UNS_8*)"Cannot initialize NAND device\r\n");
	while (1);
  }

  /* Disable write protect */
  nand_flash_wp_disable();

  wrbuff16 = (UNS_16 *) wrbuff;
  rdbuff8 = (UNS_8 *) rdbuff;
  wrbuff8 = (UNS_8 *) wrbuff;

  /* Setup a write block with a bad block marker in case it is
     needed */
  memset(wrbuff, 0xFF, 528);
  wrbuff8[NAND_SB_BADBLOCK_OFFS] = (UNS_8) ~NAND_GOOD_BLOCK_MARKER;

  uart_output((UNS_8*)"Formatting blocks...\r\n");
  progblk = 0;
  sector = nand_bp_to_sector(progblk, 0);

  /* Get sector address for first page of block */
  if (nand_sb_mlc_erase_block(progblk) == 0)
  {
	/* Erase failure, mark the block as bad */
	uart_output((UNS_8*)"Erase failure\r\n");	
   	nand_sb_mlc_write_sector(sector, wrbuff8);
  }

  /* Really, Block is reased? */
  nand_sb_mlc_read_sector(sector, rdbuff8);
  idx = compdata(rdbuff8, 0xFF);
  if(idx >= 0)
  {
		uart_output((UNS_8*)"Erase failure\r\n");	
		nand_sb_mlc_write_sector(sector, wrbuff8);
		while (1);
  }

  /* NAND is setup and ready */
  uart_output((UNS_8*)"Format complete\r\n");

  /* Setup the write buffer for page #0 ICR data */
  memset(wrbuff, 0x00, 528);

  /* Setup FLASH config for small block, 3 or 4 address */
  if (nandgeom.address_cycles == 3) 
  {
		/* 3 address cycles per sector, small block */
	    tmp16 = 0xF0;
  }
  else
  {
		/* 4 address cycles per sector, small block */
	    tmp16 = 0xD2;
  }

  /* Setup FLASH config for large block, 5 address */
  tmp16i = 0xFF - tmp16;
  wrbuff16[0] = tmp16;
  wrbuff16[2] = tmp16i;
  wrbuff16[4] = tmp16;
  wrbuff16[6] = tmp16i;

  ptw = loadsize / nandgeom.data_bytes_per_page;
  if ((ptw * nandgeom.data_bytes_per_page) < loadsize)
  {
	ptw++;
  }
  ptw++; /* Include non-used sector */

  tmp16 = (UNS_16) ptw;
  tmp16i = 0x00FF - tmp16;
  wrbuff16[8] = tmp16;
  wrbuff16[10] = tmp16i;
  wrbuff16[12] = tmp16;
  wrbuff16[14] = tmp16i;
  wrbuff16[16] = tmp16;
  wrbuff16[18] = tmp16i;
  wrbuff16[20] = tmp16;
  wrbuff16[22] = tmp16i;
  wrbuff16[24] = 0x00AA; /* Good block marker for page #0 ICR only */

  /* Get location where to write ICR */
  progblk = 0;
  sector = nand_bp_to_sector(progblk, 0);

  /* Write ICR data to first usable block/page #0 */
  nand_sb_mlc_write_sector(sector, wrbuff8);

  /* Verify page #0 */
  nand_sb_mlc_read_sector(sector, rdbuff8);
  idx = isblksame(rdbuff8, wrbuff8);
  if (idx >= 0)
  {
	uart_output((UNS_8*)"Error writing ICR data in page #0\r\n");
	while (1);
  }

  progblk = 0;
  sector = nand_bp_to_sector(progblk, 1);
  uart_output((UNS_8*)"\nWritting kickstart into flash...\r\n");

  nand_write_sectors(sector, p8, loadsize);
  uart_output((UNS_8*)"Verifing data...");
  idx = verify_data(sector, p8, rdbuff8, loadsize);
  if(idx >= 0)
	uart_output((UNS_8*)"...Failed\r\n");
  else
	uart_output((UNS_8*)"...Successfully\r\n");
  
  uart_output((UNS_8*)"NAND flash is programmed Successfully\r\n");		

  /* Loop forever */
  while (1);
}