void data_cout(void){ if(DATA == status){ printf("Asking data \n"); status = BUSY; for(uint8_t i = 0; i < 1; i++){ printf("Asking data from %d DIS, \n", dis[i].num); if(dis[i].status == DIS_STATUS_ACTIVE){ if(!DIS_getData(dis[i].num, data_buf)){ printf("Got data %X, %X, %X, %X, \n", data_buf[0],data_buf[1],data_buf[2],data_buf[3]); memcpy(data.data_buf, data_buf, 4); if(validate_data()){ printf("Got data %f \n", data.data_var); clr_buf(); error = dis_db_set_data(dis[i].num, data.data_var); if(error){ printf("Failed to set data error: %d \n", error); } } else { printf("Data is not valid \n"); } } } } status_next = IDLE; } }
//------------------------------------------------ // Complete a database read operation. // static void get_cb(int return_value, ev2citrusleaf_bin* bins, int n_bins, uint32_t generation, uint32_t expiration, void* pv_udata) { int k = (int)(uint64_t)pv_udata; int b = k % g_config.num_bases; switch (return_value) { case EV2CITRUSLEAF_OK: // Not 100% sure we only get bins if return value is OK. TODO - check. validate_data(b, k, bins, n_bins); // Invalid data will log complaints, but won't exit event loop. break; case EV2CITRUSLEAF_FAIL_TIMEOUT: DETAIL("GET TIMEOUT: base %2d, key %d", b, k); g_bases[b].num_get_timeouts++; // Otherwise ok... break; case EV2CITRUSLEAF_FAIL_NOTFOUND: DETAIL("NOT FOUND: base %2d, key %d", b, k); g_bases[b].num_not_found++; // Otherwise ok... break; default: LOG("ERROR: return-value %d, base %2d, key %d", return_value, b, k); // Won't exit event loop. break; } }
/** * Validates the bootloader found at the specified offset in the SPI NOR * * @param sf pointer to spi flash data structure * @param offset offset of bootloader in spi NOR flash * @param size size of bootloader * * @return 0 if a valid bootloader was found at the offset * 1 if no valid bootloader was found * -1 on error */ int validate_spi_bootloader(struct spi_flash *sf, uint32_t offset, size_t size) { struct bootloader_header *header; uint8_t *buffer; int rc; buffer = calloc(size, 1); if (!buffer) { puts("Out of memory\n"); return -1; } debug("%s(%p, 0x%x, 0x%x)\n", __func__, sf, offset, size); rc = spi_flash_read(sf, offset, size, buffer); if (rc) { puts("Error reading bootloader\n"); rc = -1; } else { header = (struct bootloader_header *)buffer; if (validate_header(header) || validate_data(header)) { printf("Invalid bootloader found at offset 0x%x\n", offset); rc = 1; } else { rc = 0; } } if (buffer) free(buffer); return rc; }
EXPORT_C #endif gboolean gst_rtp_buffer_validate_data (guint8 * data, guint len) { return validate_data (data, len, NULL, 0); }
/** * gst_rtp_buffer_validate: * @buffer: the buffer to validate * * Check if the data pointed to by @buffer is a valid RTP packet using * validate_data(). * Use this function to validate a packet before using the other functions in * this module. * * Returns: TRUE if @buffer is a valid RTP packet. */ gboolean gst_rtp_buffer_validate (GstBuffer * buffer) { guint8 *data; guint len; g_return_val_if_fail (GST_IS_BUFFER (buffer), FALSE); data = GST_BUFFER_DATA (buffer); len = GST_BUFFER_SIZE (buffer); return validate_data (data, len, NULL, 0); }
void asteroid_editor::OnOK() { int i; update_init(); if (!validate_data()) { return; } for (i=0; i<1 /*MAX_ASTEROID_FIELDS*/; i++) Asteroid_field = a_field[i]; update_map_window(); theApp.record_window_data(&Asteroid_wnd_data, this); CDialog::OnOK(); }
static void get_done (pami_context_t context, void * cookie, pami_result_t result) { get_info_t * info = (get_info_t *) cookie; fprintf (stderr, ">> 'get_done' callback, cookie = %p (info->value = %zu => %zu), result = %d\n", cookie, *(info->value), *(info->value)-1, result); size_t status = 0; /* success */ if (result != PAMI_SUCCESS) { fprintf (stderr, " 'get_done' callback, PAMI_Rget failed\n"); status = 1; /* get failed */ } else { /* validate the data! */ print_data ((void *)info->buffer, 4 * 12); if (!validate_data(info->buffer, info->bytes, 4)) { fprintf (stderr, " 'get_done' callback,) PAMI_Rget data validation error.\n"); status = 2; /* get data validation failure */ } } /* Send an 'ack' to the origin */ pami_send_immediate_t parameters; parameters.dispatch = DISPATCH_ID_ACK; parameters.dest = info->origin; parameters.header.iov_base = &status; parameters.header.iov_len = sizeof(status); parameters.data.iov_base = NULL; parameters.data.iov_len = 0; parameters.hints = null_send_hint; PAMI_Send_immediate (context, ¶meters); /* Destroy the local memory region */ PAMI_Memregion_destroy (context, &(info->memregion)); --*(info->value); free (cookie); fprintf (stderr, "<< 'get_done' callback\n"); }
void Parser::validate_instruction(unsigned char* iBlock, unsigned int iSize, unsigned int& tLoc) { tick(); // Conditional if (mGrammar->isConditional(iBlock[tLoc])) validate_conditional(iBlock, iSize, tLoc); // Function else if (mGrammar->isFunction(iBlock[tLoc])) validate_function(iBlock, iSize, tLoc); // Data else if (mGrammar->isData(iBlock[tLoc])) return validate_data(iBlock, iSize, tLoc); // Unknown else throw Exception(SYNTAX, "unknown byte identifier"); }
static void get_done (pami_context_t context, void * cookie, pami_result_t result) { get_info_t * info = (get_info_t *) cookie; TRACE_ERR((stderr, ">> get_done() cookie = %p (info->value = %d => %d), result = %zu\n", cookie, *(info->value), *(info->value)-1, result)); size_t status = 0; /* success */ if (result != PAMI_SUCCESS) { TRACE_ERR((stderr, " get_done() PAMI_Get failed\n")); status = 1; /* get failed */ } else { /* validate the data! */ print_data ((void *)info->buffer, 4*12); if (!validate_data(info->buffer, info->bytes, 4)) { TRACE_ERR((stderr, " get_done() PAMI_Get data validation error.\n")); status = 2; /* get data validation failure */ } } /* Send an 'ack' to the origin */ pami_send_immediate_t parameters; parameters.dispatch = DISPATCH_ID_ACK; parameters.dest = info->origin; parameters.header.iov_base = &status; parameters.header.iov_len = sizeof(status); parameters.data.iov_base = NULL; parameters.data.iov_len = 0; parameters.hints = null_send_hint; PAMI_Send_immediate (context, ¶meters); --*(info->value); free (cookie); TRACE_ERR((stderr, "<< get_done()\n")); }
void CAddVariableDlg::OnOK() { // validation name validate_variable_name(RESET_FOCUS); // validate data if ( m_name_validated ) { validate_data(RESET_FOCUS); } // both ok, then store results if ( m_name_validated && m_data_validated ) { // int sexp_add_variable(char *text, char*, int type); // char temp_name[32]; // char temp_value[32]; // strcpy_s(temp_name, m_variable_name); // strcpy_s(temp_value, m_default_value); // SEXP_VARIABLE_NUMBER SEXP_VARIABLE_STRING // int type; // // if (m_type_number) { // type = SEXP_VARIABLE_NUMBER; // } else { // type = SEXP_VARIABLE_STRING; // } // // // Goober5000 // if (m_type_player_persistent) { // type |= SEXP_VARIABLE_PLAYER_PERSISTENT; // } else if (m_type_campaign_persistent) { // type |= SEXP_VARIABLE_CAMPAIGN_PERSISTENT; // } // // m_sexp_var_index = sexp_add_variable(temp_value, temp_name, type); // this get done for free CDialog::OnOk() UpdateData(TRUE); m_create = true; CDialog::OnOK(); } }
int main(int argc, const char **argv) { qeo_factory_t *factory; qeocore_reader_t *reader; qeocore_writer_t *writer; qeocore_type_t *type; qeocore_data_t *rdata, *wdata; int i; for (i = 0; i < 2; i++) { /* initialize */ assert(NULL != (factory = qeocore_factory_new(QEO_IDENTITY_DEFAULT))); init_factory(factory); assert(NULL != (type = nested_type_get(1, 0, 0))); assert(QEO_OK == qeocore_type_register(factory, type, "nested")); assert(NULL != (reader = qeocore_reader_open(factory, type, NULL, QEOCORE_EFLAG_STATE_UPDATE | QEOCORE_EFLAG_ENABLE, NULL, NULL))); assert(NULL != (writer = qeocore_writer_open(factory, type, NULL, QEOCORE_EFLAG_STATE_UPDATE | QEOCORE_EFLAG_ENABLE, NULL, NULL))); /* write */ assert(NULL != (wdata = qeocore_writer_data_new(writer))); fill_data(wdata); assert(QEO_OK == qeocore_writer_write(writer, wdata)); /* check data */ assert(NULL != (rdata = qeocore_reader_data_new(reader))); assert(QEO_OK == qeocore_reader_read(reader, NULL, rdata)); expected_status = QEOCORE_DATA; validate_data(rdata); /* remove */ assert(QEO_OK == qeocore_writer_remove(writer, wdata)); /* clean up */ qeocore_data_free(wdata); qeocore_data_free(rdata); qeocore_writer_close(writer); qeocore_reader_close(reader); qeocore_type_free(type); qeocore_factory_close(factory); } }
void test_validate_data_and_payload_creation(const axutil_env_t* env) { wsf_wsdl_data_t* data = NULL; wsf_wsdl_data_template_t* data_template = NULL; axis2_bool_t success; axis2_char_t* payload; AXIS2_LOG_DEBUG_MSG(env->log, "[wsf_wsdl_test] Starting test_wsdl_data..."); data = create_params(env); if (data) { AXIS2_LOG_DEBUG_MSG(env->log, "[wsf_wsdl_test]data is not NULL, again a good sign!"); } data_template = create_template(env); if (data_template) { AXIS2_LOG_DEBUG_MSG(env->log, "[wsf_wsdl_test]wow!, even template is not NULL!"); } success = validate_data(env, NULL, data_template, data, VALIDATION_CRITERIA_REQUEST_MODE_TYPE); if (success) { AXIS2_LOG_DEBUG_MSG(env->log, "[wsf_wsdl_test]validation result : SUCCESS!!!"); } payload = create_payload(env, data); AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "[wsf_wsdl_test]payload : %s", payload); AXIS2_LOG_DEBUG_MSG(env->log, "[wsf_wsdl_test] Ending test_wsdl_data..."); }
int do_bootloader_validate(cmd_tbl_t * cmdtp, int flag, int argc, char *const argv[]) { uint32_t image_addr = 0; const bootloader_header_t *header; if (argc >= 2) image_addr = simple_strtoul(argv[1], NULL, 16); if (!image_addr) { image_addr = getenv_hex("fileaddr", load_addr); if (!image_addr) { puts("ERROR: Unable to get image address from " "'fileaddr' environment variable\n"); return 1; } } header = (void *)image_addr; if (validate_header(header)) { puts("Image does not have valid header\n"); return 1; } if (validate_data(header)) return 1; printf("Image validated. Header size %d, data size %d\n", header->hlen, header->dlen); printf(" Header crc 0x%x, data crc 0x%x\n", header->hcrc, header->dcrc); printf(" Image link address is 0x%llx\n", header->address); return 0; }
/** * gst_rtp_buffer_list_validate: * @list: the buffer list to validate * * Check if all RTP packets in the @list are valid using validate_data(). * Use this function to validate an list before using the other functions in * this module. * * Returns: TRUE if @list consists only of valid RTP packets. * * Since: 0.10.24 */ gboolean gst_rtp_buffer_list_validate (GstBufferList * list) { guint16 prev_seqnum = 0; GstBufferListIterator *it; guint i = 0; g_return_val_if_fail (GST_IS_BUFFER_LIST (list), FALSE); it = gst_buffer_list_iterate (list); g_return_val_if_fail (it != NULL, FALSE); /* iterate through all the RTP packets in the list */ while (gst_buffer_list_iterator_next_group (it)) { GstBuffer *rtpbuf; GstBuffer *paybuf; guint8 *packet_header; guint8 *packet_payload; guint payload_size; guint packet_size; /* each group should consists of 2 buffers: one containing the RTP header * and the other one the payload, FIXME, relax the requirement of only one * payload buffer. */ if (gst_buffer_list_iterator_n_buffers (it) != 2) goto invalid_list; /* get the RTP header */ rtpbuf = gst_buffer_list_iterator_next (it); packet_header = GST_BUFFER_DATA (rtpbuf); if (packet_header == NULL) goto invalid_list; /* get the payload */ paybuf = gst_buffer_list_iterator_next (it); packet_payload = GST_BUFFER_DATA (paybuf); if (packet_payload == NULL) { goto invalid_list; } payload_size = GST_BUFFER_SIZE (paybuf); if (payload_size == 0) { goto invalid_list; } /* the size of the RTP packet within the current group */ packet_size = GST_BUFFER_SIZE (rtpbuf) + payload_size; /* check the sequence number */ if (G_UNLIKELY (i == 0)) { prev_seqnum = g_ntohs (GST_RTP_HEADER_SEQ (packet_header)); i++; } else { if (++prev_seqnum != g_ntohs (GST_RTP_HEADER_SEQ (packet_header))) goto invalid_list; } /* validate packet */ if (!validate_data (packet_header, packet_size, packet_payload, payload_size)) { goto invalid_list; } } gst_buffer_list_iterator_free (it); return TRUE; /* ERRORS */ invalid_list: { gst_buffer_list_iterator_free (it); return FALSE; } }
void statsrequest(void) { int i; int columns; int columnsread; double v[2]; static char *file_name = NULL; /* Vars to hold data and results */ long n; /* number of records retained */ long max_n; static double *data_x = NULL; static double *data_y = NULL; /* values read from file */ long invalid; /* number of missing/invalid records */ long blanks; /* number of blank lines */ long doubleblanks; /* number of repeated blank lines */ long out_of_range; /* number pts rejected, because out of range */ struct file_stats res_file; struct sgl_column_stats res_x, res_y; struct two_column_stats res_xy; float *matrix; /* matrix data. This must be float. */ int nc, nr; /* matrix dimensions. */ int index; /* Vars for variable handling */ static char *prefix = NULL; /* prefix for user-defined vars names */ /* Vars that control output */ TBOOLEAN do_output = TRUE; /* Generate formatted output */ c_token++; /* Parse ranges */ AXIS_INIT2D(FIRST_X_AXIS, 0); AXIS_INIT2D(FIRST_Y_AXIS, 0); parse_range(FIRST_X_AXIS); parse_range(FIRST_Y_AXIS); /* Initialize */ columnsread = 2; invalid = 0; /* number of missing/invalid records */ blanks = 0; /* number of blank lines */ doubleblanks = 0; /* number of repeated blank lines */ out_of_range = 0; /* number pts rejected, because out of range */ n = 0; /* number of records retained */ nr = 0; /* Matrix dimensions */ nc = 0; max_n = INITIAL_DATA_SIZE; free(data_x); free(data_y); data_x = vec(max_n); /* start with max. value */ data_y = vec(max_n); if ( !data_x || !data_y ) int_error( NO_CARET, "Internal error: out of memory in stats" ); n = invalid = blanks = doubleblanks = out_of_range = nr = 0; /* Get filename */ free ( file_name ); file_name = try_to_get_string(); if ( !file_name ) int_error(c_token, "missing filename"); /* =========================================================== v923z: insertion for treating matrices EAM: only handles ascii matrix with uniform grid, and fails to apply any input data transforms =========================================================== */ if ( almost_equals(c_token, "mat$rix") ) { df_open(file_name, 3, NULL); index = df_num_bin_records - 1; /* We take these values as set by df_determine_matrix_info See line 1996 in datafile.c */ nc = df_bin_record[index].scan_dim[0]; nr = df_bin_record[index].scan_dim[1]; n = nc * nr; matrix = (float *)df_bin_record[index].memory_data; /* Fill up a vector, so that we can use the existing code. */ if ( !redim_vec(&data_x, n ) ) { int_error( NO_CARET, "Out of memory in stats: too many datapoints (%d)?", n ); } for( i=0; i < n; i++ ) { data_y[i] = (double)matrix[i]; } /* We can close the file here, there is nothing else to do */ df_close(); /* We will invoke single column statistics for the matrix */ columns = 1; } else { /* Not a matrix */ columns = df_open(file_name, 2, NULL); /* up to 2 using specs allowed */ if (columns < 0) int_error(NO_CARET, "Can't read data file"); if (columns > 2 ) int_error(c_token, "Need 0 to 2 using specs for stats command"); /* If the user has set an explicit locale for numeric input, apply it here so that it affects data fields read from the input file. */ /* v923z: where exactly should this be? here or before the matrix case? * I think, we should move everything here to before trying to open the file. * There is no point in trying to read anything, if the axis is logarithmic, e.g. */ set_numeric_locale(); /* For all these below: we could save the state, switch off, then restore */ if ( axis_array[FIRST_X_AXIS].log || axis_array[FIRST_Y_AXIS].log ) int_error( NO_CARET, "Stats command not available with logscale active"); if ( axis_array[FIRST_X_AXIS].datatype == DT_TIMEDATE || axis_array[FIRST_Y_AXIS].datatype == DT_TIMEDATE ) int_error( NO_CARET, "Stats command not available in timedata mode"); if ( polar ) int_error( NO_CARET, "Stats command not available in polar mode" ); if ( parametric ) int_error( NO_CARET, "Stats command not available in parametric mode" ); /* The way readline and friends work is as follows: - df_open will return the number of columns requested in the using spec so that "columns" will be 0, 1, or 2 (no using, using 1, using 1:2) - readline always returns the same number of columns (for us: 1 or 2) - using 1:2 = return two columns, skipping lines w/ bad data - using 1 = return sgl column (supply zeros (0) for the second col) - no using = return two columns (first two), fail on bad data We need to know how many columns to process. If columns==1 or ==2 (that is, if there was a using spec), all is clear and we use the value of columns. But: if columns is 0, then we need to figure out the number of cols read from the return value of readline. If readline ever returns 1, we take that; only if it always returns 2 do we assume two cols. */ while( (i = df_readline(v, 2)) != DF_EOF ) { columnsread = ( i > columnsread ? i : columnsread ); if ( n >= max_n ) { max_n = (max_n * 3) / 2; /* increase max_n by factor of 1.5 */ /* Some of the reallocations went bad: */ if ( 0 || !redim_vec(&data_x, max_n) || !redim_vec(&data_y, max_n) ) { df_close(); int_error( NO_CARET, "Out of memory in stats: too many datapoints (%d)?", max_n ); } } /* if (need to extend storage space) */ switch (i) { case DF_MISSING: case DF_UNDEFINED: /* Invalids are only recognized if the syntax is like this: stats "file" using ($1):($2) If the syntax is simply: stats "file" using 1:2 then df_readline simply skips invalid records (does not return anything!) Status: 2009-11-02 */ invalid += 1; continue; case DF_FIRST_BLANK: blanks += 1; continue; case DF_SECOND_BLANK: blanks += 1; doubleblanks += 1; continue; case 0: int_error( NO_CARET, "bad data on line %d of file %s", df_line_number, df_filename ? df_filename : "" ); break; case 1: /* Read single column successfully */ if ( validate_data(v[0], FIRST_Y_AXIS) ) { data_y[n] = v[0]; n++; } else { out_of_range++; } break; case 2: /* Read two columns successfully */ if ( validate_data(v[0], FIRST_X_AXIS) && validate_data(v[1], FIRST_Y_AXIS) ) { data_x[n] = v[0]; data_y[n] = v[1]; n++; } else { out_of_range++; } break; } } /* end-while : done reading file */ df_close(); /* now resize fields to actual length: */ redim_vec(&data_x, n); redim_vec(&data_y, n); /* figure out how many columns where really read... */ if ( columns == 0 ) columns = columnsread; } /* end of case when the data file is not a matrix */ /* Now finished reading user input; return to C locale for internal use*/ reset_numeric_locale(); /* PKJ - TODO: similar for logscale, polar/parametric, timedata */ /* No data! Try to explain why. */ if ( n == 0 ) { if ( out_of_range > 0 ) int_error( NO_CARET, "All points out of range" ); else int_error( NO_CARET, "No valid data points found in file" ); } /* Parse the remainder of the command line: 0 to 2 tokens possible */ while( !(END_OF_COMMAND) ) { if ( almost_equals( c_token, "out$put" ) ) { do_output = TRUE; c_token++; } else if ( almost_equals( c_token, "noout$put" ) ) { do_output = FALSE; c_token++; } else if ( almost_equals(c_token, "pre$fix") || equals(c_token, "name")) { c_token++; free ( prefix ); prefix = try_to_get_string(); if (!legal_identifier(prefix) || !strcmp ("GPVAL_", prefix)) int_error( --c_token, "illegal prefix" ); } else { int_error( c_token, "Expecting [no]output or prefix"); } } /* Set defaults if not explicitly set by user */ if (!prefix) prefix = gp_strdup("STATS_"); i = strlen(prefix); if (prefix[i-1] != '_') { prefix = gp_realloc(prefix, i+2, "prefix"); strcat(prefix,"_"); } /* Do the actual analysis */ res_file = analyze_file( n, out_of_range, invalid, blanks, doubleblanks ); if ( columns == 1 ) { res_y = analyze_sgl_column( data_y, n, nr ); } if ( columns == 2 ) { /* If there are two columns, then the data file is not a matrix */ res_x = analyze_sgl_column( data_x, n, 0 ); res_y = analyze_sgl_column( data_y, n, 0 ); res_xy = analyze_two_columns( data_x, data_y, res_x, res_y, n ); } /* Store results in user-accessible variables */ /* Clear out any previous use of these variables */ del_udv_by_name( prefix, TRUE ); file_variables( res_file, prefix ); if ( columns == 1 ) { sgl_column_variables( res_y, prefix, "" ); } if ( columns == 2 ) { sgl_column_variables( res_x, prefix, "_x" ); sgl_column_variables( res_y, prefix, "_y" ); two_column_variables( res_xy, prefix ); } /* Output */ if ( do_output ) { file_output( res_file ); if ( columns == 1 ) sgl_column_output( res_y, res_file.records ); else two_column_output( res_x, res_y, res_xy, res_file.records ); } /* Cleanup */ free(data_x); free(data_y); data_x = NULL; data_y = NULL; free( file_name ); file_name = NULL; free( prefix ); prefix = NULL; }
/** * Command for updating a bootloader image in flash. This function * parses the arguments, and validates the header (if header exists.) * Actual flash updating is done by flash type specific functions. * * @return 0 on success * 1 on failure */ int do_bootloader_update(cmd_tbl_t * cmdtp, int flag, int argc, char *const argv[]) { uint32_t image_addr = 0; uint32_t image_len = 0; uint32_t burn_addr = 0; int failsafe = 0; const bootloader_header_t *header; int force_nand = 0; int force_spi = 0; if (argc >= 2) { if (!strcmp(argv[1], "nand")) { debug("Forced NAND bootloader update\n"); force_nand = 1; argc--; argv++; } else if (!strcmp(argv[1], "spi")) { debug("Forced SPI bootloader update\n"); force_spi = 1; argc--; argv++; if (!strcmp(argv[1], "failsafe")) { failsafe = 1; argc--; argv++; } } } if (argc >= 2) image_addr = simple_strtoul(argv[1], NULL, 16); if (argc >= 3) image_len = simple_strtoul(argv[2], NULL, 16); if (argc >= 4) { if (force_spi || force_nand) { if (!strcmp("failsafe", argv[3])) failsafe = 1; } else { burn_addr = simple_strtoul(argv[3], NULL, 16); } } if ((argc >= 5) && (strcmp("failsafe", argv[4]) == 0)) failsafe = 1; /* If we don't support failsafe images, we need to put the image at the * base of flash, so we treat all images like failsafe image in this * case. */ #ifdef CONFIG_OCTEON_NO_FAILSAFE failsafe = 1; burn_addr = 0x1fc00000; #endif if (!burn_addr) burn_addr = getenv_hex("burnaddr", 0); if (!image_addr) { image_addr = getenv_hex("fileaddr", load_addr); if (!image_addr) { puts("ERROR: Unable to get image address from " "'fileaddr' environment variable\n"); return 1; } } DBGUPD("%s: burn address: 0x%x, image address: 0x%x\n", __func__, burn_addr, image_addr); /* Figure out what kind of flash we are going to update. This will * typically come from the bootloader header. If the bootloader does * not have a header, then it is assumed to be a legacy NOR image, and * a destination NOR flash address must be supplied. NAND images * _must_ have a header. */ header = (void *)image_addr; if (header->magic != BOOTLOADER_HEADER_MAGIC) { /* No header, assume headerless NOR bootloader image */ puts("No valid bootloader header found. Assuming old headerless image\n" "Image checks cannot be performed\n"); if (!burn_addr) { burn_addr = CONFIG_SYS_NORMAL_BOOTLOADER_BASE; DBGUPD("Unable to get burn address from 'burnaddr' environment variable,\n"); DBGUPD(" using default 0x%x\n", burn_addr); } /* We only need image length for the headerless case */ if (!image_len) { image_len = getenv_hex("filesize", 0); if (!image_len) { puts("ERROR: Unable to get image size from " "'filesize' environment variable\n"); return 1; } } return do_bootloader_update_nor(image_addr, image_len, burn_addr, failsafe); } /* We have a header, so validate image */ if (validate_header(header)) { puts("ERROR: Image header has invalid CRC.\n"); return 1; } if (validate_data(header)) /* Errors printed */ return 1; /* We now have a valid image, so determine what to do with it. */ puts("Valid bootloader image found.\n"); /* Check to see that it is for the board we are running on */ if (header->board_type != cvmx_sysinfo_get()->board_type) { printf("Current board type: %s (%d), image board type: %s (%d)\n", cvmx_board_type_to_string(cvmx_sysinfo_get()->board_type), cvmx_sysinfo_get()->board_type, cvmx_board_type_to_string(header->board_type), header->board_type); if (cvmx_sysinfo_get()->board_type != CVMX_BOARD_TYPE_GENERIC && header->board_type != CVMX_BOARD_TYPE_GENERIC) { puts("ERROR: Bootloader image is not for this board type.\n"); return 1; } else { puts("Loading mismatched image since current " "or new bootloader is generic.\n"); } } /* SDK 1.9.0 NOR images have rev of 1.1 and unkown image_type */ if (((header->image_type == BL_HEADER_IMAGE_NOR) || (header->image_type == BL_HEADER_IMAGE_UNKNOWN && header->maj_rev == 1 && header->min_rev == 1)) && !force_nand && !force_spi) { debug("Updating NOR bootloader\n"); return do_bootloader_update_nor(image_addr, 0, burn_addr, failsafe); #if defined(CONFIG_CMD_OCTEON_NAND) || defined(CONFIG_OCTEON_NAND_BOOT_END) } else if (!force_spi && (header->image_type == BL_HEADER_IMAGE_STAGE2 || header->image_type == BL_HEADER_IMAGE_STAGE3 || force_nand)) { debug("Updating NAND bootloader\n"); return (do_bootloader_update_nand(image_addr)); #endif #if defined(CONFIG_OCTEON_SPI_BOOT_END) } else if (!force_nand && (header->image_type == BL_HEADER_IMAGE_STAGE2 || header->image_type == BL_HEADER_IMAGE_STAGE3 || force_spi)) { debug("Updating SPI bootloader\n"); return do_bootloader_update_spi(image_addr, header->dlen + header->hlen, failsafe, false); #else } else { puts("ERROR: This bootloader not compiled for this medium\n"); return 1; #endif } return 1; }