1.1 --- a/pkg/landfall-examples/hw_info/hw_info.c Fri Feb 16 00:55:51 2024 +0100
1.2 +++ b/pkg/landfall-examples/hw_info/hw_info.c Fri Feb 16 23:11:25 2024 +0100
1.3 @@ -22,8 +22,10 @@
1.4 #include "common.h"
1.5 #include "defs.h"
1.6
1.7 +#include <l4/devices/boot.h>
1.8 #include <l4/devices/dma.h>
1.9 #include <l4/devices/memory.h>
1.10 +#include <l4/devices/msc.h>
1.11
1.12 #include <l4/io/io.h>
1.13 #include <l4/re/env.h>
1.14 @@ -1136,13 +1138,94 @@
1.15
1.16 /* MSC operations. */
1.17
1.18 +static void list_msc_cards(void)
1.19 +{
1.20 + void *channel = get_channel(num_msc_channels, msc_channels, NULL);
1.21 + struct msc_card *cards;
1.22 + struct CSD *csd;
1.23 + uint8_t num;
1.24 +
1.25 + if (channel == NULL)
1.26 + return;
1.27 +
1.28 + cards = msc_get_cards(channel);
1.29 +
1.30 + printf("Card RCA Bits Size\n");
1.31 + printf("---- ---- ---- --------------\n");
1.32 +
1.33 + for (num = 0; num < msc_num_cards(channel); num++)
1.34 + {
1.35 + csd = &cards[num].csd;
1.36 +
1.37 + printf("%d %04x %d %d\n", num, cards[num].rca, cards[num].bus_width,
1.38 + (1 << csd->read_blocklen) *
1.39 + (csd->device_size + 1) *
1.40 + (1 << (csd->device_size_multiplier + 2)));
1.41 + }
1.42 +}
1.43 +
1.44 +static void list_msc_card_partitions(void)
1.45 +{
1.46 + void *channel = get_channel(num_msc_channels, msc_channels, NULL);
1.47 + struct dma_region *dma_region;
1.48 + struct partition_table_entry *entry;
1.49 + uint32_t card, transferred;
1.50 + uint8_t num;
1.51 +
1.52 + if (channel == NULL)
1.53 + return;
1.54 +
1.55 + dma_region = _get_dma_region();
1.56 +
1.57 + if (dma_region == NULL)
1.58 + return;
1.59 +
1.60 + if (!read_number("Card", &card))
1.61 + return;
1.62 +
1.63 + l4_cache_inv_data(dma_region->vaddr, dma_region->vaddr + dma_region->size);
1.64 +
1.65 + transferred = msc_read_blocks(channel, (uint8_t) card, dma_region->paddr, 0, 1);
1.66 +
1.67 + if (!transferred)
1.68 + {
1.69 + printf("Could not read partitions.\n");
1.70 + return;
1.71 + }
1.72 +
1.73 + entry = get_partition_table((uint8_t *) dma_region->vaddr);
1.74 +
1.75 + if (entry == NULL)
1.76 + {
1.77 + printf("Invalid partition table.\n");
1.78 + return;
1.79 + }
1.80 +
1.81 + printf("Partition Status Type Start End Address Sectors\n");
1.82 + printf("--------- ------ ---- --------- --------- -------- --------\n");
1.83 +
1.84 + for (num = 0; num < 4; num++, entry++)
1.85 + {
1.86 + printf("%d %02x %02x %03x %02x %02x %03x %02x %02x %08x %08x\n",
1.87 + num, entry->status, entry->partition_type,
1.88 + entry->chs_first_sector.cylinder,
1.89 + entry->chs_first_sector.head,
1.90 + entry->chs_first_sector.sector,
1.91 + entry->chs_last_sector.cylinder,
1.92 + entry->chs_last_sector.head,
1.93 + entry->chs_last_sector.sector,
1.94 + entry->lba_first_sector,
1.95 + entry->num_sectors);
1.96 + }
1.97 +}
1.98 +
1.99 static void list_msc_channels(void)
1.100 {
1.101 unsigned int num;
1.102 void *channel;
1.103
1.104 - printf("Channel Status\n");
1.105 - printf("------- --------\n");
1.106 + printf("Channel Cards\n");
1.107 + printf("------- -----\n");
1.108
1.109 for (num = 0; num < num_msc_channels; num++)
1.110 {
1.111 @@ -1153,7 +1236,7 @@
1.112 if (channel == NULL)
1.113 printf("inactive\n");
1.114 else
1.115 - printf("%08x\n", msc_get_status(channel));
1.116 + printf("%d\n", msc_num_cards(channel));
1.117 }
1.118 }
1.119
1.120 @@ -1193,7 +1276,7 @@
1.121 static void read_blocks_from_msc(void)
1.122 {
1.123 void *channel = get_channel(num_msc_channels, msc_channels, NULL);
1.124 - struct dma_region *dma_region = NULL;
1.125 + struct dma_region *dma_region;
1.126 uint32_t card, transferred, block_address, block_count;
1.127
1.128 if (channel == NULL)
1.129 @@ -1755,14 +1838,18 @@
1.130 {
1.131 if (!strcmp(token, "l") || !strcmp(token, "list"))
1.132 list_msc_channels();
1.133 + else if (!strcmp(token, "C") || !strcmp(token, "cards"))
1.134 + list_msc_cards();
1.135 else if (!strcmp(token, "c") || !strcmp(token, "channel"))
1.136 new_msc_channel(msc);
1.137 else if (!strcmp(token, "e") || !strcmp(token, "enable"))
1.138 enable_msc_channel();
1.139 + else if (!strcmp(token, "p") || !strcmp(token, "partitions"))
1.140 + list_msc_card_partitions();
1.141 else if (!strcmp(token, "r") || !strcmp(token, "read"))
1.142 read_blocks_from_msc();
1.143 else
1.144 - printf("msc channel | enable | read\n");
1.145 + printf("msc cards | channel | enable | partitions | read\n");
1.146 }
1.147 else
1.148 list_msc_channels();