The UFS tool provides utilities for querying, displaying, and modifying
UFS device configuration and descriptor information.

Features:
- Query and display Device, Geometry, Unit, Configuration, and Power
  Descriptors
- Display LUN configuration and calculated capacities
- Modify LUN, Configuration, and Device Descriptor fields
- Configure WriteBooster-related parameters
- Query common UFS runtime flags
- Commit configuration changes or clear all LUN configurations
- Decode and format descriptor contents for easier debugging

Signed-off-by: Raz Ben Yehuda <[email protected]>
---
 cmd/ufs.c | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 89 insertions(+), 4 deletions(-)

diff --git a/cmd/ufs.c b/cmd/ufs.c
index 790dab50f18..c8bafcd5e1d 100644
--- a/cmd/ufs.c
+++ b/cmd/ufs.c
@@ -24,15 +24,100 @@ static int do_ufs(struct cmd_tbl *cmdtp, int flag, int 
argc, char *const argv[])
                        } else {
                                ufs_probe();
                        }
-
                        return CMD_RET_SUCCESS;
                }
-       }
 
-       return CMD_RET_USAGE;
+#if IS_ENABLED(CONFIG_UFS_TOOL)
+               if (!strcmp(argv[1], "query")) {
+                       int lun = -1;
+                       int idn = -1;
+
+                       if (argc <= 3) {
+                               printf("usage: lun idn");
+                               return CMD_RET_FAILURE;
+                       }
+
+                       lun  = dectoul(argv[2], NULL);
+                       idn  = dectoul(argv[3], NULL);
+
+                       return ufs_tool_query(lun, idn);
+               }
+
+               if (!strcmp(argv[1], "set_lun")) {
+                       int lun;
+                       u32 val;
+
+                       if (argc <= 4) {
+                               ufs_tool_help();
+                               return CMD_RET_FAILURE;
+                       }
+                       lun  = dectoul(argv[2], NULL);
+                       val  = dectoul(argv[4], NULL);
+                       return ufs_tool_set_lun(lun, argv[3], val);
+               }
+
+               if (!strcmp(argv[1], "set_dev_desc")) {
+                       const char *name;
+                       u32 val;
+
+                       if (argc <= 3) {
+                               ufs_tool_help();
+                               return CMD_RET_FAILURE;
+                       }
+                       name = argv[2];
+                       val  = dectoul(argv[3], NULL);
+                       return ufs_tool_set_device_desc(name, val);
+               }
+
+               if (!strcmp(argv[1], "set_cfg_desc")) {
+                       const char *name;
+                       u32 val;
+
+                       if (argc <= 3) {
+                               ufs_tool_help();
+                               return CMD_RET_FAILURE;
+                       }
+                       name = argv[2];
+                       val  = dectoul(argv[3], NULL);
+                       return ufs_tool_set_config_desc(name, val);
+               }
+
+               if (!strcmp(argv[1], "getflag")) {
+                       if (argc == 2) {
+                               printf("usage: getflag [flag name]");
+                               ufs_tool_help();
+                               return CMD_RET_FAILURE;
+                       }
+                       return ufs_tool_query_flag(argv[2]);
+               }
+
+               if (!strcmp(argv[1], "commit"))
+                       return ufs_tool_commit();
+
+               if (!strcmp(argv[1], "clearall"))
+                       return ufs_tool_clearall();
+
+               if (!strcmp(argv[1], "luns")) {
+                       ufs_tool_print_luns();
+                       return 0;
+               }
+       }
+       ufs_tool_help();
+#endif
+       return CMD_RET_FAILURE;
 }
 
-U_BOOT_CMD(ufs, 3, 1, do_ufs,
+U_BOOT_CMD(ufs, 5, 1, do_ufs,
           "UFS sub-system",
           "init [dev] - init UFS subsystem\n"
+#if IS_ENABLED(CONFIG_UFS_TOOL)
+          "query [LUN] [IDN]\n"
+          "set_lun [LUN] [parm name] [value]\n"
+          "set_cfg_des   [parm name] [value]\n"
+          "set_dev_desc  [parm name] [value]\n"
+          "luns - prints luns\n"
+          "clearall - zero out configuration descriptor\n"
+          "getflag [flag name]\n"
+          "commit - writes luns configuration\n"
+#endif
 );
-- 
2.43.0

Reply via email to