diff --git a/meta/classes-recipe/cargo-update-recipe-crates.bbclass b/meta/classes-recipe/cargo-update-recipe-crates.bbclass
index 9db08c08f87a28c7be8f33fa98ceb1bdbec539c8..e15019f99794fb97e654aa5160cdccf3b15534f8 100644
--- a/meta/classes-recipe/cargo-update-recipe-crates.bbclass
+++ b/meta/classes-recipe/cargo-update-recipe-crates.bbclass
@@ -17,17 +17,23 @@
 ##
 ## To perform the update: bitbake -c update_crates recipe-name
 
-addtask do_update_crates after do_patch
+addtask do_update_crates after do_patch do_prepare_recipe_sysroot
 do_update_crates[nostamp] = "1"
 do_update_crates[doc] = "Update the recipe by reading Cargo.lock and write in ${THISDIR}/${BPN}-crates.inc"
 
 RECIPE_UPGRADE_EXTRA_TASKS += "do_update_crates"
 
-# The directory where to search for Cargo.lock files
+# Space-separated list of directories where to search for Cargo.lock files.
+# Each directory must exist and contain at least one Cargo.lock file.
+# Crates found in multiple Cargo.lock files are listed only once, in the
+# section of the first Cargo.lock file that contains them, following the
+# order of the directories listed here.
 CARGO_LOCK_SRC_DIR ??= "${S}"
 
 python do_update_crates() {
-    cargo_lock_src_dir = d.getVar("CARGO_LOCK_SRC_DIR")
+    cargo_lock_src_dirs = d.getVar("CARGO_LOCK_SRC_DIR").split()
+    if not cargo_lock_src_dirs:
+        raise ValueError("CARGO_LOCK_SRC_DIR is empty")
 
     def get_legacy_checksums(crates, filename):
         # Old (v1) Cargo.lock files do not carry a 'checksum' field per
@@ -48,13 +54,13 @@ python do_update_crates() {
             checksums[(name, version, source)] = value
         return checksums
 
-    def get_crates(filename):
+    def get_crates(filename, src_dir, seen):
         try:
             import tomllib
         except ImportError:
             import bb._vendor.tomli as tomllib
 
-        c_list = '# from %s' % os.path.relpath(filename, cargo_lock_src_dir)
+        c_list = '\n# from %s' % os.path.relpath(filename, src_dir)
         c_list += '\nSRC_URI += " \\'
         with open(filename, 'rb') as fp:
             crates = tomllib.load(fp)
@@ -65,20 +71,32 @@ python do_update_crates() {
         crates_candidates = list(filter(lambda c: 'crates.io' in c.get('source', ''), crates['package']))
 
         if not crates_candidates:
-            bb.warn("Unable to find any candidate crates that use crates.io")
+            bb.warn("Unable to find any candidate crates that use crates.io in %s" % filename)
             return None
 
         # Update crates uri and their checksum, to avoid name clashing on the checksum
         # we need to rename crates with name and version to have a unique key
+        # Crates already emitted for a previous Cargo.lock are skipped.
         cksum_list = ''
+        ncrates = 0
         for c in crates_candidates:
             rename = "%s-%s" % (c['name'], c['version'])
             checksum = c.get('checksum')
             if checksum is None:
                 checksum = legacy_checksums.get((c['name'], c['version'], c['source']))
+            if rename in seen:
+                if seen[rename] != checksum:
+                    raise ValueError(f"Conflicting checksums for crate {rename}")
+                continue
             c_list += '\n    crate://crates.io/%s/%s \\' % (c['name'], c['version'])
             if checksum is not None:
                 cksum_list += '\nSRC_URI[%s.sha256sum] = "%s"' % (rename, checksum)
+                seen[rename] = checksum
+            ncrates += 1
+
+        # All crates were already emitted for a previous Cargo.lock
+        if not ncrates:
+            return ''
 
         c_list += '\n"\n'
         c_list += cksum_list
@@ -88,28 +106,32 @@ python do_update_crates() {
     import os
 
     pn = d.getVar("PN")
-    crates = f"# Autogenerated with 'bitbake -c update_crates {pn}'\n\n"
-
-    found = False
-    for root, dirs, files in os.walk(cargo_lock_src_dir):
-        # os.walk() order depends on the filesystem, sort to get a
-        # reproducible output across hosts
-        dirs.sort()
-        # ignore git and patches directories
-        if root.startswith(os.path.join(cargo_lock_src_dir, '.pc')):
-            continue
-        if root.startswith(os.path.join(cargo_lock_src_dir, '.git')):
-            continue
-        for file in files:
-            if file == 'Cargo.lock':
-                cargo_lock_path = os.path.join(root, file)
-                c = get_crates(cargo_lock_path)
-                if c is not None:
-                    crates += c
-                    found = True
-
-    if not found:
-        raise ValueError(f"Unable to find any Cargo.lock in {cargo_lock_src_dir}")
+    crates = f"# Autogenerated with 'bitbake -c update_crates {pn}'\n"
+
+    seen = {}
+    for cargo_lock_src_dir in cargo_lock_src_dirs:
+        if not os.path.isdir(cargo_lock_src_dir):
+            raise ValueError(f"CARGO_LOCK_SRC_DIR entry {cargo_lock_src_dir} does not exist")
+        found = False
+        for root, dirs, files in os.walk(cargo_lock_src_dir):
+            # os.walk() order depends on the filesystem, sort to get a
+            # reproducible output across hosts
+            dirs.sort()
+            # ignore git and patches directories
+            if root.startswith(os.path.join(cargo_lock_src_dir, '.pc')):
+                continue
+            if root.startswith(os.path.join(cargo_lock_src_dir, '.git')):
+                continue
+            for file in files:
+                if file == 'Cargo.lock':
+                    cargo_lock_path = os.path.join(root, file)
+                    c = get_crates(cargo_lock_path, cargo_lock_src_dir, seen)
+                    if c is not None:
+                        crates += c
+                        found = True
+
+        if not found:
+            raise ValueError(f"Unable to find any Cargo.lock in {cargo_lock_src_dir}")
 
     target_file = d.expand("${THISDIR}/${BPN}-crates.inc")
     with open(target_file, 'w') as f:
