bootmeth_sandbox.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Bootmethod for sandbox testing
  4. *
  5. * Copyright 2021 Google LLC
  6. * Written by Simon Glass <sjg@chromium.org>
  7. */
  8. #define LOG_CATEGORY UCLASS_BOOTSTD
  9. #include <common.h>
  10. #include <bootdev.h>
  11. #include <bootflow.h>
  12. #include <bootmeth.h>
  13. #include <dm.h>
  14. static int sandbox_check(struct udevice *dev, struct bootflow_iter *iter)
  15. {
  16. return 0;
  17. }
  18. static int sandbox_read_bootflow(struct udevice *dev, struct bootflow *bflow)
  19. {
  20. /* pretend we are ready */
  21. bflow->state = BOOTFLOWST_READY;
  22. return 0;
  23. }
  24. static int sandbox_read_file(struct udevice *dev, struct bootflow *bflow,
  25. const char *file_path, ulong addr, ulong *sizep)
  26. {
  27. return -ENOSYS;
  28. }
  29. static int sandbox_boot(struct udevice *dev, struct bootflow *bflow)
  30. {
  31. /* always fail: see bootflow_iter_disable() */
  32. return -ENOTSUPP;
  33. }
  34. static int sandbox_bootmeth_bind(struct udevice *dev)
  35. {
  36. struct bootmeth_uc_plat *plat = dev_get_uclass_plat(dev);
  37. plat->desc = "Sandbox boot for testing";
  38. return 0;
  39. }
  40. static struct bootmeth_ops sandbox_bootmeth_ops = {
  41. .check = sandbox_check,
  42. .read_bootflow = sandbox_read_bootflow,
  43. .read_file = sandbox_read_file,
  44. .boot = sandbox_boot,
  45. };
  46. static const struct udevice_id sandbox_bootmeth_ids[] = {
  47. { .compatible = "u-boot,sandbox-extlinux" },
  48. { }
  49. };
  50. U_BOOT_DRIVER(bootmeth_sandbox) = {
  51. .name = "bootmeth_sandbox",
  52. .id = UCLASS_BOOTMETH,
  53. .of_match = sandbox_bootmeth_ids,
  54. .ops = &sandbox_bootmeth_ops,
  55. .bind = sandbox_bootmeth_bind,
  56. };