board_info.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // SPDX-License-Identifier: GPL-2.0+
  2. #include <common.h>
  3. #include <dm.h>
  4. #include <init.h>
  5. #include <sysinfo.h>
  6. #include <asm/global_data.h>
  7. #include <linux/libfdt.h>
  8. #include <linux/compiler.h>
  9. DECLARE_GLOBAL_DATA_PTR;
  10. int __weak checkboard(void)
  11. {
  12. return 0;
  13. }
  14. static const struct to_show {
  15. const char *name;
  16. enum sysinfo_id id;
  17. } to_show[] = {
  18. { "Manufacturer", SYSINFO_ID_BOARD_MANUFACTURER},
  19. { "Prior-stage version", SYSINFO_ID_PRIOR_STAGE_VERSION },
  20. { "Prior-stage date", SYSINFO_ID_PRIOR_STAGE_DATE },
  21. { /* sentinel */ }
  22. };
  23. static int try_sysinfo(void)
  24. {
  25. struct udevice *dev;
  26. char str[80];
  27. int ret;
  28. /* This might provide more detail */
  29. ret = sysinfo_get(&dev);
  30. if (ret)
  31. return ret;
  32. ret = sysinfo_detect(dev);
  33. if (ret)
  34. return ret;
  35. ret = sysinfo_get_str(dev, SYSINFO_ID_BOARD_MODEL, sizeof(str), str);
  36. if (ret)
  37. return ret;
  38. printf("Model: %s\n", str);
  39. if (IS_ENABLED(CONFIG_SYSINFO_EXTRA)) {
  40. const struct to_show *item;
  41. for (item = to_show; item->id; item++) {
  42. ret = sysinfo_get_str(dev, item->id, sizeof(str), str);
  43. if (!ret)
  44. printf("%s: %s\n", item->name, str);
  45. }
  46. }
  47. return 0;
  48. }
  49. int show_board_info(void)
  50. {
  51. if (IS_ENABLED(CONFIG_OF_CONTROL)) {
  52. int ret = -ENOSYS;
  53. if (IS_ENABLED(CONFIG_SYSINFO))
  54. ret = try_sysinfo();
  55. /* Fail back to the main 'model' if available */
  56. if (ret) {
  57. const char *model;
  58. model = fdt_getprop(gd->fdt_blob, 0, "model", NULL);
  59. if (model)
  60. printf("Model: %s\n", model);
  61. }
  62. }
  63. return checkboard();
  64. }