On Tue, May 8, 2018 at 8:46 PM, Philippe Mathieu-Daudé <f4bug@amsat.org> wrote:
> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Alistair
> ---
> include/hw/sd/sd.h | 10 ++++++++++
> hw/sd/sd.c | 2 +-
> hw/sd/sdmmc-internal.c | 6 ++++++
> 3 files changed, 17 insertions(+), 1 deletion(-)
>
> diff --git a/include/hw/sd/sd.h b/include/hw/sd/sd.h
> index c854ed6a14..752d8edd6c 100644
> --- a/include/hw/sd/sd.h
> +++ b/include/hw/sd/sd.h
> @@ -150,6 +150,16 @@ uint8_t sd_frame48_calc_checksum(const void *content);
> */
> uint8_t sd_frame136_calc_checksum(const void *content);
>
> +/**
> + * sd_frame48_verify_checksum:
> + * @content: pointer to the frame content
> + *
> + * Verify the 7-bit CRC checksum of a 48-bit SD frame.
> + *
> + * Returns: A boolean indicating whether the frame 7-bit CRC is correct.
> + */
> +bool sd_frame48_verify_checksum(const void *content);
> +
> /* Legacy functions to be used only by non-qdevified callers */
> SDState *sd_init(BlockBackend *bs, bool is_spi);
> int sd_do_command(SDState *sd, SDRequest *req,
> diff --git a/hw/sd/sd.c b/hw/sd/sd.c
> index 6fc8daa5b8..125707a65c 100644
> --- a/hw/sd/sd.c
> +++ b/hw/sd/sd.c
> @@ -473,7 +473,7 @@ static bool sd_req_crc_is_valid(SDRequest *req)
> buffer[0] = 0x40 | req->cmd;
> stl_be_p(&buffer[1], req->arg);
> return true;
> - return sd_frame48_calc_checksum(buffer) == req->crc; /* TODO */
> + return sd_frame48_verify_checksum(buffer); /* TODO */
> }
>
> static void sd_response_r1_make(SDState *sd, uint8_t *response)
> diff --git a/hw/sd/sdmmc-internal.c b/hw/sd/sdmmc-internal.c
> index a94d65b756..a9d19ce3eb 100644
> --- a/hw/sd/sdmmc-internal.c
> +++ b/hw/sd/sdmmc-internal.c
> @@ -105,3 +105,9 @@ uint8_t sd_frame136_calc_checksum(const void *content)
> {
> return (sd_crc7(content, F136_CONTENT_LENGTH) << 1) | 1;
> }
> +
> +bool sd_frame48_verify_checksum(const void *content)
> +{
> + return sd_frame48_calc_checksum(content)
> + == ((const uint8_t *)content)[F48_CONTENT_LENGTH];
> +}
> --
> 2.17.0
>
>