示例#1
0
int build_new_image(const struct flashctx *flash, uint8_t *oldcontents, uint8_t *newcontents)
{
	unsigned int start = 0;
	romentry_t *entry;
	unsigned int size = flash->chip->total_size * 1024;

	/* If no regions were specified for inclusion, assume
	 * that the user wants to write the complete new image.
	 */
	if (num_include_args == 0)
		return 0;

	/* Non-included romentries are ignored.
	 * The union of all included romentries is used from the new image.
	 */
	while (start < size) {
		entry = get_next_included_romentry(start);
		/* No more romentries for remaining region? */
		if (!entry) {
			memcpy(newcontents + start, oldcontents + start,
			       size - start);
			break;
		}
		/* For non-included region, copy from old content. */
		if (entry->start > start)
			memcpy(newcontents + start, oldcontents + start,
			       entry->start - start);
		/* Skip to location after current romentry. */
		start = entry->end + 1;
		/* Catch overflow. */
		if (!start)
			break;
	}
	return 0;
}
示例#2
0
//> sheldon : this is a new implemnt for build_new_image !!
//+
int build_new_image2(struct flashctx *flash, bool oldcontents_valid, uint8_t *oldcontents, uint8_t *newcontents)
{
  int ret = 0;
	unsigned int start = 0;
	romentry_t *entry;
	unsigned int size = flash->chip->total_size * 1024;

	/* If no regions were specified for inclusion, assume
	 * that the user wants to write the complete new image.
	 */
	if (num_include_args == 0)
		return 0;

	/* Non-included romentries are ignored.
	 * The union of all included romentries is used from the new image.
	 */
	while (start < size) {
		entry = get_next_included_romentry(start);
		/* No more romentries for remaining region? */
		if (!entry) {
      /* For non-included region, copy from new content. */
			copy_old_content2(flash, oldcontents_valid, oldcontents, newcontents, start,
					 size - start);
			break;
		}
    
    //
    // read included range from chip to oldcontents
    //
    ret = flash->chip->read(flash, oldcontents + entry->start, entry->start, entry->end - entry->start + 1);
    if (ret != 0) {
      msg_gerr("Failed to read chunk 0x%06x-0x%06x.\n", entry->start, entry->end);
      return 1;
    }
    
		/* For non-included region, copy from new content. */
		if (entry->start > start)
      copy_old_content2(flash, oldcontents_valid, oldcontents, newcontents, start,
					 entry->start - start);
		/* Skip to location after current romentry. */
		start = entry->end + 1;
		/* Catch overflow. */
		if (!start)
			break;
	}
	return 0;
}
示例#3
0
//> sheldon: Add a public interface to retrieve included ranges
//+
int get_next_included_range(struct flashctx *flash, unsigned int start, chipoff_t *included_start, chipoff_t *included_end, char **name)
{
	romentry_t *entry;
	unsigned int size = flash->chip->total_size * 1024;
  
  if (start >= size) return 1;
  
  entry = get_next_included_romentry(start);
  
  /* No more romentries for remaining region? */
  if (!entry) return 1;
  
  if (included_start != NULL) {
    *included_start = entry->start;
  }
  if (included_end != NULL) {
    *included_end = entry->end;
  }
  if (name != NULL) {
    *name = entry->name;
  }
  
  return 0;
}