[Pdbg] [PATCH] src/main.c: Add detection of host type for kernel backend

Joel Stanley joel at jms.id.au
Wed Sep 12 14:35:31 AEST 2018


On Wed, 12 Sep 2018 at 13:45, Alistair Popple <alistair at popple.id.au> wrote:
>
> Signed-off-by: Alistair Popple <alistair at popple.id.au>
> ---
>  src/main.c | 40 ++++++++++++++++++++++++++++++++++++++--
>  1 file changed, 38 insertions(+), 2 deletions(-)
>
> diff --git a/src/main.c b/src/main.c
> index 883e892..79f67a5 100644
> --- a/src/main.c
> +++ b/src/main.c
> @@ -52,6 +52,8 @@
>  #include "p9r-fsi.dt.h"
>  #include "p9z-fsi.dt.h"
>  #include "p9-kernel.dt.h"
> +
> +#define FSI_CFAM_ID "/sys/devices/platform/gpio-fsi/fsi0/slave at 00:00/cfam_id"
>  #endif
>
>  #ifdef TARGET_PPC
> @@ -59,6 +61,10 @@
>  #include "p9-host.dt.h"
>  #endif
>
> +#define CHIP_ID_P8  0xea
> +#define CHIP_ID_P9  0xd1
> +#define CHIP_ID_P8P 0xd3
> +
>  #define THREADS_PER_CORE       8
>
>  static enum backend backend = KERNEL;
> @@ -629,9 +635,39 @@ static int target_selection(void)
>
>         case KERNEL:
>                 if (device_node == NULL) {
> -                       PR_ERROR("kernel backend requires a device type\n");
> -                       return -1;
> +                       FILE *cfam_id_file;
> +
> +                       /* Try and determine the correct device type */
> +                       cfam_id_file = fopen(FSI_CFAM_ID, "r");


I suggest we do something like this, so it's a bit easier to debug
what's going on. At some point soon openbmc will gain non-root users,
and we will want to have messages for when a user is not-root and
can't open the file.

if (!cfam_id_file) {
     PR_DEBUG("%s: %s, assuming P9\n", strerror(errno), FSI_CFAM_ID);
     /* The support for POWER8 included the cfam_id
      * so if it doesn't exist assume we must be on
      * P9 */
    device_node = "p9";
    } else {

> +                               uint32_t cfam_id = 0;
> +
> +                               fscanf(cfam_id_file, "0x%" PRIx32, &cfam_id);
> +                               fclose(cfam_id_file);
> +
> +                               switch((cfam_id >> 4) & 0xff) {
> +                               case CHIP_ID_P9:
> +                                       device_node = "p9";
> +                                       break;
> +
> +                               case CHIP_ID_P8:
> +                               case CHIP_ID_P8P:
> +                                       device_node = "p8";
> +                                       break;
> +
> +                               default:
> +                                       PR_ERROR("Unknown chip-id detected\n");
> +                                       PR_ERROR("You will need to specify one with -d <host type>\n");

s/one/a host type/

> +                                       return -1;
> +                               }
> +                       } else {
> +                               /* The support for POWER8 included the cfam_id
> +                                * so if it doesn't exist assume we must be on
> +                                * P9 */
> +                               device_node = "p9";
> +                       }
>                 }
> +
>                 if (!strcmp(device_node, "p8"))
>                         pdbg_targets_init(&_binary_p8_kernel_dtb_o_start);
>                 else
> --
> 2.11.0
>


More information about the Pdbg mailing list