validate_firmware_image 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #!/bin/sh
  2. . /lib/functions.sh
  3. . /lib/functions/system.sh
  4. . /usr/share/libubox/jshn.sh
  5. include /lib/upgrade
  6. VALID=1
  7. FORCEABLE=1
  8. ALLOW_BACKUP=1
  9. # Mark image as invalid but still possible to install
  10. notify_firmware_invalid() {
  11. VALID=0
  12. }
  13. # Mark image as broken (impossible to install)
  14. notify_firmware_broken() {
  15. VALID=0
  16. FORCEABLE=0
  17. }
  18. # Mark image as incompatible with preserving a backup
  19. notify_firmware_no_backup() {
  20. ALLOW_BACKUP=0
  21. }
  22. # Add result of validation test
  23. notify_firmware_test_result() {
  24. local old_ns
  25. json_set_namespace validate_firmware_image old_ns
  26. json_add_boolean "$1" "$2"
  27. json_set_namespace $old_ns
  28. }
  29. err_to_bool() {
  30. [ "$1" -ne 0 ] && echo 0 || echo 1
  31. }
  32. fwtool_check_signature "$1" >&2
  33. FWTOOL_SIGNATURE=$?
  34. [ "$FWTOOL_SIGNATURE" -ne 0 ] && notify_firmware_invalid
  35. fwtool_check_image "$1" >&2
  36. FWTOOL_DEVICE_MATCH=$?
  37. [ "$FWTOOL_DEVICE_MATCH" -ne 0 ] && notify_firmware_invalid
  38. json_set_namespace validate_firmware_image old_ns
  39. json_init
  40. json_add_object "tests"
  41. json_add_boolean fwtool_signature "$(err_to_bool $FWTOOL_SIGNATURE)"
  42. json_add_boolean fwtool_device_match "$(err_to_bool $FWTOOL_DEVICE_MATCH)"
  43. # Call platform_check_image() here so it can add its test
  44. # results and still mark image properly.
  45. json_set_namespace $old_ns
  46. platform_check_image "$1" >&2 || notify_firmware_invalid
  47. json_set_namespace validate_firmware_image old_ns
  48. json_close_object
  49. json_add_boolean valid "$VALID"
  50. json_add_boolean forceable "$FORCEABLE"
  51. json_add_boolean allow_backup "$ALLOW_BACKUP"
  52. json_dump -i
  53. json_set_namespace $old_ns