commit 1518af1ababab48ffe39867c5164fbf76fd48ea1
Author: Nikolay Nikolaev <evrinoma@gmail.com>
Date:   Thu Mar 21 15:39:04 2013 +0400

    If we detected Multiple flash chips than
    we can easy save all chips in dynamic list - pflashes.
    and we will not have a restrictions with number chips
    This is Dynamic List to sorted by Volage.
    Also I added to dynamic list the new parameter HEAD
    TODO:
      I want to add a new key possibly "-F" (or other) 
      for probing read data from chips 
      if we detect Multiple chips with identical value model_id. 
      The reading data from chips let's begin 
      from model_id with minimal value parameter  voltage.
      after that i think that we can easily write a normal names of chips
      rewrite function printing names of chips on Wiki page
      8)
    sequence of patching
    flashrom-001-list.patch
    flashrom-001-sort.patch

Signed-off-by: Nikolay Nikolaev <evrinoma@gmail.com>

diff --git a/cli_classic.c b/cli_classic.c
index 7ea0a96..6c10088 100644
--- a/cli_classic.c
+++ b/cli_classic.c
@@ -96,6 +96,7 @@ int main(int argc, char *argv[])
 	const struct flashchip *chip = NULL;
 	struct flashctx flashes = {0};
 	struct flashctx *pflashes = NULL;
+	struct flashctx *psort = NULL;
 	struct flashctx *paddress = NULL;
 	const char *name;
 	int namelen, opt, i, j;
@@ -439,23 +440,54 @@ int main(int argc, char *argv[])
 				exit(1);
 			}
 			memcpy(pflashes, &flashes, sizeof(struct flashctx));
-			pflashes->last = paddress;
-			pflashes->next = NULL;
-			if (paddress != NULL)
-				paddress->next = pflashes;
+			/*
+			 * add item and sort by voltage
+			 */
+			if (paddress != NULL) {
+				for (psort = paddress; ; psort = psort->last) {
+					if (psort->chip->voltage.min >= pflashes->chip->voltage.min) {
+						pflashes->next = psort->next;
+						pflashes->last = psort;
+						psort->next = pflashes;
+						pflashes->head = &paddress;
+						if (psort == paddress)
+							paddress = pflashes;
+						else {
+							psort = pflashes->next;
+							psort->last = pflashes;
+						}
+						pflashes = paddress;
+						break;
+					}
+					if (psort->last == NULL) {
+						pflashes->next = psort;
+						pflashes->last = NULL;
+						psort->last = pflashes;
+						pflashes->head = &paddress;
+						pflashes = *(psort->head);
+						break;
+					}
+				}
+			} else {
+				pflashes->head = &paddress;
+				pflashes->last = paddress;
+				pflashes->next = NULL;
+			}
 			chipcount++;
 			startchip++;
 		}
 	}
-
 	if (chipcount > 1) {
-		msg_cinfo("Multiple flash chips were detected: \n");
-		paddress = pflashes;
-		while (pflashes != NULL) {
-			(pflashes->last == NULL) ? msg_cinfo("\"%s\"", pflashes->chip->name) : msg_cinfo("\"%s\",", pflashes->chip->name);
-			pflashes = pflashes->last;
+		msg_cinfo("Multiple flash chips were detected:\n");
+		for (pflashes = *(pflashes->head); ; pflashes = pflashes->last) {
+			if (pflashes->last == NULL) {
+				msg_cinfo("\"%s\"", pflashes->chip->name);
+				pflashes = *(pflashes->head);
+				break;
+			} else {
+				msg_cinfo("\"%s\",", pflashes->chip->name);
+			}
 		}
-		pflashes = paddress;
 		msg_cinfo("\nPlease specify which chip to use with the -c <chipname> option.\n");
 		ret = 1;
 		goto out_shutdown;
diff --git a/flash.h b/flash.h
index 7fcc3e1..37cb2ec 100644
--- a/flash.h
+++ b/flash.h
@@ -175,6 +175,7 @@ struct flashctx {
 	/*pointer dynamic list*/
 	struct flashctx *last;
 	struct flashctx *next;
+	struct flashctx **head;
 };
 
 #define TEST_UNTESTED	0
