Skip to content

Commit

Permalink
b200: add custom bootloader
Browse files Browse the repository at this point in the history
- Adds custom bootloader code
- Refactor common functions in firmware and bootloader
  • Loading branch information
meserve authored and mbr0wn committed Apr 11, 2019
1 parent 3642ac0 commit c1e0e73
Show file tree
Hide file tree
Showing 23 changed files with 2,065 additions and 639 deletions.
2 changes: 2 additions & 0 deletions firmware/fx3/.gitignore
@@ -1,3 +1,5 @@
boot_fw
common
elf2img
lpp_source
u3p_firmware
33 changes: 24 additions & 9 deletions firmware/fx3/README.md
Expand Up @@ -5,7 +5,7 @@ INSTRUCTIONS

The USRP B200 and B210 each use the Cypress FX3 USB3 PHY for USB3 connectivity.
This device has an ARM core on it, which is programmed in C. This README will
show you how to build our firmware source
show you how to build our firmware and bootloader source.

**A brief "Theory of Operations":**
The host sends commands to the FX3, our USB3 PHY, which has an on-board ARM
Expand All @@ -32,9 +32,11 @@ tools. These variables are:
$ export ARMGCC_VERSION=4.5.2
```

Now, you'll need to set-up the Cypress SDK, as well. In the SDK, navigate to
the `firmware` directory, and copy the following sub-directories into
`uhd.git/firmware/fx3`: `common/`, `lpp_source/`, `u3p_firmware/`.
Now, you'll need to set-up the Cypress SDK, as well. In the SDK, copy the
following sub-directories from the `firmware` directory to
`uhd.git/firmware/fx3`: `common/`, `lpp_source/`, `u3p_firmware/`, `boot_fw/`.
In addition, copy the `elf2img` sub-directory from the `util` directory to
`uhd.git/firmware/fx3`.

Your directory structure should now look like:

Expand All @@ -46,7 +48,9 @@ uhd.git/
--fx3/
|
--b200/ # From UHD
--boot_fw/ # From Cypress SDK
--common/ # From Cypress SDK
--elf2img/ # From Cypress SDK
--gpif2_designer/ # From UHD
--lpp_source/ # From Cypress SDK
--u3p_firmware/ # From Cypress SDK
Expand All @@ -61,22 +65,33 @@ into the `common/` directory you just copied from the Cypress SDK, and apply the
patch `b200/fx3_mem_map.patch`.

```
# cd uhd.git/firmware/fx3/common/
$ patch -p2 < ../b200/fx3_mem_map.patch
# cd uhd.git/firmware/fx3
$ patch -p1 < ../b200/fx3_mem_map.patch
```

If you don't see any errors print on the screen, then the patch was successful.

## Building the Firmware

Now, you should be able to head into the `b200/` directory and simply build the
firmware:
Now, you should be able to head into the `b200/firmware` directory and simply
build the firmware:

```
$ cd uhd.git/firmware/fx3/b200
$ cd uhd.git/firmware/fx3/b200/firmware
$ make
```

It will generate a `usrp_b200_fw.hex` file, which you can then give to UHD to
program your USRP B200 or USRP B210.

## Building the Bootloader

The bootloader is built in the `b200/bootloader` directory:

```
$ cd uhd.git/firmware/fx3/b200/bootloader
$ make
```

It will generate a `usrp_b200_bl.img` file, which you can supply as an argument
to b2xx_fx3_utils to load it onto the device.
3 changes: 3 additions & 0 deletions firmware/fx3/b200/.gitignore
@@ -1,4 +1,7 @@
lib
!common
*.o
*.elf
*.hex
*.map
*.img
5 changes: 5 additions & 0 deletions firmware/fx3/b200/bootloader/.gitignore
@@ -0,0 +1,5 @@
cyfx3.ld
cyfx_gcc_startup.S
elf2img
fx3_armgcc_config.mak
fx3_build_config.mak
55 changes: 55 additions & 0 deletions firmware/fx3/b200/bootloader/main.c
@@ -0,0 +1,55 @@
//
// Copyright 2011-2012 Cypress Semiconductor Corporation
// Copyright 2019 Ettus Research, a National Instruments Brand
//
// SPDX-License-Identifier: GPL-3.0-or-later
//

#include "cyfx3usb.h"
#include "cyfx3device.h"

extern void usbBoot (void);
extern uint8_t glCheckForDisconnect;
extern uint8_t glInCompliance;

int main (void)
{
CyFx3BootErrorCode_t status;
CyFx3BootIoMatrixConfig_t ioCfg = {
.isDQ32Bit = CyFalse,
.useUart = CyFalse,
.useI2C = CyTrue,
.useI2S = CyFalse,
.useSpi = CyFalse,
.gpioSimpleEn[0] = 0,
.gpioSimpleEn[1] = 0
};

CyFx3BootDeviceInit(CyTrue);

status = CyFx3BootDeviceConfigureIOMatrix(&ioCfg);

if (status != CY_FX3_BOOT_SUCCESS)
{
return status;
}

usbBoot();

while (1)
{
if (glCheckForDisconnect)
{
CyFx3BootUsbCheckUsb3Disconnect();
glCheckForDisconnect = 0;
}

if (glInCompliance)
{
CyFx3BootUsbSendCompliancePatterns();
glInCompliance = 0;
}
}
return 0;
}

92 changes: 92 additions & 0 deletions firmware/fx3/b200/bootloader/makefile
@@ -0,0 +1,92 @@
#
# Copyright 2019 Ettus Research, a National Instruments Brand
#
# SPDX-License-Identifier: GPL-3.0-or-later
#

IMGOUT = usrp_b200_bl.img

all:$(IMGOUT)

BL_ROOT=../../boot_fw
BL_INC=$(BL_ROOT)/include
BL_LIB=$(BL_ROOT)/lib
BL_CYP_SRC=$(BL_ROOT)/src

ELF2IMG_SRC=../../elf2img/elf2img.c
ELF2IMG=elf2img

CYFXBUILD = gcc

include fx3_build_config.mak

MODULE = cyfx_boot_app

APP_SOURCE = main.c usb_boot.c usb_descriptors.c ../common/common_descriptors.c ../common/common_helpers.c

INCFLAGS = -I$(BL_INC) -I../common

APP_OBJECT=$(APP_SOURCE:%.c=./%.o)

APP_ASM_OBJECT=$(APP_ASM_SOURCE:%.S=./%.o)

EXES = $(MODULE).$(EXEEXT)

ifeq ($(CYFXBUILD), gcc)

APP_ASM_SOURCE = cyfx_gcc_startup.S

else

APP_ASM_SOURCE =

endif

$(APP_ASM_OBJECT) : %.o : %.S
$(ASSEMBLE)

$(APP_OBJECT) : %.o : %.c ../lib/cyfx3_boot.a cyfx3.ld
$(COMPILE) $(INCFLAGS)

$(MODULE).$(EXEEXT): $(APP_OBJECT) $(APP_ASM_OBJECT)
$(LINK)

$(ELF2IMG):
gcc -o $(ELF2IMG) $(ELF2IMG_SRC)

fx3_build_config.mak:
cp $(BL_CYP_SRC)/fx3_build_config.mak .
fx3_armgcc_config.mak:
cp $(BL_CYP_SRC)/fx3_armgcc_config.mak .
cyfx_gcc_startup.S:
cp $(BL_CYP_SRC)/cyfx_gcc_startup.S .
cyfx3.ld:
cp $(BL_CYP_SRC)/cyfx3.ld .
../lib/cyfx3_boot.a:
mkdir -p ../lib
cp $(BL_LIB)/cyfx3_boot.a ../lib


clean:
rm -f ./$(MODULE).$(EXEEXT)
rm -f ./$(MODULE).map
rm -f ./$(IMGOUT)
rm -f ./fx3_build_config.mak
rm -f ./fx3_armgcc_config.mak
rm -f ./cyfx_gcc_startup.S
rm -f ./cyfx3.ld
rm -f ../lib/cyfx3_boot.a
rmdir ../lib --ignore-fail-on-non-empty
rm -f ./*.o
rm -f ../common/*.o
rm -f ./$(ELF2IMG)
ifeq ($(CYFXBUILD), gcc)
rm -f ./gcceclipse_files/*.o
endif

compile: $(APP_OBJECT) $(APP_ASM_OBJECT) $(EXES)

$(IMGOUT): compile $(EXES) $(ELF2IMG)
./$(ELF2IMG) -i $(EXES) -o $(IMGOUT) -i2cconf 0x1A

#[]#

0 comments on commit c1e0e73

Please sign in to comment.