1  /* PR target/51623 */
       2  /* { dg-do compile { target { { powerpc*-*-linux* && ilp32 } || { powerpc-*-eabi* powerpc-*-rtems* } } } } */
       3  /* { dg-options "-mrelocatable -ffreestanding" } */
       4  
       5  /* This generated an error, since the compiler was calling
       6     unlikely_text_section_p in a context where it wasn't valid.  */
       7  
       8  typedef long long loff_t;
       9  typedef unsigned size_t;
      10  
      11  
      12  struct mtd_info {
      13    unsigned writesize;
      14    unsigned oobsize;
      15    const char *name;
      16  };
      17  
      18  extern int strcmp(const char *,const char *);
      19  extern int strncmp(const char *,const char *,size_t);
      20  extern char * strchr(const char *,int);
      21  
      22  struct cmd_tbl_s {
      23    char *name;
      24  };
      25  
      26  
      27  int printf(const char *fmt, ...) __attribute__ ((format (__printf__, 1, 2)));
      28  int putc (int);
      29  void* malloc(size_t);
      30  void free(void*);
      31  
      32  extern unsigned long simple_strtoul(const char *,char **,unsigned int);
      33  
      34  extern int nand_curr_device;
      35  extern struct mtd_info nand_info[];
      36  
      37  extern void cmd_usage(struct cmd_tbl_s *);
      38  
      39  static int nand_dump(struct mtd_info *nand, unsigned long off, int only_oob)
      40  {
      41    int i;
      42    unsigned char *datbuf, *oobbuf, *p;
      43  
      44    datbuf = malloc(nand->writesize + nand->oobsize);
      45    oobbuf = malloc(nand->oobsize);
      46    off &= ~(nand->writesize - 1);
      47  
      48    printf("Page %08lx dump:\n", off);
      49    i = nand->writesize >> 4;
      50    p = datbuf;
      51  
      52    while (i--) {
      53      if (!only_oob)
      54        printf("\t%02x %02x %02x %02x %02x %02x %02x %02x"
      55  	     "  %02x %02x %02x %02x %02x %02x %02x %02x\n",
      56  	     p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7],
      57  	     p[8], p[9], p[10], p[11], p[12], p[13], p[14],
      58  	     p[15]);
      59      p += 16;
      60    }
      61  
      62    i = nand->oobsize >> 3;
      63    free(datbuf);
      64    free(oobbuf);
      65  
      66    return 0;
      67  }
      68  
      69  int do_nand(struct cmd_tbl_s * cmdtp, int flag, int argc, char *argv[])
      70  {
      71    int dev;
      72    unsigned long  off;
      73    char *cmd, *s;
      74    struct mtd_info *nand;
      75  
      76    if (argc < 2)
      77      goto usage;
      78  
      79    cmd = argv[1];
      80  
      81    if (strcmp(cmd, "info") == 0) {
      82      putc('\n');
      83      return 0;
      84    }
      85  
      86    if (strcmp(cmd, "device") == 0) {
      87      if (argc < 3) {
      88        putc('\n');
      89      }
      90      dev = (int)simple_strtoul(argv[2], ((void *)0), 10);
      91      nand_curr_device = dev;
      92      return 0;
      93    }
      94  
      95    if (strcmp(cmd, "bad") != 0 && strcmp(cmd, "erase") != 0  )
      96      goto usage;
      97    
      98    if (nand_curr_device < 0 ) {
      99      return 1;
     100    }
     101    nand = &nand_info[nand_curr_device];
     102  
     103    if (strcmp(cmd, "erase") == 0 || strcmp(cmd, "scrub") == 0) {
     104      int clean = argc > 2 && !strcmp("clean", argv[2]);
     105      int scrub = !strcmp(cmd, "scrub");
     106      return 0;
     107    }
     108  
     109    if (strncmp(cmd, "dump", 4) == 0) {
     110      if (argc < 3)
     111        goto usage;
     112  
     113      s = strchr(cmd, '.');
     114      off = (int)simple_strtoul(argv[2], ((void *)0), 16);
     115      
     116      if (s != ((void *)0) && strcmp(s, ".oob") == 0)
     117        nand_dump(nand, off, 1);
     118      else
     119        nand_dump(nand, off, 0);
     120      
     121      return 0;
     122    }
     123  usage:
     124    cmd_usage(cmdtp);
     125    return 1;
     126  }
     127  
     128  void *ptr = do_nand;