cos-customizer: Add support for new dm-verity format.

COS plans to use upstream dm-verity format. cos-customizer modifies
the image and update the dm-verity arguments(hashtree and salt. Modify
seal-oem-partition step to support both new and old dm-verity formats.

BUG=b/240174341
TEST=Manually tested cos-cusomizer with both dm-verity formats.

Change-Id: I994a1670affe196694a0a444a363a023a91967dd
Reviewed-on: https://cos-review.googlesource.com/c/cos/tools/+/37529
Reviewed-by: He Gao <hegao@google.com>
Tested-by: Meena Shanmugam <meenashanmugam@google.com>
Cloud-Build: GCB Service account <228075978874@cloudbuild.gserviceaccount.com>
diff --git a/src/pkg/tools/seal_oem_partition.go b/src/pkg/tools/seal_oem_partition.go
index 5628113..0223024 100644
--- a/src/pkg/tools/seal_oem_partition.go
+++ b/src/pkg/tools/seal_oem_partition.go
@@ -182,9 +182,13 @@
 func appendDMEntryToGRUB(grubPath, name, partUUID, hash, salt string, oemFSSize4K uint64) error {
 	// from 4K blocks to 512B sectors
 	oemFSSizeSector := oemFSSize4K << 3
-	entryString := fmt.Sprintf("%s none ro 1, 0 %d verity payload=PARTUUID=%s hashtree=PARTUUID=%s "+
+	entryStringVersion0 := fmt.Sprintf("%s none ro 1, 0 %d verity payload=PARTUUID=%s hashtree=PARTUUID=%s "+
 		"hashstart=%d alg=sha256 root_hexdigest=%s salt=%s\"", name, oemFSSizeSector,
 		partUUID, partUUID, oemFSSizeSector, hash, salt)
+	entryStringVersion1 := fmt.Sprintf("%s,,,ro,0 %d verity 0 PARTUUID=%s PARTUUID=%s "+
+		"4096 4096 %d %d sha256 %s %s\"", name, oemFSSizeSector,
+		partUUID, partUUID, oemFSSize4K, oemFSSize4K, hash, salt)
+	entryString := entryStringVersion0
 	grubContent, err := ioutil.ReadFile(grubPath)
 	if err != nil {
 		return fmt.Errorf("cannot read grub.cfg at %q, "+
@@ -194,10 +198,15 @@
 	lines := strings.Split(string(grubContent), "\n")
 	// add the entry to all kernel command lines containing "dm="
 	for idx, line := range lines {
-		if !strings.Contains(line, "dm=") {
+		if !strings.Contains(line, "dm=") &&
+		   !strings.Contains(line, "dm-mod.create=") {
 			continue
 		}
-		startPos := strings.Index(line, "dm=")
+		var startPos = strings.Index(line, "dm=")
+		if startPos == -1 {
+			startPos = strings.Index(line, "dm-mod.create=")
+			entryString = entryStringVersion1
+		}
 		// remove the end quote.
 		lineBuf := []rune(line[:len(line)-1])
 		// add number of entries.