I have tried a bunch of different bootcodes, but none worked.
What did work was shortening the USB cable of DeviceB. Although the original cable length was within the specs of USB 2.0, I suppose the USB controller in the Pi needs a very clean signal to work properly, and the controller could not handle the signal noise and loss induced by the cable. In this sense, the USB hub acts as a "repeater", "cleaning" the digital signal.